RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
RangeAccuracy.java
1package com.osroyale.game.world.entity.combat.accuracy;
2
3import com.osroyale.game.world.entity.combat.CombatType;
4import com.osroyale.game.world.entity.combat.FormulaUtils;
5import com.osroyale.game.world.entity.mob.Mob;
6import com.osroyale.game.world.entity.mob.npc.Npc;
7import com.osroyale.game.world.entity.mob.player.Player;
8import com.osroyale.game.world.entity.mob.prayer.Prayer;
9import com.osroyale.game.world.entity.skill.Skill;
10import com.osroyale.game.world.items.containers.equipment.Equipment;
11
12import java.security.SecureRandom;
13
50
51public class RangeAccuracy {
52
53 public static final SecureRandom srand = new SecureRandom();
54
55 public static boolean successful(Mob attacker, Mob defender) {
56 double attackRoll = getAttackRoll(attacker);
57 double defenceRoll = getDefenceRoll(defender);
58
59 double chance;
60 if (attackRoll > defenceRoll)
61 chance = 1D - (defenceRoll + 2D) / (2D * (attackRoll + 1D));
62 else
63 chance = attackRoll / (2D * (defenceRoll + 1D));
64
65 double roll = srand.nextDouble();
66
67
68 return chance > roll;
69 }
70
71 public static double getPrayerAttackBonus(Mob attacker) {
72 double prayerBonus = 1;
73 if (attacker.getStrategy().getCombatType().equals(CombatType.RANGED)) {
74 if (attacker.prayer.isActive(Prayer.SHARP_EYE))
75 prayerBonus *= 1.05D; // 5% range level boost
76 else if (attacker.prayer.isActive(Prayer.HAWK_EYE))
77 prayerBonus *= 1.10D; // 10% range level boost
78 else if (attacker.prayer.isActive(Prayer.EAGLE_EYE))
79 prayerBonus *= 1.15D; // 15% range level boost
80 else if (attacker.prayer.isActive(Prayer.RIGOUR))
81 prayerBonus *= 1.20D; // 20% range level boost
82 }
83 return prayerBonus;
84 }
85
86 public static double getPrayerDefenseBonus(Mob defender) {
87 double prayerBonus = 1;
88 if (defender.prayer.isActive(Prayer.RIGOUR)) {
89 prayerBonus *= 1.25D;
90 }
91 return prayerBonus;
92 }
93
94 public static double getEffectiveLevel(Mob attacker) {
95 double effectiveLevel = getRangeLevel(attacker);
96 if (attacker instanceof Player) {
97 effectiveLevel *= getPrayerAttackBonus(attacker);
98 effectiveLevel = Math.floor(effectiveLevel);
99
100 switch (attacker.getCombat().getFightType().getStyle()) {
101 case ACCURATE -> effectiveLevel += 3;
102 case CONTROLLED -> effectiveLevel += 1;
103 }
104 }
105 effectiveLevel += 8;
106
107 if (attacker instanceof Player player) {
108 if (FormulaUtils.voidRanger(player)) {
109 effectiveLevel *= 1.10;
110 }
111 }
112
113 return Math.floor(effectiveLevel);
114 }
115
116 public static int getRangeLevel(Mob attacker) {
117 int rangeLevel = 1;
118 if (attacker instanceof Npc npc) {
119 int[] skills = npc.definition.getSkills();
120 if (skills != null) {
121 rangeLevel = skills[Skill.RANGED];
122 }
123 } else {
124 rangeLevel = attacker.skills.getLevel(Skill.RANGED);
125 }
126 return rangeLevel;
127 }
128
129 public static int getRangeBonus(Mob attacker) {
130 return attacker.getBonus(Equipment.RANGED_OFFENSE);
131 }
132
133 public static int getDefenceBonus(Mob defender) {
134 return defender.getBonus(Equipment.RANGED_DEFENSE);
135 }
136
137 public static double getAttackRoll(Mob attacker) {
138 double effectiveLevel = getEffectiveLevel(attacker);
139 double bonus = getRangeBonus(attacker);
140
141 double roll = effectiveLevel * (bonus + 64);
142
143 if (attacker instanceof Player player) {
144 final Equipment equipment = player.equipment;
145 if (equipment.contains(25865)
146 || equipment.contains(25867)
147 || equipment.contains(25884)
148 || equipment.contains(25886)
149 || equipment.contains(25888)
150 || equipment.contains(25890)
151 || equipment.contains(25892)
152 || equipment.contains(25894)
153 || equipment.contains(25896)) {
154 if (equipment.contains(23971)) {
155 roll *= 1.05;
156 }
157 if (equipment.contains(23975)) {
158 roll *= 1.15;
159 }
160 if (equipment.contains(23975)) {
161 roll *= 1.10;
162 }
163 }
164 }
165
166 return Math.floor(roll);
167 }
168
169 public static double getDefenceRoll(Mob defender) {
170 double defenceLevel = defender.skills.getLevel(Skill.DEFENCE);
171 double defenceBonus = getDefenceBonus(defender);
172
173 if (defender instanceof Player) {
174 defenceLevel *= getPrayerDefenseBonus(defender);
175
176 switch (defender.getCombat().getFightType().getStyle()) {
177 case DEFENSIVE -> defenceLevel += 3;
178 case CONTROLLED -> defenceLevel += 1;
179 }
180 } else {
181 defenceLevel += 9;
182 }
183
184 return defenceLevel * (defenceBonus + 64);
185 }
186
187}
abstract< T extends Mob > CombatStrategy<? super T > getStrategy()
abstract Combat<? extends Mob > getCombat()