From b9a4e631dbb5f84fdf7ea226c03c85a9b6d3bc81 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Sat, 14 Jun 2025 10:30:37 -0400 Subject: [PATCH] Fixed message code a bit --- src/data/moves/move.ts | 43 +++++++++++-------- src/field/pokemon.ts | 5 ++- src/phases/obtain-status-effect-phase.ts | 28 ++++++------ .../mystery-encounter-utils.test.ts | 12 +++--- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index 8f43eb65f39..e87e50ce948 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -1917,7 +1917,8 @@ export class HealAttr extends MoveEffectAttr { private healRatio: number, /** Whether to display a healing animation when healing the target; default `false` */ private showAnim = false, - selfTarget = true) { + selfTarget = true + ) { super(selfTarget); } @@ -1935,19 +1936,22 @@ export class HealAttr extends MoveEffectAttr { toDmgValue(target.getMaxHp() * healRatio), i18next.t("moveTriggers:healHp", { pokemonName: getPokemonNameWithAffix(target) }), true, !this.showAnim); } - override 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; + override canApply(user: Pokemon, target: Pokemon, _move: Move, _args?: any[]): boolean { + return !(this.selfTarget ? user : target).isFullHp(); + } + + override getFailedText(user: Pokemon, target: Pokemon, _move: Move): string | undefined { + const healedPokemon = this.selfTarget ? user : target; + return healedPokemon.isFullHp() + ? i18next.t("battle:hpIsFull", { + pokemonName: getPokemonNameWithAffix(healedPokemon), + }) + : undefined; } } @@ -1959,23 +1963,25 @@ export class RestAttr extends HealAttr { private duration: number; constructor(duration: number) { - super(1); + super(1, true); 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", { + const wasSet = user.trySetStatus(StatusEffect.SLEEP, user, this.duration, null, true, true, + i18next.t("moveTriggers:restBecameHealthy", { pokemonName: getPokemonNameWithAffix(user), - })) - return super.apply(user, target, move, args); + })); + return wasSet && super.apply(user, target, move, args); } override addHealPhase(user: Pokemon, healRatio: number): void { - globalScene.phaseManager.unshiftNew("PokemonHealPhase", user.getBattlerIndex(), healRatio, "") + globalScene.phaseManager.unshiftNew("PokemonHealPhase", user.getBattlerIndex(), healRatio, null) } - canApply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { + override canApply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { + // Intentionally suppress messages here as we display generic fail msg + // TODO: This might have order-of-operation jank return super.canApply(user, target, move, args) && user.canSetStatus(StatusEffect.SLEEP, true, true, user) } } @@ -9631,8 +9637,7 @@ export function initMoves() { 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() - .edgeCase(), + .reflectable(), new AttackMove(MoveId.WRING_OUT, PokemonType.NORMAL, MoveCategory.SPECIAL, -1, 100, 5, -1, 0, 4) .attr(OpponentHighHpPowerAttr, 120) .makesContact(), diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index adeea5d560d..f7857cd6ec7 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -4700,6 +4700,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { * @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 `true`. + * @param overrideMessage - A string containing text to be displayed upon status setting; defaults to normal key for status * @returns Whether the status effect phase was successfully created. * @see {@linkcode doSetStatus} - alternate function that sets status immediately (albeit without condition checks). */ @@ -4710,6 +4711,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { sourceText: string | null = null, overrideStatus?: boolean, quiet = true, + overrideMessage?: string | undefined, ): boolean { // TODO: This needs to propagate failure status for non-status moves if (!this.canSetStatus(effect, quiet, overrideStatus, sourcePokemon)) { @@ -4739,9 +4741,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { "ObtainStatusEffectPhase", this.getBattlerIndex(), effect, + sourcePokemon, sleepTurnsRemaining, sourceText, - sourcePokemon, + overrideMessage, ); return true; diff --git a/src/phases/obtain-status-effect-phase.ts b/src/phases/obtain-status-effect-phase.ts index 190393692f5..4a7d0266c0b 100644 --- a/src/phases/obtain-status-effect-phase.ts +++ b/src/phases/obtain-status-effect-phase.ts @@ -13,33 +13,28 @@ import { applyPostSetStatusAbAttrs } from "#app/data/abilities/apply-ab-attrs"; /** The phase where pokemon obtain status effects. */ export class ObtainStatusEffectPhase extends PokemonPhase { public readonly phaseName = "ObtainStatusEffectPhase"; - private statusEffect: StatusEffect; - private sleepTurnsRemaining?: number; - private sourceText?: string | null; - private sourcePokemon?: Pokemon | null; /** * Create a new ObtainStatusEffectPhase. * @param battlerIndex - The {@linkcode BattlerIndex} of the Pokemon obtaining the status effect. * @param statusEffect - The {@linkcode StatusEffect} being applied. + * @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 - * @param sourcePokemon + * @param sourceText - The text to show for the source of the status effect, if any; default `null`. + * @param overrideMessage - A string containing text to be displayed upon status setting; + * defaults to normal key for status if blank or `undefined`. */ constructor( battlerIndex: BattlerIndex, - statusEffect: StatusEffect, - sleepTurnsRemaining?: number, - sourceText?: string | null, - sourcePokemon?: Pokemon | null, + private statusEffect: StatusEffect, + private sourcePokemon?: Pokemon | null, + private sleepTurnsRemaining?: number, + private sourceText?: string | null, + private overrideMessage?: string | undefined, ) { super(battlerIndex); - - this.statusEffect = statusEffect; - this.sleepTurnsRemaining = sleepTurnsRemaining; - this.sourceText = sourceText; - this.sourcePokemon = sourcePokemon; } start() { @@ -50,7 +45,8 @@ export class ObtainStatusEffectPhase extends PokemonPhase { new CommonBattleAnim(CommonAnim.POISON + (this.statusEffect - 1), pokemon).play(false, () => { globalScene.phaseManager.queueMessage( - getStatusEffectObtainText(this.statusEffect, getPokemonNameWithAffix(pokemon), this.sourceText ?? undefined), + this.overrideMessage || + getStatusEffectObtainText(this.statusEffect, getPokemonNameWithAffix(pokemon), this.sourceText ?? undefined), ); if (this.statusEffect && this.statusEffect !== StatusEffect.FAINT) { globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeStatusEffectTrigger, true); diff --git a/test/mystery-encounter/mystery-encounter-utils.test.ts b/test/mystery-encounter/mystery-encounter-utils.test.ts index 80e2fb77f2b..f7aa98345c5 100644 --- a/test/mystery-encounter/mystery-encounter-utils.test.ts +++ b/test/mystery-encounter/mystery-encounter-utils.test.ts @@ -63,7 +63,7 @@ describe("Mystery Encounter Utils", () => { // Both pokemon fainted scene.getPlayerParty().forEach(p => { p.hp = 0; - p.trySetStatus(StatusEffect.FAINT); + p.doSetStatus(StatusEffect.FAINT); void p.updateInfo(); }); @@ -83,7 +83,7 @@ describe("Mystery Encounter Utils", () => { // Only faint 1st pokemon const party = scene.getPlayerParty(); party[0].hp = 0; - party[0].trySetStatus(StatusEffect.FAINT); + party[0].doSetStatus(StatusEffect.FAINT); await party[0].updateInfo(); // Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) @@ -102,7 +102,7 @@ describe("Mystery Encounter Utils", () => { // Only faint 1st pokemon const party = scene.getPlayerParty(); party[0].hp = 0; - party[0].trySetStatus(StatusEffect.FAINT); + party[0].doSetStatus(StatusEffect.FAINT); await party[0].updateInfo(); // Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) @@ -121,7 +121,7 @@ describe("Mystery Encounter Utils", () => { // Only faint 1st pokemon const party = scene.getPlayerParty(); party[0].hp = 0; - party[0].trySetStatus(StatusEffect.FAINT); + party[0].doSetStatus(StatusEffect.FAINT); await party[0].updateInfo(); // Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) @@ -167,7 +167,7 @@ describe("Mystery Encounter Utils", () => { const party = scene.getPlayerParty(); party[0].level = 100; party[0].hp = 0; - party[0].trySetStatus(StatusEffect.FAINT); + party[0].doSetStatus(StatusEffect.FAINT); await party[0].updateInfo(); party[1].level = 10; @@ -206,7 +206,7 @@ describe("Mystery Encounter Utils", () => { const party = scene.getPlayerParty(); party[0].level = 10; party[0].hp = 0; - party[0].trySetStatus(StatusEffect.FAINT); + party[0].doSetStatus(StatusEffect.FAINT); await party[0].updateInfo(); party[1].level = 100;