namespace PKHeX.Core; /// /// Logic pertaining to Pokérus -- the virus that doubles EVs gained from battle. /// public static class Pokerus { /// /// Gets the max duration (in days) that a strain can be infectious. /// /// Strain number /// Initial duration (in days). When the value decrements to zero, the Pokémon is no longer infectious. public static int GetMaxDuration(int strain) => (strain & 3) + 1; /// /// Checks if any Pokérus values are possible to have on the input entity. /// /// Entity to check /// True if Pokérus exists in the game format, or can be transmitted to the entity via another game. public static bool IsObtainable(PKM pk) => pk switch { PA8 pa8 => HasVisitedAnother(pa8), PB7 => false, PK9 => false, _ => true, }; private static bool HasVisitedAnother(PA8 pk) { if (pk.IsUntraded) return false; if (pk.Tracker == 0) return false; if (PersonalTable.BDSP.IsPresentInGame(pk.Species, pk.Form)) return true; if (PersonalTable.SWSH.IsPresentInGame(pk.Species, pk.Form)) return true; return pk.Generation is (< 8 and >= 1); // Transferred from prior game } /// /// Checks if the Pokérus value for Strain is possible to have on the input entity. /// /// Entity to check /// Strain number /// Duration remaining /// True if valid public static bool IsStrainValid(PKM pk, int strain, int days) { if (!IsObtainable(pk)) return IsSusceptible(strain, days); return IsStrainValid(strain, days); } /// public static bool IsStrainValid(int strain, int days) => strain switch { 0 when days is not 0 => false, 8 => false, _ => true, }; /// /// Checks if the Pokérus value for Duration is possible to have on the input entity. /// /// Strain number /// Duration remaining /// Maximum value permitted /// True if valid public static bool IsDurationValid(int strain, int days, out int max) { max = GetMaxDuration(strain); return (uint)days <= max; } /// /// Checks if the Pokémon is immune to the Pokérus. /// /// Strain number /// Duration remaining /// True if immune (cannot be infected). /// An immune Pokémon must have been infected and cured prior to being "immune". public static bool IsImmune(int strain, int days) => strain != 0 && days == 0; /// /// Checks if the Pokémon is currently infected with the Pokérus. /// /// Strain number /// Duration remaining /// True if currently infected, and infectious to others. public static bool IsInfectuous(int strain, int days) => strain != 0 && days != 0; /// /// Checks if the Pokémon can be infected with the Pokérus. /// /// Strain number /// Duration remaining /// True if can be infected by another infectious individual. public static bool IsSusceptible(int strain, int days) => strain == 0 && days == 0; /// /// Vaccinates the Pokémon so it will never be infectious in the format it exists in. /// /// Entity to modify. /// Overwrites all Pokérus values even if already legal. public static void Vaccinate(this PKM pk) { pk.PKRS_Strain = IsObtainable(pk) ? 1 : 0; pk.PKRS_Days = 0; } }