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;
|
|
|
|
public playerParticipantIds: Set<integer> = new Set<integer>();
|
|
|
|
|
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-03-31 04:02:35 +01:00
|
|
|
}
|
|
|
|
|
2023-03-31 21:04:39 +01:00
|
|
|
private getLevelForWave(): number {
|
2023-04-19 16:14:47 +01:00
|
|
|
let averageLevel = 1 + this.waveIndex / 2 + Math.pow(this.waveIndex / 25, 2);
|
2023-03-31 21:04:39 +01:00
|
|
|
|
|
|
|
if (!(this.waveIndex % 10))
|
2023-04-19 16:14:47 +01:00
|
|
|
return Math.floor(averageLevel * 1.2);
|
2023-03-31 21:04:39 +01:00
|
|
|
|
|
|
|
const deviation = 10 / this.waveIndex;
|
|
|
|
|
|
|
|
return Math.max(Math.round(averageLevel + Utils.randGauss(deviation)), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|