mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-28 15:00:36 +00:00
Misc tweaks
Extract better signatures for BallApplicator.ApplyBallLegalRandom Slot1: swap interface order (consistency with other classes, no impact) IEncounterTemplate vs IEncounterable interface usage
This commit is contained in:
parent
61526fad8d
commit
5c338f5f74
7 changed files with 48 additions and 23 deletions
|
@ -9,8 +9,14 @@ namespace PKHeX.Core;
|
|||
public static class BallApplicator
|
||||
{
|
||||
private static readonly Ball[] BallList = Enum.GetValues<Ball>();
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of <see cref="Ball"/> values that can be returned in a span.
|
||||
/// </summary>
|
||||
public const byte MaxBallSpanAlloc = (byte)LAOrigin + 1;
|
||||
|
||||
private static IEncounterTemplate Get(LegalityAnalysis la) => la.EncounterOriginal;
|
||||
|
||||
/// <remarks>
|
||||
/// Requires checking the <see cref="LegalityAnalysis"/>.
|
||||
/// </remarks>
|
||||
|
@ -18,7 +24,7 @@ public static class BallApplicator
|
|||
public static int GetLegalBalls(Span<Ball> result, PKM pk) => GetLegalBalls(result, pk, new LegalityAnalysis(pk));
|
||||
|
||||
/// <inheritdoc cref="GetLegalBalls(Span{Ball}, PKM, IEncounterTemplate)"/>
|
||||
public static int GetLegalBalls(Span<Ball> result, PKM pk, LegalityAnalysis la) => GetLegalBalls(result, pk, la.EncounterOriginal);
|
||||
public static int GetLegalBalls(Span<Ball> result, PKM pk, LegalityAnalysis la) => GetLegalBalls(result, pk, Get(la));
|
||||
|
||||
/// <summary>
|
||||
/// Gets all balls that are legal for the input <see cref="PKM"/>.
|
||||
|
@ -74,28 +80,38 @@ public static class BallApplicator
|
|||
return ctr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies a random legal ball value if any exist.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Requires checking the <see cref="LegalityAnalysis"/>.
|
||||
/// </remarks>
|
||||
/// <inheritdoc cref="ApplyBallLegalRandom(PKM, IEncounterTemplate)"/>
|
||||
public static byte ApplyBallLegalRandom(PKM pk) => ApplyBallLegalRandom(pk, new LegalityAnalysis(pk));
|
||||
|
||||
/// <inheritdoc cref="ApplyBallLegalRandom(PKM, IEncounterTemplate)"/>
|
||||
public static byte ApplyBallLegalRandom(PKM pk, LegalityAnalysis la) => ApplyBallLegalRandom(pk, Get(la));
|
||||
|
||||
/// <summary>
|
||||
/// Applies a random legal ball value if any exist.
|
||||
/// </summary>
|
||||
/// <param name="pk">Pokémon to modify.</param>
|
||||
public static byte ApplyBallLegalRandom(PKM pk)
|
||||
/// <param name="enc">Encounter matched to.</param>
|
||||
public static byte ApplyBallLegalRandom(PKM pk, IEncounterTemplate enc)
|
||||
{
|
||||
Span<Ball> balls = stackalloc Ball[MaxBallSpanAlloc];
|
||||
var count = GetLegalBalls(balls, pk);
|
||||
var count = GetLegalBalls(balls, pk, enc);
|
||||
balls = balls[..count];
|
||||
Util.Rand.Shuffle(balls);
|
||||
return ApplyFirstLegalBall(pk, balls, []);
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// Requires checking the <see cref="LegalityAnalysis"/>.
|
||||
/// </remarks>
|
||||
/// <inheritdoc cref="ApplyBallLegalByColor(PKM, IEncounterTemplate, PersonalColor)"/>
|
||||
public static byte ApplyBallLegalByColor(PKM pk) => ApplyBallLegalByColor(pk, PersonalColorUtil.GetColor(pk));
|
||||
/// <inheritdoc cref="ApplyBallLegalByColor(PKM, IEncounterTemplate, PersonalColor)"/>
|
||||
public static byte ApplyBallLegalByColor(PKM pk, PersonalColor color) => ApplyBallLegalByColor(pk, new LegalityAnalysis(pk), color);
|
||||
/// <inheritdoc cref="ApplyBallLegalByColor(PKM, IEncounterTemplate, PersonalColor)"/>
|
||||
public static byte ApplyBallLegalByColor(PKM pk, LegalityAnalysis la, PersonalColor color) => ApplyBallLegalByColor(pk, la.EncounterOriginal, color);
|
||||
public static byte ApplyBallLegalByColor(PKM pk, LegalityAnalysis la, PersonalColor color) => ApplyBallLegalByColor(pk, Get(la), color);
|
||||
|
||||
/// <summary>
|
||||
/// Applies a legal ball value if any exist, ordered by color.
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace PKHeX.Core;
|
|||
/// Encounter Slot found in <see cref="GameVersion.Gen1"/>.
|
||||
/// </summary>
|
||||
public sealed record EncounterSlot1(EncounterArea1 Parent, ushort Species, byte LevelMin, byte LevelMax, byte SlotNumber)
|
||||
: IEncounterConvertible<PK1>, IEncounterable, IEncounterMatch, INumberedSlot
|
||||
: IEncounterable, IEncounterMatch, IEncounterConvertible<PK1>, INumberedSlot
|
||||
{
|
||||
public byte Generation => 1;
|
||||
public EntityContext Context => EntityContext.Gen1;
|
||||
|
|
|
@ -117,7 +117,7 @@ public sealed class AbilityVerifier : Verifier
|
|||
};
|
||||
}
|
||||
|
||||
private CheckResult VerifyAbility345(LegalityAnalysis data, IEncounterable enc, IPersonalAbility12 abilities, int abilIndex)
|
||||
private CheckResult VerifyAbility345(LegalityAnalysis data, IEncounterTemplate enc, IPersonalAbility12 abilities, int abilIndex)
|
||||
{
|
||||
var pk = data.Entity;
|
||||
byte format = pk.Format;
|
||||
|
@ -353,7 +353,7 @@ public sealed class AbilityVerifier : Verifier
|
|||
};
|
||||
}
|
||||
|
||||
private CheckResult VerifyAbility8BDSP(LegalityAnalysis data, IEncounterable enc)
|
||||
private CheckResult VerifyAbility8BDSP(LegalityAnalysis data, IEncounterTemplate enc)
|
||||
{
|
||||
var pk = data.Entity;
|
||||
if (pk.AbilityNumber != 4)
|
||||
|
|
|
@ -76,7 +76,7 @@ public sealed class MiscVerifier : Verifier
|
|||
var date = new DateOnly(pk.MetYear + 2000, pk.MetMonth, pk.MetDay);
|
||||
|
||||
// HOME Gifts for Sinnoh/Hisui starters were forced JPN until May 20, 2022 (UTC).
|
||||
if (enc is WB8 { CardID: 9015 or 9016 or 9017 } or WA8 { CardID: 9018 or 9019 or 9020 })
|
||||
if (enc is WB8 { IsDateLockJapanese: true } or WA8 { IsDateLockJapanese: true })
|
||||
{
|
||||
if (date < new DateOnly(2022, 5, 20) && pk.Language != (int)LanguageID.Japanese)
|
||||
data.AddLine(GetInvalid(LDateOutsideDistributionWindow));
|
||||
|
@ -623,7 +623,7 @@ public sealed class MiscVerifier : Verifier
|
|||
data.AddLine(GetInvalid(LStatIncorrectWeight, Encounter));
|
||||
}
|
||||
|
||||
private static bool IsStarterLGPE(ISpeciesForm pk) => pk switch
|
||||
private static bool IsStarterLGPE<T>(T pk) where T : ISpeciesForm => pk switch
|
||||
{
|
||||
{ Species: (int)Species.Pikachu, Form: 8 } => true,
|
||||
{ Species: (int)Species.Eevee, Form: 1 } => true,
|
||||
|
|
|
@ -486,11 +486,10 @@ public sealed class WA8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
pk.SID16 = tr.SID16;
|
||||
}
|
||||
|
||||
pk.MetDate = IsDateRestricted && EncounterServerDate.WA8Gifts.TryGetValue(CardID, out var dt) ? dt.Start : EncounterDate.GetDateSwitch();
|
||||
|
||||
// HOME Gifts for Sinnoh/Hisui starters were forced JPN until May 20, 2022 (UTC).
|
||||
if (CardID is 9018 or 9019 or 9020)
|
||||
pk.MetDay = 20;
|
||||
var date = IsDateRestricted && EncounterServerDate.WB8Gifts.TryGetValue(CardID, out var dt) ? dt.Start : EncounterDate.GetDateSwitch();
|
||||
if (IsDateLockJapanese && language != (int)LanguageID.Japanese && date < new DateOnly(2022, 5, 20)) // 2022/05/18
|
||||
date = new DateOnly(2022, 5, 20); // Pick a better Start date that can be the language we're generating for.
|
||||
pk.MetDate = date;
|
||||
|
||||
var nickname_language = GetLanguage(language);
|
||||
pk.Language = nickname_language != 0 ? nickname_language : tr.Language;
|
||||
|
@ -521,6 +520,11 @@ public sealed class WA8(byte[] Data) : DataMysteryGift(Data), ILangNick, INature
|
|||
return pk;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HOME Gifts for Hisui starters were forced JPN until May 20, 2022 (UTC).
|
||||
/// </summary>
|
||||
public bool IsDateLockJapanese => CardID is 9018 or 9019 or 9020;
|
||||
|
||||
private void SetEggMetData(PA8 pk)
|
||||
{
|
||||
pk.IsEgg = true;
|
||||
|
|
|
@ -484,10 +484,10 @@ public sealed class WB8(byte[] Data) : DataMysteryGift(Data),
|
|||
pk.SID16 = tr.SID16;
|
||||
}
|
||||
|
||||
pk.MetDate = IsDateRestricted && EncounterServerDate.WB8Gifts.TryGetValue(CardID, out var dt) ? dt.Start : EncounterDate.GetDateSwitch();
|
||||
// HOME Gifts for Sinnoh/Hisui starters were forced JPN until May 20, 2022 (UTC).
|
||||
if (CardID is 9015 or 9016 or 9017)
|
||||
pk.MetDay = 20;
|
||||
var date = IsDateRestricted && EncounterServerDate.WB8Gifts.TryGetValue(CardID, out var dt) ? dt.Start : EncounterDate.GetDateSwitch();
|
||||
if (IsDateLockJapanese && language != (int)LanguageID.Japanese && date < new DateOnly(2022, 5, 20)) // 2022/05/18
|
||||
date = new DateOnly(2022, 5, 20); // Pick a better Start date that can be the language we're generating for.
|
||||
pk.MetDate = date;
|
||||
|
||||
var nickname_language = GetLanguage(language);
|
||||
pk.Language = nickname_language != 0 ? nickname_language : tr.Language;
|
||||
|
@ -515,6 +515,11 @@ public sealed class WB8(byte[] Data) : DataMysteryGift(Data),
|
|||
return pk;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HOME Gifts for Sinnoh starters were forced JPN until May 20, 2022 (UTC).
|
||||
/// </summary>
|
||||
public bool IsDateLockJapanese => CardID is 9015 or 9016 or 9017;
|
||||
|
||||
private void SetEggMetData(PB8 pk)
|
||||
{
|
||||
pk.IsEgg = true;
|
||||
|
|
|
@ -104,7 +104,7 @@ public sealed class LegalityRejuvenator : IEntityRejuvenator
|
|||
ResetBallPLA(result, enc);
|
||||
}
|
||||
|
||||
private static void ResetBallPLA(PKM result, IEncounterable enc)
|
||||
private static void ResetBallPLA(PKM result, IEncounterTemplate enc)
|
||||
{
|
||||
if (result.Ball is >= (int)Ball.LAPoke and <= (int)Ball.LAOrigin)
|
||||
return;
|
||||
|
@ -114,7 +114,7 @@ public sealed class LegalityRejuvenator : IEntityRejuvenator
|
|||
result.Ball = result.Species == (int)Species.Unown ? (byte)Ball.LAJet : (byte)Ball.LAPoke;
|
||||
}
|
||||
|
||||
private static void ResetDataPLA(LegalityAnalysis la, IEncounterable enc, PA8 pa8)
|
||||
private static void ResetDataPLA(LegalityAnalysis la, IEncounterTemplate enc, PA8 pa8)
|
||||
{
|
||||
ResetRelearn(pa8, la);
|
||||
|
||||
|
|
Loading…
Reference in a new issue