示例#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_EnemyClicked(MouseState mouse, Coords selectedHex, Creature hexTenant)
 {
     // Apply selected skill.
     if (_selectedCreature.GetAP() >= _selectedCreature.SpellCurrent.ExecutionTime)
     {
         ActionUseSpell useSpell = new ActionUseSpell(_selectedCreature, _selectedCreature.SpellCurrent, selectedHex);
         useSpell.Execute();
     }
 }