pokerogue/src/battle.ts
Samuel H b9f7ba173d
Implement Double Battles (#1)
* Add WiP logic for double battles

* Minor changes for double battles

* More fixes for double battles

* Show battle info for both in double battles

* Improvements to double battles

* Add double battle version of party UI

* Fix some issues with double battles

* Updates to double battles

* More work on double battles for stability

* Fix issues with ability bar and evolution screen

* Add chance for double battles
2023-05-18 11:11:06 -04:00

75 lines
2.1 KiB
TypeScript

import BattleScene, { PokeballCounts } from "./battle-scene";
import { EnemyPokemon, PlayerPokemon, QueuedMove } from "./pokemon";
import { Command } from "./ui/command-ui-handler";
import * as Utils from "./utils";
export enum BattlerIndex {
PLAYER,
PLAYER_2,
ENEMY,
ENEMY_2
}
export interface TurnCommand {
command: Command;
cursor?: integer;
move?: QueuedMove;
targets?: BattlerIndex[];
args?: any[];
};
interface TurnCommands {
[key: integer]: TurnCommand
}
export default class Battle {
public waveIndex: integer;
public enemyLevels: integer[];
public enemyField: EnemyPokemon[];
public double: boolean;
public turn: integer;
public turnCommands: TurnCommands;
public turnPokeballCounts: PokeballCounts;
public playerParticipantIds: Set<integer> = new Set<integer>();
public escapeAttempts: integer = 0;
constructor(waveIndex: integer, double: boolean) {
this.waveIndex = waveIndex;
this.enemyLevels = new Array(double ? 2 : 1).fill(null).map(() => this.getLevelForWave());
this.enemyField = [];
this.double = double;
this.turn = 0;
}
private getLevelForWave(): number {
let baseLevel = 1 + this.waveIndex / 2 + Math.pow(this.waveIndex / 25, 2);
if (!(this.waveIndex % 10)) {
if (this.waveIndex === 200)
return 200;
return Math.floor(baseLevel * 1.2);
}
const deviation = 10 / this.waveIndex;
return Math.max(Math.round(baseLevel + Math.abs(Utils.randGauss(deviation))), 1);
}
getBattlerCount(): integer {
return this.double ? 2 : 1;
}
incrementTurn(scene: BattleScene): void {
this.turn++;
this.turnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [ bt, null ]));
this.turnPokeballCounts = Object.assign({}, scene.pokeballCounts);
}
addParticipant(playerPokemon: PlayerPokemon): void {
this.playerParticipantIds.add(playerPokemon.id);
}
removeFaintedParticipant(playerPokemon: PlayerPokemon): void {
this.playerParticipantIds.delete(playerPokemon.id);
}
}