Exemple #1
0
        public static async Task <LogicArrayList <AllianceHeaderEntry> > GetJoinableAlliancesList(int score, int duelScore)
        {
            LogicArrayList <AllianceHeaderEntry> allianceList = new LogicArrayList <AllianceHeaderEntry>();
            IQueryResult <JObject> result =
                await ServerSearch.AllianceDatabase.ExecuteCommand <JObject>(SearchManager.QUERY_JOINABLE_ALLIANCES_LIST.Replace("%AVATAR_SCORE%", score.ToString())
                                                                             .Replace("%AVATAR_DUEL_SCORE%", duelScore.ToString()));

            if (result.Success)
            {
                allianceList.EnsureCapacity(result.Rows.Count);
                result.Rows.ForEach(jsonObject => { allianceList.Add(SearchManager.LoadAllianceHeaderEntry(jsonObject)); });
            }

            return(allianceList);
        }
Exemple #2
0
        public static async Task <LogicArrayList <AllianceHeaderEntry> > SearchAlliances(SearchAlliancesMessage searchAlliancesMessage, LogicClientAvatar playerAvatar)
        {
            LogicArrayList <AllianceHeaderEntry> allianceList = new LogicArrayList <AllianceHeaderEntry>();
            StringBuilder builder = new StringBuilder();

            builder.Append("SELECT ");
            builder.Append(SearchManager.QUERY_ALLIANCES_LIST_SELECT);
            builder.Append(" FROM `%BUCKET%` WHERE meta().id LIKE '%KEY_PREFIX%%' AND (");

            string searchString = searchAlliancesMessage.GetSearchString();

            if (!string.IsNullOrEmpty(searchString))
            {
                if (searchString.Length >= 16)
                {
                    searchString = searchString.Substring(0, 15);
                }

                if (searchString.StartsWith(HashTagCodeGenerator.CONVERSION_TAG))
                {
                    LogicLong allianceId = HashTagCodeGenerator.m_instance.ToId(searchString.Trim().ToUpperInvariant());

                    if (allianceId != null)
                    {
                        builder.Append(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH);
                        builder.Append(" == ");
                        builder.Append(allianceId.GetHigherInt().ToString());
                        builder.Append(" AND ");
                        builder.Append(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW);
                        builder.Append(" == ");
                        builder.Append(allianceId.GetLowerInt().ToString());
                        builder.Append(" OR ");
                    }
                }

                builder.Append("LOWER(alliance_name) LIKE '%");
                builder.Append(searchString.ToLowerInvariant());
                builder.Append("%' AND ");
            }

            builder.Append("member_count BETWEEN ");
            builder.Append(searchAlliancesMessage.GetMinimumMembers().ToString());
            builder.Append(" AND ");
            builder.Append(searchAlliancesMessage.GetMaximumMembers().ToString());

            if (searchAlliancesMessage.GetWarFrequency() != 0)
            {
                builder.Append(" AND war_freq == ");
                builder.Append(searchAlliancesMessage.GetWarFrequency().ToString());
            }

            if (searchAlliancesMessage.GetOrigin() != null)
            {
                builder.Append(" AND origin == ");
                builder.Append(searchAlliancesMessage.GetOrigin().GetGlobalID().ToString());
            }

            if (searchAlliancesMessage.GetRequiredScore() != 0)
            {
                builder.Append(" AND score >= ");
                builder.Append(searchAlliancesMessage.GetRequiredScore().ToString());
            }

            if (searchAlliancesMessage.GetRequiredDuelScore() != 0)
            {
                builder.Append(" AND duel_score >= ");
                builder.Append(searchAlliancesMessage.GetRequiredDuelScore().ToString());
            }

            if (searchAlliancesMessage.GetMinimumExpLevel() != 0)
            {
                builder.Append(" AND xp_level >= ");
                builder.Append(searchAlliancesMessage.GetMinimumExpLevel().ToString());
            }

            if (searchAlliancesMessage.IsJoinableOnly())
            {
                builder.Append(" AND required_score <= ");
                builder.Append(playerAvatar.GetScore().ToString());
                builder.Append(" AND required_duel_score <= ");
                builder.Append(playerAvatar.GetDuelScore().ToString());
            }

            builder.AppendLine(") ORDER BY score DESC LIMIT 200");

            IQueryResult <JObject> result = await ServerSearch.AllianceDatabase.ExecuteCommand <JObject>(builder.ToString());

            if (result.Success)
            {
                allianceList.EnsureCapacity(result.Rows.Count);
                result.Rows.ForEach(jsonObject => { allianceList.Add(SearchManager.LoadAllianceHeaderEntry(jsonObject)); });
            }

            return(allianceList);
        }