mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-02-19 10:47:41 +00:00
* Replace various `scene` pass-arounds with global scene variable * Modify tests * Add scene back to `fade[in|out]()` calls Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Fix Bug Superfan ME test Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Re-enable fixed test Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> * Rename `gScene` to `globalScene` * Move `globalScene` to its own file to fix import/async issues * Fix `SelectModifierPhase` tests * Fix ME tests by removing `scene` from `expect()`s * Resolve merge issues * Remove tsdocs referencing `scene` params Remove missed instances of `.scene` * Remove unnecessary `globalScene` usage in `loading-scene.ts` * Fix merge conflicts * Attempt to fix circular import issue * Found the source of the import issue * Fix merge issues --------- Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com>
85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import { globalScene } from "#app/global-scene";
|
|
import { type BattlerIndex } from "#app/battle";
|
|
import { BattleSpec } from "#enums/battle-spec";
|
|
import { type DamageResult, HitResult } from "#app/field/pokemon";
|
|
import { fixedInt } from "#app/utils";
|
|
import { PokemonPhase } from "#app/phases/pokemon-phase";
|
|
|
|
export class DamageAnimPhase extends PokemonPhase {
|
|
private amount: integer;
|
|
private damageResult: DamageResult;
|
|
private critical: boolean;
|
|
|
|
constructor(battlerIndex: BattlerIndex, amount: integer, damageResult?: DamageResult, critical: boolean = false) {
|
|
super(battlerIndex);
|
|
|
|
this.amount = amount;
|
|
this.damageResult = damageResult || HitResult.EFFECTIVE;
|
|
this.critical = critical;
|
|
}
|
|
|
|
start() {
|
|
super.start();
|
|
|
|
if (this.damageResult === HitResult.ONE_HIT_KO) {
|
|
if (globalScene.moveAnimations) {
|
|
globalScene.toggleInvert(true);
|
|
}
|
|
globalScene.time.delayedCall(fixedInt(1000), () => {
|
|
globalScene.toggleInvert(false);
|
|
this.applyDamage();
|
|
});
|
|
return;
|
|
}
|
|
|
|
this.applyDamage();
|
|
}
|
|
|
|
updateAmount(amount: integer): void {
|
|
this.amount = amount;
|
|
}
|
|
|
|
applyDamage() {
|
|
switch (this.damageResult) {
|
|
case HitResult.EFFECTIVE:
|
|
globalScene.playSound("se/hit");
|
|
break;
|
|
case HitResult.SUPER_EFFECTIVE:
|
|
case HitResult.ONE_HIT_KO:
|
|
globalScene.playSound("se/hit_strong");
|
|
break;
|
|
case HitResult.NOT_VERY_EFFECTIVE:
|
|
globalScene.playSound("se/hit_weak");
|
|
break;
|
|
}
|
|
|
|
if (this.amount) {
|
|
globalScene.damageNumberHandler.add(this.getPokemon(), this.amount, this.damageResult, this.critical);
|
|
}
|
|
|
|
if (this.damageResult !== HitResult.OTHER && this.amount > 0) {
|
|
const flashTimer = globalScene.time.addEvent({
|
|
delay: 100,
|
|
repeat: 5,
|
|
startAt: 200,
|
|
callback: () => {
|
|
this.getPokemon().getSprite().setVisible(flashTimer.repeatCount % 2 === 0);
|
|
if (!flashTimer.repeatCount) {
|
|
this.getPokemon().updateInfo().then(() => this.end());
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
this.getPokemon().updateInfo().then(() => this.end());
|
|
}
|
|
}
|
|
|
|
override end() {
|
|
if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) {
|
|
globalScene.initFinalBossPhaseTwo(this.getPokemon());
|
|
} else {
|
|
super.end();
|
|
}
|
|
}
|
|
}
|