Пример #1
0
        /// <summary>
        /// Reads the <see cref="AvatarRankingEntryMessageComponent"/> from the specified <see cref="MessageReader"/>.
        /// </summary>
        /// <param name="reader">
        /// <see cref="MessageReader"/> that will be used to read the <see cref="AvatarRankingEntryMessageComponent"/>.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="reader"/> is null.</exception>
        public override void ReadMessageComponent(MessageReader reader)
        {
            ThrowIfReaderNull(reader);

            UserId       = reader.ReadInt64();
            UserName     = reader.ReadString();
            Rank         = reader.ReadInt32();
            Trophies     = reader.ReadInt32();
            PreviousRank = reader.ReadInt32();
            ExpLevels    = reader.ReadInt32();
            AttacksWon   = reader.ReadInt32();
            AttacksLost  = reader.ReadInt32();
            DefensesWon  = reader.ReadInt32();
            DefensesLost = reader.ReadInt32();

            Unknown1 = reader.ReadInt32();

            CountryCode = reader.ReadString();
            HomeId      = reader.ReadInt64();

            Unknown2 = reader.ReadInt32();
            Unknown3 = reader.ReadInt32();

            if (reader.ReadBoolean())
            {
                Clan = new ClanMessageComponent
                {
                    Id       = reader.ReadInt64(),
                    Name     = reader.ReadString(),
                    Unknown2 = reader.ReadInt32()
                };
            }
        }
        /// <summary>
        /// Reads the <see cref="AvatarMessageComponent"/> from the specified <see cref="MessageReader"/>.
        /// </summary>
        /// <param name="reader">
        /// <see cref="MessageReader"/> that will be used to read the <see cref="AvatarMessageComponent"/>.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="reader"/> is null.</exception>
        public override void ReadMessageComponent(MessageReader reader)
        {
            ThrowIfReaderNull(reader);

            UserId = reader.ReadInt64();
            HomeId = reader.ReadInt64();
            if (reader.ReadBoolean())
            {
                ClanData          = new ClanMessageComponent();
                ClanData.Id       = reader.ReadInt64();
                ClanData.Name     = reader.ReadString();
                ClanData.Badge    = reader.ReadInt32();
                ClanData.Role     = (ClanMemberRole)reader.ReadInt32();
                ClanData.Level    = reader.ReadInt32();
                ClanData.Unknown1 = reader.ReadByte(); // Clan war?
                if (ClanData.Unknown1 == 1)
                {
                    ClanData.Unknown2 = reader.ReadInt64(); // Clan war ID?
                }
            }

            LegendaryTrophy    = reader.ReadInt32();
            BestSeasonEnabled  = reader.ReadInt32();
            BestSeasonMonth    = reader.ReadInt32();
            BestSeasonYear     = reader.ReadInt32();
            BestSeasonPosition = reader.ReadInt32();
            BestSeasonTrophies = reader.ReadInt32();
            LastSeasonEnabled  = reader.ReadInt32();
            LastSeasonMonth    = reader.ReadInt32();
            LastSeasonYear     = reader.ReadInt32();
            LastSeasonPosition = reader.ReadInt32();
            LastSeasonTrophies = reader.ReadInt32();

            LeagueLevel                 = reader.ReadInt32();
            AllianceCastleLevel         = reader.ReadInt32();
            AllianceCastleTotalCapacity = reader.ReadInt32();
            AllianceCastleUsedCapacity  = reader.ReadInt32();

            Unknown13 = reader.ReadInt32(); // 0 = 8.x.x
            Unknown14 = reader.ReadInt32(); // -1 = 8.x.x

            TownHallLevel = reader.ReadInt32();
            Name          = reader.ReadString();

            Unknown15 = reader.ReadInt32(); // -1, Facebook ID

            ExpLevels = reader.ReadInt32();
            ExpPoints = reader.ReadInt32();
            Gems      = reader.ReadInt32(); // Scrambled when not own avatar data.
            FreeGems  = reader.ReadInt32(); // Scrambled when not own avatar data.

            Unknown16 = reader.ReadInt32(); // 1200 // Scrambled when not own avatar data.
            Unknown17 = reader.ReadInt32(); // 60 // Scrambled when not own avatar data.

            Trophies     = reader.ReadInt32();
            AttacksWon   = reader.ReadInt32();
            AttacksLost  = reader.ReadInt32(); // Scrambled when not own avatar data.
            DefensesWon  = reader.ReadInt32();
            DefensesLost = reader.ReadInt32(); // Scrambled when not own avatar data.

            Unknown18 = reader.ReadInt32();
            Unknown19 = reader.ReadInt32();
            Unknown20 = reader.ReadInt32();

            // 8.511.4
            Unknown29 = reader.ReadInt32();

            Unknown21 = reader.ReadByte();  // 1, might be a bool
            Unknown22 = reader.ReadInt64(); // 946720861000

            IsNamed = reader.ReadBoolean();

            Unknown23 = reader.ReadInt32();
            Unknown24 = reader.ReadInt32(); // Scrambled when not own avatar data.
            Unknown25 = reader.ReadInt32();
            Unknown26 = reader.ReadInt32(); // 1
            Unknown27 = reader.ReadInt32(); // 0 = 8.x.x
            Unknown28 = reader.ReadInt32(); // 0 = 8.x.x

            // 8.551.4
            Unknown30 = reader.ReadByte();

            ResourcesCapacity   = reader.ReadSlotCollection <ResourceCapacitySlot>();
            ResourcesAmount     = reader.ReadSlotCollection <ResourceAmountSlot>();
            Units               = reader.ReadSlotCollection <UnitSlot>();
            Spells              = reader.ReadSlotCollection <SpellSlot>();
            UnitUpgrades        = reader.ReadSlotCollection <UnitUpgradeSlot>();
            SpellUpgrades       = reader.ReadSlotCollection <SpellUpgradeSlot>();
            HeroUpgrades        = reader.ReadSlotCollection <HeroUpgradeSlot>();
            HeroHealths         = reader.ReadSlotCollection <HeroHealthSlot>();
            HeroStates          = reader.ReadSlotCollection <HeroStateSlot>();
            AllianceUnits       = reader.ReadSlotCollection <AllianceUnitSlot>();
            TutorialProgress    = reader.ReadSlotCollection <TutorialProgressSlot>();
            Achievements        = reader.ReadSlotCollection <AchievementSlot>();
            AchievementProgress = reader.ReadSlotCollection <AchievementProgessSlot>();
            NpcStars            = reader.ReadSlotCollection <NpcStarSlot>();
            NpcGold             = reader.ReadSlotCollection <NpcGoldSlot>();
            NpcElixir           = reader.ReadSlotCollection <NpcElixirSlot>();

            Unknown31 = reader.ReadInt32();

            UnknownSlot1 = reader.ReadSlotCollection <UnknownSlot>();
            UnknownSlot2 = reader.ReadSlotCollection <UnknownSlot>();
            UnknownSlot3 = reader.ReadSlotCollection <UnknownSlot>();

            // 8.551.4
            UnknownSlot4 = reader.ReadSlotCollection <UnknownSlot>();
            UnknownSlot5 = reader.ReadSlotCollection <UnknownSlot>();
            UnknownSlot6 = reader.ReadSlotCollection <UnknownSlot>();
            UnknownSlot7 = reader.ReadSlotCollection <UnitSlot>();

            // 8.709.2
            // Could be an int32 instead.
            UnknownSlot8 = reader.ReadSlotCollection <UnknownSlot>();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AvatarMessageComponent"/> class from
        /// the specified <see cref="Level"/>.
        /// </summary>
        /// <param name="level"><see cref="Level"/> from which the data will be set.</param>
        /// <exception cref="ArgumentNullException"><paramref name="level"/> is null.</exception>
        public AvatarMessageComponent(Level level)
        {
            if (level == null)
            {
                throw new ArgumentNullException(nameof(level));
            }

            var avatar = level.Avatar;

            UserId = avatar.Id;
            HomeId = avatar.Id;

            if (avatar.Alliance != null)
            {
                var member = avatar.Alliance.Get(avatar.Id);
                Debug.Assert(member != null);
                if (member == null)
                {
                    throw new InvalidOperationException($"Unable to find ClanMember {avatar.Id} in the Alliance {avatar.Alliance.Id}.");
                }

                ClanData = new ClanMessageComponent
                {
                    Id    = avatar.Alliance.Id,
                    Name  = avatar.Alliance.Name,
                    Badge = avatar.Alliance.Badge,
                    Role  = member.Role,
                    Level = avatar.Alliance.ExpLevels
                };
            }
            else
            {
                AllianceCastleLevel = -1;
            }

            LeagueLevel = avatar.League;
            if (level.Village.TownHall == null)
            {
                level.Logs.Log("TownHall reference was null; using TownHallLevel 5.");
                TownHallLevel = 5;
            }
            else
            {
                TownHallLevel = level.Village.TownHall.UpgradeLevel;
            }
            Name = avatar.Name;

            //Unknown13 = -1;
            //Unknown14 = -1;
            Unknown15 = -1;

            ExpPoints = avatar.ExpPoints;
            ExpLevels = avatar.ExpLevels;
            Gems      = avatar.Gems;
            FreeGems  = avatar.FreeGems;

            Unknown16 = 1200;
            Unknown17 = 60;

            Trophies = avatar.Trophies;

            Unknown21 = 1;
            Unknown22 = 946720861000;
            //Unknown22 = 4294967516;
            //Unknown23 = -169129983;

            IsNamed = avatar.IsNamed;

            Unknown26 = 1;
            //Unknown27 = 1;

            ResourcesAmount     = avatar.ResourcesAmount;
            ResourcesCapacity   = avatar.ResourcesCapacity;
            Units               = avatar.Units;
            Spells              = avatar.Spells;
            UnitUpgrades        = avatar.UnitUpgrades;
            SpellUpgrades       = avatar.SpellUpgrades;
            HeroUpgrades        = avatar.HeroUpgrades;
            HeroHealths         = avatar.HeroHealths;
            HeroStates          = avatar.HeroStates;
            TutorialProgress    = avatar.TutorialProgess;
            Achievements        = avatar.Achievements;
            AchievementProgress = avatar.AchievementProgress;
            NpcStars            = avatar.NpcStars;
            NpcGold             = avatar.NpcGold;
            NpcElixir           = avatar.NpcElixir;

            UnknownSlot1 = new SlotCollection <UnknownSlot>();
            UnknownSlot2 = new SlotCollection <UnknownSlot>();
            UnknownSlot3 = new SlotCollection <UnknownSlot>();
            UnknownSlot4 = new SlotCollection <UnknownSlot>();
            UnknownSlot5 = new SlotCollection <UnknownSlot>();
            UnknownSlot6 = new SlotCollection <UnknownSlot>();
            UnknownSlot7 = new SlotCollection <UnitSlot>();
        }