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

49 lines
1.4 KiB
TypeScript
Raw Normal View History

/// <reference path="BaseEffect.ts"/>
2017-09-24 22:23:22 +00:00
module TK.SpaceTac {
/**
* 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
attrcode: keyof ShipAttributes
// Base value
value: number
2017-02-09 22:21:39 +00:00
constructor(attrcode: keyof ShipAttributes, value = 0) {
super("attr");
this.attrcode = attrcode;
this.value = value;
}
getOnDiffs(ship: Ship, source: Ship | Drone, success: number): BaseBattleDiff[] {
return [
new ShipAttributeDiff(ship, this.attrcode, { cumulative: this.value }, {}),
];
}
2017-11-29 22:03:58 +00:00
getOffDiffs(ship: Ship): BaseBattleDiff[] {
return [
new ShipAttributeDiff(ship, this.attrcode, {}, { cumulative: this.value }),
];
}
isBeneficial(): boolean {
return this.value >= 0;
}
getFullCode(): string {
return this.code + "-" + this.attrcode;
}
getDescription(): string {
let attrname = SHIP_VALUES_NAMES[this.attrcode];
return `${attrname} ${this.value > 0 ? "+" : "-"}${Math.abs(this.value)}`;
}
}
}