2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2015-01-13 00:00:00 +00:00
|
|
|
// Piece of equipment to attach in slots
|
2017-02-07 18:54:53 +00:00
|
|
|
export class Equipment {
|
2017-04-18 19:51:23 +00:00
|
|
|
// Type of slot this equipment can fit in
|
|
|
|
slot_type: SlotType | null;
|
|
|
|
|
2015-02-13 00:00:00 +00:00
|
|
|
// Actual slot this equipment is attached to
|
2017-03-09 17:11:00 +00:00
|
|
|
attached_to: Slot | null = null;
|
2015-02-13 00:00:00 +00:00
|
|
|
|
2015-02-20 00:00:00 +00:00
|
|
|
// Identifiable equipment code (may be used by UI to customize visual effects)
|
|
|
|
code: string;
|
|
|
|
|
2015-01-13 00:00:00 +00:00
|
|
|
// Equipment name
|
|
|
|
name: string;
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
// Minimum skills to be able to equip this
|
2017-02-07 19:15:21 +00:00
|
|
|
requirements: { [key: string]: number };
|
2015-02-06 00:00:00 +00:00
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
// Permanent effects on the ship that equips this
|
|
|
|
effects: BaseEffect[];
|
2015-01-22 00:00:00 +00:00
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
// Action available when equipped
|
|
|
|
action: BaseAction;
|
2015-01-22 00:00:00 +00:00
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
// Usage made of this equipment (will lower the sell price)
|
|
|
|
usage: number;
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
// Basic constructor
|
2017-03-22 21:16:59 +00:00
|
|
|
constructor(slot: SlotType | null = null, code = "equipment") {
|
2017-04-18 19:51:23 +00:00
|
|
|
this.slot_type = slot;
|
2015-02-20 00:00:00 +00:00
|
|
|
this.code = code;
|
|
|
|
this.name = code;
|
2017-02-07 19:15:21 +00:00
|
|
|
this.requirements = {};
|
2017-04-18 19:51:23 +00:00
|
|
|
this.effects = [];
|
2017-02-27 00:42:12 +00:00
|
|
|
this.action = new BaseAction("nothing", "Do nothing", false);
|
2015-01-22 00:00:00 +00:00
|
|
|
}
|
2015-02-06 00:00:00 +00:00
|
|
|
|
2017-03-14 17:48:04 +00:00
|
|
|
jasmineToString() {
|
|
|
|
return this.attached_to ? `${this.attached_to.ship.name} - ${this.name}` : this.name;
|
|
|
|
}
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Get the minimum level at which the requirements in skill may be fulfilled.
|
|
|
|
*
|
|
|
|
* This is informative and is not directly enforced. It will only be enforced by skills requirements.
|
|
|
|
*/
|
|
|
|
getMinimumLevel(): number {
|
|
|
|
let points = sum(values(this.requirements));
|
|
|
|
return ShipLevel.getLevelForPoints(points);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the equipment can be equipped on a ship.
|
|
|
|
*
|
|
|
|
* This checks *requirements* against the ship skills.
|
|
|
|
*
|
|
|
|
* This does not check where the equipment currently is (except if is it already attached and should be detached first).
|
|
|
|
*/
|
2015-02-06 00:00:00 +00:00
|
|
|
canBeEquipped(ship: Ship): boolean {
|
2015-02-13 00:00:00 +00:00
|
|
|
if (this.attached_to) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
var able = true;
|
2017-02-07 19:15:21 +00:00
|
|
|
iteritems(this.requirements, (attr, minvalue) => {
|
|
|
|
if (ship.getAttribute(<keyof ShipAttributes>attr) < minvalue) {
|
2015-02-13 00:00:00 +00:00
|
|
|
able = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return able;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Detach from the slot it is attached to
|
|
|
|
*/
|
2015-02-13 00:00:00 +00:00
|
|
|
detach(): void {
|
|
|
|
if (this.attached_to) {
|
|
|
|
this.attached_to.attached = null;
|
|
|
|
this.attached_to = null;
|
|
|
|
}
|
2015-02-06 00:00:00 +00:00
|
|
|
}
|
2017-01-17 00:02:38 +00:00
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Get a human readable description of the effects of this equipment
|
|
|
|
*/
|
2017-01-17 00:02:38 +00:00
|
|
|
getActionDescription(): string {
|
2017-04-18 19:51:23 +00:00
|
|
|
let parts: string[] = [];
|
|
|
|
|
|
|
|
this.effects.forEach(effect => {
|
|
|
|
parts.push(`- Equip: ${effect.getDescription()}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.action.getEffectsDescription().forEach(desc => {
|
|
|
|
parts.push(`- ${this.action.name}: ${desc}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
return parts.length > 0 ? parts.join("\n") : "does nothing";
|
2017-01-17 00:02:38 +00:00
|
|
|
}
|
2015-01-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|