Feature "Use another dance card" link uses a dance card even with a dance card counter active

lostcalpolydude

Developer
Staff member
"Use another dance card" link uses a dance card even with a dance card counter active

In Rotting Matilda, there's a link to use another dance card. When that link is clicked, there is no CLI output about the item being used. If the link is clicked more than once, multiple dance cards are used (inventory was refreshed to check that they were actually used), despite code that is supposed to prevent them being used when there is already a dance card counter.
 

Veracity

Developer
Staff member
The code that prevents that is in UseItemRequest.maximumUses. That is called whenever KoLmafia itself wants to use a dance card - via the GUI, the CLI, or an ASH script. The use link inserted into the Rotting Matilda page is a call to a Javascript function - singleUse - which directly submits inv_use.php?which=3&whichitem=1963&pwd=XXX&ajax=1 to KoL. If you click the link twice, it submits it twice. The reason nothing is logged in the CLI is that we do not log using items in the Relay Browser there, although we do log the usage in the session log.

I suppose we could make the link submit a command to KoLmafia itself, via "/KoLmafia/submitCommand?cmd=use+1+dance+card&pwd=XXX" or something. The trick would be to have the result show up in the Relay Browser. "specialCommand" exists for that, where the submitted command leaves the responseText in RelayRequest.specialCommandResponse.
 

Bale

Minion
I'm pretty sure that KoLmafia used to prevent that link from using a dance card if there was already a dance card counter active. It saved me from error a few times. If it has stopped working that would be distressing. I'll have to be careful.
 

Veracity

Developer
Staff member
Let me try again to explain what I understand about this.

lost says that in Rotting Matilda, "there's a link to use another dance card". He's clearly talking about seeing that page in the Relay Browser and the link that we add to the page. In particular, the link that RequestEditorKit.fixRottingMatilda adds to the page. I think of that as being a "use link" because, although it is not created by UseLinkDecorator.getItemHTML, the link is identical to an "in line" use link that is generated by that package: it uses the same Javascript method from KoLmafia's basics.js - javascript:singleUse - to "use" the item via ajax. Which is to say, to call inv_use.php with the appropriate parameters to use the item and return just the results of using that item - not including the whole inventory page where the item is found - which will be displayed in a little section at the top of the main frame. That method was originally developed by KoL itself for use by chat commands.

Since this is requesting that an item be used in the Relay Browser - not the KoLmafia GUI - let's consider the options KoL provides for that.

----------

- When you look at your inventory, KoL provides [use] links after usable items and [use multiple] links after items that are multiusable. Since a dance card is not multiusable, ignore the latter. What [use] link does KoL provide? Simply this:

http://127.0.0.1:60080/inv_use.php?pwd=XXXX&which=3&whichitem=1963

Notice that KoLmafia changed the host such that it will go through the Relay Browser, so it can watch what happens if you click it. If you click on that link, the browser submits the following:

GET /inv_use.php?pwd=XXXX&which=3&whichitem=1963&ajax=1&_=1406299898949 HTTP/1.1

I don't understand how, exactly, it decides to add on the ajax variable. In any case, KoLmafia submits the following:

http://www.kingdomofloathing.com/inv_use.php?pwd=XXXX&which=3&whichitem=1963&ajax=1&_=1406299898949

KoL responds with a small responseText containing just the Results: section that says "You pencil your name in on the last line of the dance card, and it evaporates in a puff of ectoplasm.". KoLmafia passes that down to the browser, which inserts it at the top of the inventory page and decrements the count of dance cards.

If you scroll down and look at the dance card again, it has a [use] link. If you click it again, KoL will use another dance card with the same result.

DON'T DO THAT; it wastes the second dance card.

- What happens when you say "/use 1 dance card" in chat? The browser submits the following request:

GET /inv_use.php?whichitem=1963&ajax=1&pwd=XXXX&_=1406299661121 HTTP/1.1

KoLmafia dutifully submits:

http://www.kingdomofloathing.com/inv_use.php?whichitem=1963&ajax=1&pwd=XXXX&_=1406299661121

KoL responds with a small responseText containing just the Results: section that says "You pencil your name in on the last line of the dance card, and it evaporates in a puff of ectoplasm.". KoLmafia passes that down to the browser and it inserts it at the top of the main frame.

If type "/use 1 dance card" again in chat, KoL will use another dance card with the same result.

DON'T DO THAT; it wastes the second dance card.

- What happens if you get Rotting Matilda?

KoLmafia inserts a "Use another dance card" link:

javascript:singleUse('inv_use.php','which=3&whichitem=1963&pwd=XXXX&ajax=1');void(0);

If you click it, the browser submits the following request:

GET /inv_use.php?which=3&whichitem=1963&pwd=XXXX&ajax=1 HTTP/1.1

KoLmafia dutifully submits:

http://www.kingdomofloathing.com/inv_use.php?which=3&whichitem=1963&pwd=XXXX&ajax=1

KoL responds with a small responseText containing just the Results: section that says "You pencil your name in on the last line of the dance card, and it evaporates in a puff of ectoplasm.". KoLmafia passes that down to the browser and it inserts it at the top of the Adventure Results page.

If you look at the Adventure Results section of the frame, the "Use Another Dance Card" link is still there. If you click it again, KoL will use another dance card with the same result.

DON'T DO THAT; it wastes the second dance card.

- What happens if you find a dance card in combat?

KoLmafia inserts a "[use]" link:

javascript:singleUse('inv_use.php','which=3&whichitem=1963&pwd=XXXX&ajax=1');void(0);

If you click it, the browser submits the following request:

GET /inv_use.php?which=3&whichitem=1963&pwd=XXXX&ajax=1 HTTP/1.1

KoLmafia dutifully submits:

http://www.kingdomofloathing.com/inv_use.php?which=3&whichitem=1963&pwd=XXXX&ajax=1

KoL responds with a small responseText containing just the Results: section that says "You pencil your name in on the last line of the dance card, and it evaporates in a puff of ectoplasm.". KoLmafia passes that down to the browser and it inserts it at the top of the Combat page.

If you look at the Combat section of the frame, the "[use]" link is still there. If you click it again, KoL will use another dance card with the same result.

DON'T DO THAT; it wastes the second dance card.

----------

In every one of the above situations (except for the chat command), there is a link in the main frame of the page.
If you click it (or issue the chat command), the browser submits a GET request to inv_use.php.
KoLmafia passes the request to KoL.
KoL sends a small responseText back with the Results section
The browser inserts the section at the top of the main frame, leaving the rest of the main frame visible and intact.
The "use link" remains visible and active and if you click it again (or issue the chat command again), the same thing happens.

In none of those cases does KoLmafia do anything whatsoever to suppress sending the inv_use.php request to KoL if there is already a dance card counter active. If the browser says "send this to KoL", then, by golly, KoLmafia does so.

Now, we do have code in UseItemRequest to suppress using a dance card if the dance card counter is active. That affects the GUI, the CLI "use" command, and the ASH "use" function. But the Relay Browser does not go through UseItemRequest and that code is not used.

----------

Now, let's consider the revisions that say they deal with Rotting Matilda:

r8109 | veracity0 | 2010-02-09 11:39:06 -0500 (Tue, 09 Feb 2010) | 3 lines
When you dance with Rotting Matilda and have another dance card in inventory,
add a link to use another dance card.

r8111 | veracity0 | 2010-02-09 13:46:35 -0500 (Tue, 09 Feb 2010) | 2 lines
Make Rotting Matilda dance card link load inline

r8192 | veracity0 | 2010-02-25 16:55:32 -0500 (Thu, 25 Feb 2010) | 17 lines
- The "again" button now works to take you back to the Ballroom from the
Rotting Matilda page, even if we have given you a "use another dance card" link

r14003 | darzil | 2014-05-20 10:56:47 -0400 (Tue, 20 May 2014) | 1 line
Fix Rotting Matilda - Thanks Primogenitor

What exactly did that last revision do?

- The snarfblat for the ballroom changed with the Spookyraven revamp, so the insertion point for our use link needed a different search.
- For the same reason, the "dance card" counter needed to change.

That's it. Nothing whatsoever changed about the use link that was generated or what KoLmafia itself does when you click it - which is to say, nothing, since the link goes straight to KoL itself, rather than going through KoLmafia's UseItemRequest.

lost says "despite code that is supposed to prevent them being used when there is already a dance card counter" - but that code has never applied to the Relay Browser.

Bale says "I'm pretty sure that KoLmafia used to prevent that link from using a dance card if there was already a dance card counter active". I think that's like Theraze being "pretty sure" that ASH didn't use to define variables within scopes; there is simply nothing in the code base that I can find to do that.

Now, if I am wrong about this, I respectfully request that somebody locate the revision that changed the behavior. I simply don't see any mechanism in the code for suppressing that use link "if the dance card counter is already active".

----------

There are two possibilities for addressing this Feature request (no, it really is not a Bug, since the code is behaving exactly as it was intended - precisely like KoL's own "in line" [use] link for a dance card):

- As I suggested in my first response, instead of generating a call to javascript:singleUse and making it an inline use link, generate a link that invokes a CLI command.

- Put in some sort of warning, a la clover protection, fortune cookie counters, etc, which pops up when you are about to use a dance card while the previous one is still active. The existing warnings are all "I'm about to consume adventures" things, and this would be a "I'm about to use an item" thing. That's new.

Frankly, I'm inclined to just say:

DON'T DO THAT; it wastes the second dance card.

if the user clicks on the "Use another dance card" link in the Relay Browser when the Results: of using the first one are visible at the top of the main frame.

As I said, if we really used to have different behavior (in spite of what I can find in the revision log), tell me when it broke, please.

Thank you.
 

Veracity

Developer
Staff member
Note that when you encounter Rotting Matilda, by definition, the dance card counter is not active, since that is what happens when that counter expires, but you can find new dance cards while the counter is active. I thought that we suppressed adding a use link in that case, but I was wrong. Revision 14246 will suppress adding a use link when you find a usable item which is currently use limited to 0 - like a dance card while the counter is active.
 

Bale

Minion
Fact 1: I cannot find evidence to support my memory.
Fact 2: Evidence is against my memory.
Fact 3: Memory is fallible.

Conclusion: I have no idea what I'm talking about.
 
Top