2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2015-01-16 00:00:00 +00:00
|
|
|
// Types of slots
|
|
|
|
export enum SlotType {
|
2017-03-05 14:12:08 +00:00
|
|
|
Hull,
|
2015-01-16 00:00:00 +00:00
|
|
|
Shield,
|
|
|
|
Engine,
|
|
|
|
Power,
|
|
|
|
Weapon
|
|
|
|
}
|
2015-01-13 00:00:00 +00:00
|
|
|
|
|
|
|
// Slot to attach an equipment to a ship
|
2017-02-07 18:54:53 +00:00
|
|
|
export class Slot {
|
2015-01-13 00:00:00 +00:00
|
|
|
// Link to the ship
|
|
|
|
ship: Ship;
|
|
|
|
|
|
|
|
// Type of slot
|
|
|
|
type: SlotType;
|
|
|
|
|
2015-01-14 00:00:00 +00:00
|
|
|
// Currently attached equipment, null if none
|
2017-03-09 17:11:00 +00:00
|
|
|
attached: Equipment | null;
|
2015-01-14 00:00:00 +00:00
|
|
|
|
|
|
|
// Create an empty slot for a ship
|
|
|
|
constructor(ship: Ship, type: SlotType) {
|
|
|
|
this.ship = ship;
|
|
|
|
this.type = type;
|
|
|
|
this.attached = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach an equipment in this slot
|
2017-03-09 17:11:00 +00:00
|
|
|
attach(equipment: Equipment): Equipment {
|
2017-04-25 23:27:42 +00:00
|
|
|
if (this.type === equipment.slot_type && equipment.canBeEquipped(this.ship.attributes)) {
|
2015-02-06 00:00:00 +00:00
|
|
|
this.attached = equipment;
|
2015-02-13 00:00:00 +00:00
|
|
|
equipment.attached_to = this;
|
2015-01-22 00:00:00 +00:00
|
|
|
|
2015-02-06 00:00:00 +00:00
|
|
|
if (this.ship) {
|
|
|
|
this.ship.updateAttributes();
|
|
|
|
}
|
2015-01-22 00:00:00 +00:00
|
|
|
}
|
2017-03-09 17:11:00 +00:00
|
|
|
return equipment;
|
2015-01-14 00:00:00 +00:00
|
|
|
}
|
2015-01-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|