/// <summary> /// Handler invoked at the end of a battle; Will remove state restrictions. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void OnEndOfBattle(object sender, EndOfBattleEventArgs args) { lock (_lock) { _battleManager.EndOfBattleEvent -= OnEndOfBattle; _battleManager = null; _stateManager.SetPlayerFree(PlayerId); } }
/// <summary> /// Signal to the client that the battle has ended along with whether the attackers or defenders won. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void OnEndOfBattle(object sender, EndOfBattleEventArgs args) { var tasks = new List <Task> { _battleHubContext.Clients.Users(args.ParticipantIds).SendAsync("endBattle", args.DidAttackersWin), Task.Run(() => OnDestroy?.Invoke(this, new EventArgs())) }; await Task.WhenAll(tasks); }
/// <summary> /// Invoked at the end of a battle; Removes the IBattleManager instance from the list of BattleManagers. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnEndOfBattle(object sender, EndOfBattleEventArgs args) { var manager = sender as IBattleManager; manager.EndOfBattleEvent -= OnEndOfBattle; foreach (var playerId in args.ParticipantIds) { _battleManagers.Remove(playerId); } foreach (var entityId in args.AiWorldEntityIds) { _aiBattleManagers.Remove(entityId); } _uniqueBattleManagers.Remove(manager); }
/// <summary> /// Handler invoked at the end of a battle. If all CombatEntities in the formation this AiEntityManager controls /// are dead, queues this manager for destruction. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnEndOfBattle(object sender, EndOfBattleEventArgs args) { var areAnyEntitiesLiving = _entity.ActiveFormation.Positions .AnyTwoD(entity => entity != null && entity.Resources.CurrentHealth > 0); if (!areAnyEntitiesLiving) { _mapManager.RemoveEntity(_entity); _mapBattleManager.OnCreatedBattle -= OnCreatedBattle; RemovedFromMap?.Invoke(this, new RemovedFromMapEventArgs { SpawnData = _spawnEntityData }); } _isMovementDisabled = !areAnyEntitiesLiving; _battleManager.EndOfBattleEvent -= OnEndOfBattle; _battleManager = null; }