mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-04-26 10:44:07 -05:00
Allow dragdrop into menustrip/legal/vertical tabs to load file ZA: Retain original criteria for cleanup application of IVs Inline vertical tabs color choice Simplify some expressions
165 lines
6.2 KiB
C#
165 lines
6.2 KiB
C#
using System;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Encounter Slot found in <see cref="GameVersion.ZA"/>.
|
|
/// </summary>
|
|
public sealed record EncounterSlot9a(EncounterArea9a Parent, ushort Species, byte Form, byte LevelMin, byte LevelMax, bool IsAlpha, byte Gender, Shiny Shiny)
|
|
: IEncounter9a, IEncounterConvertible<PA9>, IFixedGender
|
|
{
|
|
public byte Generation => 9;
|
|
private const GameVersion Version = GameVersion.ZA;
|
|
GameVersion IVersion.Version => GameVersion.ZA;
|
|
public EntityContext Context => EntityContext.Gen9a;
|
|
public bool IsEgg => false;
|
|
public AbilityPermission Ability => AbilityPermission.Any12;
|
|
public Ball FixedBall => Ball.None;
|
|
public bool IsShiny => false;
|
|
public ushort EggLocation => 0;
|
|
public bool IsRandomUnspecificForm => Form >= EncounterUtil.FormDynamic;
|
|
|
|
public string Name => "Wild Encounter";
|
|
public string LongName => $"{Name} {Type.ToString().Replace('_', ' ')}";
|
|
public ushort Location => Parent.Location;
|
|
public SlotType9a Type => Parent.Type;
|
|
|
|
public byte FlawlessIVCount => IsAlpha ? (byte)3 : (byte)0;
|
|
|
|
#region Generating
|
|
|
|
PKM IEncounterConvertible.ConvertToPKM(ITrainerInfo tr, EncounterCriteria criteria) => ConvertToPKM(tr, criteria);
|
|
PKM IEncounterConvertible.ConvertToPKM(ITrainerInfo tr) => ConvertToPKM(tr);
|
|
public PA9 ConvertToPKM(ITrainerInfo tr) => ConvertToPKM(tr, EncounterCriteria.Unrestricted);
|
|
public PA9 ConvertToPKM(ITrainerInfo tr, EncounterCriteria criteria)
|
|
{
|
|
int lang = (int)Language.GetSafeLanguage9a((LanguageID)tr.Language);
|
|
var pi = PersonalTable.ZA[Species, Form];
|
|
var pk = new PA9
|
|
{
|
|
Language = lang,
|
|
Species = Species,
|
|
Form = Form,
|
|
CurrentLevel = LevelMin,
|
|
MetLocation = Location,
|
|
MetLevel = LevelMin,
|
|
MetDate = EncounterDate.GetDateSwitch(),
|
|
Version = Version,
|
|
IsAlpha = IsAlpha,
|
|
Ball = (int)Ball.Poke,
|
|
|
|
OriginalTrainerName = tr.OT,
|
|
OriginalTrainerGender = tr.Gender,
|
|
ID32 = tr.ID32,
|
|
OriginalTrainerFriendship = pi.BaseFriendship,
|
|
Nickname = SpeciesName.GetSpeciesNameGeneration(Species, lang, Generation),
|
|
ObedienceLevel = LevelMin,
|
|
};
|
|
SetPINGA(pk, criteria, pi);
|
|
SetMoves(pk, pi, LevelMin);
|
|
pk.HealPP();
|
|
|
|
pk.ResetPartyStats();
|
|
return pk;
|
|
}
|
|
|
|
private void SetPINGA(PA9 pk, EncounterCriteria criteria, PersonalInfo9ZA pi)
|
|
{
|
|
var param = GetParams(pi, criteria.Shiny.IsShiny());
|
|
ulong init = Util.Rand.Rand64();
|
|
var success = this.TryApply64(pk, init, param, criteria);
|
|
if (!success && !this.TryApply64(pk, init, param, criteria.WithoutIVs()))
|
|
this.TryApply64(pk, init, param, EncounterCriteria.Unrestricted);
|
|
}
|
|
|
|
private void SetMoves(PA9 pk, PersonalInfo9ZA pi, byte level)
|
|
{
|
|
var (learn, plus) = LearnSource9ZA.GetLearnsetAndPlus(Species, Form);
|
|
Span<ushort> moves = stackalloc ushort[4];
|
|
if (!IsAlpha)
|
|
{
|
|
learn.SetEncounterMoves(level, moves);
|
|
PlusRecordApplicator.SetPlusFlagsEncounter(pk, pi, plus, level);
|
|
}
|
|
else
|
|
{
|
|
learn.SetEncounterMovesBackwards(level, moves, sameDescend: false);
|
|
PlusRecordApplicator.SetPlusFlagsEncounter(pk, pi, plus, level, moves[0] = pi.AlphaMove);
|
|
}
|
|
pk.SetMoves(moves);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Matching
|
|
|
|
public bool IsMatchExact(PKM pk, EvoCriteria evo)
|
|
{
|
|
if (Form != evo.Form && !IsRandomUnspecificForm && !IsValidOutOfBoundsForm())
|
|
return false;
|
|
if (!this.IsLevelWithinRange(pk.MetLevel))
|
|
return false;
|
|
if (pk is IAlphaReadOnly a && a.IsAlpha != IsAlpha)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
private bool IsValidOutOfBoundsForm() => Species switch
|
|
{
|
|
(int)Core.Species.Furfrou => true, // Can change forms in-game.
|
|
_ => false,
|
|
};
|
|
|
|
public EncounterMatchRating GetMatchRating(PKM pk)
|
|
{
|
|
if (IsAlpha && pk is IPlusRecord pa9 && pk.PersonalInfo is IPermitPlus p && !pa9.GetMovePlusFlag(p.PlusMoveIndexes.IndexOf(PersonalTable.ZA[Species, Form].AlphaMove)))
|
|
return EncounterMatchRating.DeferredErrors;
|
|
|
|
var pidiv = TryGetSeed(pk, out _);
|
|
if (pidiv is SeedCorrelationResult.Invalid)
|
|
return EncounterMatchRating.DeferredErrors;
|
|
if (pidiv is SeedCorrelationResult.Ignore)
|
|
return EncounterMatchRating.Deferred; // might be a better match with another template
|
|
|
|
return EncounterMatchRating.Match;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public SeedCorrelationResult TryGetSeed(PKM pk, out ulong seed)
|
|
{
|
|
var param = GetParams(PersonalTable.ZA[Species, Form], false);
|
|
if (param.TryGetSeed(pk, out seed))
|
|
return SeedCorrelationResult.Success;
|
|
if (pk.IsShiny && !LumioseSolver.SearchShiny1 || !LumioseSolver.SearchShinyN)
|
|
return SeedCorrelationResult.Ignore;
|
|
|
|
param = param with { RollCount = 1 + ShinyCharm };
|
|
if (param.TryGetSeed(pk, out seed))
|
|
return SeedCorrelationResult.Success;
|
|
return SeedCorrelationResult.Invalid;
|
|
}
|
|
|
|
public LumioseCorrelation Correlation => IsAlpha ? LumioseCorrelation.PreApplyIVs : LumioseCorrelation.Normal;
|
|
|
|
private const byte ShinyCharm = 3;
|
|
|
|
public GenerateParam9a GetParams(PersonalInfo9ZA pi) => GetParams(pi, shinyCharm: false);
|
|
|
|
public GenerateParam9a GetParams(PersonalInfo9ZA pi, bool shinyCharm)
|
|
{
|
|
// Give the +3 for Shiny Charm so that the generator search is more likely to succeed.
|
|
var rollCount = (byte)(1 + (shinyCharm ? ShinyCharm : 0));
|
|
var scaleValue = IsAlpha ? (byte)255 : (byte)0;
|
|
var scaleType = IsAlpha ? SizeType9.VALUE : SizeType9.RANDOM;
|
|
var gender = Gender switch
|
|
{
|
|
0 => PersonalInfo.RatioMagicMale,
|
|
1 => PersonalInfo.RatioMagicFemale,
|
|
2 => PersonalInfo.RatioMagicGenderless,
|
|
_ => pi.Gender,
|
|
};
|
|
return new GenerateParam9a(gender, FlawlessIVCount, rollCount, Correlation, scaleType, Scale: scaleValue, Nature.Random, Ability, Shiny);
|
|
}
|
|
}
|