2022-06-17 23:38:05 +00:00
|
|
|
namespace PKHeX.Core;
|
2022-04-09 19:27:16 +00:00
|
|
|
|
2022-04-14 21:05:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Logic pertaining to Pokérus -- the virus that doubles EVs gained from battle.
|
|
|
|
/// </summary>
|
2022-04-09 19:27:16 +00:00
|
|
|
public static class Pokerus
|
|
|
|
{
|
2022-04-14 21:05:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the max duration (in days) that a strain can be infectious.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="strain">Strain number</param>
|
|
|
|
/// <returns>Initial duration (in days). When the value decrements to zero, the Pokémon is no longer infectious.</returns>
|
2022-04-09 19:27:16 +00:00
|
|
|
public static int GetMaxDuration(int strain) => (strain & 3) + 1;
|
|
|
|
|
2022-04-14 21:05:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if any Pokérus values are possible to have on the input entity.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="pk">Entity to check</param>
|
|
|
|
/// <returns>True if Pokérus exists in the game format, or can be transmitted to the entity via another game.</returns>
|
2022-05-31 04:43:52 +00:00
|
|
|
public static bool IsObtainable(PKM pk) => pk switch
|
|
|
|
{
|
2022-07-12 01:55:32 +00:00
|
|
|
PA8 pa8 => HasVisitedAnother(pa8),
|
2022-06-17 23:38:05 +00:00
|
|
|
PB7 => false,
|
2022-11-25 01:42:17 +00:00
|
|
|
PK9 => false,
|
2022-05-31 04:43:52 +00:00
|
|
|
_ => true,
|
|
|
|
};
|
|
|
|
|
2022-07-12 01:55:32 +00:00
|
|
|
private static bool HasVisitedAnother(PA8 pk)
|
2022-05-31 04:43:52 +00:00
|
|
|
{
|
|
|
|
if (pk.IsUntraded)
|
|
|
|
return false;
|
2022-08-23 06:18:53 +00:00
|
|
|
if (pk.Tracker == 0)
|
|
|
|
return false;
|
2022-05-31 04:43:52 +00:00
|
|
|
if (PersonalTable.BDSP.IsPresentInGame(pk.Species, pk.Form))
|
|
|
|
return true;
|
|
|
|
if (PersonalTable.SWSH.IsPresentInGame(pk.Species, pk.Form))
|
|
|
|
return true;
|
2022-07-12 01:55:32 +00:00
|
|
|
return pk.Generation is (< 8 and >= 1); // Transferred from prior game
|
2022-05-31 04:43:52 +00:00
|
|
|
}
|
2022-04-09 19:27:16 +00:00
|
|
|
|
2022-04-14 21:05:32 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the Pokérus value for Strain is possible to have on the input entity.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="pk">Entity to check</param>
|
|
|
|
/// <param name="strain">Strain number</param>
|
|
|
|
/// <param name="days">Duration remaining</param>
|
|
|
|
/// <returns>True if valid</returns>
|
|
|
|
public static bool IsStrainValid(PKM pk, int strain, int days)
|
|
|
|
{
|
|
|
|
if (!IsObtainable(pk))
|
|
|
|
return IsSusceptible(strain, days);
|
2023-04-19 07:11:45 +00:00
|
|
|
if (pk.Format <= 2)
|
2023-04-21 07:22:44 +00:00
|
|
|
return IsStrainValid2(strain);
|
|
|
|
return IsStrainValid(strain);
|
2022-04-14 21:05:32 +00:00
|
|
|
}
|
2022-04-09 19:27:16 +00:00
|
|
|
|
2022-04-14 21:05:32 +00:00
|
|
|
/// <inheritdoc cref="IsStrainValid(PKM,int,int)"/>
|
2023-04-19 07:11:45 +00:00
|
|
|
/// <remarks>
|
|
|
|
/// Strains 9+ are not obtainable due to game programming error (jmp label too early).
|
|
|
|
/// </remarks>
|
|
|
|
public static bool IsStrainValid2(int strain) => strain <= 8;
|
|
|
|
|
|
|
|
/// <inheritdoc cref="IsStrainValid(PKM,int,int)"/>
|
|
|
|
/// <remarks>
|
|
|
|
/// Gen3 R/S have a 30/255 chance of giving strain 0, and a 1/255 chance of giving strain 8.
|
|
|
|
/// Transfers will retain strain 0/8 and they're still able to infect others.
|
|
|
|
/// </remarks>
|
|
|
|
public static bool IsStrainValid(int strain) => strain <= 0xF;
|
2022-04-14 21:05:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the Pokérus value for Duration is possible to have on the input entity.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="strain">Strain number</param>
|
|
|
|
/// <param name="days">Duration remaining</param>
|
|
|
|
/// <param name="max">Maximum value permitted</param>
|
|
|
|
/// <returns>True if valid</returns>
|
|
|
|
public static bool IsDurationValid(int strain, int days, out int max)
|
|
|
|
{
|
|
|
|
max = GetMaxDuration(strain);
|
|
|
|
return (uint)days <= max;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the Pokémon is immune to the Pokérus.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="strain">Strain number</param>
|
|
|
|
/// <param name="days">Duration remaining</param>
|
|
|
|
/// <returns>True if immune (cannot be infected).</returns>
|
|
|
|
/// <remarks>An immune Pokémon must have been infected and cured prior to being "immune".</remarks>
|
|
|
|
public static bool IsImmune(int strain, int days) => strain != 0 && days == 0;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the Pokémon is currently infected with the Pokérus.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="strain">Strain number</param>
|
|
|
|
/// <param name="days">Duration remaining</param>
|
|
|
|
/// <returns>True if currently infected, and infectious to others.</returns>
|
2023-04-19 07:11:45 +00:00
|
|
|
public static bool IsInfectious(int strain, int days) => days != 0;
|
2022-04-14 21:05:32 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the Pokémon can be infected with the Pokérus.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="strain">Strain number</param>
|
|
|
|
/// <param name="days">Duration remaining</param>
|
|
|
|
/// <returns>True if can be infected by another infectious individual.</returns>
|
|
|
|
public static bool IsSusceptible(int strain, int days) => strain == 0 && days == 0;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Vaccinates the Pokémon so it will never be infectious in the format it exists in.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="pk">Entity to modify.</param>
|
|
|
|
/// <remarks>Overwrites all Pokérus values even if already legal.</remarks>
|
|
|
|
public static void Vaccinate(this PKM pk)
|
|
|
|
{
|
|
|
|
pk.PKRS_Strain = IsObtainable(pk) ? 1 : 0;
|
|
|
|
pk.PKRS_Days = 0;
|
|
|
|
}
|
2022-04-09 19:27:16 +00:00
|
|
|
}
|