@armoury/fivem-roleplay-gamemode-common 1.0.54 → 1.0.56

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 (33) hide show
  1. package/dist/cjs/shared/models/account/account.js +3 -4
  2. package/dist/cjs/shared/models/businesses/business.model.js +3 -4
  3. package/dist/cjs/shared/models/character/character.js +3 -4
  4. package/dist/cjs/shared/models/house/house.js +13 -22
  5. package/dist/cjs/shared/models/items/deprecated/clothing/clothing-item.js +23 -47
  6. package/dist/cjs/shared/models/items/deprecated/errors/item-error-base.js +5 -24
  7. package/dist/cjs/shared/models/items/deprecated/errors/item-errors.js +9 -28
  8. package/dist/cjs/shared/models/items/deprecated/errors/item-stash-error-base.js +5 -24
  9. package/dist/cjs/shared/models/items/deprecated/item-stash.model.js +45 -75
  10. package/dist/cjs/shared/models/items/deprecated/item.model.js +6 -7
  11. package/dist/cjs/shared/models/items/deprecated/items-base/number-item.js +22 -51
  12. package/dist/cjs/shared/models/items/deprecated/stashes-base/generic-stash.js +5 -25
  13. package/dist/cjs/shared/models/items/deprecated/stashes-base/infinite-stash.js +10 -30
  14. package/dist/cjs/shared/models/items/deprecated/weapons/weapon-item.js +26 -63
  15. package/dist/cjs/shared/models/persistable/persistable.js +3 -5
  16. package/dist/cjs/shared/models/stash/stash.js +4 -7
  17. package/dist/esm/shared/models/account/account.js +3 -5
  18. package/dist/esm/shared/models/businesses/business.model.js +3 -5
  19. package/dist/esm/shared/models/character/character.js +3 -5
  20. package/dist/esm/shared/models/house/house.js +13 -23
  21. package/dist/esm/shared/models/items/deprecated/clothing/clothing-item.js +22 -47
  22. package/dist/esm/shared/models/items/deprecated/errors/item-error-base.js +5 -25
  23. package/dist/esm/shared/models/items/deprecated/errors/item-errors.js +8 -29
  24. package/dist/esm/shared/models/items/deprecated/errors/item-stash-error-base.js +5 -25
  25. package/dist/esm/shared/models/items/deprecated/item-stash.model.js +44 -75
  26. package/dist/esm/shared/models/items/deprecated/item.model.js +6 -8
  27. package/dist/esm/shared/models/items/deprecated/items-base/number-item.js +21 -51
  28. package/dist/esm/shared/models/items/deprecated/stashes-base/generic-stash.js +4 -25
  29. package/dist/esm/shared/models/items/deprecated/stashes-base/infinite-stash.js +9 -30
  30. package/dist/esm/shared/models/items/deprecated/weapons/weapon-item.js +25 -63
  31. package/dist/esm/shared/models/persistable/persistable.js +3 -6
  32. package/dist/esm/shared/models/stash/stash.js +4 -8
  33. package/package.json +28 -28
@@ -1,37 +1,17 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  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) {
4
+ const item_stash_model_1 = require("../item-stash.model");
5
+ class InfiniteStash extends item_stash_model_1.ItemStash /* implements IItemStash<IItemBase>*/ {
6
+ add(_item, slot) {
26
7
  return true;
27
- };
28
- InfiniteStash.prototype.consume = function (_item, _amount) { };
29
- InfiniteStash.prototype.has = function (_itemIdentifier) {
8
+ }
9
+ consume(_item, _amount) { }
10
+ has(_itemIdentifier) {
30
11
  return true;
31
- };
32
- InfiniteStash.prototype.deserialize = function (serialized) {
12
+ }
13
+ deserialize(serialized) {
33
14
  throw new Error("Method not implemented.");
34
- };
35
- return InfiniteStash;
36
- }(item_stash_model_1.ItemStash));
15
+ }
16
+ }
37
17
  exports.InfiniteStash = InfiniteStash;
@@ -1,74 +1,37 @@
1
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
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
2
  Object.defineProperty(exports, "__esModule", { value: true });
29
3
  exports.WeaponItem = void 0;
30
- var item_model_1 = require("../item.model");
31
- var WeaponItem = /** @class */ (function (_super) {
32
- __extends(WeaponItem, _super);
33
- function WeaponItem() {
34
- return _super !== null && _super.apply(this, arguments) || this;
4
+ const item_model_1 = require("../item.model");
5
+ class WeaponItem extends item_model_1.Item {
6
+ get amount() {
7
+ return this.value.ammo;
35
8
  }
36
- Object.defineProperty(WeaponItem.prototype, "amount", {
37
- get: function () {
38
- return this.value.ammo;
39
- },
40
- enumerable: false,
41
- configurable: true
42
- });
43
- Object.defineProperty(WeaponItem.prototype, "weight", {
44
- get: function () {
45
- return this.amount * this.weightPerUnit;
46
- },
47
- enumerable: false,
48
- configurable: true
49
- });
50
- WeaponItem.prototype.add = function (amount) {
51
- this.value = __assign(__assign({}, this.value), { ammo: Math.max(0, this.value.ammo + amount) });
9
+ get weight() {
10
+ return this.amount * this.weightPerUnit;
11
+ }
12
+ add(amount) {
13
+ this.value = {
14
+ ...this.value,
15
+ ammo: Math.max(0, this.value.ammo + amount)
16
+ };
52
17
  return this;
53
- };
54
- WeaponItem.prototype.consume = function (amount) {
18
+ }
19
+ consume(amount) {
55
20
  return this.add(-amount);
56
- };
57
- WeaponItem.prototype.empty = function () {
21
+ }
22
+ empty() {
58
23
  return this.add(-this.value.ammo);
59
- };
60
- WeaponItem.prototype.serialize = function () {
61
- var _a;
62
- return (_a = {},
63
- _a[this.identifier] = this.value,
64
- _a);
65
- };
66
- WeaponItem.prototype.deserialize = function (serialized) {
67
- var _a = Object.entries(serialized)[0], identifier = _a[0], value = _a[1];
24
+ }
25
+ serialize() {
26
+ return ({
27
+ [this.identifier]: this.value
28
+ });
29
+ }
30
+ deserialize(serialized) {
31
+ const [identifier, value] = Object.entries(serialized)[0];
68
32
  this.identifier = identifier;
69
33
  this.value = value;
70
34
  return this;
71
- };
72
- return WeaponItem;
73
- }(item_model_1.Item));
35
+ }
36
+ }
74
37
  exports.WeaponItem = WeaponItem;
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Persistable = void 0;
4
- var Persistable = /** @class */ (function () {
5
- function Persistable(id, owner, position, rotation) {
6
- if (rotation === void 0) { rotation = { x: 0, y: 0, z: 0 }; }
4
+ class Persistable {
5
+ constructor(id, owner, position, rotation = { x: 0, y: 0, z: 0 }) {
7
6
  this.id = id;
8
7
  this.owner = owner;
9
8
  this.position = position;
10
9
  this.rotation = rotation;
11
10
  }
12
- return Persistable;
13
- }());
11
+ }
14
12
  exports.Persistable = Persistable;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Stash = void 0;
4
- var Stash = /** @class */ (function () {
5
- function Stash() {
6
- }
7
- Stash.toStub = function (stash) {
4
+ class Stash {
5
+ static toStub(stash) {
8
6
  return {
9
7
  id: stash.id,
10
8
  maxSlots: stash.maxSlots,
@@ -12,7 +10,6 @@ var Stash = /** @class */ (function () {
12
10
  type: stash.type,
13
11
  slots: stash.slots,
14
12
  };
15
- };
16
- return Stash;
17
- }());
13
+ }
14
+ }
18
15
  exports.Stash = Stash;
@@ -1,10 +1,8 @@
1
- var Account = /** @class */ (function () {
2
- function Account(id, lastKnownName, platformId, email) {
1
+ export class Account {
2
+ constructor(id, lastKnownName, platformId, email) {
3
3
  this.id = id;
4
4
  this.lastKnownName = lastKnownName;
5
5
  this.platformId = platformId;
6
6
  this.email = email;
7
7
  }
8
- return Account;
9
- }());
10
- export { Account };
8
+ }
@@ -1,9 +1,7 @@
1
- var Business = /** @class */ (function () {
2
- function Business(data) {
1
+ export class Business {
2
+ constructor(data) {
3
3
  if (data) {
4
4
  Object.assign(this, data);
5
5
  }
6
6
  }
7
- return Business;
8
- }());
9
- export { Business };
7
+ }
@@ -1,5 +1,5 @@
1
- var Character = /** @class */ (function () {
2
- function Character(id, accountId, hoursPlayed, language, firstName, lastName, lastLogoutPosition, lastLogoutRotation, lastActivity) {
1
+ export class Character {
2
+ constructor(id, accountId, hoursPlayed, language, firstName, lastName, lastLogoutPosition, lastLogoutRotation, lastActivity) {
3
3
  this.id = id;
4
4
  this.accountId = accountId;
5
5
  this.hoursPlayed = hoursPlayed;
@@ -10,6 +10,4 @@ var Character = /** @class */ (function () {
10
10
  this.lastLogoutRotation = lastLogoutRotation;
11
11
  this.lastActivity = lastActivity;
12
12
  }
13
- return Character;
14
- }());
15
- export { Character };
13
+ }
@@ -1,19 +1,5 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var House = /** @class */ (function () {
13
- function House(id, owner, entrance, exit, originalValue, address, sellingPrice, rentPrice, requiredLevel, metadata) {
14
- if (sellingPrice === void 0) { sellingPrice = 0; }
15
- if (rentPrice === void 0) { rentPrice = 0; }
16
- if (requiredLevel === void 0) { requiredLevel = 1; }
1
+ export class House {
2
+ constructor(id, owner, entrance, exit, originalValue, address, sellingPrice = 0, rentPrice = 0, requiredLevel = 1, metadata) {
17
3
  this.id = id;
18
4
  this.owner = owner;
19
5
  this.entrance = entrance;
@@ -23,10 +9,16 @@ var House = /** @class */ (function () {
23
9
  this.sellingPrice = sellingPrice;
24
10
  this.rentPrice = rentPrice;
25
11
  this.requiredLevel = requiredLevel;
26
- this.metadata = __assign(__assign({}, (metadata !== null && metadata !== void 0 ? metadata : {})), { isOwned: owner != null, tenants: 0, maxTenants: 10, acceptsTenants: true, // TODO: Implement this
27
- address: address });
12
+ this.metadata = {
13
+ ...(metadata ?? {}),
14
+ isOwned: owner != null,
15
+ tenants: 0, // TODO: Implement this
16
+ maxTenants: 10, // TODO: Implement this
17
+ acceptsTenants: true, // TODO: Implement this
18
+ address,
19
+ };
28
20
  }
29
- House.toStub = function (house) {
21
+ static toStub(house) {
30
22
  return {
31
23
  id: house.id,
32
24
  sellingPrice: house.sellingPrice,
@@ -34,7 +26,5 @@ var House = /** @class */ (function () {
34
26
  requiredLevel: house.requiredLevel,
35
27
  metadata: house.metadata,
36
28
  };
37
- };
38
- return House;
39
- }());
40
- export { House };
29
+ }
30
+ }
@@ -1,57 +1,32 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
1
  import { Item } from "../item.model";
17
- var Clothing = /** @class */ (function (_super) {
18
- __extends(Clothing, _super);
19
- function Clothing(_name, _value) {
20
- if (_value === void 0) { _value = null; }
21
- var _this = _super.call(this, _name, 1, true, _value) || this;
22
- _this.amount = 1;
23
- return _this;
2
+ export class Clothing extends Item {
3
+ get weight() {
4
+ return this.weightPerUnit;
24
5
  }
25
- Object.defineProperty(Clothing.prototype, "weight", {
26
- get: function () {
27
- return this.weightPerUnit;
28
- },
29
- enumerable: false,
30
- configurable: true
31
- });
32
- Clothing.prototype.add = function (_amount) {
6
+ constructor(_name, _value = null) {
7
+ super(_name, 1, true, _value);
8
+ this.amount = 1;
9
+ }
10
+ add(_amount) {
33
11
  this.amount = 1;
34
12
  return this;
35
- };
36
- Clothing.prototype.consume = function (_amount) {
13
+ }
14
+ consume(_amount) {
37
15
  this.amount = 0;
38
16
  return this;
39
- };
40
- Clothing.prototype.empty = function () {
17
+ }
18
+ empty() {
41
19
  return this.consume(this.weightPerUnit);
42
- };
43
- Clothing.prototype.serialize = function () {
44
- var _a;
45
- return (_a = {},
46
- _a[this.identifier] = this.value,
47
- _a);
48
- };
49
- Clothing.prototype.deserialize = function (serialized) {
50
- var _a = Object.entries(serialized)[0], identifier = _a[0], value = _a[1];
20
+ }
21
+ serialize() {
22
+ return ({
23
+ [this.identifier]: this.value
24
+ });
25
+ }
26
+ deserialize(serialized) {
27
+ const [identifier, value] = Object.entries(serialized)[0];
51
28
  this.identifier = identifier;
52
29
  this.value = value;
53
30
  return this;
54
- };
55
- return Clothing;
56
- }(Item));
57
- export { Clothing };
31
+ }
32
+ }
@@ -1,26 +1,6 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var ItemError = /** @class */ (function (_super) {
17
- __extends(ItemError, _super);
18
- function ItemError(msg) {
19
- var _newTarget = this.constructor;
20
- var _this = _super.call(this, msg) || this;
21
- Object.setPrototypeOf(_this, _newTarget.prototype);
22
- return _this;
1
+ export class ItemError extends Error {
2
+ constructor(msg) {
3
+ super(msg);
4
+ Object.setPrototypeOf(this, new.target.prototype);
23
5
  }
24
- return ItemError;
25
- }(Error));
26
- export { ItemError };
6
+ }
@@ -1,32 +1,11 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
1
  import { ItemStashError } from "./item-stash-error-base";
17
- var ItemStashSlotsInsuficientError = /** @class */ (function (_super) {
18
- __extends(ItemStashSlotsInsuficientError, _super);
19
- function ItemStashSlotsInsuficientError(msg) {
20
- return _super.call(this, msg !== null && msg !== void 0 ? msg : 'There were insuficient slots to add to the stash.') || this;
2
+ export class ItemStashSlotsInsuficientError extends ItemStashError {
3
+ constructor(msg) {
4
+ super(msg ?? 'There were insuficient slots to add to the stash.');
21
5
  }
22
- return ItemStashSlotsInsuficientError;
23
- }(ItemStashError));
24
- export { ItemStashSlotsInsuficientError };
25
- var ItemStashGenericError = /** @class */ (function (_super) {
26
- __extends(ItemStashGenericError, _super);
27
- function ItemStashGenericError(msg) {
28
- return _super.call(this, msg !== null && msg !== void 0 ? msg : 'An unexpected runtime error occured.') || this;
6
+ }
7
+ export class ItemStashGenericError extends ItemStashError {
8
+ constructor(msg) {
9
+ super(msg ?? 'An unexpected runtime error occured.');
29
10
  }
30
- return ItemStashGenericError;
31
- }(ItemStashError));
32
- export { ItemStashGenericError };
11
+ }
@@ -1,26 +1,6 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
- return extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- if (typeof b !== "function" && b !== null)
10
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
- extendStatics(d, b);
12
- function __() { this.constructor = d; }
13
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
- };
15
- })();
16
- var ItemStashError = /** @class */ (function (_super) {
17
- __extends(ItemStashError, _super);
18
- function ItemStashError(msg) {
19
- var _newTarget = this.constructor;
20
- var _this = _super.call(this, msg) || this;
21
- Object.setPrototypeOf(_this, _newTarget.prototype);
22
- return _this;
1
+ export class ItemStashError extends Error {
2
+ constructor(msg) {
3
+ super(msg);
4
+ Object.setPrototypeOf(this, new.target.prototype);
23
5
  }
24
- return ItemStashError;
25
- }(Error));
26
- export { ItemStashError };
6
+ }
@@ -1,46 +1,29 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  import { ItemStashGenericError, ItemStashSlotsInsuficientError } from "./errors";
13
- var ItemStash = /** @class */ (function () {
14
- function ItemStash(name, slots, weightPerSlot) {
2
+ export class ItemStash {
3
+ get items() {
4
+ return Array.from(this._items.values());
5
+ }
6
+ ;
7
+ constructor(name, slots, weightPerSlot) {
15
8
  this.name = name;
16
9
  this.slots = slots;
17
10
  this.weightPerSlot = weightPerSlot;
18
11
  this._items = new Map();
19
12
  }
20
- Object.defineProperty(ItemStash.prototype, "items", {
21
- get: function () {
22
- return Array.from(this._items.values());
23
- },
24
- enumerable: false,
25
- configurable: true
26
- });
27
- ;
28
- ItemStash.prototype.add = function (item, slot) {
29
- var _this = this;
30
- var clone = ItemStash.clone(this); // Creates a clone to operate onto, instead of altering the original map
31
- var consumedWeight = 0;
32
- var weightToConsume = item.weight;
13
+ add(item, slot) {
14
+ const clone = ItemStash.clone(this); // Creates a clone to operate onto, instead of altering the original map
15
+ let consumedWeight = 0;
16
+ const weightToConsume = item.weight;
33
17
  if (!item.fullyOccupiesSlot) {
34
18
  // If there are existing slots with this item, fill them
35
- Array.from(clone._items.entries()).forEach(function (_a) {
36
- var existingSlot = _a[0], existingItem = _a[1];
19
+ Array.from(clone._items.entries()).forEach(([existingSlot, existingItem]) => {
37
20
  if (consumedWeight < weightToConsume && existingItem.identifier === item.identifier) {
38
21
  consumedWeight += ItemStash.addToSlot(clone, item.empty().add(Math.round((weightToConsume - consumedWeight) / item.weightPerUnit)), existingSlot);
39
22
  }
40
23
  });
41
24
  }
42
25
  // If the added item is not yet fully transferred, find a new slot to put the remaining amount into
43
- var attempts = 0;
26
+ let attempts = 0;
44
27
  while (consumedWeight < weightToConsume) {
45
28
  if (consumedWeight < weightToConsume && clone._items.size >= clone.slots) {
46
29
  throw new ItemStashSlotsInsuficientError();
@@ -52,50 +35,41 @@ var ItemStash = /** @class */ (function () {
52
35
  consumedWeight += ItemStash.addToSlot(clone, item.empty().add(Math.round((weightToConsume - consumedWeight) / item.weightPerUnit)), clone._items.size);
53
36
  }
54
37
  // If everything went well, propagate the modification into the original map
55
- Array.from(clone._items.entries()).forEach(function (_a) {
56
- var slot = _a[0], item = _a[1];
57
- _this._items.set(slot, item);
38
+ Array.from(clone._items.entries()).forEach(([slot, item]) => {
39
+ this._items.set(slot, item);
58
40
  });
59
41
  return true;
60
- };
61
- ItemStash.prototype.consume = function (item, amount) {
62
- var _this = this;
63
- var consumedAmount = 0;
42
+ }
43
+ consume(item, amount) {
44
+ let consumedAmount = 0;
64
45
  if (amount >= item.amount) {
65
- var slot = Array.from(this._items.entries()).find(function (_a) {
66
- var existingItem = _a[1];
67
- return existingItem.identifier === item.identifier;
68
- })[0];
46
+ const [slot,] = Array.from(this._items.entries()).find(([, existingItem]) => existingItem.identifier === item.identifier);
69
47
  if (slot != null) {
70
48
  this._items.delete(slot);
71
49
  }
72
50
  }
73
51
  else {
74
- Array.from(this._items.entries()).reverse().forEach(function (_a) {
75
- var existingSlot = _a[0], existingItem = _a[1];
52
+ Array.from(this._items.entries()).reverse().forEach(([existingSlot, existingItem]) => {
76
53
  if (consumedAmount < amount && item.identifier === existingItem.identifier) {
77
- var amountRemoved = ItemStash.removeFromSlot(_this, existingSlot, amount - consumedAmount);
54
+ const amountRemoved = ItemStash.removeFromSlot(this, existingSlot, amount - consumedAmount);
78
55
  consumedAmount += amountRemoved;
79
56
  }
80
57
  });
81
58
  }
82
- };
83
- ItemStash.prototype.has = function (itemIdentifier) {
84
- return Array.from(this._items.values()).some(function (item) { return item.identifier === itemIdentifier; });
85
- };
86
- ItemStash.prototype.serialize = function () {
87
- return this.items.reduce(function (prev, curr) { return (__assign(__assign({}, prev), curr.serialize())); }, {});
88
- };
89
- ItemStash.prototype.toUI = function () {
59
+ }
60
+ has(itemIdentifier) {
61
+ return Array.from(this._items.values()).some((item) => item.identifier === itemIdentifier);
62
+ }
63
+ serialize() {
64
+ return this.items.reduce((prev, curr) => ({ ...prev, ...curr.serialize() }), {});
65
+ }
66
+ toUI() {
90
67
  return ({
91
68
  title: this.name,
92
69
  items: Array.from(this._items.entries())
93
- .map(function (_a) {
94
- var slot = _a[0], item = _a[1];
95
- return item.toUI(slot);
96
- })
70
+ .map(([slot, item]) => item.toUI(slot))
97
71
  });
98
- };
72
+ }
99
73
  /**
100
74
  * Adds an item to a stash.
101
75
  * @param stash Stash to add the item to
@@ -103,14 +77,13 @@ var ItemStash = /** @class */ (function () {
103
77
  * @param slot The slot where the item should be placed into
104
78
  * @returns Weight added to the stash
105
79
  */
106
- ItemStash.addToSlot = function (stash, item, slot) {
107
- var _a;
108
- var existingWeightOfThisItem = ((_a = stash._items.get(slot)) === null || _a === void 0 ? void 0 : _a.weight) || 0;
109
- var availableWeightInThisSlot = stash.weightPerSlot - existingWeightOfThisItem;
110
- var weightToBeAdded = Math.max(1, Math.min(availableWeightInThisSlot, item.weight));
80
+ static addToSlot(stash, item, slot) {
81
+ const existingWeightOfThisItem = stash._items.get(slot)?.weight || 0;
82
+ const availableWeightInThisSlot = stash.weightPerSlot - existingWeightOfThisItem;
83
+ const weightToBeAdded = Math.max(1, Math.min(availableWeightInThisSlot, item.weight));
111
84
  stash._items.set(slot, item.empty().add(Math.round((existingWeightOfThisItem + weightToBeAdded) / item.weightPerUnit)));
112
85
  return weightToBeAdded;
113
- };
86
+ }
114
87
  /**
115
88
  * Removes an X amount of whichever item lies in the specified slot
116
89
  * @param stash Stash to remove the amount of the item from
@@ -118,24 +91,20 @@ var ItemStash = /** @class */ (function () {
118
91
  * @param amount The amount of the item to be removed
119
92
  * @returns The amount that has been removed (the amount in the slot can be lower than the provided amount-to-be-removed)
120
93
  */
121
- ItemStash.removeFromSlot = function (stash, slot, amount) {
122
- var _a;
123
- var existingAmountOfThisItem = ((_a = stash._items.get(slot)) === null || _a === void 0 ? void 0 : _a.amount) || 0;
94
+ static removeFromSlot(stash, slot, amount) {
95
+ const existingAmountOfThisItem = stash._items.get(slot)?.amount || 0;
124
96
  if (!existingAmountOfThisItem || !stash._items.get(slot)) {
125
97
  return 0;
126
98
  }
127
- var amountToBeConsumed = Math.min(existingAmountOfThisItem, amount);
99
+ const amountToBeConsumed = Math.min(existingAmountOfThisItem, amount);
128
100
  stash._items.set(slot, stash._items.get(slot).consume(amountToBeConsumed));
129
101
  return amountToBeConsumed;
130
- };
131
- ItemStash.clone = function (stash) {
132
- var clone = new ItemStash(stash.name, stash.slots, stash.weightPerSlot);
133
- Array.from(stash._items.entries()).forEach(function (_a) {
134
- var slot = _a[0], item = _a[1];
102
+ }
103
+ static clone(stash) {
104
+ const clone = new ItemStash(stash.name, stash.slots, stash.weightPerSlot);
105
+ Array.from(stash._items.entries()).forEach(([slot, item]) => {
135
106
  clone._items.set(slot, item);
136
107
  });
137
108
  return clone;
138
- };
139
- return ItemStash;
140
- }());
141
- export { ItemStash };
109
+ }
110
+ }