// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.builtin.adventure.npcobjectives.npc;

import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
import com.hypixel.hytale.server.npc.role.support.EntitySupport;
import java.util.UUID;
import com.hypixel.hytale.component.Archetype;
import com.hypixel.hytale.builtin.adventure.npcobjectives.NPCObjectivesPlugin;
import com.hypixel.hytale.server.core.entity.UUIDComponent;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.npc.role.Role;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.npc.corecomponents.builders.BuilderSensorBase;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import javax.annotation.Nonnull;
import com.hypixel.hytale.builtin.adventure.npcobjectives.npc.builders.BuilderSensorHasTask;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.npc.corecomponents.SensorBase;

public class SensorHasTask extends SensorBase
{
    @Nullable
    protected final String[] tasksById;
    
    public SensorHasTask(@Nonnull final BuilderSensorHasTask builder, @Nonnull final BuilderSupport support) {
        super(builder);
        this.tasksById = builder.getTasksById(support);
    }
    
    @Override
    public boolean matches(@Nonnull final Ref<EntityStore> ref, @Nonnull final Role role, final double dt, @Nonnull final Store<EntityStore> store) {
        if (!super.matches(ref, role, dt, store)) {
            return false;
        }
        final Ref<EntityStore> target = role.getStateSupport().getInteractionIterationTarget();
        if (target == null) {
            return false;
        }
        final Archetype<EntityStore> targetArchetype = store.getArchetype(target);
        if (targetArchetype.contains(DeathComponent.getComponentType())) {
            return false;
        }
        final UUIDComponent targetUuidComponent = store.getComponent(target, UUIDComponent.getComponentType());
        assert targetUuidComponent != null;
        final UUID targetUuid = targetUuidComponent.getUuid();
        final UUIDComponent uuidComponent = store.getComponent(ref, UUIDComponent.getComponentType());
        assert uuidComponent != null;
        final UUID uuid = uuidComponent.getUuid();
        final NPCObjectivesPlugin objectiveSystem = NPCObjectivesPlugin.get();
        final EntitySupport entitySupport = role.getEntitySupport();
        boolean match = false;
        for (final String taskById : this.tasksById) {
            if (NPCObjectivesPlugin.hasTask(targetUuid, uuid, taskById)) {
                match = true;
                entitySupport.addTargetPlayerActiveTask(taskById);
            }
        }
        return match;
    }
    
    @Override
    public InfoProvider getSensorInfo() {
        return null;
    }
}
