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

44 lines
1.3 KiB
TypeScript

import { RandomGenerator } from "../../common/RandomGenerator";
import { BaseBattleDiff } from "../diffs/BaseBattleDiff";
import { ShipCooldownDiff } from "../diffs/ShipCooldownDiff";
import { Drone } from "../Drone";
import { Ship } from "../Ship";
import { BaseEffect } from "./BaseEffect";
/**
* Cools down equipment of affected ships
*/
export class CooldownEffect extends BaseEffect {
// Number of cooling steps to apply
cooling: number
// Maximal number of equipment to cool on one ship (will be chosen at random)
maxcount: number
constructor(cooling = 0, maxcount = 0) {
super("cooldown");
this.cooling = cooling;
this.maxcount = maxcount;
}
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
let actions = ship.actions.listOverheated();
if (this.maxcount && actions.length > this.maxcount) {
let random = RandomGenerator.global;
actions = random.sample(actions, this.maxcount);
}
return actions.map(action => new ShipCooldownDiff(ship, action, this.cooling || ship.actions.getCooldown(action).heat));
}
isBeneficial(): boolean {
return true;
}
getDescription(): string {
return `${this.cooling ? this.cooling : "full"} cooling (${this.maxcount ? this.maxcount : "all"} equipment${this.maxcount != 1 ? "s" : ""})`;
}
}