KoLmafia & Stasis

syrinxlui

Member
Stasis Script?

Holatuwol's post in the KoL forums about version 8.9 makes note that stasis may be possible with the additions he's made. Is anyone working on one of these? What sorts of features would you like to see?
 

macman104

Member
Re: Stasis Script?

There's a discussion in the scripting section. Some parts were worked on using some of the new functionaltiy, like the visit_url, and other functions. It's not completely finished, but there are aspects completed.
 

holatuwol

Developer
Re: Stasis Script?

I'm in the middle of working on one, as I figure out whether or not I should add stasis to KoLmafia. This one is based off of the work done by Tirian in the thread in Scripting Discussion. I'm interested in where it goes from here.

Code:
# Define a record which encapsulates information for a given round.
# This is used throughout to package data a lot more easily.

record CombatState
{
    int round_number;
    monster initial_data;
    int atk_modifier;
};

# Some global semi-constants (no way to define actual constants in
# ASH, so just mutual understanding) that are used to do string
# matching in KoLmafia.

string EXTEND = "action=attack";
string DELEVEL = "action=skill&whichskill=3004";
string RESTORE_HP = "action=skill&whichskill=4014";
string FINISH = "action=skill&whichskill=1003";

# Prepares you for the location.  Checks the current stats of the
# monsters and decides whether or not it should change its equipment.

void prepare_for_location( location zone )
{
    monster [int] potential_enemies = get_monsters( zone );
    
    # Determine the optimal equipment to be using in the area that
    # reduces the overall damage and/or balances moxie best.

    print( "Not yet implemented." );
    
    # Find out the maximum damage that you'd receive in the first
    # rounds, heal up to that amount and move on.

    print( "Not yet implemented." );
}

# Figures out what monster you're fighting based on the HTML that
# was returned by the server.

monster get_enemy( location zone, string response_text )
{
    monster [int] potential_enemies = get_monsters( zone );
    foreach index in potential_enemies
        if ( contains_text( response_text, potential_enemies[index] ) )
            return potential_enemies[index];
    return $monster[none];
}

# Executes the specified action and returns the URL that resulted.
# This is really just an encapsulation to make things easier to read.

string execute_action( string action )
{
    return visit_url( "fight.php?" + action );
}

# Returns how much damage is expected from the monster given the data.
# There are some formulas out right now, but too lazy to actually
# use them right now.

int get_expected_damage( CombatState encounter )
{
    print( "Not yet implemented." );
    return 0;
}

# Figures out what to do based on the player's current health and
# the monster's current health, along with the damage that was
# received during the round.

string execute_round( CombatState encounter, int damage_received )
{
    encounter.round_number = encounter.round_number + 1;

    if ( encounter.round_number > 27 )
        return execute_action( FINISH );

    if ( damage_received > 6 || get_expected_damage( encounter ) > 6 )
    {
        encounter.atk_modifier = encounter.atk_modifier - 6;
        return execute_action( DELEVEL );
    }

    if ( my_hp() <= damage_received + 5 )
        return execute_action( RESTORE_HP );

    return execute_action( EXTEND );
}

# Runs a single adventure which attempts to stasis.  If it encounters
# a non-combat adventure, it does nothing.

void one_stasis_adventure( location zone )
{
    int damage_received = 0;
    int before_round_hp = my_hp();

    string round_result = visit_url( location_to_url( zone ) );

    CombatState encounter;
    encounter.round_number = 0;
    encounter.initial_data = get_enemy( zone, round_result );
    encounter.atk_modifier = 0;

    while ( contains_text( round_result, "fight.php" ) )
    {
        damage_received = before_round_hp - my_hp();
        before_round_hp = my_hp();
        
        # In the original script by Tirian, there was a damage-calculator
        # which determined the amount of damage done.  I didn't see any
        # use for it, based on Zair's video (not HP counting), so I'm going
        # to omit it for now.
        
        round_result = execute_round( encounter, damage_received );
    }
}

# Prompts the user for the location where they would like to adventure
# and the amount of MP they would like to restore.  Then runs adventures
# at the chosen location until the MP is up to par.

void main( location stasis_zone, int desired_mp )
{
     while( my_mp() < desired_mp )
         one_stasis_adventure( stasis_zone );
}
 

holatuwol

Developer

string attack(): Added
string runaway(): Added
string use_skill( skill touse ): Added
boolean use_skill( int count, skill touse ): Modified to accept combat skills
string throw_item( item tothrow ): Added
string throw_items( item tothrow1, item tothrow2 ): Added


I don't know if this will actually help anyone in writing their scripts, but at the very least, there won't be any problems in functionality if you decide to throw use_skill inside of a combat loop.  In case you were wondering, use_skill with the count parameter will actually loop the specified number of times, never reconsulting the script until the loop is complete.
 

muffins

Member
Thank you again sooo much for adding this functionality! I've updated my CC script (after updating from SVN, of course), and I'll be giving it a shot tonight after rollover.

If I may request one more combat-related feature, would it be possible to add a command for setting the Auto Attack option?

What I currently use is:

Code:
visit_url("account.php?action=autoattack&whichattack=0"); 
// Set Auto Attack to: Disabled
or
visit_url("account.php?action=autoattack&whichattack=4003"); 
// Set Auto Attack to: Stream of Sauce

Could be auto_attack( skill )/autoattack( skill ) with $skill[none] equalling disabling of auto attack and $skill[attack] or $skill[weapon] setting it to Attack with weapon (since skill #1 is reserved for liver)... something like that.

I really only ask becauce I've been experiencing some weirdness with cli_execute and visit_url lately... the only example I have is of when I first attempted to use the above in a script (switching to stream for the gallery, none for the treasury, so I could heal), and it didn't seem to be actually changing the auto attack method. I can post the script if needed.

Edit: Yeah, visit_url seems to be broken for me...

I tried:
Code:
string aa_text = visit_url("account.php?action=autoattack&whichattack=0");

print(aa_text);

And it returned "Script succeeded!", but didn't print any text... so I guess there's currently no way to change my auto-attack option :(
 
Top