From 1df4f0451908928c8b8851cf499e1bcb60ac1482 Mon Sep 17 00:00:00 2001 From: DustinLin Date: Sat, 11 May 2024 08:22:22 -0400 Subject: [PATCH 1/7] fixing order of messages, scences, to render messages before fainting --- src/battle-scene.ts | 2 ++ src/field/pokemon.ts | 51 ++++++++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 21 deletions(-) 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); From e13ca9173e971a1254b4cf524e776683138683e8 Mon Sep 17 00:00:00 2001 From: DustinLin Date: Sat, 11 May 2024 11:24:35 -0400 Subject: [PATCH 2/7] updated fix for effectiveness text rendering order for multi hit moves --- src/field/pokemon.ts | 53 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 938f6134e..1e11058fb 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1473,7 +1473,33 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { // requires passing in hitsLeft damage.value = this.damageAndUpdate(damage.value, result as DamageResult, isCritical, oneHitKo, oneHitKo, source.turnData.hitsLeft); this.turnData.damageTaken += damage.value; + // eg: bullet seed 1 shots, double-slap 1 shots, this isbroken right now + if (this.isFainted() && (this.turnData.hitsLeft > 0 || this.turnData.hitCount > 1)) { + // also want to check if it was a multi hit move? + //const hitsTotal = this.turnData.hitCount - Math.max(this.turnData.hitsLeft, 0); + // multi hit move killed early, then queue how many hits were made before + this.scene.queueMessage(i18next.t('battle:attackHitsCount', { count: this.turnData.hitCount})); + } + // hitsLeft: for multi-hit moves, only want to render effectiveness text at end. + // also want to render if opponent is fainting?, or if you are fainting? + if (this.turnData.hitsLeft === 1 || this.isFainted()) { + 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; + } + } + // forbidden phasequeue splice udpate, idk what happens after this this.scene.setPhaseQueueSplice(); if (source.isPlayer()) { this.scene.validateAchvs(DamageAchv, damage); @@ -1486,6 +1512,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.turnData.attacksReceived.unshift(attackResult); if (source.isPlayer() && !this.isPlayer()) this.scene.applyModifiers(DamageMoneyRewardModifier, true, source, damage) + + if (this.isFainted()) { + console.log(`${this.name} is fainting! ${this.turnData.hitCount}, ${this.turnData.hitsLeft}`) + this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), oneHitKo)); + this.resetSummonData(); + } } if (damage) @@ -1528,10 +1560,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { 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(); - } return damage; } @@ -1543,23 +1571,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { 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 From 62e51093c94620ce0bc1154f47da6c8276871372 Mon Sep 17 00:00:00 2001 From: DustinLin Date: Sun, 12 May 2024 13:05:23 -0400 Subject: [PATCH 3/7] fixing messages not appearing for multi-hit moves on faint --- src/battle-scene.ts | 3 ++- src/field/pokemon.ts | 29 +++++++++++++++++------------ src/phases.ts | 9 +++++++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index da40d850c..b9134bc0d 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1489,7 +1489,8 @@ 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)) + // debug: printing out phase queue + //this.phaseQueuePrepend.forEach(p => console.log(p.constructor.name)); } clearPhaseQueue(): void { diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 1e11058fb..c38522a9e 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1473,16 +1473,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { // requires passing in hitsLeft damage.value = this.damageAndUpdate(damage.value, result as DamageResult, isCritical, oneHitKo, oneHitKo, source.turnData.hitsLeft); this.turnData.damageTaken += damage.value; - // eg: bullet seed 1 shots, double-slap 1 shots, this isbroken right now - if (this.isFainted() && (this.turnData.hitsLeft > 0 || this.turnData.hitCount > 1)) { - // also want to check if it was a multi hit move? - //const hitsTotal = this.turnData.hitCount - Math.max(this.turnData.hitsLeft, 0); - // multi hit move killed early, then queue how many hits were made before - this.scene.queueMessage(i18next.t('battle:attackHitsCount', { count: this.turnData.hitCount})); - } + // hitsLeft: for multi-hit moves, only want to render effectiveness text at end. - // also want to render if opponent is fainting?, or if you are fainting? - if (this.turnData.hitsLeft === 1 || this.isFainted()) { + // also want to render if a pokemon fainted + console.log(`the number of hits left for this turn for ${this.name} is ${source.turnData.hitsLeft}`) + if (source.turnData.hitsLeft === 1 || this.isFainted()) { switch (result as HitResult) { case HitResult.SUPER_EFFECTIVE: this.scene.queueMessage(i18next.t('battle:hitResultSuperEffective')); @@ -1499,8 +1494,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } - // forbidden phasequeue splice udpate, idk what happens after this - this.scene.setPhaseQueueSplice(); if (source.isPlayer()) { this.scene.validateAchvs(DamageAchv, damage); if (damage.value > this.scene.gameData.gameStats.highestDamage) @@ -1513,8 +1506,20 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (source.isPlayer() && !this.isPlayer()) this.scene.applyModifiers(DamageMoneyRewardModifier, true, source, damage) + // case when multi hit move killed early, then queue how many hits were made before + // eg: bullet seed 1 shots, double-slap 1 shots, + // note that simply looking at this.turnData.attacksReceived doesn't work for double battles + if (this.isFainted() && source.turnData.hitsLeft > 0){ + console.log(`${this.name} fainted: they received this many hits: ${this.turnData.attacksReceived.length}`); + // off by one from decrement, test more + const hitsTotal = source.turnData.hitCount - Math.max(source.turnData.hitsLeft, 0) + 1; + this.scene.queueMessage(i18next.t('battle:attackHitsCount', { count: hitsTotal})); + } + + // not sure what this set function is accomplishing, perhaps for the faint phase? it messes up with the queueMessage() + this.scene.setPhaseQueueSplice(); + if (this.isFainted()) { - console.log(`${this.name} is fainting! ${this.turnData.hitCount}, ${this.turnData.hitsLeft}`) this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), oneHitKo)); this.resetSummonData(); } diff --git a/src/phases.ts b/src/phases.ts index b697f7acb..b73632877 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2518,9 +2518,13 @@ export class MoveEffectPhase extends PokemonPhase { if (--user.turnData.hitsLeft >= 1 && this.getTarget()?.isActive()) this.scene.unshiftPhase(this.getNewHitPhase()); else { + // queue message for number of hits made by multi-move + // BUG: when fainting occurs, the resulting message isn't rendered - has to do with FaintPhase + // temp fix in pokemon.ts apply() that checks, but ideally want to fix it here at the source const hitsTotal = user.turnData.hitCount - Math.max(user.turnData.hitsLeft, 0); - if (hitsTotal > 1) + if (hitsTotal > 1 || user.turnData.hitsLeft > 0){ this.scene.queueMessage(i18next.t('battle:attackHitsCount', { count: hitsTotal })); + } this.scene.applyModifiers(HitHealModifier, this.player, user); } } @@ -2985,7 +2989,8 @@ export class PostTurnStatusEffectPhase extends PokemonPhase { } export class MessagePhase extends Phase { - private text: string; + // todo change backlk to private + public text: string; private callbackDelay: integer; private prompt: boolean; private promptDelay: integer; From 1782a184596ca99ad024605a88866bc9b8edca68 Mon Sep 17 00:00:00 2001 From: DustinLin Date: Sun, 12 May 2024 13:22:41 -0400 Subject: [PATCH 4/7] updated multi-hit condition) --- src/field/pokemon.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index ee2abc786..0e7911f9f 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1648,7 +1648,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { // case when multi hit move killed early, then queue how many hits were made before // eg: bullet seed 1 shots, double-slap 1 shots, // note that simply looking at this.turnData.attacksReceived doesn't work for double battles - if (this.isFainted() && source.turnData.hitsLeft > 0){ + if (this.isFainted() && source.turnData.hitsLeft > 1){ console.log(`${this.name} fainted: they received this many hits: ${this.turnData.attacksReceived.length}`); // off by one from decrement, test more const hitsTotal = source.turnData.hitCount - Math.max(source.turnData.hitsLeft, 0) + 1; From 55f3befbcb515a83bcc3bf8d829d19f740d633f8 Mon Sep 17 00:00:00 2001 From: DustinLin Date: Mon, 13 May 2024 09:09:05 -0400 Subject: [PATCH 5/7] fixing PR conflicts --- src/field/pokemon.ts | 19 +++++++++---------- src/phases.ts | 3 +-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 0e7911f9f..a02bc2aad 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1609,13 +1609,16 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { const oneHitKo = result === HitResult.ONE_HIT_KO; // 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); + damage.value = this.damageAndUpdate(damage.value, result as DamageResult, isCritical, oneHitKo, oneHitKo); this.turnData.damageTaken += damage.value; + // queue critical message before effectiveness + if (isCritical) + this.scene.queueMessage(i18next.t('battle:hitResultCriticalHit')); + // hitsLeft: for multi-hit moves, only want to render effectiveness text at end. // also want to render if a pokemon fainted - console.log(`the number of hits left for this turn for ${this.name} is ${source.turnData.hitsLeft}`) + //console.log(`the number of hits left for this turn for ${this.name} is ${source.turnData.hitsLeft}`) if (source.turnData.hitsLeft === 1 || this.isFainted()) { switch (result as HitResult) { case HitResult.SUPER_EFFECTIVE: @@ -1640,6 +1643,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } source.turnData.damageDealt += damage.value; this.battleData.hitCount++; + // create attack result and push to turnData const attackResult = { move: move.id, result: result as DamageResult, damage: damage.value, critical: isCritical, sourceId: source.id }; this.turnData.attacksReceived.unshift(attackResult); if (source.isPlayer() && !this.isPlayer()) @@ -1658,6 +1662,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { // not sure what this set function is accomplishing, perhaps for the faint phase? it messes up with the queueMessage() this.scene.setPhaseQueueSplice(); + // finally checks and adds Fainted scene if (this.isFainted()) { this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), oneHitKo)); this.resetSummonData(); @@ -1701,20 +1706,14 @@ 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 return damage; } - damageAndUpdate(damage: integer, result?: DamageResult, critical: boolean = false, ignoreSegments: boolean = false, preventEndure: boolean = false, hitsLeft: integer = 1): integer { + 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); - // queue critical message before effectiveness - if (critical) - this.scene.queueMessage(i18next.t('battle:hitResultCriticalHit')); - damage = this.damage(damage, ignoreSegments, preventEndure); // Damage amount may have changed, but needed to be queued before calling damage function diff --git a/src/phases.ts b/src/phases.ts index f557461e1..1f358dd97 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -3004,8 +3004,7 @@ export class PostTurnStatusEffectPhase extends PokemonPhase { } export class MessagePhase extends Phase { - // todo change backlk to private - public text: string; + private text: string; private callbackDelay: integer; private prompt: boolean; private promptDelay: integer; From 4d655ccc603e286cd6c1d28d767d56993476a791 Mon Sep 17 00:00:00 2001 From: DustinLin Date: Mon, 13 May 2024 17:07:50 -0400 Subject: [PATCH 6/7] adding comments and FaintPhase setPhaseQueueSplice bug, fixing overrides merge conflict --- src/field/pokemon.ts | 33 ++++++++++++++++++++------------- src/overrides.ts | 11 ++++++----- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index db87f44a2..211350924 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -1646,28 +1646,35 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if (source.isPlayer() && !this.isPlayer()) this.scene.applyModifiers(DamageMoneyRewardModifier, true, source, damage) - // case when multi hit move killed early, then queue how many hits were made before - // eg: bullet seed 1 shots, double-slap 1 shots, - // note that simply looking at this.turnData.attacksReceived doesn't work for double battles - if (this.isFainted() && source.turnData.hitsLeft > 1){ - console.log(`${this.name} fainted: they received this many hits: ${this.turnData.attacksReceived.length}`); - // off by one from decrement, test more - const hitsTotal = source.turnData.hitCount - Math.max(source.turnData.hitsLeft, 0) + 1; - this.scene.queueMessage(i18next.t('battle:attackHitsCount', { count: hitsTotal})); - } - - // not sure what this set function is accomplishing, perhaps for the faint phase? it messes up with the queueMessage() - this.scene.setPhaseQueueSplice(); // finally checks and adds Fainted scene if (this.isFainted()) { + /** + * when adding the FaintPhase, want to toggle future unshiftPhase() and queueMessage() calls + * to appear before the FaintPhase (as FaintPhase will potentially end the encounter and add Phases such as + * GameOverPhase, VictoryPhase, etc.. that will interfere with anything else that happens during this MoveEffectPhase) + * + * once the MoveEffectPhase is over (and calls it's .end() function, shiftPhase() will reset the PhaseQueueSplice via clearPhaseQueueSplice() ) + */ + this.scene.setPhaseQueueSplice(); this.scene.unshiftPhase(new FaintPhase(this.scene, this.getBattlerIndex(), oneHitKo)); this.resetSummonData(); } + } - if (damage) + /** + * since damage is an object, I don't see how this would ever by false? + * i think the motivation was to have this here to counter setPhaseQueueSplice() + * not sure the original motivation + * + * It would be bad to run both the top if block and the one below commented out without changing the later's condition + */ + /* + if (damage){ this.scene.clearPhaseQueueSplice(); + } + */ } break; case MoveCategory.STATUS: diff --git a/src/overrides.ts b/src/overrides.ts index 704019a1d..d7975868c 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -47,12 +47,13 @@ export const POKEBALL_OVERRIDE: { active: boolean, pokeballs: PokeballCounts } = // forms can be found in pokemon-species.ts export const STARTER_FORM_OVERRIDE: integer = 0; // default 5 or 20 for Daily -export const STARTING_LEVEL_OVERRIDE: integer = 0; +export const STARTING_LEVEL_OVERRIDE: integer = 10; export const ABILITY_OVERRIDE: Abilities = Abilities.NONE; export const PASSIVE_ABILITY_OVERRIDE: Abilities = Abilities.NONE; -export const MOVESET_OVERRIDE: Array = []; export const SHINY_OVERRIDE: boolean = false; export const VARIANT_OVERRIDE: Variant = 0; +// eg: Moves.TACKLE +export const MOVESET_OVERRIDE: Array = [] /** * OPPONENT / ENEMY OVERRIDES @@ -60,7 +61,7 @@ export const VARIANT_OVERRIDE: Variant = 0; export const OPP_ABILITY_OVERRIDE: Abilities = Abilities.NONE; export const OPP_PASSIVE_ABILITY_OVERRIDE = Abilities.NONE; -export const OPP_MOVESET_OVERRIDE: Array = []; +export const OPP_MOVESET_OVERRIDE: Array = [] export const OPP_SHINY_OVERRIDE: boolean = false; export const OPP_VARIANT_OVERRIDE: Variant = 0; @@ -70,8 +71,8 @@ export const OPP_VARIANT_OVERRIDE: Variant = 0; * default is 0 to not override * @example SPECIES_OVERRIDE = Species.Bulbasaur; */ -export const STARTER_SPECIES_OVERRIDE: Species | integer = 0; -export const OPP_SPECIES_OVERRIDE: Species | integer = 0; +export const STARTER_SPECIES_OVERRIDE: Species | integer = 0 +export const OPP_SPECIES_OVERRIDE: Species | integer = 0 /** * MODIFIER / ITEM OVERRIDES From 7b86b4c4d92c9145b78b7b85d6bc12b216766742 Mon Sep 17 00:00:00 2001 From: DustinLin Date: Mon, 13 May 2024 17:23:56 -0400 Subject: [PATCH 7/7] writing better comments --- src/battle-scene.ts | 42 ++++++++++++++++++++++++++++++++++++++++-- src/phases.ts | 8 +++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 444952936..4e6a477c6 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1498,24 +1498,41 @@ export default class BattleScene extends SceneBase { getStandbyPhase(): Phase { return this.standbyPhase; } + /** + * PhaseQueuePrepend: is a temp storage of what will be added to PhaseQueue + * PhaseQueue: dequeue/remove the first element to get the next phase + * queues are moved around during shiftPhase() below + */ + // adds a phase to "nextCommandPhaseQueue", as long as boolean passed in is false pushPhase(phase: Phase, defer: boolean = false): void { (!defer ? this.phaseQueue : this.nextCommandPhaseQueue).push(phase); } + // adds phase to the end, or at some specified index unshiftPhase(phase: Phase): void { if (this.phaseQueuePrependSpliceIndex === -1) + // .push() adds to end of array this.phaseQueuePrepend.push(phase); else + // .splice(index, num elements to remove, what to add) + // modifies array by inserting at index, removing num of elements after index this.phaseQueuePrepend.splice(this.phaseQueuePrependSpliceIndex, 0, phase); - // debug: printing out phase queue - //this.phaseQueuePrepend.forEach(p => console.log(p.constructor.name)); + /** + * debugging queues via printing, may be helpful in the future + console.log(`State of the phaseQueuePrepend (will be moved over to phaseQeueu)`) + this.phaseQueuePrepend.forEach(p => console.log(p.constructor.name)); + + console.log(`State of the phaseQueue, what is going to be called next `) + this.phaseQueue.forEach(p => console.log(p.constructor.name)); + */ } clearPhaseQueue(): void { this.phaseQueue.splice(0, this.phaseQueue.length); } + // combo with unshiftPhase(), want to start inserting at current length instead of the "end", useful if phaseQueuePrepend gets longer with Phases setPhaseQueueSplice(): void { this.phaseQueuePrependSpliceIndex = this.phaseQueuePrepend.length; } @@ -1524,6 +1541,10 @@ export default class BattleScene extends SceneBase { this.phaseQueuePrependSpliceIndex = -1; } + /** + * is called by each Phase implementations "end()" by default + * dumps everything from phaseQueuePrepend to the start of of phaseQueue, then starts the first one + */ shiftPhase(): void { if (this.standbyPhase) { this.currentPhase = this.standbyPhase; @@ -1531,14 +1552,28 @@ export default class BattleScene extends SceneBase { return; } + // shifting phase (with no standby phase) will move everything from prepend to actual PhaseQueue? + // resets the index, if it was changed via setPhaseQueueSplice() if (this.phaseQueuePrependSpliceIndex > -1) this.clearPhaseQueueSplice(); if (this.phaseQueuePrepend.length) { while (this.phaseQueuePrepend.length) + // appends phaseQueuePrepend to phaseQueue + // eg: phaseQueue = [4,5,6], phaseQUeuePrepend = [1,2,3] + // -> [1,2,3,4,5,6] this.phaseQueue.unshift(this.phaseQueuePrepend.pop()); } + + // then starts from PhaseQueue, .shift() removes first elm of array + // populatePhaseQueue() adds a turnInit Phase at the end of phaseQueue (if the queue is emtpy) if (!this.phaseQueue.length) this.populatePhaseQueue(); + + /** debugging + * + console.log(`SHIFT PHASE: State of the phaseQueue, what is going to be called next`) + this.phaseQueue.forEach(p => console.log(p.constructor.name)); + */ this.currentPhase = this.phaseQueue.shift(); this.currentPhase.start(); } @@ -1589,11 +1624,14 @@ export default class BattleScene extends SceneBase { queueMessage(message: string, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer, defer?: boolean) { const phase = new MessagePhase(this, message, callbackDelay, prompt, promptDelay); if (!defer) + // adds to the end of PhaseQueuePrepend this.unshiftPhase(phase); else + //remember that pushPhase adds it to nextCommandPhaseQueue this.pushPhase(phase); } + // moves everyhting from nextCommandPhaseQueue populatePhaseQueue(): void { if (this.nextCommandPhaseQueue.length) { this.phaseQueue.push(...this.nextCommandPhaseQueue); diff --git a/src/phases.ts b/src/phases.ts index 714eba771..a050af835 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2032,6 +2032,11 @@ export class TurnStartPhase extends FieldPhase { this.scene.pushPhase(new TurnEndPhase(this.scene)); + /** + * this.end() will call shiftPhase(), which dumps everything from PrependQueue (aka everything that is unshifted()) to the front + * of the queue and dequeues to start the next phase + * this is important since stuff like SwitchSummon, AttemptRun, AttemptCapture Phases break the "flow" and should take precedence + */ this.end(); } } @@ -2251,6 +2256,7 @@ export class MovePhase extends BattlePhase { return false; }); + // Readability?: this function declaration honestly gets in the way of readability of what start() is doing , move either to beginning or end const doMove = () => { this.pokemon.turnData.acted = true; // Record that the move was attempted, even if it fails @@ -2531,7 +2537,7 @@ export class MoveEffectPhase extends PokemonPhase { const user = this.getUserPokemon(); if (user) { if (--user.turnData.hitsLeft >= 1 && this.getTarget()?.isActive()) - this.scene.unshiftPhase(this.getNewHitPhase()); + this.scene.unshiftPhase(this.getNewHitPhase()); // adds another MoveAffectPhase else { // queue message for number of hits made by multi-move // BUG: when fainting occurs, the resulting message isn't rendered - has to do with FaintPhase