Fixed message code a bit

This commit is contained in:
Bertie690 2025-06-14 10:30:37 -04:00
parent 3e2d050d70
commit b9a4e631db
4 changed files with 46 additions and 42 deletions

View File

@ -1917,7 +1917,8 @@ export class HealAttr extends MoveEffectAttr {
private healRatio: number, private healRatio: number,
/** Whether to display a healing animation when healing the target; default `false` */ /** Whether to display a healing animation when healing the target; default `false` */
private showAnim = false, private showAnim = false,
selfTarget = true) { selfTarget = true
) {
super(selfTarget); 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); 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; const score = ((1 - (this.selfTarget ? user : target).getHpRatio()) * 20) - this.healRatio * 10;
return Math.round(score / (1 - this.healRatio / 2)); return Math.round(score / (1 - this.healRatio / 2));
} }
override canApply(_user: Pokemon, target: Pokemon, _move: Move, _args?: any[]): boolean { override canApply(user: Pokemon, target: Pokemon, _move: Move, _args?: any[]): boolean {
if (target.isFullHp()) { return !(this.selfTarget ? user : target).isFullHp();
globalScene.phaseManager.queueMessage(i18next.t("battle:hpIsFull", { }
pokemonName: getPokemonNameWithAffix(target),
})) override getFailedText(user: Pokemon, target: Pokemon, _move: Move): string | undefined {
return false; const healedPokemon = this.selfTarget ? user : target;
} return healedPokemon.isFullHp()
return true; ? i18next.t("battle:hpIsFull", {
pokemonName: getPokemonNameWithAffix(healedPokemon),
})
: undefined;
} }
} }
@ -1959,23 +1963,25 @@ export class RestAttr extends HealAttr {
private duration: number; private duration: number;
constructor(duration: number) { constructor(duration: number) {
super(1); super(1, true);
this.duration = duration; this.duration = duration;
} }
override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { override apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean {
user.trySetStatus(StatusEffect.SLEEP, user, this.duration, null, true, true); const wasSet = user.trySetStatus(StatusEffect.SLEEP, user, this.duration, null, true, true,
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:restBecameHealthy", { i18next.t("moveTriggers:restBecameHealthy", {
pokemonName: getPokemonNameWithAffix(user), 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 { 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) 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) new StatusMove(MoveId.HEAL_BLOCK, PokemonType.PSYCHIC, 100, 15, -1, 0, 4)
.attr(AddBattlerTagAttr, BattlerTagType.HEAL_BLOCK, false, true, 5) .attr(AddBattlerTagAttr, BattlerTagType.HEAL_BLOCK, false, true, 5)
.target(MoveTarget.ALL_NEAR_ENEMIES) .target(MoveTarget.ALL_NEAR_ENEMIES)
.reflectable() .reflectable(),
.edgeCase(),
new AttackMove(MoveId.WRING_OUT, PokemonType.NORMAL, MoveCategory.SPECIAL, -1, 100, 5, -1, 0, 4) new AttackMove(MoveId.WRING_OUT, PokemonType.NORMAL, MoveCategory.SPECIAL, -1, 100, 5, -1, 0, 4)
.attr(OpponentHighHpPowerAttr, 120) .attr(OpponentHighHpPowerAttr, 120)
.makesContact(), .makesContact(),

View File

@ -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 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 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 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. * @returns Whether the status effect phase was successfully created.
* @see {@linkcode doSetStatus} - alternate function that sets status immediately (albeit without condition checks). * @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, sourceText: string | null = null,
overrideStatus?: boolean, overrideStatus?: boolean,
quiet = true, quiet = true,
overrideMessage?: string | undefined,
): boolean { ): boolean {
// TODO: This needs to propagate failure status for non-status moves // TODO: This needs to propagate failure status for non-status moves
if (!this.canSetStatus(effect, quiet, overrideStatus, sourcePokemon)) { if (!this.canSetStatus(effect, quiet, overrideStatus, sourcePokemon)) {
@ -4739,9 +4741,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
"ObtainStatusEffectPhase", "ObtainStatusEffectPhase",
this.getBattlerIndex(), this.getBattlerIndex(),
effect, effect,
sourcePokemon,
sleepTurnsRemaining, sleepTurnsRemaining,
sourceText, sourceText,
sourcePokemon, overrideMessage,
); );
return true; return true;

View File

@ -13,33 +13,28 @@ import { applyPostSetStatusAbAttrs } from "#app/data/abilities/apply-ab-attrs";
/** The phase where pokemon obtain status effects. */ /** The phase where pokemon obtain status effects. */
export class ObtainStatusEffectPhase extends PokemonPhase { export class ObtainStatusEffectPhase extends PokemonPhase {
public readonly phaseName = "ObtainStatusEffectPhase"; public readonly phaseName = "ObtainStatusEffectPhase";
private statusEffect: StatusEffect;
private sleepTurnsRemaining?: number;
private sourceText?: string | null;
private sourcePokemon?: Pokemon | null;
/** /**
* Create a new ObtainStatusEffectPhase. * Create a new ObtainStatusEffectPhase.
* @param battlerIndex - The {@linkcode BattlerIndex} of the Pokemon obtaining the status effect. * @param battlerIndex - The {@linkcode BattlerIndex} of the Pokemon obtaining the status effect.
* @param statusEffect - The {@linkcode StatusEffect} being applied. * @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; * @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. * defaults to a random number between 2 and 4 and is unused for non-Sleep statuses.
* @param sourceText * @param sourceText - The text to show for the source of the status effect, if any; default `null`.
* @param sourcePokemon * @param overrideMessage - A string containing text to be displayed upon status setting;
* defaults to normal key for status if blank or `undefined`.
*/ */
constructor( constructor(
battlerIndex: BattlerIndex, battlerIndex: BattlerIndex,
statusEffect: StatusEffect, private statusEffect: StatusEffect,
sleepTurnsRemaining?: number, private sourcePokemon?: Pokemon | null,
sourceText?: string | null, private sleepTurnsRemaining?: number,
sourcePokemon?: Pokemon | null, private sourceText?: string | null,
private overrideMessage?: string | undefined,
) { ) {
super(battlerIndex); super(battlerIndex);
this.statusEffect = statusEffect;
this.sleepTurnsRemaining = sleepTurnsRemaining;
this.sourceText = sourceText;
this.sourcePokemon = sourcePokemon;
} }
start() { start() {
@ -50,7 +45,8 @@ export class ObtainStatusEffectPhase extends PokemonPhase {
new CommonBattleAnim(CommonAnim.POISON + (this.statusEffect - 1), pokemon).play(false, () => { new CommonBattleAnim(CommonAnim.POISON + (this.statusEffect - 1), pokemon).play(false, () => {
globalScene.phaseManager.queueMessage( 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) { if (this.statusEffect && this.statusEffect !== StatusEffect.FAINT) {
globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeStatusEffectTrigger, true); globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeStatusEffectTrigger, true);

View File

@ -63,7 +63,7 @@ describe("Mystery Encounter Utils", () => {
// Both pokemon fainted // Both pokemon fainted
scene.getPlayerParty().forEach(p => { scene.getPlayerParty().forEach(p => {
p.hp = 0; p.hp = 0;
p.trySetStatus(StatusEffect.FAINT); p.doSetStatus(StatusEffect.FAINT);
void p.updateInfo(); void p.updateInfo();
}); });
@ -83,7 +83,7 @@ describe("Mystery Encounter Utils", () => {
// Only faint 1st pokemon // Only faint 1st pokemon
const party = scene.getPlayerParty(); const party = scene.getPlayerParty();
party[0].hp = 0; party[0].hp = 0;
party[0].trySetStatus(StatusEffect.FAINT); party[0].doSetStatus(StatusEffect.FAINT);
await party[0].updateInfo(); await party[0].updateInfo();
// Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) // 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 // Only faint 1st pokemon
const party = scene.getPlayerParty(); const party = scene.getPlayerParty();
party[0].hp = 0; party[0].hp = 0;
party[0].trySetStatus(StatusEffect.FAINT); party[0].doSetStatus(StatusEffect.FAINT);
await party[0].updateInfo(); await party[0].updateInfo();
// Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) // 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 // Only faint 1st pokemon
const party = scene.getPlayerParty(); const party = scene.getPlayerParty();
party[0].hp = 0; party[0].hp = 0;
party[0].trySetStatus(StatusEffect.FAINT); party[0].doSetStatus(StatusEffect.FAINT);
await party[0].updateInfo(); await party[0].updateInfo();
// Seeds are calculated to return index 0 first, 1 second (if both pokemon are legal) // 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(); const party = scene.getPlayerParty();
party[0].level = 100; party[0].level = 100;
party[0].hp = 0; party[0].hp = 0;
party[0].trySetStatus(StatusEffect.FAINT); party[0].doSetStatus(StatusEffect.FAINT);
await party[0].updateInfo(); await party[0].updateInfo();
party[1].level = 10; party[1].level = 10;
@ -206,7 +206,7 @@ describe("Mystery Encounter Utils", () => {
const party = scene.getPlayerParty(); const party = scene.getPlayerParty();
party[0].level = 10; party[0].level = 10;
party[0].hp = 0; party[0].hp = 0;
party[0].trySetStatus(StatusEffect.FAINT); party[0].doSetStatus(StatusEffect.FAINT);
await party[0].updateInfo(); await party[0].updateInfo();
party[1].level = 100; party[1].level = 100;