libram 0.4.0 → 0.4.4

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 (103) hide show
  1. package/dist/Clan.js +268 -485
  2. package/dist/Copier.js +11 -48
  3. package/dist/Dungeon.js +77 -157
  4. package/dist/Kmail.d.ts +3 -1
  5. package/dist/Kmail.js +92 -243
  6. package/dist/Path.js +68 -120
  7. package/dist/ascend.js +153 -172
  8. package/dist/combat.d.ts +100 -4
  9. package/dist/combat.js +352 -387
  10. package/dist/console.js +13 -36
  11. package/dist/diet/index.d.ts +31 -0
  12. package/dist/diet/index.js +390 -0
  13. package/dist/diet/knapsack.d.ts +7 -0
  14. package/dist/diet/knapsack.js +119 -0
  15. package/dist/dungeons/Dreadsylvania.d.ts +4 -0
  16. package/dist/dungeons/Dreadsylvania.js +14 -0
  17. package/dist/dungeons/Dungeon.d.ts +28 -0
  18. package/dist/dungeons/Dungeon.js +99 -0
  19. package/dist/dungeons/Hobopolis.d.ts +4 -0
  20. package/dist/dungeons/Hobopolis.js +14 -0
  21. package/dist/dungeons/SlimeTube.d.ts +4 -0
  22. package/dist/dungeons/SlimeTube.js +14 -0
  23. package/dist/freerun.d.ts +16 -4
  24. package/dist/freerun.js +88 -99
  25. package/dist/index.d.ts +5 -1
  26. package/dist/index.js +22 -300
  27. package/dist/lib.d.ts +24 -0
  28. package/dist/lib.js +304 -488
  29. package/dist/logger.js +23 -63
  30. package/dist/maximize.js +289 -556
  31. package/dist/modifier.d.ts +4 -0
  32. package/dist/modifier.js +35 -46
  33. package/dist/modifierTypes.js +8 -22
  34. package/dist/mood.d.ts +5 -0
  35. package/dist/mood.js +260 -551
  36. package/dist/property.d.ts +2 -0
  37. package/dist/property.js +99 -242
  38. package/dist/propertyTypes.d.ts +4 -3
  39. package/dist/propertyTypes.js +1 -0
  40. package/dist/propertyTyping.d.ts +4 -3
  41. package/dist/propertyTyping.js +52 -59
  42. package/dist/resources/2007/CandyHearts.d.ts +9 -0
  43. package/dist/resources/2007/CandyHearts.js +24 -0
  44. package/dist/resources/2008/DivineFavors.d.ts +9 -0
  45. package/dist/resources/2008/DivineFavors.js +27 -0
  46. package/dist/resources/2009/Bandersnatch.js +37 -112
  47. package/dist/resources/2009/LoveSongs.d.ts +9 -0
  48. package/dist/resources/2009/LoveSongs.js +24 -0
  49. package/dist/resources/2009/SpookyPutty.js +20 -46
  50. package/dist/resources/2010/Brickos.d.ts +9 -0
  51. package/dist/resources/2010/Brickos.js +21 -0
  52. package/dist/resources/2010/CrownOfThrones.d.ts +18 -0
  53. package/dist/resources/2010/CrownOfThrones.js +550 -0
  54. package/dist/resources/2011/Gygaxian.d.ts +9 -0
  55. package/dist/resources/2011/Gygaxian.js +24 -0
  56. package/dist/resources/2011/ObtuseAngel.js +21 -63
  57. package/dist/resources/2012/RainDoh.js +14 -40
  58. package/dist/resources/2012/Resolutions.d.ts +9 -0
  59. package/dist/resources/2012/Resolutions.js +28 -0
  60. package/dist/resources/2013/Florist.d.ts +1 -0
  61. package/dist/resources/2013/Florist.js +137 -207
  62. package/dist/resources/2013/PulledTaffy.d.ts +9 -0
  63. package/dist/resources/2013/PulledTaffy.js +33 -0
  64. package/dist/resources/2014/DNALab.d.ts +47 -0
  65. package/dist/resources/2014/DNALab.js +154 -0
  66. package/dist/resources/2014/WinterGarden.js +15 -43
  67. package/dist/resources/2015/ChateauMantegna.js +52 -86
  68. package/dist/resources/2015/MayoClinic.d.ts +3 -0
  69. package/dist/resources/2015/MayoClinic.js +36 -65
  70. package/dist/resources/2016/SourceTerminal.d.ts +1 -0
  71. package/dist/resources/2016/SourceTerminal.js +114 -237
  72. package/dist/resources/2016/Witchess.js +33 -59
  73. package/dist/resources/2017/AsdonMartin.d.ts +27 -0
  74. package/dist/resources/2017/AsdonMartin.js +80 -0
  75. package/dist/resources/2017/TunnelOfLove.js +62 -111
  76. package/dist/resources/2018/SongBoom.js +32 -68
  77. package/dist/resources/2019/BeachComb.js +26 -44
  78. package/dist/resources/2019/Snapper.d.ts +28 -0
  79. package/dist/resources/2019/Snapper.js +69 -0
  80. package/dist/resources/2020/Guzzlr.d.ts +3 -0
  81. package/dist/resources/2020/Guzzlr.js +92 -163
  82. package/dist/resources/LibramSummon.d.ts +12 -0
  83. package/dist/resources/LibramSummon.js +66 -0
  84. package/dist/resources/index.d.ts +20 -14
  85. package/dist/resources/index.js +21 -100
  86. package/dist/resources/putty-likes.js +15 -30
  87. package/dist/ring-buffer.d.ts +24 -0
  88. package/dist/ring-buffer.js +135 -0
  89. package/dist/since.d.ts +1 -0
  90. package/dist/since.js +56 -112
  91. package/dist/template-string.js +40 -132
  92. package/dist/utils.d.ts +12 -0
  93. package/dist/utils.js +54 -123
  94. package/package.json +8 -3
  95. package/dist/libram-example-briefcase.js +0 -16073
  96. package/dist/libram-example-clan.js +0 -7050
  97. package/dist/libram-example-consult.js +0 -5032
  98. package/dist/libram-example-item.js +0 -2870
  99. package/dist/libram-example-kmail.js +0 -2065
  100. package/dist/libram-example-lib.js +0 -6369
  101. package/dist/libram-example-modifier.js +0 -4495
  102. package/dist/libram-example-props.js +0 -3996
  103. package/dist/libram-example-resources.js +0 -10461
package/dist/maximize.js CHANGED
@@ -1,105 +1,16 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.array.slice.js");
4
-
5
- require("core-js/modules/es.symbol.js");
6
-
7
- require("core-js/modules/es.symbol.description.js");
8
-
9
- require("core-js/modules/es.object.get-own-property-descriptors.js");
10
-
11
- Object.defineProperty(exports, "__esModule", {
12
- value: true
13
- });
14
- exports.setDefaultMaximizeOptions = setDefaultMaximizeOptions;
15
- exports.maximizeCached = maximizeCached;
16
- exports.Requirement = void 0;
17
-
18
- require("core-js/modules/es.array.iterator.js");
19
-
20
- require("core-js/modules/es.object.to-string.js");
21
-
22
- require("core-js/modules/es.object.assign.js");
23
-
24
- require("core-js/modules/es.array.sort.js");
25
-
26
- require("core-js/modules/es.array.concat.js");
27
-
28
- require("core-js/modules/es.array.filter.js");
29
-
30
- require("core-js/modules/es.array.splice.js");
31
-
32
- require("core-js/modules/es.array.map.js");
33
-
34
- require("core-js/modules/es.array.includes.js");
35
-
36
- require("core-js/modules/es.string.includes.js");
37
-
38
- var _kolmafia = require("kolmafia");
39
-
40
- var _templateString = require("./template-string");
41
-
42
- var _logger = _interopRequireDefault(require("./logger"));
43
-
44
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19, _templateObject20, _templateObject21, _templateObject22, _templateObject23, _templateObject24, _templateObject25, _templateObject26, _templateObject27, _templateObject28, _templateObject29, _templateObject30, _templateObject31, _templateObject32, _templateObject33, _templateObject34, _templateObject35, _templateObject36, _templateObject37, _templateObject38;
45
-
46
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
-
48
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
49
-
50
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
51
-
52
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
53
-
54
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
55
-
56
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
57
-
58
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
59
-
60
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
61
-
62
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
63
-
64
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
65
-
66
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
67
-
68
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
69
-
70
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
71
-
72
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
73
-
74
- 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); } }
75
-
76
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
77
-
78
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
79
-
80
- function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
81
-
82
- function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
83
-
84
- function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
85
-
86
- function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
87
-
88
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
89
-
90
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
91
-
92
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
93
-
94
- var defaultMaximizeOptions = {
95
- updateOnFamiliarChange: true,
96
- updateOnCanEquipChanged: true,
97
- useOutfitCaching: true,
98
- forceEquip: [],
99
- preventEquip: [],
100
- bonusEquip: new Map(),
101
- onlySlot: [],
102
- preventSlot: []
1
+ import { availableAmount, bjornifyFamiliar, canEquip, cliExecute, enthroneFamiliar, equip, equippedAmount, equippedItem, isWearingOutfit, maximize, myBasestat, myBjornedFamiliar, myEnthronedFamiliar, myFamiliar, outfit, } from "kolmafia";
2
+ import { $familiar, $item, $slot, $slots, $stats } from "./template-string";
3
+ import logger from "./logger";
4
+ import { setEqual } from "./utils";
5
+ const defaultMaximizeOptions = {
6
+ updateOnFamiliarChange: true,
7
+ updateOnCanEquipChanged: true,
8
+ useOutfitCaching: true,
9
+ forceEquip: [],
10
+ preventEquip: [],
11
+ bonusEquip: new Map(),
12
+ onlySlot: [],
13
+ preventSlot: [],
103
14
  };
104
15
  /**
105
16
  *
@@ -110,148 +21,96 @@ var defaultMaximizeOptions = {
110
21
  * @param options.preventEquip Equipment to prevent equipping ("-equip X").
111
22
  * @param options.bonusEquip Equipment to apply a bonus to ("200 bonus X").
112
23
  */
113
-
114
- function setDefaultMaximizeOptions(options) {
115
- Object.assign(defaultMaximizeOptions, options);
116
- } // Subset of slots that are valid for caching.
117
-
118
-
119
- var cachedSlots = (0, _templateString.$slots)(_templateObject || (_templateObject = _taggedTemplateLiteral(["hat, weapon, off-hand, back, shirt, pants, acc1, acc2, acc3, familiar"])));
120
-
121
- var CacheEntry = function CacheEntry(equipment, rider, familiar, canEquipItemCount) {
122
- _classCallCheck(this, CacheEntry);
123
-
124
- _defineProperty(this, "equipment", void 0);
125
-
126
- _defineProperty(this, "rider", void 0);
127
-
128
- _defineProperty(this, "familiar", void 0);
129
-
130
- _defineProperty(this, "canEquipItemCount", void 0);
131
-
132
- this.equipment = equipment;
133
- this.rider = rider;
134
- this.familiar = familiar;
135
- this.canEquipItemCount = canEquipItemCount;
136
- };
137
-
138
- var _outfitSlots = /*#__PURE__*/new WeakMap();
139
-
140
- var _useHistory = /*#__PURE__*/new WeakMap();
141
-
142
- var _maxSize = /*#__PURE__*/new WeakMap();
143
-
144
- var OutfitLRUCache = /*#__PURE__*/function () {
145
- // Current outfits allocated
146
- // Array of indices into #outfitSlots in order of use. Most recent at the front.
147
- function OutfitLRUCache(maxSize) {
148
- _classCallCheck(this, OutfitLRUCache);
149
-
150
- _outfitSlots.set(this, {
151
- writable: true,
152
- value: []
153
- });
154
-
155
- _useHistory.set(this, {
156
- writable: true,
157
- value: []
158
- });
159
-
160
- _maxSize.set(this, {
161
- writable: true,
162
- value: void 0
163
- });
164
-
165
- _classPrivateFieldSet(this, _maxSize, maxSize);
166
- }
167
-
168
- _createClass(OutfitLRUCache, [{
169
- key: "checkConsistent",
170
- value: function checkConsistent() {
171
- if (_classPrivateFieldGet(this, _useHistory).length !== _classPrivateFieldGet(this, _outfitSlots).length || !_toConsumableArray(_classPrivateFieldGet(this, _useHistory)).sort().every((value, index) => value === index)) {
172
- throw new Error("Outfit cache consistency failed.");
173
- }
174
- }
175
- }, {
176
- key: "promote",
177
- value: function promote(index) {
178
- _classPrivateFieldSet(this, _useHistory, [index].concat(_toConsumableArray(_classPrivateFieldGet(this, _useHistory).filter(i => i !== index))));
179
-
180
- this.checkConsistent();
181
- }
182
- }, {
183
- key: "get",
184
- value: function get(key) {
185
- var index = _classPrivateFieldGet(this, _outfitSlots).indexOf(key);
186
-
187
- if (index < 0) return undefined;
188
- this.promote(index);
189
- return "".concat(OutfitLRUCache.OUTFIT_PREFIX, " ").concat(index);
190
- }
191
- }, {
192
- key: "insert",
193
- value: function insert(key) {
194
- var lastUseIndex = undefined;
195
-
196
- if (_classPrivateFieldGet(this, _outfitSlots).length >= _classPrivateFieldGet(this, _maxSize)) {
197
- lastUseIndex = _classPrivateFieldGet(this, _useHistory).pop();
198
-
199
- if (lastUseIndex === undefined) {
200
- throw new Error("Outfit cache consistency failed.");
24
+ export function setDefaultMaximizeOptions(options) {
25
+ Object.assign(defaultMaximizeOptions, options);
26
+ }
27
+ // Subset of slots that are valid for caching.
28
+ const cachedSlots = $slots `hat, weapon, off-hand, back, shirt, pants, acc1, acc2, acc3, familiar`;
29
+ class CacheEntry {
30
+ constructor(equipment, rider, familiar, canEquipItemCount) {
31
+ this.equipment = equipment;
32
+ this.rider = rider;
33
+ this.familiar = familiar;
34
+ this.canEquipItemCount = canEquipItemCount;
35
+ }
36
+ }
37
+ class OutfitLRUCache {
38
+ constructor(maxSize) {
39
+ // Current outfits allocated
40
+ this.#outfitSlots = [];
41
+ // Array of indices into #outfitSlots in order of use. Most recent at the front.
42
+ this.#useHistory = [];
43
+ this.#maxSize = maxSize;
44
+ }
45
+ // Current outfits allocated
46
+ #outfitSlots;
47
+ // Array of indices into #outfitSlots in order of use. Most recent at the front.
48
+ #useHistory;
49
+ #maxSize;
50
+ checkConsistent() {
51
+ if (this.#useHistory.length !== this.#outfitSlots.length ||
52
+ ![...this.#useHistory].sort().every((value, index) => value === index)) {
53
+ throw new Error("Outfit cache consistency failed.");
201
54
  }
202
-
203
- _classPrivateFieldGet(this, _useHistory).splice(0, 0, lastUseIndex);
204
-
205
- _classPrivateFieldGet(this, _outfitSlots)[lastUseIndex] = key;
206
- this.checkConsistent();
207
- return "".concat(OutfitLRUCache.OUTFIT_PREFIX, " ").concat(lastUseIndex);
208
- } else {
209
- var index = _classPrivateFieldGet(this, _outfitSlots).push(key) - 1;
210
-
211
- _classPrivateFieldGet(this, _useHistory).splice(0, 0, index);
212
-
55
+ }
56
+ promote(index) {
57
+ this.#useHistory = [index, ...this.#useHistory.filter((i) => i !== index)];
213
58
  this.checkConsistent();
214
- return "".concat(OutfitLRUCache.OUTFIT_PREFIX, " ").concat(index);
215
- }
216
59
  }
217
- }]);
218
-
219
- return OutfitLRUCache;
220
- }();
60
+ get(key) {
61
+ const index = this.#outfitSlots.indexOf(key);
62
+ if (index < 0)
63
+ return undefined;
64
+ this.promote(index);
65
+ return `${OutfitLRUCache.OUTFIT_PREFIX} ${index}`;
66
+ }
67
+ insert(key) {
68
+ let lastUseIndex = undefined;
69
+ if (this.#outfitSlots.length >= this.#maxSize) {
70
+ lastUseIndex = this.#useHistory.pop();
71
+ if (lastUseIndex === undefined) {
72
+ throw new Error("Outfit cache consistency failed.");
73
+ }
74
+ this.#useHistory.splice(0, 0, lastUseIndex);
75
+ this.#outfitSlots[lastUseIndex] = key;
76
+ this.checkConsistent();
77
+ return `${OutfitLRUCache.OUTFIT_PREFIX} ${lastUseIndex}`;
78
+ }
79
+ else {
80
+ const index = this.#outfitSlots.push(key) - 1;
81
+ this.#useHistory.splice(0, 0, index);
82
+ this.checkConsistent();
83
+ return `${OutfitLRUCache.OUTFIT_PREFIX} ${index}`;
84
+ }
85
+ }
86
+ }
87
+ OutfitLRUCache.OUTFIT_PREFIX = "Script Outfit";
221
88
  /**
222
89
  * Save current equipment as KoL-native outfit.
223
90
  * @param name Name of new outfit.
224
91
  */
225
-
226
-
227
- _defineProperty(OutfitLRUCache, "OUTFIT_PREFIX", "Script Outfit");
228
-
229
92
  function saveOutfit(name) {
230
- (0, _kolmafia.cliExecute)("outfit save ".concat(name));
231
- } // Objective cache entries.
232
-
233
-
234
- var cachedObjectives = {}; // Outfit cache entries. Keep 6 by default to avoid cluttering list.
235
-
236
- var outfitCache = new OutfitLRUCache(6); // Cache to prevent rescanning all items unnecessarily
237
-
238
- var cachedStats = [0, 0, 0];
239
- var cachedCanEquipItemCount = 0;
93
+ cliExecute(`outfit save ${name}`);
94
+ }
95
+ // Objective cache entries.
96
+ const cachedObjectives = {};
97
+ // Outfit cache entries. Keep 6 by default to avoid cluttering list.
98
+ const outfitCache = new OutfitLRUCache(6);
99
+ // Cache to prevent rescanning all items unnecessarily
100
+ let cachedStats = [0, 0, 0];
101
+ let cachedCanEquipItemCount = 0;
240
102
  /**
241
103
  * Count the number of unique items that can be equipped.
242
104
  * @returns The count of unique items.
243
105
  */
244
-
245
106
  function canEquipItemCount() {
246
- var stats = (0, _templateString.$stats)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["Muscle, Mysticality, Moxie"]))).map(stat => Math.min((0, _kolmafia.myBasestat)(stat), 300));
247
-
248
- if (stats.every((value, index) => value === cachedStats[index])) {
107
+ const stats = $stats `Muscle, Mysticality, Moxie`.map((stat) => Math.min(myBasestat(stat), 300));
108
+ if (stats.every((value, index) => value === cachedStats[index])) {
109
+ return cachedCanEquipItemCount;
110
+ }
111
+ cachedStats = stats;
112
+ cachedCanEquipItemCount = Item.all().filter((item) => canEquip(item)).length;
249
113
  return cachedCanEquipItemCount;
250
- }
251
-
252
- cachedStats = stats;
253
- cachedCanEquipItemCount = Item.all().filter(item => (0, _kolmafia.canEquip)(item)).length;
254
- return cachedCanEquipItemCount;
255
114
  }
256
115
  /**
257
116
  * Checks the objective cache for a valid entry.
@@ -260,229 +119,149 @@ function canEquipItemCount() {
260
119
  * @param updateOnCanEquipChanged Ignore cache if stats have changed what can be equipped.
261
120
  * @returns A valid CacheEntry or null.
262
121
  */
263
-
264
-
265
122
  function checkCache(cacheKey, options) {
266
- var entry = cachedObjectives[cacheKey];
267
-
268
- if (!entry) {
269
- return null;
270
- }
271
-
272
- if (options.updateOnFamiliarChange && (0, _kolmafia.myFamiliar)() !== entry.familiar) {
273
- _logger.default.warning("Equipment found in maximize cache but familiar is different.");
274
-
275
- return null;
276
- }
277
-
278
- if (options.updateOnCanEquipChanged && entry.canEquipItemCount !== canEquipItemCount()) {
279
- _logger.default.warning("Equipment found in maximize cache but equippable item list is out of date.");
280
-
281
- return null;
282
- }
283
-
284
- return entry;
123
+ const entry = cachedObjectives[cacheKey];
124
+ if (!entry) {
125
+ return null;
126
+ }
127
+ if (options.updateOnFamiliarChange && myFamiliar() !== entry.familiar) {
128
+ logger.warning("Equipment found in maximize cache but familiar is different.");
129
+ return null;
130
+ }
131
+ if (options.updateOnCanEquipChanged &&
132
+ entry.canEquipItemCount !== canEquipItemCount()) {
133
+ logger.warning("Equipment found in maximize cache but equippable item list is out of date.");
134
+ return null;
135
+ }
136
+ return entry;
285
137
  }
286
138
  /**
287
139
  * Applies equipment that was found in the cache.
288
140
  * @param entry The CacheEntry to apply
289
141
  */
290
-
291
-
292
142
  function applyCached(entry, options) {
293
- var outfitName = options.useOutfitCaching ? outfitCache.get(entry) : undefined;
294
-
295
- if (outfitName) {
296
- if (!(0, _kolmafia.isWearingOutfit)(outfitName)) {
297
- (0, _kolmafia.outfit)(outfitName);
298
- }
299
-
300
- var familiarEquip = entry.equipment.get((0, _templateString.$slot)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["familiar"]))));
301
- if (familiarEquip) (0, _kolmafia.equip)(familiarEquip);
302
- verifyCached(entry);
303
- } else {
304
- var _iterator = _createForOfIteratorHelper(entry.equipment),
305
- _step;
306
-
307
- try {
308
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
309
- var _step$value = _slicedToArray(_step.value, 2),
310
- slot = _step$value[0],
311
- item = _step$value[1];
312
-
313
- if ((0, _kolmafia.equippedItem)(slot) !== item && (0, _kolmafia.availableAmount)(item) > 0) {
314
- (0, _kolmafia.equip)(slot, item);
143
+ const outfitName = options.useOutfitCaching
144
+ ? outfitCache.get(entry)
145
+ : undefined;
146
+ if (outfitName) {
147
+ if (!isWearingOutfit(outfitName)) {
148
+ outfit(outfitName);
149
+ }
150
+ const familiarEquip = entry.equipment.get($slot `familiar`);
151
+ if (familiarEquip)
152
+ equip(familiarEquip);
153
+ }
154
+ else {
155
+ for (const [slot, item] of entry.equipment) {
156
+ if (equippedItem(slot) !== item && availableAmount(item) > 0) {
157
+ equip(slot, item);
158
+ }
315
159
  }
316
- }
317
- } catch (err) {
318
- _iterator.e(err);
319
- } finally {
320
- _iterator.f();
321
- }
322
-
323
- if (verifyCached(entry) && options.useOutfitCaching) {
324
- var _outfitName = outfitCache.insert(entry);
325
-
326
- _logger.default.info("Saving equipment to outfit ".concat(_outfitName, "."));
327
-
328
- saveOutfit(_outfitName);
329
- }
330
- }
331
-
332
- if ((0, _kolmafia.equippedAmount)((0, _templateString.$item)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["Crown of Thrones"])))) > 0 && entry.rider.get((0, _templateString.$item)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["Crown of Thrones"]))))) {
333
- (0, _kolmafia.enthroneFamiliar)(entry.rider.get((0, _templateString.$item)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["Crown of Thrones"])))) || (0, _templateString.$familiar)(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["none"]))));
334
- }
335
-
336
- if ((0, _kolmafia.equippedAmount)((0, _templateString.$item)(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["Buddy Bjorn"])))) > 0 && entry.rider.get((0, _templateString.$item)(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["Buddy Bjorn"]))))) {
337
- (0, _kolmafia.bjornifyFamiliar)(entry.rider.get((0, _templateString.$item)(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["Buddy Bjorn"])))) || (0, _templateString.$familiar)(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["none"]))));
338
- }
160
+ if (verifyCached(entry) && options.useOutfitCaching) {
161
+ const outfitName = outfitCache.insert(entry);
162
+ logger.info(`Saving equipment to outfit ${outfitName}.`);
163
+ saveOutfit(outfitName);
164
+ }
165
+ }
166
+ if (equippedAmount($item `Crown of Thrones`) > 0 &&
167
+ entry.rider.get($item `Crown of Thrones`)) {
168
+ enthroneFamiliar(entry.rider.get($item `Crown of Thrones`) || $familiar `none`);
169
+ }
170
+ if (equippedAmount($item `Buddy Bjorn`) > 0 &&
171
+ entry.rider.get($item `Buddy Bjorn`)) {
172
+ bjornifyFamiliar(entry.rider.get($item `Buddy Bjorn`) || $familiar `none`);
173
+ }
339
174
  }
175
+ const slotStructure = [
176
+ $slots `hat`,
177
+ $slots `back`,
178
+ $slots `shirt`,
179
+ $slots `weapon, off-hand`,
180
+ $slots `pants`,
181
+ $slots `acc1, acc2, acc3`,
182
+ $slots `familiar`,
183
+ ];
340
184
  /**
341
185
  * Verifies that a CacheEntry was applied successfully.
342
186
  * @param entry The CacheEntry to verify
343
187
  * @returns If all desired equipment was appliedn in the correct slots.
344
188
  */
345
-
346
-
347
189
  function verifyCached(entry) {
348
- var success = true;
349
-
350
- var _iterator2 = _createForOfIteratorHelper(entry.equipment),
351
- _step2;
352
-
353
- try {
354
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
355
- var _step2$value = _slicedToArray(_step2.value, 2),
356
- slot = _step2$value[0],
357
- item = _step2$value[1];
358
-
359
- if ((0, _kolmafia.equippedItem)(slot) !== item) {
360
- _logger.default.warning("Failed to apply cached ".concat(item, " in ").concat(slot, "."));
361
-
362
- success = false;
363
- }
364
- }
365
- } catch (err) {
366
- _iterator2.e(err);
367
- } finally {
368
- _iterator2.f();
369
- }
370
-
371
- if ((0, _kolmafia.equippedAmount)((0, _templateString.$item)(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["Crown of Thrones"])))) > 0 && entry.rider.get((0, _templateString.$item)(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["Crown of Thrones"]))))) {
372
- if (entry.rider.get((0, _templateString.$item)(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["Crown of Thrones"])))) !== (0, _kolmafia.myEnthronedFamiliar)()) {
373
- _logger.default.warning("Failed to apply ".concat(entry.rider.get((0, _templateString.$item)(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["Crown of Thrones"])))), " in ").concat((0, _templateString.$item)(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["Crown of Thrones"]))), "."));
374
-
375
- success = false;
376
- }
377
- }
378
-
379
- if ((0, _kolmafia.equippedAmount)((0, _templateString.$item)(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["Buddy Bjorn"])))) > 0 && entry.rider.get((0, _templateString.$item)(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["Buddy Bjorn"]))))) {
380
- if (entry.rider.get((0, _templateString.$item)(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["Buddy Bjorn"])))) !== (0, _kolmafia.myBjornedFamiliar)()) {
381
- _logger.default.warning("Failed to apply".concat(entry.rider.get((0, _templateString.$item)(_templateObject20 || (_templateObject20 = _taggedTemplateLiteral(["Buddy Bjorn"])))), " in ").concat((0, _templateString.$item)(_templateObject21 || (_templateObject21 = _taggedTemplateLiteral(["Buddy Bjorn"]))), "."));
382
-
383
- success = false;
384
- }
385
- }
386
-
387
- return success;
190
+ let success = true;
191
+ for (const slotGroup of slotStructure) {
192
+ const desiredSet = slotGroup.map((slot) => entry.equipment.get(slot) ?? $item `none`);
193
+ const equippedSet = slotGroup.map((slot) => equippedItem(slot));
194
+ if (!setEqual(desiredSet, equippedSet)) {
195
+ logger.warning(`Failed to apply cached ${desiredSet.join(", ")} in ${slotGroup.join(", ")}.`);
196
+ success = false;
197
+ }
198
+ }
199
+ if (equippedAmount($item `Crown of Thrones`) > 0 &&
200
+ entry.rider.get($item `Crown of Thrones`)) {
201
+ if (entry.rider.get($item `Crown of Thrones`) !== myEnthronedFamiliar()) {
202
+ logger.warning(`Failed to apply ${entry.rider.get($item `Crown of Thrones`)} in ${$item `Crown of Thrones`}.`);
203
+ success = false;
204
+ }
205
+ }
206
+ if (equippedAmount($item `Buddy Bjorn`) > 0 &&
207
+ entry.rider.get($item `Buddy Bjorn`)) {
208
+ if (entry.rider.get($item `Buddy Bjorn`) !== myBjornedFamiliar()) {
209
+ logger.warning(`Failed to apply${entry.rider.get($item `Buddy Bjorn`)} in ${$item `Buddy Bjorn`}.`);
210
+ success = false;
211
+ }
212
+ }
213
+ return success;
388
214
  }
389
215
  /**
390
216
  * Save current equipment to the objective cache.
391
217
  * @param cacheKey The cache key to save.
392
218
  */
393
-
394
-
395
219
  function saveCached(cacheKey, options) {
396
- var equipment = new Map();
397
- var rider = new Map();
398
-
399
- var _iterator3 = _createForOfIteratorHelper(cachedSlots),
400
- _step3;
401
-
402
- try {
403
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
404
- var _slot2 = _step3.value;
405
- equipment.set(_slot2, (0, _kolmafia.equippedItem)(_slot2));
406
- }
407
- } catch (err) {
408
- _iterator3.e(err);
409
- } finally {
410
- _iterator3.f();
411
- }
412
-
413
- if ((0, _kolmafia.equippedAmount)((0, _templateString.$item)(_templateObject22 || (_templateObject22 = _taggedTemplateLiteral(["card sleeve"])))) > 0) {
414
- equipment.set((0, _templateString.$slot)(_templateObject23 || (_templateObject23 = _taggedTemplateLiteral(["card-sleeve"]))), (0, _kolmafia.equippedItem)((0, _templateString.$slot)(_templateObject24 || (_templateObject24 = _taggedTemplateLiteral(["card-sleeve"])))));
415
- }
416
-
417
- if ((0, _kolmafia.equippedAmount)((0, _templateString.$item)(_templateObject25 || (_templateObject25 = _taggedTemplateLiteral(["Crown of Thrones"])))) > 0) {
418
- rider.set((0, _templateString.$item)(_templateObject26 || (_templateObject26 = _taggedTemplateLiteral(["Crown of Thrones"]))), (0, _kolmafia.myEnthronedFamiliar)());
419
- }
420
-
421
- if ((0, _kolmafia.equippedAmount)((0, _templateString.$item)(_templateObject27 || (_templateObject27 = _taggedTemplateLiteral(["Buddy Bjorn"])))) > 0) {
422
- rider.set((0, _templateString.$item)(_templateObject28 || (_templateObject28 = _taggedTemplateLiteral(["Buddy Bjorn"]))), (0, _kolmafia.myBjornedFamiliar)());
423
- }
424
-
425
- if (options.preventSlot && options.preventSlot.length > 0) {
426
- var _iterator4 = _createForOfIteratorHelper(options.preventSlot),
427
- _step4;
428
-
429
- try {
430
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
431
- var slot = _step4.value;
432
- equipment.delete(slot);
433
- }
434
- } catch (err) {
435
- _iterator4.e(err);
436
- } finally {
437
- _iterator4.f();
438
- }
439
-
440
- if (options.preventSlot.includes((0, _templateString.$slot)(_templateObject29 || (_templateObject29 = _taggedTemplateLiteral(["buddy-bjorn"]))))) {
441
- rider.delete((0, _templateString.$item)(_templateObject30 || (_templateObject30 = _taggedTemplateLiteral(["Buddy Bjorn"]))));
442
- }
443
-
444
- if (options.preventSlot.includes((0, _templateString.$slot)(_templateObject31 || (_templateObject31 = _taggedTemplateLiteral(["crown-of-thrones"]))))) {
445
- rider.delete((0, _templateString.$item)(_templateObject32 || (_templateObject32 = _taggedTemplateLiteral(["Crown of Thrones"]))));
446
- }
447
- }
448
-
449
- if (options.onlySlot && options.onlySlot.length > 0) {
450
- var _iterator5 = _createForOfIteratorHelper(Slot.all()),
451
- _step5;
452
-
453
- try {
454
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
455
- var _slot = _step5.value;
456
-
457
- if (!options.onlySlot.includes(_slot)) {
458
- equipment.delete(_slot);
220
+ const equipment = new Map();
221
+ const rider = new Map();
222
+ for (const slot of cachedSlots) {
223
+ equipment.set(slot, equippedItem(slot));
224
+ }
225
+ if (equippedAmount($item `card sleeve`) > 0) {
226
+ equipment.set($slot `card-sleeve`, equippedItem($slot `card-sleeve`));
227
+ }
228
+ if (equippedAmount($item `Crown of Thrones`) > 0) {
229
+ rider.set($item `Crown of Thrones`, myEnthronedFamiliar());
230
+ }
231
+ if (equippedAmount($item `Buddy Bjorn`) > 0) {
232
+ rider.set($item `Buddy Bjorn`, myBjornedFamiliar());
233
+ }
234
+ if (options.preventSlot && options.preventSlot.length > 0) {
235
+ for (const slot of options.preventSlot) {
236
+ equipment.delete(slot);
237
+ }
238
+ if (options.preventSlot.includes($slot `buddy-bjorn`)) {
239
+ rider.delete($item `Buddy Bjorn`);
240
+ }
241
+ if (options.preventSlot.includes($slot `crown-of-thrones`)) {
242
+ rider.delete($item `Crown of Thrones`);
243
+ }
244
+ }
245
+ if (options.onlySlot && options.onlySlot.length > 0) {
246
+ for (const slot of Slot.all()) {
247
+ if (!options.onlySlot.includes(slot)) {
248
+ equipment.delete(slot);
249
+ }
250
+ }
251
+ if (!options.onlySlot.includes($slot `buddy-bjorn`)) {
252
+ rider.delete($item `Buddy Bjorn`);
459
253
  }
460
- }
461
- } catch (err) {
462
- _iterator5.e(err);
463
- } finally {
464
- _iterator5.f();
465
- }
466
-
467
- if (!options.onlySlot.includes((0, _templateString.$slot)(_templateObject33 || (_templateObject33 = _taggedTemplateLiteral(["buddy-bjorn"]))))) {
468
- rider.delete((0, _templateString.$item)(_templateObject34 || (_templateObject34 = _taggedTemplateLiteral(["Buddy Bjorn"]))));
469
- }
470
-
471
- if (!options.onlySlot.includes((0, _templateString.$slot)(_templateObject35 || (_templateObject35 = _taggedTemplateLiteral(["crown-of-thrones"]))))) {
472
- rider.delete((0, _templateString.$item)(_templateObject36 || (_templateObject36 = _taggedTemplateLiteral(["Crown of Thrones"]))));
473
- }
474
- }
475
-
476
- var entry = new CacheEntry(equipment, rider, (0, _kolmafia.myFamiliar)(), canEquipItemCount());
477
- cachedObjectives[cacheKey] = entry;
478
-
479
- if (options.useOutfitCaching) {
480
- var outfitName = outfitCache.insert(entry);
481
-
482
- _logger.default.info("Saving equipment to outfit ".concat(outfitName, "."));
483
-
484
- saveOutfit(outfitName);
485
- }
254
+ if (!options.onlySlot.includes($slot `crown-of-thrones`)) {
255
+ rider.delete($item `Crown of Thrones`);
256
+ }
257
+ }
258
+ const entry = new CacheEntry(equipment, rider, myFamiliar(), canEquipItemCount());
259
+ cachedObjectives[cacheKey] = entry;
260
+ if (options.useOutfitCaching) {
261
+ const outfitName = outfitCache.insert(entry);
262
+ logger.info(`Saving equipment to outfit ${outfitName}.`);
263
+ saveOutfit(outfitName);
264
+ }
486
265
  }
487
266
  /**
488
267
  * Run the maximizer, but only if the objective and certain pieces of game state haven't changed since it was last run.
@@ -494,147 +273,101 @@ function saveCached(cacheKey, options) {
494
273
  * @param options.preventEquip Equipment to prevent equipping ("-equip X").
495
274
  * @param options.bonusEquip Equipment to apply a bonus to ("200 bonus X").
496
275
  */
497
-
498
-
499
- function maximizeCached(objectives) {
500
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
501
-
502
- var fullOptions = _objectSpread(_objectSpread({}, defaultMaximizeOptions), options);
503
-
504
- var forceEquip = fullOptions.forceEquip,
505
- preventEquip = fullOptions.preventEquip,
506
- bonusEquip = fullOptions.bonusEquip,
507
- onlySlot = fullOptions.onlySlot,
508
- preventSlot = fullOptions.preventSlot; // Sort each group in objective to ensure consistent ordering in string
509
-
510
- var objective = [].concat(_toConsumableArray(objectives.sort()), _toConsumableArray(forceEquip.map(item => "equip ".concat(item)).sort()), _toConsumableArray(preventEquip.map(item => "-equip ".concat(item)).sort()), _toConsumableArray(onlySlot.filter(slot => !(0, _templateString.$slots)(_templateObject37 || (_templateObject37 = _taggedTemplateLiteral(["buddy-bjorn, crown-of-thrones"]))).includes(slot)).map(slot => "".concat(slot)).sort()), _toConsumableArray(preventSlot.filter(slot => !(0, _templateString.$slots)(_templateObject38 || (_templateObject38 = _taggedTemplateLiteral(["buddy-bjorn, crown-of-thrones"]))).includes(slot)).map(slot => "-".concat(slot)).sort()), _toConsumableArray(Array.from(bonusEquip.entries()).filter(_ref => {
511
- var _ref2 = _slicedToArray(_ref, 2),
512
- bonus = _ref2[1];
513
-
514
- return bonus !== 0;
515
- }).map(_ref3 => {
516
- var _ref4 = _slicedToArray(_ref3, 2),
517
- item = _ref4[0],
518
- bonus = _ref4[1];
519
-
520
- return "".concat(Math.round(bonus * 100) / 100, " bonus ").concat(item);
521
- }).sort())).join(", ");
522
- var cacheEntry = checkCache(objective, fullOptions);
523
-
524
- if (cacheEntry) {
525
- _logger.default.info("Equipment found in maximize cache, equipping...");
526
-
527
- applyCached(cacheEntry, fullOptions);
528
-
529
- if (verifyCached(cacheEntry)) {
530
- _logger.default.info("Equipped cached ".concat(objective));
531
-
532
- return;
533
- }
534
-
535
- _logger.default.warning("Maximize cache application failed, maximizing...");
536
- }
537
-
538
- (0, _kolmafia.maximize)(objective, false);
539
- saveCached(objective, fullOptions);
276
+ export function maximizeCached(objectives, options = {}) {
277
+ const fullOptions = { ...defaultMaximizeOptions, ...options };
278
+ const { forceEquip, preventEquip, bonusEquip, onlySlot, preventSlot, } = fullOptions;
279
+ // Sort each group in objective to ensure consistent ordering in string
280
+ const objective = [
281
+ ...objectives.sort(),
282
+ ...forceEquip.map((item) => `equip ${item}`).sort(),
283
+ ...preventEquip.map((item) => `-equip ${item}`).sort(),
284
+ ...onlySlot.map((slot) => `${slot}`).sort(),
285
+ ...preventSlot.map((slot) => `-${slot}`).sort(),
286
+ ...Array.from(bonusEquip.entries())
287
+ .filter(([, bonus]) => bonus !== 0)
288
+ .map(([item, bonus]) => `${Math.round(bonus * 100) / 100} bonus ${item}`)
289
+ .sort(),
290
+ ].join(", ");
291
+ const cacheEntry = checkCache(objective, fullOptions);
292
+ if (cacheEntry) {
293
+ logger.info("Equipment found in maximize cache, equipping...");
294
+ applyCached(cacheEntry, fullOptions);
295
+ if (verifyCached(cacheEntry)) {
296
+ logger.info(`Equipped cached ${objective}`);
297
+ return;
298
+ }
299
+ logger.warning("Maximize cache application failed, maximizing...");
300
+ }
301
+ maximize(objective, false);
302
+ saveCached(objective, fullOptions);
540
303
  }
541
-
542
- var _maximizeParameters = /*#__PURE__*/new WeakMap();
543
-
544
- var _maximizeOptions = /*#__PURE__*/new WeakMap();
545
-
546
- var Requirement = /*#__PURE__*/function () {
547
- /**
548
- * A convenient way of combining maximization parameters and options
549
- * @param maximizeParameters Parameters you're attempting to maximize
550
- * @param maximizeOptions Object potentially containing forceEquips, bonusEquips, preventEquips, and preventSlots
551
- */
552
- function Requirement(maximizeParameters, maximizeOptions) {
553
- _classCallCheck(this, Requirement);
554
-
555
- _maximizeParameters.set(this, {
556
- writable: true,
557
- value: void 0
558
- });
559
-
560
- _maximizeOptions.set(this, {
561
- writable: true,
562
- value: void 0
563
- });
564
-
565
- _classPrivateFieldSet(this, _maximizeParameters, maximizeParameters);
566
-
567
- _classPrivateFieldSet(this, _maximizeOptions, maximizeOptions);
568
- }
569
-
570
- _createClass(Requirement, [{
571
- key: "maximizeParameters",
572
- get: function get() {
573
- return _classPrivateFieldGet(this, _maximizeParameters);
574
- }
575
- }, {
576
- key: "maximizeOptions",
577
- get: function get() {
578
- return _classPrivateFieldGet(this, _maximizeOptions);
304
+ export class Requirement {
305
+ /**
306
+ * A convenient way of combining maximization parameters and options
307
+ * @param maximizeParameters Parameters you're attempting to maximize
308
+ * @param maximizeOptions Object potentially containing forceEquips, bonusEquips, preventEquips, and preventSlots
309
+ */
310
+ constructor(maximizeParameters, maximizeOptions) {
311
+ this.#maximizeParameters = maximizeParameters;
312
+ this.#maximizeOptions = maximizeOptions;
313
+ }
314
+ #maximizeParameters;
315
+ #maximizeOptions;
316
+ get maximizeParameters() {
317
+ return this.#maximizeParameters;
318
+ }
319
+ get maximizeOptions() {
320
+ return this.#maximizeOptions;
579
321
  }
580
322
  /**
581
323
  * Merges two requirements, concanating relevant arrays. Typically used in static form.
582
324
  * @param other Requirement to merge with.
583
325
  */
584
-
585
- }, {
586
- key: "merge",
587
- value: function merge(other) {
588
- var _optionsA$forceEquip, _other$maximizeOption, _optionsA$preventEqui, _other$maximizeOption2, _optionsA$bonusEquip$, _optionsA$bonusEquip, _optionsB$bonusEquip$, _optionsB$bonusEquip, _optionsA$onlySlot, _optionsB$onlySlot, _optionsA$preventSlot, _optionsB$preventSlot;
589
-
590
- var optionsA = this.maximizeOptions;
591
- var optionsB = other.maximizeOptions;
592
- return new Requirement([].concat(_toConsumableArray(this.maximizeParameters), _toConsumableArray(other.maximizeParameters)), {
593
- updateOnFamiliarChange: optionsA.updateOnFamiliarChange || other.maximizeOptions.updateOnFamiliarChange,
594
- updateOnCanEquipChanged: optionsA.updateOnCanEquipChanged || other.maximizeOptions.updateOnCanEquipChanged,
595
- forceEquip: [].concat(_toConsumableArray((_optionsA$forceEquip = optionsA.forceEquip) !== null && _optionsA$forceEquip !== void 0 ? _optionsA$forceEquip : []), _toConsumableArray((_other$maximizeOption = other.maximizeOptions.forceEquip) !== null && _other$maximizeOption !== void 0 ? _other$maximizeOption : [])),
596
- preventEquip: [].concat(_toConsumableArray((_optionsA$preventEqui = optionsA.preventEquip) !== null && _optionsA$preventEqui !== void 0 ? _optionsA$preventEqui : []), _toConsumableArray((_other$maximizeOption2 = other.maximizeOptions.preventEquip) !== null && _other$maximizeOption2 !== void 0 ? _other$maximizeOption2 : [])),
597
- bonusEquip: new Map([].concat(_toConsumableArray((_optionsA$bonusEquip$ = (_optionsA$bonusEquip = optionsA.bonusEquip) === null || _optionsA$bonusEquip === void 0 ? void 0 : _optionsA$bonusEquip.entries()) !== null && _optionsA$bonusEquip$ !== void 0 ? _optionsA$bonusEquip$ : []), _toConsumableArray((_optionsB$bonusEquip$ = (_optionsB$bonusEquip = optionsB.bonusEquip) === null || _optionsB$bonusEquip === void 0 ? void 0 : _optionsB$bonusEquip.entries()) !== null && _optionsB$bonusEquip$ !== void 0 ? _optionsB$bonusEquip$ : []))),
598
- onlySlot: [].concat(_toConsumableArray((_optionsA$onlySlot = optionsA.onlySlot) !== null && _optionsA$onlySlot !== void 0 ? _optionsA$onlySlot : []), _toConsumableArray((_optionsB$onlySlot = optionsB.onlySlot) !== null && _optionsB$onlySlot !== void 0 ? _optionsB$onlySlot : [])),
599
- preventSlot: [].concat(_toConsumableArray((_optionsA$preventSlot = optionsA.preventSlot) !== null && _optionsA$preventSlot !== void 0 ? _optionsA$preventSlot : []), _toConsumableArray((_optionsB$preventSlot = optionsB.preventSlot) !== null && _optionsB$preventSlot !== void 0 ? _optionsB$preventSlot : []))
600
- });
326
+ merge(other) {
327
+ const optionsA = this.maximizeOptions;
328
+ const optionsB = other.maximizeOptions;
329
+ return new Requirement([...this.maximizeParameters, ...other.maximizeParameters], {
330
+ updateOnFamiliarChange: optionsA.updateOnFamiliarChange ||
331
+ other.maximizeOptions.updateOnFamiliarChange,
332
+ updateOnCanEquipChanged: optionsA.updateOnCanEquipChanged ||
333
+ other.maximizeOptions.updateOnCanEquipChanged,
334
+ forceEquip: [
335
+ ...(optionsA.forceEquip ?? []),
336
+ ...(other.maximizeOptions.forceEquip ?? []),
337
+ ],
338
+ preventEquip: [
339
+ ...(optionsA.preventEquip ?? []),
340
+ ...(other.maximizeOptions.preventEquip ?? []),
341
+ ],
342
+ bonusEquip: new Map([
343
+ ...(optionsA.bonusEquip?.entries() ?? []),
344
+ ...(optionsB.bonusEquip?.entries() ?? []),
345
+ ]),
346
+ onlySlot: [...(optionsA.onlySlot ?? []), ...(optionsB.onlySlot ?? [])],
347
+ preventSlot: [
348
+ ...(optionsA.preventSlot ?? []),
349
+ ...(optionsB.preventSlot ?? []),
350
+ ],
351
+ });
601
352
  }
602
353
  /**
603
354
  * Merges a set of requirements together, starting with an empty requirement.
604
355
  * @param allRequirements Requirements to merge
605
356
  */
606
-
607
- }, {
608
- key: "maximize",
609
- value:
357
+ static merge(allRequirements) {
358
+ return allRequirements.reduce((x, y) => x.merge(y), new Requirement([], {}));
359
+ }
610
360
  /**
611
361
  * Runs maximizeCached, using the maximizeParameters and maximizeOptions contained by this requirement.
612
362
  */
613
- function maximize() {
614
- maximizeCached(this.maximizeParameters, this.maximizeOptions);
363
+ maximize() {
364
+ maximizeCached(this.maximizeParameters, this.maximizeOptions);
615
365
  }
616
366
  /**
617
367
  * Merges requirements, and then runs maximizeCached on the combined requirement.
618
368
  * @param requirements Requirements to maximize on
619
369
  */
620
-
621
- }], [{
622
- key: "merge",
623
- value: function merge(allRequirements) {
624
- return allRequirements.reduce((x, y) => x.merge(y), new Requirement([], {}));
625
- }
626
- }, {
627
- key: "maximize",
628
- value: function maximize() {
629
- for (var _len = arguments.length, requirements = new Array(_len), _key = 0; _key < _len; _key++) {
630
- requirements[_key] = arguments[_key];
631
- }
632
-
633
- Requirement.merge(requirements).maximize();
634
- }
635
- }]);
636
-
637
- return Requirement;
638
- }();
639
-
640
- exports.Requirement = Requirement;
370
+ static maximize(...requirements) {
371
+ Requirement.merge(requirements).maximize();
372
+ }
373
+ }