public static void RemovePlayerFromGame(Net.GS.GameClient gameClient) { if (gameClient == null || gameClient.Game == null) { return; } var gameId = gameClient.Game.GameId; if (!Games.ContainsKey(gameId)) { return; } var game = Games[gameId]; if (!game.Players.ContainsKey(gameClient)) { return; } Player p = null; if (!game.Players.TryRemove(gameClient, out p)) { Logger.Error("Can't remove player ({0}) from game with id: {1}", gameClient.Player.Toon.HeroNameField.Value, gameId); } if (p != null) { //TODO: Move this inside player OnLeave event var toon = p.Toon; toon.TimePlayed += DateTimeExtensions.ToUnixTime(DateTime.UtcNow) - toon.LoginTime; toon.GoldAmount = p.Inventory.GetGoldAmount(); // Remove Player From World if (p.InGameClient != null) { p.World.Leave(p); } // Generate Update for Client gameClient.BnetClient.Account.CurrentGameAccount.NotifyUpdate(); //save hero to db after player data was updated in toon toon.Items = p.Inventory.GetInventoryGrid().Items; toon.SaveToDB(); } if (game.Players.Count == 0) { Games.Remove(gameId); // we should be also disposing it /raist. } }
public static void RemovePlayerFromGame(Net.GS.GameClient gameClient) { if (gameClient == null || gameClient.Game == null) { return; } var gameId = gameClient.Game.GameId; if (!Games.ContainsKey(gameId)) { return; } var game = Games[gameId]; if (!game.Players.ContainsKey(gameClient)) { return; } Player p = null; if (!game.Players.TryRemove(gameClient, out p)) { Logger.Error("Can't remove player ({0}) from game with id: {1}", gameClient.Player.Toon.Name, gameId); } if (p != null) { var toon = p.Toon; toon.TimePlayed += DateTimeExtensions.ToUnixTime(DateTime.UtcNow) - toon.LoginTime; toon.SaveToDB(); // Remove Player From World if (p.InGameClient != null) { p.World.Leave(p); } } if (game.Players.Count == 0) { Games.Remove(gameId); // we should be also disposing it /raist. } }
public static void RemovePlayerFromGame(Net.GS.GameClient gameClient) { if (gameClient == null || gameClient.Game == null) { return; } var gameId = gameClient.Game.GameId; if (!Games.ContainsKey(gameId)) { return; } var game = Games[gameId]; if (!game.Players.ContainsKey(gameClient)) { return; } Player p = null; if (!game.Players.TryRemove(gameClient, out p)) { Logger.Error("Can't remove player ({0}) from game with id: {1}", gameClient.Player.Toon.Name, gameId); } if (p != null) { //TODO: Move this inside player OnLeave event var toon = p.Toon; var gameAccount = toon.DBToon.DBGameAccount; // For update account profile [Necrosummon] toon.TimePlayed += DateTimeExtensions.ToUnixTime(DateTime.UtcNow) - toon.LoginTime; toon.ExperienceNext = p.Attributes[GameAttribute.Experience_Next]; if (toon.Class == ToonClass.Barbarian) { gameAccount.BarbarianPlayedTime += DateTimeExtensions.ToUnixTime(DateTime.UtcNow) - toon.LoginTime; if (gameAccount.BarbarianHighestLevel < toon.Level) // Updates the Highest Level of this class if is more high when you logout [Necrosummon] { gameAccount.BarbarianHighestLevel = toon.Level; } } else if (toon.Class == ToonClass.DemonHunter) { gameAccount.DemonHunterPlayedTime += DateTimeExtensions.ToUnixTime(DateTime.UtcNow) - toon.LoginTime; if (gameAccount.DemonHunterHighestLevel < toon.Level) { gameAccount.DemonHunterHighestLevel = toon.Level; } } else if (toon.Class == ToonClass.Monk) { gameAccount.MonkPlayedTime += DateTimeExtensions.ToUnixTime(DateTime.UtcNow) - toon.LoginTime; if (gameAccount.MonkHighestLevel < toon.Level) { gameAccount.MonkHighestLevel = toon.Level; } } else if (toon.Class == ToonClass.WitchDoctor) { gameAccount.WitchDoctorPlayedTime += DateTimeExtensions.ToUnixTime(DateTime.UtcNow) - toon.LoginTime; if (gameAccount.WitchDoctorHighestLevel < toon.Level) { gameAccount.WitchDoctorHighestLevel = toon.Level; } } else if (toon.Class == ToonClass.Wizard) { gameAccount.WizardPlayedTime += DateTimeExtensions.ToUnixTime(DateTime.UtcNow) - toon.LoginTime; if (gameAccount.WizardHighestLevel < toon.Level) { gameAccount.WizardHighestLevel = toon.Level; } } // Hardcore Highest Level Account Profile Info if (toon.Hardcore && gameAccount.HighestHardcoreLevel < toon.Level) { gameAccount.HighestHardcoreLevel = toon.Level; } // Remove Player From World if (p.InGameClient != null) { p.World.Leave(p); } // Generate Update for Client gameClient.BnetClient.Account.CurrentGameAccount.NotifyUpdate(); //save hero to db after player data was updated in toon ToonManager.SaveToDB(toon); } if (game.Players.Count == 0) { Games.Remove(gameId); // we should be also disposing it /raist. } }