diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 771159346af..ef5e9695cd2 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -9,7 +9,7 @@ import { BerryModifier, ContactHeldItemTransferChanceModifier, ExpBalanceModifie import PartyUiHandler, { PartyOption, PartyUiMode } from "./ui/party-ui-handler"; import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballName, getPokeballTintColor, PokeballType } from "./data/pokeball"; import { CommonAnim, CommonBattleAnim, MoveAnim, initMoveAnim, loadMoveAnimAssets } from "./data/battle-anims"; -import { StatusEffect, getStatusEffectActivationText, getStatusEffectCatchRateMultiplier, getStatusEffectHealText, getStatusEffectObtainText, getStatusEffectOverlapText } from "./data/status-effect"; +import { Status, StatusEffect, getStatusEffectActivationText, getStatusEffectCatchRateMultiplier, getStatusEffectHealText, getStatusEffectObtainText, getStatusEffectOverlapText } from "./data/status-effect"; import { SummaryUiMode } from "./ui/summary-ui-handler"; import EvolutionSceneHandler from "./ui/evolution-scene-handler"; import { EvolutionPhase } from "./evolution-phase"; @@ -656,11 +656,13 @@ export class ToggleDoublePositionPhase extends BattlePhase { export class CheckSwitchPhase extends BattlePhase { protected fieldIndex: integer; + protected useName: boolean; - constructor(scene: BattleScene, fieldIndex: integer) { + constructor(scene: BattleScene, fieldIndex: integer, useName: boolean) { super(scene); this.fieldIndex = fieldIndex; + this.useName = useName; } start() { @@ -684,7 +686,7 @@ export class CheckSwitchPhase extends BattlePhase { return; } - this.scene.ui.showText('Will you switch\nPOKéMON?', null, () => { + this.scene.ui.showText(`Will you switch\n${this.useName ? pokemon.name : 'POKéMON'}?`, null, () => { this.scene.ui.setMode(Mode.CONFIRM, () => { this.scene.ui.setMode(Mode.MESSAGE); this.scene.unshiftPhase(new SwitchPhase(this.scene, this.fieldIndex, false, true)); @@ -1828,7 +1830,7 @@ export class VictoryPhase extends PokemonPhase { } } - if (!this.scene.currentBattle.enemyField.filter(p => p.isActive()).length) { + if (!this.scene.getEnemyField().filter(p => !p?.isFainted(true)).length) { this.scene.pushPhase(new BattleEndPhase(this.scene)); if (this.scene.currentBattle.waveIndex < this.scene.finalWave) { this.scene.pushPhase(new SelectModifierPhase(this.scene)); diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 7bd7ab897cc..9c2d7a62555 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -19,7 +19,7 @@ import { TextStyle, addTextObject } from './ui/text'; import { Moves, initMoves } from './data/move'; import { getDefaultModifierTypeForTier, getEnemyModifierTypesForWave } from './modifier/modifier-type'; import AbilityBar from './ui/ability-bar'; -import { BlockItemTheftAbAttr, applyAbAttrs, initAbilities } from './data/ability'; +import { BlockItemTheftAbAttr, DoubleBattleChanceAbAttr, applyAbAttrs, initAbilities } from './data/ability'; import Battle from './battle'; const enableAuto = true; @@ -512,15 +512,19 @@ export default class BattleScene extends Phaser.Scene { } newBattle(waveIndex?: integer, double?: boolean): Battle { - double = (waveIndex || ((this.currentBattle?.waveIndex || (startingWave - 1)) + 1)) % 2 === 0; + let newWaveIndex = waveIndex || ((this.currentBattle?.waveIndex || (startingWave - 1)) + 1); + let newDouble: boolean; - const isDouble = double === undefined || double; - - console.log(this.currentBattle?.waveIndex); + if (double === undefined) { + const doubleChance = new Utils.IntegerHolder(newWaveIndex % 10 === 0 ? 32 : 8); + this.getPlayerField().forEach(p => applyAbAttrs(DoubleBattleChanceAbAttr, p, null, doubleChance)); + newDouble = !Utils.randInt(doubleChance.value); + } else + newDouble = double; const lastBattle = this.currentBattle; - this.currentBattle = new Battle(waveIndex || ((this.currentBattle?.waveIndex || (startingWave - 1)) + 1), isDouble); + this.currentBattle = new Battle(newWaveIndex, newDouble); this.currentBattle.incrementTurn(this); if (!waveIndex) { @@ -542,9 +546,9 @@ export default class BattleScene extends Phaser.Scene { } } - if ((lastBattle?.double || false) !== isDouble) { + if ((lastBattle?.double || false) !== newDouble) { const availablePartyMemberCount = this.getParty().filter(p => !p.isFainted()).length; - if (isDouble) { + if (newDouble) { this.pushPhase(new ToggleDoublePositionPhase(this, true)); if (availablePartyMemberCount > 1) this.pushPhase(new SummonPhase(this, 1)); @@ -556,9 +560,9 @@ export default class BattleScene extends Phaser.Scene { } if (lastBattle) { - this.pushPhase(new CheckSwitchPhase(this, 0)); - if (lastBattle.double && isDouble) - this.pushPhase(new CheckSwitchPhase(this, 1)); + this.pushPhase(new CheckSwitchPhase(this, 0, newDouble)); + if (newDouble) + this.pushPhase(new CheckSwitchPhase(this, 1, newDouble)); } } diff --git a/src/data/ability.ts b/src/data/ability.ts index aefdd99c96b..2f20204e2d9 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -83,6 +83,18 @@ export class BlockRecoilDamageAttr extends AbAttr { } } +export class DoubleBattleChanceAbAttr extends AbAttr { + constructor() { + super(false); + } + + apply(pokemon: Pokemon, cancelled: Utils.BooleanHolder, args: any[]): boolean { + const doubleChance = (args[0] as Utils.IntegerHolder); + doubleChance.value = Math.max(doubleChance.value / 2, 1); + return true; + } +} + export class PreDefendAbAttr extends AbAttr { applyPreDefend(pokemon: Pokemon, attacker: Pokemon, move: PokemonMove, cancelled: Utils.BooleanHolder, args: any[]): boolean { return false; @@ -155,9 +167,10 @@ export class TypeImmunityHealAbAttr extends TypeImmunityAbAttr { applyPreDefend(pokemon: Pokemon, attacker: Pokemon, move: PokemonMove, cancelled: Utils.BooleanHolder, args: any[]): boolean { const ret = super.applyPreDefend(pokemon, attacker, move, cancelled, args); - if (ret && pokemon.getHpRatio() < 1) { - const scene = pokemon.scene; - scene.unshiftPhase(new PokemonHealPhase(scene, pokemon.getBattlerIndex(), Math.max(Math.floor(pokemon.getMaxHp() / 4), 1), getPokemonMessage(pokemon, `'s ${pokemon.getAbility().name}\nrestored its HP a little!`), true)); + if (ret) { + if (pokemon.getHpRatio() < 1) + pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.getBattlerIndex(), + Math.max(Math.floor(pokemon.getMaxHp() / 4), 1), getPokemonMessage(pokemon, `'s ${pokemon.getAbility().name}\nrestored its HP a little!`), true)); return true; } @@ -695,7 +708,6 @@ export function applyAbAttrs(attrType: { new(...args: any[]): AbAttr }, pokemon: const ability = pokemon.getAbility(); const attrs = ability.getAttrs(attrType) as AbAttr[]; - console.log(attrs, ability); for (let attr of attrs) { if (!canApplyAttr(pokemon, attr)) continue; @@ -1220,7 +1232,8 @@ export function initAbilities() { new Ability(Abilities.HUSTLE, "Hustle (N)", "Boosts the ATTACK stat, but lowers accuracy.", 3), new Ability(Abilities.HYPER_CUTTER, "Hyper Cutter", "Prevents other POKéMON from lowering ATTACK stat.", 3) .attr(ProtectStatAbAttr, BattleStat.ATK), - new Ability(Abilities.ILLUMINATE, "Illuminate (N)", "Raises the likelihood of meeting wild POKéMON.", 3), + new Ability(Abilities.ILLUMINATE, "Illuminate", "Raises the likelihood of an encounter being a double battle.", 3) + .attr(DoubleBattleChanceAbAttr), new Ability(Abilities.IMMUNITY, "Immunity", "Prevents the POKéMON from getting poisoned.", 3) .attr(StatusEffectImmunityAbAttr, StatusEffect.POISON), new Ability(Abilities.INNER_FOCUS, "Inner Focus", "The POKéMON is protected from flinching.", 3) diff --git a/src/evolution-phase.ts b/src/evolution-phase.ts index 65cf4dd42b2..3868640e96b 100644 --- a/src/evolution-phase.ts +++ b/src/evolution-phase.ts @@ -97,7 +97,8 @@ export class EvolutionPhase extends BattlePhase { const levelMoves = pokemon.getLevelMoves(this.lastLevel + 1); for (let lm of levelMoves) - this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.partyMemberIndex, lm)); + this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.partyMemberIndex, lm)); + this.scene.unshiftPhase(new EndEvolutionPhase(this.scene)); this.scene.time.delayedCall(1000, () => { const evolutionBgm = this.scene.sound.add('evolution'); @@ -443,4 +444,12 @@ export class EvolutionPhase extends BattlePhase { updateParticle(); } +} + +export class EndEvolutionPhase extends BattlePhase { + start() { + super.start(); + + this.scene.ui.setModeForceTransition(Mode.MESSAGE).then(() => this.end()); + } } \ No newline at end of file diff --git a/src/pokemon.ts b/src/pokemon.ts index 59cb2397329..75109422cea 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -188,8 +188,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { } } - isFainted(): boolean { - return !this.hp; + isFainted(checkStatus?: boolean): boolean { + return !this.hp && (!checkStatus || this.status?.effect === StatusEffect.FAINT); } isActive(): boolean {