Bug - Fixed june cleaver preferences not updating

Tokoeka

Member
using r26832, I noticed my script running to the noob cave after every fight (and then bailing when it wasnt getting what it expected) - determined it was due to expecting a june cleaver adventure when one wasnt due. having looking into my session log, I noticed the following, which appears to show me recieving a june cleaver adventure, but then the _juneCleaverFightsLeft and _juneCleaverEncounters properties not being set

  1. equip weapon June cleaver
    Preference choiceAdventure1468 changed from 2 to 4
    Preference choiceAdventure1470 changed from 2 to 4
    Preference choiceAdventure1473 changed from 1 to 4
    Preference recoveryScript changed from scriptsUniversal_recovery.ash to
    Preference nextAdventure changed from The Tunnel of L.O.V.E. to Noob Cave
    Preference lastAdventure changed from The Copperhead Club to Noob Cave

    [563] Noob Cave
    Preference lastEncounter changed from L.O.V. Emporium to Poetic Justice
    Encounter: Poetic Justice
    Took choice 1467/3: Gain 5 adventures, get beaten up
    choice.php?forceoption=0?whichchoice=1467&option=3&pwd
    Preference juneCleaverQueue changed from 1473,1469,1472,1468,1470,1471 to 1469,1472,1468,1470,1471,1467
    You acquire an effect: Beaten Up (5)
    You gain 5 Adventures

    cast 1 Tongue of the Walrus
    You gain 38 hit points
    You lose an effect: Beaten Up
    Preference recoveryScript changed from to scriptsUniversal_recovery.ash

    cast 1 Summon Taffy

there is a previous instance in my session log from today (during running of the same script) of hitting a different cleaver noncom and the preferences being set correctly, so it might have something to do with it being the poetic justice encounter?

[563] The Copperhead Club
Preference lastEncounter changed from the Mob Penguin Capo to Lost and Found
Encounter: Lost and Found
Took choice 1471/1: savings bond
choice.php?whichchoice=1471&option=1&pwd
Preference juneCleaverQueue changed from 1475,1473,1469,1472,1468,1470 to 1473,1469,1472,1468,1470,1471
Preference _juneCleaverEncounters changed from 0 to 1
Preference _juneCleaverFightsLeft changed from 0 to 6
You acquire an item: savings bond
(edited to add current mafia revision)
 
Last edited by a moderator:

Tokoeka

Member
reran script after updating preferences - same thing occured on the guilty sprout noncom.

lowered mafia version to r26829 and reran script (after once again resetting preferences) and it no longer seems to be having this issue
 

heeheehee

Developer
Staff member
Relevant snippet from JuneCleaverManager.java:
Java:
    Matcher optionFinder = Pattern.compile("option=(?<optionNumber>\\d+)").matcher(urlString);
    if (!optionFinder.find()) return;

    // This updates juneCleaverQueue, which you saw.
    int option = Integer.parseInt(optionFinder.group("optionNumber"));

    if (option == 4) {
      Preferences.increment("_juneCleaverSkips");
      Preferences.setInteger("_juneCleaverFightsLeft", fightsLeft(true));
    } else if (option == 1 || option == 2 || option == 3) {
      Preferences.increment("_juneCleaverEncounters");
      Preferences.setInteger("_juneCleaverFightsLeft", fightsLeft(false));
    }

You'll note that the "bad" URL string is "choice.php?forceoption=0?whichchoice=1467&option=3&pwd", which catches my eye for two reasons:
  1. You use ?forceoption=0?whichchoice=1467... instead of &whichchoice=1467. Weird, but not necessarily broken.
  2. The regex actually binds to (force)option=0 instead of option=3.
I don't think this is a new regression (I spent a little while staring at r26831); rather, you got "lucky" with the failure.

Simple fix: add \\b (or explicitly [?&]) to the regex to check for a word boundary.

Better fix: instead of using regex to parse out query parameters from a string, we should be using a map lookup. We use regex all over the place for this sort of thing, so I wouldn't be surprised if there are similar ways of causing this problem elsewhere.
 
Can you show me the code in your script that submitted the choice?
It's compiled from typescript:

Code:
function juneCleave(): void {
  if (get("_juneCleaverFightsLeft") <= 0) {
    equip($slot`weapon`, $item`June cleaver`);
    skipJuneCleaverChoices();
    withProperty("recoveryScript", "", () => {
      adventureMacro($location`Noob Cave`, Macro.abort());
      if (["Poetic Justice", "Lost and Found"].includes(get("lastEncounter"))) {
        uneffect($effect`Beaten Up`);
      }
    });
  }
}

skipJuneCleaverChoices just sets various choiceAdventure properties, and adventureMacro just wraps adv1, so this isn't using anything special to run the choice, it's just adventuring.
 

Veracity

Developer
Staff member
So it submits an adventure which redirects to a choice which is automated using your choiceAdventure settings.
 

Veracity

Developer
Staff member
OK. I see what is happening.

- adventure.php redirects to choice.php?forceoption=0
- KoL says to use a GET.
- We call ChoiceManager.processRedirectedChoiceAdventure
- That calls ChoiceManager.processChoiceAdventure
- That submits a GET (As KoL directed) (this is new) to get the responseText.
- It proceeds to automate each step, inserting the appropriate whichchoice and option fields.

Code:
    request.clearDataFields();
    request.addFormField("whichchoice", String.valueOf(choice));
    request.addFormField("option", decision);
    ...
    request.addFormField("pwd", GenericRequest.passwordHash);

    request.run()

That assumes it has a POST request.

The first line should be

Code:
    request.constructURLString("choice.php");

I could submit a PR with this one line change, but I have no time to write tests; my spouse is coming back from Japan for about 12 days on Friday, and I won't have time for actual serious coding until they return to Japan.
 
Last edited:
Top