private static ModifyResult TryModifyPKM(PKM PKM, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions) { if (!PKM.ChecksumValid || PKM.Species == 0) { return(ModifyResult.Invalid); } Type pkm = PKM.GetType(); PKMInfo info = new PKMInfo(PKM); ModifyResult result = ModifyResult.Error; foreach (var cmd in Filters) { try { if (IsPKMFiltered(pkm, cmd, info, out result)) { return(result); // why it was filtered out } } catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); } } foreach (var cmd in Instructions) { try { result = SetPKMProperty(PKM, info, cmd); } catch { Debug.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); } } return(result); }
private static ModifyResult SetPKMProperty(PKM PKM, PKMInfo info, StringInstruction cmd) { if (cmd.PropertyValue.StartsWith(CONST_BYTES)) { return(SetByteArrayProperty(PKM, cmd) ? ModifyResult.Modified : ModifyResult.Error); } if (cmd.PropertyValue == CONST_SUGGEST) { return(SetSuggestedPKMProperty(PKM, cmd, info) ? ModifyResult.Modified : ModifyResult.Error); } SetProperty(PKM, cmd); return(ModifyResult.Modified); }
private static bool SetSuggestedPKMProperty(PKM PKM, StringInstruction cmd, PKMInfo info) { switch (cmd.PropertyName) { case nameof(PKM.HyperTrainFlags): PKM.HyperTrainFlags = GetSuggestedHyperTrainingStatus(PKM); return(true); case nameof(PKM.RelearnMoves): PKM.RelearnMoves = info.SuggestedRelearn; return(true); case nameof(PKM.Met_Location): var encounter = info.SuggestedEncounter; if (encounter == null) { return(false); } int level = encounter.Level; int location = encounter.Location; int minlvl = Legal.GetLowestLevel(PKM, encounter.LevelMin); PKM.Met_Level = level; PKM.Met_Location = location; PKM.CurrentLevel = Math.Max(minlvl, level); return(true); case nameof(PKM.Moves): var moves = info.SuggestedMoves; Util.Shuffle(moves); Array.Resize(ref moves, 4); PKM.Moves = moves; return(true); default: return(false); } }
private static bool IsPKMFiltered(Type pkm, StringInstruction cmd, PKMInfo info, out ModifyResult result) { result = ModifyResult.Error; if (cmd.PropertyName == PROP_LEGAL) { if (!bool.TryParse(cmd.PropertyValue, out bool legal)) { return(true); } if (legal == info.Legal == cmd.Evaluator) { return(false); } result = ModifyResult.Filtered; return(true); } if (!pkm.HasPropertyAll(cmd.PropertyName) || pkm.IsValueEqual(info.pkm, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator) { result = ModifyResult.Filtered; return(true); } return(false); }
private static ModifyResult tryModifyPKM(PKM PKM, IEnumerable <StringInstruction> Filters, IEnumerable <StringInstruction> Instructions) { if (!PKM.ChecksumValid || PKM.Species == 0) { return(ModifyResult.Invalid); } Type pkm = PKM.GetType(); PKMInfo info = new PKMInfo(PKM); foreach (var cmd in Filters) { try { if (cmd.PropertyName == PROP_LEGAL) { bool legal; if (!bool.TryParse(cmd.PropertyValue, out legal)) { return(ModifyResult.Error); } if (legal == info.Legal == cmd.Evaluator) { continue; } return(ModifyResult.Filtered); } if (!pkm.HasProperty(cmd.PropertyName)) { return(ModifyResult.Filtered); } if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator) { return(ModifyResult.Filtered); } } catch { Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); return(ModifyResult.Filtered); } } ModifyResult result = ModifyResult.Error; foreach (var cmd in Instructions) { try { if (cmd.PropertyValue == CONST_SUGGEST) { result = setSuggestedProperty(PKM, cmd, info) ? ModifyResult.Modified : ModifyResult.Error; } else { setProperty(PKM, cmd); result = ModifyResult.Modified; } } catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); } } return(result); }