2023-03-31 04:02:35 +01:00
|
|
|
import { EnemyPokemon, PlayerPokemon } from "./pokemon";
|
2023-03-31 21:04:39 +01:00
|
|
|
import * as Utils from "./utils";
|
2023-03-31 04:02:35 +01:00
|
|
|
|
|
|
|
export class Battle {
|
|
|
|
public waveIndex: integer;
|
2023-03-31 21:04:39 +01:00
|
|
|
public enemyLevel: integer;
|
2023-03-31 04:02:35 +01:00
|
|
|
public enemyPokemon: EnemyPokemon;
|
2023-04-22 00:30:04 +01:00
|
|
|
public turn: integer;
|
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-03-31 21:04:39 +01:00
|
|
|
constructor(waveIndex: integer) {
|
2023-03-31 04:02:35 +01:00
|
|
|
this.waveIndex = waveIndex;
|
2023-03-31 21:04:39 +01:00
|
|
|
this.enemyLevel = this.getLevelForWave();
|
2023-04-22 00:30:04 +01:00
|
|
|
this.turn = 1;
|
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-04-22 00:30:04 +01:00
|
|
|
incrementTurn() {
|
|
|
|
this.turn++;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|