2017-03-05 17:48:13 +00:00
|
|
|
module TS.SpaceTac.UI {
|
|
|
|
/**
|
|
|
|
* Display a ship cargo slot
|
|
|
|
*/
|
|
|
|
export class CharacterCargo extends Phaser.Image {
|
2017-03-05 23:29:02 +00:00
|
|
|
sheet: CharacterSheet;
|
|
|
|
|
2017-03-05 17:48:13 +00:00
|
|
|
constructor(sheet: CharacterSheet, x: number, y: number) {
|
|
|
|
super(sheet.game, x, y, "character-cargo-slot");
|
2017-03-05 23:29:02 +00:00
|
|
|
|
|
|
|
this.sheet = sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Snap the equipment icon inside the slot
|
|
|
|
*/
|
|
|
|
snapEquipment(equipment: CharacterEquipment) {
|
2017-03-14 17:48:04 +00:00
|
|
|
equipment.position.set(this.x + this.parent.x + 98 * this.scale.x, this.y + this.parent.y + 98 * this.scale.y);
|
|
|
|
equipment.setContainerScale(this.scale.x);
|
2017-03-05 17:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-05 23:29:02 +00:00
|
|
|
* Check if an equipment can be dropped in this slot
|
2017-03-05 17:48:13 +00:00
|
|
|
*/
|
2017-03-05 23:29:02 +00:00
|
|
|
canDropEquipment(equipment: Equipment, x: number, y: number): CharacterEquipmentDrop | null {
|
|
|
|
if (this.getBounds().contains(x, y)) {
|
2017-03-14 17:48:04 +00:00
|
|
|
if (contains(this.sheet.loot_items, equipment)) {
|
|
|
|
return {
|
|
|
|
message: "Loot",
|
|
|
|
callback: () => {
|
|
|
|
if (this.sheet.ship.addCargo(equipment)) {
|
|
|
|
remove(this.sheet.loot_items, equipment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
message: "Unequip",
|
|
|
|
callback: () => this.sheet.ship.unequip(equipment)
|
|
|
|
};
|
|
|
|
}
|
2017-03-05 23:29:02 +00:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-05 17:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|