libram 0.7.3 → 0.7.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/combat.d.ts CHANGED
@@ -7,6 +7,7 @@ import { Class, Effect, Item, Location, Monster, Skill, Stat } from "kolmafia";
7
7
  */
8
8
  export declare function getMacroId(name?: string): number;
9
9
  declare type ItemOrName = Item | string;
10
+ declare type PreBALLSPredicate = string | Monster | Monster[] | Effect | Skill | Item | Location | Class | Stat;
10
11
  declare type SkillOrName = Skill | string;
11
12
  declare type Constructor<T> = {
12
13
  new (): T;
@@ -97,20 +98,35 @@ export declare class Macro {
97
98
  * @returns {Macro} This object itself.
98
99
  */
99
100
  static runaway<T extends Macro>(this: Constructor<T>): T;
101
+ private static makeBALLSPredicate;
100
102
  /**
101
103
  * Add an "if" statement to this macro.
102
104
  * @param condition The BALLS condition for the if statement.
103
105
  * @param ifTrue Continuation if the condition is true.
104
106
  * @returns {Macro} This object itself.
105
107
  */
106
- if_(condition: string | Monster | Monster[] | Effect | Skill | Item | Location | Class | Stat, ifTrue: string | Macro): this;
108
+ if_(condition: PreBALLSPredicate, ifTrue: string | Macro): this;
107
109
  /**
108
110
  * Create a new macro with an "if" statement.
109
111
  * @param condition The BALLS condition for the if statement.
110
112
  * @param ifTrue Continuation if the condition is true.
111
113
  * @returns {Macro} This object itself.
112
114
  */
113
- static if_<T extends Macro>(this: Constructor<T>, condition: Parameters<T["if_"]>[0], ifTrue: string | Macro): T;
115
+ static if_<T extends Macro>(this: Constructor<T>, condition: PreBALLSPredicate, ifTrue: string | Macro): T;
116
+ /**
117
+ * Add an "if" statement to this macro, inverting the condition.
118
+ * @param condition The BALLS condition for the if statement.
119
+ * @param ifTrue Continuation if the condition is true.
120
+ * @returns {Macro} This object itself.
121
+ */
122
+ ifNot(condition: PreBALLSPredicate, ifTrue: string | Macro): this;
123
+ /**
124
+ * Create a new macro with an "if" statement, inverting the condition.
125
+ * @param condition The BALLS condition for the if statement.
126
+ * @param ifTrue Continuation if the condition is true.
127
+ * @returns {Macro} This object itself.
128
+ */
129
+ static ifNot<T extends Macro>(this: Constructor<T>, condition: PreBALLSPredicate, ifTrue: string | Macro): T;
114
130
  /**
115
131
  * Add a "while" statement to this macro.
116
132
  * @param condition The BALLS condition for the if statement.
package/dist/combat.js CHANGED
@@ -198,13 +198,7 @@ export class Macro {
198
198
  static runaway() {
199
199
  return new this().runaway();
200
200
  }
201
- /**
202
- * Add an "if" statement to this macro.
203
- * @param condition The BALLS condition for the if statement.
204
- * @param ifTrue Continuation if the condition is true.
205
- * @returns {Macro} This object itself.
206
- */
207
- if_(condition, ifTrue) {
201
+ static makeBALLSPredicate(condition) {
208
202
  let ballsCondition = "";
209
203
  if (condition instanceof Monster) {
210
204
  ballsCondition = `monsterid ${condition.id}`;
@@ -246,7 +240,18 @@ export class Macro {
246
240
  else {
247
241
  ballsCondition = condition;
248
242
  }
249
- return this.step(`if ${ballsCondition}`).step(ifTrue).step("endif");
243
+ return ballsCondition;
244
+ }
245
+ /**
246
+ * Add an "if" statement to this macro.
247
+ * @param condition The BALLS condition for the if statement.
248
+ * @param ifTrue Continuation if the condition is true.
249
+ * @returns {Macro} This object itself.
250
+ */
251
+ if_(condition, ifTrue) {
252
+ return this.step(`if ${Macro.makeBALLSPredicate(condition)}`)
253
+ .step(ifTrue)
254
+ .step("endif");
250
255
  }
251
256
  /**
252
257
  * Create a new macro with an "if" statement.
@@ -257,6 +262,26 @@ export class Macro {
257
262
  static if_(condition, ifTrue) {
258
263
  return new this().if_(condition, ifTrue);
259
264
  }
265
+ /**
266
+ * Add an "if" statement to this macro, inverting the condition.
267
+ * @param condition The BALLS condition for the if statement.
268
+ * @param ifTrue Continuation if the condition is true.
269
+ * @returns {Macro} This object itself.
270
+ */
271
+ ifNot(condition, ifTrue) {
272
+ return this.step(`if !(${Macro.makeBALLSPredicate(condition)})`)
273
+ .step(ifTrue)
274
+ .step("endif");
275
+ }
276
+ /**
277
+ * Create a new macro with an "if" statement, inverting the condition.
278
+ * @param condition The BALLS condition for the if statement.
279
+ * @param ifTrue Continuation if the condition is true.
280
+ * @returns {Macro} This object itself.
281
+ */
282
+ static ifNot(condition, ifTrue) {
283
+ return new this().ifNot(condition, ifTrue);
284
+ }
260
285
  /**
261
286
  * Add a "while" statement to this macro.
262
287
  * @param condition The BALLS condition for the if statement.
@@ -56,9 +56,9 @@ function inventoryItems() {
56
56
  [100, autosellPrice(item)].includes(price(item, PriceAge.RECENT)));
57
57
  }
58
58
  // Efficiency in meat per fuel.
59
- function calculateFuelUnitCost(it, targetUnits, priceAge = PriceAge.RECENT) {
59
+ function calculateFuelUnitCost(it, priceAge = PriceAge.RECENT) {
60
60
  const units = getAverageAdventures(it);
61
- return price(it, priceAge) / Math.min(targetUnits, units);
61
+ return price(it, priceAge) / units;
62
62
  }
63
63
  function isFuelItem(it) {
64
64
  return (!isNpcItem(it) &&
@@ -68,7 +68,7 @@ function isFuelItem(it) {
68
68
  it.discardable &&
69
69
  !fuelSkiplist.includes(it));
70
70
  }
71
- function getBestFuels(targetUnits) {
71
+ function getBestFuels() {
72
72
  // Three stages.
73
73
  // 1. Filter to reasonable items using historical cost (within 5x of historical best).
74
74
  const allFuel = Item.all().filter(isFuelItem);
@@ -76,7 +76,7 @@ function getBestFuels(targetUnits) {
76
76
  mallPrices("food");
77
77
  mallPrices("booze");
78
78
  }
79
- const keyHistorical = (item) => calculateFuelUnitCost(item, targetUnits, PriceAge.HISTORICAL);
79
+ const keyHistorical = (item) => calculateFuelUnitCost(item, PriceAge.HISTORICAL);
80
80
  allFuel.sort((x, y) => keyHistorical(x) - keyHistorical(y));
81
81
  const bestUnitCost = keyHistorical(allFuel[0]);
82
82
  const firstBadIndex = allFuel.findIndex((item) => keyHistorical(item) > 5 * bestUnitCost);
@@ -87,14 +87,14 @@ function getBestFuels(targetUnits) {
87
87
  mallPrices("booze");
88
88
  }
89
89
  const key1 = (item) => -getAverageAdventures(item);
90
- const key2 = (item) => calculateFuelUnitCost(item, targetUnits, PriceAge.RECENT);
90
+ const key2 = (item) => calculateFuelUnitCost(item, PriceAge.RECENT);
91
91
  potentialFuel.sort((x, y) => key1(x) - key1(y));
92
92
  potentialFuel.sort((x, y) => key2(x) - key2(y));
93
93
  // 3. Find result using precise price for those top candidates.
94
94
  const candidates = potentialFuel.slice(0, 10);
95
- const key3 = (item) => calculateFuelUnitCost(item, targetUnits, PriceAge.TODAY);
95
+ const key3 = (item) => calculateFuelUnitCost(item, PriceAge.TODAY);
96
96
  candidates.sort((x, y) => key3(x) - key3(y));
97
- if (calculateFuelUnitCost(candidates[0], targetUnits, PriceAge.TODAY) > 100) {
97
+ if (calculateFuelUnitCost(candidates[0], PriceAge.TODAY) > 100) {
98
98
  throw new Error("Could not identify any fuel with efficiency better than 100 meat per fuel. " +
99
99
  "This means something went wrong.");
100
100
  }
@@ -119,10 +119,9 @@ export function fillTo(targetUnits) {
119
119
  if (!installed())
120
120
  return false;
121
121
  while (getFuel() < targetUnits) {
122
- const remaining = targetUnits - getFuel();
123
122
  // if in Hardcore/ronin, skip the price calculation and just use soda bread
124
123
  const [bestFuel, secondBest] = canInteract()
125
- ? getBestFuels(remaining)
124
+ ? getBestFuels()
126
125
  : [$item `loaf of soda bread`, undefined];
127
126
  const count = Math.ceil(targetUnits / getAverageAdventures(bestFuel));
128
127
  let ceiling = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libram",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "JavaScript helper library for KoLmafia",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",