Update implementation of Pokeball and run commands

pull/2/head
Flashfyre 2023-10-27 17:43:53 -04:00
parent 970d014bfd
commit cc435284ec
3 changed files with 39 additions and 18 deletions

View File

@ -937,6 +937,15 @@ export class CommandPhase extends FieldPhase {
start() { start() {
super.start(); super.start();
if (this.fieldIndex) {
const allyCommand = this.scene.currentBattle.turnCommands[this.fieldIndex - 1];
if (allyCommand.command === Command.BALL || allyCommand.command === Command.RUN)
this.scene.currentBattle.turnCommands[this.fieldIndex] = { command: allyCommand.command, skip: true };
}
if (this.scene.currentBattle.turnCommands[this.fieldIndex]?.skip)
return this.end();
const playerPokemon = this.scene.getPlayerField()[this.fieldIndex]; const playerPokemon = this.scene.getPlayerField()[this.fieldIndex];
const moveQueue = playerPokemon.getMoveQueue(); const moveQueue = playerPokemon.getMoveQueue();
@ -1007,15 +1016,26 @@ export class CommandPhase extends FieldPhase {
this.scene.ui.showText(null, 0); this.scene.ui.showText(null, 0);
this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex);
}, null, true); }, null, true);
} else if (cursor < 4) { } else {
const targets = this.scene.getEnemyField().filter(p => p.isActive(true)).map(p => p.getBattlerIndex()); const targets = this.scene.getEnemyField().filter(p => p.isActive(true)).map(p => p.getBattlerIndex());
this.scene.currentBattle.turnCommands[this.fieldIndex] = { command: Command.BALL, cursor: cursor }; if (targets.length > 1) {
this.scene.currentBattle.turnPokeballCounts[cursor as PokeballType]--; this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex);
if (targets.length > 1) this.scene.ui.setMode(Mode.MESSAGE);
this.scene.unshiftPhase(new SelectTargetPhase(this.scene, this.fieldIndex)); this.scene.ui.showText(`You can only throw a Poké Ball\nwhen there is one Pokémon remaining!`, null, () => {
else this.scene.ui.showText(null, 0);
this.scene.currentBattle.turnCommands[this.fieldIndex].targets = targets; this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex);
success = true; }, null, true);
} else if (cursor < 4) {
this.scene.currentBattle.turnCommands[this.fieldIndex] = { command: Command.BALL, cursor: cursor };
if (targets.length > 1)
this.scene.unshiftPhase(new SelectTargetPhase(this.scene, this.fieldIndex));
else {
this.scene.currentBattle.turnCommands[this.fieldIndex].targets = targets;
if (this.fieldIndex)
this.scene.currentBattle.turnCommands[this.fieldIndex - 1].skip = true;
}
success = true;
}
} }
break; break;
case Command.POKEMON: case Command.POKEMON:
@ -1039,6 +1059,8 @@ export class CommandPhase extends FieldPhase {
? { command: Command.POKEMON, cursor: cursor, args: args } ? { command: Command.POKEMON, cursor: cursor, args: args }
: { command: Command.RUN }; : { command: Command.RUN };
success = true; success = true;
if (this.fieldIndex)
this.scene.currentBattle.turnCommands[this.fieldIndex - 1].skip = true;
} else if (trapTag) { } else if (trapTag) {
this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex);
this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.setMode(Mode.MESSAGE);
@ -1059,9 +1081,6 @@ export class CommandPhase extends FieldPhase {
cancel() { cancel() {
if (this.fieldIndex) { 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, 0));
this.scene.unshiftPhase(new CommandPhase(this.scene, 1)); this.scene.unshiftPhase(new CommandPhase(this.scene, 1));
this.end(); this.end();
@ -1117,12 +1136,12 @@ export class SelectTargetPhase extends PokemonPhase {
this.scene.ui.setMode(Mode.TARGET_SELECT, this.fieldIndex, move, (cursor: integer) => { this.scene.ui.setMode(Mode.TARGET_SELECT, this.fieldIndex, move, (cursor: integer) => {
this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.setMode(Mode.MESSAGE);
if (cursor === -1) { if (cursor === -1) {
if (turnCommand.command === Command.BALL)
this.scene.currentBattle.turnPokeballCounts[turnCommand.cursor]++;
this.scene.currentBattle.turnCommands[this.fieldIndex] = null; this.scene.currentBattle.turnCommands[this.fieldIndex] = null;
this.scene.unshiftPhase(new CommandPhase(this.scene, this.fieldIndex)); this.scene.unshiftPhase(new CommandPhase(this.scene, this.fieldIndex));
} else } else
turnCommand.targets = [ cursor ]; turnCommand.targets = [ cursor ];
if (this.scene.currentBattle.turnCommands[this.fieldIndex].command === Command.BALL && this.fieldIndex)
this.scene.currentBattle.turnCommands[this.fieldIndex - 1].skip = true;
this.end(); this.end();
}); });
} }
@ -1169,6 +1188,9 @@ export class TurnStartPhase extends FieldPhase {
const pokemon = field[o]; const pokemon = field[o];
const turnCommand = this.scene.currentBattle.turnCommands[o]; const turnCommand = this.scene.currentBattle.turnCommands[o];
if (turnCommand.skip)
continue;
switch (turnCommand.command) { switch (turnCommand.command) {
case Command.FIGHT: case Command.FIGHT:
const queuedMove = turnCommand.move; const queuedMove = turnCommand.move;

View File

@ -24,6 +24,7 @@ export interface TurnCommand {
cursor?: integer; cursor?: integer;
move?: QueuedMove; move?: QueuedMove;
targets?: BattlerIndex[]; targets?: BattlerIndex[];
skip?: boolean;
args?: any[]; args?: any[];
}; };
@ -42,7 +43,6 @@ export default class Battle {
public started: boolean; public started: boolean;
public turn: integer; public turn: integer;
public turnCommands: TurnCommands; public turnCommands: TurnCommands;
public turnPokeballCounts: PokeballCounts;
public playerParticipantIds: Set<integer> = new Set<integer>(); public playerParticipantIds: Set<integer> = new Set<integer>();
public escapeAttempts: integer = 0; public escapeAttempts: integer = 0;
public lastMove: Moves; public lastMove: Moves;
@ -94,7 +94,6 @@ export default class Battle {
incrementTurn(scene: BattleScene): void { incrementTurn(scene: BattleScene): void {
this.turn++; this.turn++;
this.turnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [ bt, null ])); this.turnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [ bt, null ]));
this.turnPokeballCounts = Object.assign({}, scene.pokeballCounts);
} }
addParticipant(playerPokemon: PlayerPokemon): void { addParticipant(playerPokemon: PlayerPokemon): void {

View File

@ -60,13 +60,13 @@ export default class BallUiHandler extends UiHandler {
let success = false; let success = false;
const pokeballTypeCount = Object.keys(this.scene.currentBattle.turnPokeballCounts).length; const pokeballTypeCount = Object.keys(this.scene.pokeballCounts).length;
if (button === Button.ACTION || button === Button.CANCEL) { if (button === Button.ACTION || button === Button.CANCEL) {
const commandPhase = this.scene.getCurrentPhase() as CommandPhase; const commandPhase = this.scene.getCurrentPhase() as CommandPhase;
success = true; success = true;
if (button === Button.ACTION && this.cursor < pokeballTypeCount) { if (button === Button.ACTION && this.cursor < pokeballTypeCount) {
if (this.scene.currentBattle.turnPokeballCounts[this.cursor]) { if (this.scene.pokeballCounts[this.cursor]) {
if (commandPhase.handleCommand(Command.BALL, this.cursor)) { if (commandPhase.handleCommand(Command.BALL, this.cursor)) {
this.scene.ui.setMode(Mode.COMMAND, commandPhase.getFieldIndex()); this.scene.ui.setMode(Mode.COMMAND, commandPhase.getFieldIndex());
this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.setMode(Mode.MESSAGE);
@ -94,7 +94,7 @@ export default class BallUiHandler extends UiHandler {
} }
updateCounts() { updateCounts() {
this.countsText.setText(Object.values(this.scene.currentBattle.turnPokeballCounts).map(c => `x${c}`).join('\n')); this.countsText.setText(Object.values(this.scene.pokeballCounts).map(c => `x${c}`).join('\n'));
} }
setCursor(cursor: integer): boolean { setCursor(cursor: integer): boolean {