Monster defense: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
mNo edit summary
imported>Eliteofdelete
No edit summary
 
(9 intermediate revisions by 4 users not shown)
Line 5: Line 5:
FunctionPage|
FunctionPage|
name={{#var:name}}|
name={{#var:name}}|
function_category=Adventuring|
second_category=In-combat Consulting|


function1={{Function|
function1={{Function|
Line 23: Line 21:
p1desc={{Pspan|check_me}} is the (optional) monster to get the defense value of|
p1desc={{Pspan|check_me}} is the (optional) monster to get the defense value of|
}}|
}}|
function_description=Returns the defense value of the specified monster {{pspan|check_me}}. If {{pspan|check_me}} is not specified, it defaults to the last monster you encountered. This function adjusts for know effects (such as monster level modifications).</p>
function_description=Returns the defense value of the specified monster {{pspan|check_me}}. If {{pspan|check_me}} is not specified, it will use the current monster if you are in a fight (i.e. you're calling the function from an [[In-combat Consulting]] script), or the last monster you encountered otherwise.</p>
<p>This function can be used from within an [[In-combat Consulting]] script to help determine your fight strategy. When used this way, it isn't necessary to specify a monster, as the function will default to the one currently being fought. It will update the information returned each time it is called, to the best of KoLmafia's knowledge.|
<p>When the function is given a monster as a parameter it will return the monster's defense at the start of a fight including all monster level modifications. This means that for monsters with unknown defense, the return value will be equivalent to {{f|monster_level_adjustment}}. If the zero parameter version is called and the character is currently in a fight, then the function will include all current combat deleveling modifiers from the current combat.</p>
<p>If you want to know the monster's raw defense without being modified by monster level adjustments, it is available through the monster.'''raw_defense''' proxy field.|


needscode=yes|
code1={{CodeSample|
title=Code Samples|
description=Following is an example of a function that determines your chance to hit a monster based on its defense. |
code=
<syntaxhighlight>
void hitcheck(string monstername) {
  float fumble;
  int def = monster_defense(to_monster(monstername));
  int weaponstat = buffed_hit_stat();
  int basehitchance = weaponstat-def;
  if (basehitchance <= -6)
      print("You will always miss "+monstername+".", "red");
  else if (basehitchance >= 5) {
      if (numeric_modifier("fumble") > 0)
        fumble = 100-4.545*numeric_modifier("fumble");
      else fumble = 100-4.545;
      print("You will always hit, except for fumbles (Hit "+fumble+"% of the time)", "green");
  }
  else {
      float hitchance;
      if (numeric_modifier("fumble") > 0)
        hitchance = (6.0+weaponstat-def)/11*(100-4.545*numeric_modifier("fumble"));
      else hitchance = ((6.0+weaponstat-def)/11)*(100-4.545); 
      print("Monster "+monstername+" will get hit by you ~"+round(hitchance)+"% of the time.", "blue");
  }
}
hitcheck("bar");
</syntaxhighlight>|
moreinfo=
Note: The example does not take skills that increase hit chance and the formula may be out of date. For more information about hitting see KoL's Wiki [http://kol.coldfront.net/thekolwiki/index.php/Hit_Chance Hit Chance].


see_also={{SeeAlso|monster_attack|monster_element|monster_hp}}|
}}|
 
see_also={{SeeAlso|monster_attack|monster_initiative|monster_element|monster_hp}}|
more_info=For the current discussion of what's being tracked in-combat for monster level adjustments, please see [http://kolmafia.us/showthread.php?3452 this thread].|
more_info=For the current discussion of what's being tracked in-combat for monster level adjustments, please see [http://kolmafia.us/showthread.php?3452 this thread].|
special=When not logged in, this function returns 0 if no monster is specified.|
special=If no monster is specified and no monster has been fought in this session, this function returns 0. This is because mafia forgets the value of {{f|last_monster}} when it logs out.|
}}
}}
{{RFI|Is the information about the self-updating nature of the return value correct?|Is the not-logged-in value correct?}}
 
[[Category:Adventuring]][[Category:In-combat Consulting]]

Latest revision as of 14:30, 17 January 2015

Function Syntax

int monster_defense()

int monster_defense(monster check_me )

  • check_me is the (optional) monster to get the defense value of

Returns the defense value of the specified monster check_me. If check_me is not specified, it will use the current monster if you are in a fight (i.e. you're calling the function from an In-combat Consulting script), or the last monster you encountered otherwise.

When the function is given a monster as a parameter it will return the monster's defense at the start of a fight including all monster level modifications. This means that for monsters with unknown defense, the return value will be equivalent to monster_level_adjustment(). If the zero parameter version is called and the character is currently in a fight, then the function will include all current combat deleveling modifiers from the current combat.

If you want to know the monster's raw defense without being modified by monster level adjustments, it is available through the monster.raw_defense proxy field.

Code Samples

Following is an example of a function that determines your chance to hit a monster based on its defense.

void hitcheck(string monstername) {
   float fumble;
   int def = monster_defense(to_monster(monstername));
   int weaponstat = buffed_hit_stat();
   int basehitchance = weaponstat-def;
   if (basehitchance <= -6)
      print("You will always miss "+monstername+".", "red");
   else if (basehitchance >= 5) {
      if (numeric_modifier("fumble") > 0)
         fumble = 100-4.545*numeric_modifier("fumble");
      else fumble = 100-4.545;
      print("You will always hit, except for fumbles (Hit "+fumble+"% of the time)", "green");
   }
   else {
      float hitchance;
      if (numeric_modifier("fumble") > 0)
         hitchance = (6.0+weaponstat-def)/11*(100-4.545*numeric_modifier("fumble"));
      else hitchance = ((6.0+weaponstat-def)/11)*(100-4.545);   
      print("Monster "+monstername+" will get hit by you ~"+round(hitchance)+"% of the time.", "blue");
   }
}
hitcheck("bar");

Note: The example does not take skills that increase hit chance and the formula may be out of date. For more information about hitting see KoL's Wiki Hit Chance.

See Also

monster_attack() | monster_initiative() | monster_element() | monster_hp()

More Information

For the current discussion of what's being tracked in-combat for monster level adjustments, please see this thread.

Special

If no monster is specified and no monster has been fought in this session, this function returns 0. This is because mafia forgets the value of last_monster() when it logs out.