2023-05-18 11:11:06 -04:00
|
|
|
import BattleScene, { PokeballCounts } from "./battle-scene";
|
|
|
|
import { EnemyPokemon, PlayerPokemon, QueuedMove } from "./pokemon";
|
|
|
|
import { Command } from "./ui/command-ui-handler";
|
2023-03-31 16:04:39 -04:00
|
|
|
import * as Utils from "./utils";
|
2023-10-07 16:08:33 -04:00
|
|
|
import Trainer from "./trainer";
|
2023-10-09 20:20:02 -04:00
|
|
|
import { Species } from "./data/species";
|
|
|
|
import { Moves } from "./data/move";
|
|
|
|
import { TrainerType } from "./data/trainer-type";
|
2023-10-07 16:08:33 -04:00
|
|
|
|
|
|
|
export enum BattleType {
|
|
|
|
WILD,
|
|
|
|
TRAINER
|
|
|
|
}
|
2023-03-30 23:02:35 -04:00
|
|
|
|
2023-05-18 11:11:06 -04: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 23:02:35 -04:00
|
|
|
public waveIndex: integer;
|
2023-10-07 16:08:33 -04:00
|
|
|
public battleType: BattleType;
|
|
|
|
public trainer: Trainer;
|
2023-05-18 11:11:06 -04:00
|
|
|
public enemyLevels: integer[];
|
2023-10-07 16:08:33 -04:00
|
|
|
public enemyParty: EnemyPokemon[];
|
2023-05-18 11:11:06 -04:00
|
|
|
public double: boolean;
|
2023-04-21 19:30:04 -04:00
|
|
|
public turn: integer;
|
2023-05-18 11:11:06 -04:00
|
|
|
public turnCommands: TurnCommands;
|
|
|
|
public turnPokeballCounts: PokeballCounts;
|
2023-03-30 23:02:35 -04:00
|
|
|
public playerParticipantIds: Set<integer> = new Set<integer>();
|
2023-05-07 17:05:19 -04:00
|
|
|
public escapeAttempts: integer = 0;
|
2023-10-09 20:20:02 -04:00
|
|
|
public lastMove: Moves;
|
2023-03-30 23:02:35 -04:00
|
|
|
|
2023-10-07 16:08:33 -04:00
|
|
|
constructor(waveIndex: integer, battleType: BattleType, trainer: Trainer, double: boolean) {
|
2023-03-30 23:02:35 -04:00
|
|
|
this.waveIndex = waveIndex;
|
2023-10-07 16:08:33 -04: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 = [];
|
2023-05-18 11:11:06 -04:00
|
|
|
this.double = double;
|
|
|
|
this.turn = 0;
|
2023-03-30 23:02:35 -04:00
|
|
|
}
|
|
|
|
|
2023-10-07 16:08:33 -04:00
|
|
|
private getLevelForWave(): integer {
|
2023-04-19 14:07:38 -04:00
|
|
|
let baseLevel = 1 + this.waveIndex / 2 + Math.pow(this.waveIndex / 25, 2);
|
2023-03-31 16:04:39 -04:00
|
|
|
|
2023-04-26 16:07:29 -04:00
|
|
|
if (!(this.waveIndex % 10)) {
|
2023-04-26 17:40:08 -04:00
|
|
|
if (this.waveIndex === 200)
|
|
|
|
return 200;
|
|
|
|
return Math.floor(baseLevel * 1.2);
|
2023-04-26 16:07:29 -04:00
|
|
|
}
|
2023-03-31 16:04:39 -04:00
|
|
|
|
|
|
|
const deviation = 10 / this.waveIndex;
|
|
|
|
|
2023-04-19 14:07:38 -04:00
|
|
|
return Math.max(Math.round(baseLevel + Math.abs(Utils.randGauss(deviation))), 1);
|
2023-03-31 16:04:39 -04:00
|
|
|
}
|
|
|
|
|
2023-05-18 11:11:06 -04:00
|
|
|
getBattlerCount(): integer {
|
|
|
|
return this.double ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
incrementTurn(scene: BattleScene): void {
|
2023-04-21 19:30:04 -04:00
|
|
|
this.turn++;
|
2023-05-18 11:11:06 -04:00
|
|
|
this.turnCommands = Object.fromEntries(Utils.getEnumValues(BattlerIndex).map(bt => [ bt, null ]));
|
|
|
|
this.turnPokeballCounts = Object.assign({}, scene.pokeballCounts);
|
2023-04-21 19:30:04 -04:00
|
|
|
}
|
|
|
|
|
2023-03-31 16:04:39 -04:00
|
|
|
addParticipant(playerPokemon: PlayerPokemon): void {
|
2023-03-30 23:02:35 -04:00
|
|
|
this.playerParticipantIds.add(playerPokemon.id);
|
|
|
|
}
|
|
|
|
|
2023-03-31 16:04:39 -04:00
|
|
|
removeFaintedParticipant(playerPokemon: PlayerPokemon): void {
|
2023-03-30 23:02:35 -04:00
|
|
|
this.playerParticipantIds.delete(playerPokemon.id);
|
|
|
|
}
|
2023-10-09 20:20:02 -04:00
|
|
|
|
|
|
|
getBgmOverride(): string {
|
|
|
|
const battlers = this.enemyParty.slice(0, this.getBattlerCount());
|
|
|
|
for (let pokemon of battlers) {
|
|
|
|
if (this.battleType === BattleType.TRAINER) {
|
|
|
|
if (this.trainer.config.trainerType === TrainerType.RIVAL)
|
|
|
|
return 'battle_rival';
|
|
|
|
return 'battle_trainer';
|
|
|
|
}
|
|
|
|
if (pokemon.species.speciesId === Species.ETERNATUS)
|
|
|
|
return 'battle_final';
|
|
|
|
if (pokemon.species.legendary) {
|
|
|
|
if (pokemon.species.speciesId === Species.RESHIRAM || pokemon.species.speciesId === Species.ZEKROM)
|
|
|
|
return 'battle_legendary_rz';
|
|
|
|
if (pokemon.species.speciesId === Species.KYUREM)
|
|
|
|
return 'battle_legendary_z';
|
|
|
|
return 'battle_legendary';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2023-03-30 23:02:35 -04:00
|
|
|
}
|