private void invokeEndOfTurnEvent() { EndOfTurnEvent endOfTurn = new EndOfTurnEvent() { player = currentPlayerTurn }; endOfTurn.FireEvent(); }
/// <summary> /// Applies end of turn effects, then ends the current turn. Calls StartTurn after. /// </summary> private void EndTurn() { IEnumerable <DelayedAbility> endOfTurnAbilities = null; var affectedEntities = new List <IReadOnlyCombatEntity>(); var activatedAbilities = new List <IReadOnlyAbility>(); lock (_key) { // Apply end of turn DelayedAbilities if (_battle.IsDefenderTurn) { endOfTurnAbilities = _battle.DefenderDelayedAbilities .Where(abi => abi.TurnsLeft == 0 && !abi.BaseAbility.ActivatesBeforeTurnStart) .ToList(); } else { endOfTurnAbilities = _battle.AttackerDelayedAbilities .Where(abi => abi.TurnsLeft == 0 && !abi.BaseAbility.ActivatesBeforeTurnStart) .ToList(); } if (endOfTurnAbilities != null && endOfTurnAbilities.Count() > 0) { foreach (var ability in endOfTurnAbilities) { var entities = _abilityManager.PerformDelayedAbility(ability); foreach (var entity in entities) { if (!affectedEntities.Contains(entity)) { affectedEntities.Add(entity); } } activatedAbilities.Add(ability.BaseAbility); } } _battle.ActionsLeftPerFormation.Clear(); } // EndOfTurnEvent called here to give extra time to send message to clients Task.Run(() => EndOfTurnEvent?.Invoke(this, new EndOfTurnEventArgs { DelayedAbilities = activatedAbilities, AffectedEntities = affectedEntities, ParticipantIds = _participantIds })); lock (_key) { if (_numOfAttackers <= 0 || _numOfDefenders <= 0) { EndBattle(); } else { // Call start turn after a delay var dueDate = DateTime.Now.AddSeconds(GameplayConstants.EndOfTurnDelayInSeconds); _timer.Start(); } } }