mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-16 09:08:02 +00:00
15779513f5
Not going to implement this within the base repo as z3 is too large of a dependency and is platform specific. If anyone wants to implement as a plugin project, just inject your new methods via the setters on the static func/action at the top of the 3 classes. Since z3's searches aren't instant, I'd recommend caching recent results in a dictionary, as re-parses are common. Something like the Wordfilter is what you'd be aiming for :) Closes #2617
116 lines
3.8 KiB
C#
116 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using static PKHeX.Core.Encounters8Nest;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Generation 8 Nest Encounter (Raid)
|
|
/// </summary>
|
|
public sealed class EncounterStatic8N : EncounterStatic, IGigantamax, IDynamaxLevel
|
|
{
|
|
public static Func<PKM, EncounterStatic8N, bool>? VerifyCorrelation { private get; set; }
|
|
public static Action<PKM, EncounterStatic8N, EncounterCriteria>? GenerateData { private get; set; }
|
|
|
|
public bool CanGigantamax { get; set; }
|
|
public byte DynamaxLevel { get; set; }
|
|
|
|
private readonly uint MinRank;
|
|
private readonly uint MaxRank;
|
|
private readonly byte NestID;
|
|
|
|
private IReadOnlyList<byte> NestLocations => Encounters8Nest.NestLocations[NestID];
|
|
|
|
public override int Location { get => SharedNest; set { } }
|
|
public override int Level { get => LevelMin; set { } }
|
|
public override int LevelMin => LevelCaps[MinRank * 2];
|
|
public override int LevelMax => LevelCaps[(MaxRank * 2) + 1];
|
|
|
|
public EncounterStatic8N(byte nestID, uint minRank, uint maxRank, byte val)
|
|
{
|
|
NestID = nestID;
|
|
MinRank = minRank;
|
|
MaxRank = maxRank;
|
|
DynamaxLevel = (byte)(MinRank + 1u);
|
|
FlawlessIVCount = val;
|
|
}
|
|
|
|
private static readonly int[] LevelCaps =
|
|
{
|
|
15, 20, // 0
|
|
25, 30, // 1
|
|
35, 40, // 2
|
|
45, 50, // 3
|
|
55, 60, // 4
|
|
};
|
|
|
|
public static bool IsHighestLevelTier(int lvl) => ArrayUtil.WithinRange(lvl, 55, 60);
|
|
|
|
protected override int GetMinimalLevel() => LevelCaps[MinRank * 2];
|
|
|
|
protected override bool IsMatchLevel(PKM pkm, int lvl)
|
|
{
|
|
var metLevel = pkm.Met_Level - 15;
|
|
var rank = (uint)(metLevel / 10);
|
|
if (rank > 4)
|
|
return false;
|
|
if (rank > MaxRank)
|
|
return false;
|
|
if (rank < MinRank) // downleveled
|
|
{
|
|
if (metLevel % 5 != 0)
|
|
return false;
|
|
if (pkm.Met_Location == SharedNest)
|
|
{ } // shared nests can be downleveled to any
|
|
else if (MinRank - rank > 1) // native downlevels: only allow 1 rank down (?)
|
|
return false;
|
|
}
|
|
|
|
return metLevel % 10 <= 5;
|
|
}
|
|
|
|
protected override bool IsMatchLocation(PKM pkm)
|
|
{
|
|
var loc = pkm.Met_Location;
|
|
return loc == SharedNest || (loc <= 255 && NestLocations.Contains((byte)loc));
|
|
}
|
|
|
|
public override bool IsMatch(PKM pkm, int lvl)
|
|
{
|
|
if (pkm is IDynamaxLevel d && d.DynamaxLevel < DynamaxLevel)
|
|
return false;
|
|
|
|
if (pkm.FlawlessIVCount < FlawlessIVCount)
|
|
return false;
|
|
|
|
if (Version != GameVersion.SWSH && pkm.Version != (int) Version && pkm.Met_Location != SharedNest)
|
|
return false;
|
|
|
|
if (VerifyCorrelation != null && !VerifyCorrelation(pkm, this))
|
|
return false;
|
|
|
|
return base.IsMatch(pkm, lvl);
|
|
}
|
|
|
|
public override bool IsMatchDeferred(PKM pkm)
|
|
{
|
|
if (base.IsMatchDeferred(pkm))
|
|
return true;
|
|
if (Ability != A4 && pkm.AbilityNumber == 4)
|
|
return true;
|
|
if (pkm is IGigantamax g && g.CanGigantamax != CanGigantamax)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
protected override void SetPINGA(PKM pk, EncounterCriteria criteria)
|
|
{
|
|
if (GenerateData != null)
|
|
GenerateData(pk, this, criteria);
|
|
else
|
|
base.SetPINGA(pk, criteria);
|
|
}
|
|
}
|
|
}
|