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

package com.hypixel.hytale.server.npc.corecomponents.utility;

import com.hypixel.hytale.server.npc.sensorinfo.WrappedInfoProvider;
import com.hypixel.hytale.server.npc.role.support.DebugSupport;
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.utility.builders.BuilderSensorMany;
import com.hypixel.hytale.server.npc.instructions.Sensor;
import java.util.List;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.corecomponents.utility.builders.BuilderSensorAnd;

public class SensorAnd extends SensorMany
{
    public SensorAnd(@Nonnull final BuilderSensorAnd builder, @Nonnull final BuilderSupport support, @Nonnull final List<Sensor> sensors) {
        super(builder, support, sensors);
    }
    
    @Override
    public boolean matches(@Nonnull final Ref<EntityStore> ref, @Nonnull final Role role, final double dt, @Nonnull final Store<EntityStore> store) {
        this.infoProvider.clearPositionMatch();
        final DebugSupport debugSupport = role.getDebugSupport();
        final int length = this.sensors.length;
        if (!super.matches(ref, role, dt, store) || length == 0) {
            if (this.autoUnlockTargetSlot >= 0) {
                role.getMarkedEntitySupport().clearMarkedEntity(this.autoUnlockTargetSlot);
            }
            if (debugSupport.isTraceSensorFails()) {
                debugSupport.setLastFailingSensor(this);
            }
            return false;
        }
        for (final Sensor s : this.sensors) {
            if (!s.matches(ref, role, dt, store)) {
                if (this.autoUnlockTargetSlot >= 0) {
                    role.getMarkedEntitySupport().clearMarkedEntity(this.autoUnlockTargetSlot);
                }
                this.infoProvider.clearPositionMatch();
                if (debugSupport.isTraceSensorFails()) {
                    debugSupport.setLastFailingSensor(s);
                }
                return false;
            }
            if (!this.infoProvider.hasPosition() && s.getSensorInfo() != null && s.getSensorInfo().hasPosition()) {
                this.infoProvider.setPositionMatch(s.getSensorInfo().getPositionProvider());
            }
        }
        return true;
    }
    
    @Nonnull
    @Override
    protected WrappedInfoProvider createInfoProvider() {
        return new WrappedInfoProvider(this.sensors);
    }
}
