pokerogue/src/phases/pokemon-transform-phase.ts
Dean 1d7f916240
[Refactor] Align ability display with mainline (#5267)
* Stop ShowAbilityPhase from ending until the bar has popped out

* Remove ability bar hiding from messagePhase

* Remove abilityBar reference from base Phase class

* Add HideAbilityPhase to hide ability bar after effects

* Add willSucceed to ability attrs

* Update AbAttrs and PostInitAbAttrs

* Update PreDefendAbAttrs

* Update postDefend, postMoveUsed, StatStage, postSetStatus, and PostDamage

* Update preAttack and fieldStat

* Partially implement postAttack

* Finish PostAttack

* Update PostSummon

* Update PreSwitchOut

* Update preStatStageChange

* Update PostStatStageChange, PreSetStatus, PreApplyBattlerTag

* Update postTurn and preWeatherEffect

* Update postWeatherChange

* Update postWeatherChange

* Update PostTerrainChange

* Update CheckTrapped and PostBattle

* Update postFaint

* Update PostItemLost

* Bug fixes from test cases

* Fix intimidate display

* Stop trace from displaying itself

* Rename to canApply

* Fix ability displays using getTriggerMessage

* Ensure abilities which are mistakenly shown are still hidden

* Fix ability bar showing the wrong ability with imposter

* Add canApply for imposter

* Update abilities using promises and `trySet...` functions

* Committing overrides changes is bad

* Document apply and canApply

* Update PreLeaveFieldAbAttr

* Remove boolean return type apply functions

* Remove redundant  assignment

* Remove ability display from abilities that shouldn't have it

* Move queueAbilityDisplay to battlescene

* Remove unused shown variable

* Minor changes

* Fix using id instead of battlerindex in queueAbilityDisplay

* Fix PostBattleInitFormChangeAbAttr displaying

* Prevent crashes in case an ability for a pokemon not on the field is shown

* Stop more abilities from displaying

* Move enemy ability bar to the right side

* Automatically reload bar if shown while already out, fix specific abilities

* Remove duplicate call to clearPhaseQueueSplice

* Remove ShowAbilityPhase import from ability.ts

* Update PostDefendTypeChangeAbAttr to use PokemonType

* Update PostSummonAddArenaTagAbAttr

* Minor changes
2025-03-16 02:51:02 +00:00

86 lines
2.7 KiB
TypeScript

import type { BattlerIndex } from "#app/battle";
import { BattlerTagType } from "#enums/battler-tag-type";
import { Moves } from "#enums/moves";
import { EFFECTIVE_STATS, BATTLE_STATS } from "#enums/stat";
import { PokemonMove } from "#app/field/pokemon";
import { globalScene } from "#app/global-scene";
import { PokemonPhase } from "./pokemon-phase";
import { getPokemonNameWithAffix } from "#app/messages";
import i18next from "i18next";
/**
* Transforms a Pokemon into another Pokemon on the field.
* Used for Transform (move) and Imposter (ability)
*/
export class PokemonTransformPhase extends PokemonPhase {
protected targetIndex: BattlerIndex;
private playSound: boolean;
constructor(userIndex: BattlerIndex, targetIndex: BattlerIndex, playSound = false) {
super(userIndex);
this.targetIndex = targetIndex;
this.playSound = playSound;
}
public override start(): void {
const user = this.getPokemon();
const target = globalScene.getField(true).find(p => p.getBattlerIndex() === this.targetIndex);
if (!target) {
return this.end();
}
user.summonData.speciesForm = target.getSpeciesForm();
user.summonData.ability = target.getAbility().id;
user.summonData.gender = target.getGender();
// Power Trick's effect is removed after using Transform
user.removeTag(BattlerTagType.POWER_TRICK);
// Copy all stats (except HP)
for (const s of EFFECTIVE_STATS) {
user.setStat(s, target.getStat(s, false), false);
}
// Copy all stat stages
for (const s of BATTLE_STATS) {
user.setStatStage(s, target.getStatStage(s));
}
user.summonData.moveset = target.getMoveset().map(m => {
if (m) {
// If PP value is less than 5, do nothing. If greater, we need to reduce the value to 5.
return new PokemonMove(m.moveId, 0, 0, false, Math.min(m.getMove().pp, 5));
}
console.warn(`Transform: somehow iterating over a ${m} value when copying moveset!`);
return new PokemonMove(Moves.NONE);
});
user.summonData.types = target.getTypes();
const promises = [user.updateInfo()];
if (this.playSound) {
globalScene.playSound("battle_anims/PRSFX- Transform");
}
globalScene.queueMessage(
i18next.t("abilityTriggers:postSummonTransform", {
pokemonNameWithAffix: getPokemonNameWithAffix(user),
targetName: target.name,
}),
);
promises.push(
user.loadAssets(false).then(() => {
user.playAnim();
user.updateInfo();
// If the new ability activates immediately, it needs to happen after all the transform animations
user.setTempAbility(target.getAbility());
}),
);
Promise.allSettled(promises).then(() => this.end());
}
}