libram 0.7.17 → 0.7.18

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 (67) hide show
  1. package/dist/actions/FreeRun.js +5 -5
  2. package/dist/challengePaths/2015/CommunityService.d.ts +12 -0
  3. package/dist/challengePaths/2015/CommunityService.js +33 -11
  4. package/dist/combat.d.ts +14 -0
  5. package/dist/combat.js +18 -0
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lib.d.ts +15 -1
  9. package/dist/lib.js +22 -1
  10. package/dist/modifier.d.ts +8 -0
  11. package/dist/modifier.js +10 -0
  12. package/dist/propertyTypes.d.ts +3 -3
  13. package/dist/propertyTypes.js +3 -3
  14. package/dist/resources/2007/CandyHearts.d.ts +0 -1
  15. package/dist/resources/2007/CandyHearts.js +1 -1
  16. package/dist/resources/2008/DivineFavors.d.ts +0 -1
  17. package/dist/resources/2008/DivineFavors.js +1 -1
  18. package/dist/resources/2009/Bandersnatch.d.ts +0 -1
  19. package/dist/resources/2009/Bandersnatch.js +1 -1
  20. package/dist/resources/2009/LoveSongs.d.ts +0 -1
  21. package/dist/resources/2009/LoveSongs.js +1 -1
  22. package/dist/resources/2009/SpookyPutty.d.ts +0 -1
  23. package/dist/resources/2009/SpookyPutty.js +1 -1
  24. package/dist/resources/2010/Brickos.d.ts +0 -1
  25. package/dist/resources/2010/Brickos.js +1 -1
  26. package/dist/resources/2011/Gygaxian.d.ts +0 -1
  27. package/dist/resources/2011/Gygaxian.js +1 -1
  28. package/dist/resources/2011/ObtuseAngel.d.ts +0 -1
  29. package/dist/resources/2011/ObtuseAngel.js +1 -1
  30. package/dist/resources/2011/StompingBoots.d.ts +0 -1
  31. package/dist/resources/2011/StompingBoots.js +1 -1
  32. package/dist/resources/2012/RainDoh.d.ts +0 -1
  33. package/dist/resources/2012/RainDoh.js +1 -1
  34. package/dist/resources/2012/Resolutions.d.ts +0 -1
  35. package/dist/resources/2012/Resolutions.js +1 -1
  36. package/dist/resources/2013/PulledTaffy.d.ts +0 -1
  37. package/dist/resources/2013/PulledTaffy.js +1 -1
  38. package/dist/resources/2016/SourceTerminal.d.ts +0 -1
  39. package/dist/resources/2016/SourceTerminal.js +1 -1
  40. package/dist/resources/2016/Witchess.d.ts +0 -1
  41. package/dist/resources/2016/Witchess.js +1 -1
  42. package/dist/resources/2017/Robortender.d.ts +0 -4
  43. package/dist/resources/2017/Robortender.js +1 -1
  44. package/dist/resources/2018/SongBoom.d.ts +0 -1
  45. package/dist/resources/2018/SongBoom.js +1 -1
  46. package/dist/resources/2020/Cartography.d.ts +0 -2
  47. package/dist/resources/2020/Cartography.js +1 -2
  48. package/dist/resources/2020/Guzzlr.d.ts +0 -1
  49. package/dist/resources/2020/Guzzlr.js +1 -1
  50. package/dist/resources/2020/RetroCape.d.ts +0 -1
  51. package/dist/resources/2020/RetroCape.js +1 -1
  52. package/dist/resources/2021/DaylightShavings.d.ts +0 -1
  53. package/dist/resources/2021/DaylightShavings.js +1 -1
  54. package/dist/resources/2022/AutumnAton.d.ts +0 -1
  55. package/dist/resources/2022/AutumnAton.js +1 -1
  56. package/dist/resources/2022/CombatLoversLocket.d.ts +0 -1
  57. package/dist/resources/2022/CombatLoversLocket.js +1 -1
  58. package/dist/resources/2022/GreyGoose.d.ts +0 -1
  59. package/dist/resources/2022/GreyGoose.js +1 -1
  60. package/dist/resources/2022/TrainSet.d.ts +0 -1
  61. package/dist/resources/2022/TrainSet.js +1 -1
  62. package/dist/resources/2023/ClosedCircuitPayphone.d.ts +0 -1
  63. package/dist/resources/2023/ClosedCircuitPayphone.js +4 -4
  64. package/dist/resources/2023/CursedMonkeyPaw.d.ts +15 -3
  65. package/dist/resources/2023/CursedMonkeyPaw.js +18 -8
  66. package/dist/resources/LibramSummon.js +22 -21
  67. package/package.json +1 -1
@@ -6,7 +6,7 @@ import { get } from "../property";
6
6
  import * as Bandersnatch from "../resources/2009/Bandersnatch";
7
7
  import * as StompingBoots from "../resources/2011/StompingBoots";
8
8
  import * as AsdonMartin from "../resources/2017/AsdonMartin";
9
- import { $effect, $item, $items, $skill } from "../template-string";
9
+ import { $effect, $familiar, $item, $items, $skill } from "../template-string";
10
10
  import { ActionSource, findActionSource, } from "./ActionSource";
11
11
  // Value of _lastCombatStarted the last time we updated scrapbook charges.
12
12
  let scrapbookChargesLastUpdated = get("_lastCombatStarted");
@@ -28,7 +28,7 @@ const asdonMartinSource = new ActionSource($skill `Asdon Martin: Spring-Loaded F
28
28
  });
29
29
  const freeRunSources = [
30
30
  // Free limited sources
31
- new ActionSource(Bandersnatch.familiar, () => (have($effect `Ode to Booze`) || getSongCount() < getSongLimit()) &&
31
+ new ActionSource($familiar `Frumious Bandersnatch`, () => (have($effect `Ode to Booze`) || getSongCount() < getSongLimit()) &&
32
32
  Bandersnatch.couldRunaway()
33
33
  ? Bandersnatch.getRemainingRunaways()
34
34
  : 0, Macro.step("runaway"), {
@@ -37,11 +37,11 @@ const freeRunSources = [
37
37
  ensureEffect($effect `Ode to Booze`);
38
38
  return have($effect `Ode to Booze`);
39
39
  },
40
- familiar: () => Bandersnatch.familiar,
40
+ familiar: () => $familiar `Frumious Bandersnatch`,
41
41
  }),
42
- new ActionSource(StompingBoots.familiar, () => StompingBoots.couldRunaway() ? StompingBoots.getRemainingRunaways() : 0, Macro.step("runaway"), {
42
+ new ActionSource($familiar `Pair of Stomping Boots`, () => StompingBoots.couldRunaway() ? StompingBoots.getRemainingRunaways() : 0, Macro.step("runaway"), {
43
43
  equipmentRequirements: () => new Requirement(["Familiar Weight"], {}),
44
- familiar: () => StompingBoots.familiar,
44
+ familiar: () => $familiar `Pair of Stomping Boots`,
45
45
  }),
46
46
  new ActionSource($skill `Snokebomb`, () => (have($skill `Snokebomb`) ? 3 - get("_snokebombUsed") : 0), Macro.skill($skill `Snokebomb`), {
47
47
  preparation: () => restoreMp(50),
@@ -5,6 +5,7 @@ export default class CommunityService {
5
5
  private property;
6
6
  private predictor;
7
7
  private maximizeRequirements;
8
+ private timer;
8
9
  /**
9
10
  * Class to store properties of various CS tests.
10
11
  *
@@ -35,6 +36,17 @@ export default class CommunityService {
35
36
  * @returns A Requirement object, if applicable, that aligns with the things needed to maximize for this particular test.
36
37
  */
37
38
  get requirement(): Requirement | null;
39
+ /**
40
+ * Start the time & turn counter for the Test in question.
41
+ */
42
+ startTimer(): void;
43
+ private static taskTimers;
44
+ /**
45
+ * Start the time & turn counter for the given task
46
+ *
47
+ * @param name The name of the task to start the counter of
48
+ */
49
+ static startTimer(name: string): void;
38
50
  static logTask(name: string, action: () => number | void): void;
39
51
  /**
40
52
  * Checks the "csServicesPerformed" property to see whether mafia currently believes this test is complete.
@@ -26,6 +26,7 @@ export default class CommunityService {
26
26
  property;
27
27
  predictor;
28
28
  maximizeRequirements;
29
+ timer = null;
29
30
  /**
30
31
  * Class to store properties of various CS tests.
31
32
  *
@@ -72,15 +73,34 @@ export default class CommunityService {
72
73
  get requirement() {
73
74
  return this.maximizeRequirements;
74
75
  }
76
+ /**
77
+ * Start the time & turn counter for the Test in question.
78
+ */
79
+ startTimer() {
80
+ this.timer ??= { time: Date.now(), turns: myTurncount() };
81
+ }
82
+ static taskTimers = new Map();
83
+ /**
84
+ * Start the time & turn counter for the given task
85
+ *
86
+ * @param name The name of the task to start the counter of
87
+ */
88
+ static startTimer(name) {
89
+ if (!this.taskTimers.has(name)) {
90
+ this.taskTimers.set(name, { time: Date.now(), turns: myTurncount() });
91
+ }
92
+ }
75
93
  static logTask(name, action) {
76
- const startTime = Date.now();
77
- const startTurns = myTurncount();
78
94
  const estimatedTurns = action() ?? 0;
95
+ const { time, turns } = this.taskTimers.get(name) ?? {
96
+ time: Date.now(),
97
+ turns: myTurncount(),
98
+ };
79
99
  CommunityService.log[name] = {
80
100
  type: "task",
81
- turnCost: myTurncount() - startTurns,
101
+ turnCost: myTurncount() - turns,
82
102
  predictedTurns: estimatedTurns,
83
- seconds: (Date.now() - startTime) / 1000,
103
+ seconds: (Date.now() - time) / 1000,
84
104
  };
85
105
  }
86
106
  /**
@@ -120,8 +140,10 @@ export default class CommunityService {
120
140
  run(prepare, maxTurns = Infinity) {
121
141
  if (this.isDone())
122
142
  return "already completed";
123
- const startTime = Date.now();
124
- const startTurns = myTurncount();
143
+ const { time, turns } = this.timer ?? {
144
+ time: Date.now(),
145
+ turns: myTurncount(),
146
+ };
125
147
  let additionalTurns;
126
148
  try {
127
149
  const result = prepare();
@@ -133,18 +155,18 @@ export default class CommunityService {
133
155
  }
134
156
  const prediction = this.predictor();
135
157
  const council = visitCouncil();
136
- const turns = this._actualCost(council);
137
- if (!turns)
158
+ const turnCost = this._actualCost(council);
159
+ if (!turnCost)
138
160
  return "already completed";
139
- if (turns > Math.min(maxTurns, myAdventures())) {
161
+ if (turnCost > Math.min(maxTurns, myAdventures())) {
140
162
  return "failed";
141
163
  }
142
164
  if (!this.do())
143
165
  return "failed";
144
166
  CommunityService.log[this.property] = {
145
167
  predictedTurns: prediction + additionalTurns,
146
- turnCost: myTurncount() - startTurns,
147
- seconds: (Date.now() - startTime) / 1000,
168
+ turnCost: myTurncount() - turns,
169
+ seconds: (Date.now() - time) / 1000,
148
170
  type: "test",
149
171
  };
150
172
  return "completed";
package/dist/combat.d.ts CHANGED
@@ -108,6 +108,20 @@ export declare class Macro {
108
108
  * @returns {Macro} This object itself.
109
109
  */
110
110
  static abort<T extends Macro>(this: Constructor<T>): T;
111
+ /**
112
+ * Adds an "abort" step to this macro, with a warning message to print
113
+ *
114
+ * @param warning The warning message to print
115
+ * @returns {Macro} This object itself.
116
+ */
117
+ abortWithWarning(warning: string): this;
118
+ /**
119
+ * Create a new macro with an "abort" step to this macro, with a warning message to print
120
+ *
121
+ * @param warning The warning message to print
122
+ * @returns {Macro} This object itself.
123
+ */
124
+ static abortWithWarning<T extends Macro>(this: Constructor<T>, warning: string): T;
111
125
  /**
112
126
  * Add a "runaway" step to this macro.
113
127
  *
package/dist/combat.js CHANGED
@@ -233,6 +233,24 @@ export class Macro {
233
233
  static abort() {
234
234
  return new this().abort();
235
235
  }
236
+ /**
237
+ * Adds an "abort" step to this macro, with a warning message to print
238
+ *
239
+ * @param warning The warning message to print
240
+ * @returns {Macro} This object itself.
241
+ */
242
+ abortWithWarning(warning) {
243
+ return this.step(`abort "${warning}"`);
244
+ }
245
+ /**
246
+ * Create a new macro with an "abort" step to this macro, with a warning message to print
247
+ *
248
+ * @param warning The warning message to print
249
+ * @returns {Macro} This object itself.
250
+ */
251
+ static abortWithWarning(warning) {
252
+ return new this().abortWithWarning(warning);
253
+ }
236
254
  /**
237
255
  * Add a "runaway" step to this macro.
238
256
  *
package/dist/index.d.ts CHANGED
@@ -21,7 +21,7 @@ export * as property from "./property";
21
21
  export * as propertyTypes from "./propertyTypes";
22
22
  export * from "./utils";
23
23
  export { get, PropertiesManager, set, setProperties, withProperties, withProperty, withChoices, withChoice, } from "./property";
24
- export { get as getModifier } from "./modifier";
24
+ export { get as getModifier, getTotalModifier } from "./modifier";
25
25
  export { Session } from "./session";
26
26
  export type { LogLevels } from "./logger";
27
27
  export type { Modifiers } from "./modifier";
package/dist/index.js CHANGED
@@ -21,5 +21,5 @@ export * as property from "./property";
21
21
  export * as propertyTypes from "./propertyTypes";
22
22
  export * from "./utils";
23
23
  export { get, PropertiesManager, set, setProperties, withProperties, withProperty, withChoices, withChoice, } from "./property";
24
- export { get as getModifier } from "./modifier";
24
+ export { get as getModifier, getTotalModifier } from "./modifier";
25
25
  export { Session } from "./session";
package/dist/lib.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** @module GeneralLibrary */
2
- import { Effect, Element, Familiar, Item, Location, Monster, Servant, Skill, Stat, Thrall } from "kolmafia";
2
+ import { Effect, Element, Familiar, Item, Location, Monster, Servant, Skill, Slot, Stat, Thrall } from "kolmafia";
3
3
  /**
4
4
  * Determines the current maximum Accordion Thief songs the player can have in their head
5
5
  *
@@ -367,3 +367,17 @@ export declare const byClass: <S>(options: import("./utils").Switch<import("kolm
367
367
  * @returns The html of the resulting page
368
368
  */
369
369
  export declare function directlyUse(item: Item): string;
370
+ /**
371
+ * Unequip all instances of a given equipped item
372
+ *
373
+ * @param item The item in question
374
+ * @returns Whether we succeeded completely--`false` if we unequip some but not all instances of the item.
375
+ */
376
+ export declare function unequip(item: Item): boolean;
377
+ /**
378
+ * Empty a given slot.
379
+ *
380
+ * @param slot The slot in question
381
+ * @returns Whether we successfully emptied the slot
382
+ */
383
+ export declare function unequip(slot: Slot): boolean;
package/dist/lib.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** @module GeneralLibrary */
2
- import { appearanceRates, autosellPrice, availableAmount, booleanModifier, choiceFollowsFight, cliExecute, currentRound, Effect, elementalResistance, Familiar, fullnessLimit, getCampground, getCounters, getPlayerId, getPlayerName, getRelated, handlingChoice, haveEffect, haveFamiliar, haveServant, haveSkill, holiday, inebrietyLimit, inMultiFight, Item, Location, mallPrice, Monster, myClass, myEffects, myFamiliar, myFullness, myInebriety, myPath, myPrimestat, mySpleenUse, myThrall, myTurncount, numericModifier, Path, Servant, Skill, spleenLimit, Thrall, toInt, toItem, toSkill, totalTurnsPlayed, visitUrl, } from "kolmafia";
2
+ import { appearanceRates, autosellPrice, availableAmount, booleanModifier, choiceFollowsFight, cliExecute, currentRound, Effect, elementalResistance, equip, equippedItem, Familiar, fullnessLimit, getCampground, getCounters, getPlayerId, getPlayerName, getRelated, handlingChoice, haveEffect, haveFamiliar, haveServant, haveSkill, holiday, inebrietyLimit, inMultiFight, Item, Location, mallPrice, Monster, myClass, myEffects, myFamiliar, myFullness, myInebriety, myPath, myPrimestat, mySpleenUse, myThrall, myTurncount, numericModifier, Path, Servant, Skill, Slot, spleenLimit, Thrall, toInt, toItem, toSkill, totalTurnsPlayed, visitUrl, } from "kolmafia";
3
3
  import logger from "./logger";
4
4
  import { get } from "./property";
5
5
  import { $class, $element, $familiar, $item, $items, $monsters, $skill, $stat, } from "./template-string";
@@ -746,3 +746,24 @@ export const byClass = makeByXFunction(() => myClass().toString());
746
746
  export function directlyUse(item) {
747
747
  return visitUrl(`inv_use.php?which=3&whichitem=${toInt(item)}&pwd`);
748
748
  }
749
+ /**
750
+ * Empty a slot, or unequip all instances of a given equipped item
751
+ *
752
+ * @param thing The slot or item in question
753
+ * @returns Whether we succeeded completely--`false` if we unequip some but not all instances of the item.
754
+ */
755
+ export function unequip(thing) {
756
+ if (thing instanceof Slot)
757
+ return equip(thing, $item.none);
758
+ const failedSlots = Slot.all().filter((s) => {
759
+ // Filter the slot out if it doesn't contain the relevant item
760
+ if (equippedItem(s) !== thing)
761
+ return false;
762
+ // Filter the slot out if we succeed at unequipping it
763
+ return !unequip(thing);
764
+ // This leaves only slots that do contain the item but that we failed to unequip
765
+ });
766
+ if (failedSlots.length)
767
+ logger.debug(`Failed to unequip ${thing} from slots ${failedSlots.join(", ")}`);
768
+ return failedSlots.length === 0;
769
+ }
@@ -31,3 +31,11 @@ export declare function mergeModifiers(...modifierss: Modifiers[]): Modifiers;
31
31
  */
32
32
  export declare function printModtrace(inputModifiers: string | string[], // the user's list of modifiers to look up
33
33
  baseModifier?: string, componentColor?: string, totalColor?: string): void;
34
+ /**
35
+ * Take the sum of a modifier over an array of Skills, Effects, and Items
36
+ *
37
+ * @param modifier A NumericModifier that we want to find the total value of
38
+ * @param subjects A rested array of Skills, Effects, and Items that we want to find the total value of
39
+ * @returns The sum of the appropriate modifier for all of the subjects
40
+ */
41
+ export declare function getTotalModifier(modifier: NumericModifier, ...subjects: (Skill | Effect | Item)[]): number;
package/dist/modifier.js CHANGED
@@ -148,3 +148,13 @@ baseModifier, componentColor = "purple", totalColor = "blue") {
148
148
  });
149
149
  print(`Total ${baseModifier}: ${total.toFixed(1)}`, totalColor);
150
150
  }
151
+ /**
152
+ * Take the sum of a modifier over an array of Skills, Effects, and Items
153
+ *
154
+ * @param modifier A NumericModifier that we want to find the total value of
155
+ * @param subjects A rested array of Skills, Effects, and Items that we want to find the total value of
156
+ * @returns The sum of the appropriate modifier for all of the subjects
157
+ */
158
+ export function getTotalModifier(modifier, ...subjects) {
159
+ return sum(subjects, (subject) => get(modifier, subject));
160
+ }