private void OnStopMoving(Spell spell, Fighter enemy, bool canceled, bool refused) { if (refused) { Bot.Character.SendMessage("Move refused"); } else if (canceled) { Bot.Character.SendMessage("Move canceled"); } Bot.Character.Fighter.StopMoving -= m_stopMovingDelegate; m_stopMovingDelegate = null; m_character.CastSpell(spell, enemy.Cell); MoveFar(); m_character.PassTurn(); }
private void StartAI() { var nearestMonster = GetNearestEnemy(); var shortcut = m_character.Character.SpellShortcuts.Shortcuts.FirstOrDefault(sc => sc.Slot == 1); if (shortcut == null) { m_character.Character.SendMessage("No spell on slot 1"); return; } var spell = shortcut.GetSpell(); if (spell == null) { m_character.Character.SendMessage("No spell on slot 1"); return; } if (m_character.IsInSpellRange(nearestMonster.Cell, spell.LevelTemplate)) { m_character.CastSpell(spell, nearestMonster.Cell); MoveFar(); m_character.PassTurn(); } else { MoveNear(nearestMonster, (int)(m_character.Cell.ManhattanDistanceTo(nearestMonster.Cell) - m_character.GetRealSpellRange(spell.LevelTemplate))); // wait until the movement ends if (m_stopMovingDelegate != null) { Bot.Character.Fighter.StopMoving -= m_stopMovingDelegate; m_stopMovingDelegate = null; } m_stopMovingDelegate = (sender, behavior, canceled, refused) => OnStopMoving(spell, nearestMonster, canceled, refused); Bot.Character.Fighter.StopMoving += m_stopMovingDelegate; } }