Handle get moveset for Gen1 Red Trade Jynx

Need to not devolve into Smoochum as the rules are restrictive: no relearn, but we want to allow Jynx to "permit" moves it learns from levels 0-29.
This commit is contained in:
Kurt 2023-09-04 18:23:10 -07:00
parent 91d4ba5f03
commit 4e0f23cdc0
6 changed files with 32 additions and 8 deletions

View file

@ -191,7 +191,7 @@ public static class EncounterMovesetGenerator
private static IEnumerable<IEncounterable> GenerateVersionEncounters(PKM pk, ReadOnlyMemory<ushort> moves, GameVersion version, byte generation, EntityContext context)
{
var origin = new EvolutionOrigin(pk.Species, (byte)version, generation, 1, 100, true);
var origin = new EvolutionOrigin(pk.Species, (byte)version, generation, 1, 100, OriginOptions.EncounterTemplate);
var chain = EvolutionChain.GetOriginChain(pk, origin);
if (chain.Length == 0)
yield break;
@ -259,7 +259,7 @@ public static class EncounterMovesetGenerator
var length = pk.MaxMoveID + 1;
var rent = ArrayPool<bool>.Shared.Rent(length);
var permitted = rent.AsSpan(0, length);
var enc = new EvolutionOrigin(pk.Species, (byte)ver, (byte)generation, 1, 100, true);
var enc = new EvolutionOrigin(pk.Species, (byte)ver, (byte)generation, 1, 100, OriginOptions.EncounterTemplate);
var history = EvolutionChain.GetEvolutionChainsSearch(pk, enc, context, 0);
var e = new NeededEncounter(context, generation, ver); // default empty
LearnPossible.Get(pk, e, history, permitted);

View file

@ -19,7 +19,7 @@ public static class EncounterSuggestion
return GetSuggestedEncounterEgg(pk, loc);
Span<EvoCriteria> chain = stackalloc EvoCriteria[EvolutionTree.MaxEvolutions];
var origin = new EvolutionOrigin(pk.Species, (byte)pk.Version, (byte)pk.Generation, (byte)pk.CurrentLevel, (byte)pk.CurrentLevel, SkipChecks: true);
var origin = new EvolutionOrigin(pk.Species, (byte)pk.Version, (byte)pk.Generation, (byte)pk.CurrentLevel, (byte)pk.CurrentLevel, OriginOptions.SkipChecks);
var count = EvolutionChain.GetOriginChain(chain, pk, origin);
var ver = (GameVersion)pk.Version;
var generator = EncounterGenerator.GetGenerator(ver);
@ -122,7 +122,7 @@ public static class EncounterSuggestion
int most = 1;
Span<EvoCriteria> chain = stackalloc EvoCriteria[EvolutionTree.MaxEvolutions];
var origin = new EvolutionOrigin(pk.Species, (byte)pk.Version, (byte)pk.Generation, startLevel, 100, SkipChecks: true);
var origin = new EvolutionOrigin(pk.Species, (byte)pk.Version, (byte)pk.Generation, startLevel, 100, OriginOptions.SkipChecks);
while (true)
{
var count = EvolutionChain.GetOriginChain(chain, pk, origin);

View file

@ -8,7 +8,7 @@ public sealed class EvolutionGroup1 : IEvolutionGroup, IEvolutionEnvironment
private static readonly EvolutionTree Tree = EvolutionTree.Evolves1;
public IEvolutionGroup GetNext(PKM pk, EvolutionOrigin enc) => EvolutionGroup2.Instance;
public IEvolutionGroup? GetPrevious(PKM pk, EvolutionOrigin enc) => pk.Format == 1 && ParseSettings.AllowGen1Tradeback ? EvolutionGroup2.Instance : null;
public IEvolutionGroup? GetPrevious(PKM pk, EvolutionOrigin enc) => !enc.NoDevolveGen1 && pk.Format == 1 && ParseSettings.AllowGen1Tradeback ? EvolutionGroup2.Instance : null;
public void DiscardForOrigin(Span<EvoCriteria> result, PKM pk)
{

View file

@ -1,3 +1,5 @@
using System;
namespace PKHeX.Core;
/// <summary>
@ -8,5 +10,26 @@ namespace PKHeX.Core;
/// <param name="Generation">Generation the encounter originated in</param>
/// <param name="LevelMin">Minimum level the encounter originated at</param>
/// <param name="LevelMax">Maximum level in final state</param>
/// <param name="SkipChecks">Skip enforcement of legality for evolution criteria</param>
public readonly record struct EvolutionOrigin(ushort Species, byte Version, byte Generation, byte LevelMin, byte LevelMax, bool SkipChecks = false);
/// <param name="Options">Options to toggle logic when using this data</param>
public readonly record struct EvolutionOrigin(ushort Species, byte Version, byte Generation, byte LevelMin, byte LevelMax, OriginOptions Options = 0)
{
/// <summary>
/// Checks if evolution checks against the Entity should be skipped when devolving or devolving.
/// </summary>
public bool SkipChecks => Options.HasFlag(OriginOptions.SkipChecks);
/// <summary>
/// Internally used to enforce Gen1 origin encounters NOT jumping to Gen2 to continue devolving.
/// </summary>
public bool NoDevolveGen1 => Options.HasFlag(OriginOptions.EncounterTemplate);
}
[Flags]
public enum OriginOptions : byte
{
None = 0,
SkipChecks = 1 << 0,
CheckVersionWhenNavigating = 1 << 1,
EncounterTemplate = SkipChecks | CheckVersionWhenNavigating,
}

View file

@ -186,7 +186,7 @@ public static class MoveListSuggest
var generator = EncounterGenerator.GetGenerator(enc.Version);
Span<EvoCriteria> chain = stackalloc EvoCriteria[EvolutionTree.MaxEvolutions];
var origin = new EvolutionOrigin(enc.Species, (byte)enc.Version, (byte)enc.Generation, 1, 100, true);
var origin = new EvolutionOrigin(enc.Species, (byte)enc.Version, (byte)enc.Generation, 1, 100, OriginOptions.EncounterTemplate);
int count = EvolutionChain.GetOriginChain(chain, pk, origin);
for (int i = 0; i < count; i++)
{

View file

@ -21,6 +21,7 @@ public class MarshalTests
[Theory]
[InlineData( 8, typeof(NPCLock))]
[InlineData( 8, typeof(IndividualValueSet))]
[InlineData( 8, typeof(EvolutionOrigin))]
[InlineData(16, typeof(DreamWorldEntry))]
[InlineData(16, typeof(CheckResult))]
[InlineData(16, typeof(EvolutionLink))]