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"/>
|
|
|
|
public sealed record EncounterSlot8a : EncounterSlot, IAlpha
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
public EncounterSlot8a(EncounterArea8a area, int species, int form, int min, int max, byte alphaType, byte flawlessIVs, Gender gender) : base(area, species, form, min, max)
|
|
|
|
{
|
|
|
|
AlphaType = alphaType;
|
|
|
|
FlawlessIVCount = flawlessIVs;
|
|
|
|
Gender = gender;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
|
|
|
{
|
|
|
|
base.ApplyDetails(sav, criteria, pk);
|
|
|
|
pk.SetRandomEC();
|
|
|
|
if (Gender != Gender.Random)
|
|
|
|
pk.Gender = (int)Gender;
|
|
|
|
|
|
|
|
if (IsAlpha)
|
|
|
|
{
|
|
|
|
if (pk is IAlpha a)
|
|
|
|
a.IsAlpha = true;
|
|
|
|
if (pk is IScaledSize s)
|
|
|
|
s.HeightScalar = s.WeightScalar = byte.MaxValue;
|
2022-02-05 18:23:00 +00:00
|
|
|
if (Type is not SlotType.Landmark && pk is PA8 pa)
|
2022-02-10 03:21:45 +00:00
|
|
|
{
|
|
|
|
var extra = pa.AlphaMove = pa.GetRandomAlphaMove();
|
|
|
|
pa.SetMasteryFlagMove(extra);
|
|
|
|
pk.PushMove(extra);
|
|
|
|
}
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
|
|
|
if (pk is IScaledSizeValue v)
|
|
|
|
{
|
|
|
|
v.ResetHeight();
|
|
|
|
v.ResetWeight();
|
|
|
|
}
|
|
|
|
if (pk is PA8 pa8)
|
|
|
|
{
|
|
|
|
pa8.HeightScalarCopy = pa8.HeightScalar;
|
|
|
|
pa8.SetMasteryFlags();
|
|
|
|
}
|
|
|
|
if (FlawlessIVCount > 0)
|
|
|
|
pk.SetRandomIVs(flawless: FlawlessIVCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-07 00:14:46 +00:00
|
|
|
return GetAlphaMoveCompatibility(pkm);
|
2022-02-05 01:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private EncounterMatchRating GetAlphaMoveCompatibility(PKM pkm)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|