Skip to content

Commit

Permalink
IEncounterable: Add down-level interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kwsch committed Nov 19, 2024
1 parent 8c37d9b commit 231b3ff
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace PKHeX.Core;
/// Encounter Slot found in <see cref="GameVersion.ORAS"/>.
/// </summary>
public sealed record EncounterSlot6AO(EncounterArea6AO Parent, ushort Species, byte Form, byte LevelMin, byte LevelMax)
: IEncounterable, IEncounterMatch, IEncounterConvertible<PK6>, IEncounterFormRandom
: IEncounterable, IEncounterMatch, IEncounterConvertible<PK6>, IEncounterFormRandom, IEncounterDownlevel
{
public byte Generation => 6;
public EntityContext Context => EntityContext.Gen6;
Expand Down Expand Up @@ -121,6 +121,8 @@ private void SetPINGA(PK6 pk, EncounterCriteria criteria, PersonalInfo6AO pi)
private const int FluteBoostMax = 4; // Black Flute increases levels.
private const int DexNavBoost = 29 + FluteBoostMax; // Maximum DexNav chain (95) and Flute.

public byte GetDownleveledMin() => (byte)(LevelMin - FluteBoostMin);

public bool IsMatchExact(PKM pk, EvoCriteria evo)
{
var boostMax = Type != Rock_Smash ? DexNavBoost : FluteBoostMax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace PKHeX.Core;
/// Generation 8 Nest Encounter (Regular Raid Dens)
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed record EncounterStatic8N : EncounterStatic8Nest<EncounterStatic8N>
public sealed record EncounterStatic8N : EncounterStatic8Nest<EncounterStatic8N>, IEncounterDownlevel
{
private readonly byte MinRank;
private readonly byte MaxRank;
Expand Down Expand Up @@ -77,6 +77,10 @@ protected override bool IsMatchLevel(PKM pk)
return metLevel % 10 <= 5;
}

private const byte SharedNestMinLevel = 20;

public byte GetDownleveledMin() => SharedNestMinLevel;

public bool IsDownLeveled(PKM pk)
{
var met = pk.MetLevel;
Expand All @@ -91,7 +95,7 @@ private bool IsDownLeveled(PKM pk, uint metLevel, int met)

// shared nests can be down-leveled to any
if (pk.MetLocation == SharedNest)
return met >= 20;
return met >= SharedNestMinLevel;

// native down-levels: only allow 1 rank down (1 badge 2star -> 25), (3badge 3star -> 35)
return ((MinRank <= 1 && 1 <= MaxRank && met == 25)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PKHeX.Core;
/// Generation 8 Nest Encounter (Distributed Crystal Data)
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed record EncounterStatic8NC(GameVersion Version) : EncounterStatic8Nest<EncounterStatic8NC>(Version), ILocation
public sealed record EncounterStatic8NC(GameVersion Version) : EncounterStatic8Nest<EncounterStatic8NC>(Version), ILocation, IEncounterDownlevel
{
ushort ILocation.Location => Watchtower;
public const ushort Location = Watchtower;
Expand All @@ -20,6 +20,10 @@ protected override bool IsMatchLocation(PKM pk)
return loc is SharedNest or Watchtower;
}

private const byte SharedNestMinLevel = 20;

public byte GetDownleveledMin() => SharedNestMinLevel;

protected override bool IsMatchLevel(PKM pk)
{
var lvl = pk.MetLevel;
Expand All @@ -29,7 +33,7 @@ protected override bool IsMatchLevel(PKM pk)
// Check downleveled (20-55)
if (lvl > Level)
return false;
if (lvl is < 20 or > 55)
if (lvl is < SharedNestMinLevel or > 55)
return false;
if (pk is { MetLocation: Watchtower, IsShiny: true })
return false; // host cannot downlevel and be shiny
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace PKHeX.Core;
/// Generation 8 Nest Encounter (Distributed Data)
/// </summary>
/// <inheritdoc cref="EncounterStatic8Nest{T}"/>
public sealed record EncounterStatic8ND : EncounterStatic8Nest<EncounterStatic8ND>
public sealed record EncounterStatic8ND : EncounterStatic8Nest<EncounterStatic8ND>, IEncounterDownlevel
{
/// <summary>
/// Distribution raid index for <see cref="GameVersion.SWSH"/>
Expand Down Expand Up @@ -56,6 +56,10 @@ public static EncounterStatic8ND Read(ReadOnlySpan<byte> data, [ConstantExpected
};
}

private const byte SharedNestMinLevel = 20;

public byte GetDownleveledMin() => SharedNestMinLevel;

protected override bool IsMatchLevel(PKM pk)
{
var lvl = pk.MetLevel;
Expand All @@ -73,7 +77,7 @@ protected override bool IsMatchLevel(PKM pk)
// Check downleveled (20-55)
if (lvl > Level)
return false;
if (lvl is < 20 or > 55)
if (lvl is < SharedNestMinLevel or > 55)
return false;

if (lvl % 5 != 0)
Expand Down
12 changes: 12 additions & 0 deletions PKHeX.Core/PKM/Interfaces/Templates/IEncounterDownlevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace PKHeX.Core;

/// <summary>
/// Interface for encounters that can be down-leveled by an additional game situation.
/// </summary>
public interface IEncounterDownlevel
{
/// <summary>
/// Get the minimum level when forcibly down-leveled by an additional game situation.
/// </summary>
byte GetDownleveledMin();
}

0 comments on commit 231b3ff

Please sign in to comment.