2017-03-22 21:16:59 +00:00
|
|
|
/// <reference path="CharacterEquipment.ts" />
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.UI {
|
2017-03-05 17:48:13 +00:00
|
|
|
/**
|
|
|
|
* Display a ship cargo slot
|
|
|
|
*/
|
2017-03-22 21:16:59 +00:00
|
|
|
export class CharacterCargo extends Phaser.Image implements CharacterEquipmentContainer {
|
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;
|
|
|
|
}
|
|
|
|
|
2017-04-25 18:24:43 +00:00
|
|
|
jasmineToString() {
|
|
|
|
return "CharacterCargo";
|
|
|
|
}
|
|
|
|
|
2017-03-05 23:29:02 +00:00
|
|
|
/**
|
2017-03-22 21:16:59 +00:00
|
|
|
* CharacterEquipmentContainer interface
|
2017-03-05 23:29:02 +00:00
|
|
|
*/
|
2017-03-22 21:16:59 +00:00
|
|
|
isInside(x: number, y: number): boolean {
|
|
|
|
return this.getBounds().contains(x, y);
|
2017-03-05 17:48:13 +00:00
|
|
|
}
|
2017-07-24 23:02:49 +00:00
|
|
|
getEquipmentAnchor(): { x: number, y: number, scale: number, alpha: number } {
|
2017-03-22 21:16:59 +00:00
|
|
|
return {
|
2017-07-24 23:02:49 +00:00
|
|
|
x: this.x + (this.parent ? this.parent.x : 0) + 98 * this.scale.x,
|
|
|
|
y: this.y + (this.parent ? this.parent.y : 0) + 98 * this.scale.y,
|
2017-07-31 16:25:00 +00:00
|
|
|
scale: this.scale.x * 1.25,
|
2017-07-24 23:02:49 +00:00
|
|
|
alpha: this.alpha,
|
2017-03-22 21:16:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-23 18:58:09 +00:00
|
|
|
getPriceOffset(): number {
|
2017-07-31 16:25:00 +00:00
|
|
|
return 66;
|
2017-03-23 18:58:09 +00:00
|
|
|
}
|
2017-03-22 21:16:59 +00:00
|
|
|
addEquipment(equipment: CharacterEquipment, source: CharacterEquipmentContainer | null, test: boolean): boolean {
|
2017-07-24 23:02:49 +00:00
|
|
|
if (this.sheet.ship.critical) {
|
|
|
|
return false;
|
|
|
|
} if (this.sheet.ship.getFreeCargoSpace() > 0) {
|
2017-03-22 21:16:59 +00:00
|
|
|
if (test) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this.sheet.ship.addCargo(equipment.item);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeEquipment(equipment: CharacterEquipment, destination: CharacterEquipmentContainer | null, test: boolean): boolean {
|
2017-07-24 23:02:49 +00:00
|
|
|
if (this.sheet.ship.critical) {
|
|
|
|
return false;
|
|
|
|
} else if (contains(this.sheet.ship.cargo, equipment.item)) {
|
2017-03-22 21:16:59 +00:00
|
|
|
if (test) {
|
|
|
|
return true;
|
2017-03-14 17:48:04 +00:00
|
|
|
} else {
|
2017-03-22 21:16:59 +00:00
|
|
|
return this.sheet.ship.removeCargo(equipment.item);
|
2017-03-14 17:48:04 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|