Esempio n. 1
0
        public BattleReportStreamEntry GetBattleReportStreamEntry(long replayId)
        {
            var random = new Random();

            var attackerReward = random.Next(10, 35);

            Attacker.Score += attackerReward;

            return(new BattleReportStreamEntry
            {
                MajorVersion = 5,
                Build = 2,
                ContentVersion = 4,
                CreationDateTime = DateTime.Now,
                IsRevengeUsed = true, // Revenge is not supported atm
                SenderAvatarId = Defender.AccountId,
                SenderName = Defender.Name,
                SenderLevel = Defender.ExpLevel,
                SenderLeagueType = LogicUtils.GetLeagueByScore(Defender.Score),
                ShardId = 0,
                ReplayId = replayId,
                BattleLogJson = JsonConvert.SerializeObject(new BattleLog
                {
                    // Here we use random values
                    Loot = new[] { new[] { 3000001, random.Next(1000, 100000) }, new[] { 3000002, random.Next(1000, 100000) } },
                    Units = new[] { new[] { 4000000, random.Next(10, 50) }, new[] { 4000001, random.Next(10, 50) }, new[] { 4000002, random.Next(10, 50) }, new[] { 4000003, random.Next(10, 50) }, new[] { 4000004, random.Next(10, 50) }, new[] { 4000005, random.Next(10, 50) } },
                    Levels = new int[0][],
                    Spells = new int[0][],

                    Stats = new BattleLogStats
                    {
                        TownHallDestroyed = true,
                        DestructionPercentage = random.Next(0, 100),
                        AllianceName = "RetroClash",
                        AllianceUsed = false,
                        AttackerScore = attackerReward,
                        BattleEnded = true,
                        BattleTime = 1,
                        DefenderScore = random.Next(-30, -15),
                        HomeId = Utils.GetHighLow(Defender.AccountId),
                        OriginalScore = Attacker.Score
                    }
                })
            });
        }
Esempio n. 2
0
        public async Task AvatarRankingEntry(MemoryStream stream)
        {
            await stream.WriteInt(ExpLevel);                           // Exp Level

            await stream.WriteInt(0);                                  // Attack Win Count

            await stream.WriteInt(0);                                  // Attack Lose Count

            await stream.WriteInt(0);                                  // Defense Win Count

            await stream.WriteInt(0);                                  // Defense Lose Count

            await stream.WriteInt(LogicUtils.GetLeagueByScore(Score)); // League Type

            await stream.WriteString(Language);                        // Country

            await stream.WriteLong(AccountId);                         // Home Id

            if (AllianceId > 0)
            {
                var alliance = await Resources.AllianceCache.GetAlliance(AllianceId);

                if (alliance != null)
                {
                    stream.WriteBool(true);
                    await stream.WriteLong(AllianceId);      // Clan Id

                    await stream.WriteString(alliance.Name); // Clan Name

                    await stream.WriteInt(alliance.Badge);   // Badge
                }
                else
                {
                    AllianceId = 0;
                    stream.WriteBool(false);
                }
            }
            else
            {
                stream.WriteBool(false);
            }
        }
Esempio n. 3
0
        public ReplayProfile GetReplayProfile(bool attacker)
        {
            var profile = new ReplayProfile
            {
                Name          = Name,
                Score         = Score,
                League        = LogicUtils.GetLeagueByScore(Score),
                TownHallLevel = LogicGameObjectManager.GetTownHallLevel(),
                CastleLevel   = 1,
                CastleTotal   = 15,
                CastleUsed    = 0,
                BadgeId       = 13000000,
                AllianceName  = "RetroClash"
            };

            foreach (var troop in Units.Troops)
            {
                if (troop.Count > 0)
                {
                    profile.Units.Add(new ReplayUnitItem
                    {
                        Id  = troop.Id,
                        Cnt = troop.Count
                    });
                }
            }

            foreach (var spell in Units.Spells)
            {
                if (spell.Count > 0)
                {
                    profile.Spells.Add(new ReplayUnitItem
                    {
                        Id  = spell.Id,
                        Cnt = spell.Count
                    });
                }
            }

            foreach (var unit in Units.Troops)
            {
                profile.UnitUpgrades.Add(new ReplayUnitItem
                {
                    Id  = unit.Id,
                    Cnt = unit.Level
                });
            }

            foreach (var spell in Units.Spells)
            {
                profile.SpellUpgrades.Add(new ReplayUnitItem
                {
                    Id  = spell.Id,
                    Cnt = spell.Level
                });
            }

            if (attacker)
            {
                foreach (var resource in ResourcesManager)
                {
                    profile.Resources.Add(new ReplayUnitItem
                    {
                        Id  = resource.Id,
                        Cnt = resource.Value
                    });
                }
            }

            foreach (var hero in HeroManager)
            {
                profile.HeroStates.Add(new ReplayUnitItem
                {
                    Id  = hero.Id,
                    Cnt = hero.State
                });
            }

            foreach (var hero in HeroManager)
            {
                profile.HeroHealth.Add(new ReplayUnitItem
                {
                    Id  = hero.Id,
                    Cnt = hero.Health
                });
            }

            foreach (var hero in HeroManager)
            {
                profile.HeroUpgrade.Add(new ReplayUnitItem
                {
                    Id  = hero.Id,
                    Cnt = hero.Level
                });
            }

            return(profile);
        }
Esempio n. 4
0
        public async Task LogicClientAvatar(MemoryStream stream)
        {
            await stream.WriteInt(0);

            await stream.WriteLong(AccountId); // Account Id

            await stream.WriteLong(AccountId); // Home Id

            if (AllianceId > 0)
            {
                var alliance = await Resources.AllianceCache.GetAlliance(AllianceId);

                if (alliance != null)
                {
                    stream.WriteBool(true);
                    await stream.WriteLong(AllianceId);      // Alliance Id

                    await stream.WriteString(alliance.Name); // Alliance Name

                    await stream.WriteInt(alliance.Badge);   // Alliance Badge

                    await stream.WriteInt(alliance.Members.Find(x => x.AccountId == AccountId)
                                          .Role); // Alliance Role

                    stream.WriteByte(1);
                    await stream.WriteLong(AllianceId); // Alliance Id

                    stream.WriteByte(1);
                    await stream.WriteLong(AllianceId); // Alliance Id
                }
                else
                {
                    stream.WriteBool(false);
                }
            }
            else
            {
                stream.WriteBool(false);
            }

            await stream.WriteInt(LogicUtils.GetLeagueByScore(Score));              // League Type

            await stream.WriteInt(0);                                               // Alliance Castle Level

            await stream.WriteInt(10);                                              // Alliance Total Capacity

            await stream.WriteInt(0);                                               // Alliance Used Capacity

            await stream.WriteInt(LogicGameObjectManager?.GetTownHallLevel() ?? 1); // Townhall Level

            await stream.WriteString(Name);                                         // Name

            await stream.WriteString(null);                                         // Facebook Id

            await stream.WriteInt(ExpLevel);                                        // Exp Level

            await stream.WriteInt(ExpPoints);                                       // Exp Points

            await stream.WriteInt(Diamonds);                                        // Diamonts

            await stream.WriteInt(0);                                               // Current Diamonts

            await stream.WriteInt(0);                                               // Free Diamonts

            await stream.WriteInt(0);                                               // Unknown

            await stream.WriteInt(Score);                                           // Score

            await stream.WriteInt(0);                                               // Attack Win Count

            await stream.WriteInt(0);                                               // Attack Lose Count

            await stream.WriteInt(0);                                               // Defense Win Count

            await stream.WriteInt(0);                                               // Defense Lose Count

            stream.WriteBool(false);                                                // Name Set By User
            await stream.WriteInt(0);

            // Resource Caps
            await stream.WriteInt(0);

            // Resources
            await stream.WriteInt(ResourcesManager.Count);

            foreach (var resource in ResourcesManager)
            {
                await stream.WriteInt(resource.Id);

                await stream.WriteInt(resource.Value);
            }

            // Troops
            await stream.WriteInt(Units.Troops.Count);

            foreach (var troop in Units.Troops)
            {
                await stream.WriteInt(troop.Id);

                await stream.WriteInt(troop.Count);
            }

            // Spells
            await stream.WriteInt(Units.Spells.Count);

            foreach (var spell in Units.Spells)
            {
                await stream.WriteInt(spell.Id);

                await stream.WriteInt(spell.Count);
            }

            // Troop Levels
            await stream.WriteInt(Units.Troops.Count);

            foreach (var troop in Units.Troops)
            {
                await stream.WriteInt(troop.Id);

                await stream.WriteInt(troop.Level);
            }

            // Spell Levels
            await stream.WriteInt(Units.Spells.Count);

            foreach (var spell in Units.Spells)
            {
                await stream.WriteInt(spell.Id);

                await stream.WriteInt(spell.Level);
            }

            // Hero Levels
            await stream.WriteInt(HeroManager.Count);

            foreach (var hero in HeroManager)
            {
                await stream.WriteInt(hero.Id);

                await stream.WriteInt(hero.Level);
            }

            // Hero Health
            await stream.WriteInt(HeroManager.Count);

            foreach (var hero in HeroManager)
            {
                await stream.WriteInt(hero.Id);

                await stream.WriteInt(hero.Health);
            }

            // Hero State
            await stream.WriteInt(HeroManager.Count);

            foreach (var hero in HeroManager)
            {
                await stream.WriteInt(hero.Id);

                await stream.WriteInt(hero.State);
            }

            // Alliance Units
            await stream.WriteInt(0);

            // Tutorials
            await stream.WriteInt(TutorialSteps);

            for (var index = 21000000; index < 21000000 + TutorialSteps; index++)
            {
                await stream.WriteInt(index);
            }

            // Achievements
            await stream.WriteInt(Achievements.Count);

            foreach (var achievement in Achievements)
            {
                await stream.WriteInt(achievement.Id);
            }

            // Achievement Progress
            await stream.WriteInt(Achievements.Count);

            foreach (var achievement in Achievements)
            {
                await stream.WriteInt(achievement.Id);

                await stream.WriteInt(achievement.Data);
            }

            // Npc Map Progress
            await stream.WriteInt(50);

            for (var index = 17000000; index < 17000050; index++)
            {
                await stream.WriteInt(index);

                await stream.WriteInt(3);
            }

            await stream.WriteInt(0); // Npc Looted Gold DataSlot

            await stream.WriteInt(0); // Npc Looted Elixir DataSlot
        }