Allow to explicitly ignore faint phase when damaging.

This allows to skip the faint phase in the `#damage` method for physical and special moves, to ensure we first queue the messages for the effectiveness of the attack and the potential critical hit.
We then explicitly unshift the faint phase in this case.
This commit is contained in:
Franck Trouillez 2024-05-20 19:18:59 +02:00
parent d2e455cdad
commit 24cda344f7

View File

@ -1641,18 +1641,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)
@ -1681,12 +1684,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();
}
@ -1707,7 +1715,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);
@ -1726,7 +1734,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();
}
@ -1734,10 +1742,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;
@ -3214,7 +3222,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;
@ -3250,7 +3258,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) {