Beispiel #1
0
        public Player[] _NotCached_FindPlayersMatching(string _PartOfName, WowRealm _Realm, string _Race, string _Class, string _Level, PlayersMatchingSortBy _SortBy)
        {
            int lowerLevel = int.MinValue;
            int upperLevel = int.MaxValue;

            if (_Level != "All")
            {
                try
                {
                    string[] levelsStr = _Level.SplitVF("to");
                    if (levelsStr.Length >= 2)
                    {
                        lowerLevel = int.Parse(levelsStr[0]);
                        upperLevel = int.Parse(levelsStr[1]);
                    }
                }
                catch (Exception)
                { }
            }
            PlayerRace[] races = null;
            if (_Race != "All")
            {
                try
                {
                    if (_Race == "Horde")
                    {
                        races = new PlayerRace[] { PlayerRace.Orc, PlayerRace.Undead, PlayerRace.Troll, PlayerRace.Tauren, PlayerRace.Blood_Elf }
                    }
                    ;
                    else if (_Race == "Alliance")
                    {
                        races = new PlayerRace[] { PlayerRace.Human, PlayerRace.Night_Elf, PlayerRace.Gnome, PlayerRace.Dwarf, PlayerRace.Draenei }
                    }
                    ;
                    else
                    {
                        PlayerRace currRace = StaticValues.ConvertRace(_Race);
                        if (currRace != PlayerRace.Unknown)
                        {
                            races = new PlayerRace[] { currRace }
                        }
                        ;
                    }
                }
                catch (Exception)
                { }
            }
            PlayerClass[] classes = null;
            if (_Class != "All")
            {
                var currClass = StaticValues.ConvertClass(_Class);
                if (currClass != PlayerClass.Unknown)
                {
                    classes = new PlayerClass[] { currClass }
                }
                ;
            }

            List <Player> playerMatchList = new List <Player>(100000);

            foreach (var _RealmDB in DatabaseAccess.GetRealmDBs(this))
            {
                if (_Realm != WowRealm.All && _Realm != _RealmDB.Key)
                {
                    continue;
                }

                foreach (var player in _RealmDB.Value.Players)
                {
                    if (races != null && races.Contains(player.Value.Character.Race) == false)
                    {
                        continue;
                    }
                    if (classes != null && classes.Contains(player.Value.Character.Class) == false)
                    {
                        continue;
                    }
                    if (player.Value.Character.Level < lowerLevel || player.Value.Character.Level > upperLevel)
                    {
                        continue;
                    }
                    if (player.Value.Character.Race == PlayerRace.Unknown || player.Value.Character.Class == PlayerClass.Unknown)
                    {
                        continue;
                    }
                    if (_PartOfName == "" || player.Key.ToLower().Contains(_PartOfName) == true)
                    {
                        playerMatchList.Add(player.Value);
                    }
                }
            }
            if (_SortBy == PlayersMatchingSortBy.SortBy_NameSearch)
            {
                if (_PartOfName.Length >= 2)
                {
                    string nameFormattedSearchStr = char.ToUpper(_PartOfName[0]) + _PartOfName.Substring(1).ToLower();
                    return(playerMatchList.OrderByDescending(_Player => {
                        var sortValue = _Player.LastSeen;
                        if (_Player.Name.StartsWith(nameFormattedSearchStr))
                        {
                            sortValue = sortValue.AddYears(2);
                            if (_Player.Name == nameFormattedSearchStr)
                            {
                                sortValue = sortValue.AddYears(10);
                            }
                        }
                        return sortValue;
                    }).ToArray());
                }
                else
                {
                    return(playerMatchList.OrderBy(_Player => _Player.Name).ToArray());
                }
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_Rank)
            {
                return(playerMatchList.OrderByDescending(_Player => _Player.GetRankTotal()).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_Name)
            {
                return(playerMatchList.OrderBy(_Player => _Player.Name).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_Guild)
            {
                return(playerMatchList.OrderBy(_Player => _Player.Guild.GuildName).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_Level)
            {
                return(playerMatchList.OrderByDescending(_Player => _Player.Character.Level).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_RaceClass)
            {
                return(playerMatchList.OrderBy(_Player => ((int)_Player.Character.Race) * 100 + (int)_Player.Character.Class).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_TotalHKs)
            {
                return(playerMatchList.OrderByDescending(_Player => _Player.Honor.LifetimeHK).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_Honor)
            {
                return(playerMatchList.OrderByDescending(_Player => _Player.Honor.LastWeekHonor).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_HKs)
            {
                return(playerMatchList.OrderByDescending(_Player => _Player.Honor.LastWeekHK).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_Server)
            {
                return(playerMatchList.OrderByDescending(_Player => _Player.Realm).ToArray());
            }
            else if (_SortBy == PlayersMatchingSortBy.SortBy_Seen)
            {
                return(playerMatchList.OrderByDescending(_Player => _Player.LastSeen).ToArray());
            }
            else
            {
                return(playerMatchList.ToArray());
            }
        }
Beispiel #2
0
        public Player[] FindPlayersMatching(string _PartOfName, string _Realm, string _Race, string _Class, string _Level, string _SortBy = "NameSearch")
        {
            //FIX PARAMS
            _PartOfName = _PartOfName.ToLower();

            WowRealm realm = StaticValues.ConvertRealm(_Realm);

            if (realm == WowRealm.Unknown)
            {
                realm = WowRealm.All;
            }

            int lowerLevel = int.MinValue;
            int upperLevel = int.MaxValue;

            if (_Level != "All")
            {
                try
                {
                    string[] levelsStr = _Level.SplitVF("to");
                    if (levelsStr.Length >= 2)
                    {
                        lowerLevel = int.Parse(levelsStr[0]);
                        upperLevel = int.Parse(levelsStr[1]);
                    }
                }
                catch (Exception)
                { }
            }

            if (lowerLevel < 1 || upperLevel > 60 || upperLevel < lowerLevel)
            {
                _Level = "All";
            }
            else
            {
                _Level = lowerLevel + "to" + upperLevel;
            }

            PlayerRace[] races = null;
            if (_Race != "All")
            {
                try
                {
                    if (_Race == "Horde")
                    {
                        races = new PlayerRace[] { PlayerRace.Orc, PlayerRace.Undead, PlayerRace.Troll, PlayerRace.Tauren, PlayerRace.Blood_Elf }
                    }
                    ;
                    else if (_Race == "Alliance")
                    {
                        races = new PlayerRace[] { PlayerRace.Human, PlayerRace.Night_Elf, PlayerRace.Gnome, PlayerRace.Dwarf, PlayerRace.Draenei }
                    }
                    ;
                    else
                    {
                        PlayerRace currRace = StaticValues.ConvertRace(_Race);
                        if (currRace != PlayerRace.Unknown)
                        {
                            races = new PlayerRace[] { currRace };
                            _Race = currRace.ToString();
                        }
                    }
                }
                catch (Exception)
                { }
            }
            if (races == null)
            {
                _Race = "All";
            }

            PlayerClass[] classes = null;
            if (_Class != "All")
            {
                var currClass = StaticValues.ConvertClass(_Class);
                if (currClass != PlayerClass.Unknown)
                {
                    classes = new PlayerClass[] { currClass };
                    _Class  = currClass.ToString();
                }
            }

            if (classes == null)
            {
                _Class = "All";
            }

            PlayersMatchingSortBy sortBy = PlayersMatchingSortBy.SortBy_NameSearch;

            if (Enum.TryParse("SortBy_" + _SortBy, true, out sortBy) == false)
            {
                sortBy = PlayersMatchingSortBy.SortBy_NameSearch;
            }
            //FIX PARAMS

            if (_PartOfName.Length >= 3 || (_Race != "All" && _Class != "All"))
            {
                return(_NotCached_FindPlayersMatching(_PartOfName, realm, _Race, _Class, _Level, sortBy));
            }
            else
            {
                return(Hidden.ApplicationInstance.Instance.m_ThreadSafeCache.Get("FindPlayersMatching", _NotCached_FindPlayersMatching, _PartOfName, realm, _Race, _Class, _Level, sortBy));
            }
        }