2017-03-22 21:16:59 +00:00
|
|
|
/// <reference path="CharacterEquipment.ts" />
|
|
|
|
|
2017-02-28 22:34:02 +00:00
|
|
|
module TS.SpaceTac.UI {
|
|
|
|
/**
|
|
|
|
* Display a ship slot, with equipment attached to it
|
|
|
|
*/
|
2017-03-22 21:16:59 +00:00
|
|
|
export class CharacterSlot extends Phaser.Image implements CharacterEquipmentContainer {
|
2017-03-05 23:29:02 +00:00
|
|
|
sheet: CharacterSheet;
|
|
|
|
|
2017-02-28 22:34:02 +00:00
|
|
|
constructor(sheet: CharacterSheet, x: number, y: number, slot: SlotType) {
|
|
|
|
super(sheet.game, x, y, "character-equipment-slot");
|
|
|
|
|
2017-03-05 23:29:02 +00:00
|
|
|
this.sheet = sheet;
|
|
|
|
|
2017-03-15 21:40:19 +00:00
|
|
|
let sloticon = new Phaser.Button(this.game, 150, 150, `character-slot-${SlotType[slot].toLowerCase()}`);
|
2017-02-28 22:34:02 +00:00
|
|
|
sloticon.anchor.set(0.5, 0.5);
|
|
|
|
this.addChild(sloticon);
|
2017-03-15 21:40:19 +00:00
|
|
|
sheet.view.tooltip.bindStaticText(sloticon, `${SlotType[slot]} slot`);
|
2017-02-28 22:34:02 +00:00
|
|
|
}
|
2017-03-05 17:48:13 +00:00
|
|
|
|
2017-03-05 23:29:02 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-22 21:16:59 +00:00
|
|
|
* CharacterEquipmentContainer interface
|
2017-03-05 17:48:13 +00:00
|
|
|
*/
|
2017-03-22 21:16:59 +00:00
|
|
|
isInside(x: number, y: number): boolean {
|
|
|
|
return this.getBounds().contains(x, y);
|
|
|
|
}
|
|
|
|
getEquipmentAnchor(): { x: number, y: number, scale: number } {
|
|
|
|
return {
|
|
|
|
x: this.x + this.parent.x + 84 * this.scale.x,
|
|
|
|
y: this.y + this.parent.y + 83 * this.scale.y,
|
|
|
|
scale: this.scale.x
|
|
|
|
}
|
|
|
|
}
|
2017-03-23 18:58:09 +00:00
|
|
|
getPriceOffset(): number {
|
|
|
|
return 66;
|
|
|
|
}
|
2017-03-22 21:16:59 +00:00
|
|
|
addEquipment(equipment: CharacterEquipment, source: CharacterEquipmentContainer | null, test: boolean): boolean {
|
2017-04-25 18:24:43 +00:00
|
|
|
if (this.sheet.ship.canEquip(equipment.item)) {
|
2017-03-22 21:16:59 +00:00
|
|
|
if (test) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this.sheet.ship.equip(equipment.item, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeEquipment(equipment: CharacterEquipment, destination: CharacterEquipmentContainer | null, test: boolean): boolean {
|
2017-04-18 19:51:23 +00:00
|
|
|
if (contains(this.sheet.ship.listEquipment(equipment.item.slot_type), equipment.item)) {
|
2017-03-22 21:16:59 +00:00
|
|
|
if (test) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this.sheet.ship.unequip(equipment.item, false);
|
|
|
|
}
|
2017-03-05 23:29:02 +00:00
|
|
|
} else {
|
2017-03-22 21:16:59 +00:00
|
|
|
return false;
|
2017-03-05 23:29:02 +00:00
|
|
|
}
|
2017-03-05 17:48:13 +00:00
|
|
|
}
|
2017-02-28 22:34:02 +00:00
|
|
|
}
|
|
|
|
}
|