diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 9a51950a5..da40d850c 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -125,6 +125,7 @@ export default class BattleScene extends SceneBase { public gameData: GameData; public sessionSlotId: integer; + // can debug phases using "phase.constructor.name" private phaseQueue: Phase[]; private phaseQueuePrepend: Phase[]; private phaseQueuePrependSpliceIndex: integer; @@ -1488,6 +1489,7 @@ export default class BattleScene extends SceneBase { this.phaseQueuePrepend.push(phase); else this.phaseQueuePrepend.splice(this.phaseQueuePrependSpliceIndex, 0, phase); + this.phaseQueuePrepend.forEach(p => console.log(p.constructor.name)) } clearPhaseQueue(): void { diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 8afff1b27..938f6134e 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1460,6 +1460,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { console.log('damage', damage.value, move.name, power.value, sourceAtk, targetDef); + if (damage.value) { if (this.getHpRatio() === 1) applyPreDefendAbAttrs(PreDefendFullHpEndureAbAttr, this, source, battlerMove, cancelled, damage); @@ -1467,10 +1468,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { 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); + + // damageAndUpdate: will queue potential messages for critical hit, effectiveness, fainted - in that order + // requires passing in hitsLeft + damage.value = this.damageAndUpdate(damage.value, result as DamageResult, isCritical, oneHitKo, oneHitKo, source.turnData.hitsLeft); 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); @@ -1485,23 +1488,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.scene.applyModifiers(DamageMoneyRewardModifier, true, source, damage) } - if (source.turnData.hitsLeft === 1) { - switch (result) { - case HitResult.SUPER_EFFECTIVE: - this.scene.queueMessage(i18next.t('battle:hitResultSuperEffective')); - break; - case HitResult.NOT_VERY_EFFECTIVE: - this.scene.queueMessage(i18next.t('battle:hitResultNotVeryEffective')); - break; - case HitResult.NO_EFFECT: - this.scene.queueMessage(i18next.t('battle:hitResultNoEffect', { pokemonName: this.name })); - break; - case HitResult.ONE_HIT_KO: - this.scene.queueMessage(i18next.t('battle:hitResultOneHitKO')); - break; - } - } - if (damage) this.scene.clearPhaseQueueSplice(); } @@ -1541,6 +1527,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { damage = Math.min(damage, this.hp); this.hp = this.hp - damage; + // checks and adds Fainted scene if (this.isFainted()) { this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), preventEndure)); this.resetSummonData(); @@ -1549,9 +1536,31 @@ 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, hitsLeft: integer = 1): integer { const damagePhase = new DamagePhase(this.scene, this.getBattlerIndex(), damage, result as DamageResult, critical); this.scene.unshiftPhase(damagePhase); + // queue critical message before effectiveness + if (critical) + this.scene.queueMessage(i18next.t('battle:hitResultCriticalHit')); + + // hitsLeft: for multi-hit moves, only want to render effectiveness text at end. + if (hitsLeft === 1) { + switch (result as HitResult) { + case HitResult.SUPER_EFFECTIVE: + this.scene.queueMessage(i18next.t('battle:hitResultSuperEffective')); + break; + case HitResult.NOT_VERY_EFFECTIVE: + this.scene.queueMessage(i18next.t('battle:hitResultNotVeryEffective')); + break; + case HitResult.NO_EFFECT: + this.scene.queueMessage(i18next.t('battle:hitResultNoEffect', { pokemonName: this.name })); + break; + case HitResult.ONE_HIT_KO: + this.scene.queueMessage(i18next.t('battle:hitResultOneHitKO')); + break; + } + } + damage = this.damage(damage, ignoreSegments, preventEndure); // Damage amount may have changed, but needed to be queued before calling damage function damagePhase.updateAmount(damage);