mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
Relocate some logic to core
party stats set when setting a slot to a save file simplify set/delete slotchange duplicate logic suggest better met locations beyond VC transfers hatching a gen6 egg applies memories automatically
This commit is contained in:
parent
a24e5aa742
commit
99a4c55579
11 changed files with 62 additions and 55 deletions
|
@ -5,7 +5,7 @@ namespace PKHeX.Core
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Logic for providing suggested property values with respect to the input data.
|
/// Logic for providing suggested property values with respect to the input data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class EncounterSuggestion
|
public static class EncounterSuggestion
|
||||||
{
|
{
|
||||||
public static EncounterStatic GetSuggestedMetInfo(PKM pkm)
|
public static EncounterStatic GetSuggestedMetInfo(PKM pkm)
|
||||||
{
|
{
|
||||||
|
@ -120,16 +120,22 @@ namespace PKHeX.Core
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Returns -1 if the met location is not overriden with a transfer location
|
/// Returns -1 if the met location is not overriden with a transfer location
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private static int GetSuggestedTransferLocation(PKM pkm)
|
public static int GetSuggestedTransferLocation(PKM pkm)
|
||||||
{
|
{
|
||||||
if (pkm.HasOriginalMetLocation)
|
if (pkm.HasOriginalMetLocation)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (pkm.Version == (int) GameVersion.GO)
|
||||||
|
return 30012;
|
||||||
if (pkm.VC1)
|
if (pkm.VC1)
|
||||||
return Legal.Transfer1;
|
return Legal.Transfer1;
|
||||||
if (pkm.VC2)
|
if (pkm.VC2)
|
||||||
return Legal.Transfer2;
|
return Legal.Transfer2;
|
||||||
if (pkm.Format == 4) // Pal Park
|
if (pkm.Format == 4) // Pal Park
|
||||||
return Legal.Transfer3;
|
return Legal.Transfer3;
|
||||||
|
|
||||||
|
if (pkm.GenNumber >= 5)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (pkm.Format >= 5) // Transporter
|
if (pkm.Format >= 5) // Transporter
|
||||||
{
|
{
|
||||||
return pkm.Gen4 && pkm.FatefulEncounter && Legal.CrownBeasts.Contains(pkm.Species)
|
return pkm.Gen4 && pkm.FatefulEncounter && Legal.CrownBeasts.Contains(pkm.Species)
|
||||||
|
|
|
@ -479,5 +479,18 @@ namespace PKHeX.Core
|
||||||
/// <param name="pk">Pokémon to modify.</param>
|
/// <param name="pk">Pokémon to modify.</param>
|
||||||
/// <param name="hptype">Desired Hidden Power typing.</param>
|
/// <param name="hptype">Desired Hidden Power typing.</param>
|
||||||
public static void SetHiddenPower(this PKM pk, MoveType hptype) => pk.SetHiddenPower((int) hptype);
|
public static void SetHiddenPower(this PKM pk, MoveType hptype) => pk.SetHiddenPower((int) hptype);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the Memory details to a Hatched Egg's memories.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pk">Pokémon to modify.</param>
|
||||||
|
public static void SetHatchMemory6(this PKM pk)
|
||||||
|
{
|
||||||
|
pk.OT_Memory = 2;
|
||||||
|
pk.OT_Affection = 0;
|
||||||
|
pk.OT_Feeling = Util.Rand.Next(0, 10);
|
||||||
|
pk.OT_Intensity = 1;
|
||||||
|
pk.OT_TextVar = pk.XY ? 43 : 27; // riverside road : battling spot
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,6 +373,8 @@ namespace PKHeX.Core
|
||||||
var loc = EncounterSuggestion.GetSuggestedEggMetLocation(pkm);
|
var loc = EncounterSuggestion.GetSuggestedEggMetLocation(pkm);
|
||||||
if (loc >= 0)
|
if (loc >= 0)
|
||||||
pkm.Met_Location = loc;
|
pkm.Met_Location = loc;
|
||||||
|
if (pkm.Gen6)
|
||||||
|
pkm.SetHatchMemory6();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -777,6 +777,7 @@ namespace PKHeX.Core
|
||||||
}
|
}
|
||||||
protected override void SetPartyValues(PKM pkm, bool isParty)
|
protected override void SetPartyValues(PKM pkm, bool isParty)
|
||||||
{
|
{
|
||||||
|
base.SetPartyValues(pkm, isParty);
|
||||||
uint duration = 0;
|
uint duration = 0;
|
||||||
if (isParty && pkm.AltForm != 0)
|
if (isParty && pkm.AltForm != 0)
|
||||||
switch (pkm.Species)
|
switch (pkm.Species)
|
||||||
|
|
|
@ -1049,6 +1049,7 @@ namespace PKHeX.Core
|
||||||
}
|
}
|
||||||
protected override void SetPartyValues(PKM pkm, bool isParty)
|
protected override void SetPartyValues(PKM pkm, bool isParty)
|
||||||
{
|
{
|
||||||
|
base.SetPartyValues(pkm, isParty);
|
||||||
uint duration = 0;
|
uint duration = 0;
|
||||||
if (isParty && pkm.AltForm != 0)
|
if (isParty && pkm.AltForm != 0)
|
||||||
switch (pkm.Species)
|
switch (pkm.Species)
|
||||||
|
|
|
@ -649,7 +649,15 @@ namespace PKHeX.Core
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void SetPartyValues(PKM pkm, bool isParty) { }
|
protected virtual void SetPartyValues(PKM pkm, bool isParty)
|
||||||
|
{
|
||||||
|
if (!isParty)
|
||||||
|
return;
|
||||||
|
if (pkm.Stat_HPMax != 0) // Stats already present
|
||||||
|
return;
|
||||||
|
pkm.SetStats(pkm.GetStats(pkm.PersonalInfo));
|
||||||
|
pkm.Stat_Level = pkm.CurrentLevel;
|
||||||
|
}
|
||||||
protected virtual void SetPKM(PKM pkm) { }
|
protected virtual void SetPKM(PKM pkm) { }
|
||||||
protected virtual void SetDex(PKM pkm) { }
|
protected virtual void SetDex(PKM pkm) { }
|
||||||
public virtual bool GetSeen(int species) => false;
|
public virtual bool GetSeen(int species) => false;
|
||||||
|
|
|
@ -14,5 +14,14 @@
|
||||||
|
|
||||||
public bool IsParty => 30 <= Slot && Slot < 36;
|
public bool IsParty => 30 <= Slot && Slot < 36;
|
||||||
public bool IsValid => Slot > -1 && (Box > -1 || IsParty);
|
public bool IsValid => Slot > -1 && (Box > -1 || IsParty);
|
||||||
|
|
||||||
|
public SlotChange() { }
|
||||||
|
public SlotChange(SlotChange info, SaveFile sav)
|
||||||
|
{
|
||||||
|
Box = info.Box;
|
||||||
|
Slot = info.Slot;
|
||||||
|
Offset = info.Offset;
|
||||||
|
PKM = sav.GetStoredSlot(info.Offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
using System;
|
|
||||||
using PKHeX.Core;
|
using PKHeX.Core;
|
||||||
|
|
||||||
namespace PKHeX.WinForms.Controls
|
namespace PKHeX.WinForms.Controls
|
||||||
|
|
|
@ -43,7 +43,6 @@ namespace PKHeX.WinForms.Controls
|
||||||
|
|
||||||
Stats.SetMainEditor(this);
|
Stats.SetMainEditor(this);
|
||||||
LoadShowdownSet = LoadShowdownSetDefault;
|
LoadShowdownSet = LoadShowdownSetDefault;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateStats() => Stats.UpdateStats();
|
private void UpdateStats() => Stats.UpdateStats();
|
||||||
|
@ -380,8 +379,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
|
|
||||||
bool tmp = FieldsLoaded;
|
bool tmp = FieldsLoaded;
|
||||||
FieldsLoaded = false;
|
FieldsLoaded = false;
|
||||||
CB_Ability.DisplayMember = "Text";
|
InitializeBinding(CB_Ability);
|
||||||
CB_Ability.ValueMember = "Value";
|
|
||||||
CB_Ability.DataSource = GetAbilityList(pkm);
|
CB_Ability.DataSource = GetAbilityList(pkm);
|
||||||
CB_Ability.SelectedIndex = GetSafeIndex(CB_Ability, abil); // restore original index if available
|
CB_Ability.SelectedIndex = GetSafeIndex(CB_Ability, abil); // restore original index if available
|
||||||
FieldsLoaded = tmp;
|
FieldsLoaded = tmp;
|
||||||
|
@ -735,13 +733,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
CB_MetLocation.SelectedValue = location;
|
CB_MetLocation.SelectedValue = location;
|
||||||
|
|
||||||
if (pkm.GenNumber == 6 && pkm.WasEgg && ModifyPKM)
|
if (pkm.GenNumber == 6 && pkm.WasEgg && ModifyPKM)
|
||||||
{
|
pkm.SetHatchMemory6();
|
||||||
pkm.OT_Memory = 2;
|
|
||||||
pkm.OT_Affection = 0;
|
|
||||||
pkm.OT_Feeling = Util.Rand.Next(0, 10);
|
|
||||||
pkm.OT_Intensity = 1;
|
|
||||||
pkm.OT_TextVar = pkm.XY ? 43 : 27; // riverside road : battling spot
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkm.CurrentLevel < minlvl)
|
if (pkm.CurrentLevel < minlvl)
|
||||||
|
@ -1034,29 +1026,19 @@ namespace PKHeX.WinForms.Controls
|
||||||
if (newTrack != origintrack)
|
if (newTrack != origintrack)
|
||||||
{
|
{
|
||||||
var met_list = GameInfo.GetLocationList(Version, pkm.Format, egg: false);
|
var met_list = GameInfo.GetLocationList(Version, pkm.Format, egg: false);
|
||||||
CB_MetLocation.DisplayMember = "Text";
|
InitializeBinding(CB_MetLocation);
|
||||||
CB_MetLocation.ValueMember = "Value";
|
|
||||||
CB_MetLocation.DataSource = new BindingSource(met_list, null);
|
CB_MetLocation.DataSource = new BindingSource(met_list, null);
|
||||||
|
|
||||||
if (FieldsLoaded)
|
if (FieldsLoaded)
|
||||||
{
|
{
|
||||||
int metLoc = 0; // transporter or pal park for past gen pkm
|
SetMarkings(); // Set/Remove the Nativity marking when gamegroup changes too
|
||||||
if (pkm.Format >= 7) // check transfer scenarios
|
pkm.Version = (int)Version;
|
||||||
switch (newTrack)
|
int metLoc = EncounterSuggestion.GetSuggestedTransferLocation(pkm);
|
||||||
{
|
CB_MetLocation.SelectedValue = Math.Max(0, metLoc);
|
||||||
case GameVersion.GO: metLoc = 30012; break;
|
|
||||||
case GameVersion.RBY: metLoc = Legal.Transfer1; break;
|
|
||||||
case GameVersion.GSC: metLoc = Legal.Transfer2; break;
|
|
||||||
}
|
|
||||||
if (metLoc != 0)
|
|
||||||
CB_MetLocation.SelectedValue = metLoc;
|
|
||||||
else
|
|
||||||
CB_MetLocation.SelectedIndex = metLoc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var egg_list = GameInfo.GetLocationList(Version, pkm.Format, egg: true);
|
var egg_list = GameInfo.GetLocationList(Version, pkm.Format, egg: true);
|
||||||
CB_EggLocation.DisplayMember = "Text";
|
InitializeBinding(CB_EggLocation);
|
||||||
CB_EggLocation.ValueMember = "Value";
|
|
||||||
CB_EggLocation.DataSource = new BindingSource(egg_list, null);
|
CB_EggLocation.DataSource = new BindingSource(egg_list, null);
|
||||||
if (FieldsLoaded)
|
if (FieldsLoaded)
|
||||||
CB_EggLocation.SelectedIndex = CHK_AsEgg.Checked ? 1 : 0; // daycare : none
|
CB_EggLocation.SelectedIndex = CHK_AsEgg.Checked ? 1 : 0; // daycare : none
|
||||||
|
@ -1076,9 +1058,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
// Visibility logic for Gen 4 encounter type; only show for Gen 4 Pokemon.
|
// Visibility logic for Gen 4 encounter type; only show for Gen 4 Pokemon.
|
||||||
if (pkm.Format >= 4)
|
if (pkm.Format >= 4)
|
||||||
{
|
{
|
||||||
bool g4 = Version >= GameVersion.HG && Version <= GameVersion.Pt;
|
bool g4 = pkm.Gen4;
|
||||||
if ((int)Version == 9) // invalid
|
|
||||||
g4 = false;
|
|
||||||
CB_EncounterType.Visible = Label_EncounterType.Visible = g4 && pkm.Format < 7;
|
CB_EncounterType.Visible = Label_EncounterType.Visible = g4 && pkm.Format < 7;
|
||||||
if (!g4)
|
if (!g4)
|
||||||
CB_EncounterType.SelectedValue = 0;
|
CB_EncounterType.SelectedValue = 0;
|
||||||
|
@ -1087,7 +1067,6 @@ namespace PKHeX.WinForms.Controls
|
||||||
if (!FieldsLoaded)
|
if (!FieldsLoaded)
|
||||||
return;
|
return;
|
||||||
pkm.Version = (int)Version;
|
pkm.Version = (int)Version;
|
||||||
SetMarkings(); // Set/Remove KB marking
|
|
||||||
UpdateLegality();
|
UpdateLegality();
|
||||||
}
|
}
|
||||||
private void UpdateExtraByteValue(object sender, EventArgs e)
|
private void UpdateExtraByteValue(object sender, EventArgs e)
|
||||||
|
@ -1690,7 +1669,8 @@ namespace PKHeX.WinForms.Controls
|
||||||
CB_Country, CB_SubRegion, CB_3DSReg, CB_Language, CB_Ball, CB_HeldItem, CB_Species, DEV_Ability,
|
CB_Country, CB_SubRegion, CB_3DSReg, CB_Language, CB_Ball, CB_HeldItem, CB_Species, DEV_Ability,
|
||||||
CB_Nature, CB_EncounterType, CB_GameOrigin,
|
CB_Nature, CB_EncounterType, CB_GameOrigin,
|
||||||
};
|
};
|
||||||
foreach (var cb in cbs) { cb.DisplayMember = "Text"; cb.ValueMember = "Value"; }
|
foreach (var cb in cbs)
|
||||||
|
InitializeBinding(cb);
|
||||||
|
|
||||||
// Set the various ComboBox DataSources up with their allowed entries
|
// Set the various ComboBox DataSources up with their allowed entries
|
||||||
SetCountrySubRegion(CB_Country, "countries");
|
SetCountrySubRegion(CB_Country, "countries");
|
||||||
|
@ -1728,7 +1708,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
GameInfo.MoveDataSource = (HaX ? GameInfo.HaXMoveDataSource : GameInfo.LegalMoveDataSource).Where(m => m.Value <= SAV.MaxMoveID).ToList(); // Filter Z-Moves if appropriate
|
GameInfo.MoveDataSource = (HaX ? GameInfo.HaXMoveDataSource : GameInfo.LegalMoveDataSource).Where(m => m.Value <= SAV.MaxMoveID).ToList(); // Filter Z-Moves if appropriate
|
||||||
foreach (var cb in Moves.Concat(Relearn))
|
foreach (var cb in Moves.Concat(Relearn))
|
||||||
{
|
{
|
||||||
cb.DisplayMember = "Text"; cb.ValueMember = "Value";
|
InitializeBinding(cb);
|
||||||
cb.DataSource = new BindingSource(GameInfo.MoveDataSource, null);
|
cb.DataSource = new BindingSource(GameInfo.MoveDataSource, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1747,5 +1727,10 @@ namespace PKHeX.WinForms.Controls
|
||||||
suggestion.Add($"Current Level: {minlvl}");
|
suggestion.Add($"Current Level: {minlvl}");
|
||||||
return suggestion;
|
return suggestion;
|
||||||
}
|
}
|
||||||
|
private static void InitializeBinding(ListControl cb)
|
||||||
|
{
|
||||||
|
cb.DisplayMember = nameof(ComboItem.Text);
|
||||||
|
cb.ValueMember = nameof(ComboItem.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,13 +74,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
{
|
{
|
||||||
if (info.Slot < 30)
|
if (info.Slot < 30)
|
||||||
{
|
{
|
||||||
m.SE.UndoStack.Push(new SlotChange
|
m.SE.UndoStack.Push(new SlotChange(info, sav));
|
||||||
{
|
|
||||||
Box = info.Box,
|
|
||||||
Slot = info.Slot,
|
|
||||||
Offset = info.Offset,
|
|
||||||
PKM = sav.GetStoredSlot(info.Offset)
|
|
||||||
});
|
|
||||||
m.SE.Menu_Undo.Enabled = true;
|
m.SE.Menu_Undo.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,13 +110,7 @@ namespace PKHeX.WinForms.Controls
|
||||||
{
|
{
|
||||||
if (info.Slot < 30)
|
if (info.Slot < 30)
|
||||||
{
|
{
|
||||||
m.SE.UndoStack.Push(new SlotChange
|
m.SE.UndoStack.Push(new SlotChange(info, sav));
|
||||||
{
|
|
||||||
Box = info.Box,
|
|
||||||
Slot = info.Slot,
|
|
||||||
Offset = info.Offset,
|
|
||||||
PKM = sav.GetStoredSlot(info.Offset)
|
|
||||||
});
|
|
||||||
m.SE.Menu_Undo.Enabled = true;
|
m.SE.Menu_Undo.Enabled = true;
|
||||||
}
|
}
|
||||||
m.SetPKM(sav.BlankPKM, info, true, Resources.slotDel);
|
m.SetPKM(sav.BlankPKM, info, true, Resources.slotDel);
|
||||||
|
|
|
@ -395,11 +395,6 @@ namespace PKHeX.WinForms.Controls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pk.Stat_HPMax == 0) // Without Stats (Box)
|
|
||||||
{
|
|
||||||
pk.SetStats(pk.GetStats(SAV.Personal.GetFormeEntry(pk.Species, pk.AltForm)));
|
|
||||||
pk.Stat_Level = pk.CurrentLevel;
|
|
||||||
}
|
|
||||||
SAV.SetPartySlot(pk, o);
|
SAV.SetPartySlot(pk, o);
|
||||||
SE.SetParty();
|
SE.SetParty();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue