RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
MagicAccuracyNpc.java
1package com.osroyale.game.world.entity.combat.accuracy;
2
3import com.osroyale.content.skill.impl.slayer.SlayerTask;
4import com.osroyale.game.world.entity.combat.CombatType;
5import com.osroyale.game.world.entity.combat.FormulaUtils;
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.util.Items;
12
13import java.security.SecureRandom;
14
50
51public class MagicAccuracyNpc {
52
53 public static final SecureRandom srand = new SecureRandom();
54
55 public static boolean successful(Mob attacker, Mob defender, CombatType style) {
56 double attackRoll = MagicAccuracy.getAttackRoll(attacker);//getAttackRoll(attacker, style, null); // XXX: task needs to be grabbed in the inverse direction (player attacking NPC)
57 double defenceRoll = MagicAccuracy.getDefenceRoll(defender);//getDefenceRoll(defender, style);
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 return chance > roll;
67 }
68
69 public static double getPrayerBonus(Mob attacker, CombatType style) {
70 double prayerBonus = 1D;
71 if (style == CombatType.MAGIC) {
72 if (attacker.prayer.isActive(Prayer.MYSTIC_WILL))
73 prayerBonus *= 1.05D; // 5% magic level boost
74 else if (attacker.prayer.isActive(Prayer.MYSTIC_LORE))
75 prayerBonus *= 1.10D; // 10% magic level boost
76 else if (attacker.prayer.isActive(Prayer.MYSTIC_MIGHT))
77 prayerBonus *= 1.15D; // 15% magic level boost
78 else if (attacker.prayer.isActive(Prayer.AUGURY))
79 prayerBonus *= 1.25D; // 25% magic level boost
80 }
81 return prayerBonus;
82 }
83
84 public static int getEquipmentBonus(Mob attacker, CombatType style, SlayerTask task) {
85 int bonus = 1;
86 if (attacker.isPlayer()) {
87 if (style == CombatType.MAGIC) {
88 bonus = attacker.getPlayer().getBonus(3);
89 }
90 }
91
92 if (attacker.isPlayer()) {
93 if (style.equals(CombatType.MAGIC)) {
94 if (FormulaUtils.voidMagic((Player) attacker)) {
95 bonus *= 1.45D; //45%
96 }
97 if (((Player) attacker).equipment.contains(27275)) {
98 bonus *= 3;
99 }
100 if (((Player) attacker).equipment.contains(Items.SALVE_AMULET)) {
101 bonus *= 1.10D;
102 }
103 if (attacker.isNpc()) {
104 if (((Player) attacker).equipment.contains(Items.SLAYER_HELMET)) {
105 bonus *= 1.05D;
106 }
107 if (((Player) attacker).equipment.contains(Items.BLACK_SLAYER_HELMET) || ((Player) attacker).equipment.contains(Items.GREEN_SLAYER_HELMET)
108 || ((Player) attacker).equipment.contains(Items.PURPLE_SLAYER_HELMET) || ((Player) attacker).equipment.contains(Items.RED_SLAYER_HELMET) || ((Player) attacker).equipment.contains(21888)) {
109 bonus *= 1.10D;
110 }
111 if (((Player) attacker).equipment.contains(19720)) {
112 bonus *= 1.05D;
113 }
114 if (((Player) attacker).equipment.contains(22555)) {
115 bonus *= 1.50D;
116 }
117 }
118 }
119 if (task != null && task.valid(task.getName())) {
120 if (((Player) attacker).equipment.contains(Items.SLAYER_HELMET)) {
121 bonus *= 1.15D;
122 }
123 if (((Player) attacker).equipment.contains(11865)) {
124 bonus *= 1.18D;
125 }
126 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)
127 || ((Player) attacker).equipment.contains(Items.RED_SLAYER_HELMET) || ((Player) attacker).equipment.contains(21888)) {
128 bonus *= 1.20D;
129 }
130 }
131 }
132 //some of these are custom
133 return bonus;
134 }
135
136 public static int getMagicLevelNpc(Mob defender) {
137 return defender.getNpc().definition.getSkills()[6];
138 }
139
140 public static int getMagicDefenceLevelNpc(Mob defender, CombatType style) {
141 int bonus = 0;
142 if (defender instanceof Npc npc) {
143 if (style == CombatType.MAGIC) {
144 bonus = npc.getBonus(8);
145 }
146 }
147 return bonus + 64;
148 }
149
150 public static double getEffectiveLevelDefender(Mob defender) {
151 return getMagicLevelNpc(defender);
152 }
153
154 public static double getDefenceRoll(Mob defender, CombatType style) {
155 return Math.floor((getEffectiveLevelDefender(defender) + 9) * (getMagicDefenceLevelNpc(defender, style) + 64));
156 }
157
158 public static int getMagicLevel(Mob attacker) {
159 return attacker.skills.getLevel(Skill.MAGIC);
160 }
161
162 public static double getEffectiveLevelAttacker(Mob attacker, CombatType style) {
163 return getMagicLevel(attacker) * (getPrayerBonus(attacker, style) + 9D);
164 }
165
166 public static double getAttackRoll(Mob attacker, CombatType style, SlayerTask task) {
167 return Math.round(getEffectiveLevelAttacker(attacker, style) * (getEquipmentBonus(attacker, style, task)) + 64D);
168 }
169}
170