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

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

import com.hypixel.hytale.server.npc.util.IComponentExecutionControl;
import com.hypixel.hytale.server.npc.role.support.EntitySupport;
import com.hypixel.hytale.math.random.RandomExtra;
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.builders.BuilderActionWithDelay;

public abstract class ActionWithDelay extends ActionBase
{
    private final double[] delayRange;
    private double delay;
    private boolean isDelaying;
    
    public ActionWithDelay(@Nonnull final BuilderActionWithDelay builder, @Nonnull final BuilderSupport support) {
        super(builder);
        this.delayRange = builder.getDelayRange(support);
    }
    
    @Override
    public boolean processDelay(final float dt) {
        if (!this.isDelaying) {
            return true;
        }
        final double delay = this.delay - dt;
        this.delay = delay;
        if (delay <= 0.0) {
            this.isDelaying = false;
        }
        return !this.isDelaying;
    }
    
    protected boolean isDelaying() {
        return this.isDelaying;
    }
    
    protected boolean isDelayPrepared() {
        return this.delay > 0.0;
    }
    
    protected void prepareDelay() {
        this.delay = RandomExtra.randomRange(this.delayRange);
        this.isDelaying = false;
    }
    
    protected void clearDelay() {
        this.delay = 0.0;
        this.isDelaying = false;
    }
    
    protected void startDelay(@Nonnull final EntitySupport support) {
        support.registerDelay(this);
        this.isDelaying = true;
    }
}
