package electrosphere.entity.state.movement;

import electrosphere.entity.Entity;
import electrosphere.entity.btree.BehaviorTree;
import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree;
import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementTreeState;

/**
 * Client sprint tree
 */
public class SprintTree implements BehaviorTree {
    
    public static enum SprintTreeState {
        SPRINTING,
        NOT_SPRINTING,
    }
    
    SprintTreeState state;
    
    ClientGroundMovementTree groundMovementTree;
    
    Entity parent;
    
    int staminaCurrent = 0;
    int staminaMax = 1;
    
    float maxVelocity;
    
    public SprintTree(Entity e, float maxVelocity, int staminaMax){
        state = SprintTreeState.NOT_SPRINTING;
        parent = e;
        this.maxVelocity = maxVelocity;
        this.staminaMax = staminaMax;
    }
    
    public SprintTreeState getState(){
        return state;
    }
    
    public void start(){
        if(staminaCurrent > 0){
            // System.out.println("Starting sprinting");
            state = SprintTreeState.SPRINTING;
        }
    }
    
    public void stop(){
        state = SprintTreeState.NOT_SPRINTING;
    }
    
    @Override
    public void simulate(float deltaTime){
        switch(state){
            case SPRINTING:
                if(groundMovementTree != null && groundMovementTree.getState() != MovementTreeState.IDLE){
                    staminaCurrent--;
                    if(staminaCurrent < 1){
                        state = SprintTreeState.NOT_SPRINTING;
                    }
                }
                break;
            case NOT_SPRINTING:
                staminaCurrent++;
                if(staminaCurrent > staminaMax){
                    staminaCurrent = staminaMax;
                }
                break;
        }
    }
    
    public void setGroundMovementTree(ClientGroundMovementTree groundMovementTree){
        this.groundMovementTree = groundMovementTree;
    }

    //get max velocity
    public float getMaxVelocity() {
        return maxVelocity;
    }

    
    
}
