public MoveTowardsTargetAction(Actor actor, Entity target)
     : base(actor)
 {
     entity_target = target;
     move_action = new MoveAction (actor);
     fallback_action = new RandomMoveAction (actor);
 }
Example #2
0
        private Action CreateMoveAction(Direction direction)
        {
            GridInformation info = GridInformation.Invalid;
            Action action = null;
            Location loc = null;

            loc = direction.ApplyTo (base.Location);
            if (loc != null) {
                info = loc.GridInformation;
            }

            switch (info)
            {
                case GridInformation.Invalid:
                    Messages.Instance.Add ("You can't go that way!");
                    break;

                case GridInformation.BlockingTerrain:
                    Messages.Instance.Add ("There is something in the way.");
                    break;

                case GridInformation.Occupied:
                    AddAction (new AttackAction (this, loc.Actor));
                    break;

                default:
                    action = new MoveAction (this, direction);
                    break;
            }

            return action;
        }
Example #3
0
        public override void TakeTurn()
        {
            Action action = null;
            Location location = base.Location;

            // Possibly attack someone
            Actor enemy = AdjacentHostiles.FirstOrDefault ();
            if (enemy != null) {
                action = new AttackAction (this, enemy);
            }

            // Move towards the Hero
            if (action == null) {
                Location target = Game.Instance.Hero.Location;
                Direction direction = location.DirectionOf (target);

                if (base.CanMoveIn (direction))
                    action = new MoveAction (this, direction);
            }

            // Move randomly
            if (action == null)
                action = new RandomMoveAction (this);

            base.Action = action;
            base.TakeTurn ();
        }