RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
RangeAccuracyNpc.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.combat.attack.FightStyle;
6import com.osroyale.game.world.entity.mob.Mob;
7import com.osroyale.game.world.entity.mob.npc.Npc;
8import com.osroyale.game.world.entity.mob.player.Player;
9import com.osroyale.game.world.entity.mob.prayer.Prayer;
10import com.osroyale.game.world.entity.skill.Skill;
11import com.osroyale.game.world.items.Item;
12import com.osroyale.game.world.position.Area;
13import com.osroyale.util.Items;
14
15import java.security.SecureRandom;
16
17
55
56public class RangeAccuracyNpc {
57 public static final SecureRandom srand = new SecureRandom();
58
59 public static boolean successful(Mob attacker, Mob defender, CombatType style) {
60 double attackBonus = RangeAccuracy.getAttackRoll(attacker);//getAttackRoll(attacker, defender, style);
61 double defenceBonus = RangeAccuracy.getDefenceRoll(defender);//getDefenceRoll(defender, style);
62 double successfulRoll;
63 double selectedChance = srand.nextDouble();
64
65 if (attackBonus > defenceBonus)
66 successfulRoll = 1D - (defenceBonus + 2D) / (2D * (attackBonus + 1D));
67 else
68 successfulRoll = attackBonus / (2D * (defenceBonus + 1D));
69
70
71 return successfulRoll > selectedChance;
72 }
73
74 public static double getPrayerAttackBonus(Mob attacker) {
75 double prayerBonus = 1;
76 if (attacker.getStrategy().getCombatType().equals(CombatType.RANGED)) {
77 if (attacker.prayer.isActive(Prayer.SHARP_EYE))
78 prayerBonus *= 1.05D; // 5% range level boost
79 else if (attacker.prayer.isActive(Prayer.HAWK_EYE))
80 prayerBonus *= 1.10D; // 10% range level boost
81 else if (attacker.prayer.isActive(Prayer.EAGLE_EYE))
82 prayerBonus *= 1.15D; // 15% range level boost
83 else if (attacker.prayer.isActive(Prayer.RIGOUR))
84 prayerBonus *= 1.20D; // 20% range level boost
85 }
86 return prayerBonus;
87 }
88
89 public static int getDefenceNpc(Mob defender) {
90 return defender.getNpc().definition.getSkills()[1];
91 }
92
93 public static double getEffectiveRanged(Mob attacker, CombatType style) {
94 double effectiveLevel = Math.floor(getRangeLevel(attacker)) * getPrayerAttackBonus(attacker);
95 FightStyle fightStyle = attacker.getCombat().getFightType().getStyle();
96 switch (fightStyle) {
97 case ACCURATE:
98 effectiveLevel += 3.0D;
99 break;
100 }
101
102 effectiveLevel += 8;
103
104 if(attacker.isPlayer()) {
105 if (style.equals(CombatType.RANGED)) {
106 if (FormulaUtils.voidRanger((Player) attacker)) {
107 effectiveLevel *= 1.10D;
108 effectiveLevel = Math.floor(effectiveLevel);
109 }
110 }
111 if (((Player) attacker).equipment.contains(Items.SALVE_AMULET)) {
112 effectiveLevel *= 1.10D;
113 }//END OF UNDEAD
114 if (Area.inWilderness(attacker)) {
115 if (((Player) attacker).equipment.contains(22550)) {
116 effectiveLevel *= 1.50D;
117 }
118 }//END OF WILDERNESS BUFFS
119 if (attacker.isNpc()) {
120 if (((Player) attacker).equipment.contains(Items.SLAYER_HELMET)) {
121 effectiveLevel *= 1.05D;
122 }
123 if (((Player) attacker).equipment.contains(Items.BLACK_SLAYER_HELMET) || ((Player) attacker).equipment.contains(Items.GREEN_SLAYER_HELMET) || ((Player) attacker).equipment.contains(Items.PURPLE_SLAYER_HELMET) || ((Player) attacker).equipment.contains(Items.RED_SLAYER_HELMET) || ((Player) attacker).equipment.contains(21888)) {
124 effectiveLevel *= 1.10D;
125 }
126
127 }
128 }
129 return Math.floor(effectiveLevel);
130 }
131
132 public static double getEffectiveLevelDefender(Mob defender) {
133 return getDefenceNpc(defender) + 9;
134 }
135
136 public static int getRangeLevel(Mob attacker) {
137 int rangeLevel = 1;
138 if (attacker instanceof Npc npc) {
139 if (npc.definition.getSkills() != null)
140 rangeLevel = npc.definition.getSkills()[4];
141 } else {
142 rangeLevel = attacker.skills.getLevel(Skill.RANGED);
143 }
144 return rangeLevel;
145 }
146
147 public static double twistedBowBonus(Mob attacker, Mob defender) {
148 double bonus = 1;
149 double magicLevel = 1;
150 int getMagicLevel = defender.skills.getMaxLevel(Skill.MAGIC);
151 Player player = (Player) attacker;
152 final Item weapon = player.equipment.getWeapon();
153 if (weapon != null) {
154 if (player.equipment.contains(20997)) {
155 if (attacker.isPlayer()) {
156 if (defender instanceof Npc n) {
157 if (n.definition.getSkills() != null)
158 magicLevel = defender.skills.getMaxLevel(Skill.MAGIC) > 350 ? 350 :defender.skills.getMaxLevel(Skill.MAGIC) > 250D ? 250D : defender.skills.getMaxLevel(Skill.MAGIC);
159 } else {
160 magicLevel = getMagicLevel;
161 }
162 bonus += ((140 + (((10 * 3) * magicLevel) - 10) / 100D) - ((((3 * magicLevel) - 100D) * 2)) / 100D);
163 if (bonus > 2.4D)
164 bonus = (int) 2.4;
165 }
166 }
167 }
168 return bonus;
169 }
170
171 public static int getGearAttackBonus(Mob attacker, Mob defender, CombatType style) {
172 int bonus = 1;
173 if (style == CombatType.RANGED) {
174 bonus = attacker.getBonus(4);
175 }
176 if (attacker.getPlayer().equipment.contains(20997)) {
177 bonus *= twistedBowBonus(attacker, defender);
178 }
179 return bonus;
180 }
181
182 public static int getRangeDefenceLevelNpc(Mob defender, CombatType style) {
183 int bonus = 1;
184 if (defender instanceof Npc) {
185 if (style == CombatType.RANGED) {
186 bonus = defender.getNpc().getBonus(9);
187 }
188 }
189 return bonus;
190 }
191
192 public static double getAttackRoll(Mob attacker, Mob defender, CombatType style) {
193 double effectiveRangeLevel = getEffectiveRanged(attacker, style);
194
195 double equipmentRangeBonus = getGearAttackBonus(attacker, defender, style);
196
197 double maxRoll = effectiveRangeLevel * (equipmentRangeBonus);
198
199 return (int) (maxRoll);
200 }
201
202 public static double getDefenceRoll(Mob defender, CombatType style) {
203 double effectiveDefenceLevel = getEffectiveLevelDefender(defender);
204
205 int equipmentRangeBonus = getRangeDefenceLevelNpc(defender, style);
206
207 double maxRoll = effectiveDefenceLevel * (equipmentRangeBonus);
208
209 return (int) maxRoll;
210 }
211
212}
abstract< T extends Mob > CombatStrategy<? super T > getStrategy()
abstract Combat<? extends Mob > getCombat()