libram 0.9.32 → 0.9.34

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.
@@ -1,7 +1,8 @@
1
- import { retrievePrice, useFamiliar } from "kolmafia";
1
+ import { useFamiliar } from "kolmafia";
2
2
  import { Macro } from "../combat.js";
3
3
  import { Requirement } from "../maximize.js";
4
4
  import { sum } from "../utils.js";
5
+ import { getAcquirePrice } from "../lib.js";
5
6
  /**
6
7
  * Merge a set of constraints into one
7
8
  *
@@ -37,7 +38,7 @@ function mergeConstraints(...allConstraints) {
37
38
  * A combat-based action resource in the game (e.g. a free run or free kill).
38
39
  */
39
40
  export class ActionSource {
40
- static defaultPriceFunction = (item) => retrievePrice(item) > 0 ? retrievePrice(item) : Infinity;
41
+ static defaultPriceFunction = (item) => getAcquirePrice(item) > 0 ? getAcquirePrice(item) : Infinity;
41
42
  source;
42
43
  potential; // Infinity: unlimited
43
44
  macro;
package/dist/lib.d.ts CHANGED
@@ -580,4 +580,12 @@ export type FamiliarTag = (typeof familiarTags)[number];
580
580
  * @returns An array of the familiar's tags
581
581
  */
582
582
  export declare function getFamiliarTags(familiar: Familiar): FamiliarTag[];
583
+ /**
584
+ * Determines the cost of acquiring an item taking into account your valueOfInventory preference
585
+ *
586
+ * @param item The item to check the price of
587
+ * @param quantity the number of items to acquire
588
+ * @returns The total value of the items
589
+ */
590
+ export declare function getAcquirePrice(item: Item, quantity?: number): number;
583
591
  export {};
package/dist/lib.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** @module GeneralLibrary */
2
- import { appearanceRates, autosellPrice, availableAmount, booleanModifier, choiceFollowsFight, cliExecute, currentRound, Effect, elementalResistance, equip, equippedItem, extractItems as kolmafiaExtractItems, Familiar, fullnessLimit, getCampground, getCounters, getPlayerId, getPlayerName, getRelated, handlingChoice, haveEffect, haveFamiliar, haveServant, haveSkill, holiday, inebrietyLimit, inMultiFight, Item, Location, mallPrice, myClass, myEffects, myFamiliar, myFullness, myInebriety, myPath, myPrimestat, mySpleenUse, myThrall, myTurncount, numericModifier, Path, Servant, Skill, Slot, spleenLimit, Thrall, todayToString, toItem, toSkill, totalTurnsPlayed, visitUrl, xpath, monsterEval, batchOpen, batchClose, autosell, putCloset, putDisplay, putShop, putStash, sell, takeCloset, takeDisplay, takeShop, takeStash, takeStorage, repriceShop, familiarWeight, weightAdjustment, MafiaClasses, toMonster, } from "kolmafia";
2
+ import { appearanceRates, autosellPrice, availableAmount, booleanModifier, choiceFollowsFight, cliExecute, currentRound, Effect, elementalResistance, equip, equippedItem, extractItems as kolmafiaExtractItems, Familiar, fullnessLimit, getCampground, getCounters, getPlayerId, getPlayerName, getRelated, handlingChoice, haveEffect, haveFamiliar, haveServant, haveSkill, holiday, inebrietyLimit, inMultiFight, Item, Location, mallPrice, myClass, myEffects, myFamiliar, myFullness, myInebriety, myPath, myPrimestat, mySpleenUse, myThrall, myTurncount, numericModifier, Path, Servant, Skill, Slot, spleenLimit, Thrall, todayToString, toItem, toSkill, totalTurnsPlayed, visitUrl, xpath, monsterEval, batchOpen, batchClose, autosell, putCloset, putDisplay, putShop, putStash, sell, takeCloset, takeDisplay, takeShop, takeStash, takeStorage, repriceShop, familiarWeight, weightAdjustment, MafiaClasses, toMonster, retrievePrice, craftType, isNpcItem, npcPrice, } from "kolmafia";
3
3
  import logger from "./logger.js";
4
4
  import { get } from "./property.js";
5
5
  import { $class, $effect, $element, $familiar, $item, $items, $monsters, $skill, $stat, } from "./template-string.js";
@@ -820,7 +820,7 @@ export function unequip(thing) {
820
820
  if (equippedItem(s) !== thing)
821
821
  return false;
822
822
  // Filter the slot out if we succeed at unequipping it
823
- return !unequip(thing);
823
+ return !unequip(s);
824
824
  // This leaves only slots that do contain the item but that we failed to unequip
825
825
  });
826
826
  if (failedSlots.length)
@@ -1179,3 +1179,39 @@ export const familiarTags = Object.freeze([
1179
1179
  export function getFamiliarTags(familiar) {
1180
1180
  return familiar.attributes.split("; ").filter(Boolean);
1181
1181
  }
1182
+ /**
1183
+ * Determines the cost of acquiring an item taking into account your valueOfInventory preference
1184
+ *
1185
+ * @param item The item to check the price of
1186
+ * @param quantity the number of items to acquire
1187
+ * @returns The total value of the items
1188
+ */
1189
+ export function getAcquirePrice(item, quantity = 1) {
1190
+ if (quantity <= 0)
1191
+ return 0;
1192
+ const currentAmount = availableAmount(item);
1193
+ const amountNeeded = Math.max(0, quantity - currentAmount);
1194
+ const retrieveCost = retrievePrice(item, currentAmount + quantity) -
1195
+ retrievePrice(item, currentAmount);
1196
+ const mallMinPrice = Math.max(100, 2 * autosellPrice(item));
1197
+ if (craftType(item) === "Meatpasting" && retrieveCost > 0) {
1198
+ return retrieveCost;
1199
+ }
1200
+ if (isNpcItem(item) &&
1201
+ npcPrice(item) > 0 &&
1202
+ npcPrice(item) < mallPrice(item)) {
1203
+ return quantity * npcPrice(item);
1204
+ }
1205
+ if (item.tradeable && mallPrice(item) === mallMinPrice) {
1206
+ return currentAmount * autosellPrice(item) + amountNeeded * mallPrice(item);
1207
+ }
1208
+ if (item.tradeable && mallPrice(item) > mallMinPrice) {
1209
+ return quantity * mallPrice(item);
1210
+ }
1211
+ if (item.tradeable)
1212
+ return quantity * autosellPrice(item);
1213
+ if (item.discardable) {
1214
+ return have(item, quantity) ? quantity * autosellPrice(item) : Infinity;
1215
+ }
1216
+ return 0;
1217
+ }
@@ -1,5 +1,5 @@
1
1
  import { Bounty, Class, Coinmaster, Effect, Element, Familiar, Item, Location, Monster, Phylum, Servant, Skill, Slot, Stat, Thrall } from "kolmafia";
2
- import { BooleanProperty, FamiliarProperty, LocationProperty, MonsterProperty, NumericOrStringProperty, NumericProperty, PhylumProperty, StatProperty, StringProperty } from "./propertyTypes.js";
2
+ import { BooleanProperty, FamiliarProperty, ItemProperty, LocationProperty, MonsterProperty, NumericOrStringProperty, NumericProperty, PhylumProperty, StatProperty, StringProperty } from "./propertyTypes.js";
3
3
  import { KnownProperty } from "./propertyTyping.js";
4
4
  export declare const getString: (property: string, default_?: string | undefined) => string;
5
5
  export declare const getCommaSeparated: (property: string, default_?: string[] | undefined) => string[];
@@ -38,9 +38,13 @@ export declare function get(property: StatProperty): Stat | null;
38
38
  export declare function get(property: StatProperty, _default: Stat): Stat;
39
39
  export declare function get(property: PhylumProperty): Phylum | null;
40
40
  export declare function get(property: PhylumProperty, _default: Phylum): Phylum;
41
- export declare function get(property: string, _default: Location): Location | null;
42
- export declare function get(property: string, _default: Monster): Monster | null;
43
- export declare function get(property: string, _default: Familiar): Familiar | null;
41
+ export declare function get(property: ItemProperty): Item | null;
42
+ export declare function get(property: ItemProperty, _default: Item): Item;
43
+ export declare function get(property: string, _default: Location): Location;
44
+ export declare function get(property: string, _default: Monster): Monster;
45
+ export declare function get(property: string, _default: Familiar): Familiar;
46
+ export declare function get(property: string, _default: Phylum): Phylum;
47
+ export declare function get(property: string, _default: Item): Item;
44
48
  export declare function get(property: string, _default: boolean): boolean;
45
49
  export declare function get(property: string, _default: number): number;
46
50
  export declare function get(property: string, _default?: string): string;
package/dist/property.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Bounty, Class, Coinmaster, Effect, Element, Familiar, getProperty, Item, Location, Monster, Phylum, propertyExists, removeProperty, Servant, setProperty, Skill, Slot, Stat, Thrall, toBounty, toClass, toCoinmaster, toEffect, toElement, toFamiliar, toItem, toLocation, toMonster, toPhylum, toServant, toSkill, toSlot, toStat, toThrall, } from "kolmafia";
2
- import { isBooleanProperty, isFamiliarProperty, isLocationProperty, isMonsterProperty, isNumericOrStringProperty, isNumericProperty, isPhylumProperty, isStatProperty, isStringProperty, } from "./propertyTyping.js";
2
+ import { isBooleanProperty, isFamiliarProperty, isItemProperty, isLocationProperty, isMonsterProperty, isNumericOrStringProperty, isNumericProperty, isPhylumProperty, isStatProperty, isStringProperty, } from "./propertyTyping.js";
3
3
  const createPropertyGetter = (transform) => (property, default_) => {
4
4
  const value = getProperty(property);
5
5
  if (default_ !== undefined && value === "") {
@@ -66,6 +66,9 @@ export function get(property, _default) {
66
66
  else if (isPhylumProperty(property)) {
67
67
  return getPhylum(property, _default);
68
68
  }
69
+ else if (isItemProperty(property)) {
70
+ return getItem(property, _default);
71
+ }
69
72
  else if (isStringProperty(property)) {
70
73
  return value === "" && _default !== undefined ? _default : value;
71
74
  }
@@ -85,6 +88,9 @@ export function get(property, _default) {
85
88
  else if (_default instanceof Phylum) {
86
89
  return getPhylum(property, _default);
87
90
  }
91
+ else if (_default instanceof Item) {
92
+ return getItem(property, _default);
93
+ }
88
94
  else if (typeof _default === "boolean") {
89
95
  return value === "true" ? true : value === "false" ? false : _default;
90
96
  }