/// <inheritdoc /> public void RemovePlayer(int characterId) { Character player; if (Players.TryRemove(characterId, out player)) { _logger.LogDebug($"Player {characterId} left game world"); TradeManagers.TryRemove(characterId, out var tradeManager); tradeManager.Dispose(); PartyManagers.TryRemove(characterId, out var partyManager); partyManager.Dispose(); DuelManagers.TryRemove(characterId, out var duelManager); duelManager.Dispose(); player.Client.OnPacketArrived -= Client_OnPacketArrived; var map = Maps[player.MapId]; map.UnloadPlayer(player); player.Dispose(); } else { // 0 means, that connection with client was lost, when he was in character selection screen. if (characterId != 0) { _logger.LogError($"Couldn't remove player {characterId} from game world"); } } }
/// <inheritdoc /> public void RemovePlayer(int characterId) { Character player; if (Players.TryRemove(characterId, out player)) { _logger.LogDebug($"Player {characterId} left game world"); TradeManagers.TryRemove(characterId, out var tradeManager); tradeManager.Dispose(); PartyManagers.TryRemove(characterId, out var partyManager); partyManager.Dispose(); DuelManagers.TryRemove(characterId, out var duelManager); duelManager.Dispose(); player.Client.OnPacketArrived -= Client_OnPacketArrived; IMap map = null; // Try find player's map. if (Maps.ContainsKey(player.MapId)) { map = Maps[player.MapId]; } else if (player.Party != null && PartyMaps.ContainsKey(player.Party.Id)) { map = PartyMaps[player.Party.Id]; } else if (PartyMaps.ContainsKey(player.PreviousPartyId)) { map = PartyMaps[player.PreviousPartyId]; } if (map is null) { _logger.LogError($"Couldn't find character's {characterId} map {player.MapId}."); } else { map.UnloadPlayer(player); } player.Dispose(); } else { // 0 means, that connection with client was lost, when he was in character selection screen. if (characterId != 0) { _logger.LogError($"Couldn't remove player {characterId} from game world"); } } }