Split up trySetStatus fully; fixed rest turn order display to match mainline

This commit is contained in:
Bertie690 2025-06-14 09:25:23 -04:00
parent c76739f629
commit 8a10cc2037
23 changed files with 513 additions and 411 deletions

View File

@ -1549,7 +1549,7 @@ export class PostDefendContactApplyStatusEffectAbAttr extends PostDefendAbAttr {
): void {
const effect =
this.effects.length === 1 ? this.effects[0] : this.effects[pokemon.randBattleSeedInt(this.effects.length)];
attacker.trySetStatus(effect, true, pokemon);
attacker.trySetStatus(effect, pokemon);
}
}
@ -2885,7 +2885,7 @@ export class PostAttackApplyStatusEffectAbAttr extends PostAttackAbAttr {
): void {
const effect =
this.effects.length === 1 ? this.effects[0] : this.effects[pokemon.randBattleSeedInt(this.effects.length)];
attacker.trySetStatus(effect, true, pokemon);
attacker.trySetStatus(effect, pokemon);
}
}
@ -3092,7 +3092,7 @@ export class SynchronizeStatusAbAttr extends PostSetStatusAbAttr {
_args: any[],
): void {
if (!simulated && sourcePokemon) {
sourcePokemon.trySetStatus(effect, true, pokemon);
sourcePokemon.trySetStatus(effect, pokemon);
}
}
}
@ -8931,7 +8931,7 @@ export function initAbilities() {
new Ability(AbilityId.ORICHALCUM_PULSE, 9)
.attr(PostSummonWeatherChangeAbAttr, WeatherType.SUNNY)
.attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.SUNNY)
.conditionalAttr(getWeatherCondition(WeatherType.SUNNY, WeatherType.HARSH_SUN), StatMultiplierAbAttr, Stat.ATK, 4 / 3), // No game freak rounding jank
.conditionalAttr(getWeatherCondition(WeatherType.SUNNY, WeatherType.HARSH_SUN), StatMultiplierAbAttr, Stat.ATK, 4 / 3),
new Ability(AbilityId.HADRON_ENGINE, 9)
.attr(PostSummonTerrainChangeAbAttr, TerrainType.ELECTRIC)
.attr(PostBiomeChangeTerrainChangeAbAttr, TerrainType.ELECTRIC)

View File

@ -552,7 +552,7 @@ class WishTag extends ArenaTag {
const target = globalScene.getField()[this.battlerIndex];
if (target?.isActive(true)) {
globalScene.phaseManager.queueMessage(this.triggerMessage);
globalScene.phaseManager.unshiftNew("PokemonHealPhase", target.getBattlerIndex(), this.healHp, null, true, false);
globalScene.phaseManager.unshiftNew("PokemonHealPhase", target.getBattlerIndex(), this.healHp, null);
}
}
}
@ -839,7 +839,6 @@ class ToxicSpikesTag extends ArenaTrapTag {
return pokemon.trySetStatus(
this.layers === 1 ? StatusEffect.POISON : StatusEffect.TOXIC,
true,
null,
0,
this.getMoveName(),

View File

@ -487,7 +487,7 @@ export class BeakBlastChargingTag extends BattlerTag {
target: pokemon,
})
) {
phaseData.attacker.trySetStatus(StatusEffect.BURN, true, pokemon);
phaseData.attacker.trySetStatus(StatusEffect.BURN, pokemon);
}
return true;
}
@ -1377,7 +1377,7 @@ export class DrowsyTag extends BattlerTag {
lapse(pokemon: Pokemon, lapseType: BattlerTagLapseType): boolean {
if (!super.lapse(pokemon, lapseType)) {
pokemon.trySetStatus(StatusEffect.SLEEP, true);
pokemon.trySetStatus(StatusEffect.SLEEP);
return false;
}
@ -1706,7 +1706,7 @@ export class ContactSetStatusProtectedTag extends DamageProtectedTag {
* @param user - The pokemon that is being attacked and has the tag
*/
override onContact(attacker: Pokemon, user: Pokemon): void {
attacker.trySetStatus(this.statusEffect, true, user);
attacker.trySetStatus(this.statusEffect, user);
}
}
@ -2668,7 +2668,7 @@ export class GulpMissileTag extends BattlerTag {
if (this.tagType === BattlerTagType.GULP_MISSILE_ARROKUDA) {
globalScene.phaseManager.unshiftNew("StatStageChangePhase", attacker.getBattlerIndex(), false, [Stat.DEF], -1);
} else {
attacker.trySetStatus(StatusEffect.PARALYSIS, true, pokemon);
attacker.trySetStatus(StatusEffect.PARALYSIS, pokemon);
}
}
return false;

View File

@ -27,7 +27,7 @@ import {
} from "../status-effect";
import { getTypeDamageMultiplier } from "../type";
import { PokemonType } from "#enums/pokemon-type";
import { BooleanHolder, NumberHolder, isNullOrUndefined, toDmgValue, randSeedItem, randSeedInt, getEnumValues, toReadableString, type Constructor, randSeedFloat } from "#app/utils/common";
import { BooleanHolder, NumberHolder, isNullOrUndefined, toDmgValue, randSeedItem, randSeedInt, getEnumValues, toReadableString, type Constructor, randSeedFloat, coerceArray } from "#app/utils/common";
import { WeatherType } from "#enums/weather-type";
import type { ArenaTrapTag } from "../arena-tag";
import { WeakenMoveTypeTag } from "../arena-tag";
@ -70,13 +70,9 @@ import {
getStatKey,
Stat,
} from "#app/enums/stat";
import { BattleEndPhase } from "#app/phases/battle-end-phase";
import { MoveEndPhase } from "#app/phases/move-end-phase";
import { MovePhase } from "#app/phases/move-phase";
import { NewBattlePhase } from "#app/phases/new-battle-phase";
import { PokemonHealPhase } from "#app/phases/pokemon-heal-phase";
import { StatStageChangePhase } from "#app/phases/stat-stage-change-phase";
import { SwitchPhase } from "#app/phases/switch-phase";
import { SwitchSummonPhase } from "#app/phases/switch-summon-phase";
import { SpeciesFormChangeRevertWeatherFormTrigger } from "../pokemon-forms/form-change-triggers";
import type { GameMode } from "#app/game-mode";
@ -1916,19 +1912,16 @@ export class AddSubstituteAttr extends MoveEffectAttr {
* @see {@linkcode apply}
*/
export class HealAttr extends MoveEffectAttr {
/** The percentage of {@linkcode Stat.HP} to heal */
private healRatio: number;
/** Should an animation be shown? */
private showAnim: boolean;
constructor(healRatio = 1, showAnim = false, selfTarget = true) {
constructor(
/** The percentage of {@linkcode Stat.HP} to heal. */
private healRatio: number,
/** Whether to display a healing animation when healing the target; default `false` */
private showAnim = false,
selfTarget = true) {
super(selfTarget);
this.healRatio = healRatio;
this.showAnim = showAnim;
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
override apply(user: Pokemon, target: Pokemon, _move: Move, _args: any[]): boolean {
this.addHealPhase(this.selfTarget ? user : target, this.healRatio);
return true;
}
@ -1937,15 +1930,97 @@ export class HealAttr extends MoveEffectAttr {
* Creates a new {@linkcode PokemonHealPhase}.
* This heals the target and shows the appropriate message.
*/
addHealPhase(target: Pokemon, healRatio: number) {
protected addHealPhase(target: Pokemon, healRatio: number) {
globalScene.phaseManager.unshiftNew("PokemonHealPhase", target.getBattlerIndex(),
toDmgValue(target.getMaxHp() * healRatio), i18next.t("moveTriggers:healHp", { pokemonName: getPokemonNameWithAffix(target) }), true, !this.showAnim);
}
getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number {
override getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number {
const score = ((1 - (this.selfTarget ? user : target).getHpRatio()) * 20) - this.healRatio * 10;
return Math.round(score / (1 - this.healRatio / 2));
}
override canApply(_user: Pokemon, target: Pokemon, _move: Move, _args?: any[]): boolean {
if (target.isFullHp()) {
globalScene.phaseManager.queueMessage(i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(target),
}))
return false;
}
return true;
}
}
/**
* Attribute for moves with variable healing amounts.
* Heals the target by an amount depending on the return value of {@linkcode healFunc}.
*
* Used for {@linkcode MoveId.MOONLIGHT}, {@linkcode MoveId.SHORE_UP}, {@linkcode MoveId.JUNGLE_HEALING}, {@linkcode MoveId.SWALLOW}
*/
export class VariableHealAttr extends HealAttr {
constructor(
/** A function yielding the amount of HP to heal. */
private healFunc: (user: Pokemon, target: Pokemon, _move: Move) => number,
showAnim = false,
selfTarget = true,
) {
super(1, showAnim, selfTarget);
this.healFunc = healFunc;
}
apply(user: Pokemon, target: Pokemon, move: Move, _args: any[]): boolean {
const healRatio = this.healFunc(user, target, move)
this.addHealPhase(target, healRatio);
return true;
}
}
/**
* Heals the target only if it is an ally.
* Used for {@linkcode MoveId.POLLEN_PUFF}.
*/
export class HealOnAllyAttr extends HealAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (user.getAlly() === target) {
super.apply(user, target, move, args);
return true;
}
return false;
}
override canApply(user: Pokemon, target: Pokemon, _move: Move, _args?: any[]): boolean {
return user.getAlly() !== target || super.canApply(user, target, _move, _args);
}
}
/**
* Attribute to put the user to sleep for a fixed duration, fully heal them and cure their status.
* Used for {@linkcode MoveId.REST}.
*/
export class RestAttr extends HealAttr {
private duration: number;
constructor(duration: number) {
super(1);
this.duration = duration;
}
override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
user.trySetStatus(StatusEffect.SLEEP, user, this.duration, null, true, true);
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:restBecameHealthy", {
pokemonName: getPokemonNameWithAffix(user),
}))
return super.apply(user, target, move, args);
}
override addHealPhase(user: Pokemon, healRatio: number): void {
globalScene.phaseManager.unshiftNew("PokemonHealPhase", user.getBattlerIndex(), healRatio, "")
}
canApply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
return super.canApply(user, target, move, args) && user.canSetStatus(StatusEffect.SLEEP, true, true, user)
}
}
/**
@ -2128,111 +2203,6 @@ export class IgnoreWeatherTypeDebuffAttr extends MoveAttr {
}
}
export abstract class WeatherHealAttr extends HealAttr {
constructor() {
super(0.5);
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
let healRatio = 0.5;
if (!globalScene.arena.weather?.isEffectSuppressed()) {
const weatherType = globalScene.arena.weather?.weatherType || WeatherType.NONE;
healRatio = this.getWeatherHealRatio(weatherType);
}
this.addHealPhase(user, healRatio);
return true;
}
abstract getWeatherHealRatio(weatherType: WeatherType): number;
}
export class PlantHealAttr extends WeatherHealAttr {
getWeatherHealRatio(weatherType: WeatherType): number {
switch (weatherType) {
case WeatherType.SUNNY:
case WeatherType.HARSH_SUN:
return 2 / 3;
case WeatherType.RAIN:
case WeatherType.SANDSTORM:
case WeatherType.HAIL:
case WeatherType.SNOW:
case WeatherType.HEAVY_RAIN:
return 0.25;
default:
return 0.5;
}
}
}
export class SandHealAttr extends WeatherHealAttr {
getWeatherHealRatio(weatherType: WeatherType): number {
switch (weatherType) {
case WeatherType.SANDSTORM:
return 2 / 3;
default:
return 0.5;
}
}
}
/**
* Heals the target or the user by either {@linkcode normalHealRatio} or {@linkcode boostedHealRatio}
* depending on the evaluation of {@linkcode condition}
* @extends HealAttr
* @see {@linkcode apply}
*/
export class BoostHealAttr extends HealAttr {
/** Healing received when {@linkcode condition} is false */
private normalHealRatio: number;
/** Healing received when {@linkcode condition} is true */
private boostedHealRatio: number;
/** The lambda expression to check against when boosting the healing value */
private condition?: MoveConditionFunc;
constructor(normalHealRatio: number = 0.5, boostedHealRatio: number = 2 / 3, showAnim?: boolean, selfTarget?: boolean, condition?: MoveConditionFunc) {
super(normalHealRatio, showAnim, selfTarget);
this.normalHealRatio = normalHealRatio;
this.boostedHealRatio = boostedHealRatio;
this.condition = condition;
}
/**
* @param user {@linkcode Pokemon} using the move
* @param target {@linkcode Pokemon} target of the move
* @param move {@linkcode Move} with this attribute
* @param args N/A
* @returns true if the move was successful
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const healRatio: number = (this.condition ? this.condition(user, target, move) : false) ? this.boostedHealRatio : this.normalHealRatio;
this.addHealPhase(target, healRatio);
return true;
}
}
/**
* Heals the target only if it is the ally
* @extends HealAttr
* @see {@linkcode apply}
*/
export class HealOnAllyAttr extends HealAttr {
/**
* @param user {@linkcode Pokemon} using the move
* @param target {@linkcode Pokemon} target of the move
* @param move {@linkcode Move} with this attribute
* @param args N/A
* @returns true if the function succeeds
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (user.getAlly() === target) {
super.apply(user, target, move, args);
return true;
}
return false;
}
}
/**
* Heals user as a side effect of a move that hits a target.
* Healing is based on {@linkcode healRatio} * the amount of damage dealt or a stat of the target.
@ -2240,6 +2210,7 @@ export class HealOnAllyAttr extends HealAttr {
* @see {@linkcode apply}
* @see {@linkcode getUserBenefitScore}
*/
// TODO: Make Strength Sap its own attribute that extends off of this one
export class HitHealAttr extends MoveEffectAttr {
private healRatio: number;
private healStat: EffectiveStat | null;
@ -2508,7 +2479,7 @@ export class StatusEffectAttr extends MoveEffectAttr {
const quiet = move.category !== MoveCategory.STATUS;
if (
target.trySetStatus(this.effect, true, user, undefined, null, false, quiet)
target.trySetStatus(this.effect, user, undefined, null, false, quiet)
) {
applyPostAttackAbAttrs("ConfusionOnStatusEffectAbAttr", user, target, move, null, false, this.effect);
return true;
@ -2516,7 +2487,6 @@ export class StatusEffectAttr extends MoveEffectAttr {
return false;
}
getTargetBenefitScore(user: Pokemon, target: Pokemon, move: Move): number {
const moveChance = this.getMoveChance(user, target, move, this.selfTarget, false);
const score = moveChance < 0 ? -10 : Math.floor(moveChance * -0.1);
@ -2526,25 +2496,6 @@ export class StatusEffectAttr extends MoveEffectAttr {
}
}
/**
* Attribute to put the target to sleep for a fixed duration and cure its status.
* Used for {@linkcode Moves.REST}.
*/
export class RestAttr extends StatusEffectAttr {
private duration: number;
constructor(duration: number) {
// Sleep is the only duration-based status ATM
super(StatusEffect.SLEEP, true);
this.duration = duration;
}
// TODO: Add custom text for rest and make `HealAttr` no longer show the message
protected override doSetStatus(pokemon: Pokemon, user: Pokemon, quiet: boolean): boolean {
return pokemon.trySetStatus(this.effect, true, user, this.duration, null, true, quiet)
}
}
/**
* Attribute to randomly apply one of several statuses to the target.
* Used for {@linkcode Moves.TRI_ATTACK} and {@linkcode Moves.DIRE_CLAW}.
@ -2587,13 +2538,13 @@ export class PsychoShiftEffectAttr extends MoveEffectAttr {
(user.hasAbility(AbilityId.COMATOSE) ? StatusEffect.SLEEP : undefined);
// Bang is justified as condition func returns early if no status is found
if (!target.trySetStatus(statusToApply!, true, user)) {
if (!target.trySetStatus(statusToApply!, user)) {
return false;
}
if (user.status) {
// Add tag to user to heal its status effect after the move ends (unless we have comatose);
// Occurs after move use to ensure correct Synchronize timing
// occurs after move use to ensure correct Synchronize timing
user.addTag(BattlerTagType.PSYCHO_SHIFT)
}
@ -2677,7 +2628,7 @@ export class StealHeldItemChanceAttr extends MoveEffectAttr {
* Used for Incinerate and Knock Off.
* Not Implemented Cases: (Same applies for Thief)
* "If the user faints due to the target's Ability (Rough Skin or Iron Barbs) or held Rocky Helmet, it cannot remove the target's held item."
* "If the Pokémon is knocked out by the attack, Sticky Hold does not protect the held item.""
* "If the Pokémon is knocked out by the attack, Sticky Hold does not protect the held item."
*/
export class RemoveHeldItemAttr extends MoveEffectAttr {
@ -2887,10 +2838,7 @@ export class HealStatusEffectAttr extends MoveEffectAttr {
*/
constructor(selfTarget: boolean, effects: StatusEffect | StatusEffect[]) {
super(selfTarget, { lastHitOnly: true });
if (!Array.isArray(effects)) {
effects = [ effects ]
}
this.effects = effects
this.effects = coerceArray(effects)
}
/**
@ -4363,36 +4311,6 @@ export class SpitUpPowerAttr extends VariablePowerAttr {
}
}
/**
* Attribute used to apply Swallow's healing, which scales with Stockpile stacks.
* Does NOT remove stockpiled stacks.
*/
export class SwallowHealAttr extends HealAttr {
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
const stockpilingTag = user.getTag(StockpilingTag);
if (stockpilingTag && stockpilingTag.stockpiledCount > 0) {
const stockpiled = stockpilingTag.stockpiledCount;
let healRatio: number;
if (stockpiled === 1) {
healRatio = 0.25;
} else if (stockpiled === 2) {
healRatio = 0.50;
} else { // stockpiled >= 3
healRatio = 1.00;
}
if (healRatio) {
this.addHealPhase(user, healRatio);
return true;
}
}
return false;
}
}
const hasStockpileStacksCondition: MoveConditionFunc = (user) => {
const hasStockpilingTag = user.getTag(StockpilingTag);
return !!hasStockpilingTag && hasStockpilingTag.stockpiledCount > 0;
@ -7862,7 +7780,7 @@ export class StatusIfBoostedAttr extends MoveEffectAttr {
*/
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
if (target.turnData.statStagesIncreased) {
target.trySetStatus(this.effect, true, user);
target.trySetStatus(this.effect, user);
}
return true;
}
@ -8028,6 +7946,53 @@ const attackedByItemMessageFunc = (user: Pokemon, target: Pokemon, move: Move) =
return message;
};
const sunnyHealRatioFunc = (): number => {
if (globalScene.arena.weather?.isEffectSuppressed()) {
return 1 / 2;
}
switch (globalScene.arena.getWeatherType()) {
case WeatherType.SUNNY:
case WeatherType.HARSH_SUN:
return 2 / 3;
case WeatherType.RAIN:
case WeatherType.SANDSTORM:
case WeatherType.HAIL:
case WeatherType.SNOW:
case WeatherType.HEAVY_RAIN:
case WeatherType.FOG:
return 1 / 4;
case WeatherType.STRONG_WINDS:
default:
return 1 / 2;
}
}
const shoreUpHealRatioFunc = (): number => {
if (globalScene.arena.weather?.isEffectSuppressed()) {
return 1 / 2;
}
return globalScene.arena.getWeatherType() === WeatherType.SANDSTORM ? 2 / 3 : 1 / 2;
}
const swallowHealFunc = (user: Pokemon): number => {
const tag = user.getTag(StockpilingTag);
if (!tag || tag.stockpiledCount <= 0) {
return 0;
}
switch (tag.stockpiledCount) {
case 1:
return 0.25
case 2:
return 0.5
case 3:
default: // in case we ever get more stacks
return 1;
}
}
export class MoveCondition {
protected func: MoveConditionFunc;
@ -8238,15 +8203,12 @@ const MoveAttrs = Object.freeze({
SacrificialAttrOnHit,
HalfSacrificialAttr,
AddSubstituteAttr,
HealAttr,
PartyStatusCureAttr,
FlameBurstAttr,
SacrificialFullRestoreAttr,
IgnoreWeatherTypeDebuffAttr,
WeatherHealAttr,
PlantHealAttr,
SandHealAttr,
BoostHealAttr,
HealAttr,
VariableHealAttr,
HealOnAllyAttr,
HitHealAttr,
IncrementMovePriorityAttr,
@ -8311,7 +8273,6 @@ const MoveAttrs = Object.freeze({
PresentPowerAttr,
WaterShurikenPowerAttr,
SpitUpPowerAttr,
SwallowHealAttr,
MultiHitPowerIncrementAttr,
LastMoveDoublePowerAttr,
CombinedPledgePowerAttr,
@ -8888,7 +8849,6 @@ export function initMoves() {
.attr(MultiHitAttr, MultiHitType._2)
.makesContact(false),
new SelfStatusMove(MoveId.REST, PokemonType.PSYCHIC, -1, 5, -1, 0, 1)
.attr(HealAttr, 1, true)
.attr(RestAttr, 3)
.triageMove(),
new AttackMove(MoveId.ROCK_SLIDE, PokemonType.ROCK, MoveCategory.PHYSICAL, 75, 90, 10, 30, 0, 1)
@ -9158,13 +9118,13 @@ export function initMoves() {
.attr(StatStageChangeAttr, [ Stat.ATK ], 1, true),
new AttackMove(MoveId.VITAL_THROW, PokemonType.FIGHTING, MoveCategory.PHYSICAL, 70, -1, 10, -1, -1, 2),
new SelfStatusMove(MoveId.MORNING_SUN, PokemonType.NORMAL, -1, 5, -1, 0, 2)
.attr(PlantHealAttr)
.attr(VariableHealAttr, sunnyHealRatioFunc)
.triageMove(),
new SelfStatusMove(MoveId.SYNTHESIS, PokemonType.GRASS, -1, 5, -1, 0, 2)
.attr(PlantHealAttr)
.attr(VariableHealAttr, sunnyHealRatioFunc)
.triageMove(),
new SelfStatusMove(MoveId.MOONLIGHT, PokemonType.FAIRY, -1, 5, -1, 0, 2)
.attr(PlantHealAttr)
.attr(VariableHealAttr, sunnyHealRatioFunc)
.triageMove(),
new AttackMove(MoveId.HIDDEN_POWER, PokemonType.NORMAL, MoveCategory.SPECIAL, 60, 100, 15, -1, 0, 2)
.attr(HiddenPowerTypeAttr),
@ -9221,12 +9181,12 @@ export function initMoves() {
.condition(user => (user.getTag(StockpilingTag)?.stockpiledCount ?? 0) < 3)
.attr(AddBattlerTagAttr, BattlerTagType.STOCKPILING, true),
new AttackMove(MoveId.SPIT_UP, PokemonType.NORMAL, MoveCategory.SPECIAL, -1, -1, 10, -1, 0, 3)
.condition(hasStockpileStacksCondition)
.attr(SpitUpPowerAttr, 100)
.condition(hasStockpileStacksCondition)
.attr(RemoveBattlerTagAttr, [ BattlerTagType.STOCKPILING ], true),
new SelfStatusMove(MoveId.SWALLOW, PokemonType.NORMAL, -1, 10, -1, 0, 3)
.attr(VariableHealAttr, swallowHealFunc)
.condition(hasStockpileStacksCondition)
.attr(SwallowHealAttr)
.attr(RemoveBattlerTagAttr, [ BattlerTagType.STOCKPILING ], true)
.triageMove(),
new AttackMove(MoveId.HEAT_WAVE, PokemonType.FIRE, MoveCategory.SPECIAL, 95, 90, 10, 10, 0, 3)
@ -9610,15 +9570,16 @@ export function initMoves() {
.unimplemented(),
new StatusMove(MoveId.PSYCHO_SHIFT, PokemonType.PSYCHIC, 100, 10, -1, 0, 4)
.attr(PsychoShiftEffectAttr)
.edgeCase(),
// TODO: Verify status applied if a statused pokemon obtains Comatose (via Transform) and uses Psycho Shift
.edgeCase(),
new AttackMove(MoveId.TRUMP_CARD, PokemonType.NORMAL, MoveCategory.SPECIAL, -1, -1, 5, -1, 0, 4)
.makesContact()
.attr(LessPPMorePowerAttr),
new StatusMove(MoveId.HEAL_BLOCK, PokemonType.PSYCHIC, 100, 15, -1, 0, 4)
.attr(AddBattlerTagAttr, BattlerTagType.HEAL_BLOCK, false, true, 5)
.target(MoveTarget.ALL_NEAR_ENEMIES)
.reflectable(),
.reflectable()
.edgeCase(),
new AttackMove(MoveId.WRING_OUT, PokemonType.NORMAL, MoveCategory.SPECIAL, -1, 100, 5, -1, 0, 4)
.attr(OpponentHighHpPowerAttr, 120)
.makesContact(),
@ -10471,7 +10432,7 @@ export function initMoves() {
.unimplemented(),
/* End Unused */
new SelfStatusMove(MoveId.SHORE_UP, PokemonType.GROUND, -1, 5, -1, 0, 7)
.attr(SandHealAttr)
.attr(VariableHealAttr, shoreUpHealRatioFunc)
.triageMove(),
new AttackMove(MoveId.FIRST_IMPRESSION, PokemonType.BUG, MoveCategory.PHYSICAL, 90, 100, 10, -1, 2, 7)
.condition(new FirstMoveCondition()),
@ -10491,7 +10452,7 @@ export function initMoves() {
.attr(StatStageChangeAttr, [ Stat.SPD ], -1, true)
.punchingMove(),
new StatusMove(MoveId.FLORAL_HEALING, PokemonType.FAIRY, -1, 10, -1, 0, 7)
.attr(BoostHealAttr, 0.5, 2 / 3, true, false, (user, target, move) => globalScene.arena.terrain?.terrainType === TerrainType.GRASSY)
.attr(VariableHealAttr, () => globalScene.arena.terrain?.terrainType === TerrainType.GRASSY ? 2 / 3 : 1 / 2, true, false)
.triageMove()
.reflectable(),
new AttackMove(MoveId.HIGH_HORSEPOWER, PokemonType.GROUND, MoveCategory.PHYSICAL, 95, 95, 10, -1, 0, 7),

View File

@ -243,8 +243,9 @@ export const FieryFalloutEncounter: MysteryEncounter = MysteryEncounterBuilder.w
if (burnable?.length > 0) {
const roll = randSeedInt(burnable.length);
const chosenPokemon = burnable[roll];
if (chosenPokemon.trySetStatus(StatusEffect.BURN)) {
if (chosenPokemon.canSetStatus(StatusEffect.BURN, true)) {
// Burn applied
chosenPokemon.doSetStatus(StatusEffect.BURN);
encounter.setDialogueToken("burnedPokemon", chosenPokemon.getNameToRender());
encounter.setDialogueToken("abilityName", allAbilities[AbilityId.HEATPROOF].name);
queueEncounterMessage(`${namespace}:option.2.target_burned`);

View File

@ -304,7 +304,7 @@ export function getRandomSpeciesByStarterCost(
*/
export function koPlayerPokemon(pokemon: PlayerPokemon) {
pokemon.hp = 0;
pokemon.trySetStatus(StatusEffect.FAINT);
pokemon.doSetStatus(StatusEffect.FAINT);
pokemon.updateInfo();
queueEncounterMessage(
i18next.t("battle:fainted", {

View File

@ -154,7 +154,6 @@ export function getRandomStatus(statusA: Status | null, statusB: Status | null):
return randIntRange(0, 2) ? statusA : statusB;
}
// TODO: Make this a type and remove these
/**
* Gets all non volatile status effects
* @returns A list containing all non volatile status effects

View File

@ -1,5 +1,5 @@
/** Enum representing all non-volatile status effects. */
// TODO: Add a type that excludes `NONE` and `FAINT`
// TODO: Remove StatusEffect.FAINT
export enum StatusEffect {
NONE,
POISON,

View File

@ -3190,6 +3190,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
while (rand > movePool[index][1]) {
rand -= movePool[index++][1];
}
this.moveset.push(new PokemonMove(movePool[index][0], 0, 0));
}
// Trigger FormChange, except for enemy Pokemon during Mystery Encounters, to avoid crashes
@ -4560,14 +4561,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
);
}
// TODO: Add messages for misty/electric terrain
private queueImmuneMessage(quiet: boolean, effect: StatusEffect): void {
queueImmuneMessage(quiet: boolean, effect?: StatusEffect): void {
if (!effect || quiet) {
return;
}
const message =
effect && this.status?.effect === effect
? getStatusEffectOverlapText(effect, getPokemonNameWithAffix(this))
? getStatusEffectOverlapText(effect ?? StatusEffect.NONE, getPokemonNameWithAffix(this))
: i18next.t("abilityTriggers:moveImmunity", {
pokemonNameWithAffix: getPokemonNameWithAffix(this),
});
@ -4587,6 +4587,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
* @returns Whether {@linkcode effect} can be applied to this Pokemon.
*/
// TODO: Review and verify the message order precedence in mainline if multiple status-blocking effects are present at once
// TODO: Make argument order consistent with `trySetStatus`
canSetStatus(
effect: StatusEffect,
quiet = false,
@ -4595,7 +4596,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
ignoreField = false,
): boolean {
if (effect !== StatusEffect.FAINT) {
// Status-overriding moves (ie Rest) fail if their respective status already exists;
// Status-overriding moves (i.e. Rest) fail if their respective status already exists;
// all other moves fail if the target already has _any_ status
if (overrideStatus ? this.status?.effect === effect : this.status) {
this.queueImmuneMessage(quiet, effect);
@ -4690,29 +4691,27 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
/**
* Attempt to set this Pokemon's status to the specified condition.
* Enqueues a new `ObtainStatusEffectPhase` to trigger animations, etc.
* @param effect - The {@linkcode StatusEffect} to set.
* @param asPhase - Whether to set the status in a new {@linkcode ObtainStatusEffectPhase} or immediately; default `false`.
* If `false`, will not display most messages associated with status setting.
* @param sourcePokemon - The {@linkcode Pokemon} applying the status effect to the target,
* or `null` if the status is applied from a non-Pokemon source (hazards, etc.); default `null`.
* @param sleepTurnsRemaining - The number of turns to set {@linkcode StatusEffect.SLEEP} for;
* defaults to a random number between 2 and 4 and is unused for non-Sleep statuses.
* @param sourceText - The text to show for the source of the status effect, if any;
* defaults to `null` and is unused if `asPhase=false`.
* @param sourceText - The text to show for the source of the status effect, if any; default `null`.
* @param overrideStatus - Whether to allow overriding the Pokemon's current status with a different one; default `false`.
* @param quiet - Whether to suppress in-battle messages for status checks; default `false`.
* @returns Whether the status effect was successfully applied (or a phase for it)
* @param quiet - Whether to suppress in-battle messages for status checks; default `true`.
* @returns Whether the status effect phase was successfully created.
* @see {@linkcode doSetStatus} - alternate function that sets status immediately (albeit without condition checks).
*/
trySetStatus(
effect: StatusEffect,
asPhase = false,
sourcePokemon: Pokemon | null = null,
sleepTurnsRemaining?: number,
sourceText: string | null = null,
overrideStatus?: boolean,
quiet = true,
): boolean {
// TODO: Remove uses of `asPhase=false` in favor of checking status directly
// TODO: This needs to propagate failure status for non-status moves
if (!this.canSetStatus(effect, quiet, overrideStatus, sourcePokemon)) {
return false;
}
@ -4736,46 +4735,42 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
this.resetStatus(false);
}
// TODO: This needs to propagate failure status for non-status moves
if (asPhase) {
globalScene.phaseManager.unshiftNew(
"ObtainStatusEffectPhase", this.getBattlerIndex(), effect, sleepTurnsRemaining, sourceText, sourcePokemon
)
} else {
this.doSetStatus(effect, sleepTurnsRemaining);
}
globalScene.phaseManager.unshiftNew(
"ObtainStatusEffectPhase",
this.getBattlerIndex(),
effect,
sleepTurnsRemaining,
sourceText,
sourcePokemon,
);
return true;
}
/**
* Attempt to give the specified Pokemon the given status effect.
* Does **NOT** perform any feasibility checks whatsoever, and should thus never be called directly
* unless conditions are known to be met.
* Set this Pokemon's {@linkcode status | status condition} to the specified effect.
* Does **NOT** perform any feasibility checks whatsoever; must be checked by the caller.
* @param effect - The {@linkcode StatusEffect} to set
*/
doSetStatus(effect: Exclude<StatusEffect, StatusEffect.SLEEP>): void;
/**
* Attempt to give the specified Pokemon the given status effect.
* Does **NOT** perform any feasibility checks whatsoever, and should thus never be called directly
* unless conditions are known to be met.
* Set this Pokemon's {@linkcode status | status condition} to the specified effect.
* Does **NOT** perform any feasibility checks whatsoever; must be checked by the caller.
* @param effect - {@linkcode StatusEffect.SLEEP}
* @param sleepTurnsRemaining - The number of turns to inflict sleep for; defaults to a random number between 2 and 4.
*/
doSetStatus(effect: StatusEffect.SLEEP, sleepTurnsRemaining?: number): void;
/**
* Attempt to give the specified Pokemon the given status effect.
* Does **NOT** perform any feasibility checks whatsoever, and should thus never be called directly
* unless conditions are known to be met.
* Set this Pokemon's {@linkcode status | status condition} to the specified effect.
* Does **NOT** perform any feasibility checks whatsoever; must be checked by the caller.
* @param effect - The {@linkcode StatusEffect} to set
* @param sleepTurnsRemaining - The number of turns to inflict sleep for; defaults to a random number between 2 and 4
* and is unused for all non-sleep Statuses.
*/
doSetStatus(effect: StatusEffect, sleepTurnsRemaining?: number): void;
/**
* Attempt to give the specified Pokemon the given status effect.
* Does **NOT** perform any feasibility checks whatsoever, and should thus never be called directly
* unless conditions are known to be met.
* Set this Pokemon's {@linkcode status | status condition} to the specified effect.
* Does **NOT** perform any feasibility checks whatsoever; must be checked by the caller.
* @param effect - The {@linkcode StatusEffect} to set
* @param sleepTurnsRemaining - The number of turns to inflict sleep for; defaults to a random number between 2 and 4
* and is unused for all non-sleep Statuses.
@ -4789,7 +4784,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
// If the user is semi-invulnerable when put asleep (such as due to Yawm),
// remove their invulnerability and cancel the upcoming move from the queue
const invulnTag = this.getTag(SemiInvulnerableTag)
const invulnTag = this.getTag(SemiInvulnerableTag);
if (invulnTag) {
this.removeTag(invulnTag.tagType);
this.getMoveQueue().shift();

View File

@ -1766,7 +1766,7 @@ export class TurnStatusEffectModifier extends PokemonHeldItemModifier {
* @returns `true` if the status effect was applied successfully
*/
override apply(pokemon: Pokemon): boolean {
return pokemon.trySetStatus(this.effect, true, pokemon, undefined, this.type.name);
return pokemon.trySetStatus(this.effect, pokemon, undefined, this.type.name);
}
getMaxHeldItemCount(_pokemon: Pokemon): number {
@ -3639,7 +3639,7 @@ export class EnemyAttackStatusEffectChanceModifier extends EnemyPersistentModifi
*/
override apply(enemyPokemon: Pokemon): boolean {
if (randSeedFloat() <= this.chance * this.getStackCount()) {
return enemyPokemon.trySetStatus(this.effect, true);
return enemyPokemon.trySetStatus(this.effect);
}
return false;

View File

@ -264,7 +264,7 @@ export class AttemptCapturePhase extends PokemonPhase {
const removePokemon = () => {
globalScene.addFaintedEnemyScore(pokemon);
pokemon.hp = 0;
pokemon.trySetStatus(StatusEffect.FAINT);
pokemon.doSetStatus(StatusEffect.FAINT);
globalScene.clearEnemyHeldItemModifiers();
pokemon.leaveField(true, true, true);
};

View File

@ -49,7 +49,7 @@ export class AttemptRunPhase extends PokemonPhase {
enemyField.forEach(enemyPokemon => {
enemyPokemon.hideInfo().then(() => enemyPokemon.destroy());
enemyPokemon.hp = 0;
enemyPokemon.trySetStatus(StatusEffect.FAINT);
enemyPokemon.doSetStatus(StatusEffect.FAINT);
});
globalScene.phaseManager.pushNew("BattleEndPhase", false);

View File

@ -209,7 +209,7 @@ export class FaintPhase extends PokemonPhase {
pokemon.lapseTags(BattlerTagLapseType.FAINT);
pokemon.y -= 150;
pokemon.trySetStatus(StatusEffect.FAINT);
pokemon.doSetStatus(StatusEffect.FAINT);
if (pokemon.isPlayer()) {
globalScene.currentBattle.removeFaintedParticipant(pokemon as PlayerPokemon);
} else {

View File

@ -2,14 +2,13 @@ import { globalScene } from "#app/global-scene";
import type { BattlerIndex } from "#enums/battler-index";
import { CommonBattleAnim } from "#app/data/battle-anims";
import { CommonAnim } from "#enums/move-anims-common";
import { getStatusEffectObtainText, getStatusEffectOverlapText } from "#app/data/status-effect";
import { getStatusEffectObtainText } from "#app/data/status-effect";
import { StatusEffect } from "#app/enums/status-effect";
import type Pokemon from "#app/field/pokemon";
import { getPokemonNameWithAffix } from "#app/messages";
import { PokemonPhase } from "./pokemon-phase";
import { SpeciesFormChangeStatusEffectTrigger } from "#app/data/pokemon-forms/form-change-triggers";
import { applyPostSetStatusAbAttrs } from "#app/data/abilities/apply-ab-attrs";
import { isNullOrUndefined } from "#app/utils/common";
/** The phase where pokemon obtain status effects. */
export class ObtainStatusEffectPhase extends PokemonPhase {
@ -49,7 +48,7 @@ export class ObtainStatusEffectPhase extends PokemonPhase {
pokemon.doSetStatus(this.statusEffect, this.sleepTurnsRemaining);
pokemon.updateInfo(true);
new CommonBattleAnim(CommonAnim.POISON + (this.statusEffect! - 1), pokemon).play(false, () => {
new CommonBattleAnim(CommonAnim.POISON + (this.statusEffect - 1), pokemon).play(false, () => {
globalScene.phaseManager.queueMessage(
getStatusEffectObtainText(this.statusEffect, getPokemonNameWithAffix(pokemon), this.sourceText ?? undefined),
);

View File

@ -13,6 +13,7 @@ import { CommonAnimPhase } from "./common-anim-phase";
import { BattlerTagType } from "#app/enums/battler-tag-type";
import type { HealBlockTag } from "#app/data/battler-tags";
// TODO: Refactor this - it has far too many arguments
export class PokemonHealPhase extends CommonAnimPhase {
public readonly phaseName = "PokemonHealPhase";
private hpHealed: number;
@ -28,7 +29,7 @@ export class PokemonHealPhase extends CommonAnimPhase {
battlerIndex: BattlerIndex,
hpHealed: number,
message: string | null,
showFullHpMessage: boolean,
showFullHpMessage = true,
skipAnim = false,
revive = false,
healStatus = false,
@ -69,9 +70,10 @@ export class PokemonHealPhase extends CommonAnimPhase {
if (healBlock && this.hpHealed > 0) {
globalScene.phaseManager.queueMessage(healBlock.onActivation(pokemon));
this.message = null;
return super.end();
super.end();
return;
}
if (healOrDamage) {
const hpRestoreMultiplier = new NumberHolder(1);
if (!this.revive) {

View File

@ -64,7 +64,7 @@ describe("Abilities - Corrosion", () => {
expect(enemyPokemon.status?.effect).toBeUndefined();
game.move.select(MoveId.TOXIC);
await game.toEndOfTurn()
await game.toEndOfTurn();
expect(playerPokemon.status?.effect).toBe(StatusEffect.TOXIC);
expect(enemyPokemon.status?.effect).toBeUndefined();

View File

@ -47,9 +47,11 @@ describe("Abilities - Healer", () => {
it("should not queue a message phase for healing if the ally has fainted", async () => {
game.override.moveset([MoveId.SPLASH, MoveId.LUNAR_DANCE]);
await game.classicMode.startBattle([SpeciesId.MAGIKARP, SpeciesId.MAGIKARP]);
const user = game.scene.getPlayerPokemon()!;
// Only want one magikarp to have the ability.
vi.spyOn(user, "getAbility").mockReturnValue(allAbilities[AbilityId.HEALER]);
game.move.select(MoveId.SPLASH);
// faint the ally
game.move.select(MoveId.LUNAR_DANCE, 1);
@ -67,9 +69,10 @@ describe("Abilities - Healer", () => {
it("should heal the status of an ally if the ally has a status", async () => {
await game.classicMode.startBattle([SpeciesId.MAGIKARP, SpeciesId.MAGIKARP]);
const [user, ally] = game.scene.getPlayerField();
// Only want one magikarp to have the ability.
vi.spyOn(user, "getAbility").mockReturnValue(allAbilities[AbilityId.HEALER]);
expect(ally.trySetStatus(StatusEffect.BURN)).toBe(true);
ally.doSetStatus(StatusEffect.BURN);
game.move.select(MoveId.SPLASH);
game.move.select(MoveId.SPLASH, 1);
@ -85,7 +88,7 @@ describe("Abilities - Healer", () => {
const [user, ally] = game.scene.getPlayerField();
// Only want one magikarp to have the ability.
vi.spyOn(user, "getAbility").mockReturnValue(allAbilities[AbilityId.HEALER]);
expect(ally.trySetStatus(StatusEffect.BURN)).toBe(true);
ally.doSetStatus(StatusEffect.BURN);
game.move.select(MoveId.SPLASH);
game.move.select(MoveId.SPLASH, 1);
await game.phaseInterceptor.to("TurnEndPhase");

View File

@ -44,7 +44,7 @@ describe("Moves - Fusion Flare", () => {
await game.phaseInterceptor.to(TurnStartPhase, false);
// Inflict freeze quietly and check if it was properly inflicted
partyMember.trySetStatus(StatusEffect.FREEZE, false);
partyMember.doSetStatus(StatusEffect.FREEZE);
expect(partyMember.status!.effect).toBe(StatusEffect.FREEZE);
await game.toNextTurn();

View File

@ -5,6 +5,9 @@ import { SpeciesId } from "#enums/species-id";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
import { MoveResult } from "#enums/move-result";
import { getPokemonNameWithAffix } from "#app/messages";
import i18next from "i18next";
describe("Moves - Pollen Puff", () => {
let phaserGame: Phaser.Game;
@ -23,42 +26,77 @@ describe("Moves - Pollen Puff", () => {
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.moveset([MoveId.POLLEN_PUFF])
.ability(AbilityId.BALL_FETCH)
.battleStyle("single")
.disableCrits()
.enemyLevel(100)
.enemySpecies(SpeciesId.MAGIKARP)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH);
});
it("should not heal more than once when the user has a source of multi-hit", async () => {
game.override.battleStyle("double").moveset([MoveId.POLLEN_PUFF, MoveId.ENDURE]).ability(AbilityId.PARENTAL_BOND);
it("should damage an enemy when used, or heal an ally for 50% max HP", async () => {
game.override.battleStyle("double").ability(AbilityId.PARENTAL_BOND);
await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.OMANYTE]);
const [_, rightPokemon] = game.scene.getPlayerField();
const [_, omantye, karp1] = game.scene.getField();
omantye.hp = 1;
rightPokemon.damageAndUpdate(rightPokemon.hp - 1);
game.move.use(MoveId.POLLEN_PUFF, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2);
game.move.use(MoveId.POLLEN_PUFF, BattlerIndex.PLAYER_2, BattlerIndex.ENEMY);
await game.toEndOfTurn();
game.move.select(MoveId.POLLEN_PUFF, 0, BattlerIndex.PLAYER_2);
game.move.select(MoveId.ENDURE, 1);
expect(karp1.hp).toBeLessThan(karp1.getMaxHp());
expect(omantye.hp).toBeCloseTo(0.5 * omantye.getMaxHp() + 1, 1);
expect(game.phaseInterceptor.log).toContain("PokemonHealPhase");
});
await game.phaseInterceptor.to("BerryPhase");
it("should display message & count as failed when hitting a full HP ally", async () => {
game.override.battleStyle("double").ability(AbilityId.PARENTAL_BOND);
await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.OMANYTE]);
// Pollen Puff heals with a ratio of 0.5, as long as Pollen Puff triggers only once the pokemon will always be <= (0.5 * Max HP) + 1
expect(rightPokemon.hp).toBeLessThanOrEqual(0.5 * rightPokemon.getMaxHp() + 1);
const [bulbasaur, omantye] = game.scene.getPlayerField();
game.move.use(MoveId.POLLEN_PUFF, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2);
game.move.use(MoveId.SPLASH, BattlerIndex.PLAYER_2);
await game.toEndOfTurn();
// move failed without unshifting a phase
expect(omantye.hp).toBe(omantye.getMaxHp());
expect(bulbasaur.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
expect(game.textInterceptor.logs).toContain(
i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(omantye),
}),
);
expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase");
});
it("should not heal more than once if the user has a source of multi-hit", async () => {
game.override.battleStyle("double").ability(AbilityId.PARENTAL_BOND);
await game.classicMode.startBattle([SpeciesId.BULBASAUR, SpeciesId.OMANYTE]);
const [bulbasaur, omantye] = game.scene.getPlayerField();
omantye.hp = 1;
game.move.use(MoveId.POLLEN_PUFF, BattlerIndex.PLAYER, BattlerIndex.PLAYER_2);
game.move.use(MoveId.SPLASH, BattlerIndex.PLAYER_2);
await game.toEndOfTurn();
expect(bulbasaur.turnData.hitCount).toBe(1);
expect(omantye.hp).toBeLessThanOrEqual(0.5 * omantye.getMaxHp() + 1);
expect(game.phaseInterceptor.log.filter(l => l === "PokemonHealPhase")).toHaveLength(1);
});
it("should damage an enemy multiple times when the user has a source of multi-hit", async () => {
game.override.moveset([MoveId.POLLEN_PUFF]).ability(AbilityId.PARENTAL_BOND).enemyLevel(100);
game.override.ability(AbilityId.PARENTAL_BOND);
await game.classicMode.startBattle([SpeciesId.MAGIKARP]);
game.move.use(MoveId.POLLEN_PUFF);
await game.toEndOfTurn();
const target = game.scene.getEnemyPokemon()!;
game.move.select(MoveId.POLLEN_PUFF);
await game.phaseInterceptor.to("BerryPhase");
expect(target.battleData.hitCount).toBe(2);
});
});

View File

@ -0,0 +1,175 @@
import { getPokemonNameWithAffix } from "#app/messages";
import { getEnumValues, toReadableString } from "#app/utils/common";
import { AbilityId } from "#enums/ability-id";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import { WeatherType } from "#enums/weather-type";
import GameManager from "#test/testUtils/gameManager";
import i18next from "i18next";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Moves - Recovery Moves", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
describe.each<{ name: string; move: MoveId }>([
{ name: "Recover", move: MoveId.RECOVER },
{ name: "Soft-Boiled", move: MoveId.SOFT_BOILED },
{ name: "Milk Drink", move: MoveId.MILK_DRINK },
{ name: "Slack Off", move: MoveId.SLACK_OFF },
{ name: "Roost", move: MoveId.ROOST },
])("Normal Recovery Moves - $name", ({ move }) => {
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.ability(AbilityId.BALL_FETCH)
.battleStyle("single")
.disableCrits()
.enemySpecies(SpeciesId.MAGIKARP)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH)
.startingLevel(100)
.enemyLevel(100);
});
it("should heal 50% of the user's maximum HP", async () => {
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(move);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.5, 1);
expect(game.phaseInterceptor.log).toContain("PokemonHealPhase");
});
it("should display message and fail if used at full HP", async () => {
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
game.move.use(move);
await game.toEndOfTurn();
const blissey = game.field.getPlayerPokemon();
expect(blissey.hp).toBe(blissey.getMaxHp());
expect(game.textInterceptor.logs).toContain(
i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(blissey),
}),
);
expect(game.phaseInterceptor.log).not.toContain("PokemonHealPhase");
});
});
describe("Weather-based Healing moves", () => {
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.ability(AbilityId.BALL_FETCH)
.battleStyle("single")
.disableCrits()
.enemySpecies(SpeciesId.MAGIKARP)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH)
.startingLevel(100)
.enemyLevel(100);
});
it.each([
{ name: "Harsh Sunlight", ability: AbilityId.DROUGHT },
{ name: "Extremely Harsh Sunlight", ability: AbilityId.DESOLATE_LAND },
])("should heal 66% of the user's maximum HP under $name", async ({ ability }) => {
game.override.passiveAbility(ability);
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(MoveId.MOONLIGHT);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.67, 1);
});
const nonSunWTs = getEnumValues(WeatherType)
.filter(wt => ![WeatherType.NONE, WeatherType.STRONG_WINDS].includes(wt))
.map(wt => ({
name: toReadableString(WeatherType[wt]),
weather: wt,
}));
it.each(nonSunWTs)("should heal 25% of the user's maximum HP under $name", async ({ weather }) => {
game.override.weather(weather);
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(MoveId.MOONLIGHT);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.25, 1);
});
it("should heal 50% of the user's maximum HP under strong winds", async () => {
game.override.ability(AbilityId.DELTA_STREAM);
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(MoveId.MOONLIGHT);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.5, 1);
});
});
describe("Shore Up", () => {
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.ability(AbilityId.BALL_FETCH)
.battleStyle("single")
.disableCrits()
.enemySpecies(SpeciesId.MAGIKARP)
.enemyAbility(AbilityId.BALL_FETCH)
.enemyMoveset(MoveId.SPLASH)
.startingLevel(100)
.enemyLevel(100);
});
it("should heal 66% of the user's maximum HP under sandstorm", async () => {
game.override.ability(AbilityId.SAND_STREAM);
await game.classicMode.startBattle([SpeciesId.BLISSEY]);
const blissey = game.field.getPlayerPokemon();
blissey.hp = 1;
game.move.use(MoveId.SHORE_UP);
await game.toEndOfTurn();
expect(blissey.getHpRatio()).toBeCloseTo(0.66, 1);
});
});
});

View File

@ -1,4 +1,4 @@
import { MoveResult } from "#app/field/pokemon";
import { MoveResult } from "#enums/move-result";
import { AbilityId } from "#enums/ability-id";
import { BattlerTagType } from "#enums/battler-tag-type";
import { MoveId } from "#enums/move-id";
@ -26,7 +26,6 @@ describe("MoveId - Rest", () => {
beforeEach(() => {
game = new GameManager(phaserGame);
game.override
.moveset([MoveId.REST, MoveId.SWORDS_DANCE])
.ability(AbilityId.BALL_FETCH)
.battleStyle("single")
.disableCrits()
@ -39,11 +38,11 @@ describe("MoveId - Rest", () => {
game.override.statusEffect(StatusEffect.POISON);
await game.classicMode.startBattle([SpeciesId.SNORLAX]);
const snorlax = game.scene.getPlayerPokemon()!;
const snorlax = game.field.getPlayerPokemon();
snorlax.hp = 1;
expect(snorlax.status?.effect).toBe(StatusEffect.POISON);
game.move.select(MoveId.REST);
game.move.use(MoveId.REST);
await game.toEndOfTurn();
expect(snorlax.isFullHp()).toBe(true);
@ -53,26 +52,26 @@ describe("MoveId - Rest", () => {
it("should always last 3 turns", async () => {
await game.classicMode.startBattle([SpeciesId.SNORLAX]);
const snorlax = game.scene.getPlayerPokemon()!;
const snorlax = game.field.getPlayerPokemon();
snorlax.hp = 1;
// Cf https://bulbapedia.bulbagarden.net/wiki/Rest_(move):
// > The user is unable to use MoveId while asleep for 2 turns after the turn when Rest is used.
game.move.select(MoveId.REST);
game.move.use(MoveId.REST);
await game.toNextTurn();
expect(snorlax.status?.effect).toBe(StatusEffect.SLEEP);
expect(snorlax.status?.sleepTurnsRemaining).toBe(3);
game.move.select(MoveId.SWORDS_DANCE);
game.move.use(MoveId.SWORDS_DANCE);
await game.toNextTurn();
expect(snorlax.status?.sleepTurnsRemaining).toBe(2);
game.move.select(MoveId.SWORDS_DANCE);
game.move.use(MoveId.SWORDS_DANCE);
await game.toNextTurn();
expect(snorlax.status?.sleepTurnsRemaining).toBe(1);
game.move.select(MoveId.SWORDS_DANCE);
game.move.use(MoveId.SWORDS_DANCE);
await game.toNextTurn();
expect(snorlax.status?.effect).toBeUndefined();
expect(snorlax.getStatStage(Stat.ATK)).toBe(2);
@ -81,11 +80,11 @@ describe("MoveId - Rest", () => {
it("should preserve non-volatile status conditions", async () => {
await game.classicMode.startBattle([SpeciesId.SNORLAX]);
const snorlax = game.scene.getPlayerPokemon()!;
const snorlax = game.field.getPlayerPokemon();
snorlax.hp = 1;
snorlax.addTag(BattlerTagType.CONFUSED, 999);
game.move.select(MoveId.REST);
game.move.use(MoveId.REST);
await game.toEndOfTurn();
expect(snorlax.getTag(BattlerTagType.CONFUSED)).toBeDefined();
@ -100,11 +99,11 @@ describe("MoveId - Rest", () => {
game.override.ability(ability).statusEffect(status);
await game.classicMode.startBattle([SpeciesId.SNORLAX]);
const snorlax = game.scene.getPlayerPokemon()!;
const snorlax = game.field.getPlayerPokemon();
snorlax.hp = snorlax.getMaxHp() - dmg;
game.move.select(MoveId.REST);
game.move.use(MoveId.REST);
await game.toEndOfTurn();
expect(snorlax.getLastXMoves()[0].result).toBe(MoveResult.FAIL);
@ -114,7 +113,7 @@ describe("MoveId - Rest", () => {
game.override.statusEffect(StatusEffect.SLEEP).moveset([MoveId.REST, MoveId.SLEEP_TALK]);
await game.classicMode.startBattle([SpeciesId.SNORLAX]);
const snorlax = game.scene.getPlayerPokemon()!;
const snorlax = game.field.getPlayerPokemon();
snorlax.hp = 1;
// Need to use sleep talk here since you normally can't move while asleep
@ -126,22 +125,22 @@ describe("MoveId - Rest", () => {
expect(snorlax.getLastXMoves(-1).map(tm => tm.result)).toEqual([MoveResult.FAIL, MoveResult.SUCCESS]);
});
it("should succeed if called the turn after waking up", async () => {
it("should succeed if called the same turn as the user wakes", async () => {
game.override.statusEffect(StatusEffect.SLEEP);
await game.classicMode.startBattle([SpeciesId.SNORLAX]);
const snorlax = game.scene.getPlayerPokemon()!;
const snorlax = game.field.getPlayerPokemon();
snorlax.hp = 1;
expect(snorlax.status?.effect).toBe(StatusEffect.SLEEP);
snorlax.status!.sleepTurnsRemaining = 1;
game.move.select(MoveId.REST);
game.move.use(MoveId.REST);
await game.toNextTurn();
expect(snorlax.status?.effect).toBe(StatusEffect.SLEEP);
expect(snorlax.status!.effect).toBe(StatusEffect.SLEEP);
expect(snorlax.isFullHp()).toBe(true);
expect(snorlax.getLastXMoves()[0].result).toBe(MoveResult.SUCCESS);
expect(snorlax.status?.sleepTurnsRemaining).toBeGreaterThan(1);
expect(snorlax.status!.sleepTurnsRemaining).toBeGreaterThan(1);
});
});

View File

@ -46,17 +46,17 @@ describe("Moves - Sleep Talk", () => {
const feebas = game.field.getPlayerPokemon();
expect(feebas.getStatStage(Stat.ATK)).toBe(2);
expect(feebas.getLastXMoves(2)).toEqual([
expect.objectContaining({
move: MoveId.SWORDS_DANCE,
result: MoveResult.SUCCESS,
virtual: true,
}),
expect.objectContaining({
move: MoveId.SLEEP_TALK,
result: MoveResult.SUCCESS,
virtual: false,
})
])
expect.objectContaining({
move: MoveId.SWORDS_DANCE,
result: MoveResult.SUCCESS,
virtual: true,
}),
expect.objectContaining({
move: MoveId.SLEEP_TALK,
result: MoveResult.SUCCESS,
virtual: false,
}),
]);
});
it("should fail if the user is not asleep", async () => {
@ -96,7 +96,7 @@ describe("Moves - Sleep Talk", () => {
game.move.select(MoveId.SLEEP_TALK);
await game.toNextTurn();
const feebas = game.field.getPlayerPokemon()
const feebas = game.field.getPlayerPokemon();
expect(feebas.getStatStage(Stat.SPD)).toBe(1);
expect(feebas.getStatStage(Stat.DEF)).toBe(-1);
});

View File

@ -3,14 +3,12 @@ import { StockpilingTag } from "#app/data/battler-tags";
import { BattlerTagType } from "#app/enums/battler-tag-type";
import type { TurnMove } from "#app/field/pokemon";
import { MoveResult } from "#enums/move-result";
import { MovePhase } from "#app/phases/move-phase";
import { TurnInitPhase } from "#app/phases/turn-init-phase";
import { AbilityId } from "#enums/ability-id";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("Moves - Swallow", () => {
let phaserGame: Phaser.Game;
@ -31,99 +29,41 @@ describe("Moves - Swallow", () => {
.battleStyle("single")
.enemySpecies(SpeciesId.RATTATA)
.enemyMoveset(MoveId.SPLASH)
.enemyAbility(AbilityId.NONE)
.enemyLevel(2000)
.moveset(MoveId.SWALLOW)
.ability(AbilityId.NONE);
.enemyAbility(AbilityId.BALL_FETCH)
.enemyLevel(1000)
.startingLevel(1000)
.ability(AbilityId.BALL_FETCH);
});
describe("consumes all stockpile stacks to heal (scaling with stacks)", () => {
it("1 stack -> 25% heal", async () => {
const stacksToSetup = 1;
const expectedHeal = 25;
it.each<{ stackCount: number; healPercent: number }>([
{ stackCount: 1, healPercent: 25 },
{ stackCount: 2, healPercent: 50 },
{ stackCount: 3, healPercent: 100 },
])(
"should heal the user by $healPercent% when consuming $count stockpile stacks",
async ({ stackCount, healPercent }) => {
await game.classicMode.startBattle([SpeciesId.SWALOT]);
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const swalot = game.field.getPlayerPokemon();
swalot.hp = 1;
const pokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
pokemon["hp"] = 1;
for (let i = 0; i < stackCount; i++) {
swalot.addTag(BattlerTagType.STOCKPILING);
}
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
const stockpilingTag = swalot.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
expect(stockpilingTag.stockpiledCount).toBe(stackCount);
vi.spyOn(pokemon, "heal");
game.move.use(MoveId.SWALLOW);
await game.toEndOfTurn();
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(swalot.getHpRatio()).toBeCloseTo(healPercent / 100, 1);
expect(swalot.getTag(StockpilingTag)).toBeUndefined();
},
);
expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expectedHeal);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("2 stacks -> 50% heal", async () => {
const stacksToSetup = 2;
const expectedHeal = 50;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
pokemon["hp"] = 1;
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
vi.spyOn(pokemon, "heal");
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expectedHeal);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("3 stacks -> 100% heal", async () => {
const stacksToSetup = 3;
const expectedHeal = 100;
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
vi.spyOn(pokemon, "getMaxHp").mockReturnValue(100);
pokemon["hp"] = 0.0001;
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
pokemon.addTag(BattlerTagType.STOCKPILING);
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
expect(stockpilingTag.stockpiledCount).toBe(stacksToSetup);
vi.spyOn(pokemon, "heal");
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.heal).toHaveBeenCalledOnce();
expect(pokemon.heal).toHaveReturnedWith(expect.closeTo(expectedHeal));
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
});
it("fails without stacks", async () => {
it("should fail without stacks", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
const pokemon = game.scene.getPlayerPokemon()!;
@ -131,17 +71,17 @@ describe("Moves - Swallow", () => {
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeUndefined();
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(TurnInitPhase);
game.move.use(MoveId.SWALLOW);
await game.toEndOfTurn();
expect(pokemon.getMoveHistory().at(-1)).toMatchObject<TurnMove>({
expect(pokemon.getLastXMoves()[0]).toMatchObject({
move: MoveId.SWALLOW,
result: MoveResult.FAIL,
targets: [pokemon.getBattlerIndex()],
});
});
describe("restores stat stage boosts granted by stacks", () => {
describe("should reset stat stage boosts granted by stacks", () => {
it("decreases stats based on stored values (both boosts equal)", async () => {
await game.classicMode.startBattle([SpeciesId.ABOMASNOW]);
@ -150,16 +90,13 @@ describe("Moves - Swallow", () => {
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
game.move.select(MoveId.SWALLOW);
await game.phaseInterceptor.to(MovePhase);
expect(pokemon.getStatStage(Stat.DEF)).toBe(1);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(1);
await game.phaseInterceptor.to(TurnInitPhase);
game.move.use(MoveId.SWALLOW);
await game.toEndOfTurn();
expect(pokemon.getMoveHistory().at(-1)).toMatchObject<TurnMove>({
expect(pokemon.getLastXMoves()[0]).toMatchObject({
move: MoveId.SWALLOW,
result: MoveResult.SUCCESS,
targets: [pokemon.getBattlerIndex()],
@ -167,8 +104,6 @@ describe("Moves - Swallow", () => {
expect(pokemon.getStatStage(Stat.DEF)).toBe(0);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(0);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
it("lower stat stages based on stored values (different boosts)", async () => {
@ -179,7 +114,6 @@ describe("Moves - Swallow", () => {
const stockpilingTag = pokemon.getTag(StockpilingTag)!;
expect(stockpilingTag).toBeDefined();
// for the sake of simplicity (and because other tests cover the setup), set boost amounts directly
stockpilingTag.statChangeCounts = {
[Stat.DEF]: -1,
@ -187,10 +121,9 @@ describe("Moves - Swallow", () => {
};
game.move.select(MoveId.SWALLOW);
await game.toEndOfTurn();
await game.phaseInterceptor.to(TurnInitPhase);
expect(pokemon.getMoveHistory().at(-1)).toMatchObject<TurnMove>({
expect(pokemon.getLastXMoves()[0]).toMatchObject<TurnMove>({
move: MoveId.SWALLOW,
result: MoveResult.SUCCESS,
targets: [pokemon.getBattlerIndex()],
@ -198,8 +131,6 @@ describe("Moves - Swallow", () => {
expect(pokemon.getStatStage(Stat.DEF)).toBe(1);
expect(pokemon.getStatStage(Stat.SPDEF)).toBe(-2);
expect(pokemon.getTag(StockpilingTag)).toBeUndefined();
});
});
});