fixing order of messages, scences, to render messages before fainting

pull/783/head
DustinLin 2024-05-11 08:22:22 -04:00
parent f1935a3e15
commit 1df4f04519
2 changed files with 32 additions and 21 deletions

View File

@ -125,6 +125,7 @@ export default class BattleScene extends SceneBase {
public gameData: GameData; public gameData: GameData;
public sessionSlotId: integer; public sessionSlotId: integer;
// can debug phases using "phase.constructor.name"
private phaseQueue: Phase[]; private phaseQueue: Phase[];
private phaseQueuePrepend: Phase[]; private phaseQueuePrepend: Phase[];
private phaseQueuePrependSpliceIndex: integer; private phaseQueuePrependSpliceIndex: integer;
@ -1488,6 +1489,7 @@ export default class BattleScene extends SceneBase {
this.phaseQueuePrepend.push(phase); this.phaseQueuePrepend.push(phase);
else else
this.phaseQueuePrepend.splice(this.phaseQueuePrependSpliceIndex, 0, phase); this.phaseQueuePrepend.splice(this.phaseQueuePrependSpliceIndex, 0, phase);
this.phaseQueuePrepend.forEach(p => console.log(p.constructor.name))
} }
clearPhaseQueue(): void { clearPhaseQueue(): void {

View File

@ -1460,6 +1460,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
console.log('damage', damage.value, move.name, power.value, sourceAtk, targetDef); console.log('damage', damage.value, move.name, power.value, sourceAtk, targetDef);
if (damage.value) { if (damage.value) {
if (this.getHpRatio() === 1) if (this.getHpRatio() === 1)
applyPreDefendAbAttrs(PreDefendFullHpEndureAbAttr, this, source, battlerMove, cancelled, damage); 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); this.scene.applyModifiers(EnemyEndureChanceModifier, false, this);
const oneHitKo = result === HitResult.ONE_HIT_KO; 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; this.turnData.damageTaken += damage.value;
if (isCritical)
this.scene.queueMessage(i18next.t('battle:hitResultCriticalHit'));
this.scene.setPhaseQueueSplice(); this.scene.setPhaseQueueSplice();
if (source.isPlayer()) { if (source.isPlayer()) {
this.scene.validateAchvs(DamageAchv, damage); 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) 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) if (damage)
this.scene.clearPhaseQueueSplice(); this.scene.clearPhaseQueueSplice();
} }
@ -1541,6 +1527,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
damage = Math.min(damage, this.hp); damage = Math.min(damage, this.hp);
this.hp = this.hp - damage; this.hp = this.hp - damage;
// checks and adds Fainted scene
if (this.isFainted()) { if (this.isFainted()) {
this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), preventEndure)); this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), preventEndure));
this.resetSummonData(); this.resetSummonData();
@ -1549,9 +1536,31 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
return damage; 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); const damagePhase = new DamagePhase(this.scene, this.getBattlerIndex(), damage, result as DamageResult, critical);
this.scene.unshiftPhase(damagePhase); 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 = this.damage(damage, ignoreSegments, preventEndure);
// Damage amount may have changed, but needed to be queued before calling damage function // Damage amount may have changed, but needed to be queued before calling damage function
damagePhase.updateAmount(damage); damagePhase.updateAmount(damage);