2017-01-26 23:52:45 +00:00
|
|
|
module TS.SpaceTac.Game {
|
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 {
|
2015-02-13 00:00:00 +00:00
|
|
|
// Actual slot this equipment is attached to
|
|
|
|
attached_to: Slot;
|
|
|
|
|
|
|
|
// Type of slot this equipment can fit in
|
2015-01-13 00:00:00 +00:00
|
|
|
slot: SlotType;
|
|
|
|
|
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;
|
|
|
|
|
2015-01-29 00:00:00 +00:00
|
|
|
// Maximal distance allowed to target
|
2015-01-13 00:00:00 +00:00
|
|
|
distance: number;
|
|
|
|
|
|
|
|
// Effect area's radius
|
|
|
|
blast: number;
|
|
|
|
|
|
|
|
// Duration
|
|
|
|
duration: number;
|
|
|
|
|
|
|
|
// Action Points usage
|
|
|
|
ap_usage: number;
|
|
|
|
|
|
|
|
// Level requirement
|
|
|
|
min_level: number;
|
2015-01-16 00:00:00 +00:00
|
|
|
|
2015-02-06 00:00:00 +00:00
|
|
|
// Minimal attribute to be able to equip this equipment
|
2017-02-07 19:15:21 +00:00
|
|
|
requirements: { [key: string]: number };
|
2015-02-06 00:00:00 +00:00
|
|
|
|
2015-01-16 00:00:00 +00:00
|
|
|
// Action associated with this equipment
|
|
|
|
action: BaseAction;
|
2015-01-22 00:00:00 +00:00
|
|
|
|
2015-02-06 00:00:00 +00:00
|
|
|
// Permanent effects on the ship that equips the equipment
|
2015-01-22 00:00:00 +00:00
|
|
|
permanent_effects: BaseEffect[];
|
|
|
|
|
2015-01-28 00:00:00 +00:00
|
|
|
// Effects on target
|
|
|
|
target_effects: BaseEffect[];
|
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
// Basic constructor
|
2015-02-20 00:00:00 +00:00
|
|
|
constructor(slot: SlotType = null, code: string = null) {
|
2015-02-13 00:00:00 +00:00
|
|
|
this.slot = 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 = {};
|
2015-01-22 00:00:00 +00:00
|
|
|
this.permanent_effects = [];
|
2015-01-28 00:00:00 +00:00
|
|
|
this.target_effects = [];
|
2015-01-22 00:00:00 +00:00
|
|
|
}
|
2015-02-06 00:00:00 +00:00
|
|
|
|
|
|
|
// Returns true if the equipment can be equipped on a ship
|
|
|
|
// This checks *requirements* against the ship capabilities
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Detach from the slot it is attached to
|
|
|
|
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
|
|
|
|
|
|
|
// Get a human readable description of the effects of this equipment
|
|
|
|
getActionDescription(): string {
|
|
|
|
if (this.permanent_effects.length == 0 && this.target_effects.length == 0) {
|
|
|
|
return "does nothing";
|
|
|
|
} else {
|
|
|
|
var result: string[] = [];
|
|
|
|
this.target_effects.forEach(effect => {
|
2017-02-08 00:18:54 +00:00
|
|
|
let suffix = this.blast ? `in ${this.blast}km radius` : "on target";
|
2017-01-23 23:07:54 +00:00
|
|
|
if (effect instanceof StickyEffect) {
|
2017-01-17 00:02:38 +00:00
|
|
|
suffix = `for ${effect.duration} turn${effect.duration > 1 ? "s" : ""} ${suffix}`;
|
|
|
|
}
|
|
|
|
result.push("- " + effect.getDescription() + " " + suffix);
|
|
|
|
});
|
|
|
|
return result.join("\n");
|
|
|
|
}
|
|
|
|
}
|
2015-01-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|