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

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

import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.npc.sensorinfo.InfoProvider;
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.BuilderActionBase;
import com.hypixel.hytale.server.npc.asset.builder.BuilderSupport;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.corecomponents.utility.builders.BuilderActionResetInstructions;
import com.hypixel.hytale.server.npc.corecomponents.ActionBase;

public class ActionResetInstructions extends ActionBase
{
    protected final int[] instructions;
    
    public ActionResetInstructions(@Nonnull final BuilderActionResetInstructions builder, @Nonnull final BuilderSupport support) {
        super(builder);
        this.instructions = builder.getInstructions(support);
    }
    
    @Override
    public boolean execute(@Nonnull final Ref<EntityStore> ref, @Nonnull final Role role, final InfoProvider sensorInfo, final double dt, @Nonnull final Store<EntityStore> store) {
        super.execute(ref, role, sensorInfo, dt, store);
        role.addDeferredAction((_ref, _role, _dt, _store) -> this.resetInstructions(_role, _dt));
        return true;
    }
    
    protected boolean resetInstructions(@Nonnull final Role role, final double dt) {
        if (this.instructions.length == 0) {
            role.resetAllInstructions();
            return true;
        }
        for (final int instruction : this.instructions) {
            role.resetInstruction(instruction);
        }
        return true;
    }
}
