2022-02-05 01:35:15 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Encounter Slot found in <see cref="GameVersion.SWSH"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <inheritdoc cref="EncounterSlot"/>
|
2022-05-06 22:43:23 +00:00
|
|
|
public sealed record EncounterSlot8a : EncounterSlot, IAlpha, IMasteryInitialMoveShop8
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
|
|
|
public override int Generation => 8;
|
2022-02-05 18:23:00 +00:00
|
|
|
public SlotType Type => Area.Type;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
|
|
|
public bool IsAlpha { get => AlphaType is not 0; set => throw new InvalidOperationException("Do not mutate this field."); }
|
|
|
|
public byte FlawlessIVCount { get; }
|
|
|
|
public Gender Gender { get; }
|
|
|
|
public byte AlphaType { get; } // 0=Never, 1=Random, 2=Guaranteed
|
|
|
|
|
2022-03-07 07:25:47 +00:00
|
|
|
public EncounterSlot8a(EncounterArea8a area, ushort species, byte form, byte min, byte max, byte alphaType, byte flawlessIVs, Gender gender) : base(area, species, form, min, max)
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
|
|
|
AlphaType = alphaType;
|
|
|
|
FlawlessIVCount = flawlessIVs;
|
|
|
|
Gender = gender;
|
|
|
|
}
|
|
|
|
|
2022-04-23 04:11:11 +00:00
|
|
|
public bool HasAlphaMove => IsAlpha && Type is not SlotType.Landmark;
|
|
|
|
|
2022-05-06 22:43:23 +00:00
|
|
|
protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
2022-05-06 22:43:23 +00:00
|
|
|
base.SetPINGA(pk, criteria);
|
2022-02-05 01:35:15 +00:00
|
|
|
if (Gender != Gender.Random)
|
|
|
|
pk.Gender = (int)Gender;
|
|
|
|
|
2022-04-23 04:11:11 +00:00
|
|
|
var para = GetParams();
|
|
|
|
var (_, slotSeed) = Overworld8aRNG.ApplyDetails(pk, criteria, para, HasAlphaMove);
|
|
|
|
if (LevelMin != LevelMax)
|
|
|
|
pk.CurrentLevel = pk.Met_Level = Overworld8aRNG.GetRandomLevel(slotSeed, LevelMin, LevelMax);
|
2022-05-06 22:43:23 +00:00
|
|
|
}
|
2022-02-21 01:59:48 +00:00
|
|
|
|
2022-05-06 22:43:23 +00:00
|
|
|
protected override void SetEncounterMoves(PKM pk, GameVersion version, int level)
|
|
|
|
{
|
|
|
|
var pa8 = (PA8)pk;
|
|
|
|
Span<int> moves = stackalloc int[4];
|
|
|
|
var index = PersonalTable.LA.GetFormIndex(Species, Form);
|
|
|
|
var mastery = Legal.MasteryLA[index];
|
|
|
|
var learn = Legal.LevelUpLA[index];
|
|
|
|
if (pa8.AlphaMove != 0)
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
2022-05-06 22:43:23 +00:00
|
|
|
moves[0] = pa8.AlphaMove;
|
|
|
|
learn.SetEncounterMovesBackwards(level, moves, 1);
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
2022-05-06 22:43:23 +00:00
|
|
|
else
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
2022-05-06 22:43:23 +00:00
|
|
|
learn.SetEncounterMoves(level, moves);
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
2022-05-06 22:43:23 +00:00
|
|
|
pk.SetMoves(moves);
|
|
|
|
pk.SetMaximumPPCurrent(moves);
|
|
|
|
foreach (var move in moves)
|
|
|
|
{
|
|
|
|
if (mastery.GetMoveLevel(move) <= level)
|
|
|
|
pa8.SetMasteryFlagMove(move);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void SetFormatSpecificData(PKM pk)
|
|
|
|
{
|
|
|
|
var pa8 = (PA8)pk;
|
|
|
|
if (IsAlpha)
|
|
|
|
pa8.IsAlpha = true;
|
|
|
|
pa8.HeightScalarCopy = pa8.HeightScalar;
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void ApplyDetailsBall(PKM pk) => pk.Ball = (int)Ball.LAPoke;
|
|
|
|
|
|
|
|
public override EncounterMatchRating GetMatchRating(PKM pkm)
|
|
|
|
{
|
|
|
|
if (Gender is not Gender.Random && pkm.Gender != (int)Gender)
|
2022-02-07 00:14:46 +00:00
|
|
|
return EncounterMatchRating.PartialMatch;
|
|
|
|
|
|
|
|
var result = GetMatchRatingInternal(pkm);
|
|
|
|
var orig = base.GetMatchRating(pkm);
|
|
|
|
return result > orig ? result : orig;
|
|
|
|
}
|
|
|
|
|
|
|
|
private EncounterMatchRating GetMatchRatingInternal(PKM pkm)
|
|
|
|
{
|
|
|
|
if (pkm is IAlpha a && a.IsAlpha != IsAlpha)
|
2022-02-05 01:35:15 +00:00
|
|
|
return EncounterMatchRating.DeferredErrors;
|
2022-02-05 03:31:45 +00:00
|
|
|
if (FlawlessIVCount is not 0 && pkm.FlawlessIVCount < FlawlessIVCount)
|
2022-02-05 01:35:15 +00:00
|
|
|
return EncounterMatchRating.DeferredErrors;
|
2022-03-06 02:54:50 +00:00
|
|
|
if (IsFormArgMismatch(pkm))
|
|
|
|
return EncounterMatchRating.DeferredErrors;
|
2022-05-06 22:43:23 +00:00
|
|
|
if (!IsForcedMasteryCorrect(pkm))
|
|
|
|
return EncounterMatchRating.DeferredErrors;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
2022-05-06 22:43:23 +00:00
|
|
|
return GetMoveCompatibility(pkm);
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 02:54:50 +00:00
|
|
|
private bool IsFormArgMismatch(PKM pkm) => pkm.Species switch
|
|
|
|
{
|
|
|
|
(int)Core.Species.Wyrdeer when Species is not (int)Core.Species.Wyrdeer && pkm is IFormArgument { FormArgument: 0 } => true,
|
|
|
|
(int)Core.Species.Overqwil when Species is not (int)Core.Species.Overqwil && pkm is IFormArgument { FormArgument: 0 } => true,
|
|
|
|
(int)Core.Species.Basculegion when Species is not (int)Core.Species.Basculegion && pkm is IFormArgument { FormArgument: 0 } => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
2022-05-06 22:43:23 +00:00
|
|
|
private EncounterMatchRating GetMoveCompatibility(PKM pkm)
|
2022-02-05 01:35:15 +00:00
|
|
|
{
|
|
|
|
// Check for Alpha move compatibility.
|
|
|
|
if (pkm is not PA8 pa)
|
|
|
|
return EncounterMatchRating.Match;
|
|
|
|
|
|
|
|
var alphaMove = pa.AlphaMove;
|
2022-02-05 18:23:00 +00:00
|
|
|
bool hasAlphaMove = alphaMove != 0;
|
2022-02-10 00:17:44 +00:00
|
|
|
if (!pa.IsAlpha || Type is SlotType.Landmark)
|
2022-02-05 18:23:00 +00:00
|
|
|
return !hasAlphaMove ? EncounterMatchRating.Match : EncounterMatchRating.DeferredErrors;
|
2022-02-05 01:35:15 +00:00
|
|
|
|
|
|
|
var pi = PersonalTable.LA.GetFormEntry(Species, Form);
|
|
|
|
var tutors = pi.SpecialTutors[0];
|
|
|
|
|
|
|
|
if (alphaMove is 0)
|
|
|
|
{
|
|
|
|
bool hasAnyTutor = Array.IndexOf(tutors, true) >= 0;
|
|
|
|
if (hasAnyTutor)
|
|
|
|
return EncounterMatchRating.Deferred;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var idx = pa.MoveShopPermitIndexes;
|
|
|
|
var index = idx.IndexOf(idx);
|
|
|
|
if (index == -1)
|
|
|
|
return EncounterMatchRating.Deferred;
|
|
|
|
if (!tutors[index])
|
|
|
|
return EncounterMatchRating.Deferred;
|
|
|
|
}
|
|
|
|
return EncounterMatchRating.Match;
|
|
|
|
}
|
2022-02-21 01:59:48 +00:00
|
|
|
|
2022-05-06 22:43:23 +00:00
|
|
|
public bool IsForcedMasteryCorrect(PKM pkm)
|
|
|
|
{
|
|
|
|
if (pkm is not IMoveShop8Mastery p)
|
|
|
|
return true; // Can't check.
|
|
|
|
|
|
|
|
Span<int> moves = stackalloc int[4];
|
|
|
|
var level = pkm.Met_Level;
|
|
|
|
var index = PersonalTable.LA.GetFormIndex(Species, Form);
|
|
|
|
var mastery = Legal.MasteryLA[index];
|
|
|
|
var learn = Legal.LevelUpLA[index];
|
|
|
|
ushort alpha = 0;
|
|
|
|
if (pkm is PA8 { AlphaMove: not 0 } pa8)
|
|
|
|
{
|
|
|
|
moves[0] = alpha = pa8.AlphaMove;
|
|
|
|
learn.SetEncounterMovesBackwards(level, moves, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
learn.SetEncounterMoves(level, moves);
|
|
|
|
}
|
|
|
|
|
|
|
|
return p.IsValidMasteredEncounter(moves, mastery, level, alpha);
|
|
|
|
}
|
|
|
|
|
2022-04-23 04:11:11 +00:00
|
|
|
private OverworldParam8a GetParams()
|
2022-02-21 01:59:48 +00:00
|
|
|
{
|
|
|
|
var pt = PersonalTable.LA;
|
|
|
|
var entry = pt.GetFormEntry(Species, Form);
|
|
|
|
var gender = (byte)entry.Gender;
|
|
|
|
return new OverworldParam8a
|
|
|
|
{
|
|
|
|
IsAlpha = IsAlpha,
|
|
|
|
FlawlessIVs = FlawlessIVCount,
|
|
|
|
Shiny = Shiny,
|
2022-04-23 04:11:11 +00:00
|
|
|
RollCount = GetRollCount(Type),
|
2022-02-21 01:59:48 +00:00
|
|
|
GenderRatio = gender,
|
|
|
|
};
|
|
|
|
}
|
2022-04-23 04:11:11 +00:00
|
|
|
|
|
|
|
// hardcoded 7 to assume max dex progress + shiny charm.
|
|
|
|
private const int MaxRollCount = 7;
|
|
|
|
|
|
|
|
private static byte GetRollCount(SlotType type) => (byte)(MaxRollCount + type switch
|
|
|
|
{
|
2022-04-23 05:44:55 +00:00
|
|
|
SlotType.OverworldMMO => 12,
|
2022-04-23 04:11:11 +00:00
|
|
|
SlotType.OverworldMass => 25,
|
|
|
|
_ => 0,
|
|
|
|
});
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|