RuneHive-Game
Loading...
Searching...
No Matches
Justiciar.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.npc.boss.magearena;
2
3import com.runehive.game.Animation;
4import com.runehive.game.Graphic;
5import com.runehive.game.Projectile;
6import com.runehive.game.UpdatePriority;
7import com.runehive.game.task.impl.ForceMovementTask;
8import com.runehive.game.world.World;
9import com.runehive.game.world.entity.combat.CombatType;
10import com.runehive.game.world.entity.combat.CombatUtil;
11import com.runehive.game.world.entity.combat.attack.FightType;
12import com.runehive.game.world.entity.combat.hit.CombatHit;
13import com.runehive.game.world.entity.combat.hit.Hit;
14import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
15import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
16import com.runehive.game.world.entity.combat.strategy.npc.MultiStrategy;
17import com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
18import com.runehive.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
19import com.runehive.game.world.entity.combat.strategy.npc.NpcRangedStrategy;
20import com.runehive.game.world.entity.mob.Direction;
21import com.runehive.game.world.entity.mob.Mob;
22import com.runehive.game.world.entity.mob.npc.Npc;
23import com.runehive.game.world.entity.mob.player.ForceMovement;
24import com.runehive.game.world.pathfinding.path.SimplePathChecker;
25import com.runehive.game.world.position.Position;
26import com.runehive.net.packet.out.SendMessage;
27import com.runehive.util.RandomUtils;
28import com.runehive.util.Utility;
29
30import static com.runehive.game.world.entity.combat.CombatUtil.createStrategyArray;
31import static com.runehive.game.world.entity.combat.CombatUtil.randomStrategy;
32
33/**
34 * Handles Justiciar Combat Strategy
35 *
36 * @author TJ#5762
37 */
38public class Justiciar extends MultiStrategy {
39 private static Magic MAGIC = new Magic();
40 private static Melee MELEE = new Melee();
42 private static TeleGrab TELE_GRAB = new TeleGrab();
43
44 private static final CombatStrategy<Npc>[] FULL_STRATEGIES = createStrategyArray(NpcMeleeStrategy.get(), MAGIC,
46 private static final CombatStrategy<Npc>[] MAGIC_STRATEGIES = createStrategyArray(MAGIC, MAGIC, MAGIC, TELE_GRAB,
48 private static final CombatStrategy<Npc>[] NON_MELEE = createStrategyArray(MAGIC, MELEE, MELEE, MAGIC, MAGIC,
50
51 /** Constructs a new <code>Justiciar</code>. */
56
57 @Override
58 public boolean canAttack(Npc attacker, Mob defender) {
59 if (!currentStrategy.withinDistance(attacker, defender)) {
60 currentStrategy = randomStrategy(MAGIC_STRATEGIES);
61 currentStrategy = randomStrategy(NON_MELEE);
62 }
63 return currentStrategy.canAttack(attacker, defender);
64 }
65
66 @Override
67 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
68 currentStrategy.block(attacker, defender, hit, combatType);
69 defender.getCombat().attack(attacker);
70
71 if (!defender.getCombat().isAttacking()) {
72 defender.animate(new Animation(7962, UpdatePriority.VERY_HIGH));
73 defender.graphic(1196);
74 defender.graphic(481);
75 defender.speak("Night King, Lend me your powers for i am your faithful servant!");
76
77 CombatUtil.areaAction(attacker, 64, 18, mob -> {
78 if (RandomUtils.success(.65))
79 return;
80
81 World.schedule(2, () -> {
82 Position destination = Utility.randomElement(defender.boundaries);
83 World.sendGraphic(new Graphic(481), destination);
84 attacker.move(destination);
85
86 });
87 });
88 }
89 }
90
91 @Override
92 public void finishOutgoing(Npc attacker, Mob defender) {
93 currentStrategy.finishOutgoing(attacker, defender);
94 if (NpcMeleeStrategy.get().withinDistance(attacker, defender)) {
95 currentStrategy = randomStrategy(FULL_STRATEGIES);
96 } else {
97 currentStrategy = randomStrategy(MAGIC_STRATEGIES);
98 }
99 }
100
101 @Override
102 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
103 return attacker.definition.getAttackDelay();
104 }
105
106 private static class Melee extends NpcRangedStrategy {
107
108 public Melee() {
109 super(CombatProjectile.getDefinition("EMPTY"));
110 }
111
112 @Override
113 public void hit(Npc attacker, Mob defender, Hit hit) {
114 }
115
116 @Override
117 public void attack(Npc attacker, Mob defender, Hit hit) {
118 }
119
120 @Override
121 public void start(Npc attacker, Mob defender, Hit[] hits) {
122
123 attacker.animate(new Animation(7962, UpdatePriority.VERY_HIGH));
124 Projectile projectile = new Projectile(162, 50, 80, 85, 25);
125 CombatHit hit = nextMeleeHit(attacker, defender, 21);
126 defender.graphic(163);
127 CombatUtil.areaAction(attacker, 64, 18, mob -> {
128 projectile.send(attacker, defender);
129 mob.damage(nextMagicHit(attacker, defender, 35));
130 });
131
132 /*
133 * if (Utility.random(0, 8) == 1) { attacker.animate(new Animation(7965,
134 * UpdatePriority.VERY_HIGH)); attacker.graphic(new Graphic(1296,
135 * UpdatePriority.VERY_HIGH)); attacker.heal(50);
136 * attacker.speak("Time To HEAL!"); System.out.println("It executes!");
137 *
138 * }
139 */
140
141 }
142
143 @Override
144 public CombatHit[] getHits(Npc attacker, Mob defender) {
145 CombatHit hit = nextRangedHit(attacker, defender, 38);
146 hit.setAccurate(false);
147 return new CombatHit[] { hit };
148 }
149
150 @Override
151 public int modifyAccuracy(Npc attacker, Mob defender, int roll) {
152 return roll + 50_000;
153 }
154
155 }
156
157 /** Jisticiar magic strategy. */
158 private static class Magic extends NpcMagicStrategy {
159 public Magic() {
160 super(CombatProjectile.getDefinition("EMPTY"));
161 }
162
163 @Override
164 public void hit(Npc attacker, Mob defender, Hit hit) {
165 }
166
167 @Override
168 public void attack(Npc attacker, Mob defender, Hit hit) {
169 }
170
171 @Override
172 public void start(Npc attacker, Mob defender, Hit[] hits) {
173 Projectile projectile = new Projectile(393, 50, 80, 85, 25);
174 attacker.animate(new Animation(7853, UpdatePriority.VERY_HIGH));
175 CombatUtil.areaAction(attacker, 64, 18, mob -> {
176 projectile.send(attacker, defender);
177 defender.graphic(157);
178 mob.damage(nextMagicHit(attacker, defender, 35));
179
180 });
181
182 if (Utility.random(0, 20) == 1) {
183 attacker.animate(new Animation(7965, UpdatePriority.VERY_HIGH));
184 attacker.graphic(new Graphic(1296, UpdatePriority.VERY_HIGH));
185 attacker.heal(130);
186 attacker.speak("Time To HEAL!");
187
188 }
189
190 }
191
192 @Override
193 public CombatHit[] getHits(Npc attacker, Mob defender) {
194 CombatHit hit = nextMagicHit(attacker, defender, 38);
195 hit.setAccurate(false);
196 return new CombatHit[] { hit };
197 }
198
199 @Override
200 public int modifyAccuracy(Npc attacker, Mob defender, int roll) {
201 return roll + 50_000;
202 }
203 }
204
205 private static class TeleGrab extends NpcMagicStrategy {
207 super(CombatProjectile.getDefinition("EMPTY"));
208 }
209
210 @Override
211 public void hit(Npc attacker, Mob defender, Hit hit) {
212 }
213
214 @Override
215 public void attack(Npc attacker, Mob defender, Hit hit) {
216 }
217
218 @Override
219 public void start(Npc attacker, Mob defender, Hit[] hits) {
220
221 attacker.animate(new Animation(7964, UpdatePriority.VERY_HIGH));
222 Projectile projectile = new Projectile(1479, 50, 80, 85, 25);
223 projectile.send(attacker, defender);
224 defender.damage(new Hit(Utility.random(20, 50)));
225 attacker.speak("I AM A DECENDENT OF HELL!");
226
227
228 }
229
230
231
232 @Override
233 public CombatHit[] getHits(Npc attacker, Mob defender) {
234 CombatHit hit = nextMagicHit(attacker, defender, 38);
235 hit.setAccurate(false);
236 return new CombatHit[] { hit };
237 }
238 }
239
240 private static class LightingRain extends NpcMagicStrategy {
242 super(CombatProjectile.getDefinition("Vorkath Frozen Special"));
243 }
244
245 @Override
246 public void hit(Npc attacker, Mob defender, Hit hit) {
247 }
248
249 @Override
250 public void attack(Npc attacker, Mob defender, Hit hit) {
251 }
252
253 @Override
254 public void start(Npc attacker, Mob defender, Hit[] hits) {
255 attacker.animate(new Animation(7962, UpdatePriority.VERY_HIGH));
256 World.sendProjectile(attacker, defender, new Projectile(395, 46, 80, 43, 31));
257 World.schedule(1, () -> {
258 if (defender.isPlayer()) {
259 Position current = defender.getPosition();
260 Position best = Utility.findBestInside(defender, attacker);
261 int dx = current.getX() - best.getX();
262 int dy = current.getY() - best.getY();
263 int y = dy / (dx == 0 ? dy : dx);
264
265 Position destination = current.transform(dx, y);
266 if (SimplePathChecker.checkLine(defender, destination)) {
267 }
268 defender.damage(new Hit(Utility.random(1, 3)));
269 defender.interact(attacker);
270
271 }
272 });
273 }
274
275 @Override
276 public CombatHit[] getHits(Npc attacker, Mob defender) {
277 CombatHit hit = nextMagicHit(attacker, defender, 38);
278 hit.setAccurate(false);
279 return new CombatHit[] { hit };
280 }
281 }
282}
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
static void sendGraphic(Graphic graphic, Position position, int instance)
Sends a graphic to the world.
Definition World.java:268
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Sends a world projectile.
Definition World.java:295
A collection of util methods and constants related to combat.
static void areaAction(Mob mob, Consumer< Mob > action)
Executes an action for mobs within a 3x3 square, including the source mob.
A wrapper for a Hit object, adding additional variables for hit and hitsplat delays.
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
final CombatHit nextRangedHit(T attacker, Mob defender)
final CombatHit nextMagicHit(T attacker, Mob defender)
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
Handles the mob class.
Definition Mob.java:66
void speak(String forceChat)
Sets the mob's forced chat.
Definition Mob.java:127
void interact(Mob mob)
Sets the mob interacting with another mob.
Definition Mob.java:278
void move(Position position)
Moves the mob to a set position.
Definition Mob.java:340
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
Optional< Graphic > graphic
Definition Mob.java:91
Represents a non-player character in the in-game world.
Definition Npc.java:29
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
Represents a PathFinder which is meant to be used to check projectiles passage in a straight line.
static boolean checkLine(Interactable source, Interactable target)
Represents a single tile on the game world.
Definition Position.java:14
int getY()
Gets the absolute y coordinate.
Definition Position.java:46
int getX()
Gets the absolute x coordinate.
Definition Position.java:41
Position transform(int diffX, int diffY, int diffZ)
Creates a new location based on this location.
A static-util class that provides additional functionality for generating pseudo-random numbers.
static boolean success(double value)
Determines if a pseudorandomly generated double rounded to two decimal places is below or equal to va...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static Position findBestInside(Interactable source, Interactable target)
Definition Utility.java:498
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.