namespace Supercell.Laser.Logic.Avatar { using Newtonsoft.Json; using Supercell.Laser.Titan.DataStream; using Supercell.Laser.Logic.Friends; using Supercell.Laser.Logic.Helper; using Supercell.Laser.Logic.Home; using Supercell.Laser.Logic.Home.Structures; public enum AllianceRole { None = 0, Member = 1, Leader = 2, Elder = 3, CoLeader = 4 } [JsonObject(MemberSerialization.OptIn)] public class ClientAvatar { [JsonProperty] public long AccountId; [JsonProperty] public string PassToken; [JsonProperty] public long AccountIdRedirect; [JsonProperty] public string Name; [JsonProperty] public bool NameSetByUser; [JsonProperty] public int TutorialsCompletedCount = 2; [JsonIgnore] public HomeMode HomeMode; [JsonProperty] public int Gold; [JsonProperty] public int Diamonds; [JsonProperty] public int StarPoints; [JsonProperty] public List Heroes; [JsonProperty] public int TrioWins; [JsonProperty] public int DuoWins; [JsonProperty] public int SoloWins; [JsonProperty] public int Tokens; [JsonProperty] public int StarTokens; [JsonProperty] public bool IsDev; [JsonProperty] public bool IsPremium; [JsonProperty] public long AllianceId; [JsonProperty] public AllianceRole AllianceRole; [JsonProperty] public DateTime LastOnline; [JsonProperty] public List Friends; [JsonProperty] public bool Banned; [JsonProperty] public DateTime? BanEndTime; [JsonProperty] public string BanReason; [JsonIgnore] public int PlayerStatus; [JsonIgnore] public long TeamId; [JsonIgnore] public long BattleId; [JsonIgnore] public long UdpSessionId; [JsonIgnore] public int TeamIndex; [JsonIgnore] public int OwnIndex; /// Вызывается при любом изменении баланса: (тип, дельта, причина, балансДо, балансПосле) [JsonIgnore] public Action OnBalanceChanged; [JsonProperty] public List Starpowers; [JsonProperty] public List SelectedStarpowers; [JsonProperty] public bool DoNotDisturb; [JsonProperty] public bool DisabledTeamChat; [JsonProperty] public int RollsSinceGoodDrop; [JsonProperty] public double ForcedDrops; [JsonProperty] public string SupportedCreator; [JsonProperty] public string Region; [JsonProperty] public int CreatorLevel; [JsonProperty] public int PremiumLevel; [JsonProperty] public List OldBans = new(); [JsonProperty] public int BannedReason; [JsonProperty] public int[] BanTime = new int[2]; public void PlusTrophies(long count) { foreach (Hero hero in Heroes) hero.Trophies += (int)count; } 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 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 bool IsTemporarilyBanned() { return BanEndTime.HasValue && BanEndTime.Value > DateTime.UtcNow; } public bool HasActiveBan() { return Banned || IsTemporarilyBanned(); } public void ApplyPermanentBan(string reason = null) { Banned = true; BanEndTime = null; BanReason = reason; } public void ApplyTemporaryBan(DateTime expiresAtUtc, string reason = null) { Banned = false; BanEndTime = expiresAtUtc; BanReason = reason; } public void ClearBan() { Banned = false; BanEndTime = null; BanReason = null; } public bool TryExpireBan() { if (Banned || !BanEndTime.HasValue || BanEndTime.Value > DateTime.UtcNow) { return false; } ClearBan(); return true; } public Hero GetHero(int characterId) { return Heroes.Find(x => x.CharacterId == characterId); } public bool UseDiamonds(int count) { if (count > Diamonds) return false; int before = Diamonds; Diamonds -= count; OnBalanceChanged?.Invoke("gems", -count, "spend", before, Diamonds); return true; } public bool UseGold(int count) { if (count > Gold) return false; int before = Gold; Gold -= count; OnBalanceChanged?.Invoke("gold", -count, "spend", before, Gold); return true; } public bool UseStarPoints(int count) { if (count > StarPoints) return false; int before = StarPoints; StarPoints -= count; OnBalanceChanged?.Invoke("starpoints", -count, "spend", before, StarPoints); return true; } public void AddTrophies(int count, int brawlerID) { foreach (Hero hero in Heroes) { if (hero.CharacterId == brawlerID) { hero.Trophies += count; hero.HighestTrophies += count; } else { hero.Trophies += 0; hero.HighestTrophies += 0; } } } public void AddDiamonds(int count) { int before = Diamonds; Diamonds += count; OnBalanceChanged?.Invoke("gems", count, "gain", before, Diamonds); } public void AddGold(int count) { int before = Gold; Gold += count; OnBalanceChanged?.Invoke("gold", count, "gain", before, Gold); } public void AddStarPoints(int count) { int before = StarPoints; StarPoints += count; OnBalanceChanged?.Invoke("starpoints", count, "gain", before, StarPoints); } public void AddDiamondsCmd(string count) { if (count == "30") Diamonds += 30; if (count == "80") Diamonds += 80; if (count == "170") Diamonds += 170; if (count == "360") Diamonds += 360; if (count == "950") Diamonds += 950; if (count == "2000") Diamonds += 2000; } 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 ClientAvatar() { Name = "Brawler"; Gold = 100; Diamonds = 0; Heroes = new List(); IsDev = false; IsPremium = false; AllianceRole = AllianceRole.None; AllianceId = -1; LastOnline = DateTime.UtcNow; Friends = new List(); Starpowers = new List(); SelectedStarpowers = new List(); } 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); { //govno kod btw 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(Starpowers.Count); foreach (int s in Starpowers) { ByteStreamHelper.WriteDataReference(Stream, s); Stream.WriteVInt(SelectedStarpowers.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); /* потом мб туториал сделаем */ } } }