2017-11-14 00:07:06 +00:00
|
|
|
/// <reference path="BaseBattleDiff.ts"/>
|
|
|
|
|
|
|
|
module TK.SpaceTac {
|
|
|
|
/**
|
|
|
|
* A ship activated or deactivated a toggle action
|
|
|
|
*/
|
|
|
|
export class ShipActionToggleDiff extends BaseBattleShipDiff {
|
|
|
|
// Pointer to the action
|
|
|
|
action: RObjectId
|
|
|
|
|
|
|
|
// true for activation, false for deactivation
|
|
|
|
activated: boolean
|
|
|
|
|
|
|
|
constructor(ship: Ship | RObjectId, action: BaseAction | RObjectId, activated: boolean) {
|
|
|
|
super(ship);
|
|
|
|
|
|
|
|
this.action = (action instanceof BaseAction) ? action.id : action;
|
|
|
|
this.activated = activated;
|
|
|
|
}
|
|
|
|
|
|
|
|
applyOnShip(ship: Ship, battle: Battle): void {
|
2018-02-08 15:16:03 +00:00
|
|
|
let action = ship.actions.getById(this.action);
|
2017-11-14 00:07:06 +00:00
|
|
|
if (action && action instanceof ToggleAction) {
|
2018-02-08 15:16:03 +00:00
|
|
|
let activated = ship.actions.isToggled(action);
|
|
|
|
if (activated == this.activated) {
|
2017-11-14 00:07:06 +00:00
|
|
|
console.warn("Diff not applied - action already in good state", this, action);
|
|
|
|
} else {
|
2018-02-08 15:16:03 +00:00
|
|
|
ship.actions.toggle(action, this.activated);
|
2017-11-14 00:07:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.error("Diff not applied - action not found on ship", this, ship);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getReverse(): BaseBattleDiff {
|
|
|
|
return new ShipActionToggleDiff(this.ship_id, this.action, !this.activated);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|