41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
/// <reference path="BaseEffect.ts"/>
|
|
|
|
module TK.SpaceTac {
|
|
/**
|
|
* 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
|
|
|
|
constructor(valuetype: keyof ShipValues, value: number = 0) {
|
|
super("value");
|
|
|
|
this.valuetype = valuetype;
|
|
this.value = value;
|
|
}
|
|
|
|
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
|
|
return ship.getValueDiffs(this.valuetype, this.value, true);
|
|
}
|
|
|
|
isBeneficial(): boolean {
|
|
return this.value >= 0;
|
|
}
|
|
|
|
getFullCode(): string {
|
|
return `${this.code}-${this.valuetype}`;
|
|
}
|
|
|
|
getDescription(): string {
|
|
let attrname = SHIP_VALUES_NAMES[this.valuetype];
|
|
return `${attrname} ${this.value > 0 ? "+" : "-"}${Math.abs(this.value)}`;
|
|
}
|
|
}
|
|
}
|