Changes to autoplay mode

pull/1/head
Flashfyre 2023-04-09 00:22:14 -04:00
parent 8bacb9bc84
commit 4ec91695f7
6 changed files with 128 additions and 77 deletions

View File

@ -13,36 +13,43 @@ import PartyUiHandler, { PartyUiMode } from "./ui/party-ui-handler";
import ConfirmUiHandler from "./ui/confirm-ui-handler"; import ConfirmUiHandler from "./ui/confirm-ui-handler";
import { Mode } from "./ui/ui"; import { Mode } from "./ui/ui";
export function initAutoPlay(speed: number) { export function initAutoPlay() {
const thisArg = this as BattleScene; const thisArg = this as BattleScene;
const originalDelayedCall = this.time.delayedCall; const originalDelayedCall = this.time.delayedCall;
this.time.delayedCall = function (delay: number, callback: Function, args?: any[], callbackScope?: any) { 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 ]); originalDelayedCall.apply(this, [ delay, callback, args, callbackScope ]);
}; };
const originalAddEvent = this.time.addEvent; const originalAddEvent = this.time.addEvent;
this.time.addEvent = function (config: Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig) { this.time.addEvent = function (config: Phaser.Time.TimerEvent | Phaser.Types.Time.TimerEventConfig) {
if (config.delay) if (thisArg.auto) {
config.delay = Math.ceil(config.delay / speed); if (config.delay)
if (config.startAt) config.delay = Math.ceil(config.delay / thisArg.autoSpeed);
config.startAt = Math.ceil(config.startAt / speed); if (config.startAt)
config.startAt = Math.ceil(config.startAt / thisArg.autoSpeed);
}
return originalAddEvent.apply(this, [ config ]); return originalAddEvent.apply(this, [ config ]);
}; };
const originalTweensAdd = this.tweens.add; const originalTweensAdd = this.tweens.add;
this.tweens.add = function (config: Phaser.Types.Tweens.TweenBuilderConfig | object) { this.tweens.add = function (config: Phaser.Types.Tweens.TweenBuilderConfig | object) {
if (config.duration) if (thisArg.auto) {
config.duration = Math.ceil(config.duration / speed); if (config.duration)
if (config.delay) config.duration = Math.ceil(config.duration / thisArg.autoSpeed);
config.delay = Math.ceil(config.delay / speed); if (config.delay)
config.delay = Math.ceil(config.delay / thisArg.autoSpeed);
}
return originalTweensAdd.apply(this, [ config ]); return originalTweensAdd.apply(this, [ config ]);
}; };
const originalAddCounter = this.tweens.addCounter; const originalAddCounter = this.tweens.addCounter;
this.tweens.addCounter = function (config: Phaser.Types.Tweens.NumberTweenBuilderConfig) { this.tweens.addCounter = function (config: Phaser.Types.Tweens.NumberTweenBuilderConfig) {
if (config.duration) if (thisArg.auto) {
config.duration = Math.ceil(config.duration / speed); if (config.duration)
if (config.delay) config.duration = Math.ceil(config.duration / thisArg.autoSpeed);
config.delay = Math.ceil(config.delay / speed); if (config.delay)
config.delay = Math.ceil(config.delay / thisArg.autoSpeed);
}
return originalAddCounter.apply(this, [ config ]); return originalAddCounter.apply(this, [ config ]);
}; };
@ -68,12 +75,15 @@ export function initAutoPlay(speed: number) {
const pokemon = party[p]; const pokemon = party[p];
if (pokemon.getHpRatio() <= 0.4) if (pokemon.getHpRatio() <= 0.4)
continue; continue;
const effectiveness = getMaxMoveEffectiveness(pokemon, enemyPokemon) / getMaxMoveEffectiveness(enemyPokemon, pokemon); const effectiveness = enemyPokemon
? getMaxMoveEffectiveness(pokemon, enemyPokemon) / getMaxMoveEffectiveness(enemyPokemon, pokemon)
: 1;
if (effectiveness > bestPartyMemberEffectiveness) { if (effectiveness > bestPartyMemberEffectiveness) {
bestPartyMemberIndex = p; bestPartyMemberIndex = p;
bestPartyMemberEffectiveness = effectiveness; 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) { if (bestPartyMemberIndex === -1) {
@ -108,80 +118,93 @@ export function initAutoPlay(speed: number) {
const originalMessageUiHandlerShowText = MessageUiHandler.prototype.showText; const originalMessageUiHandlerShowText = MessageUiHandler.prototype.showText;
MessageUiHandler.prototype.showText = function (text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean) { MessageUiHandler.prototype.showText = function (text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean) {
delay = 0; if (thisArg.auto) {
callbackDelay = 0; delay = 1;
callbackDelay = 0;
}
originalMessageUiHandlerShowText.apply(this, [ text, delay, callback, callbackDelay, prompt ]); originalMessageUiHandlerShowText.apply(this, [ text, delay, callback, callbackDelay, prompt ]);
}; };
const originalMessageUiHandlerShowPrompt = MessageUiHandler.prototype.showPrompt; const originalMessageUiHandlerShowPrompt = MessageUiHandler.prototype.showPrompt;
MessageUiHandler.prototype.showPrompt = function (callback: Function, callbackDelay: integer) { MessageUiHandler.prototype.showPrompt = function (callback: Function, callbackDelay: integer) {
callbackDelay = 0; if (thisArg.auto)
callbackDelay = 0;
originalMessageUiHandlerShowPrompt.apply(this, [ callback, callbackDelay ]); 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; const originalMessageUiHandlerPromptLevelUpStats = messageUiHandler.promptLevelUpStats;
messageUiHandler.promptLevelUpStats = function (prevStats: integer[], showTotals: boolean, callback?: Function) { messageUiHandler.promptLevelUpStats = function (prevStats: integer[], showTotals: boolean, callback?: Function) {
originalMessageUiHandlerPromptLevelUpStats.apply(this, [ prevStats, showTotals, callback ]); 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; const originalCommandUiHandlerShow = commandUiHandler.show;
commandUiHandler.show = function (args: any[]) { commandUiHandler.show = function (args: any[]) {
originalCommandUiHandlerShow.apply(this, [ args ]); originalCommandUiHandlerShow.apply(this, [ args ]);
thisArg.time.delayedCall(20, () => { if (thisArg.auto) {
const bestPartyMemberIndex = getBestPartyMemberIndex(); thisArg.time.delayedCall(20, () => {
if (bestPartyMemberIndex) { const bestPartyMemberIndex = getBestPartyMemberIndex();
console.log(bestPartyMemberIndex, thisArg.getParty()) if (bestPartyMemberIndex) {
console.log('Switching to ', Species[thisArg.getParty()[bestPartyMemberIndex].species.speciesId]); console.log(bestPartyMemberIndex, thisArg.getParty())
nextPartyMemberIndex = bestPartyMemberIndex; console.log('Switching to ', Species[thisArg.getParty()[bestPartyMemberIndex].species.speciesId]);
commandUiHandler.setCursor(2); nextPartyMemberIndex = bestPartyMemberIndex;
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); commandUiHandler.setCursor(2);
} else { thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
commandUiHandler.setCursor(0); } else {
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); commandUiHandler.setCursor(0);
} thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
}); }
});
}
}; };
const originalFightUiHandlerShow = fightUiHandler.show; const originalFightUiHandlerShow = fightUiHandler.show;
fightUiHandler.show = function (args: any[]) { fightUiHandler.show = function (args: any[]) {
originalFightUiHandlerShow.apply(this, [ args ]); originalFightUiHandlerShow.apply(this, [ args ]);
if (!playerPokemon.aiType) if (thisArg.auto) {
playerPokemon.aiType = AiType.SMART; if (!playerPokemon.aiType)
thisArg.time.delayedCall(20, () => { playerPokemon.aiType = AiType.SMART;
const nextMove = playerPokemon.getNextMove() as PokemonMove; thisArg.time.delayedCall(20, () => {
fightUiHandler.setCursor(playerPokemon.moveset.indexOf(nextMove)); const nextMove = playerPokemon.getNextMove() as PokemonMove;
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); fightUiHandler.setCursor(playerPokemon.moveset.indexOf(nextMove));
}); thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
});
}
}; };
const originalPartyUiHandlerShow = partyUiHandler.show; const originalPartyUiHandlerShow = partyUiHandler.show;
partyUiHandler.show = function (args: any[]) { partyUiHandler.show = function (args: any[]) {
originalPartyUiHandlerShow.apply(this, [ args ]); originalPartyUiHandlerShow.apply(this, [ args ]);
thisArg.time.delayedCall(20, () => { if (thisArg.auto) {
if (nextPartyMemberIndex === -1) thisArg.time.delayedCall(20, () => {
nextPartyMemberIndex = getBestPartyMemberIndex(); if (nextPartyMemberIndex === -1)
partyUiHandler.setCursor(nextPartyMemberIndex); nextPartyMemberIndex = getBestPartyMemberIndex();
nextPartyMemberIndex = -1; partyUiHandler.setCursor(nextPartyMemberIndex);
if (partyUiHandler.partyUiMode === PartyUiMode.MODIFIER || partyUiHandler.getCursor()) { nextPartyMemberIndex = -1;
this.processInput(keyCodes.Z); if (partyUiHandler.partyUiMode === PartyUiMode.MODIFIER || partyUiHandler.getCursor()) {
this.processInput(keyCodes.Z); this.processInput(keyCodes.Z);
} else thisArg.time.delayedCall(250, () => this.processInput(keyCodes.Z));
this.processInput(keyCodes.X); } else
}); this.processInput(keyCodes.X);
});
}
}; };
const originalSwitchCheckUiHandlerShow = switchCheckUiHandler.show; const originalSwitchCheckUiHandlerShow = switchCheckUiHandler.show;
switchCheckUiHandler.show = function (args: any[]) { switchCheckUiHandler.show = function (args: any[]) {
originalSwitchCheckUiHandlerShow.apply(this, [ args ]); originalSwitchCheckUiHandlerShow.apply(this, [ args ]);
const bestPartyMemberIndex = getBestPartyMemberIndex(); if (thisArg.auto) {
thisArg.time.delayedCall(20, () => { const bestPartyMemberIndex = getBestPartyMemberIndex();
if (bestPartyMemberIndex) thisArg.time.delayedCall(20, () => {
nextPartyMemberIndex = bestPartyMemberIndex; if (bestPartyMemberIndex)
switchCheckUiHandler.setCursor(bestPartyMemberIndex ? 1 : 0); nextPartyMemberIndex = bestPartyMemberIndex;
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z)); switchCheckUiHandler.setCursor(bestPartyMemberIndex ? 1 : 0);
}); thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
});
}
} }
const tryGetBestModifier = (modifierTypes: Array<ModifierType>, predicate: Function) => { const tryGetBestModifier = (modifierTypes: Array<ModifierType>, predicate: Function) => {
@ -197,6 +220,11 @@ export function initAutoPlay(speed: number) {
const originalModifierSelectUiHandlerShow = modifierSelectUiHandler.show; const originalModifierSelectUiHandlerShow = modifierSelectUiHandler.show;
modifierSelectUiHandler.show = function (args: any[]) { modifierSelectUiHandler.show = function (args: any[]) {
if (!thisArg.auto) {
originalModifierSelectUiHandlerShow.apply(this, [ args ]);
return;
}
if (modifierSelectUiHandler.active) if (modifierSelectUiHandler.active)
return; return;
@ -262,7 +290,7 @@ export function initAutoPlay(speed: number) {
if (thisArg.getCurrentPhase() instanceof SelectModifierPhase) { if (thisArg.getCurrentPhase() instanceof SelectModifierPhase) {
if (optionIndex < modifierSelectUiHandler.options.length - 1) { if (optionIndex < modifierSelectUiHandler.options.length - 1) {
optionIndex++; optionIndex++;
trySelectModifier(); thisArg.time.delayedCall(250, () => trySelectModifier());
} else } else
modifierSelectUiHandler.processInput(keyCodes.X); modifierSelectUiHandler.processInput(keyCodes.X);
} }

View File

@ -21,7 +21,7 @@ export class BattlePhase {
} }
start() { start() {
console.log(`Start Phase ${this.constructor.name}`) console.log(`%cStart Phase ${this.constructor.name}`, 'color:green;')
} }
end() { end() {

View File

@ -12,9 +12,11 @@ import { initAutoPlay } from './auto-play';
import { Battle } from './battle'; import { Battle } from './battle';
import { populateAnims } from './battle-anims'; import { populateAnims } from './battle-anims';
const enableAuto = true;
export default class BattleScene extends Phaser.Scene { export default class BattleScene extends Phaser.Scene {
private auto: boolean = true; public auto: boolean;
private autoSpeed: integer = 1; public autoSpeed: integer = 1;
private phaseQueue: Array<BattlePhase>; private phaseQueue: Array<BattlePhase>;
private phaseQueuePrepend: Array<BattlePhase>; private phaseQueuePrepend: Array<BattlePhase>;
@ -49,6 +51,8 @@ export default class BattleScene extends Phaser.Scene {
private actionKey: Phaser.Input.Keyboard.Key; private actionKey: Phaser.Input.Keyboard.Key;
private cancelKey: Phaser.Input.Keyboard.Key; private cancelKey: Phaser.Input.Keyboard.Key;
private f2Key: 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; 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.rightKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
this.actionKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z); this.actionKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z);
this.cancelKey = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.X); 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(() => { Promise.all(loadPokemonAssets).then(() => {
if (this.auto) if (enableAuto)
initAutoPlay.apply(this, [ this.autoSpeed ]); initAutoPlay.apply(this);
this.pokeballCounts[PokeballType.POKEBALL] += 5; this.pokeballCounts[PokeballType.POKEBALL] += 5;
@ -344,7 +350,7 @@ export default class BattleScene extends Phaser.Scene {
} }
newBiome(): BiomeArena { 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()); this.arena = new BiomeArena(this, biome, Biome[biome].toLowerCase());
return this.arena; return this.arena;
} }
@ -370,7 +376,18 @@ export default class BattleScene extends Phaser.Scene {
this.ui.processInput(this.actionKey.keyCode); this.ui.processInput(this.actionKey.keyCode);
else if (this.cancelKey.isDown) else if (this.cancelKey.isDown)
this.ui.processInput(this.cancelKey.keyCode); 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; return;
this.blockInput = true; this.blockInput = true;
this.time.delayedCall(250, () => { this.time.delayedCall(250, () => {

View File

@ -1754,12 +1754,12 @@ const biomePools = {
] ]
], ],
[ Species.SLUGMA, Type.FIRE, -1, [ [ Species.SLUGMA, Type.FIRE, -1, [
[ Biome.MOUNTAIN, PoolTier.RARE ], [ Biome.MOUNTAIN, PoolTier.UNCOMMON ],
[ Biome.VOLCANO, PoolTier.COMMON ] [ Biome.VOLCANO, PoolTier.COMMON ]
] ]
], ],
[ Species.MAGCARGO, Type.FIRE, Type.ROCK, [ [ Species.MAGCARGO, Type.FIRE, Type.ROCK, [
[ Biome.MOUNTAIN, PoolTier.RARE ], [ Biome.MOUNTAIN, PoolTier.UNCOMMON ],
[ Biome.VOLCANO, PoolTier.COMMON ], [ Biome.VOLCANO, PoolTier.COMMON ],
[ Biome.VOLCANO, PoolTier.BOSS ] [ Biome.VOLCANO, PoolTier.BOSS ]
] ]
@ -2511,8 +2511,8 @@ const biomePools = {
] ]
], ],
[ Species.REGISTEEL, Type.STEEL, -1, [ [ Species.REGISTEEL, Type.STEEL, -1, [
[ Biome.MOUNTAIN, PoolTier.ULTRA_RARE ], [ Biome.CAVE, PoolTier.ULTRA_RARE ],
[ Biome.MOUNTAIN, PoolTier.BOSS_SUPER_RARE ] [ Biome.CAVE, PoolTier.BOSS_SUPER_RARE ]
] ]
], ],
[ Species.LATIAS, Type.DRAGON, Type.PSYCHIC, [ [ Species.LATIAS, Type.DRAGON, Type.PSYCHIC, [

View File

@ -90,12 +90,18 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
if (keyCode === keyCodes.Z) { if (keyCode === keyCodes.Z) {
success = true; success = true;
if (this.onActionInput) if (this.onActionInput) {
this.onActionInput(this.cursor); const originalOnActionInput = this.onActionInput;
this.onActionInput = null;
originalOnActionInput(this.cursor);
}
} else if (keyCode === keyCodes.X) { } else if (keyCode === keyCodes.X) {
success = true; success = true;
if (this.onActionInput) if (this.onActionInput) {
this.onActionInput(-1); const originalOnActionInput = this.onActionInput;
this.onActionInput = null;
originalOnActionInput(-1);
}
} else { } else {
switch (keyCode) { switch (keyCode) {
case keyCodes.LEFT: case keyCodes.LEFT:

View File

@ -119,7 +119,7 @@ export default class UI extends Phaser.GameObjects.Container {
this.getHandler().show(args); this.getHandler().show(args);
resolve(); 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.transitioning = true;
this.overlay.setAlpha(0); this.overlay.setAlpha(0);
this.overlay.setVisible(true); this.overlay.setVisible(true);