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 modify an attribute.
|
|
|
|
*
|
|
|
|
* Attribute effects are stacking, and the value of an attribute is in fact the sum of all active attribute effects.
|
|
|
|
*/
|
|
|
|
export class AttributeEffect extends BaseEffect {
|
|
|
|
// Affected attribute
|
2017-11-14 00:07:06 +00:00
|
|
|
attrcode: keyof ShipAttributes
|
2017-02-07 19:15:21 +00:00
|
|
|
|
|
|
|
// Base value
|
2017-11-14 00:07:06 +00:00
|
|
|
value: number
|
2017-02-07 19:15:21 +00:00
|
|
|
|
2017-02-09 22:21:39 +00:00
|
|
|
constructor(attrcode: keyof ShipAttributes, value = 0) {
|
2017-02-07 19:15:21 +00:00
|
|
|
super("attr");
|
|
|
|
|
|
|
|
this.attrcode = attrcode;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
|
|
|
|
return [
|
|
|
|
new ShipAttributeDiff(ship, this.attrcode, { cumulative: this.value }, {}),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getOffDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
|
|
|
|
return [
|
|
|
|
new ShipAttributeDiff(ship, this.attrcode, {}, { cumulative: this.value }),
|
|
|
|
];
|
2017-02-07 19:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isBeneficial(): boolean {
|
|
|
|
return this.value >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
getFullCode(): string {
|
|
|
|
return this.code + "-" + this.attrcode;
|
|
|
|
}
|
2017-04-18 22:55:59 +00:00
|
|
|
|
|
|
|
getDescription(): string {
|
2017-11-14 00:07:06 +00:00
|
|
|
let attrname = SHIP_VALUES_NAMES[this.attrcode];
|
2017-04-18 22:55:59 +00:00
|
|
|
return `${attrname} ${this.value > 0 ? "+" : "-"}${Math.abs(this.value)}`;
|
|
|
|
}
|
2017-02-07 19:15:21 +00:00
|
|
|
}
|
|
|
|
}
|