Bug - Fixed Using the Force doesn't set choice_follows_fight() (in certain conditions?)

Malibu Stacey

Active member
Code:
cast 1 Calculate the Universe
numberology 51
Preference lastEncounter changed from pine bat to War Frat 151st Infantryman
Encounter: War Frat 151st Infantryman
Preference _lastCombatStarted changed from 20200718060816 to 20200718060824
Round 0: Player Two wins initiative!
Round 1: You lose 1 hit point
Preference _universeCalculated changed from 0 to 1
Round 1: Player Two casts USE THE FORCE!
Preference lastEncounter changed from War Frat 151st Infantryman to Using the Force
Encounter: Using the Force

At this point, my code is supposed to do

Code:
if (choice_follows_fight()) {
	run_choice(-1);
}

as the choiceAdventureScript has handling for Using the Force. However it does not do anything of the kind because

Code:
> ash choice_follows_fight()

Returned:     false

> ash available_choice_options()

Returned:     aggregate string [int]
1 => "I am not the adventurer you are looking     for."
2 => "You will go find two friends and meet me here."
3     => "You will drop your things and walk away."

> ash fight_follows_choice()

Returned:     true

We're in a fight, in choice.php with choice options apparently.

Not sure if this happens in other places too or if it's specific to combats that start from choices such as using Calculate the Universe to fight a War Frat 151st Infantryman.

Code:
> version

KoLmafia v20.6 r20253
 

Malibu Stacey

Active member
I realised after I posted this that I could probably handle this by changing that code snippet to

Code:
if (choice_follows_fight() || handling_choice()) {
	run_choice(-1);
}

waiting on the script to need another use of the saber NC to see if that works now.

and I can confirm it works

Code:
[504] Cobb's Knob Harem
Preference lastEncounter changed from sausage goblin to Knob Goblin Harem Girl
Encounter: Knob Goblin Harem Girl
Preference _lastCombatStarted changed from 20200718080508 to 20200718080602
Round 0: Player Two wins initiative!
Round 1: Player Two casts USE THE FORCE!
Preference lastEncounter changed from Knob Goblin Harem Girl to Using the Force
Encounter: Using the Force
Took choice 1387/3: "You will drop your things and walk away."
choice.php?whichchoice=1387&option=3&pwd
Preference _saberForceUses changed from 1 to 2
You acquire an item: Knob Goblin harem pants
You acquire an item: Knob Goblin harem veil
You acquire an item: disease
You acquire an item: finger cymbals

Actually thinking about it more, that's not testing the same thing. I guess I'll have to wait until the next run to test the same thing.
 
Last edited:

Veracity

Developer
Staff member
I'll have to think more about this, but my initial response is that choice_follows_fight() is not appropriate for Using the Force.

When you use run_combat(), it handles the entire fright, until you win, run away, or otherwise end the fight with a banish.
Use the Force is a combat skill. While you are processing that, you are still in the fight.
As it happens, it is handled via a choice, all of whose options end the fight.

When you submit the option, then the combat ends, the combat is over, and choice_follows_fight() will not be set, since there is, in fact, no choice following the fight.

I'll have to look at Calculate the Universe (and maybe genie wishes) to see how it is automating a fight. I'd expect it to automate all the way through multi fights (like clingy or eldritch attunement) and fight/choice(/fight/...) situations.
 

Veracity

Developer
Staff member
I reproduced this by doing the following:

I set my CCS to include:

Code:
[ war frat 151st infantryman ]
skill use the force

I iinstalled a choiceAdventureScript:

Code:
void main( int choice, string page )
{
    // code to handle the choice, using available_choice_options(), run_choice(), etc.
    print( "In choice adventure " + choice );

    int option = 0;
    boolean fight = false;

    switch ( choice ) {
	// Using the Force
    case 1387:
	option = 3;
	break;

    default:
	print( "not handling " + choice );
	return;
    }

    // Argument 2 is "should automate fights" We don't want to do that
    // inside this script; follow the redirect and leave it to outer
    // automation.
    run_choice( option, !fight );
    if ( fight_follows_choice() ) {
	print( "Heading into a fight..." );
    }
    print( "Done!" );
}
When I did "numberology 51", it redirected to a fight, found my CCS, which cast "Use the Force" - and left me in the choice adventure.

The "numberology" command uses a NumberologyRequest. I noticed that GenericRequest has special handling for certain classes which can redirect to a fight.
I added NumberologyRequest to that:

Code:
		if ( this.redirectLocation.startsWith( "fight.php" ) || this.redirectLocation.startsWith( "fambattle.php" ) )
		{
			String location = this.getURLString();

			GenericRequest.checkItemRedirection( location );
			GenericRequest.checkChoiceRedirection( location );
			GenericRequest.checkSkillRedirection( location );
			GenericRequest.checkOtherRedirection( location );

			if ( this instanceof UseItemRequest ||
			     this instanceof CampgroundRequest ||
			     this instanceof ChateauRequest ||
			     this instanceof DeckOfEveryCardRequest ||
			     this instanceof GenieRequest ||
			     this instanceof NumberologyRequest ||
			     this instanceof UseSkillRequest )
			{
				this.redirectHandled = true;
				FightRequest.INSTANCE.run( this.redirectLocation );
				if ( FightRequest.currentRound == 0 && !FightRequest.inMultiFight && !FightRequest.choiceFollowsFight )
				{
					KoLmafia.executeAfterAdventureScript();
				}
				return !LoginRequest.isInstanceRunning();
			}
		}
It still left me at the choice, because FightRequest did not automate once it redirected to a choice.

That is typically left to the outer script - adv1(), etc. - to do. In fact, any of these requests - mushroom garden, chateau monster, genie wishes, numberology - can lead to multi-fights (clingy monsters, Eldritch Attunement) or a choice (Use the Force). So I added automation for those conditions, the same as adv1() etc. needs to do:

Code:
				// Clingy monsters or Eldritch Attunement can lead to a multi-fight
				// Using the Force can leave you in a choice.
				while ( !KoLmafia.refusesContinue() )
				{
					if ( FightRequest.inMultiFight || FightRequest.fightFollowsChoice )
					{
						FightRequest.INSTANCE.run();
						continue;
					}
					if ( FightRequest.choiceFollowsFight )
					{
						RequestThread.postRequest( new GenericRequest( "choice.php" ) );
						// Fall through
					}
					if ( ChoiceManager.handlingChoice )
					{
						ChoiceManager.gotoGoal();
						continue;
					}
					break;
				}
With those changes, I did this:

Code:
[color=green]> numberology 51[/color]

[1199] numberology 51
Encounter: War Frat 151st Infantryman
Round 0: Veracity wins initiative!
Round 1: Veracity executes a macro!
Encounter: Using the Force
In choice adventure 1387
Submitting option 3 for choice 1387
You acquire an item: distressed denim pants
You acquire an item: beer helmet
You acquire an item: bejeweled pledge pin
You acquire an item: bottle opener belt buckle
You acquire an item: perforated battle paddle
You acquire an item: keg shield
You acquire an item: beer bomb
You acquire an item: flask flops
Done!
Notice that it called my choiceAdventureScript: "In choice adventure 1387" and "Done!" were printed by this.

So, as long as you are Calculating the Universe via the "numberology" command - which casts the skill, follows the choice.php redirection, submits the derived number to get the desired result - you should be good to go.

If you are doing all those manually with visit_url(), then you need to handle the fights and choices on your own.

Revision 20261
 

Malibu Stacey

Active member
I just automated the war frat combat (ending with using the force as in the earlier message) and it worked perfectly in r20263.

Thanks for looking in to this Veracity. It is very much appreciated.
 
Top