Ejemplo n.º 1
0
        public override void Update()
        {
            // have agent update move space to be safe
            _owner.MyMoveRangeCalculator.Update();

            // careful with this loop
            while ((_owner as Creature).GetAP() > 0)
            {
                // if no enemies in sight, engage in idle behavior
                if (base._observedEnemies.Count == 0)
                {
                    // idle behavior
                    Coords goal = RandomAccessibleHex(_owner.MyMoveRangeCalculator);
                    if (goal != _owner.PositionGet())
                    {
                        Action goSomewhere = new ActionMove((_owner as Creature), _owner.MyMoveRangeCalculator.RetrieveRoute(goal),
                                                            _owner.MyMoveRangeCalculator.Cost(goal), _drawer);
                        goSomewhere.Execute();
                    }

                    return;
                }

                // if enemy in range, attack
                Creature potentialTarget = EnemyNearest();

                float range = (_owner as Creature).GetAttackRange();
                if (potentialTarget.PositionGet().DistanceTo(_owner.PositionGet()) <= (_owner as Creature).GetAttackRange())
                {
                    UInt16 ap = (_owner as Creature).GetAP();
                    if ((_owner as Creature).GetAP() > (_owner as Creature).SpellCurrent.ExecutionTime)
                    {
                        Action attack = new ActionUseSpell(_owner as Creature, (_owner as Creature).SpellCurrent, potentialTarget.PositionGet());
                        attack.Execute();
                    }
                    else
                    {
                        // not enough AP. end turn.
                        return;
                    }
                }
                else
                {
                    Coords goal = NearestAcessibleHex(potentialTarget.PositionGet(), _owner.MyMoveRangeCalculator);
                    if (goal != _owner.PositionGet())
                    {
                        Action goToAction = new ActionMove(_owner, _owner.MyMoveRangeCalculator.RetrieveRoute(goal),
                                                           _owner.MyMoveRangeCalculator.Cost(goal), _drawer);
                        goToAction.Execute();
                    }
                    else
                    {
                        return;
                    }
                }

                // no enemy in range - approach nearest enemy
            }
        }
 private void HandlerMouse_RightButton_TerrainClicked(MouseState mouse, Coords selectedHex)
 {
     //List<Direction> route = _selectedCreature.MyPathfinder.PathfinderAStarCoarse
     //    (_selectedCreature.PositionTile, selectedHex, StaticMathFunctions.DistanceBetweenTwoCoordsEucledean);
     if (_selectedCreature.MyMoveRangeCalculator.Accessible(selectedHex))
     {
         List <Direction> route = _selectedCreature.MyMoveRangeCalculator.RetrieveRoute(selectedHex);
         ActionMove       move  = new ActionMove(_selectedCreature, route, _selectedCreature.MyMoveRangeCalculator.Cost(selectedHex), _myDrawer);
         //_myDrawer.AddMovementAnimation(_selectedCreature, route);
         _myGame.ExecuteAction(move);
     }
 }