UNPKG

camelot-unchained

Version:
125 lines (110 loc) 4.14 kB
"use strict"; /** * EquippedGear */ var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var EquippedGear = function () { function EquippedGear() { var equippedgear = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; _classCallCheck(this, EquippedGear); this.items = equippedgear.items || []; } /** * Get the item in specific gear slot * @param {gearSlot} slot - the gear slot to get item for * @return {Item} the item in gear slot, or null if there is no item equipped */ _createClass(EquippedGear, [{ key: "getItemInGearSlot", value: function getItemInGearSlot(slot) { var gearSlotItems = this.items.filter(function (item) { return item.gearSlot == slot; }); if (gearSlotItems.length > 0) { return gearSlotItems[0]; } else { return null; } } /** * Check if the equippedgear contains an item * @param {string} id - the id of item to look for * @return {boolean} returns true if the item existing in the equippedgear */ }, { key: "hasItem", value: function hasItem(id) { return this.items.filter(function (item) { return item.id == id; }).length > 0; } /** * Removes an item from given gear slot * @param {gearSlot} slot the gear slot to remove item from */ }, { key: "removeItemInGearSlot", value: function removeItemInGearSlot(slot) { var _this = this; var ids = []; this.items.forEach(function (item) { if (item.gearSlot == slot) { ids.push(item.id); } }); ids.forEach(function (id) { _this.removeItem(id); }); } /** * Adds an item to the equippedgear * @param {Item} item - the item to add to equippedgear */ }, { key: "addItem", value: function addItem(item) { this.removeItemInGearSlot(item.gearSlot); this.items.push(item); } /** * Removes an item from the equippedgear with the given item id * @param {string} id - the item id to remove */ }, { key: "removeItem", value: function removeItem(id) { var itemIndex = null; this.items.forEach(function (item, index) { if (item.id == id) { itemIndex = index; } }); if (itemIndex != null) { this.items.splice(itemIndex, 1); } } /** * Get a list of all item ID's currently in the equippedgear * @return {string[]} an array of item ID's */ }, { key: "getItemIDs", value: function getItemIDs() { var itemIDs = []; this.items.forEach(function (item) { itemIDs.push(item.id); }); return itemIDs; } }], [{ key: "create", value: function create() { var a = new EquippedGear(); return a; } }]); return EquippedGear; }(); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = EquippedGear;