# 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 );
}