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

package com.hypixel.hytale.server.npc.decisionmaker.core.conditions;

import com.hypixel.hytale.server.npc.role.support.PositionCache;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.npc.decisionmaker.core.EvaluationContext;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Ref;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.ArchetypeChunk;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.npc.entities.NPCEntity;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.server.npc.decisionmaker.core.conditions.base.SimpleCondition;

public class LineOfSightCondition extends SimpleCondition
{
    public static final BuilderCodec<LineOfSightCondition> CODEC;
    @Nullable
    protected static final ComponentType<EntityStore, NPCEntity> NPC_COMPONENT_TYPE;
    
    @Override
    public int getSimplicity() {
        return 40;
    }
    
    @Override
    protected boolean evaluate(final int selfIndex, @Nonnull final ArchetypeChunk<EntityStore> archetypeChunk, @Nullable final Ref<EntityStore> targetRef, @Nonnull final CommandBuffer<EntityStore> commandBuffer, final EvaluationContext context) {
        if (targetRef == null || !targetRef.isValid()) {
            return false;
        }
        final Ref<EntityStore> selfRef = archetypeChunk.getReferenceTo(selfIndex);
        final NPCEntity selfNpcComponent = archetypeChunk.getComponent(selfIndex, LineOfSightCondition.NPC_COMPONENT_TYPE);
        assert selfNpcComponent != null;
        final PositionCache positionCache = selfNpcComponent.getRole().getPositionCache();
        return positionCache.hasLineOfSight(selfRef, targetRef, commandBuffer);
    }
    
    static {
        CODEC = BuilderCodec.builder(LineOfSightCondition.class, LineOfSightCondition::new, LineOfSightCondition.ABSTRACT_CODEC).documentation("A simple boolean condition that returns whether or not there is a line of sight to the target.").build();
        NPC_COMPONENT_TYPE = NPCEntity.getComponentType();
    }
}
