diff --git a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs index e0c5c4660..4065696e5 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/SAV_Wondercard.cs @@ -407,7 +407,7 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) // Hijack to the latest unfilled slot if index creates interstitial empty slots. int lastUnfilled = getLastUnfilledByType(mg, mga); - if (lastUnfilled > -1 && lastUnfilled < index) + if (lastUnfilled > -1 && lastUnfilled < index && mga.Gifts[lastUnfilled].Type == mga.Gifts[index].Type) index = lastUnfilled; if (wc_slot == -1) // dropped @@ -420,17 +420,17 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) { WinFormsUtil.Alert("Data size invalid.", files[0]); return; } byte[] data = File.ReadAllBytes(files[0]); - MysteryGift mg = MysteryGift.getMysteryGift(data, new FileInfo(files[0]).Extension); + MysteryGift gift = MysteryGift.getMysteryGift(data, new FileInfo(files[0]).Extension); - if (mg is PCD && mga.Gifts[index] is PGT) - mg = (mg as PCD).Gift; - else if (mg.Type != mga.Gifts[index].Type) + if (gift is PCD && mga.Gifts[index] is PGT) + gift = (gift as PCD).Gift; + else if (gift.Type != mga.Gifts[index].Type) { - WinFormsUtil.Alert("Can't set slot here.", $"{mg.Type} != {mga.Gifts[index].Type}"); + WinFormsUtil.Alert("Can't set slot here.", $"{gift.Type} != {mga.Gifts[index].Type}"); return; } setBackground(index, Core.Properties.Resources.slotSet); - mga.Gifts[index] = mg.Clone(); + mga.Gifts[index] = gift.Clone(); setCardID(mga.Gifts[index].CardID); viewGiftData(mga.Gifts[index]); @@ -440,8 +440,15 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) MysteryGift s1 = mga.Gifts[index]; MysteryGift s2 = mga.Gifts[wc_slot]; + if (s2 is PCD && s1 is PGT) + { + // set the PGT to the PGT slot instead + viewGiftData(s2); + clickSet(pba[index], null); + { WinFormsUtil.Alert($"Set {s2.Type} gift to {s1.Type} slot."); return; } + } if (s1.Type != s2.Type) - { WinFormsUtil.Alert($"Can't swap {s1.Type} with {s2.Type}."); return; } + { WinFormsUtil.Alert($"Can't swap {s2.Type} with {s1.Type}."); return; } mga.Gifts[wc_slot] = s1; mga.Gifts[index] = s2; diff --git a/PKHeX/MysteryGifts/PGT.cs b/PKHeX/MysteryGifts/PGT.cs index d127a2b9b..5ec68cac5 100644 --- a/PKHeX/MysteryGifts/PGT.cs +++ b/PKHeX/MysteryGifts/PGT.cs @@ -67,6 +67,12 @@ public override string CardTitle public override bool IsShiny => Gift.IsShiny; public override bool IsEgg { get { return Gift.IsEgg; } set { Gift.IsEgg = value; } } + public bool GiftEquals(PGT pgt) + { + // Skip over the PGT's "Corresponding PCD Slot" + return Gift.Data.Take(2).Skip(1).SequenceEqual(pgt.Data.Take(2).Skip(1)); + } + public override PKM convertToPKM(SaveFile SAV) { return Gift.convertToPKM(SAV); diff --git a/PKHeX/Saves/SAV4.cs b/PKHeX/Saves/SAV4.cs index b33a88eab..14dd12e39 100644 --- a/PKHeX/Saves/SAV4.cs +++ b/PKHeX/Saves/SAV4.cs @@ -605,6 +605,12 @@ private static int[] matchMysteryGifts(MysteryGift[] value) if (pgt == null) continue; + if (pgt.CardType == 0) // empty + { + cardMatch[i] = pgt.Slot = 0; + continue; + } + cardMatch[i] = pgt.Slot = 3; for (byte j = 0; j < 3; j++) { @@ -613,7 +619,7 @@ private static int[] matchMysteryGifts(MysteryGift[] value) continue; // Check if data matches (except Slot @ 0x02) - if (!pcd.Gift.Data.Take(2).Skip(1).SequenceEqual(pgt.Data.Take(2).Skip(1))) + if (!pcd.GiftEquals(pgt)) continue; cardMatch[i] = pgt.Slot = j;