Exemple #1
0
 public IASpell(int spellId, int relaunchs, SpellTarget target, bool handToHand, bool moveFirst, SpellLevel spellLevel)
 {
     SpellId    = spellId;
     Relaunchs  = relaunchs;
     Target     = target;
     HandToHand = handToHand;
     MoveFirst  = moveFirst;
     Name       = D2OParsing.GetSpellName(SpellId);
     Spell      = spellLevel;
 }
        private void ExecuteSpell()
        {
            Logger.Default.Log($"Vie du bot: {_account.Character.LifePercentage}");
            if (_spells == null)
            {
                return;
            }
            var monster = _account.Character.Fight.NearestMonster();
            //foreach (var spell in _spells)
            //{
            var spell = _spells[0];

            _currentSpell = spell;
            var fighter = (IFighter)monster;

            if (spell.Target == SpellTarget.Self)
            {
                fighter = _account.Character.Fight.Fighter;
            }
            var useSpell  = _account.Character.Fight.CanUseSpell(spell.SpellId, fighter);
            var nameSpell = D2OParsing.GetSpellName(spell.SpellId);

            if (_totalSpellLauch <= spell.Relaunchs)
            {
                Logger.Default.Log($"Attaque {monster.Name}");
                switch (useSpell)
                {
                case -1:
                    _account.Character.Fight.EndTurn();
                    break;

                case 0:
                    Logger.Default.Log($"Lancement de {nameSpell}");
                    _spellEvent              = new SpellCast(_account, spell.SpellId, fighter.CellId);
                    _spellEvent.SpellCasted += OnSpellCasted;
                    _spellEvent.PerformCast();
                    break;

                default:
                    Logger.Default.Log($"Déplacement en {useSpell}");
                    var movement = _account.Character.Fight.MoveToCell(useSpell);
                    movement.MovementFinished += (sender, e) =>
                    {
                        if (e.Sucess)
                        {
                            Logger.Default.Log($"Lancement de {nameSpell}");
                            _spellEvent              = new SpellCast(_account, spell.SpellId, fighter.CellId);
                            _spellEvent.SpellCasted += OnSpellCasted;
                            _spellEvent.PerformCast();
                        }
                        else
                        {
                            Logger.Default.Log(
                                $"Erreur lors du lancement du spell {spell.SpellId} sur la cell {fighter.CellId}",
                                LogMessageType.Public);
                        }
                    };
                    movement.PerformMovement();
                    break;
                }
            }
            else
            {
                _totalSpellLauch = 0;
                _account.Character.Fight.EndTurn();
            }
        }