2018-06-10 18:28:20 +00:00
|
|
|
using System;
|
2018-06-10 04:04:34 +00:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
internal class OPowerFlagSet
|
|
|
|
{
|
|
|
|
public readonly OPower6Type Identifier;
|
|
|
|
public readonly int Count;
|
|
|
|
public int Offset;
|
2018-06-10 18:28:20 +00:00
|
|
|
public int BaseCount => Math.Min(3, Count);
|
|
|
|
public bool HasOPowerS => Count > 3;
|
|
|
|
public bool HasOPowerMAX => Count == 5;
|
2018-06-10 04:04:34 +00:00
|
|
|
|
|
|
|
public OPowerFlagSet(int count, OPower6Type ident)
|
|
|
|
{
|
|
|
|
Identifier = ident;
|
|
|
|
Count = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetOPowerLevel(byte[] data, int offset)
|
|
|
|
{
|
2018-06-10 18:28:20 +00:00
|
|
|
for (int i = 0; i < BaseCount; i++)
|
2018-06-10 04:04:34 +00:00
|
|
|
{
|
2018-06-10 18:28:20 +00:00
|
|
|
if (GetFlag(data, offset, i))
|
2018-06-10 04:04:34 +00:00
|
|
|
continue;
|
|
|
|
Debug.WriteLine($"Fetched {Identifier}: {i}");
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2018-06-10 18:28:20 +00:00
|
|
|
Debug.WriteLine($"Fetched {Identifier}: {BaseCount}");
|
|
|
|
return BaseCount;
|
2018-06-10 04:04:34 +00:00
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2018-06-10 04:04:34 +00:00
|
|
|
public void SetOPowerLevel(byte[] data, int offset, int value)
|
|
|
|
{
|
|
|
|
Debug.WriteLine($"Setting {Identifier}: {value}");
|
2018-06-10 18:28:20 +00:00
|
|
|
for (int i = 0; i < BaseCount; i++)
|
|
|
|
SetFlag(data, offset, i, i + 1 <= value);
|
2018-06-10 04:04:34 +00:00
|
|
|
Debug.Assert(value == GetOPowerLevel(data, offset));
|
|
|
|
}
|
2018-06-10 18:28:20 +00:00
|
|
|
|
|
|
|
public bool GetOPowerS(byte[] data, int offset) => HasOPowerS && GetFlag(data, offset, 3);
|
|
|
|
public bool GetOPowerMAX(byte[] data, int offset) => HasOPowerMAX && GetFlag(data, offset, 4);
|
|
|
|
public void SetOPowerS(byte[] data, int offset, bool value) => SetFlag(data, offset, 3, value);
|
|
|
|
public void SetOPowerMAX(byte[] data, int offset, bool value) => SetFlag(data, offset, 4, value);
|
|
|
|
|
|
|
|
private bool GetFlag(byte[] data, int offset, int index)
|
|
|
|
{
|
|
|
|
return data[Offset + offset + index] == (byte)OPowerFlagState.Unlocked;
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
2018-06-10 18:28:20 +00:00
|
|
|
private void SetFlag(byte[] data, int offset, int index, bool value)
|
|
|
|
{
|
|
|
|
if (index < Count)
|
|
|
|
data[Offset + offset + index] = (byte)(value ? OPowerFlagState.Unlocked : OPowerFlagState.Locked);
|
|
|
|
}
|
2018-06-10 04:04:34 +00:00
|
|
|
}
|
|
|
|
}
|