Code:
package org.hyperion.rs2.content.combat.melee;
import org.hyperion.rs2.content.combat.Combat;
import org.hyperion.rs2.content.skills.Prayer;
import org.hyperion.rs2.model.Bonuses;
import org.hyperion.rs2.model.Entity;
import org.hyperion.rs2.model.NPC;
import org.hyperion.rs2.model.Player;
import org.hyperion.rs2.model.Skills;
import org.hyperion.rs2.model.container.Equipment;
/**
*
* @author 2012
*
*/
public class MeleeMaxHit {
/**
* Constants holding item ids
*/
private static final int BLACK_MASK = 8921;
private static final int VOID_TOP = 8839;
private static final int VOID_BOTTOM = 8840;
private static final int VOID_GLOVES = 8842;
private static final int SALVE_AMULET = 4081;
private static final int SALVE_AMULET_E = 10588;
/**
* This is the special modifier, with this we time the max hit by. maxhit *
* special[][1]
*/
private static final double[][] SPECIAL = { { 5698, 1.2 }, { 5680, 1.2 },
{ 1231, 1.2 }, { 1215, 1.2 }, { 3204, 1.1 }, { 1305, 1.15 },
{ 1434, 1.45 }, { 861, 1.1 }, { 4151, 1.1 }, { 10887, 1.2933 }, };
/**
* This is an array that holds all the obby weapons
*/
private static final int[] OBDIDIAN_WEAPONS = { 746, 747, 6523, 6525, 6526,
6527, 6528 };
/**
* This is an array that holds all the names of undead monsters
*/
private static final String[] UNDEAD = { "aberrant spectre", "banshee",
"crawling hand", "ghost", "ghast", "mummy", "shade", "skeleton",
"undead", "zombie", "zogre", };
/**
* This method is used for calculating salve amulet. Only works if player
* has one equipped and fighting undead monster
*
* @param p
* instance of Player
* @param e
* instance of Entity
* @return modifier
*/
public static final double addSalveAmulet(Player p, Entity e) {
/**
* We check if the victim is a npc
*/
if (e instanceof NPC) {
/**
* the victim is a npc so we give it a variable to call it stricly
*
* @param n
* the actual npc
*/
NPC n = (NPC) e;
/**
* @param npcName
* the name of the npc victim
*/
String npcName = n.getDefinition().getName().toLowerCase();
/**
* If any errors have occured with the npc name then we just end the
* method with no extra modifier
*/
if (npcName == null) {
return 1.0;
}
/**
* We loop through the array holding the npc names which are undead.
* Looping through names is cleaner because some names are similiar
* but the id are never. We can get the absolute correct one with
* string.contains
*/
for (int i = 0; i < UNDEAD.length; i++) {
if (npcName.contains(UNDEAD[i])) {
/**
* Here we give the bonus, we check using a ternary
* operation to specifically give the correct one.
*/
return p.getEquipment().contains(SALVE_AMULET) ? 1.15 : p
.getEquipment().contains(SALVE_AMULET_E) ? 1.20
: 1.0;
}
}
}
return 1.0;
}
/**
* This method is used for calculating black mask. Only works if player has
* one equipped and fighting slayer task
*
* @param p
* instance of Player
* @param e
* instance of Entity
* @return modifier
*/
public static double addBlackMask(Player p, Entity e) {
/**
* We check if the victim is a npc
*/
if (e instanceof NPC) {
/**
* the victim is a npc so we give it a variable to call it stricly
*
* @param n
* the actual npc
*/
NPC n = (NPC) e;
/**
* We check if the player has a task
*/
if (p.getSlayerTask().hasTask()) {
/**
* We loop through the slayer npcs and find if the entity
* matches the slayer task
*/
for (int task : p.getSlayerTask().getSlayerNpcs()) {
/**
* The entity matches the id?
*/
if (task == n.getDefinition().getId()) {
/**
* if the player is wearing a black mask the modifier is
* created.
*/
if (p.getEquipment().contains(BLACK_MASK)) {
return 1.15;
}
}
}
}
}
return 1.0;
}
/**
* This method is used for calculating prayer bonus Each one has a specific
* percentage that the max hit will be increased by
*
* @param p
* instance of Player
* @return modifier
*/
private static final double addPrayerBonus(Player p) {
/**
* @param prayerBonus
* the modifier
*/
double prayerBonus = 1.0;
/**
* Player has toggled burst of strength?
*/
if (p.getPrayer().isPrayerToggled(Prayer.BURST_OF_STRENGTH)) {
prayerBonus = 1.05;
/**
* Player has toggle superhuman strength?
*/
} else if (p.getPrayer().isPrayerToggled(Prayer.SUPERHUMAN_STRENGTH)) {
prayerBonus = 1.10;
/**
* Player has toggled ultimate strength?
*/
} else if (p.getPrayer().isPrayerToggled(Prayer.ULTIMATE_STRENGTH)) {
prayerBonus = 1.15;
}
return prayerBonus;
}
/**
* This method is for adding style bonus. Bonus is only added if player is
* either using aggressive style or controlled
*
* @param p
* instance of Player
* @return style bonus
*/
private static int addStyleBonus(Player p) {
return p.getAttackStyle() == Combat.AGGRESSIVE ? 3
: p.getAttackStyle() == Combat.CONTROLLED ? 1 : 0;
}
/**
* This method is used for calculating extra bonus if player is wearing full
* void armour.
*
* @param p
* instance of Player
* @return void bonus
*/
private static int addVoidBonus(Player p) {
int voidBonus = 0;
int strengthLevel = p.getSkills().getLevel(Skills.STRENGTH);
if (p.getEquipment().contains(VOID_TOP)
&& p.getEquipment().contains(VOID_BOTTOM)
&& p.getEquipment().contains(VOID_GLOVES)) {
voidBonus = (int) Math.floor((strengthLevel / 50) + 1.6);
}
return voidBonus;
}
/**
* Very accurate.
*
* NOTE: At times it hits either 1 hit less or 1 hit more. Not a problem at
* all.
*
* @param attacker
* instance of Entity
* @param e
* instance of Entity
* @param special
* used for special attacks only
* @return entity max hit
*/
public static int calculateBase(Entity attacker, Entity e, boolean special) {
/**
* We check if the attacker is a player. if so then we calculate the max
* hit otherwise the entity is a npc so we return a fixed max hit
*/
if (attacker instanceof Player) {
/**
* @param p
* the actual player
*/
Player p = (Player) attacker;
/**
* We start of with just void bonus, it actually only is added if
* player is wearing full void.
*/
int base = addVoidBonus(p);
/**
* The players strength bonus
*/
int bonus = p.getBonuses().getBonus(Bonuses.STRENGTH);
/**
* The players strength level
*/
int strength = p.getSkills().getLevel(Skills.STRENGTH);
/**
* The players current hitpoints
*/
int hpCurrent = p.getSkills().getLevel(Skills.HITPOINTS);
/**
* The players overall hitpoints
*/
int hpBase = p.getSkills().getLevelForExperience(Skills.HITPOINTS);
/**
* We calculate the effective strength by timing the players
* strength by player bonus and adding the bonus attack style.
*
* 3 for aggressive and 1 for controlled.
*/
int effective = (int) (strength * addPrayerBonus(p))
+ addStyleBonus(p);
/**
* The base is calculated like this. Even though it seems out of
* bounds, it works as it suppose to. Very accurate I have to say. I
* had 5 different max hit methods and it in the end none of them
* where were they suppose to be So using them all I managed to get
* an accurate perspective hit by this site:
*
* http://www.scape-xp.com/runescape-max-hit-calculator.html
*
* 116.85 (116.85 + (86 / 8) + ((116.85 * 86) / 64)) / 10
*/
base += (effective + (bonus / 10) + ((effective * bonus) / 64)) / 10;
/**
* If player is wearing full dharoks then the base and other bonus
* don't count anymore. It's simply 99 - 1 + 1.5 = 100.49 / 2 = 50.23-
*
*
*/
if (Equipment.wearingDharock(p)) {
base += (int) Math.floor((hpBase - hpCurrent) + 1.5) / 2;
}
/**
* If player is wearing black mask and fighting slayer tasks then
* the hit is multiplied by %15
*
* So if max hit with whip full bonus, pray, etc is 43 We're going
* to do 43 * 1.15 = 49.45 - floor : 49
*/
base *= addBlackMask(p, e);
/**
* There are two salve amulets, one is %15 and the other %20
*
* We calculate the max hit by the percentage
*
* 43 * 1.15 = 49.45 - floor : 49 43 * 1.20 = 51.60 - floor : 51
*
* The max that can be hit with black mask and salve amulet is
*
* (43 * 1.15) * 1.20 = 59.34 - floor : 59 That is ofcoure with 128
* str bonus (max), potted, prayer, slayer task and slayer task is a
* undead monster.
*
* If dharoks is the case then the max hit is 120.
*/
base *= addSalveAmulet(p, e);
/**
* If player is using special and a special modifier set then it's
* calculated by the set.
*
* Example DDS(5698) is 1.2
*
* Max hit, lets say 20 would be 24 if using special.
*
*/
if (special) {
for (int i = 0; i < SPECIAL.length; i++) {
if (p.getEquipment().contains((int) SPECIAL[i][0])) {
base *= SPECIAL[i][1];
}
}
}
/**
* Hmm
*
* If player is using obby weapons and has the necklace too then the
* max hit is calculated by %20.
*
* Say max hit is 40 and we're using below, then it would be 48.
*/
for (int i = 0; i < OBDIDIAN_WEAPONS.length; i++) {
if (p.getEquipment().contains(OBDIDIAN_WEAPONS[i])
&& p.getEquipment().contains(11128)) {
base *= 1.20;
}
}
/**
* We floor the hits.
*
* Floor math is basically ignoring the decimals.
*
* i.e 49.98 = 49, 49.04 = 49, 49.-- is 49.
*/
p.getActionSender().sendMessage(" "+ base + "");
return (int) Math.floor(base);
} else {
/**
* The attacker is not a instance of player but is a npc. Npcs have
* a fix hit.
*
* @param n
* the actual npc
*/
NPC n = (NPC) attacker;
return n.getDefinition().getMaxHit();
}
}
}
Code:
package org.hyperion.rs2.content.combat.range;
import org.hyperion.rs2.content.combat.Combat;
import org.hyperion.rs2.content.combat.melee.MeleeMaxHit;
import org.hyperion.rs2.content.skills.Prayer;
import org.hyperion.rs2.model.Entity;
import org.hyperion.rs2.model.Player;
import org.hyperion.rs2.model.Skills;
/**
*
* @author 2012
*
*
*/
public class RangeMaxHit {
/**
* Rune arrow:
*
* http://www.scape-xp.com/runescape-ranged-max-hit.html
*
* Site: 25.66 - floor : 25
*
* 99 range, eagle eye, full void, accurate:
*
* ((99 * 1.5) + 3 ((99 / 50) + 1.6)) = 159.24
* (159.24 + 8) * (49 + 64) / 640 = 25.41 - floor : 25
*
* Dbow spec = 25 * 1.3
*
* THIS: 32.50 - floor : 32
* Site: 32.46 - floor : 32
*
*
* WIN ?
*/
private static final int VOID_TOP = 8839;
private static final int VOID_BOTTOM = 8840;
private static final int VOID_GLOVES = 8842;
private static final int DARK_BOW = 11235;
private static final int DRAGON_ARROWS = 11235;
private static double addRangePrayerBonus(Player p) {
double prayerBonus = 1.0;
if (p.getPrayer().isPrayerToggled(Prayer.SHARP_EYE)) {
prayerBonus = 1.05;
} else if (p.getPrayer().isPrayerToggled(Prayer.HAWK_EYE)) {
prayerBonus = 1.1;
} else if (p.getPrayer().isPrayerToggled(Prayer.EAGLE_EYE)) {
prayerBonus = 1.15;
}
return prayerBonus;
}
private static int addStyleBonus(Player p) {
return p.getAttackStyle() == Combat.ACCURATE ? 3
: (p.getAttackStyle() == Combat.LONGRANGE ? 1 : 0);
}
private static int addVoidBonus(Player p) {
int voidBonus = 0;
int rangeLevel = p.getSkills().getLevel(Skills.RANGE);
if (p.getEquipment().contains(VOID_TOP)
&& p.getEquipment().contains(VOID_BOTTOM)
&& p.getEquipment().contains(VOID_GLOVES)) {
voidBonus = (int) Math.floor((rangeLevel / 50) + 1.6);
}
return voidBonus;
}
private static int writeEffectiveStrength(Player p, Entity e) {
return (int) ((p.getSkills().getLevel(Skills.RANGE))
* addRangePrayerBonus(p) * MeleeMaxHit.addBlackMask(p, e)
* MeleeMaxHit.addSalveAmulet(p, e) + addStyleBonus(p) + addVoidBonus(p));
}
public static int calculateBase(Player p, Entity e, boolean usingSpecial) {
int base = 0;
int rangeStrength = (int) Math.floor(RangeData.getRangedStrength(p));
int effective = writeEffectiveStrength(p, e);
double equipmentBonus = 1.0;
base += (effective + 8) * (rangeStrength + 64) / 640;
if (usingSpecial) {
if (p.getEquipment().contains(DARK_BOW)) {
equipmentBonus = p.getEquipment().contains(DRAGON_ARROWS) ? 1.5
: 1.3;
}
}
base *= equipmentBonus;
return (int) Math.floor(base);
}
/**
*
* http://runescape.wikia.com/wiki/Black_salamander
*
* Site: floor : 35
*
* A: 2.5 * 99 / 10 = 24.75
* B: 49 / 10 = 4.9
*
* C = A + B = 29.65
*
* D = 2
* E = 99 / 50 + 1.6 = 3.58
*
* F = D + E = 5.58
*
* G = C + F = 35.23 - floor : 35
*
* (2.5 * 99 / 10) + (49 / 10) + (2 + 99 / 50 * 1.6)
*/
public static int calculateSalamander(Player p, int skill) {
int base = 0;
int rangeLevel = p.getSkills().getLevel(skill);
int rangeStrength = (int) Math.floor(RangeData.getRangedStrength(p));
base += (2.5 * rangeLevel / 10) + (rangeStrength / 10) + (2 + addVoidBonus(p));
return (int) Math.floor(base);
}
}