PKHeX/PKHeX.Core/Saves/Substructures/Gen6/SubEventLog6.cs
Kurt f4bafe0809 Add extension methods for gym team get/set for all
Closes #2607

SAV6XY/AO had GymTeams get/set, this now makes similar logic accessible
for even SAV5BW/B2W2.
2019-12-28 22:32:45 -08:00

45 lines
No EOL
1.5 KiB
C#

using System;
namespace PKHeX.Core
{
public abstract class SubEventLog6 : SaveBlock, IGymTeamInfo
{
protected SubEventLog6(SAV6 sav, int offset) : base(sav) => Offset = offset;
protected abstract int BadgeVictoryOffset { get; }
private int GetBadgeVictorySpeciesOffset(uint badge, uint slot)
{
if (badge >= 8)
throw new ArgumentException(nameof(badge));
if (slot >= 6)
throw new ArgumentException(nameof(slot));
return Offset + BadgeVictoryOffset + (int)(((6 * badge) + slot) * sizeof(ushort));
}
public ushort GetBadgeVictorySpecies(uint badge, uint slot)
{
var ofs = GetBadgeVictorySpeciesOffset(badge, slot);
return BitConverter.ToUInt16(Data, ofs);
}
public void SetBadgeVictorySpecies(uint badge, uint slot, ushort species)
{
var ofs = GetBadgeVictorySpeciesOffset(badge, slot);
SAV.SetData(BitConverter.GetBytes(species), ofs);
}
}
public sealed class SubEventLog6XY : SubEventLog6
{
public SubEventLog6XY(SAV6XY sav, int offset) : base(sav, offset) { }
protected override int BadgeVictoryOffset => 0x2C; // thru 0x8B
}
public sealed class SubEventLog6AO : SubEventLog6
{
public SubEventLog6AO(SAV6AO sav, int offset) : base(sav, offset) { }
protected override int BadgeVictoryOffset => 0x60; // thru 0xBF
}
}