RuneHive-Game
Loading...
Searching...
No Matches
JalTokJad.java
Go to the documentation of this file.
1package com.runehive.content.activity.infernomobs;
2
3import com.runehive.game.Animation;
4import com.runehive.game.Graphic;
5import com.runehive.game.UpdatePriority;
6import com.runehive.game.task.Task;
7import com.runehive.game.task.impl.CeillingCollapseTask;
8import com.runehive.game.world.World;
9import com.runehive.game.world.entity.combat.CombatType;
10import com.runehive.game.world.entity.combat.attack.FightType;
11import com.runehive.game.world.entity.combat.hit.CombatHit;
12import com.runehive.game.world.entity.combat.hit.Hit;
13import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
14import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
15import com.runehive.game.world.entity.combat.strategy.npc.MultiStrategy;
16import com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
17import com.runehive.game.world.entity.combat.strategy.npc.NpcMeleeStrategy;
18import com.runehive.game.world.entity.combat.strategy.npc.NpcRangedStrategy;
19import com.runehive.game.world.entity.mob.Mob;
20import com.runehive.game.world.entity.mob.movement.waypoint.Waypoint;
21import com.runehive.game.world.entity.mob.npc.Npc;
22import com.runehive.game.world.entity.mob.player.Player;
23import com.runehive.game.world.entity.mob.prayer.Prayer;
24import com.runehive.game.world.position.Position;
25import com.runehive.util.RandomUtils;
26import com.runehive.util.Stopwatch;
27import com.runehive.util.Utility;
28
29import java.util.concurrent.TimeUnit;
30
31import static com.runehive.game.world.entity.combat.CombatUtil.createStrategyArray;
32import static com.runehive.game.world.entity.combat.CombatUtil.randomStrategy;
33import static com.runehive.game.world.entity.combat.projectile.CombatProjectile.getDefinition;
34
35public class JalTokJad extends MultiStrategy {
36 private static RangedAttack RANGED = new RangedAttack();
37 private static MagicAttack MAGIC = new MagicAttack();
38 private static MeleeAttack MELEE = new MeleeAttack();
39 private static final CombatStrategy<Npc>[] FULL_STRATEGIES = createStrategyArray(RANGED, MAGIC, MELEE);
40 private static final CombatStrategy<Npc>[] NON_MELEE = createStrategyArray(RANGED, MAGIC);
41
42 public JalTokJad() {
43 currentStrategy = randomStrategy(NON_MELEE);
44 }
45
46 @Override
47 public boolean canAttack(Npc attacker, Mob defender) {
48 if (!currentStrategy.withinDistance(attacker, defender)) {
49 currentStrategy = randomStrategy(NON_MELEE);
50 }
51 return currentStrategy.canAttack(attacker, defender);
52 }
53
54 @Override
55 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
56 currentStrategy.block(attacker, defender, hit, combatType);
57 defender.getCombat().attack(attacker);
58 }
59
60 private boolean hasGuardians;
61 private static int OBJECT = 1;
62 public static int POS1 = 2274;
63 public static int POS2 = 5337;
64
65 @Override
66 public void hit(Npc attacker, Mob defender, Hit hit) {
67 super.hit(attacker, defender, hit);
68
69 if (!defender.isPlayer())
70 return;
71 Player player = defender.getPlayer();
72
73 if (currentStrategy.getCombatType().equals(CombatType.MELEE)
75 hit.setDamage(0);
76 } else if (currentStrategy.getCombatType().equals(CombatType.RANGED)
78 hit.setDamage(0);
79 } else if (currentStrategy.getCombatType().equals(CombatType.MAGIC)
81 hit.setDamage(0);
82 }
83
84 if (hasGuardians || attacker.getCurrentHealth() >= 175) {
85 return;
86 }
87 hasGuardians = true;
88
89 for (int i = 0; i <= 2; i++) {
91 Npc guardian = new Guardian(spawn, attacker);
92 guardian.register();
93 guardian.definition.setRespawnTime(-1);
94 guardian.walkExactlyTo(new Position(POS1, POS2, guardian.getHeight()), () -> {
95
96 World.sendGraphic(new Graphic(1460, true), guardian.getPosition());
97 defender.damage(new Hit(10 * guardian.getCurrentHealth() / guardian.getMaximumHealth()));
98 World.schedule(new CeillingCollapseTask(defender.getPlayer()));
99 });
100 }
101 }
102
103 @Override
104 public void finishOutgoing(Npc attacker, Mob defender) {
105 currentStrategy.finishOutgoing(attacker, defender);
106 if (NpcMeleeStrategy.get().withinDistance(attacker, defender)) {
107 currentStrategy = randomStrategy(FULL_STRATEGIES);
108 } else {
109 currentStrategy = randomStrategy(NON_MELEE);
110 }
111 }
112
113 @Override
114 public int modifyAccuracy(Npc attacker, Mob defender, int roll) {
115 return roll + 150_000;
116 }
117
118 private static class RangedAttack extends NpcRangedStrategy {
119
120 private final Animation ANIMATION = new Animation(7593, UpdatePriority.HIGH);
121
123 super(CombatProjectile.getDefinition("EMPTY"));
124 }
125
126 @Override
127 public void start(Npc attacker, Mob defender, Hit[] hits) {
128 attacker.animate(ANIMATION, true);
129 World.schedule(new Task(2) {
130 @Override
131 protected void execute() {
133 cancel();
134
135 World.schedule(new Task(1) {
136 @Override
137 protected void execute() {
138 cancel();
139 }
140 });
141 }
142 });
143 }
144
145 @Override
146 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
147 return 5;
148 }
149
150 @Override
151 public void hit(Npc attacker, Mob defender, Hit hit) {
152 }
153
154 @Override
155 public void attack(Npc attacker, Mob defender, Hit hit) {
156 }
157
158 @Override
159 public CombatHit[] getHits(Npc attacker, Mob defender) {
160 return new CombatHit[] { nextRangedHit(attacker, defender, 97, 2, 2) };
161 }
162
163 @Override
164 public Animation getAttackAnimation(Npc attacker, Mob defender) {
165 return ANIMATION;
166 }
167 }
168
169 private static class MagicAttack extends NpcMagicStrategy {
170 private final Animation ANIMATION = new Animation(7592, UpdatePriority.HIGH);
171
172 public MagicAttack() {
173 super(getDefinition("jal jad Magic"));
174 }
175
176 @Override
177 public CombatHit[] getHits(Npc attacker, Mob defender) {
178 CombatHit hit = nextMagicHit(attacker, defender, 97, 2, 2);
179 hit.setAccurate(true);
180 return new CombatHit[] { hit };
181 }
182
183 @Override
184 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
185 return 5;
186 }
187
188 public Animation getAttackAnimation(Npc attacker, Mob defender) {
189 return ANIMATION;
190 }
191 }
192
193 private class Guardian extends Npc {
194 private final Stopwatch lastHeal = new Stopwatch();
195
196 private Guardian(Position spawn, Npc healer) {
197 super(7705, spawn);
198 lastHeal.start();
199 setWaypoint(new Waypoint(this, healer) {
200 @Override
201 protected void onDestination() {
202 CombatProjectile.getDefinition("Scorpia guardian").getProjectile()
203 .ifPresent(projectile -> projectile.send(mob, healer));
204 lastHeal.reset();
205 lastHeal.start();
206 mob.animate(new Animation(2637));
207 healer.heal(4);
208 }
209 });
210 }
211
212 @Override
213 public void sequence() {
214 super.sequence();
215 long millis = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
216 if (millis > 15_000) {
217 unregister();
218 }
219 }
220 }
221
222 private static class MeleeAttack extends NpcMeleeStrategy {
223 private final Animation ANIMATION = new Animation(7590, UpdatePriority.HIGH);
224
225 @Override
226 public CombatHit[] getHits(Npc attacker, Mob defender) {
227 CombatHit hit = nextMeleeHit(attacker, defender, 97, 5, 2);
228 hit.setAccurate(true);
229 return new CombatHit[] { hit };
230 }
231
232 public Animation getAttackAnimation(Npc attacker, Mob defender) {
233 return ANIMATION;
234 }
235 }
236
237}
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
Animation getAttackAnimation(Npc attacker, Mob defender)
Animation getAttackAnimation(Npc attacker, Mob defender)
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
void start(Npc attacker, Mob defender, Hit[] hits)
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
static final CombatStrategy< Npc >[] FULL_STRATEGIES
void finishOutgoing(Npc attacker, Mob defender)
int modifyAccuracy(Npc attacker, Mob defender, int roll)
void hit(Npc attacker, Mob defender, Hit hit)
static final CombatStrategy< Npc >[] NON_MELEE
boolean canAttack(Npc attacker, Mob defender)
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
A game representing a cyclic unit of work.
Definition Task.java:11
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
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)
Handles the mob class.
Definition Mob.java:66
void setWaypoint(Waypoint waypoint)
Definition Mob.java:434
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
void walkExactlyTo(Position position)
Definition Mob.java:384
Represents a non-player character in the in-game world.
Definition Npc.java:29
Npc(int id, Position position)
Definition Npc.java:46
void register()
Registers an entity to the World.
Definition Npc.java:112
void unregister()
Unregisters an entity from the World.
Definition Npc.java:126
Combat< Npc > getCombat()
The combat of the mob.
Definition Npc.java:156
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 single tile on the game world.
Definition Position.java:14
A static-util class that provides additional functionality for generating pseudo-random numbers.
static< T > T random(T[] array)
Pseudo-randomly retrieves a element from array.
Handles miscellaneous methods.
Definition Utility.java:27
static Position[] getInnerBoundaries(Position position, int width, int length)
Definition Utility.java:621
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.