52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { BaseBattleDiff } from "../diffs/BaseBattleDiff";
|
|
import { ShipAttributeDiff } from "../diffs/ShipAttributeDiff";
|
|
import { Drone } from "../Drone";
|
|
import { Ship } from "../Ship";
|
|
import { ShipAttributes, SHIP_VALUES_NAMES } from "../ShipValue";
|
|
import { BaseEffect } from "./BaseEffect";
|
|
|
|
/**
|
|
* Enforce a limitation on ship attribute final value
|
|
*
|
|
* For example, this could be used to slow a target by limiting its action points
|
|
*/
|
|
export class AttributeLimitEffect extends BaseEffect {
|
|
// Affected attribute
|
|
attrcode: keyof ShipAttributes;
|
|
|
|
// Limit of the attribute value
|
|
value: number;
|
|
|
|
constructor(attrcode: keyof ShipAttributes, value = 0) {
|
|
super("attrlimit");
|
|
|
|
this.attrcode = attrcode;
|
|
this.value = value;
|
|
}
|
|
|
|
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
|
|
return [
|
|
new ShipAttributeDiff(ship, this.attrcode, { limit: this.value }, {}),
|
|
];
|
|
}
|
|
|
|
getOffDiffs(ship: Ship): BaseBattleDiff[] {
|
|
return [
|
|
new ShipAttributeDiff(ship, this.attrcode, {}, { limit: this.value }),
|
|
];
|
|
}
|
|
|
|
isBeneficial(): boolean {
|
|
return false;
|
|
}
|
|
|
|
getFullCode(): string {
|
|
return this.code + "-" + this.attrcode;
|
|
}
|
|
|
|
getDescription(): string {
|
|
let attrname = SHIP_VALUES_NAMES[this.attrcode];
|
|
return `limit ${attrname} to ${this.value}`;
|
|
}
|
|
}
|