コード例 #1
0
        internal static bool GetIncorrectRibbonsEgg(PKM pkm, object encounterContent)
        {
            var event3      = encounterContent as IRibbonSetEvent3;
            var event4      = encounterContent as IRibbonSetEvent4;
            var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon");

            if (event3 != null)
            {
                RibbonNames = RibbonNames.Except(event3.RibbonNames());
            }
            if (event4 != null)
            {
                RibbonNames = RibbonNames.Except(event4.RibbonNames());
            }

            foreach (object RibbonValue in RibbonNames.Select(RibbonName => ReflectUtil.GetValue(pkm, RibbonName)))
            {
                if (HasFlag(RibbonValue) || HasCount(RibbonValue))
                {
                    return(true);
                }

                bool HasFlag(object o) => o is bool z && z;
                bool HasCount(object o) => o is int z && z > 0;
            }
            return(false);
        }
コード例 #2
0
        public IEnumerable <FlagPairG1Detail> GetFlagPairs()
        {
            var pz = ReflectUtil.GetPropertiesStartWithPrefix(GetType(), FlagPropertyPrefix);

            foreach (var pair in pz)
            {
                if (ReflectUtil.GetValue(this, pair) is not FlagPairG1 p)
                {
                    continue;
                }
                yield return(new FlagPairG1Detail(p, pair, EventFlags, SpawnFlags));
            }
        }
コード例 #3
0
        /// <summary>
        /// Applies all shared properties from <see cref="Source"/> to <see cref="Destination"/>.
        /// </summary>
        /// <param name="Source"><see cref="PKM"/> that supplies property values.</param>
        /// <param name="Destination"><see cref="PKM"/> that receives property values.</param>
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            // Only transfer declared properties not defined in PKM.cs but in the actual type
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublicDeclared(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublicDeclared(Destination.GetType());

            foreach (string property in SourceProperties.Intersect(DestinationProperties))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop != null)
                {
                    ReflectUtil.SetValue(Destination, property, prop);
                }
            }
        }
コード例 #4
0
ファイル: PKM.cs プロジェクト: tkfltkgk/PKHeX
        /// <summary>
        /// Applies all shared properties from <see cref="Source"/> to <see cref="Destination"/>.
        /// </summary>
        /// <param name="Source"><see cref="PKM"/> that supplies property values.</param>
        /// <param name="Destination"><see cref="PKM"/> that receives property values.</param>
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublic(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType());

            // Skip Data property when applying all individual properties. Let the setters do the updates for Data.
            foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data)))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop != null)
                {
                    ReflectUtil.SetValue(Destination, property, prop);
                }
            }
        }
コード例 #5
0
ファイル: PKM.cs プロジェクト: muldos/ImportableToPKHeX
        protected void TransferPropertiesWithReflection(PKM Source, PKM Destination)
        {
            var SourceProperties      = ReflectUtil.getPropertiesCanWritePublic(Source.GetType());
            var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType());

            foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data)))
            {
                var prop = ReflectUtil.GetValue(this, property);
                if (prop == null)
                {
                    continue;
                }
                ReflectUtil.SetValue(Destination, property, prop);
            }
        }
コード例 #6
0
        public IEnumerable <FlagPair> GetFlagPairs()
        {
            var pz = ReflectUtil.GetPropertiesStartWithPrefix(GetType(), "Flag");

            foreach (var pair in pz)
            {
                if (!(ReflectUtil.GetValue(this, pair) is FlagPair p))
                {
                    continue;
                }
                p.Name  = pair;
                p.Event = EventFlags;
                p.Spawn = SpawnFlags;
                yield return(p);
            }
        }
コード例 #7
0
        private static bool GetIncorrectRibbonsEgg(PKM pkm, object encounterContent)
        {
            var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon");

            if (encounterContent is IRibbonSetEvent3 event3)
            {
                RibbonNames = RibbonNames.Except(event3.RibbonNames());
            }
            if (encounterContent is IRibbonSetEvent4 event4)
            {
                RibbonNames = RibbonNames.Except(event4.RibbonNames());
            }

            foreach (object RibbonValue in RibbonNames.Select(RibbonName => ReflectUtil.GetValue(pkm, RibbonName)))
            {
                if (HasFlag(RibbonValue) || HasCount(RibbonValue))
                {
                    return(true);
                }
コード例 #8
0
        public static IReadOnlyList <RibbonInfo> GetRibbonInfo(PKM pkm)
        {
            // Get a list of all Ribbon Attributes in the PKM
            var riblist = new List <RibbonInfo>();
            var names   = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon");

            foreach (var name in names)
            {
                object RibbonValue = ReflectUtil.GetValue(pkm, name);
                if (RibbonValue is int x)
                {
                    riblist.Add(new RibbonInfo(name, x));
                }
                if (RibbonValue is bool b)
                {
                    riblist.Add(new RibbonInfo(name, b));
                }
            }

            return(riblist);
        }
コード例 #9
0
ファイル: RibbonVerifier.cs プロジェクト: Bl4ckSh4rk/PKHeX
        private static bool GetIncorrectRibbonsEgg(PKM pkm, IEncounterTemplate enc)
        {
            var names = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), RibbonInfo.PropertyPrefix);

            if (enc is IRibbonSetEvent3 event3)
            {
                names = names.Except(event3.RibbonNames());
            }
            if (enc is IRibbonSetEvent4 event4)
            {
                names = names.Except(event4.RibbonNames());
            }

            foreach (var value in names.Select(name => ReflectUtil.GetValue(pkm, name)))
            {
                if (value is null)
                {
                    continue;
                }
                if (HasFlag(value) || HasCount(value))
                {
                    return(true);
                }
コード例 #10
0
        private static IEnumerable <string> DumpStrings(Type t)
        {
            var props = ReflectUtil.GetPropertiesStartWithPrefix(t, string.Empty);

            return(props.Select(p => $"{p}{TranslationSplitter}{ReflectUtil.GetValue(t, p)}"));
        }