PKHeX/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic8N.cs
Kurt 88830e0d00
Update from .NET Framework 4.6 to .NET 7 (#3729)
Updates from net46->net7, dropping support for mono in favor of using the latest runtime (along with the performance/API improvements). Releases will be posted as 64bit only for now.

Refactors a good amount of internal API methods to be more performant and more customizable for future updates & fixes.

Adds functionality for Batch Editor commands to `>`, `<` and <=/>=

TID/SID properties renamed to TID16/SID16 for clarity; other properties exposed for Gen7 / display variants.

Main window has a new layout to account for DPI scaling (8 point grid)

Fixed: Tatsugiri and Paldean Tauros now output Showdown form names as Showdown expects
Changed: Gen9 species now interact based on the confirmed National Dex IDs (closes #3724)
Fixed: Pokedex set all no longer clears species with unavailable non-base forms (closes #3720)
Changed: Hyper Training suggestions now apply for level 50 in SV. (closes #3714)
Fixed: B2/W2 hatched egg met locations exclusive to specific versions are now explicitly checked (closes #3691)
Added: Properties for ribbon/mark count (closes #3659)
Fixed: Traded SV eggs are now checked correctly (closes #3692)
2023-01-21 20:02:33 -08:00

113 lines
3.3 KiB
C#

using System;
using static PKHeX.Core.Encounters8Nest;
namespace PKHeX.Core;
/// <summary>
/// Generation 8 Nest Encounter (Regular Raid Dens)
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed record EncounterStatic8N : EncounterStatic8Nest<EncounterStatic8N>
{
private readonly byte MinRank;
private readonly byte MaxRank;
private readonly byte NestID;
private byte[] NestLocations => Encounters8Nest.NestLocations[NestID];
public override byte Level { get => LevelMin; init { } }
public override byte LevelMin => LevelCaps[MinRank * 2];
public override byte LevelMax => LevelCaps[(MaxRank * 2) + 1];
public EncounterStatic8N(byte nestID, byte minRank, byte maxRank, byte val, GameVersion game) : base(game)
{
NestID = nestID;
MinRank = minRank;
MaxRank = maxRank;
DynamaxLevel = (byte)(MinRank + 1u);
FlawlessIVCount = val;
}
public static EncounterStatic8N Read(ReadOnlySpan<byte> data, GameVersion game) => new(data[6], data[7], data[8], data[9], game)
{
Species = System.Buffers.Binary.BinaryPrimitives.ReadUInt16LittleEndian(data),
Form = data[2],
Gender = (sbyte)data[3],
Ability = (AbilityPermission)data[4],
CanGigantamax = data[5] != 0,
};
private static ReadOnlySpan<byte> LevelCaps => new byte[]
{
15, 20, // 0
25, 30, // 1
35, 40, // 2
45, 50, // 3
55, 60, // 4
};
protected override bool IsMatchLevel(PKM pk, EvoCriteria evo)
{
var met = pk.Met_Level;
var metLevel = met - 15;
var rank = ((uint)metLevel) / 10;
if (rank > 4)
return false;
if (rank > MaxRank)
return false;
if (rank <= 1 && met <= byte.MaxValue)
{
if (InaccessibleRank12Nests.TryGetValue((byte)met, out var nests))
{
var nest = Array.IndexOf(nests, NestID);
if (nest >= 0)
return false;
}
}
if (rank < MinRank) // down-leveled
return IsDownLeveled(pk, metLevel, met);
return metLevel % 10 <= 5;
}
public bool IsDownLeveled(PKM pk)
{
var met = pk.Met_Level;
var metLevel = met - 15;
return met != LevelMax && IsDownLeveled(pk, metLevel, met);
}
private bool IsDownLeveled(PKM pk, int metLevel, int met)
{
if (metLevel % 5 != 0)
return false;
// shared nests can be down-leveled to any
if (pk.Met_Location == SharedNest)
return met >= 20;
// native down-levels: only allow 1 rank down (1 badge 2star -> 25), (3badge 3star -> 35)
return ((MinRank <= 1 && 1 <= MaxRank && met == 25)
|| (MinRank <= 2 && 2 <= MaxRank && met == 35)) && !pk.IsShiny;
}
protected override bool IsMatchLocation(PKM pk)
{
var loc = pk.Met_Location;
if (loc == SharedNest)
return true;
if (loc > byte.MaxValue)
return false;
return Array.IndexOf(NestLocations, (byte)loc) >= 0;
}
public override bool IsMatchExact(PKM pk, EvoCriteria evo)
{
if (pk.FlawlessIVCount < FlawlessIVCount)
return false;
return base.IsMatchExact(pk, evo);
}
}