Exemple #1
0
        public static List <BattleAction> attackNearestPlayer(GameCharacter enemy, BattleGame game)
        {
            List <BattleAction> actionList = new List <BattleAction>();

            var attackTarget = findNearestPlayer(enemy, game.board, game.characterList);

            var targetTile = game.board.getTileFromLocation(attackTarget.x, attackTarget.y);

            //path find to target
            List <Point> pointList = PathFind.Pathfind(game.board, enemy.x, enemy.y, targetTile.x, targetTile.y);

            pointList.RemoveAt(0);                   //remove the character from pathfind.
            pointList.RemoveAt(pointList.Count - 1); //remove the target from pathfind.

            foreach (var p in pointList)
            {
                actionList.Add(new BattleAction()
                {
                    AP = 1, character = enemy, actionType = BattleActionType.Move, targetTile = game.board.getTileFromPoint(p)
                });
            }

            //attack action
            actionList.Add(new BattleAction()
            {
                AP = enemy.weapon.actionPoints, character = enemy, targetTile = targetTile, actionType = BattleActionType.Attack
            });

            return(actionList);
        }
Exemple #2
0
        //iterates over the path find and moves single spaces
        public static void moveToPlayer(GameCharacter enemy, GameCharacter target, Board board)
        {
            var pointList = PathFind.Pathfind(board, enemy.x, enemy.y, target.x, target.y);

            foreach (var p in pointList)
            {
                board.MoveCharacter(enemy, board.getTileFromLocation(p.x, p.y));
            }
        }
Exemple #3
0
        public List <BattleAction> GetMoveActionList(int x, int y)
        {
            List <BattleAction> moveList = new List <BattleAction>();

            List <Point> pointList = PathFind.Pathfind(board, ActiveCharacter.x, ActiveCharacter.y, x, y);

            pointList.RemoveAt(0); //remove the character from pathfind.
            foreach (var p in pointList)
            {
                moveList.Add(new BattleAction()
                {
                    character = ActiveCharacter, actionType = BattleActionType.Move, targetTile = board.getTileFromPoint(p)
                });
            }

            return(moveList);
        }
Exemple #4
0
        public static GameCharacter findNearestPlayer(GameCharacter enemy, Board board, List <GameCharacter> charList)
        {
            GameCharacter retval = null;
            int           dist   = 999;

            foreach (GameCharacter c in charList)
            {
                if (c.type == CharacterType.Player)
                {
                    var pointList = PathFind.Pathfind(board, enemy.x, enemy.y, c.x, c.y);
                    if (pointList.Count < dist)
                    {
                        dist   = pointList.Count;
                        retval = c;
                    }
                }
            }
            return(retval);
        }
Exemple #5
0
        //if we have a melee weapon, calculate nearest enemy + weapon ap
        private List <AIAction> getAIAttackActions(BattleGame game)
        {
            List <AIAction> aiActionList = new List <AIAction>();

            if (character.weapon != null)
            {
                if (character.weapon.weaponType == WeaponType.OneHandMelee || character.weapon.weaponType == WeaponType.TwoHandMelee)
                {
                    GameCharacter targetCharacter = AI.findNearestPlayer(character, game.board, game.characterList);

                    List <Point> pointList = PathFind.Pathfind(game.board, character.x, character.y, targetCharacter.x, targetCharacter.y);
                    pointList.RemoveAt(0);                   //remove the character from pathfind.
                    pointList.RemoveAt(pointList.Count - 1); //remove the target from pathfind.

                    int dist = pointList.Count;

                    int cost = dist + character.weapon.actionPoints;

                    List <BattleAction> battleActionList = new List <BattleAction>();

                    foreach (var p in pointList)
                    {
                        battleActionList.Add(new BattleAction()
                        {
                            AP = 1, character = character, actionType = BattleActionType.Move, targetTile = game.board.getTileFromPoint(p)
                        });
                    }

                    battleActionList.Add(new BattleAction()
                    {
                        AP = character.weapon.actionPoints, character = character, targetCharacter = targetCharacter, targetTile = game.board.getTileFromLocation(targetCharacter.x, targetCharacter.y), actionType = BattleActionType.Attack
                    });

                    aiActionList.Add(new AIAction()
                    {
                        actionType = AIActionType.Attack, cost = cost, battleActionList = battleActionList
                    });
                }
            }

            return(aiActionList);
        }
Exemple #6
0
        //Return a path to the tile that has LOS with the destination
        public List <Point> getPathToLOS(Tile origin, Tile destination)
        {
            List <Point> pathList = PathFind.Pathfind(this, origin.x, origin.y, destination.x, destination.y);

            pathList.RemoveAt(0);
            pathList.RemoveAt(pathList.Count - 1);

            int counter = 0;

            foreach (var p in pathList)
            {
                if (checkLOS(getTileFromPoint(p), destination))
                {
                    break;
                }
                counter++;
            }

            pathList.RemoveRange(0, counter);
            return(pathList);
        }
Exemple #7
0
        public List <BattleAction> getAttackActionList(int x, int y)
        {
            List <BattleAction> actionList = new List <BattleAction>();
            List <Point>        pointList  = PathFind.Pathfind(board, ActiveCharacter.x, ActiveCharacter.y, x, y);

            pointList.RemoveAt(0);                   //remove the character from pathfind.
            pointList.RemoveAt(pointList.Count - 1); //remove the target from pathfind.

            foreach (var p in pointList)
            {
                actionList.Add(new BattleAction()
                {
                    character = ActiveCharacter, actionType = BattleActionType.Move, targetTile = board.getTileFromPoint(p)
                });
            }

            actionList.Add(new BattleAction()
            {
                character = ActiveCharacter, targetTile = board.getTileFromLocation(x, y), actionType = BattleActionType.Attack
            });

            return(actionList);
        }
Exemple #8
0
 //Pathfinding helper for Zone Map
 public List <Point> getPath(int x1, int y1, int x2, int y2)
 {
     //return PathFind.Pathfind(this.zoneTileArray, x1, y1, x2, y2);
     return(PathFind.PathfindDiagonal(this.zoneTileArray, x1, y1, x2, y2));
 }