2017-02-09 00:00:35 +00:00
|
|
|
module TS.SpaceTac {
|
2017-04-18 22:55:59 +00:00
|
|
|
/**
|
|
|
|
* Quality of loot.
|
|
|
|
*/
|
|
|
|
export enum EquipmentQuality {
|
|
|
|
WEAK,
|
|
|
|
COMMON,
|
|
|
|
FINE,
|
|
|
|
PREMIUM,
|
|
|
|
LEGENDARY
|
|
|
|
}
|
|
|
|
|
2015-01-13 00:00:00 +00:00
|
|
|
// Piece of equipment to attach in slots
|
2017-02-07 18:54:53 +00:00
|
|
|
export class Equipment {
|
2017-04-18 19:51:23 +00:00
|
|
|
// Type of slot this equipment can fit in
|
2017-04-18 22:55:59 +00:00
|
|
|
slot_type: SlotType | null
|
2017-04-18 19:51:23 +00:00
|
|
|
|
2015-02-13 00:00:00 +00:00
|
|
|
// Actual slot this equipment is attached to
|
2017-04-18 22:55:59 +00:00
|
|
|
attached_to: Slot | null = null
|
2015-02-13 00:00:00 +00:00
|
|
|
|
2015-02-20 00:00:00 +00:00
|
|
|
// Identifiable equipment code (may be used by UI to customize visual effects)
|
2017-04-18 22:55:59 +00:00
|
|
|
code: string
|
2015-02-20 00:00:00 +00:00
|
|
|
|
2015-01-13 00:00:00 +00:00
|
|
|
// Equipment name
|
2017-04-18 22:55:59 +00:00
|
|
|
name: string
|
|
|
|
|
|
|
|
// Equipment generic description
|
2017-04-20 21:20:50 +00:00
|
|
|
description = ""
|
2017-04-18 22:55:59 +00:00
|
|
|
|
|
|
|
// Indicative equipment level
|
|
|
|
level = 1
|
|
|
|
|
|
|
|
// Indicative equipment quality
|
|
|
|
quality = EquipmentQuality.COMMON
|
2015-01-13 00:00:00 +00:00
|
|
|
|
2017-04-20 21:20:50 +00:00
|
|
|
// Base price
|
|
|
|
price = 0
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
// Minimum skills to be able to equip this
|
2017-04-20 21:20:50 +00:00
|
|
|
requirements: { [key: string]: number } = {}
|
2015-02-06 00:00:00 +00:00
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
// Permanent effects on the ship that equips this
|
2017-04-20 21:20:50 +00:00
|
|
|
effects: BaseEffect[] = []
|
2015-01-22 00:00:00 +00:00
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
// Action available when equipped
|
2017-04-20 21:20:50 +00:00
|
|
|
action = new BaseAction("nothing", "Do nothing", false)
|
2015-01-22 00:00:00 +00:00
|
|
|
|
2017-04-24 17:59:16 +00:00
|
|
|
// Equipment wear due to usage in battles (will lower the sell price)
|
|
|
|
wear = 0
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2017-05-16 23:12:05 +00:00
|
|
|
// Cooldown needed by the equipment
|
|
|
|
cooldown = new Cooldown()
|
|
|
|
|
2015-01-22 00:00:00 +00:00
|
|
|
// Basic constructor
|
2017-03-22 21:16:59 +00:00
|
|
|
constructor(slot: SlotType | null = null, code = "equipment") {
|
2017-04-18 19:51:23 +00:00
|
|
|
this.slot_type = slot;
|
2015-02-20 00:00:00 +00:00
|
|
|
this.code = code;
|
|
|
|
this.name = code;
|
2015-01-22 00:00:00 +00:00
|
|
|
}
|
2015-02-06 00:00:00 +00:00
|
|
|
|
2017-03-14 17:48:04 +00:00
|
|
|
jasmineToString() {
|
2017-07-31 18:17:43 +00:00
|
|
|
return this.attached_to ? `${this.attached_to.ship.getFullName()} - ${this.name}` : this.name;
|
2017-03-14 17:48:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 22:55:59 +00:00
|
|
|
/**
|
|
|
|
* Get the fully qualified name (e.g. "Level 4 Strong Ray of Death")
|
|
|
|
*/
|
|
|
|
getFullName(): string {
|
|
|
|
let name = this.name;
|
|
|
|
if (this.quality != EquipmentQuality.COMMON) {
|
|
|
|
name = capitalize(EquipmentQuality[this.quality].toLowerCase()) + " " + name;
|
|
|
|
}
|
2017-05-28 22:24:41 +00:00
|
|
|
return `${name} Mk${this.level}`;
|
2017-04-18 22:55:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the full textual description for this equipment (without the full name).
|
|
|
|
*/
|
|
|
|
getFullDescription(): string {
|
2017-04-20 21:20:50 +00:00
|
|
|
let requirements: string[] = [];
|
2017-05-02 21:33:58 +00:00
|
|
|
iteritems(this.requirements, (skill: keyof ShipAttributes, value) => {
|
2017-04-20 21:20:50 +00:00
|
|
|
if (value > 0) {
|
2017-05-10 17:48:28 +00:00
|
|
|
requirements.push(`• ${SHIP_ATTRIBUTES[skill].name} ${value}`);
|
2017-04-20 21:20:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-18 22:55:59 +00:00
|
|
|
let description = this.getEffectsDescription();
|
|
|
|
if (this.description) {
|
|
|
|
description += "\n\n" + this.description;
|
|
|
|
}
|
2017-04-20 21:20:50 +00:00
|
|
|
if (requirements.length > 0) {
|
|
|
|
description = "Requires:\n" + requirements.join("\n") + "\n\n" + description;
|
|
|
|
}
|
2017-05-16 23:12:05 +00:00
|
|
|
if (this.cooldown.overheat > 0) {
|
|
|
|
description = `${this.cooldown}\n\n${description}`;
|
|
|
|
}
|
2017-04-24 17:59:16 +00:00
|
|
|
if (this.wear > 0) {
|
|
|
|
description = (this.wear >= 100 ? "Worn" : "Second hand") + "\n\n" + description;
|
|
|
|
}
|
2017-04-18 22:55:59 +00:00
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Get the minimum level at which the requirements in skill may be fulfilled.
|
|
|
|
*
|
|
|
|
* This is informative and is not directly enforced. It will only be enforced by skills requirements.
|
|
|
|
*/
|
|
|
|
getMinimumLevel(): number {
|
|
|
|
let points = sum(values(this.requirements));
|
|
|
|
return ShipLevel.getLevelForPoints(points);
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:20:50 +00:00
|
|
|
/**
|
|
|
|
* Get the equipment price value.
|
|
|
|
*/
|
|
|
|
getPrice(): number {
|
2017-04-24 17:59:16 +00:00
|
|
|
return Math.floor(this.price * 100 / (100 + this.wear));
|
2017-04-20 21:20:50 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
2017-04-25 23:27:42 +00:00
|
|
|
* Returns true if the equipment can be equipped on a ship with given skills.
|
2017-04-18 19:51:23 +00:00
|
|
|
*
|
2017-05-02 21:33:58 +00:00
|
|
|
* This checks *requirements* against the effective (modified) skills.
|
2017-04-18 19:51:23 +00:00
|
|
|
*
|
|
|
|
* This does not check where the equipment currently is (except if is it already attached and should be detached first).
|
|
|
|
*/
|
2017-04-25 23:27:42 +00:00
|
|
|
canBeEquipped(skills: ShipAttributes): boolean {
|
2015-02-13 00:00:00 +00:00
|
|
|
if (this.attached_to) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
var able = true;
|
2017-05-02 21:33:58 +00:00
|
|
|
iteritems(this.requirements, (attr: keyof ShipAttributes, minvalue) => {
|
2017-04-25 23:27:42 +00:00
|
|
|
if (skills[attr].get() < minvalue) {
|
2015-02-13 00:00:00 +00:00
|
|
|
able = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return able;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Detach from the slot it is attached to
|
|
|
|
*/
|
2015-02-13 00:00:00 +00:00
|
|
|
detach(): void {
|
|
|
|
if (this.attached_to) {
|
|
|
|
this.attached_to.attached = null;
|
|
|
|
this.attached_to = null;
|
|
|
|
}
|
2015-02-06 00:00:00 +00:00
|
|
|
}
|
2017-01-17 00:02:38 +00:00
|
|
|
|
2017-04-18 19:51:23 +00:00
|
|
|
/**
|
|
|
|
* Get a human readable description of the effects of this equipment
|
|
|
|
*/
|
2017-04-18 22:55:59 +00:00
|
|
|
getEffectsDescription(): string {
|
2017-04-18 19:51:23 +00:00
|
|
|
let parts: string[] = [];
|
|
|
|
|
2017-04-18 22:55:59 +00:00
|
|
|
if (this.effects.length > 0) {
|
2017-05-10 17:48:28 +00:00
|
|
|
parts.push(["When equipped:"].concat(this.effects.map(effect => "• " + effect.getDescription())).join("\n"));
|
2017-04-18 22:55:59 +00:00
|
|
|
}
|
2017-04-18 19:51:23 +00:00
|
|
|
|
2017-04-18 22:55:59 +00:00
|
|
|
let action_desc = this.action.getEffectsDescription();
|
|
|
|
if (action_desc != "") {
|
|
|
|
parts.push(action_desc);
|
|
|
|
}
|
2017-04-18 19:51:23 +00:00
|
|
|
|
2017-04-18 22:55:59 +00:00
|
|
|
return parts.length > 0 ? parts.join("\n\n") : "does nothing";
|
2017-01-17 00:02:38 +00:00
|
|
|
}
|
2017-04-24 17:59:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add equipment wear
|
|
|
|
*/
|
|
|
|
addWear(factor: number): void {
|
|
|
|
this.wear += factor;
|
|
|
|
}
|
2015-01-13 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|