Пример #1
0
        /// <summary>
        /// Sets the <see cref="PKM"/> byte array propery to a specified value.
        /// </summary>
        /// <param name="pkm">Pokémon to modify.</param>
        /// <param name="cmd">Modification</param>
        private static ModifyResult SetByteArrayProperty(PKM pkm, StringInstruction cmd)
        {
            switch (cmd.PropertyName)
            {
            case nameof(pkm.Nickname_Trash):
                pkm.Nickname_Trash = string2arr(cmd.PropertyValue);
                return(ModifyResult.Modified);

            case nameof(pkm.OT_Trash):
                pkm.OT_Trash = string2arr(cmd.PropertyValue);
                return(ModifyResult.Modified);

            default:
                return(ModifyResult.Error);
            }
            byte[] string2arr(string str) => str.Substring(CONST_BYTES.Length).Split(',').Select(z => Convert.ToByte(z.Trim(), 16)).ToArray();
        }
Пример #2
0
        /// <summary>
        /// Initializes the <see cref="StringInstruction"/> with a context-sensitive value. If the provided value is a string, it will attempt to convert that string to its corresponding index.
        /// </summary>
        /// <param name="i">Instruction to initialize.</param>
        private static void SetInstructionScreenedValue(StringInstruction i)
        {
            switch (i.PropertyName)
            {
            case nameof(PKM.Species): i.SetScreenedValue(GameInfo.Strings.specieslist); return;

            case nameof(PKM.HeldItem): i.SetScreenedValue(GameInfo.Strings.itemlist); return;

            case nameof(PKM.Ability): i.SetScreenedValue(GameInfo.Strings.abilitylist); return;

            case nameof(PKM.Nature): i.SetScreenedValue(GameInfo.Strings.natures); return;

            case nameof(PKM.Ball): i.SetScreenedValue(GameInfo.Strings.balllist); return;

            case nameof(PKM.Move1) or nameof(PKM.Move2) or nameof(PKM.Move3) or nameof(PKM.Move4):
            case nameof(PKM.RelearnMove1) or nameof(PKM.RelearnMove2) or nameof(PKM.RelearnMove3) or nameof(PKM.RelearnMove4):
                i.SetScreenedValue(GameInfo.Strings.movelist); return;
            }
        }
Пример #3
0
        /// <summary>
        /// Sets the if the <see cref="PKMInfo"/> should be filtered due to the <see cref="StringInstruction"/> provided.
        /// </summary>
        /// <param name="cmd">Command Filter</param>
        /// <param name="info">Pokémon to check.</param>
        /// <param name="props">PropertyInfo cache (optional)</param>
        /// <returns>True if filtered, else false.</returns>
        private static ModifyResult SetPKMProperty(StringInstruction cmd, PKMInfo info, IReadOnlyDictionary <string, PropertyInfo> props)
        {
            var pk = info.Entity;

            if (cmd.PropertyValue.StartsWith(CONST_BYTES))
            {
                return(SetByteArrayProperty(pk, cmd));
            }

            if (cmd.PropertyValue.StartsWith(CONST_SUGGEST))
            {
                return(SetSuggestedPKMProperty(cmd.PropertyName, info, cmd.PropertyValue));
            }
            if (cmd.PropertyValue == CONST_RAND && cmd.PropertyName == nameof(PKM.Moves))
            {
                return(SetMoves(pk, pk.GetMoveSet(info.Legality, true)));
            }

            if (SetComplexProperty(pk, cmd))
            {
                return(ModifyResult.Modified);
            }

            if (!props.TryGetValue(cmd.PropertyName, out var pi))
            {
                return(ModifyResult.Error);
            }

            if (!pi.CanWrite)
            {
                return(ModifyResult.Error);
            }

            object val = cmd.Random ? (object)cmd.RandomValue : cmd.PropertyValue;

            ReflectUtil.SetValue(pi, pk, val);
            return(ModifyResult.Modified);
        }
Пример #4
0
 public StringInstructionSet(ICollection <string> set)
 {
     Filters      = StringInstruction.GetFilters(set).ToList();
     Instructions = StringInstruction.GetInstructions(set).ToList();
 }
Пример #5
0
 public bool IsFiltered(object pkm, StringInstruction cmd) => FilterPKM(pkm, cmd);
Пример #6
0
 public bool IsFiltered(BatchInfo info, StringInstruction cmd) => FilterBulk(info, cmd);