2018-06-10 04:04:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using static PKHeX.Core.OPower6Type;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2019-10-04 02:09:02 +00:00
|
|
|
|
public sealed class OPower6 : SaveBlock
|
2018-06-10 04:04:34 +00:00
|
|
|
|
{
|
|
|
|
|
private static readonly OPowerFlagSet[] Mapping =
|
|
|
|
|
{
|
2021-08-20 20:42:25 +00:00
|
|
|
|
// Skip unused byte
|
|
|
|
|
new(5, Hatching) {Offset = 1},
|
|
|
|
|
new(5, Bargain) {Offset = 6},
|
|
|
|
|
new(5, Prize_Money) {Offset = 11},
|
|
|
|
|
new(5, Exp_Point) {Offset = 16},
|
|
|
|
|
new(5, Capture) {Offset = 21},
|
|
|
|
|
|
|
|
|
|
new(3, Encounter) {Offset = 26},
|
|
|
|
|
new(3, Stealth) {Offset = 29},
|
|
|
|
|
new(3, HP_Restoring) {Offset = 32},
|
|
|
|
|
new(3, PP_Restoring) {Offset = 35},
|
|
|
|
|
|
|
|
|
|
new(1, Full_Recovery) {Offset = 38},
|
|
|
|
|
|
|
|
|
|
new(5, Befriending) {Offset = 39},
|
|
|
|
|
|
|
|
|
|
new(3, Attack) {Offset = 44},
|
|
|
|
|
new(3, Defense) {Offset = 47},
|
|
|
|
|
new(3, Sp_Attack) {Offset = 50},
|
|
|
|
|
new(3, Sp_Defense) {Offset = 53},
|
|
|
|
|
new(3, Speed) {Offset = 56},
|
|
|
|
|
new(3, Critical) {Offset = 59},
|
|
|
|
|
new(3, Accuracy) {Offset = 62},
|
2018-06-10 04:04:34 +00:00
|
|
|
|
};
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public OPower6(SaveFile sav, int offset) : base(sav) => Offset = offset;
|
2018-06-10 04:04:34 +00:00
|
|
|
|
|
2019-10-26 19:33:58 +00:00
|
|
|
|
private static OPowerFlagSet Get(OPower6Type type) => Array.Find(Mapping, t => t.Identifier == type);
|
|
|
|
|
public static int GetOPowerCount(OPower6Type type) => Get(type).BaseCount;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public int GetOPowerLevel(OPower6Type type) => Get(type).GetOPowerLevel(Data.AsSpan(Offset));
|
2019-10-26 19:33:58 +00:00
|
|
|
|
|
|
|
|
|
public static bool GetHasOPowerS(OPower6Type type) => Get(type).HasOPowerS;
|
|
|
|
|
public static bool GetHasOPowerMAX(OPower6Type type) => Get(type).HasOPowerMAX;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public bool GetOPowerS(OPower6Type type) => Get(type).GetOPowerS(Data.AsSpan(Offset));
|
|
|
|
|
public bool GetOPowerMAX(OPower6Type type) => Get(type).GetOPowerMAX(Data.AsSpan(Offset));
|
2019-10-26 19:33:58 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public void SetOPowerLevel(OPower6Type type, int lvl) => Get(type).SetOPowerLevel(Data.AsSpan(Offset), lvl);
|
|
|
|
|
public void SetOPowerS(OPower6Type type, bool value) => Get(type).SetOPowerS(Data.AsSpan(Offset), value);
|
|
|
|
|
public void SetOPowerMAX(OPower6Type type, bool value) => Get(type).SetOPowerMAX(Data.AsSpan(Offset), value);
|
2018-06-10 18:28:20 +00:00
|
|
|
|
|
2018-06-10 04:04:34 +00:00
|
|
|
|
public bool MasterFlag
|
|
|
|
|
{
|
|
|
|
|
get => Data[Offset] == 1;
|
|
|
|
|
set => Data[Offset] = (byte) (value ? OPowerFlagState.Unlocked : OPowerFlagState.Locked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UnlockAll() => ToggleFlags(allEvents: true);
|
2018-06-10 21:07:36 +00:00
|
|
|
|
public void UnlockRegular() => ToggleFlags();
|
2018-06-10 04:04:34 +00:00
|
|
|
|
public void ClearAll() => ToggleFlags(clearOnly: true);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-06-10 19:27:53 +00:00
|
|
|
|
private void ToggleFlags(bool allEvents = false, bool clearOnly = false)
|
2018-06-10 04:04:34 +00:00
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
var span = Data.AsSpan(Offset);
|
2018-06-10 04:04:34 +00:00
|
|
|
|
foreach (var m in Mapping)
|
|
|
|
|
{
|
|
|
|
|
// Clear before applying new value
|
2022-01-03 05:35:59 +00:00
|
|
|
|
m.SetOPowerLevel(span, 0);
|
|
|
|
|
m.SetOPowerS(span, false);
|
|
|
|
|
m.SetOPowerMAX(span, false);
|
2018-06-10 04:04:34 +00:00
|
|
|
|
|
|
|
|
|
if (clearOnly)
|
|
|
|
|
continue;
|
|
|
|
|
|
2018-06-10 19:27:53 +00:00
|
|
|
|
int lvl = allEvents ? m.BaseCount : (m.BaseCount != 1 ? 3 : 0); // Full_Recovery is ORAS/event only @ 1 level
|
2022-01-03 05:35:59 +00:00
|
|
|
|
m.SetOPowerLevel(span, lvl);
|
2018-06-10 19:27:53 +00:00
|
|
|
|
if (!allEvents)
|
|
|
|
|
continue;
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
m.SetOPowerS(span, true);
|
|
|
|
|
m.SetOPowerMAX(span, true);
|
2018-06-10 04:04:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] Write() => Data;
|
|
|
|
|
}
|
|
|
|
|
}
|