private void ProcessTurns() { var buttons = _battleGUI.AbilityButtons .Where(c => c.Value.IsClicked) .ToDictionary(c => c.Key, v => v.Value); string ability = null; var actor = _actors.Where(c => c.State == Actor.States.Alive).ToList()[_currentActor]; actor.ShowTurnBar = true; if (buttons.Count > 0) { var button = buttons.First(); ability = button.Key; actor.ActionResult.State = Engine.ActionStates.Waiting; } var actionResult = actor.GetAction(ability); if (actionResult == null) { return; } if (actionResult.State == Engine.ActionStates.WaitingForTarget) { if (actor is Player) { _targets = actor.GetTargets(Enemies.Cast <Actor>()); } else if (actor is Enemy) { _targets = actor.GetTargets(Players.Cast <Actor>()); } else { throw new Exception("Unexpected type: " + actor.ToString()); } } if (actionResult.State == Engine.ActionStates.Running) { actionResult.Action(); } if (actionResult.State != Engine.ActionStates.Finished) { return; } // Since the attack is finished, we need to remove health from whoever has been hit foreach (var target in _targets) { var damage = GetDamage(actor, target); target.CurrentHealth -= damage; target.ActorModel.BattleStats.DamageReceived += damage; actor.ActorModel.BattleStats.DamageDealt += damage; if (target.CurrentHealth <= 0) { target.State = Actor.States.Dying; actor.ActorModel.BattleStats.FinalBlows += 1; if (_actors.IndexOf(target) < _currentActor) { _currentActor--; } } } var validActors = _actors.Where(c => c.State == Actor.States.Alive).ToList(); _currentActor = (_currentActor + 1) % validActors.Count; _battleGUI.SetAbilities(validActors[_currentActor].ActorModel); _battleGUI.SetTurns(validActors.Select(c => c.ActorModel).Skip(_currentActor).ToList()); // As the move is over, there is no longer a target _targets = new List <Actor>(); }