PKHeX/PKHeX.Core/Editing/Saves/Slots/Info/SlotInfoParty.cs
Kurt 0ffb256052 Add slot source legality checks
Useful for save files with misplaced data (you really have to be using the program weirdly to get these flagged).
Stuff like Eggs deposited in Daycare, non-fuseable species in the Fused slots, etc.

Allow HaX to view any slot, & Delete if Set is allowed
2024-06-15 00:14:49 -05:00

33 lines
1.0 KiB
C#

using System;
namespace PKHeX.Core;
/// <summary>
/// Party Data <see cref="ISlotInfo"/>
/// </summary>
public sealed record SlotInfoParty(int Slot) : ISlotInfo
{
public int Slot { get; private set; } = Slot;
public StorageSlotType Type => StorageSlotType.Party;
public bool CanWriteTo(SaveFile sav) => sav.HasParty;
public WriteBlockedMessage CanWriteTo(SaveFile sav, PKM pk) => pk.IsEgg && sav.IsPartyAllEggs(Slot)
? WriteBlockedMessage.InvalidPartyConfiguration
: WriteBlockedMessage.None;
public bool WriteTo(SaveFile sav, PKM pk, PKMImportSetting setting = PKMImportSetting.UseDefault)
{
if (pk.Species == 0)
{
sav.DeletePartySlot(Slot);
Slot = Math.Max(0, sav.PartyCount - 1);
return true;
}
Slot = Math.Min(Slot, sav.PartyCount); // realign if necessary
sav.SetPartySlotAtIndex(pk, Slot, setting, setting);
return true;
}
public PKM Read(SaveFile sav) => sav.GetPartySlotAtIndex(Slot);
}