1
0
Fork 0
spacetac/src/core/BattleCheats.ts
2019-11-21 23:14:27 +01:00

44 lines
981 B
TypeScript

import { iforeach } from "../common/Iterators";
import { first } from "../common/Tools";
import { Battle } from "./Battle";
import { Player } from "./Player";
/**
* Cheat helpers for current battle
*
* May be used from the console to help development
*/
export class BattleCheats {
battle: Battle
player: Player
constructor(battle: Battle, player: Player) {
this.battle = battle;
this.player = player;
}
/**
* Make player win the current battle
*/
win(): void {
iforeach(this.battle.iships(), ship => {
if (!this.player.is(ship.fleet.player)) {
ship.setDead();
}
});
this.battle.endBattle(this.player.fleet);
}
/**
* Make player lose the current battle
*/
lose(): void {
iforeach(this.battle.iships(), ship => {
if (this.player.is(ship.fleet.player)) {
ship.setDead();
}
});
this.battle.endBattle(first(this.battle.fleets, fleet => !this.player.is(fleet.player)));
}
}