diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 42e36c195de..c319ae43502 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1640,18 +1640,21 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { console.log('damage', damage.value, move.name, power.value, sourceAtk, targetDef); + const oneHitKo = result === HitResult.ONE_HIT_KO; if (damage.value) { if (this.getHpRatio() === 1) applyPreDefendAbAttrs(PreDefendFullHpEndureAbAttr, this, source, battlerMove, cancelled, damage); else if (!this.isPlayer() && damage.value >= this.hp) this.scene.applyModifiers(EnemyEndureChanceModifier, false, this); - const oneHitKo = result === HitResult.ONE_HIT_KO; - damage.value = this.damageAndUpdate(damage.value, result as DamageResult, isCritical, oneHitKo, oneHitKo); + /** + * We explicitly require to ignore the faint phase here, as we want to show the messages + * about the critical hit and the super effective/not very effective messages before the faint phase. + */ + damage.value = this.damageAndUpdate(damage.value, result as DamageResult, isCritical, oneHitKo, oneHitKo, true); this.turnData.damageTaken += damage.value; if (isCritical) this.scene.queueMessage(i18next.t('battle:hitResultCriticalHit')); - this.scene.setPhaseQueueSplice(); if (source.isPlayer()) { this.scene.validateAchvs(DamageAchv, damage); if (damage.value > this.scene.gameData.gameStats.highestDamage) @@ -1680,12 +1683,17 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { case HitResult.IMMUNE: this.scene.queueMessage(`${this.name} is unaffected!`); break; - case HitResult.ONE_HIT_KO: + case HitResult.ONE_HIT_KO: this.scene.queueMessage(i18next.t('battle:hitResultOneHitKO')); break; } } + if (this.isFainted()) { + this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), oneHitKo)); + this.resetSummonData(); + } + if (damage) this.scene.clearPhaseQueueSplice(); } @@ -1706,7 +1714,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return result; } - damage(damage: integer, ignoreSegments: boolean = false, preventEndure: boolean = false): integer { + damage(damage: integer, ignoreSegments: boolean = false, preventEndure: boolean = false, ignoreFaintPhase: boolean = false): integer { if (this.isFainted()) return 0; const surviveDamage = new Utils.BooleanHolder(false); @@ -1725,7 +1733,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { damage = Math.min(damage, this.hp); this.hp = this.hp - damage; - if (this.isFainted()) { + if (this.isFainted() && !ignoreFaintPhase) { this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), preventEndure)); this.resetSummonData(); } @@ -1733,10 +1741,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return damage; } - damageAndUpdate(damage: integer, result?: DamageResult, critical: boolean = false, ignoreSegments: boolean = false, preventEndure: boolean = false): integer { + damageAndUpdate(damage: integer, result?: DamageResult, critical: boolean = false, ignoreSegments: boolean = false, preventEndure: boolean = false, ignoreFaintPhase: boolean = false): integer { const damagePhase = new DamagePhase(this.scene, this.getBattlerIndex(), damage, result as DamageResult, critical); this.scene.unshiftPhase(damagePhase); - damage = this.damage(damage, ignoreSegments, preventEndure); + damage = this.damage(damage, ignoreSegments, preventEndure, ignoreFaintPhase); // Damage amount may have changed, but needed to be queued before calling damage function damagePhase.updateAmount(damage); return damage; @@ -3213,7 +3221,7 @@ export class EnemyPokemon extends Pokemon { return 0; } - damage(damage: integer, ignoreSegments: boolean = false, preventEndure: boolean = false): integer { + damage(damage: integer, ignoreSegments: boolean = false, preventEndure: boolean = false, ignoreFaintPhase: boolean = false): integer { if (this.isFainted()) return 0; @@ -3249,7 +3257,7 @@ export class EnemyPokemon extends Pokemon { damage = Math.min(damage, this.hp - 1); } - let ret = super.damage(damage, ignoreSegments, preventEndure); + let ret = super.damage(damage, ignoreSegments, preventEndure, ignoreFaintPhase); if (this.isBoss()) { if (ignoreSegments) {