diff --git a/src/data/ability.ts b/src/data/ability.ts index 3a529ce0f59..723b51fbb22 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -905,8 +905,7 @@ export class PostWeatherLapseDamageAbAttr extends PostWeatherLapseAbAttr { if (pokemon.getHpRatio() < 1) { const scene = pokemon.scene; scene.queueMessage(getPokemonMessage(pokemon, ` is hurt\nby its ${pokemon.getAbility()}!`)); - const damage = pokemon.damage(Math.ceil(pokemon.getMaxHp() / (16 / this.damageFactor))); - scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.getBattlerIndex(), damage, HitResult.OTHER)); + pokemon.damageAndUpdate(Math.ceil(pokemon.getMaxHp() / (16 / this.damageFactor)), HitResult.OTHER); return true; } diff --git a/src/data/arena-tag.ts b/src/data/arena-tag.ts index e2a51d1a8d0..c6ca43722d9 100644 --- a/src/data/arena-tag.ts +++ b/src/data/arena-tag.ts @@ -173,7 +173,7 @@ class SpikesTag extends ArenaTrapTag { const damage = Math.ceil(pokemon.getMaxHp() * damageHpRatio); pokemon.scene.queueMessage(getPokemonMessage(pokemon, ' is hurt\nby the spikes!')); - pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.damage(damage), HitResult.OTHER)); + pokemon.damageAndUpdate(damage, HitResult.OTHER); return true; } @@ -268,7 +268,7 @@ class StealthRockTag extends ArenaTrapTag { if (damageHpRatio) { const damage = Math.ceil(pokemon.getMaxHp() * damageHpRatio); pokemon.scene.queueMessage(`Pointed stones dug into\n${pokemon.name}!`); - pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.damage(damage), HitResult.OTHER)); + pokemon.damageAndUpdate(damage, HitResult.OTHER); } return false; diff --git a/src/data/battler-tags.ts b/src/data/battler-tags.ts index d85942f462f..870bbc271db 100644 --- a/src/data/battler-tags.ts +++ b/src/data/battler-tags.ts @@ -179,7 +179,7 @@ export class ConfusedTag extends BattlerTag { const def = pokemon.getBattleStat(Stat.DEF); const damage = Math.ceil(((((2 * pokemon.level / 5 + 2) * 40 * atk / def) / 50) + 2) * (pokemon.randSeedInt(15, 85) / 100)); pokemon.scene.queueMessage('It hurt itself in its\nconfusion!'); - pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.damage(damage))); + pokemon.damageAndUpdate(damage); pokemon.battleData.hitCount++; (pokemon.scene.getCurrentPhase() as MovePhase).cancel(); } @@ -263,9 +263,7 @@ export class SeedTag extends BattlerTag { if (source) { pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, source.getBattlerIndex(), pokemon.getBattlerIndex(), CommonAnim.LEECH_SEED)); - const damage = pokemon.damage(Math.max(Math.floor(pokemon.getMaxHp() / 8), 1)); - - pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.getBattlerIndex(), damage)); + const damage = pokemon.damageAndUpdate(Math.max(Math.floor(pokemon.getMaxHp() / 8), 1)); pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, source.getBattlerIndex(), damage, getPokemonMessage(pokemon, '\'s health is\nsapped by Leech Seed!'), false, true)); } } @@ -302,8 +300,7 @@ export class NightmareTag extends BattlerTag { pokemon.scene.queueMessage(getPokemonMessage(pokemon, ' is locked\nin a Nightmare!')); pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), undefined, CommonAnim.CURSE)); // TODO: Update animation type - const damage = Math.ceil(pokemon.getMaxHp() / 4); - pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.damage(damage))); + pokemon.damageAndUpdate(Math.ceil(pokemon.getMaxHp() / 4)); } return ret; @@ -470,8 +467,7 @@ export abstract class DamagingTrapTag extends TrappedTag { pokemon.scene.queueMessage(getPokemonMessage(pokemon, ` is hurt\nby ${this.getMoveName()}!`)); pokemon.scene.unshiftPhase(new CommonAnimPhase(pokemon.scene, pokemon.getBattlerIndex(), undefined, this.commonAnim)); - const damage = Math.ceil(pokemon.getMaxHp() / 8); - pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.damage(damage))); + pokemon.damageAndUpdate(Math.ceil(pokemon.getMaxHp() / 8)) } return ret; @@ -615,7 +611,7 @@ export class PerishSongTag extends BattlerTag { if (ret) pokemon.scene.queueMessage(getPokemonMessage(pokemon, `\'s perish count fell to ${this.turnCount}.`)); else - pokemon.scene.unshiftPhase(new DamagePhase(pokemon.scene, pokemon.getBattlerIndex(), pokemon.damage(pokemon.hp, true, true), HitResult.ONE_HIT_KO)); + pokemon.damageAndUpdate(pokemon.hp, HitResult.ONE_HIT_KO, false, true, true); return ret; } diff --git a/src/data/move.ts b/src/data/move.ts index 908392f8483..c601be76a3f 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -532,7 +532,7 @@ export class RecoilAttr extends MoveEffectAttr { if (!recoilDamage) return false; - user.scene.unshiftPhase(new DamagePhase(user.scene, user.getBattlerIndex(), user.damage(recoilDamage, true), HitResult.OTHER)); + user.damageAndUpdate(recoilDamage, HitResult.OTHER, false, true); user.scene.queueMessage(getPokemonMessage(user, ' is hit\nwith recoil!')); return true; @@ -552,7 +552,7 @@ export class SacrificialAttr extends MoveEffectAttr { if (!super.apply(user, target, move, args)) return false; - user.scene.unshiftPhase(new DamagePhase(user.scene, user.getBattlerIndex(), user.damage(user.hp, true, true), HitResult.OTHER)); + user.damageAndUpdate(user.hp, HitResult.OTHER, false, true, true); return true; } diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 0602e288182..158614f3202 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1123,8 +1123,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.scene.applyModifiers(EnemyDamageReducerModifier, false, damage); if (damage) { - damage.value = this.damage(damage.value); - this.scene.unshiftPhase(new DamagePhase(this.scene, this.getBattlerIndex(), damage.value, result as DamageResult, isCritical)); + damage.value = this.damageAndUpdate(damage.value, result as DamageResult, isCritical); if (isCritical) this.scene.queueMessage('A critical hit!'); this.scene.setPhaseQueueSplice(); @@ -1201,6 +1200,15 @@ 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 { + const damagePhase = new DamagePhase(this.scene, this.getBattlerIndex(), damage, result as DamageResult, critical); + this.scene.unshiftPhase(damagePhase); + damage = this.damage(damage, ignoreSegments, preventEndure); + // Damage amount may have changed, but needed to be queued before calling damage function + damagePhase.updateAmount(damage); + return damage; + } + heal(amount: integer): integer { const healAmount = Math.min(amount, this.getMaxHp() - this.hp); this.hp += healAmount; diff --git a/src/phases.ts b/src/phases.ts index cf2c2727e32..c78c0d7306f 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2397,7 +2397,7 @@ export class WeatherEffectPhase extends CommonAnimPhase { const damage = Math.ceil(pokemon.getMaxHp() / 16); this.scene.queueMessage(getWeatherDamageMessage(this.weather.weatherType, pokemon)); - this.scene.unshiftPhase(new DamagePhase(this.scene, pokemon.getBattlerIndex(), pokemon.damage(damage))); + pokemon.damageAndUpdate(damage); }; this.executeForAll((pokemon: Pokemon) => { @@ -2543,6 +2543,10 @@ export class DamagePhase extends PokemonPhase { this.applyDamage(); } + updateAmount(amount: integer): void { + this.amount = amount; + } + applyDamage() { switch (this.damageResult) { case HitResult.EFFECTIVE: