2015-03-03 00:00:00 +00:00
|
|
|
/// <reference path="Serializable.ts"/>
|
|
|
|
|
2015-01-13 00:00:00 +00:00
|
|
|
module SpaceTac.Game {
|
|
|
|
"use strict";
|
|
|
|
|
2015-01-16 00:00:00 +00:00
|
|
|
// 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
|
2015-03-03 00:00:00 +00:00
|
|
|
export class Slot extends Serializable {
|
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
|
2015-01-13 00:00:00 +00:00
|
|
|
attached: Equipment;
|
2015-01-14 00:00:00 +00:00
|
|
|
|
|
|
|
// Create an empty slot for a ship
|
|
|
|
constructor(ship: Ship, type: SlotType) {
|
2015-03-03 00:00:00 +00:00
|
|
|
super();
|
|
|
|
|
2015-01-14 00:00:00 +00:00
|
|
|
this.ship = ship;
|
|
|
|
this.type = type;
|
|
|
|
this.attached = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attach an equipment in this slot
|
|
|
|
attach(equipment: Equipment): void {
|
2015-02-06 00:00:00 +00:00
|
|
|
if (this.type === equipment.slot && equipment.canBeEquipped(this.ship)) {
|
|
|
|
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
|
|
|
}
|
2015-01-14 00:00:00 +00:00
|
|
|
}
|
2015-01-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|