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.
- package/dist/Clan.js +268 -485
- package/dist/Copier.js +11 -48
- package/dist/Dungeon.js +77 -157
- package/dist/Kmail.d.ts +3 -1
- package/dist/Kmail.js +92 -243
- package/dist/Path.js +68 -120
- package/dist/ascend.js +153 -172
- package/dist/combat.d.ts +100 -4
- package/dist/combat.js +352 -387
- package/dist/console.js +13 -36
- package/dist/diet/index.d.ts +31 -0
- package/dist/diet/index.js +390 -0
- package/dist/diet/knapsack.d.ts +7 -0
- package/dist/diet/knapsack.js +119 -0
- package/dist/dungeons/Dreadsylvania.d.ts +4 -0
- package/dist/dungeons/Dreadsylvania.js +14 -0
- package/dist/dungeons/Dungeon.d.ts +28 -0
- package/dist/dungeons/Dungeon.js +99 -0
- package/dist/dungeons/Hobopolis.d.ts +4 -0
- package/dist/dungeons/Hobopolis.js +14 -0
- package/dist/dungeons/SlimeTube.d.ts +4 -0
- package/dist/dungeons/SlimeTube.js +14 -0
- package/dist/freerun.d.ts +16 -4
- package/dist/freerun.js +88 -99
- package/dist/index.d.ts +5 -1
- package/dist/index.js +22 -300
- package/dist/lib.d.ts +24 -0
- package/dist/lib.js +304 -488
- package/dist/logger.js +23 -63
- package/dist/maximize.js +289 -556
- package/dist/modifier.d.ts +4 -0
- package/dist/modifier.js +35 -46
- package/dist/modifierTypes.js +8 -22
- package/dist/mood.d.ts +5 -0
- package/dist/mood.js +260 -551
- package/dist/property.d.ts +2 -0
- package/dist/property.js +99 -242
- package/dist/propertyTypes.d.ts +4 -3
- package/dist/propertyTypes.js +1 -0
- package/dist/propertyTyping.d.ts +4 -3
- package/dist/propertyTyping.js +52 -59
- package/dist/resources/2007/CandyHearts.d.ts +9 -0
- package/dist/resources/2007/CandyHearts.js +24 -0
- package/dist/resources/2008/DivineFavors.d.ts +9 -0
- package/dist/resources/2008/DivineFavors.js +27 -0
- package/dist/resources/2009/Bandersnatch.js +37 -112
- package/dist/resources/2009/LoveSongs.d.ts +9 -0
- package/dist/resources/2009/LoveSongs.js +24 -0
- package/dist/resources/2009/SpookyPutty.js +20 -46
- package/dist/resources/2010/Brickos.d.ts +9 -0
- package/dist/resources/2010/Brickos.js +21 -0
- package/dist/resources/2010/CrownOfThrones.d.ts +18 -0
- package/dist/resources/2010/CrownOfThrones.js +550 -0
- package/dist/resources/2011/Gygaxian.d.ts +9 -0
- package/dist/resources/2011/Gygaxian.js +24 -0
- package/dist/resources/2011/ObtuseAngel.js +21 -63
- package/dist/resources/2012/RainDoh.js +14 -40
- package/dist/resources/2012/Resolutions.d.ts +9 -0
- package/dist/resources/2012/Resolutions.js +28 -0
- package/dist/resources/2013/Florist.d.ts +1 -0
- package/dist/resources/2013/Florist.js +137 -207
- package/dist/resources/2013/PulledTaffy.d.ts +9 -0
- package/dist/resources/2013/PulledTaffy.js +33 -0
- package/dist/resources/2014/DNALab.d.ts +47 -0
- package/dist/resources/2014/DNALab.js +154 -0
- package/dist/resources/2014/WinterGarden.js +15 -43
- package/dist/resources/2015/ChateauMantegna.js +52 -86
- package/dist/resources/2015/MayoClinic.d.ts +3 -0
- package/dist/resources/2015/MayoClinic.js +36 -65
- package/dist/resources/2016/SourceTerminal.d.ts +1 -0
- package/dist/resources/2016/SourceTerminal.js +114 -237
- package/dist/resources/2016/Witchess.js +33 -59
- package/dist/resources/2017/AsdonMartin.d.ts +27 -0
- package/dist/resources/2017/AsdonMartin.js +80 -0
- package/dist/resources/2017/TunnelOfLove.js +62 -111
- package/dist/resources/2018/SongBoom.js +32 -68
- package/dist/resources/2019/BeachComb.js +26 -44
- package/dist/resources/2019/Snapper.d.ts +28 -0
- package/dist/resources/2019/Snapper.js +69 -0
- package/dist/resources/2020/Guzzlr.d.ts +3 -0
- package/dist/resources/2020/Guzzlr.js +92 -163
- package/dist/resources/LibramSummon.d.ts +12 -0
- package/dist/resources/LibramSummon.js +66 -0
- package/dist/resources/index.d.ts +20 -14
- package/dist/resources/index.js +21 -100
- package/dist/resources/putty-likes.js +15 -30
- package/dist/ring-buffer.d.ts +24 -0
- package/dist/ring-buffer.js +135 -0
- package/dist/since.d.ts +1 -0
- package/dist/since.js +56 -112
- package/dist/template-string.js +40 -132
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +54 -123
- package/package.json +8 -3
- package/dist/libram-example-briefcase.js +0 -16073
- package/dist/libram-example-clan.js +0 -7050
- package/dist/libram-example-consult.js +0 -5032
- package/dist/libram-example-item.js +0 -2870
- package/dist/libram-example-kmail.js +0 -2065
- package/dist/libram-example-lib.js +0 -6369
- package/dist/libram-example-modifier.js +0 -4495
- package/dist/libram-example-props.js +0 -3996
- package/dist/libram-example-resources.js +0 -10461
package/dist/maximize.js
CHANGED
|
@@ -1,105 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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
|
-
|
|
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
|
-
|
|
614
|
-
|
|
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
|
-
|
|
623
|
-
|
|
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
|
+
}
|