diff --git a/PKHeX.Core/Legality/Verifiers/Egg/EggStateLegality.cs b/PKHeX.Core/Legality/Verifiers/Egg/EggStateLegality.cs index 55480852293..9f11d0dbf6b 100644 --- a/PKHeX.Core/Legality/Verifiers/Egg/EggStateLegality.cs +++ b/PKHeX.Core/Legality/Verifiers/Egg/EggStateLegality.cs @@ -2,13 +2,40 @@ { public static class EggStateLegality { - public static int GetMinimumEggHatchCycles(PKM pkm) => pkm switch + public static bool GetIsEggHatchCyclesValid(PKM pk, IEncounterTemplate enc) + { + var hatchCounter = pk.OT_Friendship; + var max = GetMaximumEggHatchCycles(pk, enc); + if (hatchCounter > max) + return false; + var min = GetMinimumEggHatchCycles(pk); + if (hatchCounter < min) + return false; + + return true; + } + + public static int GetMinimumEggHatchCycles(PKM pk) => pk switch { PK7 => 0, // pelago can decrement to 0 _ => 1, // whenever it hits 0, it hatches, so anything above that is fine. }; - public static bool IsValidHTEgg(PKM pkm) => pkm switch + public static int GetMaximumEggHatchCycles(PKM pk) + { + var la = new LegalityAnalysis(pk); + var enc = la.EncounterMatch; + return GetMaximumEggHatchCycles(pk, enc); + } + + public static int GetMaximumEggHatchCycles(PKM pk, IEncounterTemplate enc) + { + if (enc is EncounterStatic { EggCycles: not 0 } s) + return s.EggCycles; + return pk.PersonalInfo.HatchCycles; + } + + public static bool IsValidHTEgg(PKM pk) => pk switch { PB8 { Met_Location: Locations.LinkTrade6NPC } pb8 when pb8.HT_Friendship == PersonalTable.BDSP[pb8.Species].BaseFriendship => true, _ => false, diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index 46660179d8d..560cb08b1de 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -262,10 +262,7 @@ private static void VerifyMiscEggCommon(LegalityAnalysis data) data.AddLine(GetInvalid(LEggPP, Egg)); var enc = data.EncounterMatch; - var HatchCycles = enc is EncounterStatic s ? s.EggCycles : 0; - if (HatchCycles == 0) // no value set - HatchCycles = pkm.PersonalInfo.HatchCycles; - if (pkm.OT_Friendship > HatchCycles || pkm.OT_Friendship < EggStateLegality.GetMinimumEggHatchCycles(pkm)) + if (!EggStateLegality.GetIsEggHatchCyclesValid(pkm, enc)) data.AddLine(GetInvalid(LEggHatchCycles, Egg)); if (pkm.Format >= 6 && enc is EncounterEgg && !MovesMatchRelearn(pkm)) diff --git a/PKHeX.Core/PKM/PB8.cs b/PKHeX.Core/PKM/PB8.cs index 9cfd31ef429..b4ed9383713 100644 --- a/PKHeX.Core/PKM/PB8.cs +++ b/PKHeX.Core/PKM/PB8.cs @@ -97,7 +97,7 @@ private void TradeHT(ITrainerInfo tr) { if (HT_Name != tr.OT) { - HT_Friendship = 50; + HT_Friendship = PersonalInfo.BaseFriendship; HT_Name = tr.OT; } CurrentHandler = 1; diff --git a/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs b/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs index 25298a690b8..1b4e97dd980 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/LoadSave.cs @@ -177,12 +177,19 @@ private void LoadMisc2(PKM pk) if (pk is IFormArgument f) FA_Form.LoadArgument(f, pk.Species, pk.Form, pk.Format); - TB_Friendship.Text = pk.CurrentFriendship.ToString(); + ReloadToFriendshipTextBox(pk); Label_HatchCounter.Visible = CHK_IsEgg.Checked; Label_Friendship.Visible = !CHK_IsEgg.Checked; } + private void ReloadToFriendshipTextBox(PKM pk) + { + // Show OT friendship always if it is an egg. + var fs = (pk.IsEgg ? pk.OT_Friendship : pk.CurrentFriendship); + TB_Friendship.Text = fs.ToString(); + } + private void SaveMisc2(PKM pk) { SavePKRS(pk); @@ -191,7 +198,17 @@ private void SaveMisc2(PKM pk) pk.Form = CB_Form.Enabled ? CB_Form.SelectedIndex & 0x1F : 0; if (Entity is IFormArgument f) FA_Form.SaveArgument(f); - pk.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); + + var friendship = Util.ToInt32(TB_Friendship.Text); + UpdateFromFriendshipTextBox(pk, friendship); + } + + private static void UpdateFromFriendshipTextBox(PKM pk, int friendship) + { + if (pk.IsEgg) + pk.OT_Friendship = friendship; + else + pk.CurrentFriendship = friendship; } private void LoadMisc3(PKM pk) diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs index 70e158b15ee..d0ce1189bc5 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.Designer.cs @@ -960,6 +960,7 @@ private void InitializeComponent() this.Label_HatchCounter.TabIndex = 61; this.Label_HatchCounter.Text = "Hatch Counter:"; this.Label_HatchCounter.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.Label_HatchCounter.Click += new System.EventHandler(this.ClickFriendship); // // FLP_FriendshipRight // diff --git a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs index 182d5fc498e..7a393c6d5fd 100644 --- a/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs +++ b/PKHeX.WinForms/Controls/PKM Editor/PKMEditor.cs @@ -572,10 +572,10 @@ private static void SetCountrySubRegion(ComboBox cb, string type) // Prompted Updates of PKM // private void ClickFriendship(object sender, EventArgs e) { - if (ModifierKeys == Keys.Control) // clear - TB_Friendship.Text = "0"; + if (ModifierKeys == Keys.Control ^ CHK_IsEgg.Checked) // clear + TB_Friendship.Text = CHK_IsEgg.Checked ? EggStateLegality.GetMinimumEggHatchCycles(Entity).ToString() : "0"; else - TB_Friendship.Text = TB_Friendship.Text == "255" ? Entity.PersonalInfo.BaseFriendship.ToString() : "255"; + TB_Friendship.Text = CHK_IsEgg.Checked ? EggStateLegality.GetMaximumEggHatchCycles(Entity).ToString() : TB_Friendship.Text == "255" ? Entity.PersonalInfo.BaseFriendship.ToString() : "255"; } private void ClickLevel(object sender, EventArgs e) @@ -706,7 +706,7 @@ private void ClickGT(object? sender, EventArgs e) Entity.CurrentHandler = 1; UpadteHandlingTrainerBackground(Entity.CurrentHandler); - TB_Friendship.Text = Entity.CurrentFriendship.ToString(); + ReloadToFriendshipTextBox(Entity); } private void ClickNature(object sender, EventArgs e) @@ -972,7 +972,7 @@ private void Update255_MTB(object sender, EventArgs e) tb.Text = "255"; if (sender == TB_Friendship && int.TryParse(TB_Friendship.Text, out var val)) { - Entity.CurrentFriendship = val; + UpdateFromFriendshipTextBox(Entity, val); UpdateStats(); } } @@ -1383,7 +1383,7 @@ private void UpdateNotOT(object sender, EventArgs e) { ClickGT(GB_OT, EventArgs.Empty); // Switch CT over to OT. Label_CTGender.Text = string.Empty; - TB_Friendship.Text = Entity.CurrentFriendship.ToString(); + ReloadToFriendshipTextBox(Entity); } else if (string.IsNullOrWhiteSpace(Label_CTGender.Text)) { @@ -1766,10 +1766,10 @@ private void OpenHistory(object sender, EventArgs e) Entity.HT_Name = TB_OTt2.Text; Entity.OT_Name = TB_OT.Text; Entity.IsEgg = CHK_IsEgg.Checked; - Entity.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); + UpdateFromFriendshipTextBox(Entity, Util.ToInt32(TB_Friendship.Text)); using var form = new MemoryAmie(Entity); form.ShowDialog(); - TB_Friendship.Text = Entity.CurrentFriendship.ToString(); + ReloadToFriendshipTextBox(Entity); } private void B_Records_Click(object sender, EventArgs e) diff --git a/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs b/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs index e4a78ccbe72..fa6e919edbc 100644 --- a/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs +++ b/PKHeX.WinForms/Subforms/PKM Editors/MemoryAmie.cs @@ -101,7 +101,7 @@ private void LoadFields() GB_M_OT.Enabled = GB_M_CT.Enabled = GB_Residence.Enabled = BTN_Save.Enabled = M_Fullness.Enabled = M_Enjoyment.Enabled = L_Sociability.Enabled = MT_Sociability.Enabled = - L_Fullness.Enabled = L_Enjoyment.Enabled = !pkm.IsEgg; + L_Fullness.Enabled = L_Enjoyment.Enabled = !(pkm.IsEgg && pkm.IsUntraded && pkm.HT_Friendship == 0); if (!pkm.IsEgg) {