2017-02-07 19:15:21 +00:00
|
|
|
/// <reference path="BaseEffect.ts"/>
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-02-07 19:15:21 +00:00
|
|
|
/**
|
|
|
|
* Effect to add (or subtract if negative) an amount to a ship value.
|
|
|
|
*
|
|
|
|
* The effect is immediate and permanent.
|
|
|
|
*/
|
|
|
|
export class ValueEffect extends BaseEffect {
|
|
|
|
// Affected value
|
|
|
|
valuetype: keyof ShipValues;
|
|
|
|
|
|
|
|
// Value to add (or subtract if negative)
|
|
|
|
value: number;
|
|
|
|
|
2017-02-09 22:21:39 +00:00
|
|
|
constructor(valuetype: keyof ShipValues, value: number = 0) {
|
2017-02-07 19:15:21 +00:00
|
|
|
super("value");
|
|
|
|
|
|
|
|
this.valuetype = valuetype;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
2017-05-28 22:16:50 +00:00
|
|
|
applyOnShip(ship: Ship, source: Ship | Drone): boolean {
|
2017-02-07 19:15:21 +00:00
|
|
|
return ship.setValue(this.valuetype, this.value, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
isBeneficial(): boolean {
|
|
|
|
return this.value >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
getFullCode(): string {
|
|
|
|
return `${this.code}-${this.valuetype}`;
|
|
|
|
}
|
2017-02-08 00:18:54 +00:00
|
|
|
|
|
|
|
getDescription(): string {
|
|
|
|
let attrname = SHIP_VALUES[this.valuetype].name;
|
|
|
|
return `${attrname} ${this.value > 0 ? "+" : "-"}${Math.abs(this.value)}`;
|
|
|
|
}
|
2017-02-07 19:15:21 +00:00
|
|
|
}
|
|
|
|
}
|