1
0
Fork 0
spacetac/src/core/effects/ValueEffect.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

/// <reference path="BaseEffect.ts"/>
2017-09-24 22:23:22 +00:00
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
2017-02-09 22:21:39 +00:00
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)}`;
}
}
}