Difference between revisions of "Monster attack"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
(Created page with '{{ #vardefine:name|monster_attack}}{{ #vardefine:return_type|int}}{{ FunctionPage| name={{#var:name}}| function_category=Adventuring| second_category=In-combat Consulting| func…')
 
imported>Eliteofdelete
(Added a precise monster hit-chance example based on monster attack.)
 
(12 intermediate revisions by 6 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 attack value of|
 
p1desc={{Pspan|check_me}} is the (optional) monster to get the attack value of|
 
}}|
 
}}|
function_description=Returns the attack 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 attack 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 attack at the start of a fight including all monster level modifications. This means that for monsters with unknown attack, 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 attack without being modified by monster level adjustments, it is available through the monster.'''raw_attack''' proxy field.|
  
needscode=yes|
+
code1={{CodeSample|
 +
title=Code Samples|
 +
description=Following example is a non-percise function that uses the monster's attack to estimate hit chance based on your moxie.|
 +
code=
 +
<syntaxhighlight>
 +
boolean safecheck(string monstername) {
 +
  int att = monster_attack(to_monster(monstername));
 +
  if (att+10 <= my_buffedstat($stat[moxie])) {
 +
      print("Monster "+monstername+" will always miss! (except for crits)", "green");
 +
      return true;
 +
  }
 +
  else if (att-10 >= my_buffedstat($stat[moxie])){
 +
      print(att+10);
 +
      print("Monster "+monstername+" will always hit you! (except for fumbles)", "red");
 +
      return false;
 +
  }
 +
  else {
 +
      print(att);
 +
      int hitchance = (att+10-my_buffedstat($stat[moxie]))*5;
 +
      print("Monster "+monstername+" will hit you "+hitchance+"% of the time.", "blue");
 +
      return false;
 +
  }
 +
return false;
 +
}
  
see_also={{SeeAlso|monster_defense|monster_hp}}|
+
safecheck("bar");
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].|
+
</syntaxhighlight>|
special=When not logged in, this function returns 0 if no monster is specified.|
+
}}|
 +
 
 +
code2={{CodeSample|
 +
description=Following example returns the exact chance for a monster to hit. The function can be supplied a string or monster varible.|
 +
code=
 +
<syntaxhighlight>
 +
float monsterHitChance(monster monsterName) {
 +
int difference = my_buffedstat($stat[moxie]) - monster_attack(monstername); //Also known as monster awesomeness
 +
if (difference >= 10)
 +
return 0;
 +
else if (difference <= -9)
 +
return 1;
 +
switch (difference) {
 +
case -8:
 +
return 0.99;
 +
case -7:
 +
return 0.97;
 +
case -6:
 +
return 0.9;
 +
case -5:
 +
return 0.85;
 +
case -4:
 +
return 0.79;
 +
case -3:
 +
return 0.72;
 +
case -2:
 +
return 0.64;
 +
case -1:
 +
return 0.55;
 +
case 0:
 +
return 0.5;
 +
case 1:
 +
return 0.45;
 +
case 2:
 +
return 0.36;
 +
case 3:
 +
return 0.28;
 +
case 4:
 +
return 0.21;
 +
case 5:
 +
return 0.15;
 +
case 6:
 +
return 0.1;
 +
case 7:
 +
return 0.16;
 +
case 8:
 +
return 0.03;
 +
case 9:
 +
return 0.01;
 +
  }
 +
  return 1;
 +
}
 +
float monsterHitChance(string monsterName) {return monsterHitChance(to_monster(monsterName));}
 +
 
 +
foreach mob, freq in appearance_rates($location[The VERY Unquiet Garves]) {
 +
if (freq > 0)
 +
print("The monster ("+mob+") will hit you "+monsterHitChance(mob)*100+"% of the time.", "blue");
 +
}
 +
</syntaxhighlight>|
 +
}}|
 +
 
 +
see_also={{SeeAlso|monster_defense|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].<br>
 +
For more details on monster hit-chance, please visit [https://kol.coldfront.net/thekolwiki/index.php/Monsters here].|
 +
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 05:36, 19 September 2019

Function Syntax

int monster_attack()

int monster_attack(monster check_me )

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

Returns the attack 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 attack at the start of a fight including all monster level modifications. This means that for monsters with unknown attack, 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 attack without being modified by monster level adjustments, it is available through the monster.raw_attack proxy field.

Code Samples

Following example is a non-percise function that uses the monster's attack to estimate hit chance based on your moxie.

boolean safecheck(string monstername) {
   int att = monster_attack(to_monster(monstername));
   if (att+10 <= my_buffedstat($stat[moxie])) {
      print("Monster "+monstername+" will always miss! (except for crits)", "green");
      return true;
   }
   else if (att-10 >= my_buffedstat($stat[moxie])){
      print(att+10);
      print("Monster "+monstername+" will always hit you! (except for fumbles)", "red");
      return false;
   }
   else {
      print(att);
      int hitchance = (att+10-my_buffedstat($stat[moxie]))*5;
      print("Monster "+monstername+" will hit you "+hitchance+"% of the time.", "blue");
      return false;
   }
return false;
}

safecheck("bar");

Following example returns the exact chance for a monster to hit. The function can be supplied a string or monster varible.

float monsterHitChance(monster monsterName) {
	int difference = my_buffedstat($stat[moxie]) - monster_attack(monstername); //Also known as monster awesomeness
	if (difference >= 10)
		return 0;
	else if (difference <= -9)
		return 1;
	switch (difference) {
		case -8:
			return 0.99;
		case -7:
			return 0.97;
		case -6:
			return 0.9;
		case -5:
			return 0.85;
		case -4:
			return 0.79;
		case -3:
			return 0.72;
		case -2:
			return 0.64;
		case -1:
			return 0.55;
		case 0:
			return 0.5;
		case 1:
			return 0.45;
		case 2:
			return 0.36;
		case 3:
			return 0.28;
		case 4:
			return 0.21;
		case 5:
			return 0.15;
		case 6:
			return 0.1;
		case 7:
			return 0.16;
		case 8:
			return 0.03;
		case 9:
			return 0.01;
   }
   return 1;
}
float monsterHitChance(string monsterName) {return monsterHitChance(to_monster(monsterName));}

foreach mob, freq in appearance_rates($location[The VERY Unquiet Garves]) {
	if (freq > 0)
		print("The monster ("+mob+") will hit you "+monsterHitChance(mob)*100+"% of the time.", "blue");	
}

See Also

monster_defense() | 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.
For more details on monster hit-chance, please visit here.

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.