From a4a0e3ac6e1969ce2068e2cfd07cb4edae4c2ca9 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 19 Sep 2019 22:37:56 -0700 Subject: [PATCH] Fix flute level amp direction The inputs to "IsLevelWithinRange" are the highest value the lowest-level can be, and the lowest value the highest level can be... seems confusing (hence the original error). If a slot is 6-7, with a wild encounter (flute), we can go +/-3 from 6-7, which is 3-10. With an encounter of level 5, the inputs are: 5+3, and 5-3 (8, 2). Since 8>lvlmin and 2 GetMatchFromEvoLevel(PKM pkm, IEnu var slots = Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && evo.Level >= (slot.LevelMin - FluteBoostMax))); int getMaxLevelBoost(EncounterSlot s) => s.Type == SlotType.Rock_Smash ? FluteBoostMax : DexNavBoost; - int fluteMinLevel = minLevel - FluteBoostMax; + int fluteMinLevel = minLevel + FluteBoostMax; // highest possible min-level of slot before flute decrease // Get slots where pokemon can exist with respect to level constraints return slots.Where(s => s.IsLevelWithinRange(fluteMinLevel, minLevel - getMaxLevelBoost(s))); } diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot.cs index 99d65a531..db17d52f0 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot.cs @@ -12,7 +12,20 @@ public class EncounterSlot : IEncounterable, IGeneration, ILocation, IVersion public int LevelMin { get; set; } public int LevelMax { get; set; } + /// + /// Gets if the specified level inputs are within range of the and + /// + /// Single level + /// True if within slot's range, false if impossible. + /// Use if can have a range of values public bool IsLevelWithinRange(int lvl) => LevelMin <= lvl && lvl <= LevelMax; + + /// + /// Gets if the specified level inputs are within range of the and + /// + /// Highest value the low end of levels can be + /// Lowest value the high end of levels can be + /// True if within slot's range, false if impossible. public bool IsLevelWithinRange(int min, int max) => LevelMin <= min && max <= LevelMax; public SlotType Type { get; set; } = SlotType.Any;