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:
Kurt 2018-03-25 19:05:49 -07:00
parent a24e5aa742
commit 99a4c55579
11 changed files with 62 additions and 55 deletions

View file

@ -5,7 +5,7 @@ namespace PKHeX.Core
/// <summary>
/// Logic for providing suggested property values with respect to the input data.
/// </summary>
internal static class EncounterSuggestion
public static class EncounterSuggestion
{
public static EncounterStatic GetSuggestedMetInfo(PKM pkm)
{
@ -120,16 +120,22 @@ namespace PKHeX.Core
/// <remarks>
/// Returns -1 if the met location is not overriden with a transfer location
/// </remarks>
private static int GetSuggestedTransferLocation(PKM pkm)
public static int GetSuggestedTransferLocation(PKM pkm)
{
if (pkm.HasOriginalMetLocation)
return -1;
if (pkm.Version == (int) GameVersion.GO)
return 30012;
if (pkm.VC1)
return Legal.Transfer1;
if (pkm.VC2)
return Legal.Transfer2;
if (pkm.Format == 4) // Pal Park
return Legal.Transfer3;
if (pkm.GenNumber >= 5)
return -1;
if (pkm.Format >= 5) // Transporter
{
return pkm.Gen4 && pkm.FatefulEncounter && Legal.CrownBeasts.Contains(pkm.Species)

View file

@ -479,5 +479,18 @@ namespace PKHeX.Core
/// <param name="pk">Pokémon to modify.</param>
/// <param name="hptype">Desired Hidden Power typing.</param>
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
}
}
}

View file

@ -373,6 +373,8 @@ namespace PKHeX.Core
var loc = EncounterSuggestion.GetSuggestedEggMetLocation(pkm);
if (loc >= 0)
pkm.Met_Location = loc;
if (pkm.Gen6)
pkm.SetHatchMemory6();
}
/// <summary>

View file

@ -777,6 +777,7 @@ namespace PKHeX.Core
}
protected override void SetPartyValues(PKM pkm, bool isParty)
{
base.SetPartyValues(pkm, isParty);
uint duration = 0;
if (isParty && pkm.AltForm != 0)
switch (pkm.Species)

View file

@ -1049,6 +1049,7 @@ namespace PKHeX.Core
}
protected override void SetPartyValues(PKM pkm, bool isParty)
{
base.SetPartyValues(pkm, isParty);
uint duration = 0;
if (isParty && pkm.AltForm != 0)
switch (pkm.Species)

View file

@ -649,7 +649,15 @@ namespace PKHeX.Core
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 SetDex(PKM pkm) { }
public virtual bool GetSeen(int species) => false;

View file

@ -14,5 +14,14 @@
public bool IsParty => 30 <= Slot && Slot < 36;
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);
}
}
}

View file

@ -1,4 +1,3 @@
using System;
using PKHeX.Core;
namespace PKHeX.WinForms.Controls

View file

@ -43,7 +43,6 @@ namespace PKHeX.WinForms.Controls
Stats.SetMainEditor(this);
LoadShowdownSet = LoadShowdownSetDefault;
}
private void UpdateStats() => Stats.UpdateStats();
@ -380,8 +379,7 @@ namespace PKHeX.WinForms.Controls
bool tmp = FieldsLoaded;
FieldsLoaded = false;
CB_Ability.DisplayMember = "Text";
CB_Ability.ValueMember = "Value";
InitializeBinding(CB_Ability);
CB_Ability.DataSource = GetAbilityList(pkm);
CB_Ability.SelectedIndex = GetSafeIndex(CB_Ability, abil); // restore original index if available
FieldsLoaded = tmp;
@ -735,13 +733,7 @@ namespace PKHeX.WinForms.Controls
CB_MetLocation.SelectedValue = location;
if (pkm.GenNumber == 6 && pkm.WasEgg && ModifyPKM)
{
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
}
pkm.SetHatchMemory6();
}
if (pkm.CurrentLevel < minlvl)
@ -1034,29 +1026,19 @@ namespace PKHeX.WinForms.Controls
if (newTrack != origintrack)
{
var met_list = GameInfo.GetLocationList(Version, pkm.Format, egg: false);
CB_MetLocation.DisplayMember = "Text";
CB_MetLocation.ValueMember = "Value";
InitializeBinding(CB_MetLocation);
CB_MetLocation.DataSource = new BindingSource(met_list, null);
if (FieldsLoaded)
{
int metLoc = 0; // transporter or pal park for past gen pkm
if (pkm.Format >= 7) // check transfer scenarios
switch (newTrack)
{
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;
SetMarkings(); // Set/Remove the Nativity marking when gamegroup changes too
pkm.Version = (int)Version;
int metLoc = EncounterSuggestion.GetSuggestedTransferLocation(pkm);
CB_MetLocation.SelectedValue = Math.Max(0, metLoc);
}
var egg_list = GameInfo.GetLocationList(Version, pkm.Format, egg: true);
CB_EggLocation.DisplayMember = "Text";
CB_EggLocation.ValueMember = "Value";
InitializeBinding(CB_EggLocation);
CB_EggLocation.DataSource = new BindingSource(egg_list, null);
if (FieldsLoaded)
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.
if (pkm.Format >= 4)
{
bool g4 = Version >= GameVersion.HG && Version <= GameVersion.Pt;
if ((int)Version == 9) // invalid
g4 = false;
bool g4 = pkm.Gen4;
CB_EncounterType.Visible = Label_EncounterType.Visible = g4 && pkm.Format < 7;
if (!g4)
CB_EncounterType.SelectedValue = 0;
@ -1087,7 +1067,6 @@ namespace PKHeX.WinForms.Controls
if (!FieldsLoaded)
return;
pkm.Version = (int)Version;
SetMarkings(); // Set/Remove KB marking
UpdateLegality();
}
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_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
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
foreach (var cb in Moves.Concat(Relearn))
{
cb.DisplayMember = "Text"; cb.ValueMember = "Value";
InitializeBinding(cb);
cb.DataSource = new BindingSource(GameInfo.MoveDataSource, null);
}
}
@ -1747,5 +1727,10 @@ namespace PKHeX.WinForms.Controls
suggestion.Add($"Current Level: {minlvl}");
return suggestion;
}
private static void InitializeBinding(ListControl cb)
{
cb.DisplayMember = nameof(ComboItem.Text);
cb.ValueMember = nameof(ComboItem.Value);
}
}
}

View file

@ -74,13 +74,7 @@ namespace PKHeX.WinForms.Controls
{
if (info.Slot < 30)
{
m.SE.UndoStack.Push(new SlotChange
{
Box = info.Box,
Slot = info.Slot,
Offset = info.Offset,
PKM = sav.GetStoredSlot(info.Offset)
});
m.SE.UndoStack.Push(new SlotChange(info, sav));
m.SE.Menu_Undo.Enabled = true;
}
@ -116,13 +110,7 @@ namespace PKHeX.WinForms.Controls
{
if (info.Slot < 30)
{
m.SE.UndoStack.Push(new SlotChange
{
Box = info.Box,
Slot = info.Slot,
Offset = info.Offset,
PKM = sav.GetStoredSlot(info.Offset)
});
m.SE.UndoStack.Push(new SlotChange(info, sav));
m.SE.Menu_Undo.Enabled = true;
}
m.SetPKM(sav.BlankPKM, info, true, Resources.slotDel);

View file

@ -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);
SE.SetParty();
}