package electrosphere.server.ai.trees.creature;

import electrosphere.data.entity.creature.ai.WanderTreeData;
import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementRelativeFacing;
import electrosphere.server.ai.blackboard.BlackboardKeys;
import electrosphere.server.ai.nodes.AITreeNode;
import electrosphere.server.ai.nodes.actions.move.FaceTargetNode;
import electrosphere.server.ai.nodes.actions.move.MoveStartNode;
import electrosphere.server.ai.nodes.actions.move.MoveStopNode;
import electrosphere.server.ai.nodes.meta.DataDeleteNode;
import electrosphere.server.ai.nodes.meta.collections.RandomizerNode;
import electrosphere.server.ai.nodes.meta.collections.SequenceNode;
import electrosphere.server.ai.nodes.meta.debug.PublishStatusNode;
import electrosphere.server.ai.nodes.meta.decorators.SucceederNode;
import electrosphere.server.ai.nodes.meta.decorators.TimerNode;
import electrosphere.server.ai.nodes.plan.TargetRandomPositionNode;

/**
 * Wanders around aimlessly
 */
public class WanderTree {
    
    /**
     * Name of the tree
     */
    public static final String TREE_NAME = "Wander";

    /**
     * Creates an wander ai tree
     * @return The root node of the tree
     */
    public static AITreeNode create(WanderTreeData wanderTreeData){
        return new SequenceNode(
            "WanderTree",
            //select action to perform
            new RandomizerNode(

                //wait
                new SequenceNode(
                    "MeleeAITree",
                    new PublishStatusNode("Waiting"),
                    new SucceederNode(new MoveStopNode()),
                    new DataDeleteNode(BlackboardKeys.POINT_TARGET),
                    new TimerNode(new SucceederNode(null), 1200)
                ),

                //move towards a random position
                new SequenceNode(
                    "WanderMove",
                    new PublishStatusNode("Move into wander target range"),
                    new TargetRandomPositionNode(BlackboardKeys.POINT_TARGET),
                    new FaceTargetNode(BlackboardKeys.MOVE_TO_TARGET),
                    new SucceederNode(new MoveStartNode(MovementRelativeFacing.FORWARD)),
                    new TimerNode(new SucceederNode(null), 600)
                )
            )
        );
    }

}
