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

44 lines
1 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac {
// Types of slots
export enum SlotType {
2017-03-05 14:12:08 +00:00
Hull,
Shield,
Power,
Engine,
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
2017-03-09 17:11:00 +00:00
attached: Equipment | null;
// 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 {
if (this.type === equipment.slot_type && equipment.canBeEquipped(this.ship.attributes)) {
this.attached = equipment;
equipment.attached_to = this;
2015-01-22 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-13 00:00:00 +00:00
}
}