2023-05-18 16:11:06 +01:00
|
|
|
import BattleScene, { PokeballCounts } from "./battle-scene";
|
|
|
|
import { EnemyPokemon, PlayerPokemon, QueuedMove } from "./pokemon";
|
|
|
|
import { Command } from "./ui/command-ui-handler";
|
2023-03-31 21:04:39 +01:00
|
|
|
import * as Utils from "./utils";
|
2023-03-31 04:02:35 +01:00
|
|
|
|
2023-05-18 16:11:06 +01:00
|
|
|
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 {
|
2023-03-31 04:02:35 +01:00
|
|
|
public waveIndex: integer;
|
2023-05-18 16:11:06 +01:00
|
|
|
public enemyLevels: integer[];
|
|
|
|
public enemyField: EnemyPokemon[];
|
|
|
|
public double: boolean;
|
2023-04-22 00:30:04 +01:00
|
|
|
public turn: integer;
|
2023-05-18 16:11:06 +01:00
|
|
|
public turnCommands: TurnCommands;
|
|
|
|
public turnPokeballCounts: PokeballCounts;
|
2023-03-31 04:02:35 +01:00
|
|
|
public playerParticipantIds: Set<integer> = new Set<integer>();
|
2023-05-07 22:05:19 +01:00
|
|
|
public escapeAttempts: integer = 0;
|
2023-03-31 04:02:35 +01:00
|
|
|
|
2023-05-18 16:11:06 +01:00
|
|
|
constructor(waveIndex: integer, double: boolean) {
|
2023-03-31 04:02:35 +01:00
|
|
|
this.waveIndex = waveIndex;
|
2023-05-18 16:11:06 +01:00
|
|
|
this.enemyLevels = new Array(double ? 2 : 1).fill(null).map(() => this.getLevelForWave());
|
|
|
|
this.enemyField = [];
|
|
|
|
this.double = double;
|
|
|
|
this.turn = 0;
|
2023-03-31 04:02:35 +01:00
|
|
|
}
|
|
|
|
|
2023-03-31 21:04:39 +01:00
|
|
|
private getLevelForWave(): number {
|
2023-04-19 19:07:38 +01:00
|
|
|
let baseLevel = 1 + this.waveIndex / 2 + Math.pow(this.waveIndex / 25, 2);
|
2023-03-31 21:04:39 +01:00
|
|
|
|
2023-04-26 21:07:29 +01:00
|
|
|
if (!(this.waveIndex % 10)) {
|
2023-04-26 22:40:08 +01:00
|
|
|
if (this.waveIndex === 200)
|
|
|
|
return 200;
|
|
|
|
return Math.floor(baseLevel * 1.2);
|
2023-04-26 21:07:29 +01:00
|
|
|
}
|
2023-03-31 21:04:39 +01:00
|
|
|
|
|
|
|
const deviation = 10 / this.waveIndex;
|
|
|
|
|
2023-04-19 19:07:38 +01:00
|
|
|
return Math.max(Math.round(baseLevel + Math.abs(Utils.randGauss(deviation))), 1);
|
2023-03-31 21:04:39 +01:00
|
|
|
}
|
|
|
|
|
2023-05-18 16:11:06 +01:00
|
|
|
getBattlerCount(): integer {
|
|
|
|
return this.double ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
incrementTurn(scene: BattleScene): void {
|
2023-04-22 00:30:04 +01:00
|
|
|
this.turn++;
|
2023-05-18 16:11:06 +01:00
|
|
|
this.turnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [ bt, null ]));
|
|
|
|
this.turnPokeballCounts = Object.assign({}, scene.pokeballCounts);
|
2023-04-22 00:30:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-31 21:04:39 +01:00
|
|
|
addParticipant(playerPokemon: PlayerPokemon): void {
|
2023-03-31 04:02:35 +01:00
|
|
|
this.playerParticipantIds.add(playerPokemon.id);
|
|
|
|
}
|
|
|
|
|
2023-03-31 21:04:39 +01:00
|
|
|
removeFaintedParticipant(playerPokemon: PlayerPokemon): void {
|
2023-03-31 04:02:35 +01:00
|
|
|
this.playerParticipantIds.delete(playerPokemon.id);
|
|
|
|
}
|
|
|
|
}
|