1package com.runehive.game.world.entity.combat.accuracy;
3import com.runehive.game.world.entity.combat.CombatType;
4import com.runehive.game.world.entity.combat.FormulaUtils;
5import com.runehive.game.world.entity.mob.Mob;
6import com.runehive.game.world.entity.mob.npc.Npc;
7import com.runehive.game.world.entity.mob.player.Player;
8import com.runehive.game.world.entity.mob.prayer.Prayer;
9import com.runehive.game.world.entity.skill.Skill;
10import com.runehive.game.world.items.containers.equipment.Equipment;
12import java.security.SecureRandom;
20 public static final SecureRandom
srand =
new SecureRandom();
27 if (attackRoll > defenceRoll)
28 chance = 1D - (defenceRoll + 2D) / (2D * (attackRoll + 1D));
30 chance = attackRoll / (2D * (defenceRoll + 1D));
32 double roll =
srand.nextDouble();
39 double prayerBonus = 1;
54 double prayerBonus = 1;
63 if (attacker instanceof
Player) {
65 effectiveLevel = Math.floor(effectiveLevel);
67 switch (attacker.
getCombat().getFightType().getStyle()) {
68 case ACCURATE -> effectiveLevel += 3;
69 case CONTROLLED -> effectiveLevel += 1;
74 if (attacker instanceof
Player player) {
76 effectiveLevel *= 1.10;
80 return Math.floor(effectiveLevel);
85 if (attacker instanceof
Npc npc) {
86 int[] skills = npc.definition.getSkills();
108 double roll = effectiveLevel * (bonus + 64);
110 if (attacker instanceof
Player player) {
111 final Equipment equipment = player.equipment;
133 return Math.floor(roll);
140 if (defender instanceof
Player) {
143 switch (defender.
getCombat().getFightType().getStyle()) {
144 case DEFENSIVE -> defenceLevel += 3;
145 case CONTROLLED -> defenceLevel += 1;
151 return defenceLevel * (defenceBonus + 64);
static int getDefenceBonus(Mob defender)
static final SecureRandom srand
static int getRangeBonus(Mob attacker)
static double getPrayerDefenseBonus(Mob defender)
static double getPrayerAttackBonus(Mob attacker)
static int getRangeLevel(Mob attacker)
static double getAttackRoll(Mob attacker)
static double getDefenceRoll(Mob defender)
static double getEffectiveLevel(Mob attacker)
static boolean successful(Mob attacker, Mob defender)
abstract< T extends Mob > CombatStrategy<? super T > getStrategy()
The combat strategy of the mob.
final SkillManager skills
abstract Combat<? extends Mob > getCombat()
The combat of the mob.
Represents a non-player character in the in-game world.
This class represents a character controlled by a player.
boolean isActive(Prayer... prayers)
Checks if all given prayers are active.
Represents a trainable and usable skill.
static final int RANGED
The ranged skill id.
static final int DEFENCE
The defence skill id.
int getLevel(int id)
Gets the level of a skill.
The container that manages the equipment for a player.
boolean contains(int[] bowsWithNoArrowsRequired)
static final int RANGED_OFFENSE
static final int RANGED_DEFENSE