namespace Supercell.Laser.Logic.Home.Structures { using System; using System.Collections.Generic; using System.Text.Json.Serialization; using Supercell.Laser.Logic.Data; using Supercell.Laser.Logic.Helper; using Supercell.Laser.Titan.DataStream; using Supercell.Laser.Titan.Math; public class Hero { public static readonly int[] UpgradePowerPointsTable = new int[] { 20, 50, 100, 180, 310, 520, 860, 1410, 2300, 2300 + 1440 }; public static readonly int[] UpgradeCostTable = new int[] { 20, 35, 75, 140, 290, 480, 800, 1250, 1875, 2800 }; public int CharacterId; public int CardId; public int Trophies; public int HighestTrophies; public int PowerPoints; public int PowerLevel; public bool HasStarpower; public bool IsNew; public int SelectedSkinId; public Dictionary Emotes; public int SelectedStarPowerId; public int SelectedGadgetId; [JsonIgnore] public CharacterData CharacterData => DataTables.Get(DataType.Character).GetDataByGlobalId(CharacterId); [JsonIgnore] public CardData CardData => DataTables.Get(DataType.Card).GetDataByGlobalId(CardId); public Hero(int characterId, int cardId) { CharacterId = characterId; Emotes = new Dictionary(); try { CharacterData characterData = DataTables.Get(DataType.Character)?.GetDataByGlobalId(characterId); if (characterData != null) { CardData gadget = GetDefaultMetaForHero(5); if (gadget != null) SelectedGadgetId = gadget.GetInstanceId(); CardData starPower = GetDefaultMetaForHero(4); if (starPower != null) SelectedStarPowerId = starPower.GetInstanceId(); CardData unlockCard = DataTables.GetUnlockCardFor(CharacterData); if (unlockCard != null) CardId = unlockCard.GetGlobalId(); var defaultEmote = GetDefaultEmoteForCharacter(characterData.Name); if (defaultEmote != null) { Emotes[1] = defaultEmote.GetInstanceId(); } else { Emotes[1] = 0; } Emotes[2] = 137 - 3; Emotes[3] = 148 - 3; } PowerLevel = 0; SelectedSkinId = 0; } catch (Exception) { PowerLevel = 0; SelectedGadgetId = 0; SelectedStarPowerId = 0; Emotes = new Dictionary { { 1, 0 }, { 2, 134 }, { 3, 145 } }; } } public EmoteData GetDefaultEmoteForCharacter(string characterName) { if (string.IsNullOrEmpty(characterName)) return null; var emoteTable = DataTables.Get(DataType.Emote); if (emoteTable == null) return null; foreach (var data in emoteTable.GetDatas()) { if (data is EmoteData emoteData && emoteData.Character == characterName && emoteData.EmoteType == 0) { return emoteData; } } return null; } public CardData GetDefaultMetaForHero(int MetaType) { foreach (CardData carddata in DataTables.Get(DataType.Card).GetDatas()) { if (carddata.Target == CharacterData.Name && carddata.MetaType == MetaType) { return carddata; } } return null; } public void AddTrophies(int trophies) { Trophies += trophies; HighestTrophies = LogicMath.Max(HighestTrophies, Trophies); } public void Encode(ByteStream stream) { ByteStreamHelper.WriteDataReference(stream, CharacterData); ByteStreamHelper.WriteDataReference(stream, null); stream.WriteVInt(Trophies); stream.WriteVInt(HighestTrophies); stream.WriteVInt(PowerLevel + 1 + (HasStarpower ? 1 : 0)); } } }