mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-11 06:15:18 -05:00
Relocate level suggestions to EncounterSuggestion
This commit is contained in:
@@ -404,7 +404,7 @@ private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info, s
|
||||
|
||||
int level = encounter.LevelMin;
|
||||
int location = encounter.Location;
|
||||
int minlvl = Legal.GetLowestLevel(pk, encounter.LevelMin);
|
||||
int minlvl = EncounterSuggestion.GetLowestLevel(pk, encounter.LevelMin);
|
||||
|
||||
pk.Met_Level = level;
|
||||
pk.Met_Location = location;
|
||||
|
||||
@@ -577,23 +577,6 @@ internal static bool GetCanInheritMoves(int species)
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int GetLowestLevel(PKM pkm, int startLevel)
|
||||
{
|
||||
if (startLevel == -1)
|
||||
startLevel = 100;
|
||||
|
||||
var table = EvolutionTree.GetEvolutionTree(pkm, pkm.Format);
|
||||
int count = 1;
|
||||
for (int i = 100; i >= startLevel; i--)
|
||||
{
|
||||
var evos = table.GetValidPreEvolutions(pkm, maxLevel: i, minLevel: startLevel, skipChecks: true);
|
||||
if (evos.Count < count) // lost an evolution, prior level was minimum current level
|
||||
return evos.Max(evo => evo.Level) + 1;
|
||||
count = evos.Count;
|
||||
}
|
||||
return startLevel;
|
||||
}
|
||||
|
||||
internal static bool GetCanLearnMachineMove(PKM pkm, int move, int generation, GameVersion version = GameVersion.Any)
|
||||
{
|
||||
return GetValidMoves(pkm, version, EvolutionChain.GetValidPreEvolutions(pkm), generation, Machine: true).Contains(move);
|
||||
|
||||
@@ -166,6 +166,40 @@ public static int GetSuggestedTransferLocation(PKM pkm)
|
||||
return Legal.GetTransfer45MetLocation(pkm);
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int GetLowestLevel(PKM pkm, int startLevel)
|
||||
{
|
||||
if (startLevel == -1)
|
||||
startLevel = 100;
|
||||
|
||||
var table = EvolutionTree.GetEvolutionTree(pkm, pkm.Format);
|
||||
int count = 1;
|
||||
for (int i = 100; i >= startLevel; i--)
|
||||
{
|
||||
var evos = table.GetValidPreEvolutions(pkm, maxLevel: i, minLevel: startLevel, skipChecks: true);
|
||||
if (evos.Count < count) // lost an evolution, prior level was minimum current level
|
||||
return evos.Max(evo => evo.Level) + 1;
|
||||
count = evos.Count;
|
||||
}
|
||||
return startLevel;
|
||||
}
|
||||
|
||||
|
||||
public static int GetSuggestedMetLevel(PKM pkm, int minLevel)
|
||||
{
|
||||
var clone = pkm.Clone();
|
||||
int minMove = -1;
|
||||
for (int i = clone.CurrentLevel; i >= minLevel; i--)
|
||||
{
|
||||
clone.Met_Level = i;
|
||||
var la = new LegalityAnalysis(clone);
|
||||
if (la.Valid)
|
||||
return i;
|
||||
if (la.Info.Moves.All(z => z.Valid))
|
||||
minMove = i;
|
||||
}
|
||||
return Math.Max(minMove, minLevel);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EncounterSuggestionData : IRelearn
|
||||
@@ -202,17 +236,6 @@ public EncounterSuggestionData(PKM pkm, int met, int lvl)
|
||||
public int LevelMin { get; }
|
||||
public int LevelMax { get; }
|
||||
|
||||
public int GetSuggestedMetLevel(PKM pkm)
|
||||
{
|
||||
var clone = pkm.Clone();
|
||||
for (int i = clone.CurrentLevel; i > LevelMin; i--)
|
||||
{
|
||||
clone.Met_Level = i;
|
||||
var la = new LegalityAnalysis(clone);
|
||||
if (la.Info.Moves.All(z => z.Valid))
|
||||
return i;
|
||||
}
|
||||
return LevelMin;
|
||||
}
|
||||
public int GetSuggestedMetLevel(PKM pkm) => EncounterSuggestion.GetSuggestedMetLevel(pkm, LevelMin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,7 +744,7 @@ private bool SetSuggestedMetLocation(bool silent = false)
|
||||
|
||||
int level = encounter.LevelMin;
|
||||
int location = encounter.Location;
|
||||
int minlvl = Legal.GetLowestLevel(Entity, encounter.LevelMin);
|
||||
int minlvl = EncounterSuggestion.GetLowestLevel(Entity, encounter.LevelMin);
|
||||
if (minlvl == 0)
|
||||
minlvl = level;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user