Exemple #1
0
        private async Task UpdateAvatarRankingList()
        {
            Dictionary <long, AvatarRankingEntry> prevAvatarRankingDictionary = this.m_avatarRankingList;
            Dictionary <long, AvatarRankingEntry> avatarRankingDictionary     = new Dictionary <long, AvatarRankingEntry>(SeasonDocument.RANKING_LIST_SIZE);
            LogicArrayList <AvatarRankingEntry>   avatarRankingList           = this.AvatarRankingList;

            avatarRankingList.Clear();

            IViewResult <JObject> result =
                await ServerScoring.GameDatabase.ExecuteCommand <JObject>(new ViewQuery().From("players", "leaderboard_0").Desc().Limit(SeasonDocument.RANKING_LIST_SIZE));

            if (result.Success)
            {
                int orderCounter = 0;

                foreach (JObject value in result.Values)
                {
                    AvatarRankingEntry avatarRankingEntry = new AvatarRankingEntry();
                    LogicLong          id = new LogicLong((int)value["id_hi"], (int)value["id_lo"]);

                    avatarRankingEntry.SetId(id);
                    avatarRankingEntry.SetName((string)value["name"]);
                    avatarRankingEntry.SetScore((int)value["score"]);
                    avatarRankingEntry.SetExpLevel((int)value["xp_level"]);
                    avatarRankingEntry.SetAttackWinCount((int)value["attackWin"]);
                    avatarRankingEntry.SetAttackLoseCount((int)value["attackLose"]);
                    avatarRankingEntry.SetDefenseWinCount((int)value["defenseWin"]);
                    avatarRankingEntry.SetDefenseLoseCount((int)value["defenseLose"]);
                    avatarRankingEntry.SetLeagueType((int)value["leagueType"]);
                    avatarRankingEntry.SetCountry((string)value["country"]);
                    avatarRankingEntry.SetHomeId(id);

                    if (value.TryGetValue("allianceId_High", out JToken allianceIdHigh))
                    {
                        avatarRankingEntry.SetAllianceId(new LogicLong((int)allianceIdHigh, (int)value["allianceId_Low"]));
                        avatarRankingEntry.SetAllianceName((string)value["allianceName"]);
                        avatarRankingEntry.SetAllianceBadgeId((int)value["badgeId"]);
                    }

                    avatarRankingEntry.SetOrder(++orderCounter);

                    if (prevAvatarRankingDictionary != null && prevAvatarRankingDictionary.TryGetValue(id, out AvatarRankingEntry prevEntry))
                    {
                        avatarRankingEntry.SetPreviousOrder(prevEntry.GetPreviousOrder());
                    }

                    avatarRankingDictionary.Add(id, avatarRankingEntry);
                    avatarRankingList.Add(avatarRankingEntry);
                }

                this.m_avatarRankingList = avatarRankingDictionary;
            }
            else
            {
                Logging.Warning("ScoringSeason.updateAvatarRankingList: view error: " + result.Error);
            }
        }
Exemple #2
0
        private async Task UpdateAllianceRankingList(int villageType)
        {
            Dictionary <long, AllianceRankingEntry> prevAllianceRankingDictionary = this.m_allianceRankingList[villageType];
            Dictionary <long, AllianceRankingEntry> allianceRankingDictionary     = new Dictionary <long, AllianceRankingEntry>(SeasonDocument.RANKING_LIST_SIZE);
            LogicArrayList <AllianceRankingEntry>   allianceRankingList           = this.AllianceRankingList[villageType];

            allianceRankingList.Clear();

            IViewResult <JObject> result =
                await ServerScoring.AllianceDatabase.ExecuteCommand <JObject>(new ViewQuery().From("alliances", "leaderboard_" + villageType).Desc().Limit(SeasonDocument.RANKING_LIST_SIZE));

            if (result.Success)
            {
                int orderCounter = 0;

                foreach (JObject value in result.Values)
                {
                    AllianceRankingEntry allianceRankingEntry = new AllianceRankingEntry();
                    LogicLong            id = new LogicLong((int)value["id_hi"], (int)value["id_lo"]);

                    allianceRankingEntry.SetId(id);
                    allianceRankingEntry.SetName((string)value["name"]);
                    allianceRankingEntry.SetScore((int)value["score"]);
                    allianceRankingEntry.SetAllianceBadgeId((int)value["badge_id"]);
                    allianceRankingEntry.SetAllianceLevel((int)value["xp_level"]);
                    allianceRankingEntry.SetMemberCount((int)value["member_count"]);

                    if (value.TryGetValue("origin", out JToken originToken))
                    {
                        allianceRankingEntry.SetOriginData(LogicDataTables.GetDataById((int)originToken));
                    }

                    allianceRankingEntry.SetOrder(++orderCounter);

                    if (prevAllianceRankingDictionary != null && prevAllianceRankingDictionary.TryGetValue(id, out AllianceRankingEntry prevEntry))
                    {
                        allianceRankingEntry.SetPreviousOrder(prevEntry.GetPreviousOrder());
                    }

                    allianceRankingDictionary.Add(id, allianceRankingEntry);
                    allianceRankingList.Add(allianceRankingEntry);
                }

                this.m_allianceRankingList[villageType] = allianceRankingDictionary;
            }
            else
            {
                Logging.Warning("ScoringSeason.updateAllianceRankingList: view error: " + result.Error);
            }
        }