PKHeX/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic4Pokewalker.cs
Kurt ef3cb34387
Refactor EvoCriteria to be a struct, reduce allocation (#3483)
* Make EvolutionCriteria struct

8 bytes per object instead of 26
Unify LevelMin/LevelMax to match EncounterTemplate
bubble up precise array type for better iteration

* Inline queue operations, less allocation

* Inline some logic

* Update EvolutionChain.cs

* Improve clarity on duplicate move check

* Search reverse

For a dual stage chain, finds it first iteration rather than second.
2022-04-23 21:33:17 -07:00

55 lines
1.7 KiB
C#

namespace PKHeX.Core
{
/// <summary>
/// Generation 4 Pokéwalker Encounter
/// </summary>
/// <inheritdoc cref="EncounterStatic"/>
public sealed record EncounterStatic4Pokewalker : EncounterStatic
{
public override int Generation => 4;
public EncounterStatic4Pokewalker(ushort species, sbyte gender, byte level) : base(GameVersion.HGSS)
{
Species = species;
Gender = gender;
Level = level;
Gift = true;
Location = Locations.PokeWalker4;
}
protected override bool IsMatchLocation(PKM pkm)
{
if (pkm.Format == 4)
return Location == pkm.Met_Location;
return true; // transfer location verified later
}
protected override bool IsMatchLevel(PKM pkm, IDexLevel evo)
{
if (pkm.Format != 4) // Met Level lost on PK4=>PK5
return Level <= evo.LevelMax;
return pkm.Met_Level == Level;
}
protected override bool IsMatchPartial(PKM pkm)
{
if (Gift && pkm.Ball != Ball)
return true;
return base.IsMatchPartial(pkm);
}
protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
{
var pi = pk.PersonalInfo;
int gender = criteria.GetGender(Gender, pi);
int nature = (int)criteria.GetNature(Nature.Random);
// Cannot force an ability; nature-gender-trainerID only yield fixed PIDs.
// int ability = criteria.GetAbilityFromNumber(Ability, pi);
PIDGenerator.SetRandomPIDPokewalker(pk, nature, gender);
criteria.SetRandomIVs(pk);
}
}
}