Feature - Rejected Get Equipment

Baden

Member
Would it be worth adding a function that returns a map of the currently equipped items to the amount equipped (similar to get)closet, get_inventory, etc)? This is currently possible using equipped_item and equipped_amount but a single function to achieve this would allow a player to get the entirety of all items in their posession using the various get_<SOURCE> functions.
 

fronobulax

Developer
Staff member
What's your expected use/benefit? You clearly know how to write a script that does the same thing so why should this be a function included in, and supported by KoLmafia, as opposed to something a scripter has included in a library that is maintained by the scripter?
 

Baden

Member
My particular use case is cataloging every item a player has in their possession for tracking items earned over a period of time. I think it should be included because there are functions to get a player's items from every other source (display case, shop, inventory, storage, campground, closet). Yes it can be achieved with other functionality, but so can the other "get_" functions, e.g. get_display could be replicated with visit_url and some parsing.
 

Ryo_Sangnoir

Developer
Staff member
I don't think this is a good idea as written. My naive expectation of a "get_equipment" function would be a map of slot to equipment -- equipment to count seems too heavily focused to be generally useful.

There are a variety of edge cases a Mafia implementation would need to consider:
* which slots count?
* if the user has a folder holder, do you count all their folders as well? only if the holder is equipped?
* what about stickers?
* do you count all the fake hands?

I think you should use equipped_item for the slots you're interested in.
 

Baden

Member
All good points, thanks for considering! For those who do want this functionality, this is what I came up with in TS:

JavaScript:
function getEquipment(): { [item: string]: number } {
  const items = [...new Set(Slot.all().map((slot) => equippedItem(slot)))];
  return items.reduce((obj, item) => {
    if (equippedAmount(item) > 0) obj[item.name] = equippedAmount(item);
    return obj;
  }, {} as { [item: string]: number });
}
 
Last edited:
Top