/// <summary>Обновляем состояние магии</summary> private void GetMagic(MouseState state) { //Магия равна нулю выходим if (_SelectedMagic == null) return; //Магия запущена убираем все выделения if (_SelectedMagic.Finished) { if (_SelectedMagic.Targets.Contains(TargetType.town)) foreach (Building build in _Buildings) { build.DrawEnemySelector = false; build.DrawOurSelector = false; } if (_SelectedMagic.Targets.Contains(TargetType.hero)) foreach (Player player in _Players) { player.DrawOurSelector = false; player.DrawEnemySelector = false; } _Players[0].CurrentMagic -= _SelectedMagic.Cost; if (_TargetBuilding != null) { if (_TargetBuilding.CurrentResource > _SelectedMagic.Effect) _TargetBuilding.CurrentResource -= _SelectedMagic.Effect; else { _TargetBuilding.CurrentResource = _TargetBuilding.MaxResource; _Players[0].AddBuilding(_TargetBuilding); } } else if (_TargetPlayer != null) { _TargetPlayer.CurrentMagic -= _SelectedMagic.Effect; } _TargetBuilding = null; _TargetPlayer = null; _SelectedMagic = null; return; } if (_SelectedMagic.Executed|_Wait) return; //Агрессивная магия if (_SelectedMagic.Type == MagicType.agressive) { //Удар по городу if (_SelectedMagic.Targets.Contains(TargetType.town)) { foreach (Building castle in _Buildings) if (castle.Contains(state.X, state.Y) && castle.Owner != _Players[0]) { castle.DrawEnemySelector = true; _TargetBuilding = castle; _TargetPlayer = null; } else castle.DrawEnemySelector = false; } //Удар по герою if (_SelectedMagic.Targets.Contains(TargetType.hero)) { foreach (Player player in _Players) if (player.Contains(state.X, state.Y) && player != _Players[0] && !player.Dead) { player.DrawEnemySelector = true; _TargetPlayer = player; _TargetBuilding = null; } else player.DrawEnemySelector = false; } } //Мирная магия else { if (_SelectedMagic.Targets.Contains(TargetType.town)) { foreach (Building castle in _Buildings) if (castle.Contains(state.X, state.Y) && castle.Owner == _Players[0]) { castle.DrawOurSelector = true; _TargetBuilding = castle; } else castle.DrawOurSelector = false; } if (_SelectedMagic.Targets.Contains(TargetType.hero)) { if (_Players[0].Contains(state.X, state.Y)) { _Players[0].DrawOurSelector = true; _TargetPlayer = _Players[0]; } else _Players[0].DrawOurSelector = false; } } }
/// <summary>Убираем выделение со всех магий кроме current</summary> /// <param name="current">Выделенная магия.</param> private void Unselect(Magic current) { foreach (Magic magic in _Magics.MagicList) if (magic != current) magic.Selected = false; }
/// <summary>Меняем активную магию</summary> private void ChangeSelectedMagic(MouseState state) { foreach (Magic magic in _Magics.MagicList) if (magic._Back.Contains(state.X, state.Y) && magic.Active&&magic.Cost<=_Players[0].CurrentMagic) { magic.Selected = true; _SelectedMagic = magic; _SelectedMagic.Finished = false; Unselect(magic); break; } }