Mall prices: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
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..."
 
Add SeeAlso template, several corrections
 
Line 17: Line 17:
|function2.param1.description=Items to search for. This can be constructed using the <code>$items[]</code> plural-typed constant.
|function2.param1.description=Items to search for. This can be constructed using the <code>$items[]</code> plural-typed constant.
|description=
|description=
The set-based version can be used to search for multiple items at once, so that calling {{f|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.
<p>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.</p>


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.
<p>The category search uses KoL's mall item categories. Valid category values are:</p>
 
The category search uses KoL's mall item categories. Valid category values include:


* <code>allitems</code>: All items ('''WARNING: This will take very long''')
* <code>allitems</code>: All items ('''WARNING: This will take very long''')
Line 43: Line 41:
* <code>new</code> (New Stuff)
* <code>new</code> (New Stuff)


{{pspan|tiers}} can be any string that contains a consumable tier name. Valid tier names are: <code>crappy</code>, <code>decent</code>, <code>good</code>, <code>awesome</code>, <code>EPIC</code>. Tier names are are case-sensitive.
<p>{{pspan|tiers}} can be any string that contains a consumable tier name. Valid tier names are: <code>crappy</code>, <code>decent</code>, <code>good</code>, <code>awesome</code>, <code>EPIC</code>. Tier names are are case-sensitive.</p>
 
<p>KoLmafia does not care what separator you use, or if you use a separator at all. For example, both <code>"crappy, decent, good"</code> and <code>"crappydecentgood"</code> will search for crappy/decent/good consumables. However, we recommend using proper separators, as it will make your life easier.</p>


KoLmafia does not care what separator you use, or if you use a separator at all. For example, both <code>"crappy, decent, good"</code> and <code>"crappydecentbooze"</code> will search for crappy/decent/good consumables. However, we recommend using proper separators, as it will make your life easier.
<p>The set-based version can be used to search for multiple items at once, so that calling {{f|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.</p>


The category-based search was added in [https://kolmafia.us/threads/18892-add-mall_prices-category-to-bulk-calculate-mall-prices-for-entire-categoriesu.23173/ r18892], and the optional {{pspan|tiers}} parameter was added in [https://kolmafia.us/threads/18893-add-two-argument-form-of-mall_prices-int-mall_prices-string-category-strin.23175/ r18893]. The item set search variant was added in [https://kolmafia.us/threads/18937-new-ash-function-int-mall_prices-boolean-item-to-look-up-the-curren.23234/ r18937].
<p>The category-based search was added in [https://kolmafia.us/threads/18892-add-mall_prices-category-to-bulk-calculate-mall-prices-for-entire-categoriesu.23173/ r18892], and the optional {{pspan|tiers}} parameter was added in [https://kolmafia.us/threads/18893-add-two-argument-form-of-mall_prices-int-mall_prices-string-category-strin.23175/ r18893]. The item set search variant was added in [https://kolmafia.us/threads/18937-new-ash-function-int-mall_prices-boolean-item-to-look-up-the-curren.23234/ r18937].</p>
|code1={{CodeSample
|code1={{CodeSample
   |title=Code Samples
   |title=Code Samples
Line 197: Line 197:
   |moreinfo=
   |moreinfo=
}}
}}
|see_also={{SeeAlso|}}
|see_also={{SeeAlso/Mall Prices}}
|cli_equiv=
|cli_equiv=
|more_info=
|more_info=

Latest revision as of 13:55, 31 December 2020

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
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

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