Ejemplo n.º 1
0
        public static List <MoveNode> getPath(MoveNode node)
        {
            List <MoveNode> path    = new List <MoveNode>();
            MoveNode        current = node;

            while (current != null)
            {
                path.Add(current);
                current = current.parent;
            }

            path.Reverse();

            return(path);
        }
Ejemplo n.º 2
0
        public BattleMove(BattleUnit unit, MoveNode node, List <MoveNode> moveNodes)
        {
            this.unit      = unit;
            this.node      = node;
            this.moveNodes = moveNodes;

            path     = BattleMap.getPath(node);
            CTR      = 0;
            Ready    = true;
            Priority = 1;
            ID       = GameBattle.generateID();

            //restrict path to unit's move limit
            if (path.Count > unit.moveLimit)
            {
                path = path.Take(unit.moveLimit).ToList();
            }
        }
Ejemplo n.º 3
0
        public void invoke(BattleMap map, List <BattleUnit> units, BattleQueue queue)
        {
            GameBattle.WriteLine(name + " invoked");

            //this.safetyMap = generateSafetyMap(battle.units, this);
            List <BattleAction> coverage = BattleAction.generateCoverage(map, units, this);

            if (!moved && !acted)
            {
                if (action != null)
                {
                    GameBattle.WriteLine(name + " is already preparing to act.");
                    //todo: if action is sticky, allow movement
                    acted = true;
                }
                else
                {
                    action = coverage.First();  //supposedly the best action

                    //if action requires move
                    if (action.node.x != X || action.node.y != Y)
                    {
                        move = new BattleMove(this, action.node, action.moveNodes);
                        queue.add(move);
                        moved  = true;
                        action = null; //will get new action after move is completed
                    }
                    else
                    {
                        queue.add(action);
                        acted = true;
                        GameBattle.WriteLine(name + " queued an action called " + action.actiondef.name);
                    }
                }
            }
            else if (acted && !moved)
            {
                GameBattle.WriteLine("Moving to a safer location.");

                List <MoveNode> moveNodes = BattleMap.getMoveNodes(map.tiles, GameBattle.MAP_WIDTH, GameBattle.MAP_HEIGHT, units, this, moveLimit, true);

                moveNodes.Sort();

                MoveNode newNode = moveNodes[0];
                move = new BattleMove(this, newNode, action.moveNodes);
                queue.add(move);

                //only counts as move if actually moved
                if (newNode.x != X || newNode.y != Y)
                {
                    moved = true;
                }

                done();
            }
            else if (!acted && moved)
            {
                if (action != null)
                {
                    GameBattle.WriteLine(name + " is already preparing to act!!!");
                }
                else
                {
                    action = coverage[0];
                    queue.add(action);
                    acted = true;
                    GameBattle.WriteLine(name + " queued an action called " + action.actiondef.name);
                }

                done();
            }
            else
            {
                GameBattle.WriteLine("This should never happen.");
                done();
            }
        }