Rework & fix party slot deletion

Two birds with one stone:
- sav4 doesn't use Data (instead uses General/Storage), so we need to
use the abstracted method calls instead of trying to do things manually.
- setting a blank pkm at a party slot will decrease the party count!
don't decrease things twice.
This commit is contained in:
Kurt 2019-10-18 21:10:39 -07:00
parent c3a6fd2a64
commit 3b0fd81aae

View file

@ -424,17 +424,17 @@ namespace PKHeX.Core
public void DeletePartySlot(int slot)
{
if (PartyCount <= slot) // beyond party range (or empty data already present)
int newEmpty = PartyCount - 1;
if ((uint)slot > newEmpty) // beyond party range (or empty data already present)
return;
// Move all party slots down one
for (int i = slot + 1; i < 6; i++) // Slide slots down
for (int i = slot + 1; i <= newEmpty; i++) // Slide slots down
{
int slotTo = GetPartyOffset(i - 1);
int slotFrom = GetPartyOffset(i);
SetData(GetData(slotFrom, SIZE_PARTY), slotTo);
var current = GetPartySlotAtIndex(i);
SetPartySlotAtIndex(current, i - 1, PKMImportSetting.Skip, PKMImportSetting.Skip);
}
SetPartySlot(BlankPKM, GetPartyOffset(5), PKMImportSetting.Skip, PKMImportSetting.Skip);
PartyCount--;
SetPartySlotAtIndex(BlankPKM, newEmpty, PKMImportSetting.Skip, PKMImportSetting.Skip);
// PartyCount will automatically update via above call. Do not adjust.
}
#region Slot Storing