private Character GetCharacterAsync(int accountId, int characterIndex) { var character = Global.FindCharacterByIndexAndAccountId(accountId, characterIndex); if (character == null) { // Quando não encontrado, procura no banco de dados. var database = new DBGameDatabase(); var dbError = database.Open(); if (dbError.Number > 0) { Global.WriteLog(LogType.System, $"Failed to get character from database Account Id {accountId}", LogColor.Red); Global.WriteLog(LogType.System, $"Error Number: {dbError.Number}", LogColor.Red); Global.WriteLog(LogType.System, $"Error Message: {dbError.Message}", LogColor.Red); } else { character = database.GetCharacter(accountId, characterIndex); character.Spell = database.GetCharacterSpells(character.CharacterId); character.Inventory = database.GetCharacterItems(character.CharacterId, InventoryType.Inventory); character.Equipment = database.GetCharacterItems(character.CharacterId, InventoryType.Equipment); character.Warehouse = database.GetCharacterItems(character.CharacterId, InventoryType.Warehouse); character.Hotbar = database.GetCharacterHotbar(character.CharacterId); character.Title = database.GetCharacterTitle(character.CharacterId); character.Variable = database.GetCharacterVariable(character.CharacterId); character.SpellBuff = database.GetCharacterSpellBuff(character.CharacterId); character.Currency = database.GetCharacterCurrency(character.CharacterId); character.Craft = database.GetCharacterCraft(character.CharacterId); character.Achievement = database.GetCharacterAchievements(character.CharacterId); database.Close(); // Adiciona o personagem quando válido. Global.Characters.Add(character); } } return(character); }