namespace Supercell.Laser.Logic.Avatar { using System; using System.Collections.Generic; using System.Text.Json.Serialization; using Supercell.Laser.Logic.Home.Structures; using Supercell.Laser.Logic.Home; using Supercell.Laser.Logic.Friends; using Supercell.Laser.Logic.Helper; using Supercell.Laser.Logic.Data; using Supercell.Laser.Titan.DataStream; public enum AllianceRole { None = 0, Member = 1, Leader = 2, Elder = 3, CoLeader = 4 } public class ClientAvatar { public long AccountId; public string PassToken; public string Name; public bool NameSetByUser; public int TutorialsCompletedCount = 2; [JsonIgnore] public string AllianceName; [JsonIgnore] public DateTime BattleStartTime; [JsonIgnore] public HomeMode HomeMode; public int Gold; public int Diamonds; public List Heroes; public List PlayerMaps; public int TrioWins; public int EventWins; public int DuoWins; public int SoloWins; public int Tokens; public int StarTokens; public int StarPoints; public bool IsDev; public bool IsPremium; public int PremiumLevel; public long AllianceId; public AllianceRole AllianceRole; public DateTime LastOnline; public List Friends; public bool Banned; public bool DoNotDisturb; [JsonIgnore] public int PlayerStatus; [JsonIgnore] public long TeamId; [JsonIgnore] public long BattleId; [JsonIgnore] public long UdpSessionId; [JsonIgnore] public int TeamIndex; [JsonIgnore] public int OwnIndex; public List UnlockedMeta; public List SelectedMeta; public bool IsCommunityBanned; public bool IsCommunityWarned; public int HighestTrophies; // /lobbyinfo on/off — по дефолту включено (false = информация в лобби показывается) public bool LobbyInfoDisabled; public int RollsSinceGoodDrop; public double ForcedDrops; public bool ShouldRedirect; public long RedirectId; public string Password; [JsonIgnore] public int RankedId; public int RankedRank = 0; public int Trophies { get { int result = 0; foreach (Hero hero in Heroes.ToArray()) { result += hero.Trophies; } return result; } } /*public int HighestTrophies { get { int result = 0; foreach (Hero hero in Heroes.ToArray()) { result += hero.HighestTrophies; } return result; } }*/ public void AddTrophies(int t) { HighestTrophies = Math.Max(HighestTrophies, Trophies + t); } public int GetUnlockedBrawlersCountWithRarity(string rarity) { return Heroes.Count(x => x.CardData.Rarity == rarity); } public void ResetTrophies() { foreach (Hero hero in Heroes.ToArray()) { hero.Trophies = 0; hero.HighestTrophies = 0; } } public int GetUnlockedHeroesCount() { return Heroes.Count; } public void UnlockHero(int characterId, int cardId) { Hero heroEntry = new Hero(characterId, cardId); Heroes.Add(heroEntry); } public bool HasHero(int characterId) { return Heroes.Find(x => x.CharacterId == characterId) != null; } public Hero GetHero(int characterId) { return Heroes.Find(x => x.CharacterId == characterId); } public bool UseDiamonds(int count) { if (count > Diamonds) return false; Diamonds -= count; return true; } public bool UseGold(int count) { if (count > Gold) return false; Gold -= count; return true; } public bool UseStarPoints(int count) { if (count > StarPoints) return false; StarPoints -= count; return true; } public void AddDiamonds(int count) { Diamonds += count; } public void AddGold(int count) { Gold += count; } public bool UseTokens(int count) { if (count > Tokens) return false; Tokens -= count; return true; } public void AddTokens(int count) { HomeMode.Home.BrawlPassTokens += count; } public bool UseStarTokens(int count) { if (count > StarTokens) return false; StarTokens -= count; return true; } public void AddStarTokens(int count) { StarTokens += count; } public void SetEmoteForBrawler(int characterId, int slot, int pin) { Hero heroEntry = GetHero(characterId); heroEntry.Emotes[slot] = pin; } /* public EmoteData GetDefaultEmoteForCharacter(string Character, string Type) { foreach (EmoteData emoteData in DataTables.Get(DataType.Emote).GetDatas()) { if (emoteData.Character == Character && emoteData.EmoteType == Type) return emoteData; } return null; }*/ public void Refresh() { for (int i = 0; ; i++) { CharacterData character = DataTables.Get(16) .GetDataWithId(i); if (character == null) break; if (character.Disabled && !character.LockedForChronos) { RemoveHero(character.GetGlobalId()); continue; } if (!character.IsHero()) break; } } public void RemoveHero(int characterId) { Hero hero = GetHero(characterId); if (hero != null) Heroes.Remove(hero); } public ClientAvatar() { Name = "Brawler"; Gold = 0; Diamonds = 0; Heroes = new List(); IsDev = false; IsPremium = false; AllianceRole = AllianceRole.None; AllianceId = -1; LastOnline = DateTime.UtcNow; Friends = new List(); UnlockedMeta = new List(); SelectedMeta = new List(); BattleStartTime = new(); if (HighestTrophies == 0 && Trophies != 0) { HighestTrophies = Trophies; } ; } public void SkipTutorial() { TutorialsCompletedCount = 2; } public bool IsTutorialState() { return TutorialsCompletedCount < 2; } public Friend GetRequestFriendById(long id) { return Friends.Find(friend => friend.AccountId == id && friend.FriendState != 4); } public Friend GetAcceptedFriendById(long id) { return Friends.Find(friend => friend.AccountId == id && friend.FriendState == 4); } public Friend GetFriendById(long id) { return Friends.Find(friend => friend.AccountId == id); } public int Checksum { get { ChecksumEncoder encoder = new ChecksumEncoder(); Encode(encoder); return encoder.GetCheckSum(); } } public void Encode(ChecksumEncoder Stream) { Stream.WriteVLong(AccountId); Stream.WriteVLong(AccountId); Stream.WriteVLong(AccountId); Stream.WriteString(Name); Stream.WriteBoolean(NameSetByUser); Stream.WriteInt(-1); Stream.WriteVInt(8); { Stream.WriteVInt(4 + Heroes.Count); { ByteStreamHelper.WriteDataReference(Stream, 5000001); Stream.WriteVInt(Tokens); ByteStreamHelper.WriteDataReference(Stream, 5000008); Stream.WriteVInt(Gold); ByteStreamHelper.WriteDataReference(Stream, 5000009); Stream.WriteVInt(StarTokens); ByteStreamHelper.WriteDataReference(Stream, 5000010); Stream.WriteVInt(StarPoints); foreach (Hero hero in Heroes) { ByteStreamHelper.WriteDataReference(Stream, hero.CardData); Stream.WriteVInt(1); } } Stream.WriteVInt(Heroes.Count); foreach (Hero hero in Heroes) { ByteStreamHelper.WriteDataReference(Stream, hero.CharacterData); Stream.WriteVInt(hero.Trophies); } Stream.WriteVInt(Heroes.Count); foreach (Hero hero in Heroes) { ByteStreamHelper.WriteDataReference(Stream, hero.CharacterData); Stream.WriteVInt(hero.HighestTrophies); } Stream.WriteVInt(0); Stream.WriteVInt(Heroes.Count); foreach (Hero hero in Heroes) { ByteStreamHelper.WriteDataReference(Stream, hero.CharacterData); Stream.WriteVInt(hero.PowerPoints); } Stream.WriteVInt(Heroes.Count); foreach (Hero hero in Heroes) { ByteStreamHelper.WriteDataReference(Stream, hero.CharacterData); Stream.WriteVInt(hero.PowerLevel); } Stream.WriteVInt(UnlockedMeta.Count); foreach (int s in UnlockedMeta) { ByteStreamHelper.WriteDataReference(Stream, s); Stream.WriteVInt(SelectedMeta.Contains(s) ? 2 : 1); } Stream.WriteVInt(0); } Stream.WriteVInt(Diamonds); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(0); Stream.WriteVInt(TutorialsCompletedCount); } } }