mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-24 11:44:44 -05:00
Enhance Pokerus api functions
Fixes #3480 ; (0,0) is a valid state regardless of format.
This commit is contained in:
@@ -1,17 +1,92 @@
|
||||
namespace PKHeX.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Logic pertaining to Pokérus -- the virus that doubles EVs gained from battle.
|
||||
/// </summary>
|
||||
public static class Pokerus
|
||||
{
|
||||
/// <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>
|
||||
public static int GetMaxDuration(int strain) => (strain & 3) + 1;
|
||||
|
||||
public static bool IsObtainable(PKM pkm) => pkm is not PA8; // don't care about PK1
|
||||
/// <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>
|
||||
public static bool IsObtainable(PKM pk) => pk is not PA8; // don't care about PK1, not stored in the data.
|
||||
|
||||
public static bool IsStrainValid(PKM pkm, int strain, int days) => IsObtainable(pkm) && IsStrainValid(strain, days);
|
||||
/// <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);
|
||||
return IsStrainValid(strain, days);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IsStrainValid(PKM,int,int)"/>
|
||||
public static bool IsStrainValid(int strain, int days) => strain switch
|
||||
{
|
||||
0 when days is not 0 => false,
|
||||
8 => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
/// <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>
|
||||
public static bool IsInfectuous(int strain, int days) => strain != 0 && days != 0;
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,9 +130,9 @@ private void VerifyMiscPokerus(LegalityAnalysis data)
|
||||
if (!strainValid)
|
||||
data.AddLine(GetInvalid(string.Format(LPokerusStrainUnobtainable_0, strain)));
|
||||
|
||||
var expect = Pokerus.GetMaxDuration(strain);
|
||||
if (days > expect)
|
||||
data.AddLine(GetInvalid(string.Format(LPokerusDaysTooHigh_0, expect)));
|
||||
bool daysValid = Pokerus.IsDurationValid(strain, days, out var max);
|
||||
if (!daysValid)
|
||||
data.AddLine(GetInvalid(string.Format(LPokerusDaysTooHigh_0, max)));
|
||||
}
|
||||
|
||||
public void VerifyMiscG1(LegalityAnalysis data)
|
||||
|
||||
@@ -1102,13 +1102,16 @@ private void UpdatePKRSstrain(object sender, EventArgs e)
|
||||
|
||||
private void UpdatePKRSdays(object sender, EventArgs e)
|
||||
{
|
||||
if (CB_PKRSDays.SelectedIndex != 0)
|
||||
var days = CB_PKRSDays.SelectedIndex;
|
||||
if (days != 0)
|
||||
return;
|
||||
|
||||
// If no days are selected
|
||||
if (CB_PKRSStrain.SelectedIndex == 0)
|
||||
var strain = CB_PKRSStrain.SelectedIndex;
|
||||
if (Pokerus.IsSusceptible(strain, days))
|
||||
CHK_Cured.Checked = CHK_Infected.Checked = false; // No Strain = Never Cured / Infected, triggers Strain update
|
||||
else CHK_Cured.Checked = true; // Any Strain = Cured
|
||||
else if (Pokerus.IsImmune(strain, days))
|
||||
CHK_Cured.Checked = true; // Any Strain = Cured
|
||||
}
|
||||
|
||||
private void UpdatePKRSCured(object sender, EventArgs e)
|
||||
@@ -1141,7 +1144,7 @@ private void UpdatePKRSCured(object sender, EventArgs e)
|
||||
}
|
||||
// if not cured yet, days > 0
|
||||
if (!CHK_Cured.Checked && CHK_Infected.Checked && CB_PKRSDays.SelectedIndex == 0)
|
||||
CB_PKRSDays.SelectedIndex++;
|
||||
CB_PKRSDays.SelectedIndex = 1;
|
||||
|
||||
SetMarkings();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user