2017-11-14 00:07:06 +00:00
|
|
|
/// <reference path="BaseBattleDiff.ts"/>
|
|
|
|
|
|
|
|
module TK.SpaceTac {
|
|
|
|
/**
|
2018-02-08 15:16:03 +00:00
|
|
|
* A ship's action cools down
|
2017-11-14 00:07:06 +00:00
|
|
|
*/
|
|
|
|
export class ShipCooldownDiff extends BaseBattleShipDiff {
|
2018-02-08 15:16:03 +00:00
|
|
|
// Action to cool
|
|
|
|
action: RObjectId
|
2017-11-14 00:07:06 +00:00
|
|
|
|
|
|
|
// Quantity of heat to dissipate
|
|
|
|
heat: number
|
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
constructor(ship: Ship | RObjectId, action: BaseAction | RObjectId, heat: number) {
|
2017-11-14 00:07:06 +00:00
|
|
|
super(ship);
|
|
|
|
|
2018-02-08 15:16:03 +00:00
|
|
|
this.action = (action instanceof BaseAction) ? action.id : action;
|
2017-11-14 00:07:06 +00:00
|
|
|
this.heat = heat;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyOnShip(ship: Ship, battle: Battle) {
|
2018-02-08 15:16:03 +00:00
|
|
|
let action = ship.actions.getById(this.action);
|
|
|
|
if (action) {
|
|
|
|
let cooldown = ship.actions.getCooldown(action);
|
|
|
|
cooldown.heat -= this.heat;
|
|
|
|
if (cooldown.heat == 0) {
|
|
|
|
cooldown.uses = 0;
|
2017-12-20 21:21:12 +00:00
|
|
|
}
|
2017-11-14 00:07:06 +00:00
|
|
|
} else {
|
2018-02-08 15:16:03 +00:00
|
|
|
console.error("Cannot apply diff, action not found", this, ship.actions);
|
2017-11-14 00:07:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
revertOnShip(ship: Ship, battle: Battle) {
|
2018-02-08 15:16:03 +00:00
|
|
|
let action = ship.actions.getById(this.action);
|
|
|
|
if (action) {
|
|
|
|
let cooldown = ship.actions.getCooldown(action);
|
|
|
|
if (cooldown.heat == 0) {
|
|
|
|
cooldown.uses = cooldown.overheat;
|
2017-12-20 21:21:12 +00:00
|
|
|
}
|
2018-02-08 15:16:03 +00:00
|
|
|
cooldown.heat += this.heat;
|
2017-11-14 00:07:06 +00:00
|
|
|
} else {
|
2018-02-08 15:16:03 +00:00
|
|
|
console.error("Cannot revert diff, action not found", this, ship.actions);
|
2017-11-14 00:07:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|