2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Cooldown system for equipments
|
|
|
|
*/
|
|
|
|
export class Cooldown {
|
|
|
|
// Number of uses in the current turn
|
|
|
|
uses = 0
|
|
|
|
|
|
|
|
// Accumulated heat to dissipate (number of turns)
|
|
|
|
heat = 0
|
|
|
|
|
|
|
|
// Maximum number of uses allowed per turn before overheating (0 for unlimited)
|
|
|
|
overheat = 0
|
|
|
|
|
2017-05-22 16:29:04 +00:00
|
|
|
// Number of "end turn" needed to cooldown when overheated
|
|
|
|
cooling = 1
|
2017-04-18 19:51:23 +00:00
|
|
|
|
2017-05-22 16:29:04 +00:00
|
|
|
constructor(overheat = 0, cooling = 1) {
|
2017-05-16 23:12:05 +00:00
|
|
|
this.configure(overheat, cooling);
|
|
|
|
}
|
|
|
|
|
|
|
|
toString(): string {
|
|
|
|
return `Overheat ${this.overheat} / Cooldown ${this.cooling}`;
|
|
|
|
}
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Check if the equipment can be used in regards to heat
|
|
|
|
*/
|
|
|
|
canUse(): boolean {
|
|
|
|
return this.heat == 0;
|
|
|
|
}
|
|
|
|
|
2017-05-16 23:12:05 +00:00
|
|
|
/**
|
|
|
|
* Check if the equipment would overheat if used
|
|
|
|
*/
|
|
|
|
willOverheat(): boolean {
|
|
|
|
return this.overheat > 0 && this.uses + 1 >= this.overheat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the number of uses before overheating
|
|
|
|
*/
|
|
|
|
getRemainingUses(): number {
|
2017-05-22 16:29:04 +00:00
|
|
|
if (this.overheat) {
|
|
|
|
return (this.heat > 0) ? 0 : (this.overheat - this.uses);
|
|
|
|
} else {
|
|
|
|
return Infinity;
|
|
|
|
}
|
2017-05-16 23:12:05 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Configure the overheat and cooling
|
|
|
|
*/
|
|
|
|
configure(overheat: number, cooling: number) {
|
|
|
|
this.overheat = overheat;
|
2017-05-22 16:29:04 +00:00
|
|
|
this.cooling = Math.max(1, cooling);
|
2017-05-16 23:12:05 +00:00
|
|
|
this.reset();
|
2017-04-18 19:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use the equipment, increasing the heat
|
|
|
|
*/
|
|
|
|
use(): void {
|
2017-05-16 23:12:05 +00:00
|
|
|
if (this.overheat) {
|
|
|
|
this.uses += 1;
|
|
|
|
if (this.uses >= this.overheat) {
|
2017-05-22 16:29:04 +00:00
|
|
|
this.heat = this.cooling;
|
2017-05-16 23:12:05 +00:00
|
|
|
}
|
2017-04-18 19:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply one cooling-down step if necessary
|
|
|
|
*/
|
2017-10-02 16:02:30 +00:00
|
|
|
cool(steps = 1): void {
|
|
|
|
this.heat = Math.max(this.heat - steps, 0);
|
2017-05-22 16:29:04 +00:00
|
|
|
|
|
|
|
if (this.heat == 0) {
|
|
|
|
this.uses = 0;
|
|
|
|
}
|
2017-04-18 19:51:23 +00:00
|
|
|
}
|
2017-05-16 23:12:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the cooldown (typically at the end of turn)
|
|
|
|
*/
|
|
|
|
reset(): void {
|
|
|
|
this.uses = 0;
|
|
|
|
this.heat = 0;
|
|
|
|
}
|
2017-04-18 19:51:23 +00:00
|
|
|
}
|
|
|
|
}
|