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<lvlhi, we can get a level 5 pkm from the slot
(using a negative flute yielding a -1 adjustment).

I could probably refactor it to be a 3-input signature (lvl, lvlneg,
lvlpos), and have it do LevelMin - lvlneg <= lvl && lvl <= LevelMax +
lvlpos

I should probably refactor these methods to do minLevel & maxLevel (so
baseSpecies.Level to CurrentLevel for pkm that lost their original met
data) but nothing needs the extra logic at this time.
This commit is contained in:
Kurt
2019-09-19 22:37:56 -07:00
parent 7e70d83664
commit a4a0e3ac6e
2 changed files with 14 additions and 1 deletions

View File

@@ -17,7 +17,7 @@ protected override IEnumerable<EncounterSlot> 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)));
}

View File

@@ -12,7 +12,20 @@ public class EncounterSlot : IEncounterable, IGeneration, ILocation, IVersion
public int LevelMin { get; set; }
public int LevelMax { get; set; }
/// <summary>
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
/// </summary>
/// <param name="lvl">Single level</param>
/// <returns>True if within slot's range, false if impossible.</returns>
/// <remarks>Use <see cref="IsLevelWithinRange(int, int)"/> if <see cref="lvl"/> can have a range of values</remarks>
public bool IsLevelWithinRange(int lvl) => LevelMin <= lvl && lvl <= LevelMax;
/// <summary>
/// Gets if the specified level inputs are within range of the <see cref="LevelMin"/> and <see cref="LevelMax"/>
/// </summary>
/// <param name="min">Highest value the low end of levels can be</param>
/// <param name="max">Lowest value the high end of levels can be</param>
/// <returns>True if within slot's range, false if impossible.</returns>
public bool IsLevelWithinRange(int min, int max) => LevelMin <= min && max <= LevelMax;
public SlotType Type { get; set; } = SlotType.Any;