Example #1
0
        protected static bool Move(Squad mover, Step[] path, BattleData bd)
        {
            if (path == null)
                return false;
            int length = path.Length;
            if (length < 1)
                return true;
            double movement = mover.Unit.MovementSpeed;
            Point temp = path[0].Key;

            for (int k = length - 1; k > 0; k--)
            {
                if (path[k].Value > movement)
                {
                    temp = path[k + 1].Key;

                    mover.CurrentAction.Type = Squad.ActionType.Move;
                    mover.CurrentAction.Path = path.Select(x => x.Key).SkipWhile(x => x != temp).TakeWhile(x => x != mover.Position).Concat(new Point[] { mover
                    .Position}).ToArray();

                    bd.Relocate(mover.Position, temp);
                    mover.Position = temp;
                    return false;
                }
            }

            mover.CurrentAction.Type = Squad.ActionType.Move;
            mover.CurrentAction.Path = path.Select(x => x.Key).SkipWhile(x => x != temp).TakeWhile(x => x != mover.Position).Concat(new Point[] { mover
                    .Position}).ToArray();

            bd.Relocate(mover.Position, temp);
            mover.Position = temp;
            return true;
        }
Example #2
0
        static void HitAndRun(BattleData battleData, Squad current)
        {
            if (battleData.EnemyArmy.Length < 1)
                return;

            int TargetIndex = Strategy.NearestToPoint(current.Position, battleData.EnemyArmy);
            if (TargetIndex < 0)
                return;
            Step[] Path = DistanceAndPath.PathTo(
                battleData,
                current.Position,
                battleData.EnemyArmy[TargetIndex].Position,
                current.Unit.Range);
            if (Path != null)
                if (Path.Length == 0)
                {
                    Point SafePoint = GetSafeFrom(current.Position, battleData.EnemyArmy[TargetIndex].Position);

                    Path = DistanceAndPath.PathTo(
                    battleData,
                    current.Position,
                    SafePoint,
                    0);

                    Strategy.AttackAndMove(current, battleData.EnemyArmy[TargetIndex], Path, battleData);
                }
                else
                    Strategy.MoveAndAttack(current, battleData.EnemyArmy[TargetIndex], Path, battleData);
        }
Example #3
0
        protected static void AttackAndMove(Squad attacker, Squad target, Step[] path, BattleData bd)
        {
            attacker.CurrentAction.Type = Squad.ActionType.Attack;
            attacker.CurrentAction.Target = target;

            int dmg = target.Amount;
            attacker.Attack(target);

            attacker.CurrentAction.Damage = dmg - target.Amount;

            Move(attacker, path, bd);

            if (attacker.CurrentAction.Type == Squad.ActionType.Move)
                attacker.CurrentAction.Type = Squad.ActionType.AttackAndMove;
        }
Example #4
0
        static void Ambysh(BattleData battleData, Squad current)
        {
            if (battleData.EnemyArmy.Length < 1)
                return;

                int TargetIndex = Strategy.NearestToPoint(current.Position, battleData.EnemyArmy);
                if (TargetIndex < 0)
                    return;
                Step[] Path = DistanceAndPath.PathTo(
                    battleData,
                    current.Position,
                    battleData.EnemyArmy[TargetIndex].Position,
                    current.Unit.Range);
                if (Path != null)
                    Strategy.MoveAndAttack(current, battleData.EnemyArmy[TargetIndex], Path, battleData);
        }
Example #5
0
 //public static Func<Point, Point, Squad[,], KeyValuePair<Point[],double>> PathFinder;
 public AI(Player player, BattleData battleData)
 {
     // TODO: Complete member initialization
     this.Player = player;
     this.BattleData = battleData;
 }
 public static Step[] PathTo(BattleData battleData, Point p1, Point p2, float range)
 {
     return battleData.PathFinder.FindPath(p1, p2, range);
 }