RuneHive-Game
Loading...
Searching...
No Matches
MagicAccuracyNpc.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.accuracy;
2
3import com.runehive.content.skill.impl.slayer.SlayerTask;
4import com.runehive.game.world.entity.combat.CombatType;
5import com.runehive.game.world.entity.combat.FormulaUtils;
6import com.runehive.game.world.entity.mob.Mob;
7import com.runehive.game.world.entity.mob.npc.Npc;
8import com.runehive.game.world.entity.mob.player.Player;
9import com.runehive.game.world.entity.mob.prayer.Prayer;
10import com.runehive.game.world.entity.skill.Skill;
11import com.runehive.util.Items;
12
13import java.security.SecureRandom;
14
15/**
16 * @Author Origin
17 * 2/22/2023
18 */
19public class MagicAccuracyNpc {
20
21 public static final SecureRandom srand = new SecureRandom();
22
23 public static boolean successful(Mob attacker, Mob defender, CombatType style) {
24 double attackRoll = MagicAccuracy.getAttackRoll(attacker);//getAttackRoll(attacker, style, null); // XXX: task needs to be grabbed in the inverse direction (player attacking NPC)
25 double defenceRoll = MagicAccuracy.getDefenceRoll(defender);//getDefenceRoll(defender, style);
26
27 double chance;
28 if (attackRoll > defenceRoll)
29 chance = 1D - (defenceRoll + 2D) / (2D * (attackRoll + 1D));
30 else
31 chance = attackRoll / (2D * (defenceRoll + 1D));
32
33 double roll = srand.nextDouble();
34 return chance > roll;
35 }
36
37 public static double getPrayerBonus(Mob attacker, CombatType style) {
38 double prayerBonus = 1D;
39 if (style == CombatType.MAGIC) {
40 if (attacker.prayer.isActive(Prayer.MYSTIC_WILL))
41 prayerBonus *= 1.05D; // 5% magic level boost
42 else if (attacker.prayer.isActive(Prayer.MYSTIC_LORE))
43 prayerBonus *= 1.10D; // 10% magic level boost
44 else if (attacker.prayer.isActive(Prayer.MYSTIC_MIGHT))
45 prayerBonus *= 1.15D; // 15% magic level boost
46 else if (attacker.prayer.isActive(Prayer.AUGURY))
47 prayerBonus *= 1.25D; // 25% magic level boost
48 }
49 return prayerBonus;
50 }
51
52 public static int getEquipmentBonus(Mob attacker, CombatType style, SlayerTask task) {
53 int bonus = 1;
54 if (attacker.isPlayer()) {
55 if (style == CombatType.MAGIC) {
56 bonus = attacker.getPlayer().getBonus(3);
57 }
58 }
59
60 if (attacker.isPlayer()) {
61 if (style.equals(CombatType.MAGIC)) {
62 if (FormulaUtils.voidMagic((Player) attacker)) {
63 bonus *= 1.45D; //45%
64 }
65 if (((Player) attacker).equipment.contains(27275)) {
66 bonus *= 3;
67 }
68 if (((Player) attacker).equipment.contains(Items.SALVE_AMULET)) {
69 bonus *= 1.10D;
70 }
71 if (attacker.isNpc()) {
72 if (((Player) attacker).equipment.contains(Items.SLAYER_HELMET)) {
73 bonus *= 1.05D;
74 }
75 if (((Player) attacker).equipment.contains(Items.BLACK_SLAYER_HELMET) || ((Player) attacker).equipment.contains(Items.GREEN_SLAYER_HELMET)
76 || ((Player) attacker).equipment.contains(Items.PURPLE_SLAYER_HELMET) || ((Player) attacker).equipment.contains(Items.RED_SLAYER_HELMET) || ((Player) attacker).equipment.contains(21888)) {
77 bonus *= 1.10D;
78 }
79 if (((Player) attacker).equipment.contains(19720)) {
80 bonus *= 1.05D;
81 }
82 if (((Player) attacker).equipment.contains(22555)) {
83 bonus *= 1.50D;
84 }
85 }
86 }
87 if (task != null && task.valid(task.getName())) {
88 if (((Player) attacker).equipment.contains(Items.SLAYER_HELMET)) {
89 bonus *= 1.15D;
90 }
91 if (((Player) attacker).equipment.contains(11865)) {
92 bonus *= 1.18D;
93 }
94 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)
95 || ((Player) attacker).equipment.contains(Items.RED_SLAYER_HELMET) || ((Player) attacker).equipment.contains(21888)) {
96 bonus *= 1.20D;
97 }
98 }
99 }
100 //some of these are custom
101 return bonus;
102 }
103
104 public static int getMagicLevelNpc(Mob defender) {
105 return defender.getNpc().definition.getSkills()[6];
106 }
107
108 public static int getMagicDefenceLevelNpc(Mob defender, CombatType style) {
109 int bonus = 0;
110 if (defender instanceof Npc npc) {
111 if (style == CombatType.MAGIC) {
112 bonus = npc.getBonus(8);
113 }
114 }
115 return bonus + 64;
116 }
117
118 public static double getEffectiveLevelDefender(Mob defender) {
119 return getMagicLevelNpc(defender);
120 }
121
122 public static double getDefenceRoll(Mob defender, CombatType style) {
123 return Math.floor((getEffectiveLevelDefender(defender) + 9) * (getMagicDefenceLevelNpc(defender, style) + 64));
124 }
125
126 public static int getMagicLevel(Mob attacker) {
127 return attacker.skills.getLevel(Skill.MAGIC);
128 }
129
130 public static double getEffectiveLevelAttacker(Mob attacker, CombatType style) {
131 return getMagicLevel(attacker) * (getPrayerBonus(attacker, style) + 9D);
132 }
133
134 public static double getAttackRoll(Mob attacker, CombatType style, SlayerTask task) {
135 return Math.round(getEffectiveLevelAttacker(attacker, style) * (getEquipmentBonus(attacker, style, task)) + 64D);
136 }
137}
138
static int getMagicDefenceLevelNpc(Mob defender, CombatType style)
static int getEquipmentBonus(Mob attacker, CombatType style, SlayerTask task)
static double getAttackRoll(Mob attacker, CombatType style, SlayerTask task)
static double getEffectiveLevelAttacker(Mob attacker, CombatType style)
static double getPrayerBonus(Mob attacker, CombatType style)
static double getDefenceRoll(Mob defender, CombatType style)
static boolean successful(Mob attacker, Mob defender, CombatType style)
Handles the mob class.
Definition Mob.java:66
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Represents a non-player character in the in-game world.
Definition Npc.java:29
This class represents a character controlled by a player.
Definition Player.java:125
boolean isActive(Prayer... prayers)
Checks if all given prayers are active.
Represents a trainable and usable skill.
Definition Skill.java:18
static final int MAGIC
The magic skill id.
Definition Skill.java:39
int getLevel(int id)
Gets the level of a skill.
static final int RED_SLAYER_HELMET
Definition Items.java:19652
static final int PURPLE_SLAYER_HELMET
Definition Items.java:21269
static final int SLAYER_HELMET
Definition Items.java:11869
static final int BLACK_SLAYER_HELMET
Definition Items.java:19644
static final int SALVE_AMULET
Definition Items.java:4086
static final int GREEN_SLAYER_HELMET
Definition Items.java:19648