2022-10-15 08:14:50 +00:00
|
|
|
using System;
|
2019-11-24 06:23:43 +00:00
|
|
|
using static PKHeX.Core.Encounters8Nest;
|
2019-11-21 01:07:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 8 Nest Encounter (Regular Raid Dens)
|
|
|
|
/// </summary>
|
|
|
|
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
|
|
|
|
public sealed record EncounterStatic8N : EncounterStatic8Nest<EncounterStatic8N>
|
2019-11-19 03:23:01 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
private readonly byte MinRank;
|
|
|
|
private readonly byte MaxRank;
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly byte NestID;
|
2019-11-21 01:07:51 +00:00
|
|
|
|
2022-10-15 08:14:50 +00:00
|
|
|
private byte[] NestLocations => Encounters8Nest.NestLocations[NestID];
|
2019-11-21 01:07:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override byte Level { get => LevelMin; init { } }
|
|
|
|
public override byte LevelMin => LevelCaps[MinRank * 2];
|
|
|
|
public override byte LevelMax => LevelCaps[(MaxRank * 2) + 1];
|
2019-11-19 03:23:01 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public EncounterStatic8N(byte nestID, byte minRank, byte maxRank, byte val, GameVersion game) : base(game)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
NestID = nestID;
|
|
|
|
MinRank = minRank;
|
|
|
|
MaxRank = maxRank;
|
|
|
|
DynamaxLevel = (byte)(MinRank + 1u);
|
|
|
|
FlawlessIVCount = val;
|
|
|
|
}
|
2019-11-19 03:23:01 +00:00
|
|
|
|
2022-11-25 01:42:17 +00:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
private static ReadOnlySpan<byte> LevelCaps => new byte[]
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2022-10-15 08:14:50 +00:00
|
|
|
if (rank <= 1 && met <= byte.MaxValue)
|
2019-11-19 03:23:01 +00:00
|
|
|
{
|
2022-10-15 08:14:50 +00:00
|
|
|
if (InaccessibleRank12Nests.TryGetValue((byte)met, out var nests))
|
|
|
|
{
|
|
|
|
var nest = Array.IndexOf(nests, NestID);
|
|
|
|
if (nest >= 0)
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2021-04-23 04:47:25 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
if (rank < MinRank) // down-leveled
|
|
|
|
return IsDownLeveled(pk, metLevel, met);
|
2020-01-06 02:46:30 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return metLevel % 10 <= 5;
|
|
|
|
}
|
2020-05-31 20:28:14 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool IsDownLeveled(PKM pk)
|
|
|
|
{
|
|
|
|
var met = pk.Met_Level;
|
|
|
|
var metLevel = met - 15;
|
|
|
|
return met != LevelMax && IsDownLeveled(pk, metLevel, met);
|
|
|
|
}
|
2020-05-31 20:28:14 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool IsDownLeveled(PKM pk, int metLevel, int met)
|
|
|
|
{
|
|
|
|
if (metLevel % 5 != 0)
|
|
|
|
return false;
|
2020-05-24 05:17:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// shared nests can be down-leveled to any
|
|
|
|
if (pk.Met_Location == SharedNest)
|
|
|
|
return met >= 20;
|
2019-11-19 03:23:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2019-11-19 03:23:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override bool IsMatchLocation(PKM pk)
|
|
|
|
{
|
|
|
|
var loc = pk.Met_Location;
|
2022-10-15 08:14:50 +00:00
|
|
|
if (loc == SharedNest)
|
|
|
|
return true;
|
|
|
|
if (loc > byte.MaxValue)
|
|
|
|
return false;
|
|
|
|
return Array.IndexOf(NestLocations, (byte)loc) >= 0;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-11-21 01:07:51 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override bool IsMatchExact(PKM pk, EvoCriteria evo)
|
|
|
|
{
|
|
|
|
if (pk.FlawlessIVCount < FlawlessIVCount)
|
|
|
|
return false;
|
2019-11-19 03:23:01 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return base.IsMatchExact(pk, evo);
|
2019-11-19 03:23:01 +00:00
|
|
|
}
|
2019-11-22 04:03:02 +00:00
|
|
|
}
|