// 
// 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.BuilderSensorOr;

public class SensorOr extends SensorMany
{
    public SensorOr(@Nonnull final BuilderSensorOr 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.clearMatches();
        this.infoProvider.clearPositionMatch();
        final DebugSupport debugSupport = role.getDebugSupport();
        if (!super.matches(ref, role, dt, store)) {
            if (this.autoUnlockTargetSlot >= 0) {
                role.getMarkedEntitySupport().clearMarkedEntity(this.autoUnlockTargetSlot);
            }
            if (debugSupport.isTraceSensorFails()) {
                debugSupport.setLastFailingSensor(this);
            }
            return false;
        }
        Sensor match = null;
        if (super.matches(ref, role, dt, store)) {
            for (final Sensor s : this.sensors) {
                if (s.matches(ref, role, dt, store)) {
                    if (match == null) {
                        match = s;
                    }
                    this.infoProvider.addMatch(s);
                    if (!this.infoProvider.hasPosition() && s.getSensorInfo() != null && s.getSensorInfo().hasPosition()) {
                        this.infoProvider.setPositionMatch(s.getSensorInfo().getPositionProvider());
                    }
                }
            }
        }
        if (match == null) {
            if (this.autoUnlockTargetSlot >= 0) {
                role.getMarkedEntitySupport().clearMarkedEntity(this.autoUnlockTargetSlot);
            }
            if (debugSupport.isTraceSensorFails()) {
                debugSupport.setLastFailingSensor(this);
            }
            return false;
        }
        return true;
    }
    
    @Nonnull
    @Override
    protected WrappedInfoProvider createInfoProvider() {
        return new WrappedInfoProvider();
    }
}
