private static bool SetComplexProperty(Item item, StringInstruction cmd) { // Zeroed out item? if (cmd.PropertyName == nameof(Item.ItemId)) { if (!int.TryParse(cmd.PropertyValue, out var val)) { return(false); } if (val is not 0 or 0xFFFE) { return(false); } item.Delete(); return(true); } return(false); }
/// <summary> /// Sets the if the <see cref="Item"/> should be filtered due to the <see cref="StringInstruction"/> provided. /// </summary> /// <param name="cmd">Command Filter</param> /// <param name="item">Pokémon to check.</param> /// <param name="props">PropertyInfo cache (optional)</param> /// <returns>True if filtered, else false.</returns> private static ModifyResult SetProperty(StringInstruction cmd, Item item, IReadOnlyDictionary <string, PropertyInfo> props) { if (SetComplexProperty(item, 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, item, val); return(ModifyResult.Modified); }
public StringInstructionSet(ICollection <string> set) { Filters = StringInstruction.GetFilters(set).ToList(); Instructions = StringInstruction.GetInstructions(set).ToList(); }
/// <summary> /// Checks if the <see cref="Item"/> should be filtered due to the <see cref="StringInstruction"/> provided. /// </summary> /// <param name="cmd">Command Filter</param> /// <param name="item">Pokémon to check.</param> /// <param name="props">PropertyInfo cache (optional)</param> /// <returns>True if filter matches, else false.</returns> private static bool IsFilterMatch(StringInstruction cmd, Item item, IReadOnlyDictionary <string, PropertyInfo> props) { return(IsPropertyFiltered(cmd, item, props)); }