@armoury/fivem-roleplay-gamemode-common 1.0.46 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/cjs/shared/models/house/house.js +13 -8
  2. package/dist/cjs/shared/models/index.js +4 -2
  3. package/dist/cjs/shared/models/items/deprecated/clothing/clothing-item.js +60 -0
  4. package/dist/cjs/shared/models/items/deprecated/clothing/index.js +17 -0
  5. package/dist/cjs/shared/models/items/deprecated/errors/index.js +17 -0
  6. package/dist/cjs/shared/models/items/deprecated/errors/item-error-base.js +29 -0
  7. package/dist/cjs/shared/models/items/deprecated/errors/item-errors.js +35 -0
  8. package/dist/cjs/shared/models/items/deprecated/errors/item-stash-error-base.js +29 -0
  9. package/dist/cjs/shared/models/items/deprecated/index.js +24 -0
  10. package/dist/cjs/shared/models/items/deprecated/item-stash.model.js +144 -0
  11. package/dist/cjs/shared/models/items/deprecated/item-transfer.model.js +2 -0
  12. package/dist/cjs/shared/models/items/deprecated/item.model.js +26 -0
  13. package/dist/cjs/shared/models/items/deprecated/items-base/index.js +17 -0
  14. package/dist/cjs/shared/models/items/deprecated/items-base/number-item.js +64 -0
  15. package/dist/cjs/shared/models/items/deprecated/stashes-base/generic-stash.js +30 -0
  16. package/dist/cjs/shared/models/items/deprecated/stashes-base/index.js +18 -0
  17. package/dist/cjs/shared/models/items/deprecated/stashes-base/infinite-stash.js +37 -0
  18. package/dist/cjs/shared/models/items/deprecated/weapons/index.js +17 -0
  19. package/dist/cjs/shared/models/items/deprecated/weapons/weapon-item.js +74 -0
  20. package/dist/cjs/shared/models/items/item.js +2 -0
  21. package/dist/cjs/shared/models/stash/stash.js +2 -0
  22. package/dist/esm/shared/models/house/house.js +13 -8
  23. package/dist/esm/shared/models/index.js +4 -2
  24. package/dist/esm/shared/models/items/deprecated/clothing/clothing-item.js +57 -0
  25. package/dist/esm/shared/models/items/deprecated/clothing/index.js +1 -0
  26. package/dist/esm/shared/models/items/deprecated/errors/index.js +1 -0
  27. package/dist/esm/shared/models/items/deprecated/errors/item-error-base.js +26 -0
  28. package/dist/esm/shared/models/items/deprecated/errors/item-errors.js +32 -0
  29. package/dist/esm/shared/models/items/deprecated/errors/item-stash-error-base.js +26 -0
  30. package/dist/esm/shared/models/items/deprecated/index.js +8 -0
  31. package/dist/esm/shared/models/items/deprecated/item-stash.model.js +141 -0
  32. package/dist/esm/shared/models/items/deprecated/item-transfer.model.js +1 -0
  33. package/dist/esm/shared/models/items/deprecated/item.model.js +23 -0
  34. package/dist/esm/shared/models/items/deprecated/items-base/index.js +1 -0
  35. package/dist/esm/shared/models/items/deprecated/items-base/number-item.js +61 -0
  36. package/dist/esm/shared/models/items/deprecated/stashes-base/generic-stash.js +27 -0
  37. package/dist/esm/shared/models/items/deprecated/stashes-base/index.js +2 -0
  38. package/dist/esm/shared/models/items/deprecated/stashes-base/infinite-stash.js +34 -0
  39. package/dist/esm/shared/models/items/deprecated/weapons/index.js +1 -0
  40. package/dist/esm/shared/models/items/deprecated/weapons/weapon-item.js +71 -0
  41. package/dist/esm/shared/models/items/item.js +1 -0
  42. package/dist/esm/shared/models/stash/stash.js +1 -0
  43. package/dist/types/shared/models/house/house.d.ts +2 -2
  44. package/dist/types/shared/models/index.d.ts +4 -2
  45. package/dist/types/shared/models/items/deprecated/clothing/clothing-item.d.ts +25 -0
  46. package/dist/types/shared/models/items/deprecated/clothing/index.d.ts +1 -0
  47. package/dist/types/shared/models/items/deprecated/errors/index.d.ts +1 -0
  48. package/dist/types/shared/models/items/deprecated/errors/item-error-base.d.ts +3 -0
  49. package/dist/types/shared/models/items/deprecated/errors/item-errors.d.ts +7 -0
  50. package/dist/types/shared/models/items/deprecated/errors/item-stash-error-base.d.ts +3 -0
  51. package/dist/types/shared/models/items/deprecated/index.d.ts +8 -0
  52. package/dist/types/shared/models/items/deprecated/item-stash.model.d.ts +53 -0
  53. package/dist/types/shared/models/items/deprecated/item-transfer.model.d.ts +5 -0
  54. package/dist/types/shared/models/items/deprecated/item.model.d.ts +50 -0
  55. package/dist/types/shared/models/items/deprecated/items-base/index.d.ts +1 -0
  56. package/dist/types/shared/models/items/deprecated/items-base/number-item.d.ts +14 -0
  57. package/dist/types/shared/models/items/deprecated/stashes-base/generic-stash.d.ts +7 -0
  58. package/dist/types/shared/models/items/deprecated/stashes-base/index.d.ts +2 -0
  59. package/dist/types/shared/models/items/deprecated/stashes-base/infinite-stash.d.ts +10 -0
  60. package/dist/types/shared/models/items/deprecated/weapons/index.d.ts +1 -0
  61. package/dist/types/shared/models/items/deprecated/weapons/weapon-item.d.ts +18 -0
  62. package/dist/types/shared/models/items/item.d.ts +2 -0
  63. package/dist/types/shared/models/stash/stash.d.ts +13 -0
  64. package/package.json +2 -2
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  exports.House = void 0;
4
15
  var House = /** @class */ (function () {
@@ -15,14 +26,8 @@ var House = /** @class */ (function () {
15
26
  this.sellingPrice = sellingPrice;
16
27
  this.rentPrice = rentPrice;
17
28
  this.requiredLevel = requiredLevel;
18
- this.metadata = metadata;
19
- metadata = {
20
- isOwned: owner != null,
21
- tenants: 0, // TODO: Implement this
22
- maxTenants: 10, // TODO: Implement this
23
- acceptsTenants: true, // TODO: Implement this
24
- address: address,
25
- };
29
+ this.metadata = __assign(__assign({}, (metadata !== null && metadata !== void 0 ? metadata : {})), { isOwned: owner != null, tenants: 0, maxTenants: 10, acceptsTenants: true, // TODO: Implement this
30
+ address: address });
26
31
  }
27
32
  House.toStub = function (house) {
28
33
  return {
@@ -20,9 +20,11 @@ __exportStar(require("./account"), exports);
20
20
  __exportStar(require("./character"), exports);
21
21
  /** Persistable */
22
22
  __exportStar(require("./persistable/persistable"), exports);
23
+ /** Stash */
24
+ __exportStar(require("./stash/stash"), exports);
25
+ /** Item */
26
+ __exportStar(require("./items/item"), exports);
23
27
  /** House */
24
28
  __exportStar(require("./house/house"), exports);
25
- /** Item (Deprecated) */
26
- __exportStar(require("./items"), exports);
27
29
  /** Business (Deprecated) */
28
30
  __exportStar(require("./businesses"), exports);
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Clothing = void 0;
19
+ var item_model_1 = require("../item.model");
20
+ var Clothing = /** @class */ (function (_super) {
21
+ __extends(Clothing, _super);
22
+ function Clothing(_name, _value) {
23
+ if (_value === void 0) { _value = null; }
24
+ var _this = _super.call(this, _name, 1, true, _value) || this;
25
+ _this.amount = 1;
26
+ return _this;
27
+ }
28
+ Object.defineProperty(Clothing.prototype, "weight", {
29
+ get: function () {
30
+ return this.weightPerUnit;
31
+ },
32
+ enumerable: false,
33
+ configurable: true
34
+ });
35
+ Clothing.prototype.add = function (_amount) {
36
+ this.amount = 1;
37
+ return this;
38
+ };
39
+ Clothing.prototype.consume = function (_amount) {
40
+ this.amount = 0;
41
+ return this;
42
+ };
43
+ Clothing.prototype.empty = function () {
44
+ return this.consume(this.weightPerUnit);
45
+ };
46
+ Clothing.prototype.serialize = function () {
47
+ var _a;
48
+ return (_a = {},
49
+ _a[this.identifier] = this.value,
50
+ _a);
51
+ };
52
+ Clothing.prototype.deserialize = function (serialized) {
53
+ var _a = Object.entries(serialized)[0], identifier = _a[0], value = _a[1];
54
+ this.identifier = identifier;
55
+ this.value = value;
56
+ return this;
57
+ };
58
+ return Clothing;
59
+ }(item_model_1.Item));
60
+ exports.Clothing = Clothing;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./clothing-item"), exports);
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./item-errors"), exports);
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ItemError = void 0;
19
+ var ItemError = /** @class */ (function (_super) {
20
+ __extends(ItemError, _super);
21
+ function ItemError(msg) {
22
+ var _newTarget = this.constructor;
23
+ var _this = _super.call(this, msg) || this;
24
+ Object.setPrototypeOf(_this, _newTarget.prototype);
25
+ return _this;
26
+ }
27
+ return ItemError;
28
+ }(Error));
29
+ exports.ItemError = ItemError;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ItemStashGenericError = exports.ItemStashSlotsInsuficientError = void 0;
19
+ var item_stash_error_base_1 = require("./item-stash-error-base");
20
+ var ItemStashSlotsInsuficientError = /** @class */ (function (_super) {
21
+ __extends(ItemStashSlotsInsuficientError, _super);
22
+ function ItemStashSlotsInsuficientError(msg) {
23
+ return _super.call(this, msg !== null && msg !== void 0 ? msg : 'There were insuficient slots to add to the stash.') || this;
24
+ }
25
+ return ItemStashSlotsInsuficientError;
26
+ }(item_stash_error_base_1.ItemStashError));
27
+ exports.ItemStashSlotsInsuficientError = ItemStashSlotsInsuficientError;
28
+ var ItemStashGenericError = /** @class */ (function (_super) {
29
+ __extends(ItemStashGenericError, _super);
30
+ function ItemStashGenericError(msg) {
31
+ return _super.call(this, msg !== null && msg !== void 0 ? msg : 'An unexpected runtime error occured.') || this;
32
+ }
33
+ return ItemStashGenericError;
34
+ }(item_stash_error_base_1.ItemStashError));
35
+ exports.ItemStashGenericError = ItemStashGenericError;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ItemStashError = void 0;
19
+ var ItemStashError = /** @class */ (function (_super) {
20
+ __extends(ItemStashError, _super);
21
+ function ItemStashError(msg) {
22
+ var _newTarget = this.constructor;
23
+ var _this = _super.call(this, msg) || this;
24
+ Object.setPrototypeOf(_this, _newTarget.prototype);
25
+ return _this;
26
+ }
27
+ return ItemStashError;
28
+ }(Error));
29
+ exports.ItemStashError = ItemStashError;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./item-stash.model"), exports);
18
+ __exportStar(require("./item.model"), exports);
19
+ __exportStar(require("./item-transfer.model"), exports);
20
+ __exportStar(require("./items-base"), exports);
21
+ __exportStar(require("./stashes-base"), exports);
22
+ __exportStar(require("./errors"), exports);
23
+ __exportStar(require("./clothing"), exports);
24
+ __exportStar(require("./weapons"), exports);
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ItemStash = void 0;
15
+ var errors_1 = require("./errors");
16
+ var ItemStash = /** @class */ (function () {
17
+ function ItemStash(name, slots, weightPerSlot) {
18
+ this.name = name;
19
+ this.slots = slots;
20
+ this.weightPerSlot = weightPerSlot;
21
+ this._items = new Map();
22
+ }
23
+ Object.defineProperty(ItemStash.prototype, "items", {
24
+ get: function () {
25
+ return Array.from(this._items.values());
26
+ },
27
+ enumerable: false,
28
+ configurable: true
29
+ });
30
+ ;
31
+ ItemStash.prototype.add = function (item, slot) {
32
+ var _this = this;
33
+ var clone = ItemStash.clone(this); // Creates a clone to operate onto, instead of altering the original map
34
+ var consumedWeight = 0;
35
+ var weightToConsume = item.weight;
36
+ if (!item.fullyOccupiesSlot) {
37
+ // If there are existing slots with this item, fill them
38
+ Array.from(clone._items.entries()).forEach(function (_a) {
39
+ var existingSlot = _a[0], existingItem = _a[1];
40
+ if (consumedWeight < weightToConsume && existingItem.identifier === item.identifier) {
41
+ consumedWeight += ItemStash.addToSlot(clone, item.empty().add(Math.round((weightToConsume - consumedWeight) / item.weightPerUnit)), existingSlot);
42
+ }
43
+ });
44
+ }
45
+ // If the added item is not yet fully transferred, find a new slot to put the remaining amount into
46
+ var attempts = 0;
47
+ while (consumedWeight < weightToConsume) {
48
+ if (consumedWeight < weightToConsume && clone._items.size >= clone.slots) {
49
+ throw new errors_1.ItemStashSlotsInsuficientError();
50
+ }
51
+ attempts++;
52
+ if (attempts >= this.slots) {
53
+ throw new errors_1.ItemStashGenericError();
54
+ }
55
+ consumedWeight += ItemStash.addToSlot(clone, item.empty().add(Math.round((weightToConsume - consumedWeight) / item.weightPerUnit)), clone._items.size);
56
+ }
57
+ // If everything went well, propagate the modification into the original map
58
+ Array.from(clone._items.entries()).forEach(function (_a) {
59
+ var slot = _a[0], item = _a[1];
60
+ _this._items.set(slot, item);
61
+ });
62
+ return true;
63
+ };
64
+ ItemStash.prototype.consume = function (item, amount) {
65
+ var _this = this;
66
+ var consumedAmount = 0;
67
+ if (amount >= item.amount) {
68
+ var slot = Array.from(this._items.entries()).find(function (_a) {
69
+ var existingItem = _a[1];
70
+ return existingItem.identifier === item.identifier;
71
+ })[0];
72
+ if (slot != null) {
73
+ this._items.delete(slot);
74
+ }
75
+ }
76
+ else {
77
+ Array.from(this._items.entries()).reverse().forEach(function (_a) {
78
+ var existingSlot = _a[0], existingItem = _a[1];
79
+ if (consumedAmount < amount && item.identifier === existingItem.identifier) {
80
+ var amountRemoved = ItemStash.removeFromSlot(_this, existingSlot, amount - consumedAmount);
81
+ consumedAmount += amountRemoved;
82
+ }
83
+ });
84
+ }
85
+ };
86
+ ItemStash.prototype.has = function (itemIdentifier) {
87
+ return Array.from(this._items.values()).some(function (item) { return item.identifier === itemIdentifier; });
88
+ };
89
+ ItemStash.prototype.serialize = function () {
90
+ return this.items.reduce(function (prev, curr) { return (__assign(__assign({}, prev), curr.serialize())); }, {});
91
+ };
92
+ ItemStash.prototype.toUI = function () {
93
+ return ({
94
+ title: this.name,
95
+ items: Array.from(this._items.entries())
96
+ .map(function (_a) {
97
+ var slot = _a[0], item = _a[1];
98
+ return item.toUI(slot);
99
+ })
100
+ });
101
+ };
102
+ /**
103
+ * Adds an item to a stash.
104
+ * @param stash Stash to add the item to
105
+ * @param item Item to add to the stash
106
+ * @param slot The slot where the item should be placed into
107
+ * @returns Weight added to the stash
108
+ */
109
+ ItemStash.addToSlot = function (stash, item, slot) {
110
+ var _a;
111
+ var existingWeightOfThisItem = ((_a = stash._items.get(slot)) === null || _a === void 0 ? void 0 : _a.weight) || 0;
112
+ var availableWeightInThisSlot = stash.weightPerSlot - existingWeightOfThisItem;
113
+ var weightToBeAdded = Math.max(1, Math.min(availableWeightInThisSlot, item.weight));
114
+ stash._items.set(slot, item.empty().add(Math.round((existingWeightOfThisItem + weightToBeAdded) / item.weightPerUnit)));
115
+ return weightToBeAdded;
116
+ };
117
+ /**
118
+ * Removes an X amount of whichever item lies in the specified slot
119
+ * @param stash Stash to remove the amount of the item from
120
+ * @param slot Slot of the stash which will have this amount of the item removed
121
+ * @param amount The amount of the item to be removed
122
+ * @returns The amount that has been removed (the amount in the slot can be lower than the provided amount-to-be-removed)
123
+ */
124
+ ItemStash.removeFromSlot = function (stash, slot, amount) {
125
+ var _a;
126
+ var existingAmountOfThisItem = ((_a = stash._items.get(slot)) === null || _a === void 0 ? void 0 : _a.amount) || 0;
127
+ if (!existingAmountOfThisItem || !stash._items.get(slot)) {
128
+ return 0;
129
+ }
130
+ var amountToBeConsumed = Math.min(existingAmountOfThisItem, amount);
131
+ stash._items.set(slot, stash._items.get(slot).consume(amountToBeConsumed));
132
+ return amountToBeConsumed;
133
+ };
134
+ ItemStash.clone = function (stash) {
135
+ var clone = new ItemStash(stash.name, stash.slots, stash.weightPerSlot);
136
+ Array.from(stash._items.entries()).forEach(function (_a) {
137
+ var slot = _a[0], item = _a[1];
138
+ clone._items.set(slot, item);
139
+ });
140
+ return clone;
141
+ };
142
+ return ItemStash;
143
+ }());
144
+ exports.ItemStash = ItemStash;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Item = void 0;
4
+ var Item = /** @class */ (function () {
5
+ function Item(identifier, weightPerUnit, fullyOccupiesSlot, value) {
6
+ this.identifier = identifier;
7
+ this.weightPerUnit = weightPerUnit;
8
+ this.fullyOccupiesSlot = fullyOccupiesSlot;
9
+ this.value = value;
10
+ this.fullyOccupiesSlot = fullyOccupiesSlot !== null && fullyOccupiesSlot !== void 0 ? fullyOccupiesSlot : false;
11
+ }
12
+ Item.prototype.toUI = function (slot) {
13
+ return ({
14
+ image: this.identifier,
15
+ type: 'item',
16
+ description: 'Just an inventory item.',
17
+ topLeft: '',
18
+ bottomRight: JSON.stringify(this.value),
19
+ _piKey: '', // TODO: Can we remove this?
20
+ outline: '#878b9f',
21
+ width: 65,
22
+ });
23
+ };
24
+ return Item;
25
+ }());
26
+ exports.Item = Item;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./number-item"), exports);
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.NumberItem = void 0;
19
+ var item_model_1 = require("../item.model");
20
+ var NumberItem = /** @class */ (function (_super) {
21
+ __extends(NumberItem, _super);
22
+ function NumberItem() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ Object.defineProperty(NumberItem.prototype, "amount", {
26
+ get: function () {
27
+ return this.value;
28
+ },
29
+ enumerable: false,
30
+ configurable: true
31
+ });
32
+ Object.defineProperty(NumberItem.prototype, "weight", {
33
+ get: function () {
34
+ return this.value * this.weightPerUnit;
35
+ },
36
+ enumerable: false,
37
+ configurable: true
38
+ });
39
+ NumberItem.prototype.add = function (amount) {
40
+ this.value = Math.max(0, this.value + amount);
41
+ return this;
42
+ };
43
+ NumberItem.prototype.consume = function (amount) {
44
+ return this.add(-amount);
45
+ };
46
+ NumberItem.prototype.empty = function () {
47
+ this.value = 0;
48
+ return this;
49
+ };
50
+ NumberItem.prototype.serialize = function () {
51
+ var _a;
52
+ return (_a = {},
53
+ _a[this.identifier] = this.value,
54
+ _a);
55
+ };
56
+ NumberItem.prototype.deserialize = function (serialized) {
57
+ var _a = Object.entries(serialized)[0], identifier = _a[0], value = _a[1];
58
+ this.identifier = identifier;
59
+ this.value = value;
60
+ return this;
61
+ };
62
+ return NumberItem;
63
+ }(item_model_1.Item));
64
+ exports.NumberItem = NumberItem;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.GenericStash = void 0;
19
+ var item_stash_model_1 = require("../item-stash.model");
20
+ var GenericStash = /** @class */ (function (_super) {
21
+ __extends(GenericStash, _super); /* implements IItemStash<IItemBase>*/
22
+ function GenericStash() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ GenericStash.prototype.deserialize = function (serialized) {
26
+ throw new Error("Method not implemented.");
27
+ };
28
+ return GenericStash;
29
+ }(item_stash_model_1.ItemStash));
30
+ exports.GenericStash = GenericStash;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./generic-stash"), exports);
18
+ __exportStar(require("./infinite-stash"), exports);
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.InfiniteStash = void 0;
19
+ var item_stash_model_1 = require("../item-stash.model");
20
+ var InfiniteStash = /** @class */ (function (_super) {
21
+ __extends(InfiniteStash, _super); /* implements IItemStash<IItemBase>*/
22
+ function InfiniteStash() {
23
+ return _super !== null && _super.apply(this, arguments) || this;
24
+ }
25
+ InfiniteStash.prototype.add = function (_item, slot) {
26
+ return true;
27
+ };
28
+ InfiniteStash.prototype.consume = function (_item, _amount) { };
29
+ InfiniteStash.prototype.has = function (_itemIdentifier) {
30
+ return true;
31
+ };
32
+ InfiniteStash.prototype.deserialize = function (serialized) {
33
+ throw new Error("Method not implemented.");
34
+ };
35
+ return InfiniteStash;
36
+ }(item_stash_model_1.ItemStash));
37
+ exports.InfiniteStash = InfiniteStash;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./weapon-item"), exports);