1
0
Fork 0
spacetac/src/core/Slot.ts

47 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-02-09 00:00:35 +00:00
module TS.SpaceTac {
// Types of slots
export enum SlotType {
Armor,
Shield,
Engine,
Power,
Weapon
}
2015-01-13 00:00:00 +00:00
// Slot to attach an equipment to a ship
export class Slot {
2015-01-13 00:00:00 +00:00
// Link to the ship
ship: Ship;
// Type of slot
type: SlotType;
// Currently attached equipment, null if none
2015-01-13 00:00:00 +00:00
attached: Equipment;
// 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
attach(equipment: Equipment): Equipment | null {
if (this.type === equipment.slot && equipment.canBeEquipped(this.ship)) {
this.attached = equipment;
equipment.attached_to = this;
2015-01-22 00:00:00 +00:00
if (this.ship) {
this.ship.updateAttributes();
}
return equipment;
} else {
return null;
2015-01-22 00:00:00 +00:00
}
}
2015-01-13 00:00:00 +00:00
}
}