diff --git a/src/auto-play.ts b/src/auto-play.ts index 6bfd4c754ec..7314adf38f5 100644 --- a/src/auto-play.ts +++ b/src/auto-play.ts @@ -13,36 +13,43 @@ import PartyUiHandler, { PartyUiMode } from "./ui/party-ui-handler"; import ConfirmUiHandler from "./ui/confirm-ui-handler"; import { Mode } from "./ui/ui"; -export function initAutoPlay(speed: number) { +export function initAutoPlay() { const thisArg = this as BattleScene; const originalDelayedCall = this.time.delayedCall; this.time.delayedCall = function (delay: number, callback: Function, args?: any[], callbackScope?: any) { - delay /= speed; + if (thisArg.auto) + delay /= thisArg.autoSpeed; originalDelayedCall.apply(this, [ delay, callback, args, callbackScope ]); }; const originalAddEvent = this.time.addEvent; this.time.addEvent = function (config: Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig) { - if (config.delay) - config.delay = Math.ceil(config.delay / speed); - if (config.startAt) - config.startAt = Math.ceil(config.startAt / speed); + if (thisArg.auto) { + if (config.delay) + config.delay = Math.ceil(config.delay / thisArg.autoSpeed); + if (config.startAt) + config.startAt = Math.ceil(config.startAt / thisArg.autoSpeed); + } return originalAddEvent.apply(this, [ config ]); }; const originalTweensAdd = this.tweens.add; this.tweens.add = function (config: Phaser.Types.Tweens.TweenBuilderConfig | object) { - if (config.duration) - config.duration = Math.ceil(config.duration / speed); - if (config.delay) - config.delay = Math.ceil(config.delay / speed); + if (thisArg.auto) { + if (config.duration) + config.duration = Math.ceil(config.duration / thisArg.autoSpeed); + if (config.delay) + config.delay = Math.ceil(config.delay / thisArg.autoSpeed); + } return originalTweensAdd.apply(this, [ config ]); }; const originalAddCounter = this.tweens.addCounter; this.tweens.addCounter = function (config: Phaser.Types.Tweens.NumberTweenBuilderConfig) { - if (config.duration) - config.duration = Math.ceil(config.duration / speed); - if (config.delay) - config.delay = Math.ceil(config.delay / speed); + if (thisArg.auto) { + if (config.duration) + config.duration = Math.ceil(config.duration / thisArg.autoSpeed); + if (config.delay) + config.delay = Math.ceil(config.delay / thisArg.autoSpeed); + } return originalAddCounter.apply(this, [ config ]); }; @@ -68,12 +75,15 @@ export function initAutoPlay(speed: number) { const pokemon = party[p]; if (pokemon.getHpRatio() <= 0.4) continue; - const effectiveness = getMaxMoveEffectiveness(pokemon, enemyPokemon) / getMaxMoveEffectiveness(enemyPokemon, pokemon); + const effectiveness = enemyPokemon + ? getMaxMoveEffectiveness(pokemon, enemyPokemon) / getMaxMoveEffectiveness(enemyPokemon, pokemon) + : 1; if (effectiveness > bestPartyMemberEffectiveness) { bestPartyMemberIndex = p; bestPartyMemberEffectiveness = effectiveness; } - console.log(p, Species[pokemon.species.speciesId], '->', Species[enemyPokemon.species.speciesId], effectiveness); + if (enemyPokemon) + console.log(p, Species[pokemon.species.speciesId], '->', Species[enemyPokemon.species.speciesId], effectiveness); } if (bestPartyMemberIndex === -1) { @@ -108,80 +118,93 @@ export function initAutoPlay(speed: number) { const originalMessageUiHandlerShowText = MessageUiHandler.prototype.showText; MessageUiHandler.prototype.showText = function (text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean) { - delay = 0; - callbackDelay = 0; + if (thisArg.auto) { + delay = 1; + callbackDelay = 0; + } originalMessageUiHandlerShowText.apply(this, [ text, delay, callback, callbackDelay, prompt ]); }; const originalMessageUiHandlerShowPrompt = MessageUiHandler.prototype.showPrompt; MessageUiHandler.prototype.showPrompt = function (callback: Function, callbackDelay: integer) { - callbackDelay = 0; + if (thisArg.auto) + callbackDelay = 0; originalMessageUiHandlerShowPrompt.apply(this, [ callback, callbackDelay ]); - thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); + if (thisArg.auto) + thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); }; const originalMessageUiHandlerPromptLevelUpStats = messageUiHandler.promptLevelUpStats; messageUiHandler.promptLevelUpStats = function (prevStats: integer[], showTotals: boolean, callback?: Function) { originalMessageUiHandlerPromptLevelUpStats.apply(this, [ prevStats, showTotals, callback ]); - this.processInput(keyCodes.Z); + if (thisArg.auto) + thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); }; const originalCommandUiHandlerShow = commandUiHandler.show; commandUiHandler.show = function (args: any[]) { originalCommandUiHandlerShow.apply(this, [ args ]); - thisArg.time.delayedCall(20, () => { - const bestPartyMemberIndex = getBestPartyMemberIndex(); - if (bestPartyMemberIndex) { - console.log(bestPartyMemberIndex, thisArg.getParty()) - console.log('Switching to ', Species[thisArg.getParty()[bestPartyMemberIndex].species.speciesId]); - nextPartyMemberIndex = bestPartyMemberIndex; - commandUiHandler.setCursor(2); - thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); - } else { - commandUiHandler.setCursor(0); - thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); - } - }); + if (thisArg.auto) { + thisArg.time.delayedCall(20, () => { + const bestPartyMemberIndex = getBestPartyMemberIndex(); + if (bestPartyMemberIndex) { + console.log(bestPartyMemberIndex, thisArg.getParty()) + console.log('Switching to ', Species[thisArg.getParty()[bestPartyMemberIndex].species.speciesId]); + nextPartyMemberIndex = bestPartyMemberIndex; + commandUiHandler.setCursor(2); + thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); + } else { + commandUiHandler.setCursor(0); + thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); + } + }); + } }; const originalFightUiHandlerShow = fightUiHandler.show; fightUiHandler.show = function (args: any[]) { originalFightUiHandlerShow.apply(this, [ args ]); - if (!playerPokemon.aiType) - playerPokemon.aiType = AiType.SMART; - thisArg.time.delayedCall(20, () => { - const nextMove = playerPokemon.getNextMove() as PokemonMove; - fightUiHandler.setCursor(playerPokemon.moveset.indexOf(nextMove)); - thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); - }); + if (thisArg.auto) { + if (!playerPokemon.aiType) + playerPokemon.aiType = AiType.SMART; + thisArg.time.delayedCall(20, () => { + const nextMove = playerPokemon.getNextMove() as PokemonMove; + fightUiHandler.setCursor(playerPokemon.moveset.indexOf(nextMove)); + thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); + }); + } }; const originalPartyUiHandlerShow = partyUiHandler.show; partyUiHandler.show = function (args: any[]) { originalPartyUiHandlerShow.apply(this, [ args ]); - thisArg.time.delayedCall(20, () => { - if (nextPartyMemberIndex === -1) - nextPartyMemberIndex = getBestPartyMemberIndex(); - partyUiHandler.setCursor(nextPartyMemberIndex); - nextPartyMemberIndex = -1; - if (partyUiHandler.partyUiMode === PartyUiMode.MODIFIER || partyUiHandler.getCursor()) { - this.processInput(keyCodes.Z); - this.processInput(keyCodes.Z); - } else - this.processInput(keyCodes.X); - }); + if (thisArg.auto) { + thisArg.time.delayedCall(20, () => { + if (nextPartyMemberIndex === -1) + nextPartyMemberIndex = getBestPartyMemberIndex(); + partyUiHandler.setCursor(nextPartyMemberIndex); + nextPartyMemberIndex = -1; + if (partyUiHandler.partyUiMode === PartyUiMode.MODIFIER || partyUiHandler.getCursor()) { + this.processInput(keyCodes.Z); + thisArg.time.delayedCall(250, () => this.processInput(keyCodes.Z)); + } else + this.processInput(keyCodes.X); + }); + } }; const originalSwitchCheckUiHandlerShow = switchCheckUiHandler.show; switchCheckUiHandler.show = function (args: any[]) { originalSwitchCheckUiHandlerShow.apply(this, [ args ]); - const bestPartyMemberIndex = getBestPartyMemberIndex(); - thisArg.time.delayedCall(20, () => { - if (bestPartyMemberIndex) - nextPartyMemberIndex = bestPartyMemberIndex; - switchCheckUiHandler.setCursor(bestPartyMemberIndex ? 1 : 0); - thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); - }); + if (thisArg.auto) { + const bestPartyMemberIndex = getBestPartyMemberIndex(); + thisArg.time.delayedCall(20, () => { + if (bestPartyMemberIndex) + nextPartyMemberIndex = bestPartyMemberIndex; + switchCheckUiHandler.setCursor(bestPartyMemberIndex ? 1 : 0); + thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); + }); + } } const tryGetBestModifier = (modifierTypes: Array, predicate: Function) => { @@ -197,6 +220,11 @@ export function initAutoPlay(speed: number) { const originalModifierSelectUiHandlerShow = modifierSelectUiHandler.show; modifierSelectUiHandler.show = function (args: any[]) { + if (!thisArg.auto) { + originalModifierSelectUiHandlerShow.apply(this, [ args ]); + return; + } + if (modifierSelectUiHandler.active) return; @@ -262,7 +290,7 @@ export function initAutoPlay(speed: number) { if (thisArg.getCurrentPhase() instanceof SelectModifierPhase) { if (optionIndex < modifierSelectUiHandler.options.length - 1) { optionIndex++; - trySelectModifier(); + thisArg.time.delayedCall(250, () => trySelectModifier()); } else modifierSelectUiHandler.processInput(keyCodes.X); } diff --git a/src/battle-phase.ts b/src/battle-phase.ts index 5a98df35fcb..24b2b088c19 100644 --- a/src/battle-phase.ts +++ b/src/battle-phase.ts @@ -21,7 +21,7 @@ export class BattlePhase { } start() { - console.log(`Start Phase ${this.constructor.name}`) + console.log(`%cStart Phase ${this.constructor.name}`, 'color:green;') } end() { diff --git a/src/battle-scene.ts b/src/battle-scene.ts index ebeeb35e363..b57607aae56 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -12,9 +12,11 @@ import { initAutoPlay } from './auto-play'; import { Battle } from './battle'; import { populateAnims } from './battle-anims'; +const enableAuto = true; + export default class BattleScene extends Phaser.Scene { - private auto: boolean = true; - private autoSpeed: integer = 1; + public auto: boolean; + public autoSpeed: integer = 1; private phaseQueue: Array; private phaseQueuePrepend: Array; @@ -49,6 +51,8 @@ export default class BattleScene extends Phaser.Scene { private actionKey: Phaser.Input.Keyboard.Key; private cancelKey: Phaser.Input.Keyboard.Key; private f2Key: Phaser.Input.Keyboard.Key; + private plusKey: Phaser.Input.Keyboard.Key; + private minusKey: Phaser.Input.Keyboard.Key; private blockInput: boolean; @@ -293,11 +297,13 @@ export default class BattleScene extends Phaser.Scene { this.rightKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT); this.actionKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z); this.cancelKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.X); - this.f2Key = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.F2) + this.f2Key = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.F2); + this.plusKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.PLUS); + this.minusKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.MINUS); Promise.all(loadPokemonAssets).then(() => { - if (this.auto) - initAutoPlay.apply(this, [ this.autoSpeed ]); + if (enableAuto) + initAutoPlay.apply(this); this.pokeballCounts[PokeballType.POKEBALL] += 5; @@ -344,7 +350,7 @@ export default class BattleScene extends Phaser.Scene { } newBiome(): BiomeArena { - const biome = Utils.randInt(20) as Biome; + const biome = this.currentBattle ? Utils.randInt(20) as Biome : Biome.PLAINS; this.arena = new BiomeArena(this, biome, Biome[biome].toLowerCase()); return this.arena; } @@ -370,7 +376,18 @@ export default class BattleScene extends Phaser.Scene { this.ui.processInput(this.actionKey.keyCode); else if (this.cancelKey.isDown) this.ui.processInput(this.cancelKey.keyCode); - else + else if (enableAuto) { + if (this.f2Key.isDown) + this.auto = !this.auto; + else if (this.plusKey.isDown) { + if (this.autoSpeed < 20) + this.autoSpeed++; + } else if (this.minusKey.isDown) { + if (this.autoSpeed > 1) + this.autoSpeed--; + } + return; + } else return; this.blockInput = true; this.time.delayedCall(250, () => { diff --git a/src/biome.ts b/src/biome.ts index 1d42d7d3dfb..afaf94ea1ed 100644 --- a/src/biome.ts +++ b/src/biome.ts @@ -1754,12 +1754,12 @@ const biomePools = { ] ], [ Species.SLUGMA, Type.FIRE, -1, [ - [ Biome.MOUNTAIN, PoolTier.RARE ], + [ Biome.MOUNTAIN, PoolTier.UNCOMMON ], [ Biome.VOLCANO, PoolTier.COMMON ] ] ], [ Species.MAGCARGO, Type.FIRE, Type.ROCK, [ - [ Biome.MOUNTAIN, PoolTier.RARE ], + [ Biome.MOUNTAIN, PoolTier.UNCOMMON ], [ Biome.VOLCANO, PoolTier.COMMON ], [ Biome.VOLCANO, PoolTier.BOSS ] ] @@ -2511,8 +2511,8 @@ const biomePools = { ] ], [ Species.REGISTEEL, Type.STEEL, -1, [ - [ Biome.MOUNTAIN, PoolTier.ULTRA_RARE ], - [ Biome.MOUNTAIN, PoolTier.BOSS_SUPER_RARE ] + [ Biome.CAVE, PoolTier.ULTRA_RARE ], + [ Biome.CAVE, PoolTier.BOSS_SUPER_RARE ] ] ], [ Species.LATIAS, Type.DRAGON, Type.PSYCHIC, [ diff --git a/src/ui/modifier-select-ui-handler.ts b/src/ui/modifier-select-ui-handler.ts index 234ccbdf37c..e9456566924 100644 --- a/src/ui/modifier-select-ui-handler.ts +++ b/src/ui/modifier-select-ui-handler.ts @@ -90,12 +90,18 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { if (keyCode === keyCodes.Z) { success = true; - if (this.onActionInput) - this.onActionInput(this.cursor); + if (this.onActionInput) { + const originalOnActionInput = this.onActionInput; + this.onActionInput = null; + originalOnActionInput(this.cursor); + } } else if (keyCode === keyCodes.X) { success = true; - if (this.onActionInput) - this.onActionInput(-1); + if (this.onActionInput) { + const originalOnActionInput = this.onActionInput; + this.onActionInput = null; + originalOnActionInput(-1); + } } else { switch (keyCode) { case keyCodes.LEFT: diff --git a/src/ui/ui.ts b/src/ui/ui.ts index a7776cdc14a..ccf51b0eb58 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -119,7 +119,7 @@ export default class UI extends Phaser.GameObjects.Container { this.getHandler().show(args); resolve(); }; - if (transitionModes.indexOf(this.mode) > -1 || transitionModes.indexOf(mode) > -1) { + if ((transitionModes.indexOf(this.mode) > -1 || transitionModes.indexOf(mode) > -1) && !(this.scene as BattleScene).auto) { this.transitioning = true; this.overlay.setAlpha(0); this.overlay.setVisible(true);