/// <summary> /// Handler invoked whenever a battle is created for any entities on the current map. /// <para>Checks if the WorldEntity being managed is in the newly created battle.</para> /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnCreatedBattle(object sender, CreatedBattleEventArgs args) { if (args.AiEntitiesInBattle.Contains(_entity.Id)) { if (_battleManager != null) { throw new Exception($"A battle already exists for ai WorldEntity of id {_entity.Id} on map id {_mapManager.Map.Id}!"); } _isMovementDisabled = true; _battleManager = args.BattleManager; _battleManager.EndOfBattleEvent += OnEndOfBattle; } }
/// <summary> /// Handler invoked whenever any battle is created on the map the managed WorldEntity is on. /// <para>If the WorldEntity is in the newly created battle, initiates battle for this player.</para> /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnCreatedBattle(object sender, CreatedBattleEventArgs args) { // Call initiated battle if (args.PlayersInBattle.TryGetValue(PlayerId, out Guid actual)) { lock (_lock) { if (_battleManager != null) { throw new Exception($"A new battle was created for {PlayerId} while player was in another battle!"); } _battleManager = args.BattleManager; _battleManager.EndOfBattleEvent += OnEndOfBattle; _stateManager.SetPlayerInCombat(PlayerId); } Task.Run(() => OnBattleInitiated?.Invoke(this, args)); } }