Batch Editor: Combine simple & complex EC rand

Just pipe everything to the complicated EC pathway and allow it to select for biases. Swap input preferences to retain a proper EC for dudun/maus.
Closes #4179
This commit is contained in:
Kurt
2024-01-29 17:41:12 -08:00
parent 3618caa4e3
commit f99e4e54f3
2 changed files with 16 additions and 10 deletions

View File

@@ -67,7 +67,6 @@ public static class BatchMods
new ComplexSet(nameof(PKM.AbilityNumber), value => value.Length == 2 && value.StartsWith(CONST_SPECIAL), (pk, cmd) => pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30)),
// Random
new ComplexSet(nameof(PKM.EncryptionConstant), value => value == CONST_RAND, (pk, _) => pk.EncryptionConstant = Util.Rand32()),
new ComplexSet(nameof(PKM.PID), value => value == CONST_RAND, (pk, _) => pk.PID = Util.Rand32()),
new ComplexSet(nameof(PKM.Gender), value => value == CONST_RAND, (pk, _) => pk.SetPIDGender(pk.Gender)),
new ComplexSet(PROP_EVS, value => value == CONST_RAND, (pk, _) => SetRandomEVs(pk)),
@@ -82,7 +81,7 @@ public static class BatchMods
new ComplexSet(nameof(PKM.IsNicknamed), value => string.Equals(value, "false", StringComparison.OrdinalIgnoreCase), (pk, _) => pk.SetDefaultNickname()),
// Complicated
new ComplexSet(nameof(PKM.EncryptionConstant), value => value.StartsWith(CONST_RAND), (pk, cmd) => pk.EncryptionConstant = CommonEdits.GetComplicatedEC(pk, option: cmd.PropertyValue[^1])),
new ComplexSet(nameof(PKM.EncryptionConstant), value => value.StartsWith(CONST_RAND), (pk, cmd) => pk.EncryptionConstant = CommonEdits.GetComplicatedEC(pk, option: (cmd.PropertyValue.Length == CONST_RAND.Length ? default : cmd.PropertyValue[^1]))),
];
private static void SetRandomTeraType(PKM pk)

View File

@@ -440,7 +440,7 @@ public static string GetLocationString(this PKM pk, bool eggmet)
/// <summary>
/// Gets a <see cref="PKM.EncryptionConstant"/> to match the requested option.
/// </summary>
public static uint GetComplicatedEC(ISpeciesForm pk, char option = ' ')
public static uint GetComplicatedEC(ISpeciesForm pk, char option = default)
{
var species = pk.Species;
var form = pk.Form;
@@ -448,11 +448,11 @@ public static uint GetComplicatedEC(ISpeciesForm pk, char option = ' ')
}
/// <inheritdoc cref="GetComplicatedEC(ISpeciesForm,char)"/>
public static uint GetComplicatedEC(ushort species, byte form, char option = ' ')
public static uint GetComplicatedEC(ushort species, byte form, char option = default)
{
var rng = Util.Rand;
uint rand = rng.Rand32();
uint mod = 1, noise = 0;
uint mod, noise;
if (species is >= (int)Species.Wurmple and <= (int)Species.Dustox)
{
mod = 10;
@@ -462,13 +462,16 @@ public static uint GetComplicatedEC(ushort species, byte form, char option = ' '
else if (species is (int)Species.Dunsparce or (int)Species.Dudunsparce or (int)Species.Tandemaus or (int)Species.Maushold)
{
mod = 100;
noise = option switch
noise = species switch
{
'0' or '3' => 0u,
_ => species switch
// Retain requisite correlation to allow for evolving into this species too.
(int)Species.Dudunsparce => form == 1 ? 0 : (uint)rng.Next(1, 100), // 3 Segment
(int)Species.Maushold => form == 0 ? 0 : (uint)rng.Next(1, 100), // Family of 3
// Otherwise, check if one is preferred, and if not, just make it the more common outcome.
_ => option switch
{
(int)Species.Dudunsparce when form == 1 => 0, // 3 Segment
(int)Species.Maushold when form == 0 => 0, // Family of 3
'0' or '3' => 0u,
_ => (uint)rng.Next(1, 100),
},
};
@@ -478,6 +481,10 @@ public static uint GetComplicatedEC(ushort species, byte form, char option = ' '
mod = 6;
noise = (uint)(option - '0');
}
else
{
return rand;
}
return unchecked(rand - (rand % mod) + noise);
}
}