/// <summary> /// Attempts to join the battle of the provided allied WorldEntities. /// </summary> /// <param name="allies">A list of WorldEntities this AiEntityManager will try to join the battle of.</param> /// <returns>Returns true if joining a battle was successful.</returns> private bool TryJoinBattle(List <WorldEntity> allies) { int i = 0; bool battleSuccess = false; while (i < allies.Count && !battleSuccess) { if (_mapBattleManager.TryJoinBattle(allies[i], _entity, out IBattleManager battleManager)) { battleSuccess = true; _battleManager = battleManager; _battleManager.EndOfBattleEvent += OnEndOfBattle; _isMovementDisabled = true; } i++; } return(battleSuccess); }
/// <summary> /// Attempts to join the battle of the stored target WorldEntity. /// </summary> private void JoinBattle() { lock (_lock) { // Player hasn't created a formation or is in combat, prevent from joining a battle if (_stateManager.GetPlayerState(PlayerId) != PlayerStateConstants.Free) { return; } if (_contactsQueuedForBattle == null || _contactsQueuedForBattle.Count() <= 0) { return; } if (_battleManager != null) { throw new Exception($"Player {PlayerId} tried to join a battle while another is in progress!"); } var hostEntity = _contactsQueuedForBattle.FirstOrDefault(entity => { return(entity.Id == _targetEntityId && entity.OwnerGuid.ToString() == _targetOwnerId); }); if (_mapBattleManager.TryJoinBattle(hostEntity, Entity, out IBattleManager battleManager)) { _battleManager = battleManager; } } if (_battleManager != null) { _battleManager.EndOfBattleEvent += OnEndOfBattle; _stateManager.SetPlayerInCombat(PlayerId); Task.Run(() => OnJoinBattleSuccess?.Invoke(this, new JoinBattleSuccessEventArgs { BattleManager = _battleManager })); } }