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

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

import com.hypixel.hytale.server.npc.entities.NPCEntity;
import com.hypixel.hytale.component.RemoveReason;
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 javax.annotation.Nonnull;
import com.hypixel.hytale.server.npc.corecomponents.lifecycle.builders.BuilderActionDespawn;
import com.hypixel.hytale.server.npc.corecomponents.ActionBase;

public class ActionDespawn extends ActionBase
{
    protected final boolean force;
    
    public ActionDespawn(@Nonnull final BuilderActionDespawn builderActionDespawn) {
        super(builderActionDespawn);
        this.force = builderActionDespawn.isForced();
    }
    
    @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);
        if (this.force) {
            store.removeEntity(ref, RemoveReason.REMOVE);
        }
        else {
            final NPCEntity npcComponent = store.getComponent(ref, NPCEntity.getComponentType());
            assert npcComponent != null;
            npcComponent.setToDespawn();
        }
        return true;
    }
}
