aboutsummaryrefslogtreecommitdiff
path: root/V3/AI/Internal/MoveAction.cs
blob: fcbba54aee392304b84689076e414aaa5f1bb74d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Microsoft.Xna.Framework;
using V3.Objects;

namespace V3.AI.Internal
{
    /// <summary>
    /// Moves a creature to a destination point.
    /// </summary>
    // ReSharper disable once ClassNeverInstantiated.Global
    public class MoveAction : AbstractAction
    {
        private ICreature mCreature;
        private Vector2 mDestination;

        /// <summary>
        /// Creates a new MoveAction to move the given creature to the given
        /// destination.
        /// </summary>
        /// <param name="creature">the creature to mvoe</param>
        /// <param name="destination">the destination of the creature</param>
        public MoveAction(ICreature creature, Vector2 destination)
        {
            mCreature = creature;
            mDestination = destination;
        }

        /// <summary>
        /// Start the execution of the action.
        /// </summary>
        public override void Start()
        {
            mCreature.Move(mDestination);
            base.Start();
        }

        protected override ActionState GetNextState()
        {
            switch (mCreature.MovementState)
            {
                case MovementState.Idle:
                    return ActionState.Done;
                case MovementState.Attacking:
                case MovementState.Dying:
                    return ActionState.Failed;
                case MovementState.Moving:
                    return ActionState.Executing;
                default:
                    return ActionState.Failed;
            }
        }

    }
}