IGanbaru int->byte fields

This commit is contained in:
Kurt 2022-03-04 22:33:28 -08:00
parent 7443db3564
commit 6ae59c509f
4 changed files with 63 additions and 33 deletions

View file

@ -236,12 +236,12 @@ namespace PKHeX.Core
public int OT_TextVar { get => ReadUInt16LittleEndian(Data.AsSpan(0x274)); set => WriteUInt16LittleEndian(Data.AsSpan(0x274), (ushort)value); }
// Only derivations to WC8
public int GV_HP { get => Data[0x27E]; set => Data[0x27E] = (byte)value; }
public int GV_ATK { get => Data[0x27F]; set => Data[0x27F] = (byte)value; }
public int GV_DEF { get => Data[0x280]; set => Data[0x280] = (byte)value; }
public int GV_SPE { get => Data[0x281]; set => Data[0x281] = (byte)value; }
public int GV_SPA { get => Data[0x282]; set => Data[0x282] = (byte)value; }
public int GV_SPD { get => Data[0x283]; set => Data[0x283] = (byte)value; }
public byte GV_HP { get => Data[0x27E]; set => Data[0x27E] = value; }
public byte GV_ATK { get => Data[0x27F]; set => Data[0x27F] = value; }
public byte GV_DEF { get => Data[0x280]; set => Data[0x280] = value; }
public byte GV_SPE { get => Data[0x281]; set => Data[0x281] = value; }
public byte GV_SPA { get => Data[0x282]; set => Data[0x282] = value; }
public byte GV_SPD { get => Data[0x283]; set => Data[0x283] = value; }
// Meta Accessible Properties
public override int[] IVs

View file

@ -398,12 +398,12 @@ public sealed class PA8 : PKM, ISanityChecksum,
public override int Status_Condition { get => ReadInt32LittleEndian(Data.AsSpan(0x9C)); set => WriteInt32LittleEndian(Data.AsSpan(0x9C), value); }
public int UnkA0 { get => ReadInt32LittleEndian(Data.AsSpan(0xA0)); set => WriteInt32LittleEndian(Data.AsSpan(0xA0), value); }
public int GV_HP { get => Data[0xA4]; set => Data[0xA4] = (byte)value; }
public int GV_ATK { get => Data[0xA5]; set => Data[0xA5] = (byte)value; }
public int GV_DEF { get => Data[0xA6]; set => Data[0xA6] = (byte)value; }
public int GV_SPE { get => Data[0xA7]; set => Data[0xA7] = (byte)value; }
public int GV_SPA { get => Data[0xA8]; set => Data[0xA8] = (byte)value; }
public int GV_SPD { get => Data[0xA9]; set => Data[0xA9] = (byte)value; }
public byte GV_HP { get => Data[0xA4]; set => Data[0xA4] = value; }
public byte GV_ATK { get => Data[0xA5]; set => Data[0xA5] = value; }
public byte GV_DEF { get => Data[0xA6]; set => Data[0xA6] = value; }
public byte GV_SPE { get => Data[0xA7]; set => Data[0xA7] = value; }
public byte GV_SPA { get => Data[0xA8]; set => Data[0xA8] = value; }
public byte GV_SPD { get => Data[0xA9]; set => Data[0xA9] = value; }
// 0xAA-0xAB unused
@ -581,7 +581,7 @@ public sealed class PA8 : PKM, ISanityChecksum,
};
}
public static int GetGanbaruStat(int baseStat, int iv, int gv, int level)
public static int GetGanbaruStat(int baseStat, int iv, byte gv, int level)
{
int mul = GanbaruExtensions.GetGanbaruMultiplier(gv, iv);
double step1 = Math.Abs(Math.Sqrt((float)baseStat)) * mul; // The game does abs after sqrt; should be before. It's fine because baseStat is never negative.

View file

@ -2,37 +2,55 @@
namespace PKHeX.Core;
/// <summary>
/// Effort Level stat values gained via applied Grit items.
/// </summary>
public interface IGanbaru
{
int GV_HP { get; set; }
int GV_ATK { get; set; }
int GV_DEF { get; set; }
int GV_SPE { get; set; }
int GV_SPA { get; set; }
int GV_SPD { get; set; }
byte GV_HP { get; set; }
byte GV_ATK { get; set; }
byte GV_DEF { get; set; }
byte GV_SPE { get; set; }
byte GV_SPA { get; set; }
byte GV_SPD { get; set; }
}
public static class GanbaruExtensions
{
public const int TrueMax = 10;
/// <summary>
/// Overall maximum value permitted (adding the base factor and gained value).
/// </summary>
public const byte TrueMax = 10;
private static readonly ushort[] GanbaruMultiplier = { 0, 2, 3, 4, 7, 8, 9, 14, 15, 16, 25 };
private static readonly byte[] GanbaruMultiplier = { 0, 2, 3, 4, 7, 8, 9, 14, 15, 16, 25 };
public static int GetMax(this IGanbaru _, PKM pk, int index) => GetMaxGanbaru(pk, index);
/// <summary>
/// Gets the max possible value that can be legally stored for the specific stat <see cref="index"/>.
/// </summary>
public static byte GetMax(this IGanbaru _, PKM pk, int index) => GetMaxGanbaru(pk, index);
public static int GetMaxGanbaru(this PKM pk, int index)
/// <summary>
/// Gets the max possible value that can be legally stored for the specific stat <see cref="index"/>.
/// </summary>
public static byte GetMaxGanbaru(this PKM pk, int index)
{
var iv = pk.GetIV(index);
return GetMaxGanbaru(iv);
}
private static int GetMaxGanbaru(int iv)
/// <summary>
/// Gets the max possible value that can be legally stored for a stat with value <see cref="iv"/>.
/// </summary>
private static byte GetMaxGanbaru(int iv)
{
var bias = GetBias(iv);
return TrueMax - bias;
return (byte)(TrueMax - bias);
}
public static int GetBias(int iv) => iv switch
/// <summary>
/// Gets the added boost for a stat with a base potential <see cref="iv"/>.
/// </summary>
public static byte GetBias(int iv) => iv switch
{
>= 31 => 3,
>= 26 => 2,
@ -40,16 +58,22 @@ public static class GanbaruExtensions
_ => 0,
};
/// <summary>
/// Sets all values to the maximum. Attack and Speed are set to 0 if the corresponding IV is zero.
/// </summary>
public static void SetSuggestedGanbaruValues(this IGanbaru g, PKM pk)
{
g.GV_HP = GetMaxGanbaru(pk.IV_HP);
g.GV_ATK = pk.IV_ATK == 0 ? 0 : GetMaxGanbaru(pk.IV_ATK);
g.GV_ATK = pk.IV_ATK == 0 ? (byte)0: GetMaxGanbaru(pk.IV_ATK);
g.GV_DEF = GetMaxGanbaru(pk.IV_DEF);
g.GV_SPE = pk.IV_SPE == 0 ? 0 : GetMaxGanbaru(pk.IV_SPE);
g.GV_SPE = pk.IV_SPE == 0 ? (byte)0 : GetMaxGanbaru(pk.IV_SPE);
g.GV_SPA = GetMaxGanbaru(pk.IV_SPA);
g.GV_SPD = GetMaxGanbaru(pk.IV_SPD);
}
/// <summary>
/// Checks if the values are at the favorable maximum per <see cref="SetSuggestedGanbaruValues"/>.
/// </summary>
public static bool IsGanbaruValuesMax(this IGanbaru g, PKM pk)
{
var result = true;
@ -62,6 +86,9 @@ public static class GanbaruExtensions
return result;
}
/// <summary>
/// Sets all values to 0.
/// </summary>
public static void ClearGanbaruValues(this IGanbaru g)
{
g.GV_HP = 0;
@ -72,7 +99,10 @@ public static class GanbaruExtensions
g.GV_SPD = 0;
}
public static int GetGanbaruMultiplier(int gv, int iv) => GanbaruMultiplier[Math.Min(gv + GetBias(iv), 10)];
/// <summary>
/// Gets the stat calculation modifier using the saved <see cref="gv"/> and base <see cref="iv"/>.
/// </summary>
public static byte GetGanbaruMultiplier(byte gv, int iv) => GanbaruMultiplier[Math.Min(gv + GetBias(iv), TrueMax)];
/// <summary>
/// Sets one of the <see cref="IAwakened"/> values based on its index within the array.
@ -80,9 +110,9 @@ public static class GanbaruExtensions
/// <param name="pk">Pokémon to modify.</param>
/// <param name="index">Index to set to</param>
/// <param name="value">Value to set</param>
public static int SetGV(this IGanbaru pk, int index, int value) => index switch
public static byte SetGV(this IGanbaru pk, int index, byte value) => index switch
{
0 => pk.GV_HP = value,
0 => pk.GV_HP = value,
1 => pk.GV_ATK = value,
2 => pk.GV_DEF = value,
3 => pk.GV_SPE = value,
@ -96,7 +126,7 @@ public static class GanbaruExtensions
/// </summary>
/// <param name="pk">Pokémon to check.</param>
/// <param name="index">Index to get</param>
public static int GetGV(this IGanbaru pk, int index) => index switch
public static byte GetGV(this IGanbaru pk, int index) => index switch
{
0 => pk.GV_HP,
1 => pk.GV_ATK,

View file

@ -244,7 +244,7 @@ namespace PKHeX.WinForms.Controls
}
int index = Array.IndexOf(MT_GVs, m);
g.SetGV(index, value);
g.SetGV(index, (byte)value);
RefreshGanbaru(Entity, g, index);
}