mall_prices

From Kolmafia
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 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 are:

  • 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 "crappydecentgood" will search for crappy/decent/good consumables. However, we recommend using proper separators, as it will make your life easier.

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 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
 1 int food_count = mall_prices( "food" );
 2 print( `{food_count} food prices retrieved.` );
 3 
 4 item [int] food_list;
 5 foreach it in $items[]
 6 {
 7    // Items that are untradable or not available in the mall have a price of 0.
 8    // We will ignore such items.
 9    if ( item_type( it ) == "food" && mall_price( it ) > 0 )
10    {
11       // Add item to list
12       food_list[ count(food_list) ] = it;
13    }
14 }
15 
16 // Sort the list by mall price, from highest to lowest
17 sort food_list by -mall_price( value );
18 // Print the name and price of first 5 items
19 for i from 0 to 5
20 {
21    print( `{food_list[i].name}: {mall_price( food_list[i] )}` );
22 }
 1 const { mallPrice, mallPrices, print, itemType } = require("kolmafia");
 2 
 3 const foodCount = mallPrices("food");
 4 print(foodCount + " food prices retrieved.");
 5 
 6 // Items that are untradable or not available in the mall have a price of 0.
 7 // We will ignore such items.
 8 const foodList = Item.all()
 9   .filter((it) => itemType(it) === "food" && mallPrice(it) > 0)
10   .sort((a, b) => mallPrice(b) - mallPrice(a))  // Sort from highest to lowest
11   .slice(0, 5);
12 
13 for (let food of foodList) {
14   print(food.name + ": " + mallPrice(food));
15 }

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
 1 boolean [ item ] wads = $items[
 2   cold wad,
 3   hot wad,
 4   sleaze wad,
 5   spooky wad,
 6   stench wad,
 7 ];
 8 
 9 mall_prices( wads );
10 
11 foreach wad in wads
12 {
13    print( `{wad.name}: {mall_price( wad )}` );
14 }
 1 const { mallPrice, mallPrices, print } = require("kolmafia");
 2 
 3 const wads = Item.get([
 4   "cold wad",
 5   "hot wad",
 6   "sleaze wad",
 7   "spooky wad",
 8   "stench wad",
 9 ]);
10 
11 // For JavaScript, we must manually build an object whose keys are item names.
12 const wadsObj = {};
13 for (let wad of wads) {
14   wadsObj[wad.name] = true;
15 }
16 mallPrices(wadsObj);
17 
18 for (let wad of wads) {
19   print(wad.name + ": " + mallPrice(wad));
20 }

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
 1 boolean [ item ] pieces;
 2 // Add items to the map
 3 foreach key, piece in outfit_pieces( "Star Garb" )
 4 {
 5    pieces[ piece ] = true;
 6 }
 7 
 8 // Perform a search at once
 9 mall_prices( pieces );
10 
11 foreach piece in pieces
12 {
13    print( `{piece.name}: {mall_price(piece)}` );
14 }
 1 const { mallPrice, mallPrices, outfitPieces, print } = require("kolmafia");
 2 
 3 const pieces = outfitPieces("Star Garb");
 4 const piecesObj = {};
 5 // Add items to the object
 6 for (let piece of pieces) {
 7   piecesObj[piece.name] = true;
 8 }
 9 
10 // Perform a search at once
11 mallPrices(piecesObj);
12 
13 for (let piece of pieces) {
14   print(piece.name + ": " + mallPrice(piece));
15 }

See Also

historical_age() | historical_price() | mall_price() | mall_prices()