mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
Add AltForm parameter to exp/level fetch
Starter Pikachu & Eevee have different growth rates than their base forms (seriously WHY?) remove old api surface in PKX as a breaking change as adding the parameter is necessary.
This commit is contained in:
parent
26647996c6
commit
76a2e4f527
17 changed files with 48 additions and 37 deletions
|
@ -363,7 +363,7 @@ namespace PKHeX.Core
|
|||
Nature = pkm.Nature;
|
||||
Gender = genders[pkm.Gender < 2 ? pkm.Gender : 2];
|
||||
Friendship = pkm.CurrentFriendship;
|
||||
Level = PKX.GetLevel(pkm.Species, pkm.EXP);
|
||||
Level = Experience.GetLevel(pkm.EXP, pkm.Species, pkm.AltForm);
|
||||
Shiny = pkm.IsShiny;
|
||||
|
||||
FormIndex = pkm.AltForm;
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace PKHeX.Core
|
|||
return;
|
||||
|
||||
const int maxEV = 100; // Vitamin Max
|
||||
if (PKX.GetEXP(EncounterMatch.LevelMin, pkm.Species) == pkm.EXP && evs.Any(ev => ev > maxEV))
|
||||
if (Experience.GetEXP(EncounterMatch.LevelMin, pkm.Species, pkm.AltForm) == pkm.EXP && evs.Any(ev => ev > maxEV))
|
||||
data.AddLine(GetInvalid(string.Format(LEffortUntrainedCap, maxEV)));
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace PKHeX.Core
|
|||
|
||||
var reqEXP = EncounterMatch is EncounterStatic s && s.Version == GameVersion.C
|
||||
? 125 // Gen2 Dizzy Punch gifts always have 125 EXP, even if it's more than the Lv5 exp required.
|
||||
: PKX.GetEXP(elvl, pkm.Species);
|
||||
: Experience.GetEXP(elvl, pkm.Species, pkm.AltForm);
|
||||
if (reqEXP != pkm.EXP)
|
||||
data.AddLine(GetInvalid(LEggEXP));
|
||||
return;
|
||||
|
@ -55,7 +55,7 @@ namespace PKHeX.Core
|
|||
int lvl = pkm.CurrentLevel;
|
||||
if (lvl < pkm.Met_Level)
|
||||
data.AddLine(GetInvalid(LLevelMetBelow));
|
||||
else if (!EncounterMatch.IsWithinRange(pkm) && lvl != 100 && pkm.EXP == PKX.GetEXP(lvl, pkm.Species))
|
||||
else if (!EncounterMatch.IsWithinRange(pkm) && lvl != 100 && pkm.EXP == Experience.GetEXP(lvl, pkm.Species, pkm.AltForm))
|
||||
data.AddLine(Get(LLevelEXPThreshold, Severity.Fishy));
|
||||
else
|
||||
data.AddLine(GetValid(LLevelMetSane));
|
||||
|
|
|
@ -211,7 +211,7 @@ namespace PKHeX.Core
|
|||
return GetInvalid(string.Format(LMemoryArgBadPokecenter, tr));
|
||||
|
||||
// {0} saw {2} carrying {1} on its back. {4} that {3}.
|
||||
case 21 when !Legal.GetCanLearnMachineMove(new PK6 {Species = t, EXP = PKX.GetEXP(100, t)}, 19, 6):
|
||||
case 21 when !Legal.GetCanLearnMachineMove(new PK6 {Species = t, EXP = Experience.GetEXP(100, t, 0)}, 19, 6):
|
||||
return GetInvalid(string.Format(LMemoryArgBadMove, tr));
|
||||
|
||||
case 16 when t == 0 || !Legal.GetCanKnowMove(pkm, t, 6):
|
||||
|
|
|
@ -199,7 +199,7 @@ namespace PKHeX.Core
|
|||
CNT_Tough = CNT_Tough,
|
||||
CNT_Sheen = CNT_Sheen,
|
||||
|
||||
EXP = PKX.GetEXP(Level, Species),
|
||||
EXP = Experience.GetEXP(Level, Species, 0),
|
||||
|
||||
// Ribbons
|
||||
RibbonCountry = RibbonCountry,
|
||||
|
|
|
@ -361,7 +361,7 @@ namespace PKHeX.Core
|
|||
HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0,
|
||||
CurrentHandler = OT_Name.Length > 0 ? 1 : 0,
|
||||
|
||||
EXP = PKX.GetEXP(currentLevel, Species),
|
||||
EXP = Experience.GetEXP(currentLevel, Species, 0),
|
||||
|
||||
// Ribbons
|
||||
RibbonCountry = RibbonCountry,
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace PKHeX.Core
|
|||
Met_Location = Location,
|
||||
Ball = 4,
|
||||
|
||||
EXP = PKX.GetEXP(Level, Species),
|
||||
EXP = Experience.GetEXP(Level, Species, 0),
|
||||
|
||||
// Ribbons
|
||||
RibbonCountry = RibbonCountry,
|
||||
|
|
|
@ -327,7 +327,7 @@ namespace PKHeX.Core
|
|||
HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0,
|
||||
CurrentHandler = OT_Name.Length > 0 ? 1 : 0,
|
||||
|
||||
EXP = PKX.GetEXP(Level, Species),
|
||||
EXP = Experience.GetEXP(Level, Species, 0),
|
||||
|
||||
// Ribbons
|
||||
RibbonCountry = RibbonCountry,
|
||||
|
|
|
@ -367,7 +367,7 @@ namespace PKHeX.Core
|
|||
HT_Gender = OT_Name.Length > 0 ? SAV.Gender : 0,
|
||||
CurrentHandler = OT_Name.Length > 0 ? 1 : 0,
|
||||
|
||||
EXP = PKX.GetEXP(currentLevel, Species),
|
||||
EXP = Experience.GetEXP(currentLevel, Species, 0),
|
||||
|
||||
// Ribbons
|
||||
RibbonCountry = RibbonCountry,
|
||||
|
|
|
@ -167,7 +167,7 @@ namespace PKHeX.Core
|
|||
Species = Species,
|
||||
TID = TID,
|
||||
SID = SID,
|
||||
EXP = IsEgg ? PKX.GetEXP(5, Species) : EXP,
|
||||
EXP = IsEgg ? Experience.GetEXP(5, Species, 0) : EXP,
|
||||
IsEgg = false,
|
||||
OT_Friendship = 70,
|
||||
Markings = Markings,
|
||||
|
@ -260,7 +260,7 @@ namespace PKHeX.Core
|
|||
pk4.OT_Name = OT_Name;
|
||||
|
||||
// Set Final Data
|
||||
pk4.Met_Level = PKX.GetLevel(pk4.Species, pk4.EXP);
|
||||
pk4.Met_Level = Experience.GetLevel(pk4.EXP, pk4.Species, 0);
|
||||
pk4.Gender = PKX.GetGenderFromPID(pk4.Species, pk4.PID);
|
||||
pk4.IsNicknamed = IsNicknamed;
|
||||
|
||||
|
|
|
@ -410,7 +410,7 @@ namespace PKHeX.Core
|
|||
pk5.OT_Name = OT_Name;
|
||||
|
||||
// Fix Level
|
||||
pk5.Met_Level = PKX.GetLevel(pk5.Species, pk5.EXP);
|
||||
pk5.Met_Level = Experience.GetLevel(pk5.EXP, pk5.Species, 0);
|
||||
|
||||
// Remove HM moves; Defog should be kept if both are learned.
|
||||
int[] banned = Moves.Contains(250) && Moves.Contains(432) // Whirlpool & Defog
|
||||
|
|
|
@ -332,7 +332,7 @@ namespace PKHeX.Core
|
|||
public bool PKRS_Infected => PKRS_Strain > 0;
|
||||
public bool PKRS_Cured => PKRS_Days == 0 && PKRS_Strain > 0;
|
||||
public virtual bool ChecksumValid => Checksum == CalculateChecksum();
|
||||
public int CurrentLevel { get => PKX.GetLevel(Species, EXP); set => EXP = PKX.GetEXP(value, Species); }
|
||||
public int CurrentLevel { get => Experience.GetLevel(EXP, Species, AltForm); set => EXP = Experience.GetEXP(value, Species, AltForm); }
|
||||
public int MarkCircle { get => Markings[0]; set { var marks = Markings; marks[0] = value; Markings = marks; } }
|
||||
public int MarkTriangle { get => Markings[1]; set { var marks = Markings; marks[1] = value; Markings = marks; } }
|
||||
public int MarkSquare { get => Markings[2]; set { var marks = Markings; marks[2] = value; Markings = marks; } }
|
||||
|
|
|
@ -8,12 +8,13 @@
|
|||
/// <summary>
|
||||
/// Gets the current level of a species.
|
||||
/// </summary>
|
||||
/// <param name="species">National Dex number of the Pokémon.</param>
|
||||
/// <param name="exp">Experience points</param>
|
||||
/// <param name="species">National Dex number of the Pokémon.</param>
|
||||
/// <param name="forme">AltForm ID (starters in Let's Go)</param>
|
||||
/// <returns>Current level of the species.</returns>
|
||||
public static int GetLevel(int species, uint exp)
|
||||
public static int GetLevel(uint exp, int species, int forme = 0)
|
||||
{
|
||||
int growth = PKX.Personal[species].EXPGrowth;
|
||||
int growth = PKX.Personal.GetFormeEntry(species, forme).EXPGrowth;
|
||||
if (exp >= ExpTable[99, growth])
|
||||
return 100;
|
||||
int tl = 1; // Initial Level. Iterate upwards to find the level
|
||||
|
@ -27,14 +28,15 @@
|
|||
/// </summary>
|
||||
/// <param name="level">Current level</param>
|
||||
/// <param name="species">National Dex number of the Pokémon.</param>
|
||||
/// <param name="forme">AltForm ID (starters in Let's Go)</param>
|
||||
/// <returns>Experience points needed to have specified level.</returns>
|
||||
public static uint GetEXP(int level, int species)
|
||||
public static uint GetEXP(int level, int species, int forme = 0)
|
||||
{
|
||||
if (level <= 1)
|
||||
return 0;
|
||||
if (level > 100)
|
||||
level = 100;
|
||||
return ExpTable[level - 1, PKX.Personal[species].EXPGrowth];
|
||||
return ExpTable[level - 1, PKX.Personal.GetFormeEntry(species, forme).EXPGrowth];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -49,12 +51,13 @@
|
|||
/// </summary>
|
||||
/// <param name="level">Current Level</param>
|
||||
/// <param name="species"><see cref="PKM.Species"/></param>
|
||||
/// <param name="forme">AltForm ID (starters in Let's Go)</param>
|
||||
/// <returns>Percentage [0,1.00)</returns>
|
||||
public static uint GetEXPToLevelUp(int level, int species)
|
||||
public static uint GetEXPToLevelUp(int level, int species, int forme = 0)
|
||||
{
|
||||
if (level >= 100)
|
||||
return 0;
|
||||
var growth = PKX.Personal[species].EXPGrowth;
|
||||
var growth = PKX.Personal.GetFormeEntry(species, forme).EXPGrowth;
|
||||
var current = ExpTable[level - 1, growth];
|
||||
var next = ExpTable[level, growth];
|
||||
return next - current;
|
||||
|
@ -64,14 +67,15 @@
|
|||
/// Gets a percentage for Experience Bar progress indication.
|
||||
/// </summary>
|
||||
/// <param name="level">Current Level</param>
|
||||
/// <param name="species"><see cref="PKM.Species"/></param>
|
||||
/// <param name="exp">Current Experience</param>
|
||||
/// <param name="species"><see cref="PKM.Species"/></param>
|
||||
/// <param name="forme">AltForm ID (starters in Let's Go)</param>
|
||||
/// <returns>Percentage [0,1.00)</returns>
|
||||
public static double GetEXPToLevelUpPercentage(int level, int species, uint exp)
|
||||
public static double GetEXPToLevelUpPercentage(int level, uint exp, int species, int forme = 0)
|
||||
{
|
||||
if (level >= 100)
|
||||
return 0;
|
||||
var growth = PKX.Personal[species].EXPGrowth;
|
||||
var growth = PKX.Personal.GetFormeEntry(species, forme).EXPGrowth;
|
||||
var current = ExpTable[level - 1, growth];
|
||||
var next = ExpTable[level, growth];
|
||||
var amount = next - current;
|
||||
|
|
|
@ -211,12 +211,13 @@ namespace PKHeX.Core
|
|||
/// <summary>
|
||||
/// Gets the current level of a species.
|
||||
/// </summary>
|
||||
/// <param name="species">National Dex number of the Pokémon.</param>
|
||||
/// <param name="exp">Experience points</param>
|
||||
/// <param name="species">National Dex number of the Pokémon.</param>
|
||||
/// <param name="forme">AltForm ID (starters in Let's Go)</param>
|
||||
/// <returns>Current level of the species.</returns>
|
||||
public static int GetLevel(int species, uint exp)
|
||||
public static int GetLevel(uint exp, int species, int forme)
|
||||
{
|
||||
return Experience.GetLevel(species, exp);
|
||||
return Experience.GetLevel(exp, species, forme);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -224,10 +225,11 @@ namespace PKHeX.Core
|
|||
/// </summary>
|
||||
/// <param name="level">Current level</param>
|
||||
/// <param name="species">National Dex number of the Pokémon.</param>
|
||||
/// <param name="forme">AltForm ID (starters in Let's Go)</param>
|
||||
/// <returns>Experience points needed to have specified level.</returns>
|
||||
public static uint GetEXP(int level, int species)
|
||||
public static uint GetEXP(int level, int species, int forme)
|
||||
{
|
||||
return Experience.GetEXP(level, species);
|
||||
return Experience.GetEXP(level, species, forme);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -20,9 +20,9 @@ namespace PKHeX.WinForms.Controls
|
|||
private void LoadSpeciesLevelEXP(PKM pk)
|
||||
{
|
||||
// Do first
|
||||
pk.Stat_Level = PKX.GetLevel(pk.Species, pk.EXP);
|
||||
pk.Stat_Level = Experience.GetLevel(pk.EXP, pk.Species, pk.AltForm);
|
||||
if (pk.Stat_Level == 100 && !HaX)
|
||||
pk.EXP = PKX.GetEXP(pk.Stat_Level, pk.Species);
|
||||
pk.EXP = Experience.GetEXP(pk.Stat_Level, pk.Species, pk.AltForm);
|
||||
|
||||
CB_Species.SelectedValue = pk.Species;
|
||||
TB_Level.Text = pk.Stat_Level.ToString();
|
||||
|
|
|
@ -240,7 +240,7 @@ namespace PKHeX.WinForms.Controls
|
|||
|
||||
if (HaX) // Load original values from pk not pkm
|
||||
{
|
||||
MT_Level.Text = (pk.Stat_HPMax != 0 ? pk.Stat_Level : PKX.GetLevel(pk.Species, pk.EXP)).ToString();
|
||||
MT_Level.Text = (pk.Stat_HPMax != 0 ? pk.Stat_Level : Experience.GetLevel(pk.EXP, pk.Species, pk.AltForm)).ToString();
|
||||
TB_EXP.Text = pk.EXP.ToString();
|
||||
MT_Form.Text = pk.AltForm.ToString();
|
||||
if (pk.Stat_HPMax != 0) // stats present
|
||||
|
@ -833,9 +833,10 @@ namespace PKHeX.WinForms.Controls
|
|||
// Change the Level
|
||||
uint EXP = Util.ToUInt32(TB_EXP.Text);
|
||||
int Species = pkm.Species;
|
||||
int Level = PKX.GetLevel(Species, EXP);
|
||||
int Form = pkm.AltForm;
|
||||
int Level = Experience.GetLevel(EXP, Species, Form);
|
||||
if (Level == 100)
|
||||
EXP = PKX.GetEXP(100, Species);
|
||||
EXP = Experience.GetEXP(100, Species, Form);
|
||||
|
||||
TB_Level.Text = Level.ToString();
|
||||
if (!HaX)
|
||||
|
@ -860,7 +861,7 @@ namespace PKHeX.WinForms.Controls
|
|||
if (Level > byte.MaxValue)
|
||||
MT_Level.Text = "255";
|
||||
else if (Level <= 100)
|
||||
TB_EXP.Text = PKX.GetEXP(Level, pkm.Species).ToString();
|
||||
TB_EXP.Text = Experience.GetEXP(Level, pkm.Species, pkm.AltForm).ToString();
|
||||
}
|
||||
ChangingFields = false;
|
||||
if (FieldsLoaded) // store values back
|
||||
|
@ -921,7 +922,11 @@ namespace PKHeX.WinForms.Controls
|
|||
private void UpdateForm(object sender, EventArgs e)
|
||||
{
|
||||
if (CB_Form == sender && FieldsLoaded)
|
||||
{
|
||||
pkm.AltForm = CB_Form.SelectedIndex;
|
||||
uint EXP = Experience.GetEXP(pkm.CurrentLevel, pkm.Species, pkm.AltForm);
|
||||
TB_EXP.Text = EXP.ToString();
|
||||
}
|
||||
|
||||
UpdateStats();
|
||||
SetAbilityList();
|
||||
|
@ -1112,7 +1117,7 @@ namespace PKHeX.WinForms.Controls
|
|||
return;
|
||||
|
||||
// Recalculate EXP for Given Level
|
||||
uint EXP = PKX.GetEXP(pkm.CurrentLevel, pkm.Species);
|
||||
uint EXP = Experience.GetEXP(pkm.CurrentLevel, pkm.Species, pkm.AltForm);
|
||||
TB_EXP.Text = EXP.ToString();
|
||||
|
||||
// Check for Gender Changes
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace PKHeX.WinForms
|
|||
var strings = GameInfo.Strings;
|
||||
foreach (PKM pkm in Data.Where(pkm => pkm.ChecksumValid && pkm.Species != 0))
|
||||
{
|
||||
pkm.Stat_Level = PKX.GetLevel(pkm.Species, pkm.EXP); // recalc Level
|
||||
pkm.Stat_Level = Experience.GetLevel(pkm.EXP, pkm.Species, pkm.AltForm); // recalc Level
|
||||
PL.Add(new PKMPreview(pkm, strings));
|
||||
BoxBar.PerformStep();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue