Пример #1
0
        internal static Coverage MakeCoverage(params TypeToken[] types)
        {
            Debug.Assert(types.Length > 0 && types.Length <= 4);

            var effective4x   = new HashSet <PokemonType>();
            var effective2x   = new HashSet <PokemonType>();
            var effective1x   = new HashSet <PokemonType>();
            var effective05x  = new HashSet <PokemonType>();
            var effective025x = new HashSet <PokemonType>();
            var effective0x   = new HashSet <PokemonType>();

            var         typesLength = Enum.GetValues(typeof(TypeToken)).Length;
            PokemonType t;

            for (int i = 0; i < typesLength; i++)
            {
                var t1 = (TypeToken)i;
                t = API.MakeType(t1);

                foreach (var type in types)
                {
                    MakeCoverageHelper(
                        type,
                        t,
                        effective4x,
                        effective2x,
                        effective1x,
                        effective05x,
                        effective025x,
                        effective0x);
                }

                for (int j = i + 1; j < typesLength; j++)
                {
                    var t2 = (TypeToken)j;
                    t = API.MakeType(t1, t2);

                    foreach (var type in types)
                    {
                        MakeCoverageHelper(
                            type,
                            t,
                            effective4x,
                            effective2x,
                            effective1x,
                            effective05x,
                            effective025x,
                            effective0x);
                    }
                }
            }

            var arrEffective4x   = new PokemonType[effective4x.Count];
            var arrEffective2x   = new PokemonType[effective2x.Count];
            var arrEffective1x   = new PokemonType[effective1x.Count];
            var arrEffective05x  = new PokemonType[effective05x.Count];
            var arrEffective025x = new PokemonType[effective025x.Count];
            var arrEffective0x   = new PokemonType[effective0x.Count];

            effective4x.CopyTo(arrEffective4x);
            effective2x.CopyTo(arrEffective2x);
            effective1x.CopyTo(arrEffective1x);
            effective05x.CopyTo(arrEffective05x);
            effective025x.CopyTo(arrEffective025x);
            effective0x.CopyTo(arrEffective0x);

            return(new Coverage(
                       arrEffective4x,
                       arrEffective2x,
                       arrEffective1x,
                       arrEffective05x,
                       arrEffective025x,
                       arrEffective0x,
                       types));
        }
Пример #2
0
        private static void MakeCoverageHelper(
            TypeToken attackingType,
            PokemonType defendingType,
            HashSet <PokemonType> effective4x,
            HashSet <PokemonType> effective2x,
            HashSet <PokemonType> effective1x,
            HashSet <PokemonType> effective05x,
            HashSet <PokemonType> effective025x,
            HashSet <PokemonType> effective0x)
        {
            if (effective4x.Contains(defendingType))
            {
                return;
            }

            foreach (var t in defendingType.WeakTo4x)
            {
                if (t == attackingType)
                {
                    effective4x.Add(defendingType);
                    effective2x.Remove(defendingType);
                    effective1x.Remove(defendingType);
                    effective05x.Remove(defendingType);
                    effective025x.Remove(defendingType);
                    effective0x.Remove(defendingType);

                    return;
                }
            }

            if (effective2x.Contains(defendingType))
            {
                return;
            }

            foreach (var t in defendingType.WeakTo2x)
            {
                if (t == attackingType)
                {
                    effective2x.Add(defendingType);
                    effective1x.Remove(defendingType);
                    effective05x.Remove(defendingType);
                    effective025x.Remove(defendingType);
                    effective0x.Remove(defendingType);

                    return;
                }
            }

            if (effective1x.Contains(defendingType))
            {
                return;
            }

            foreach (var t in defendingType.Normal)
            {
                if (t == attackingType)
                {
                    effective1x.Add(defendingType);
                    effective05x.Remove(defendingType);
                    effective025x.Remove(defendingType);
                    effective0x.Remove(defendingType);

                    return;
                }
            }

            if (effective05x.Contains(defendingType))
            {
                return;
            }

            foreach (var t in defendingType.Resist2x)
            {
                if (t == attackingType)
                {
                    effective05x.Add(defendingType);
                    effective025x.Remove(defendingType);
                    effective0x.Remove(defendingType);

                    return;
                }
            }

            if (effective025x.Contains(defendingType))
            {
                return;
            }

            foreach (var t in defendingType.Resist4x)
            {
                if (t == attackingType)
                {
                    effective025x.Add(defendingType);
                    effective0x.Remove(defendingType);

                    return;
                }
            }

            if (effective0x.Contains(defendingType))
            {
                return;
            }

            foreach (var t in defendingType.Immune)
            {
                if (t == attackingType)
                {
                    effective0x.Add(defendingType);

                    return;
                }
            }

            throw new ArgumentException();
        }
Пример #3
0
 public static PokemonType MakeType(params TypeToken[] types)
 {
     return(PokemonType.MakeType(types));
 }