RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
MagicAccuracy.java
1package com.osroyale.game.world.entity.combat.accuracy;
2
3import com.osroyale.game.world.entity.combat.FormulaUtils;
4import com.osroyale.game.world.entity.mob.Mob;
5import com.osroyale.game.world.entity.mob.npc.Npc;
6import com.osroyale.game.world.entity.mob.player.Player;
7import com.osroyale.game.world.entity.mob.prayer.Prayer;
8import com.osroyale.game.world.entity.skill.Skill;
9import com.osroyale.game.world.items.containers.equipment.Equipment;
10
11import java.security.SecureRandom;
12
48
49public class MagicAccuracy {
50
51 public static final SecureRandom srand = new SecureRandom();
52
53 public static boolean successful(Mob attacker, Mob defender) {
54 double attackRoll = getAttackRoll(attacker);
55 if (attacker instanceof Player player) {
56 if (FormulaUtils.voidMagic(player)) {
57 attackRoll *= 1.45;
58 }
59 }
60
61 double defenceRoll = getDefenceRoll(defender);
62
63 double chance;
64 if (attackRoll > defenceRoll)
65 chance = 1D - (defenceRoll + 2D) / (2D * (attackRoll + 1D));
66 else
67 chance = attackRoll / (2D * (defenceRoll + 1D));
68
69 double roll = srand.nextDouble();
70 return chance > roll;
71 }
72
73 public static int getAttackBonus(Mob attacker) {
74 return attacker.getBonus(Equipment.MAGIC_OFFENSE);
75 }
76
77 public static int getDefenceBonus(Mob defender) {
78 return defender.getBonus(Equipment.MAGIC_DEFENSE);
79 }
80
81 public static double getDefenceRoll(Mob defender) {
82 double magicLevel = getMagicLevel(defender);
83 double defenceBonus = getDefenceBonus(defender);
84
85 double effectiveLevel;
86 if (defender instanceof Player) {
87 magicLevel *= getPrayerBonusDefender(defender);
88
89 double defenceLevel = defender.skills.getLevel(Skill.DEFENCE);
90 switch (defender.getCombat().getFightType().getStyle()) {
91 case DEFENSIVE -> defenceLevel += 3;
92 case CONTROLLED -> defenceLevel += 1;
93 }
94
95 effectiveLevel = magicLevel * 0.7 + defenceLevel * 0.3 + 8;
96 } else {
97 effectiveLevel = magicLevel + 9;
98 }
99
100 return effectiveLevel * (defenceBonus + 64);
101 }
102
103 public static int getMagicLevel(Mob mob) {
104 int magicLevel = 1;
105 if (mob instanceof Npc npc) {
106 int[] skills = npc.definition.getSkills();
107 if (skills != null) {
108 magicLevel = skills[Skill.MAGIC];
109 }
110 } else {
111 magicLevel = mob.skills.getLevel(Skill.MAGIC);
112 }
113 return magicLevel;
114 }
115
116 public static double getPrayerBonus(Mob attacker) {
117 double prayerBonus = 1;
118 if (attacker.prayer.isActive(Prayer.MYSTIC_WILL))
119 prayerBonus *= 1.05D; // 5% magic level boost
120 else if (attacker.prayer.isActive(Prayer.MYSTIC_LORE))
121 prayerBonus *= 1.10D; // 10% magic level boost
122 else if (attacker.prayer.isActive(Prayer.MYSTIC_MIGHT))
123 prayerBonus *= 1.15D; // 15% magic level boost
124 else if (attacker.prayer.isActive(Prayer.AUGURY))
125 prayerBonus *= 1.25D; // 25% magic level boost
126 return prayerBonus;
127 }
128
129 public static double getPrayerBonusDefender(Mob defender) {
130 double prayerBonus = 1;
131 if (defender.prayer.isActive(Prayer.AUGURY))
132 prayerBonus *= 1.25D;
133 return prayerBonus;
134 }
135
136 public static double getAttackRoll(Mob attacker) {
137 double magicLevel = getMagicLevel(attacker);
138 double attackBonus = getAttackBonus(attacker);
139
140 double effectiveLevel;
141 if (attacker instanceof Player) {
142 effectiveLevel = magicLevel * getPrayerBonus(attacker) + 8;
143 } else {
144 effectiveLevel = magicLevel + 9;
145 }
146
147 return effectiveLevel * (attackBonus + 64);
148 }
149
150}
abstract Combat<? extends Mob > getCombat()