From eab6d082fde115d27aaf8bf68d7b6ff2b56f27b7 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Wed, 18 Oct 2023 23:16:38 -0400 Subject: [PATCH] Add command cancelling and 2nd battler move memory --- src/battle-phases.ts | 17 ++++++++++++++- src/data/pokemon-species.ts | 1 + src/ui/command-ui-handler.ts | 7 +++--- src/ui/fight-ui-handler.ts | 42 +++++++++++++++++++++++++----------- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index bec3b3e51..914c6de2d 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -973,7 +973,7 @@ export class CommandPhase extends FieldPhase { this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.showText(`${move.getName()} is disabled!`, null, () => { this.scene.ui.clearText(); - this.scene.ui.setMode(Mode.FIGHT); + this.scene.ui.setMode(Mode.FIGHT, this.fieldIndex); }, null, true); } } @@ -1044,6 +1044,21 @@ export class CommandPhase extends FieldPhase { return success; } + cancel() { + if (this.fieldIndex) { + const lastCommand = this.scene.currentBattle.turnCommands[0]; + if (lastCommand.command === Command.BALL) + this.scene.currentBattle.turnPokeballCounts[lastCommand.cursor]++; + this.scene.unshiftPhase(new CommandPhase(this.scene, 0)); + this.scene.unshiftPhase(new CommandPhase(this.scene, 1)); + this.end(); + } + } + + getFieldIndex(): integer { + return this.fieldIndex; + } + getPokemon(): PlayerPokemon { return this.scene.getPlayerField()[this.fieldIndex]; } diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index 9e073fd8b..d440ac851 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -124,6 +124,7 @@ export abstract class PokemonSpeciesForm { case Species.MELOETTA: ret += this.getFormSpriteKey(formIndex).replace(/-/g, ''); break; + case Species.UNFEZANT: case Species.FRILLISH: case Species.JELLICENT: ret += !female ? 'm' : 'f'; diff --git a/src/ui/command-ui-handler.ts b/src/ui/command-ui-handler.ts index 7437192b0..d38df7de5 100644 --- a/src/ui/command-ui-handler.ts +++ b/src/ui/command-ui-handler.ts @@ -2,7 +2,7 @@ import { CommandPhase } from "../battle-phases"; import BattleScene, { Button } from "../battle-scene"; import { addTextObject, TextStyle } from "./text"; import PartyUiHandler, { PartyUiMode } from "./party-ui-handler"; -import UI, { Mode } from "./ui"; +import { Mode } from "./ui"; import UiHandler from "./uiHandler"; export enum Command { @@ -56,7 +56,7 @@ export default class CommandUiHandler extends UiHandler { if (button === Button.ACTION) { switch (this.cursor) { case 0: - ui.setMode(Mode.FIGHT); + ui.setMode(Mode.FIGHT, (this.scene.getCurrentPhase() as CommandPhase).getFieldIndex()); success = true; break; case 1: @@ -72,7 +72,8 @@ export default class CommandUiHandler extends UiHandler { success = true; break; } - } + } else + (this.scene.getCurrentPhase() as CommandPhase).cancel(); } else { switch (button) { case Button.UP: diff --git a/src/ui/fight-ui-handler.ts b/src/ui/fight-ui-handler.ts index 4a8efef99..edc721f5c 100644 --- a/src/ui/fight-ui-handler.ts +++ b/src/ui/fight-ui-handler.ts @@ -13,6 +13,9 @@ export default class FightUiHandler extends UiHandler { private ppText: Phaser.GameObjects.Text; private cursorObj: Phaser.GameObjects.Image; + protected fieldIndex: integer = 0; + protected cursor2: integer = 0; + constructor(scene: BattleScene) { super(scene, Mode.FIGHT); } @@ -36,9 +39,11 @@ export default class FightUiHandler extends UiHandler { show(args: any[]) { super.show(args); + this.fieldIndex = args.length ? args[0] as integer : 0; + const messageHandler = this.getUi().getMessageHandler(); messageHandler.bg.setTexture('bg_fight'); - this.setCursor(this.cursor); + this.setCursor(this.getCursor()); this.displayMoves(); } @@ -47,9 +52,11 @@ export default class FightUiHandler extends UiHandler { let success = false; + const cursor = this.getCursor(); + if (button === Button.CANCEL || button === Button.ACTION) { if (button === Button.ACTION) { - if ((this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, this.cursor, false)) + if ((this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, cursor, false)) success = true; else ui.playError(); @@ -60,20 +67,20 @@ export default class FightUiHandler extends UiHandler { } else { switch (button) { case Button.UP: - if (this.cursor >= 2) - success = this.setCursor(this.cursor - 2); + if (cursor >= 2) + success = this.setCursor(cursor - 2); break; case Button.DOWN: - if (this.cursor < 2) - success = this.setCursor(this.cursor + 2); + if (cursor < 2) + success = this.setCursor(cursor + 2); break; case Button.LEFT: - if (this.cursor % 2 === 1) - success = this.setCursor(this.cursor - 1); + if (cursor % 2 === 1) + success = this.setCursor(cursor - 1); break; case Button.RIGHT: - if (this.cursor % 2 === 0) - success = this.setCursor(this.cursor + 1); + if (cursor % 2 === 0) + success = this.setCursor(cursor + 1); break; } } @@ -82,9 +89,20 @@ export default class FightUiHandler extends UiHandler { ui.playSelect(); } + getCursor(): integer { + return !this.fieldIndex ? this.cursor : this.cursor2; + } + setCursor(cursor: integer): boolean { const ui = this.getUi(); - const ret = super.setCursor(cursor); + + const changed = this.getCursor() !== cursor; + if (changed) { + if (!this.fieldIndex) + this.cursor = cursor; + else + this.cursor2 = cursor; + } if (!this.cursorObj) { this.cursorObj = this.scene.add.image(0, 0, 'cursor'); @@ -110,7 +128,7 @@ export default class FightUiHandler extends UiHandler { this.cursorObj.setPosition(13 + (cursor % 2 === 1 ? 100 : 0), -31 + (cursor >= 2 ? 15 : 0)); - return ret; + return changed; } displayMoves() {