Feature - Implemented More robust item detection for moves from closet

Veracity

Developer
Staff member
A recent bug report pointed out that taking multiple things out of the closet is in the form of "You acquire <b><x> <plural name></b>" and if we don't recognize the name, we can get confused. As it turns out, the full page is more informative:

Code:
<script type="text/javascript">if (window.updateInv) updateInv({"3440":3})</script><center><table  width=95%  cellspacing=0 cellpadding=0><tr><td style="color: white;" align=center bgcolor=blue><b>Results:</b></td></tr><tr><td style="padding: 5px; border: 1px solid blue;"><center><table><tr><td>You take some things out of your closet.<center><table class="item" style="float: none" rel="id=3440&s=90&q=0&d=1&g=0&t=1&n=3&m=1&p=0&u=u"><tr><td><img src="http://images.kingdomofloathing.com/itemimages/prismwad.gif" alt="prismatic wad" title="prismatic wad" class=hand onClick='descitem(267408834)'></td><td valign=center class=effect>You acquire <b>3 prismatic wads</b></td></tr></table></center></td></tr></table></center></td></tr><tr><td height=4></td></tr></table></center>
The item is in an HTML table of class "item" with a "rel" string. There is a clickable image with a DESCID. And then there is the message, with the number of items removed and the name of the item - or the plural, if there are more than one.

Note that the "rel" string has the itemId ("id") and the number moved ("n"), as well as all sorts of other attributes about the item - including multi-usability.

We already have code to look up an item given a "rel" string - ItemDatabase.itemFromRelString(). And when we read your closet at login, we register unknown items that we find there (since you can use api.php?what=item to get info about items that are in "accessible" places - including your closet).

Seems to me that for transfers from the closet - or anywhere that includes a "rel" string - we should use the "id" and "n" fields to unambiguously identify it - and we could use the "m" field to check our understanding of multi-usability and the plural. In the ideal world, those things would be in api.php?what=item.

In any case, there is no reason to be confused by plurals and closet transfers.
 

Veracity

Developer
Staff member
Revision 13342 soups up processing "rel" strings, wherever they appear: we will check for unrecognized plurals (and log them), check if the multi-usable flag differs from what we expect for the item (and log such a difference), and will actually move the item to inventory as specified by rel string, not by parsing the "You acquire" message.

I should consider doing this for the mall, too, since we have special code there to not be fooled by unexpected acquisitions that is probably obviated by this new technique.
 

Darzil

Developer
Great stuff, especially if and when it hits the mall, which I use a lot more than the closet, and it's where I encounter plural issues most.
 

Veracity

Developer
Staff member
Thanks.

KoL's purpose of the "class=item" table with the "rel" string is to tell the right-click menu what you can do with an item. That is why they changed former messages of the form "You move x from closet to inventory" to standard "You acquire" messages wrapped in the table. That means that this technique should be usable for ANY thing that results in an item arriving in inventory. That includes fights, closet, stash, display, storage, NPC purchases, taking from your store, and buying from the mall.

Now, moving things in the other direction retains the old messages: "Item x moved from inventory to closet", say.

The key for KoLmafia is to make sure that we use ResultProcessor.processResults to parse what happens for all moves that result in items in inventory. We definitely do that in fights, for the purpose of registering new items, although we actually do the item acquisition in sequence with other combat actions, so we can get the session log right.

I think everything else flows through ResultProcessor.processResults, although mall purchases are trickier, since we send the results to a list and look at it from there, since sometimes the items end up in storage and sometimes you end up with fewer than you expected and we want to move on to the next store in that case.

I'll look at all of the other cases, but I suspect the only change that will be necessary is to remove the special code in the mall purchase case to log unknown plurals, because that should have already have been done, what with the code I submitted for this.
 

Veracity

Developer
Staff member
Revision 13362 now sends mall purchases (and removing items from your store) through the "rel" string item acquisition method. Turns out, even if the items end up in storage, KoL gives you a "rel" string. Perhaps the right-click menu has a "pull" option on it.

I have tested the following and they all have "rel" strings and go through that kind of result processing now:

closet to inventory
stash to inventory
store to inventory
mall to inventory
NPC store (General Market) to inventory
Coinmaster (Hermit) to inventory

I have not yet tested:

storage to inventory

The following does NOT have a "rel" string:

display case to inventory. It says, for example, <b>cyborg stompin' boot (2)</b> moved from case to inventory.

This is probably as done as it going to be, modulo KoL changing display case transfers.
 
Top