mall_prices

From Kolmafia
Revision as of 13:44, 31 December 2020 by Philmasterplus (talk | contribs) (Created page with "<onlyinclude>{{{{{format|Function2}}} |name=mall_prices |function1.return_type=int |function1.description=Updates the mall price for a category of items, and returns the numbe...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Function Syntax

int mall_pricesstring category, string? tiers = "" )

Updates the mall price for a category of items, and returns the number of items searched.
  • category: Item category (must be exact match)
  • tiers: String containing item quality tiers. Only relevent if category is a consumable category (food, booze, or othercon)

int mall_pricesboolean [itemitems )

Updates the mall price for a set of items, and returns the number of items searched.
  • items: Items to search for. This can be constructed using the $items[] plural-typed constant.

The set-based version can be used to search for multiple items at once, so that calling mall_price() later on individual items won't trigger server requests. This can be useful when your script needs to retrieve the price of multiple items, but do not want the search results to be interleaved with the script's output. The category-based version can be used to update the price of a whole category of items while making a minimal number of server requests. Depending on the number of items in the category, this will make anywhere between 20 and 80 requests. The category search uses KoL's mall item categories. Valid category values include:

  • allitems: All items (WARNING: This will take very long)
  • food: Food and Beverages
  • booze
  • othercon (Other consumables)
  • weapons
  • hats
  • shirts
  • container (Back items)
  • pants
  • acc (Accessories)
  • offhand
  • combat (Combat items)
  • potions
  • hprestore (HP Restorers)
  • mprestore (MP Restorers)
  • familiars (Familiar hatchlings)
  • mrstore (Mr. Store Items)
  • unlockers (Content Unlockers)
  • new (New Stuff)

tiers can be any string that contains a consumable tier name. Valid tier names are: crappy, decent, good, awesome, EPIC. Tier names are are case-sensitive. KoLmafia does not care what separator you use, or if you use a separator at all. For example, both "crappy, decent, good" and "crappydecentbooze" will search for crappy/decent/good consumables. However, we recommend using proper separators, as it will make your life easier. The category-based search was added in r18892, and the optional tiers parameter was added in r18893. The item set search variant was added in r18937.

Code Samples

Find the 5 most expensive foods in the mall.

ASH JavaScript
int food_count = mall_prices( "food" );
print( `{food_count} food prices retrieved.` );

item [int] food_list;
foreach it in $items[]
{
   // Items that are untradable or not available in the mall have a price of 0.
   // We will ignore such items.
   if ( item_type( it ) == "food" && mall_price( it ) > 0 )
   {
      // Add item to list
      food_list[ count(food_list) ] = it;
   }
}

// Sort the list by mall price, from highest to lowest
sort food_list by -mall_price( value );
// Print the name and price of first 5 items
for i from 0 to 5
{
   print( `{food_list[i].name}: {mall_price( food_list[i] )}` );
}
const { mallPrice, mallPrices, print, itemType } = require("kolmafia");

const foodCount = mallPrices("food");
print(foodCount + " food prices retrieved.");

// Items that are untradable or not available in the mall have a price of 0.
// We will ignore such items.
const foodList = Item.all()
  .filter((it) => itemType(it) === "food" && mallPrice(it) > 0)
  .sort((a, b) => mallPrice(b) - mallPrice(a))  // Sort from highest to lowest
  .slice(0, 5);

for (let food of foodList) {
  print(food.name + ": " + mallPrice(food));
}

Find the price of all elemental wads. Using mall_prices() allows us to print the price of all pieces at once, without having KoLmafia print "Searching for <item name>..." between them.

ASH JavaScript
boolean [ item ] wads = $items[
  cold wad,
  hot wad,
  sleaze wad,
  spooky wad,
  stench wad,
];

mall_prices( wads );

foreach wad in wads
{
   print( `{wad.name}: {mall_price( wad )}` );
}
const { mallPrice, mallPrices, print } = require("kolmafia");

const wads = Item.get([
  "cold wad",
  "hot wad",
  "sleaze wad",
  "spooky wad",
  "stench wad",
]);

// For JavaScript, we must manually build an object whose keys are item names.
const wadsObj = {};
for (let wad of wads) {
  wadsObj[wad.name] = true;
}
mallPrices(wadsObj);

for (let wad of wads) {
  print(wad.name + ": " + mallPrice(wad));
}

Find the price of all pieces of the Star Garb outfit. Since the return type of outfit_pieces() and the parameter type of mall_prices() is different, we must manually build a map of pieces.

ASH JavaScript
boolean [ item ] pieces;
// Add items to the map
foreach key, piece in outfit_pieces( "Star Garb" )
{
   pieces[ piece ] = true;
}

// Perform a search at once
mall_prices( pieces );

foreach piece in pieces
{
   print( `{piece.name}: {mall_price(piece)}` );
}
const { mallPrice, mallPrices, outfitPieces, print } = require("kolmafia");

const pieces = outfitPieces("Star Garb");
const piecesObj = {};
// Add items to the object
for (let piece of pieces) {
  piecesObj[piece.name] = true;
}

// Perform a search at once
mallPrices(piecesObj);

for (let piece of pieces) {
  print(piece.name + ": " + mallPrice(piece));
}

See Also