Thanks for your replies, Linknoid and Pazleysocks. Getting through the choice adventure, and starting the fight, wasn't giving me any trouble. I was just struggling to figure out how to automate the fight itself (other than with run_combat).
Here's what I ended up doing:
Code:
visit_url("place.php?whichplace=forestvillage&action=fv_scientist");
run_choice(2);
adv1(my_location(), -1, "[I][my combat strategy][/I]");
That works well, for defining my strategy in the script.
Sorry that I ignored this; I plead my new job (six months now, so is it still new?) which sucks away all my attention during the week - and I'm less inclined to dive into coding on the weekend. My brain is full.
This thread is full of interesting things. Some observations:
1) visit_url() will follow a redirect for you. So, when you visit_url() to fight a Witchess Piece or to follow a choice in the Science Tent, KoL redirects to fight.php and visit_url() itself will follow that redirect, which will set up KoLmafia to know that you are inside a fight. At that point, you can use run_combat() and it will carry on as directed. In particular, if you give it a combat filter, it will use it.
2) I don't think run_choice follows a redirect. Given an option > 0, I see this:
Code:
else if ( option > 0 )
{
// Submit the option chosen
String message = "Submitting option " + option + " for choice " + ChoiceManager.getLastChoice();
RequestLogger.printLine( message );
response = ChoiceManager.processChoiceAdventure( option, false );
}
processChoiceAdventure with "false" means "do not try to automate".
Code:
public static final String processChoiceAdventure( final int decision, final boolean tryToAutomate )
{
GenericRequest request = ChoiceManager.CHOICE_HANDLER;
request.constructURLString( "choice.php" );
request.addFormField( "whichchoice", String.valueOf( ChoiceManager.lastChoice ) );
request.addFormField( "option", String.valueOf( decision ) );
request.addFormField( "pwd", GenericRequest.passwordHash );
request.run();
if ( tryToAutomate )
{
ChoiceManager.processChoiceAdventure( request, "choice.php", request.responseText );
return "";
}
return request.responseText;
}
Which is to say, it should simply submit the choice.php URL and return the page text. However, choice.php redirected to fight.php. So, what does it return?
I'm wondering where - if ever - it follows the redirect to fight.php to let KoLmafia know you are in a fight. Apparently, it does not (although I have not finished tracing the code in GenericRequest to understand that, yet) in which case, run_combat() would not know you are already in a combat.
3) run_combat() when called and we think you are not in a fight will return "" (if given a filter function) or whatever the last combat round returns. I'm not sure why the difference.
4) adv1 will try to adventure, will get redirected to a fight, and will do it. That is why your solution is working - at the expense of an extra server hit.
5) VeracityMeatFarm does this for Witchess pieces:
Code:
visit_url( "campground.php?action=witchess" );
run_choice( 1 );
visit_url( "choice.php?whichchoice=1182&option=1&piece=" + fight.id + "&pwd=" + my_hash(), false );
combat_filter_setup( NO_LOCATION );
run_combat( "hobo_monkey_filter" );
It does visit_url to choose the monster - because you need to specify the "piece" parameter in addition to the option - which redirects to the fight, and run_combat() works well.
6) VeracityMeatFarm does this for the Science Tent:
Code:
string page = visit_url( "place.php?whichplace=forestvillage&action=fv_scientist" );
...
run_choice( fight );
and I see the following in my session log:
Code:
> Fighting Eldritch Tentacles
Visiting a Science Tent
Encounter: Dr. Gordon Stuart, a Scientist
Took choice 1201/1: Can I fight that tentacle you saved for science?
choice.php?whichchoice=1201&option=1&pwd
[20795] Dr. Gordon Stuart's Science Tent
Encounter: Eldritch Tentacle named Shhhhhblrgglblllrrgggh
Round 0: Veracity wins initiative!
...
And I'm not sure where the fighting happens! It used my CCS, as you commented.
I need to track down how GenericRequest processes a choice.php -> fight.php.
For me, it seems to automate the fight, in this case.
For you, it seems to leave the fight un-started.