PKHeX/PKHeX.Core/Editing/Applicators/CatchRateApplicator.cs
Kurt a02712e375 Add gen5 spin trade as valid link trade loc
ty Cappy for reporting, and @PP-theSLAYER & @Lusamine for testing.
https://projectpokemon.org/home/forums/topic/57375-pkhex-new-update-legality-errors-contribution-page/page/32/#findComment-296214

gen4 spin trades in pt/hgss do not set the wrong value -- gen5 only bug.
2025-07-23 22:37:39 -05:00

57 lines
1.8 KiB
C#

namespace PKHeX.Core;
/// <summary>
/// Logic for applying a <see cref="PK1.CatchRate"/> value.
/// </summary>
public static class CatchRateApplicator
{
/// <summary>
/// Gets the suggested <see cref="PK1.CatchRate"/> for the entity.
/// </summary>
public static int GetSuggestedCatchRate(PK1 pk, SaveFile sav)
{
var la = new LegalityAnalysis(pk);
return GetSuggestedCatchRate(pk, sav, la);
}
/// <summary>
/// Gets the suggested <see cref="PK1.CatchRate"/> for the entity.
/// </summary>
public static byte GetSuggestedCatchRate(PK1 pk, SaveFile sav, LegalityAnalysis la)
{
// If it is already valid, just use the current value.
if (la.Valid)
return pk.CatchRate;
// If it has ever visited generation 2, the Held Item can be removed prior to trade back.
if (la.Info.Generation == 2)
return 0;
// Return the encounter's original value.
var enc = la.EncounterMatch;
switch (enc)
{
case EncounterGift1 { Trainer: EncounterGift1.TrainerType.Stadium, Species: (int)Species.Psyduck }:
return pk.Japanese ? (byte)167 : (byte)168; // Amnesia Psyduck has different catch rates depending on language
default:
var pt = GetPersonalTable(sav, enc.Version);
var pi = pt[enc.Species];
return pi.CatchRate;
}
}
private static PersonalTable1 GetPersonalTable(SaveFile sav, GameVersion version)
{
if (sav.Personal is PersonalTable1 pt)
{
var other = sav.Version;
if (other.Contains(version) || version.Contains(other))
return pt;
}
if (!GameVersion.RB.Contains(version))
return PersonalTable.Y;
return PersonalTable.RB;
}
}