Changes to autoplay mode

This commit is contained in:
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 { 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 (thisArg.auto) {
if (config.delay)
config.delay = Math.ceil(config.delay / speed);
config.delay = Math.ceil(config.delay / thisArg.autoSpeed);
if (config.startAt)
config.startAt = Math.ceil(config.startAt / speed);
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 (thisArg.auto) {
if (config.duration)
config.duration = Math.ceil(config.duration / speed);
config.duration = Math.ceil(config.duration / thisArg.autoSpeed);
if (config.delay)
config.delay = Math.ceil(config.delay / speed);
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 (thisArg.auto) {
if (config.duration)
config.duration = Math.ceil(config.duration / speed);
config.duration = Math.ceil(config.duration / thisArg.autoSpeed);
if (config.delay)
config.delay = Math.ceil(config.delay / speed);
config.delay = Math.ceil(config.delay / thisArg.autoSpeed);
}
return originalAddCounter.apply(this, [ config ]);
};
@ -68,11 +75,14 @@ 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;
}
if (enemyPokemon)
console.log(p, Species[pokemon.species.speciesId], '->', Species[enemyPokemon.species.speciesId], effectiveness);
}
@ -108,27 +118,33 @@ 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;
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) {
if (thisArg.auto)
callbackDelay = 0;
originalMessageUiHandlerShowPrompt.apply(this, [ callback, callbackDelay ]);
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 ]);
if (thisArg.auto) {
thisArg.time.delayedCall(20, () => {
const bestPartyMemberIndex = getBestPartyMemberIndex();
if (bestPartyMemberIndex) {
@ -142,11 +158,13 @@ export function initAutoPlay(speed: number) {
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
}
});
}
};
const originalFightUiHandlerShow = fightUiHandler.show;
fightUiHandler.show = function (args: any[]) {
originalFightUiHandlerShow.apply(this, [ args ]);
if (thisArg.auto) {
if (!playerPokemon.aiType)
playerPokemon.aiType = AiType.SMART;
thisArg.time.delayedCall(20, () => {
@ -154,11 +172,13 @@ export function initAutoPlay(speed: number) {
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 ]);
if (thisArg.auto) {
thisArg.time.delayedCall(20, () => {
if (nextPartyMemberIndex === -1)
nextPartyMemberIndex = getBestPartyMemberIndex();
@ -166,15 +186,17 @@ export function initAutoPlay(speed: number) {
nextPartyMemberIndex = -1;
if (partyUiHandler.partyUiMode === PartyUiMode.MODIFIER || partyUiHandler.getCursor()) {
this.processInput(keyCodes.Z);
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 ]);
if (thisArg.auto) {
const bestPartyMemberIndex = getBestPartyMemberIndex();
thisArg.time.delayedCall(20, () => {
if (bestPartyMemberIndex)
@ -183,6 +205,7 @@ export function initAutoPlay(speed: number) {
thisArg.time.delayedCall(20, () => this.processInput(keyCodes.Z));
});
}
}
const tryGetBestModifier = (modifierTypes: Array<ModifierType>, predicate: Function) => {
for (let mt = 0; mt < modifierTypes.length; mt++) {
@ -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);
}

View File

@ -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() {

View File

@ -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<BattlePhase>;
private phaseQueuePrepend: Array<BattlePhase>;
@ -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, () => {

View File

@ -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, [

View File

@ -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:

View File

@ -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);