Add SizeType9 for fixed range Scale values

This commit is contained in:
Kurt 2023-02-26 16:14:11 -08:00
parent b4b1310934
commit 52f1bf081c
8 changed files with 50 additions and 15 deletions

View File

@ -238,7 +238,7 @@ protected override bool IsMatchPartial(PKM pk)
return true;
var pi = PersonalTable.SV.GetFormEntry(Species, Form);
var param = new GenerateParam9(Species, pi.Gender, FlawlessIVCount, 1, 0, 0, 0, Ability, Shiny);
var param = new GenerateParam9(Species, pi.Gender, FlawlessIVCount, 1, 0, 0, 0, 0, Ability, Shiny);
if (!Encounter9RNG.IsMatch(pk, param, seed))
return true;
return base.IsMatchPartial(pk);
@ -259,7 +259,7 @@ protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
const byte undefinedSize = 0;
var pi = PersonalTable.SV.GetFormEntry(Species, Form);
var param = new GenerateParam9(Species, pi.Gender, FlawlessIVCount, rollCount,
undefinedSize, undefinedSize, undefinedSize,
undefinedSize, undefinedSize, undefinedSize, undefinedSize,
Ability, Shiny);
var init = Util.Rand.Rand64();

View File

@ -13,7 +13,11 @@ public sealed record EncounterMight9 : EncounterStatic, ITeraRaid9
public byte Index { get; private init; }
public byte Stars { get; private init; }
public byte RandRate { get; private init; } // weight chance of this encounter
public byte Scale { get; init; }
/// <summary> Indicates how the <see cref="Scale"/> value is used, if at all. </summary>
public SizeType9 ScaleType { get; private init; }
/// <summary> Used only for <see cref="ScaleType"/> == <see cref="SizeType9.VALUE"/> </summary>
public byte Scale { get; private init; }
public ushort RandRate0MinScarlet { get; private init; }
public ushort RandRate0MinViolet { get; private init; }
@ -193,7 +197,8 @@ private static EncounterMight9 ReadEncounter(ReadOnlySpan<byte> data) => new()
Nature = (Nature)data[0x34],
IVs = new IndividualValueSet((sbyte)data[0x35], (sbyte)data[0x36], (sbyte)data[0x37], (sbyte)data[0x38], (sbyte)data[0x39], (sbyte)data[0x3A], data[0x3B]),
Scale = data[0x3C],
ScaleType = (SizeType9)data[0x3C],
Scale = data[0x3D],
};
private static AbilityPermission GetAbility(byte b) => b switch
@ -236,8 +241,6 @@ protected override bool IsMatchPartial(PKM pk)
return true;
}
if (pk is IScaledSize3 s3 && s3.Scale != Scale)
return true;
if (IVs.IsSpecified && !Legal.GetIsFixedIVSequenceValidSkipRand(IVs, pk))
return true;
@ -248,7 +251,7 @@ protected override bool IsMatchPartial(PKM pk)
return true;
byte gender = GetGender();
var param = new GenerateParam9(Species, gender, FlawlessIVCount, 1, 0, 0, Scale, Ability, Shiny, Nature, IVs);
var param = new GenerateParam9(Species, gender, FlawlessIVCount, 1, 0, 0, ScaleType, Scale, Ability, Shiny, Nature, IVs);
if (!Encounter9RNG.IsMatch(pk, param, seed))
return true;
return base.IsMatchPartial(pk);
@ -270,7 +273,7 @@ protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
const byte undefinedSize = 0;
byte gender = GetGender();
var param = new GenerateParam9(Species, gender, FlawlessIVCount, rollCount,
undefinedSize, undefinedSize, Scale,
undefinedSize, undefinedSize, ScaleType, Scale,
Ability, Shiny, Nature, IVs);
var init = Util.Rand.Rand64();

View File

@ -17,6 +17,8 @@ public sealed record EncounterStatic9(GameVersion Version) : EncounterStatic(Ver
public bool StarterBoxLegend => Gift && Species is (int)Core.Species.Koraidon or (int)Core.Species.Miraidon;
public bool ScriptedYungoos => Species == (int)Core.Species.Yungoos && Level == 2;
public SizeType9 ScaleType => NoScalarsDefined ? SizeType9.RANDOM : SizeType9.VALUE;
protected override bool IsMatchPartial(PKM pk)
{
if (pk is IScaledSize v && !NoScalarsDefined)
@ -71,7 +73,7 @@ protected override void ApplyDetails(ITrainerInfo tr, EncounterCriteria criteria
const byte rollCount = 1;
var pi = PersonalTable.SV.GetFormEntry(Species, Form);
var param = new GenerateParam9(Species, pi.Gender, FlawlessIVCount, rollCount, height, weight, scale, Ability, Shiny);
var param = new GenerateParam9(Species, pi.Gender, FlawlessIVCount, rollCount, height, weight, ScaleType, scale, Ability, Shiny);
ulong init = Util.Rand.Rand64();
var success = this.TryApply64(pk9, init, param, criteria, IVs.IsSpecified);

View File

@ -132,7 +132,7 @@ protected override bool IsMatchPartial(PKM pk)
return true;
var pi = PersonalTable.SV.GetFormEntry(Species, Form);
var param = new GenerateParam9(Species, pi.Gender, FlawlessIVCount, 1, 0, 0, 0, Ability, Shiny);
var param = new GenerateParam9(Species, pi.Gender, FlawlessIVCount, 1, 0, 0, 0, 0, Ability, Shiny);
if (!Encounter9RNG.IsMatch(pk, param, seed))
return true;
return base.IsMatchPartial(pk);
@ -153,7 +153,7 @@ protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
const byte undefinedSize = 0;
var pi = PersonalTable.SV.GetFormEntry(Species, Form);
var param = new GenerateParam9(Species, pi.Gender, FlawlessIVCount, rollCount,
undefinedSize, undefinedSize, undefinedSize,
undefinedSize, undefinedSize, undefinedSize, undefinedSize,
Ability, Shiny);
var init = Util.Rand.Rand64();

View File

@ -0,0 +1,30 @@
using System;
using static PKHeX.Core.SizeType9;
namespace PKHeX.Core;
public enum SizeType9
{
RANDOM = 0,
XS = 1,
S = 2,
M = 3,
L = 4,
XL = 5,
VALUE = 6,
}
public static class SizeType9Extensions
{
public static byte GetSizeValue(this SizeType9 type, byte value, ref Xoroshiro128Plus rand) => type switch
{
RANDOM => (byte)(rand.NextInt(0x81) + rand.NextInt(0x80)),
XS => (byte)rand.NextInt(0x10),
S => (byte)(rand.NextInt(0x20) + 0x10),
M => (byte)(rand.NextInt(0xA0) + 0x30),
L => (byte)(rand.NextInt(0x20) + 0xD0),
XL => (byte)(rand.NextInt(0x10) + 0xF0),
VALUE => value,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
};
}

View File

@ -119,7 +119,7 @@ public static bool GenerateData(PK9 pk, in GenerateParam9 enc, EncounterCriteria
pk.HeightScalar = enc.Height != 0 ? enc.Height : (byte)(rand.NextInt(0x81) + rand.NextInt(0x80));
pk.WeightScalar = enc.Weight != 0 ? enc.Weight : (byte)(rand.NextInt(0x81) + rand.NextInt(0x80));
pk.Scale = enc.Scale != 0 ? enc.Scale : (byte)(rand.NextInt(0x81) + rand.NextInt(0x80));
pk.Scale = enc.ScaleType.GetSizeValue(enc.Scale, ref rand);
return true;
}
@ -207,9 +207,9 @@ public static bool IsMatch(PKM pk, in GenerateParam9 enc, in ulong seed)
if (pk is IScaledSize s && s.WeightScalar != value)
return false;
}
if (enc.Scale == 0)
// Scale
{
var value = (int)rand.NextInt(0x81) + (int)rand.NextInt(0x80);
var value = enc.ScaleType.GetSizeValue(enc.Scale, ref rand);
if (pk is IScaledSize3 s && s.Scale != value)
return false;
}

View File

@ -15,5 +15,5 @@ namespace PKHeX.Core;
/// <param name="Nature">Nature specification.</param>
/// <param name="IVs">IV specification.</param>
public readonly record struct GenerateParam9(ushort Species, byte GenderRatio, byte FlawlessIVs, byte RollCount, byte Height,
byte Weight, byte Scale, AbilityPermission Ability = AbilityPermission.Any12, Shiny Shiny = Shiny.Random,
byte Weight, SizeType9 ScaleType, byte Scale, AbilityPermission Ability = AbilityPermission.Any12, Shiny Shiny = Shiny.Random,
Nature Nature = Nature.Random, IndividualValueSet IVs = default);