gen4 wondercard updates continued

Don't set Slot to 3 for an empty slot
Move slot check comparison to PCD class
Allow PCD->PGT 'swap' override to just set the slot
Update alert message to indicate source type first

#730
This commit is contained in:
Kurt 2017-01-20 19:35:56 -08:00
parent 4f99ef6c09
commit eaa233bdd8
3 changed files with 28 additions and 9 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;