pokerogue/src/battle.ts

85 lines
2.5 KiB
TypeScript
Raw Normal View History

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