libram 0.3.2 → 0.4.2

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 (99) 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 +13 -7
  5. package/dist/Kmail.js +92 -233
  6. package/dist/Path.js +68 -120
  7. package/dist/ascend.js +153 -172
  8. package/dist/combat.d.ts +86 -1
  9. package/dist/combat.js +295 -387
  10. package/dist/console.js +13 -36
  11. package/dist/diet/index.d.ts +31 -0
  12. package/dist/diet/index.js +333 -0
  13. package/dist/diet/knapsack.d.ts +7 -0
  14. package/dist/diet/knapsack.js +106 -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 +23 -0
  24. package/dist/freerun.js +92 -0
  25. package/dist/index.d.ts +6 -1
  26. package/dist/index.js +21 -263
  27. package/dist/lib.d.ts +43 -0
  28. package/dist/lib.js +296 -405
  29. package/dist/logger.js +23 -63
  30. package/dist/maximize.d.ts +29 -12
  31. package/dist/maximize.js +318 -421
  32. package/dist/modifier.d.ts +13 -0
  33. package/dist/modifier.js +35 -0
  34. package/dist/modifierTypes.d.ts +16 -0
  35. package/dist/modifierTypes.js +9 -0
  36. package/dist/mood.js +220 -531
  37. package/dist/property.d.ts +2 -0
  38. package/dist/property.js +96 -242
  39. package/dist/propertyTypes.d.ts +9 -0
  40. package/dist/propertyTypes.js +1 -0
  41. package/dist/propertyTyping.d.ts +2 -9
  42. package/dist/propertyTyping.js +42 -53
  43. package/dist/resources/2007/CandyHearts.d.ts +9 -0
  44. package/dist/resources/2007/CandyHearts.js +24 -0
  45. package/dist/resources/2008/DivineFavors.d.ts +9 -0
  46. package/dist/resources/2008/DivineFavors.js +27 -0
  47. package/dist/resources/2009/Bandersnatch.js +37 -112
  48. package/dist/resources/2009/LoveSongs.d.ts +9 -0
  49. package/dist/resources/2009/LoveSongs.js +24 -0
  50. package/dist/resources/2009/SpookyPutty.js +20 -46
  51. package/dist/resources/2010/Brickos.d.ts +9 -0
  52. package/dist/resources/2010/Brickos.js +21 -0
  53. package/dist/resources/2010/CrownOfThrones.d.ts +18 -0
  54. package/dist/resources/2010/CrownOfThrones.js +550 -0
  55. package/dist/resources/2011/Gygaxian.d.ts +9 -0
  56. package/dist/resources/2011/Gygaxian.js +24 -0
  57. package/dist/resources/2011/ObtuseAngel.js +21 -63
  58. package/dist/resources/2012/RainDoh.js +14 -40
  59. package/dist/resources/2012/Resolutions.d.ts +9 -0
  60. package/dist/resources/2012/Resolutions.js +28 -0
  61. package/dist/resources/2013/Florist.d.ts +61 -0
  62. package/dist/resources/2013/Florist.js +149 -0
  63. package/dist/resources/2013/PulledTaffy.d.ts +9 -0
  64. package/dist/resources/2013/PulledTaffy.js +33 -0
  65. package/dist/resources/2014/WinterGarden.js +15 -43
  66. package/dist/resources/2015/ChateauMantegna.js +52 -86
  67. package/dist/resources/2015/MayoClinic.d.ts +13 -0
  68. package/dist/resources/2015/MayoClinic.js +36 -0
  69. package/dist/resources/2016/SourceTerminal.d.ts +1 -0
  70. package/dist/resources/2016/SourceTerminal.js +114 -237
  71. package/dist/resources/2016/Witchess.js +33 -59
  72. package/dist/resources/2017/TunnelOfLove.js +62 -111
  73. package/dist/resources/2018/SongBoom.js +32 -68
  74. package/dist/resources/2019/BeachComb.d.ts +2 -0
  75. package/dist/resources/2019/BeachComb.js +26 -0
  76. package/dist/resources/2019/Snapper.d.ts +28 -0
  77. package/dist/resources/2019/Snapper.js +70 -0
  78. package/dist/resources/2020/Guzzlr.js +79 -163
  79. package/dist/resources/LibramSummon.d.ts +12 -0
  80. package/dist/resources/LibramSummon.js +66 -0
  81. package/dist/resources/index.d.ts +18 -11
  82. package/dist/resources/index.js +19 -85
  83. package/dist/resources/putty-likes.js +15 -30
  84. package/dist/ring-buffer.d.ts +24 -0
  85. package/dist/ring-buffer.js +135 -0
  86. package/dist/since.d.ts +1 -0
  87. package/dist/since.js +56 -112
  88. package/dist/template-string.js +40 -132
  89. package/dist/utils.d.ts +14 -0
  90. package/dist/utils.js +50 -114
  91. package/package.json +5 -3
  92. package/dist/libram-example-briefcase.js +0 -16073
  93. package/dist/libram-example-clan.js +0 -8898
  94. package/dist/libram-example-consult.js +0 -6179
  95. package/dist/libram-example-item.js +0 -3248
  96. package/dist/libram-example-kmail.js +0 -2065
  97. package/dist/libram-example-lib.js +0 -7608
  98. package/dist/libram-example-props.js +0 -4770
  99. package/dist/libram-example-resources.js +0 -12226
package/dist/mood.js CHANGED
@@ -1,586 +1,275 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.reflect.construct.js");
4
-
5
- require("core-js/modules/es.array.slice.js");
6
-
7
- require("core-js/modules/es.object.to-string.js");
8
-
9
- require("core-js/modules/es.symbol.js");
10
-
11
- require("core-js/modules/es.symbol.description.js");
12
-
13
- require("core-js/modules/es.array.iterator.js");
14
-
15
- require("core-js/modules/es.array.filter.js");
16
-
17
- require("core-js/modules/es.object.get-own-property-descriptors.js");
18
-
19
- Object.defineProperty(exports, "__esModule", {
20
- value: true
21
- });
22
- exports.Mood = exports.MagicalSausages = exports.OscusSoda = exports.MpSource = void 0;
23
-
24
- require("core-js/modules/es.array.find.js");
25
-
26
- require("core-js/modules/es.array.includes.js");
27
-
28
- require("core-js/modules/es.string.includes.js");
29
-
30
- var _kolmafia = require("kolmafia");
31
-
32
- var _lib = require("./lib");
33
-
34
- var _property = require("./property");
35
-
36
- var _templateString = require("./template-string");
37
-
38
- var _utils = require("./utils");
39
-
40
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
41
-
42
- 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; }
43
-
44
- 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; }
45
-
46
- 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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
47
-
48
- 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); }
49
-
50
- 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; }
51
-
52
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
53
-
54
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
55
-
56
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
57
-
58
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
59
-
60
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
61
-
62
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
63
-
64
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
65
-
66
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
67
-
68
- 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; }
69
-
70
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
71
-
72
- 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); } }
73
-
74
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
75
-
76
- var MpSource = /*#__PURE__*/function () {
77
- function MpSource() {
78
- _classCallCheck(this, MpSource);
79
- }
80
-
81
- _createClass(MpSource, [{
82
- key: "usesRemaining",
83
- value: function usesRemaining() {
84
- return null;
1
+ import { availableAmount, buy, cliExecute, eat, effectModifier, haveEffect, haveSkill, hpCost, itemAmount, mallPrice, mpCost, myHp, myMaxmp, myMp, numericModifier, retrieveItem, toEffect, toSkill, turnsPerCast, use, useSkill, } from "kolmafia";
2
+ import { getActiveSongs, have, isSong } from "./lib";
3
+ import { get } from "./property";
4
+ import { $item, $skill } from "./template-string";
5
+ import { clamp, sum } from "./utils";
6
+ export class MpSource {
7
+ usesRemaining() {
8
+ return null;
85
9
  }
86
- }, {
87
- key: "availableMpMax",
88
- value: function availableMpMax() {
89
- return this.availableMpMin();
10
+ availableMpMax() {
11
+ return this.availableMpMin();
90
12
  }
91
- }]);
92
-
93
- return MpSource;
94
- }();
95
-
96
- exports.MpSource = MpSource;
97
-
98
- var OscusSoda = /*#__PURE__*/function (_MpSource) {
99
- _inherits(OscusSoda, _MpSource);
100
-
101
- var _super = _createSuper(OscusSoda);
102
-
103
- function OscusSoda() {
104
- _classCallCheck(this, OscusSoda);
105
-
106
- return _super.apply(this, arguments);
107
- }
108
-
109
- _createClass(OscusSoda, [{
110
- key: "available",
111
- value: function available() {
112
- return (0, _lib.have)((0, _templateString.$item)(_templateObject || (_templateObject = _taggedTemplateLiteral(["Oscus's neverending soda"]))));
13
+ }
14
+ export class OscusSoda extends MpSource {
15
+ available() {
16
+ return have($item `Oscus's neverending soda`);
113
17
  }
114
- }, {
115
- key: "usesRemaining",
116
- value: function usesRemaining() {
117
- return (0, _property.get)("oscusSodaUsed") ? 0 : 1;
18
+ usesRemaining() {
19
+ return get("oscusSodaUsed") ? 0 : 1;
118
20
  }
119
- }, {
120
- key: "availableMpMin",
121
- value: function availableMpMin() {
122
- return this.available() ? 200 : 0;
21
+ availableMpMin() {
22
+ return this.available() ? 200 : 0;
123
23
  }
124
- }, {
125
- key: "availableMpMax",
126
- value: function availableMpMax() {
127
- return this.available() ? 300 : 0;
24
+ availableMpMax() {
25
+ return this.available() ? 300 : 0;
128
26
  }
129
- }, {
130
- key: "execute",
131
- value: function execute() {
132
- (0, _kolmafia.use)((0, _templateString.$item)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["Oscus's neverending soda"]))));
27
+ execute() {
28
+ use($item `Oscus's neverending soda`);
133
29
  }
134
- }]);
135
-
136
- return OscusSoda;
137
- }(MpSource);
138
-
139
- exports.OscusSoda = OscusSoda;
140
-
141
- _defineProperty(OscusSoda, "instance", new OscusSoda());
142
-
143
- var MagicalSausages = /*#__PURE__*/function (_MpSource2) {
144
- _inherits(MagicalSausages, _MpSource2);
145
-
146
- var _super2 = _createSuper(MagicalSausages);
147
-
148
- function MagicalSausages() {
149
- _classCallCheck(this, MagicalSausages);
150
-
151
- return _super2.apply(this, arguments);
152
- }
153
-
154
- _createClass(MagicalSausages, [{
155
- key: "usesRemaining",
156
- value: function usesRemaining() {
157
- return 23 - (0, _property.get)("_sausagesEaten");
30
+ }
31
+ OscusSoda.instance = new OscusSoda();
32
+ export class MagicalSausages extends MpSource {
33
+ usesRemaining() {
34
+ return 23 - get("_sausagesEaten");
158
35
  }
159
- }, {
160
- key: "availableMpMin",
161
- value: function availableMpMin() {
162
- var maxSausages = Math.min(23 - (0, _property.get)("_sausagesEaten"), (0, _kolmafia.itemAmount)((0, _templateString.$item)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["magical sausage"])))) + (0, _kolmafia.itemAmount)((0, _templateString.$item)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["magical sausage casing"])))));
163
- return Math.min((0, _kolmafia.myMaxmp)(), 999) * maxSausages;
36
+ availableMpMin() {
37
+ const maxSausages = Math.min(23 - get("_sausagesEaten"), itemAmount($item `magical sausage`) +
38
+ itemAmount($item `magical sausage casing`));
39
+ return Math.min(myMaxmp(), 999) * maxSausages;
164
40
  }
165
- }, {
166
- key: "execute",
167
- value: function execute() {
168
- var mpSpaceAvailable = (0, _kolmafia.myMaxmp)() - (0, _kolmafia.myMp)();
169
- if (mpSpaceAvailable < 700) return;
170
- var maxSausages = Math.min(23 - (0, _property.get)("_sausagesEaten"), (0, _kolmafia.itemAmount)((0, _templateString.$item)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["magical sausage"])))) + (0, _kolmafia.itemAmount)((0, _templateString.$item)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["magical sausage casing"])))), Math.floor(((0, _kolmafia.myMaxmp)() - (0, _kolmafia.myMp)()) / Math.min((0, _kolmafia.myMaxmp)() - (0, _kolmafia.myMp)(), 999)));
171
- (0, _kolmafia.retrieveItem)(maxSausages, (0, _templateString.$item)(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["magical sausage"]))));
172
- (0, _kolmafia.eat)(maxSausages, (0, _templateString.$item)(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["magical sausage"]))));
41
+ execute() {
42
+ const mpSpaceAvailable = myMaxmp() - myMp();
43
+ if (mpSpaceAvailable < 700)
44
+ return;
45
+ const maxSausages = Math.min(23 - get("_sausagesEaten"), itemAmount($item `magical sausage`) +
46
+ itemAmount($item `magical sausage casing`), Math.floor((myMaxmp() - myMp()) / Math.min(myMaxmp() - myMp(), 999)));
47
+ retrieveItem(maxSausages, $item `magical sausage`);
48
+ eat(maxSausages, $item `magical sausage`);
173
49
  }
174
- }]);
175
-
176
- return MagicalSausages;
177
- }(MpSource);
178
-
179
- exports.MagicalSausages = MagicalSausages;
180
-
181
- _defineProperty(MagicalSausages, "instance", new MagicalSausages());
182
-
183
- var MoodElement = /*#__PURE__*/function () {
184
- function MoodElement() {
185
- _classCallCheck(this, MoodElement);
186
- }
187
-
188
- _createClass(MoodElement, [{
189
- key: "mpCostPerTurn",
190
- value: function mpCostPerTurn() {
191
- return 0;
50
+ }
51
+ MagicalSausages.instance = new MagicalSausages();
52
+ class MoodElement {
53
+ mpCostPerTurn() {
54
+ return 0;
192
55
  }
193
- }, {
194
- key: "turnIncrement",
195
- value: function turnIncrement() {
196
- return 1;
56
+ turnIncrement() {
57
+ return 1;
197
58
  }
198
- }]);
199
-
200
- return MoodElement;
201
- }();
202
-
203
- var SkillMoodElement = /*#__PURE__*/function (_MoodElement) {
204
- _inherits(SkillMoodElement, _MoodElement);
205
-
206
- var _super3 = _createSuper(SkillMoodElement);
207
-
208
- function SkillMoodElement(skill) {
209
- var _this;
210
-
211
- _classCallCheck(this, SkillMoodElement);
212
-
213
- _this = _super3.call(this);
214
-
215
- _defineProperty(_assertThisInitialized(_this), "skill", void 0);
216
-
217
- _this.skill = skill;
218
- return _this;
219
- }
220
-
221
- _createClass(SkillMoodElement, [{
222
- key: "mpCostPerTurn",
223
- value: function mpCostPerTurn() {
224
- var turns = (0, _kolmafia.turnsPerCast)(this.skill);
225
- return turns > 0 ? (0, _kolmafia.mpCost)(this.skill) / turns : 0;
59
+ }
60
+ class SkillMoodElement extends MoodElement {
61
+ constructor(skill) {
62
+ super();
63
+ this.skill = skill;
226
64
  }
227
- }, {
228
- key: "turnIncrement",
229
- value: function turnIncrement() {
230
- return (0, _kolmafia.turnsPerCast)(this.skill);
65
+ mpCostPerTurn() {
66
+ const turns = turnsPerCast(this.skill);
67
+ return turns > 0 ? mpCost(this.skill) / turns : 0;
231
68
  }
232
- }, {
233
- key: "execute",
234
- value: function execute(mood, ensureTurns) {
235
- var effect = (0, _kolmafia.toEffect)(this.skill);
236
- var initialTurns = (0, _kolmafia.haveEffect)(effect);
237
- if (!(0, _kolmafia.haveSkill)(this.skill)) return false;
238
- if (initialTurns >= ensureTurns) return true; // Deal with song slots.
239
-
240
- if (mood.options.songSlots.length > 0 && (0, _lib.isSong)(this.skill) && !(0, _lib.have)(effect)) {
241
- var activeSongs = (0, _lib.getActiveSongs)();
242
-
243
- var _iterator = _createForOfIteratorHelper(activeSongs),
244
- _step;
245
-
246
- try {
247
- var _loop = function _loop() {
248
- var song = _step.value;
249
- var slot = mood.options.songSlots.find(slot => slot.includes(song));
250
- if (!slot || slot.includes(effect)) (0, _kolmafia.cliExecute)("shrug ".concat(song));
251
- };
252
-
253
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
254
- _loop();
255
- }
256
- } catch (err) {
257
- _iterator.e(err);
258
- } finally {
259
- _iterator.f();
69
+ turnIncrement() {
70
+ return turnsPerCast(this.skill);
71
+ }
72
+ execute(mood, ensureTurns) {
73
+ const effect = toEffect(this.skill);
74
+ const initialTurns = haveEffect(effect);
75
+ if (!haveSkill(this.skill))
76
+ return false;
77
+ if (initialTurns >= ensureTurns)
78
+ return true;
79
+ // Deal with song slots.
80
+ if (mood.options.songSlots.length > 0 &&
81
+ isSong(this.skill) &&
82
+ !have(effect)) {
83
+ const activeSongs = getActiveSongs();
84
+ for (const song of activeSongs) {
85
+ const slot = mood.options.songSlots.find((slot) => slot.includes(song));
86
+ if (!slot || slot.includes(effect))
87
+ cliExecute(`shrug ${song}`);
88
+ }
260
89
  }
261
- }
262
-
263
- var oldRemainingCasts = -1;
264
- var remainingCasts = Math.ceil((ensureTurns - (0, _kolmafia.haveEffect)(effect)) / (0, _kolmafia.turnsPerCast)(this.skill));
265
-
266
- while (remainingCasts > 0 && oldRemainingCasts !== remainingCasts) {
267
- var maxCasts = void 0;
268
-
269
- if ((0, _kolmafia.hpCost)(this.skill) > 0) {
270
- // FIXME: restore HP
271
- maxCasts = Math.floor((0, _kolmafia.myHp)() / (0, _kolmafia.hpCost)(this.skill));
272
- } else {
273
- var cost = (0, _kolmafia.mpCost)(this.skill);
274
- maxCasts = Math.floor((0, _kolmafia.myMp)() / cost);
275
-
276
- if (maxCasts === 0) {
277
- mood.moreMp(cost);
278
- maxCasts = Math.floor((0, _kolmafia.myMp)() / cost);
279
- }
90
+ let oldRemainingCasts = -1;
91
+ let remainingCasts = Math.ceil((ensureTurns - haveEffect(effect)) / turnsPerCast(this.skill));
92
+ while (remainingCasts > 0 && oldRemainingCasts !== remainingCasts) {
93
+ let maxCasts;
94
+ if (hpCost(this.skill) > 0) {
95
+ // FIXME: restore HP
96
+ maxCasts = Math.floor(myHp() / hpCost(this.skill));
97
+ }
98
+ else {
99
+ const cost = mpCost(this.skill);
100
+ maxCasts = Math.floor(myMp() / cost);
101
+ if (maxCasts === 0) {
102
+ mood.moreMp(cost);
103
+ maxCasts = Math.floor(myMp() / cost);
104
+ }
105
+ }
106
+ const casts = clamp(remainingCasts, 0, Math.min(100, maxCasts));
107
+ useSkill(casts, this.skill);
108
+ oldRemainingCasts = remainingCasts;
109
+ remainingCasts = Math.ceil((ensureTurns - haveEffect(effect)) / turnsPerCast(this.skill));
280
110
  }
281
-
282
- var casts = (0, _utils.clamp)(remainingCasts, 0, Math.min(100, maxCasts));
283
- (0, _kolmafia.useSkill)(casts, this.skill);
284
- oldRemainingCasts = remainingCasts;
285
- remainingCasts = Math.ceil((ensureTurns - (0, _kolmafia.haveEffect)(effect)) / (0, _kolmafia.turnsPerCast)(this.skill));
286
- }
287
-
288
- return (0, _kolmafia.haveEffect)(effect) > ensureTurns;
111
+ return haveEffect(effect) > ensureTurns;
289
112
  }
290
- }]);
291
-
292
- return SkillMoodElement;
293
- }(MoodElement);
294
-
295
- var PotionMoodElement = /*#__PURE__*/function (_MoodElement2) {
296
- _inherits(PotionMoodElement, _MoodElement2);
297
-
298
- var _super4 = _createSuper(PotionMoodElement);
299
-
300
- function PotionMoodElement(potion, maxPricePerTurn) {
301
- var _this2;
302
-
303
- _classCallCheck(this, PotionMoodElement);
304
-
305
- _this2 = _super4.call(this);
306
-
307
- _defineProperty(_assertThisInitialized(_this2), "potion", void 0);
308
-
309
- _defineProperty(_assertThisInitialized(_this2), "maxPricePerTurn", void 0);
310
-
311
- _this2.potion = potion;
312
- _this2.maxPricePerTurn = maxPricePerTurn;
313
- return _this2;
314
- }
315
-
316
- _createClass(PotionMoodElement, [{
317
- key: "execute",
318
- value: function execute(mood, ensureTurns) {
319
- // FIXME: Smarter buying logic.
320
- // FIXME: Allow constructing stuff (e.g. snow cleats)
321
- var effect = (0, _kolmafia.effectModifier)(this.potion, "Effect");
322
- var effectTurns = (0, _kolmafia.haveEffect)(effect);
323
- var turnsPerUse = (0, _kolmafia.numericModifier)(this.potion, "Effect Duration");
324
-
325
- if ((0, _kolmafia.mallPrice)(this.potion) > this.maxPricePerTurn * turnsPerUse) {
326
- return false;
327
- }
328
-
329
- if (effectTurns < ensureTurns) {
330
- var uses = (ensureTurns - effectTurns) / turnsPerUse;
331
- var quantityToBuy = (0, _utils.clamp)(uses - (0, _kolmafia.availableAmount)(this.potion), 0, 100);
332
- (0, _kolmafia.buy)(quantityToBuy, this.potion, this.maxPricePerTurn * turnsPerUse);
333
- var quantityToUse = (0, _utils.clamp)(uses, 0, (0, _kolmafia.availableAmount)(this.potion));
334
- (0, _kolmafia.use)(quantityToUse, this.potion);
335
- }
336
-
337
- return (0, _kolmafia.haveEffect)(effect) >= ensureTurns;
113
+ }
114
+ class PotionMoodElement extends MoodElement {
115
+ constructor(potion, maxPricePerTurn) {
116
+ super();
117
+ this.potion = potion;
118
+ this.maxPricePerTurn = maxPricePerTurn;
338
119
  }
339
- }]);
340
-
341
- return PotionMoodElement;
342
- }(MoodElement);
343
-
344
- var GenieMoodElement = /*#__PURE__*/function (_MoodElement3) {
345
- _inherits(GenieMoodElement, _MoodElement3);
346
-
347
- var _super5 = _createSuper(GenieMoodElement);
348
-
349
- function GenieMoodElement(effect) {
350
- var _this3;
351
-
352
- _classCallCheck(this, GenieMoodElement);
353
-
354
- _this3 = _super5.call(this);
355
-
356
- _defineProperty(_assertThisInitialized(_this3), "effect", void 0);
357
-
358
- _this3.effect = effect;
359
- return _this3;
360
- }
361
-
362
- _createClass(GenieMoodElement, [{
363
- key: "execute",
364
- value: function execute(mood, ensureTurns) {
365
- if ((0, _kolmafia.haveEffect)(this.effect) >= ensureTurns) return true;
366
- var neededWishes = Math.ceil(((0, _kolmafia.haveEffect)(this.effect) - ensureTurns) / 20);
367
- var wishesToBuy = (0, _utils.clamp)(neededWishes - (0, _kolmafia.availableAmount)((0, _templateString.$item)(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["pocket wish"])))), 0, 20);
368
- (0, _kolmafia.buy)(wishesToBuy, (0, _templateString.$item)(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["pocket wish"]))), 50000);
369
- var wishesToUse = (0, _utils.clamp)(neededWishes, 0, (0, _kolmafia.availableAmount)((0, _templateString.$item)(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["pocket wish"])))));
370
-
371
- for (; wishesToUse > 0; wishesToUse--) {
372
- (0, _kolmafia.cliExecute)("genie effect ".concat(this.effect.name));
373
- }
374
-
375
- return (0, _kolmafia.haveEffect)(this.effect) >= ensureTurns;
120
+ execute(mood, ensureTurns) {
121
+ // FIXME: Smarter buying logic.
122
+ // FIXME: Allow constructing stuff (e.g. snow cleats)
123
+ const effect = effectModifier(this.potion, "Effect");
124
+ const effectTurns = haveEffect(effect);
125
+ const turnsPerUse = numericModifier(this.potion, "Effect Duration");
126
+ if (mallPrice(this.potion) > this.maxPricePerTurn * turnsPerUse) {
127
+ return false;
128
+ }
129
+ if (effectTurns < ensureTurns) {
130
+ const uses = (ensureTurns - effectTurns) / turnsPerUse;
131
+ const quantityToBuy = clamp(uses - availableAmount(this.potion), 0, 100);
132
+ buy(quantityToBuy, this.potion, this.maxPricePerTurn * turnsPerUse);
133
+ const quantityToUse = clamp(uses, 0, availableAmount(this.potion));
134
+ use(quantityToUse, this.potion);
135
+ }
136
+ return haveEffect(effect) >= ensureTurns;
376
137
  }
377
- }]);
378
-
379
- return GenieMoodElement;
380
- }(MoodElement);
381
-
382
- var CustomMoodElement = /*#__PURE__*/function (_MoodElement4) {
383
- _inherits(CustomMoodElement, _MoodElement4);
384
-
385
- var _super6 = _createSuper(CustomMoodElement);
386
-
387
- function CustomMoodElement(effect, gainEffect) {
388
- var _this4;
389
-
390
- _classCallCheck(this, CustomMoodElement);
391
-
392
- _this4 = _super6.call(this);
393
-
394
- _defineProperty(_assertThisInitialized(_this4), "effect", void 0);
395
-
396
- _defineProperty(_assertThisInitialized(_this4), "gainEffect", void 0);
397
-
398
- _this4.effect = effect;
399
- _this4.gainEffect = gainEffect !== null && gainEffect !== void 0 ? gainEffect : () => (0, _kolmafia.cliExecute)(effect.default);
400
- return _this4;
401
- }
402
-
403
- _createClass(CustomMoodElement, [{
404
- key: "execute",
405
- value: function execute(mood, ensureTurns) {
406
- var currentTurns = (0, _kolmafia.haveEffect)(this.effect);
407
- var lastCurrentTurns = -1;
408
-
409
- while (currentTurns < ensureTurns && currentTurns !== lastCurrentTurns) {
410
- this.gainEffect();
411
- lastCurrentTurns = currentTurns;
412
- currentTurns = (0, _kolmafia.haveEffect)(this.effect);
413
- }
414
-
415
- return (0, _kolmafia.haveEffect)(this.effect) > ensureTurns;
138
+ }
139
+ class GenieMoodElement extends MoodElement {
140
+ constructor(effect) {
141
+ super();
142
+ this.effect = effect;
416
143
  }
417
- }]);
418
-
419
- return CustomMoodElement;
420
- }(MoodElement);
144
+ execute(mood, ensureTurns) {
145
+ if (haveEffect(this.effect) >= ensureTurns)
146
+ return true;
147
+ const neededWishes = Math.ceil((haveEffect(this.effect) - ensureTurns) / 20);
148
+ const wishesToBuy = clamp(neededWishes - availableAmount($item `pocket wish`), 0, 20);
149
+ buy(wishesToBuy, $item `pocket wish`, 50000);
150
+ let wishesToUse = clamp(neededWishes, 0, availableAmount($item `pocket wish`));
151
+ for (; wishesToUse > 0; wishesToUse--) {
152
+ cliExecute(`genie effect ${this.effect.name}`);
153
+ }
154
+ return haveEffect(this.effect) >= ensureTurns;
155
+ }
156
+ }
157
+ class CustomMoodElement extends MoodElement {
158
+ constructor(effect, gainEffect) {
159
+ super();
160
+ this.effect = effect;
161
+ this.gainEffect = gainEffect ?? (() => cliExecute(effect.default));
162
+ }
163
+ execute(mood, ensureTurns) {
164
+ let currentTurns = haveEffect(this.effect);
165
+ let lastCurrentTurns = -1;
166
+ while (currentTurns < ensureTurns && currentTurns !== lastCurrentTurns) {
167
+ this.gainEffect();
168
+ lastCurrentTurns = currentTurns;
169
+ currentTurns = haveEffect(this.effect);
170
+ }
171
+ return haveEffect(this.effect) > ensureTurns;
172
+ }
173
+ }
421
174
  /**
422
175
  * Class representing a mood object. Add mood elements using the instance methods, which can be chained.
423
176
  */
424
-
425
-
426
- var Mood = /*#__PURE__*/function () {
427
- /**
428
- * Construct a new Mood instance.
429
- * @param options Options for mood.
430
- */
431
- function Mood() {
432
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
433
-
434
- _classCallCheck(this, Mood);
435
-
436
- _defineProperty(this, "options", void 0);
437
-
438
- _defineProperty(this, "elements", []);
439
-
440
- this.options = _objectSpread(_objectSpread({}, Mood.defaultOptions), options);
441
- }
442
- /**
443
- * Get the MP available for casting skills.
444
- */
445
-
446
-
447
- _createClass(Mood, [{
448
- key: "availableMp",
449
- value: function availableMp() {
450
- return (0, _utils.sum)(this.options.mpSources, mpSource => mpSource.availableMpMin()) + Math.max((0, _kolmafia.myMp)() - this.options.reserveMp, 0);
177
+ export class Mood {
178
+ /**
179
+ * Construct a new Mood instance.
180
+ * @param options Options for mood.
181
+ */
182
+ constructor(options = {}) {
183
+ this.elements = [];
184
+ this.options = { ...Mood.defaultOptions, ...options };
451
185
  }
452
- }, {
453
- key: "moreMp",
454
- value: function moreMp(minimumTarget) {
455
- var _iterator2 = _createForOfIteratorHelper(this.options.mpSources),
456
- _step2;
457
-
458
- try {
459
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
460
- var mpSource = _step2.value;
461
- var usesRemaining = mpSource.usesRemaining();
462
-
463
- if (usesRemaining !== null && usesRemaining > 0) {
464
- mpSource.execute();
465
- if ((0, _kolmafia.myMp)() >= minimumTarget) break;
466
- }
186
+ /**
187
+ * Set default options for new Mood instances.
188
+ * @param options Default options for new Mood instances.
189
+ */
190
+ static setDefaultOptions(options) {
191
+ Mood.defaultOptions = { ...Mood.defaultOptions, ...options };
192
+ }
193
+ /**
194
+ * Get the MP available for casting skills.
195
+ */
196
+ availableMp() {
197
+ return (sum(this.options.mpSources, (mpSource) => mpSource.availableMpMin()) + Math.max(myMp() - this.options.reserveMp, 0));
198
+ }
199
+ moreMp(minimumTarget) {
200
+ for (const mpSource of this.options.mpSources) {
201
+ const usesRemaining = mpSource.usesRemaining();
202
+ if (usesRemaining !== null && usesRemaining > 0) {
203
+ mpSource.execute();
204
+ if (myMp() >= minimumTarget)
205
+ break;
206
+ }
467
207
  }
468
- } catch (err) {
469
- _iterator2.e(err);
470
- } finally {
471
- _iterator2.f();
472
- }
473
208
  }
474
209
  /**
475
210
  * Add a skill to the mood.
476
211
  * @param skill Skill to add.
477
212
  */
478
-
479
- }, {
480
- key: "skill",
481
- value: function skill(_skill) {
482
- this.elements.push(new SkillMoodElement(_skill));
483
- return this;
213
+ skill(skill) {
214
+ this.elements.push(new SkillMoodElement(skill));
215
+ return this;
484
216
  }
485
217
  /**
486
218
  * Add an effect to the mood, with casting based on {effect.default}.
487
219
  * @param effect Effect to add.
488
220
  * @param gainEffect How to gain the effect. Only runs if we don't have the effect.
489
221
  */
490
-
491
- }, {
492
- key: "effect",
493
- value: function effect(_effect, gainEffect) {
494
- var skill = (0, _kolmafia.toSkill)(_effect);
495
-
496
- if (!gainEffect && skill !== (0, _templateString.$skill)(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["none"])))) {
497
- this.skill(skill);
498
- } else {
499
- this.elements.push(new CustomMoodElement(_effect, gainEffect));
500
- }
501
-
502
- return this;
222
+ effect(effect, gainEffect) {
223
+ const skill = toSkill(effect);
224
+ if (!gainEffect && skill !== $skill `none`) {
225
+ this.skill(skill);
226
+ }
227
+ else {
228
+ this.elements.push(new CustomMoodElement(effect, gainEffect));
229
+ }
230
+ return this;
503
231
  }
504
232
  /**
505
233
  * Add a potion to the mood.
506
234
  * @param potion Potion to add.
507
235
  * @param maxPricePerTurn Maximum price to pay per turn of the effect.
508
236
  */
509
-
510
- }, {
511
- key: "potion",
512
- value: function potion(_potion, maxPricePerTurn) {
513
- this.elements.push(new PotionMoodElement(_potion, maxPricePerTurn));
514
- return this;
237
+ potion(potion, maxPricePerTurn) {
238
+ this.elements.push(new PotionMoodElement(potion, maxPricePerTurn));
239
+ return this;
515
240
  }
516
241
  /**
517
242
  * Add an effect to acquire via pocket wishes to the mood.
518
243
  * @param effect Effect to wish for in the mood.
519
244
  */
520
-
521
- }, {
522
- key: "genie",
523
- value: function genie(effect) {
524
- this.elements.push(new GenieMoodElement(effect));
525
- return this;
245
+ genie(effect) {
246
+ this.elements.push(new GenieMoodElement(effect));
247
+ return this;
526
248
  }
527
249
  /**
528
250
  * Execute the mood, trying to ensure {ensureTurns} of each effect.
529
251
  * @param ensureTurns Turns of each effect to try and achieve.
530
252
  * @returns Whether or not we successfully got this many turns of every effect in the mood.
531
253
  */
532
-
533
- }, {
534
- key: "execute",
535
- value: function execute() {
536
- var ensureTurns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
537
- var availableMp = this.availableMp();
538
- var totalMpPerTurn = (0, _utils.sum)(this.elements, element => element.mpCostPerTurn());
539
- var potentialTurns = Math.floor(availableMp / totalMpPerTurn);
540
- var completeSuccess = true;
541
-
542
- var _iterator3 = _createForOfIteratorHelper(this.elements),
543
- _step3;
544
-
545
- try {
546
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
547
- var element = _step3.value;
548
- var elementTurns = ensureTurns;
549
-
550
- if (element.mpCostPerTurn() > 0) {
551
- var elementPotentialTurns = Math.floor(potentialTurns / element.turnIncrement()) * element.turnIncrement();
552
- elementTurns = Math.min(ensureTurns, elementPotentialTurns);
553
- }
554
-
555
- completeSuccess = element.execute(this, elementTurns) && completeSuccess;
254
+ execute(ensureTurns = 1) {
255
+ const availableMp = this.availableMp();
256
+ const totalMpPerTurn = sum(this.elements, (element) => element.mpCostPerTurn());
257
+ const potentialTurns = Math.floor(availableMp / totalMpPerTurn);
258
+ let completeSuccess = true;
259
+ for (const element of this.elements) {
260
+ let elementTurns = ensureTurns;
261
+ if (element.mpCostPerTurn() > 0) {
262
+ const elementPotentialTurns = Math.floor(potentialTurns / element.turnIncrement()) *
263
+ element.turnIncrement();
264
+ elementTurns = Math.min(ensureTurns, elementPotentialTurns);
265
+ }
266
+ completeSuccess = element.execute(this, elementTurns) && completeSuccess;
556
267
  }
557
- } catch (err) {
558
- _iterator3.e(err);
559
- } finally {
560
- _iterator3.f();
561
- }
562
-
563
- return completeSuccess;
564
- }
565
- }], [{
566
- key: "setDefaultOptions",
567
- value:
568
- /**
569
- * Set default options for new Mood instances.
570
- * @param options Default options for new Mood instances.
571
- */
572
- function setDefaultOptions(options) {
573
- Mood.defaultOptions = _objectSpread(_objectSpread({}, Mood.defaultOptions), options);
268
+ return completeSuccess;
574
269
  }
575
- }]);
576
-
577
- return Mood;
578
- }();
579
-
580
- exports.Mood = Mood;
581
-
582
- _defineProperty(Mood, "defaultOptions", {
583
- songSlots: [],
584
- mpSources: [MagicalSausages.instance, OscusSoda.instance],
585
- reserveMp: 0
586
- });
270
+ }
271
+ Mood.defaultOptions = {
272
+ songSlots: [],
273
+ mpSources: [MagicalSausages.instance, OscusSoda.instance],
274
+ reserveMp: 0,
275
+ };