Пример #1
0
        public int CompareTo(object obj)
        {
            if (!(obj is RiotVersion))
            {
                return(-1);
            }

            if (ReferenceEquals(this, obj))
            {
                return(0);
            }

            RiotVersion other = obj as RiotVersion;
            int         diff  = Major.CompareTo(other.Major);

            if (diff != 0 || Minor == null)
            {
                return(diff);
            }

            diff = Minor.CompareTo(other.Minor);
            if (diff != 0 || Patch == null)
            {
                return(diff);
            }

            diff = Patch.CompareTo(other.Patch);
            if (diff != 0 || SubPatch == null)
            {
                return(diff);
            }

            diff = SubPatch.CompareTo(other.SubPatch);
            return(diff);
        }
Пример #2
0
 /// <summary>
 /// Test whether this version matches another version, to a specified tolerance.
 /// </summary>
 public bool IsSamePatch(RiotVersion other, MatchTolerance tolerance = MatchTolerance.Minor)
 {
     if (Major != other.Major)
     {
         return(false);
     }
     if (tolerance == MatchTolerance.Major)
     {
         return(true);
     }
     if (Minor != other.Minor)
     {
         return(false);
     }
     if (tolerance == MatchTolerance.Minor)
     {
         return(true);
     }
     if (Patch != other.Patch)
     {
         return(false);
     }
     if (tolerance == MatchTolerance.Patch)
     {
         return(false);
     }
     return(SubPatch != other.SubPatch);
 }
Пример #3
0
        internal RealmStaticData(StaticRiotApi riotStaticApi, Realm realm, Region region)
        {
            Realm   = realm;
            Version = new RiotVersion(Realm.V);
            Region  = region;

            Champions      = riotStaticApi.GetChampions(region, ChampionData.all);
            Items          = riotStaticApi.GetItems(region, ItemData.all);
            SummonerSpells = riotStaticApi.GetSummonerSpells(region, SummonerSpellData.all);
        }
Пример #4
0
        internal RealmStaticData(StaticRiotApi riotStaticApi, Realm realm, Region region)
        {
            Realm = realm;
            Version = new RiotVersion(Realm.V);
            Region = region;

            Champions = riotStaticApi.GetChampions(region, ChampionData.all);
            Items = riotStaticApi.GetItems(region, ItemData.all);
            SummonerSpells = riotStaticApi.GetSummonerSpells(region, SummonerSpellData.all);
        }
Пример #5
0
        public override bool Equals(object obj)
        {
            if (!(obj is RiotVersion))
            {
                return(false);
            }

            if (ReferenceEquals(this, obj))
            {
                return(true);
            }


            RiotVersion other = obj as RiotVersion;

            return(version == other.version);
        }
Пример #6
0
 /// <summary>
 /// Test whether this version matches another version, to a specified tolerance.
 /// </summary>
 public bool IsSamePatch(RiotVersion other, MatchTolerance tolerance = MatchTolerance.Minor)
 {
     if (Major != other.Major) return false;
     if (tolerance == MatchTolerance.Major) return true;
     if (Minor != other.Minor) return false;
     if (tolerance == MatchTolerance.Minor) return true;
     if (Patch != other.Patch) return false;
     if (tolerance == MatchTolerance.Patch) return false;
     return (SubPatch != other.SubPatch);
 }
Пример #7
0
        /// <summary>
        /// Initialize the static data store by pulling down all data we care about.
        /// </summary>
        public static void Initialize(StaticRiotApi riotStaticApi)
        {
            var realms = Enum.GetValues(typeof(Region)).OfType<Region>().AsParallel().WithDegreeOfParallelism(4).Select(region => new { Region = region, Realm = riotStaticApi.GetRealm(region) }).ToList();
            Version = realms.Max(realm => new RiotVersion(realm.Realm.V));
            var filteredRealms = realms.Where(realm => Version.IsSamePatch(new RiotVersion(realm.Realm.V)));

            // Get data for all valid realms
            Realms = filteredRealms.ToDictionary(realm => realm.Region, realm => new RealmStaticData(riotStaticApi, realm.Realm, realm.Region));

            // Try getting NA data if available
            RealmStaticData primaryrealm;
            if (!Realms.TryGetValue(Region.na, out primaryrealm))
            {
                // Try to find an english realm
                primaryrealm = Realms.FirstOrDefault(kvp => kvp.Value.Realm.L.Contains("en")).Value;

                // If we can't find english data, give up and just choose the first realm
                if (primaryrealm == null)
                    primaryrealm = Realms.FirstOrDefault().Value;

                // If there are no realms, just return
                if (primaryrealm == null)
                    return;
            }

            Champions = primaryrealm.Champions;
            Items = primaryrealm.Items;
            SummonerSpells = primaryrealm.SummonerSpells;
        }