RuneHive-Game
Loading...
Searching...
No Matches
StoneGuardian.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.npc.boss;
2
3import com.runehive.content.bloodmoney.BloodMoneyChest;
4import com.runehive.game.Animation;
5import com.runehive.game.Graphic;
6import com.runehive.game.Projectile;
7import com.runehive.game.UpdatePriority;
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.Mob;
21import com.runehive.game.world.entity.mob.data.LockType;
22import com.runehive.game.world.entity.mob.npc.Npc;
23import com.runehive.game.world.entity.mob.player.Player;
24import com.runehive.game.world.entity.mob.prayer.Prayer;
25import com.runehive.game.world.position.Position;
26import com.runehive.util.RandomUtils;
27import com.runehive.util.Utility;
28
29import static com.runehive.game.world.entity.combat.CombatUtil.createStrategyArray;
30import static com.runehive.game.world.entity.combat.CombatUtil.randomStrategy;
31
32public class StoneGuardian extends MultiStrategy {
33
34 private static final Integer[] GUARDIAN_IDS = {8064, 8065, 8066};
35 private final static Transform TRANSFORM = new Transform();
36 private final static NpcMeleeStrategy MELEE = NpcMeleeStrategy.get();
37 private final static Magic MAGIC = new Magic();
38 private final static Ranged RANGED = new Ranged();
39 private static final BarrageAttack BARRAGE = new BarrageAttack();
40 private final static PrayerAttack PRAYER = new PrayerAttack();
41 private final static BoomAttack BOOM = new BoomAttack();
42
43 private static int nextForm(int id) {
45 }
46
47 @Override
48 public boolean canAttack(Npc attacker, Mob defender) {
49 if (!attacker.attributes.has("STONE_GUARDIAN_ATTACK")) {
50 attacker.attributes.put("STONE_GUARDIAN_ATTACK", 0);
51 }
52
53 if (!attacker.attributes.has("STONE_GUARDIAN_BLOCK")) {
54 attacker.attributes.put("STONE_GUARDIAN_BLOCK", 0);
55 }
56 int attackCount = attacker.attributes.get("STONE_GUARDIAN_ATTACK", Integer.class);
57 int blockCount = attacker.attributes.get("STONE_GUARDIAN_BLOCK", Integer.class);
58
59 if (attackCount >= 10 || blockCount >= 10) {
61 return true;
62 }
63
64 switch (attacker.id) {
65 case 8064: {
66 CombatStrategy<Npc>[] SPECIALS = createStrategyArray(MELEE, PRAYER, BARRAGE, BOOM);
67 currentStrategy = randomStrategy(SPECIALS);
68 break;
69 }
70 case 8065: {
71 CombatStrategy<Npc>[] SPECIALS = createStrategyArray(RANGED, PRAYER, BARRAGE, BOOM);
72 currentStrategy = randomStrategy(SPECIALS);
73 break;
74 }
75 case 8066: {
76 CombatStrategy<Npc>[] SPECIALS = createStrategyArray(MAGIC, PRAYER, BARRAGE, BOOM);
77 currentStrategy = randomStrategy(SPECIALS);
78 break;
79 }
80 }
81
82 return currentStrategy.canAttack(attacker, defender);
83 }
84
85 @Override
86 public void preDeath(Mob attacker, Npc defender, Hit hit) {
87 defender.speak("NOOOOOOOOOO!!!");
88 super.preDeath(attacker, defender, hit);
89 World.schedule(5, () -> {
90 defender.unregister();
92 });
93 }
94
95 @Override
96 public void hitsplat(Npc attacker, Mob defender, Hit hit) {
97 super.hitsplat(attacker, defender, hit);
98 int count = attacker.attributes.get("STONE_GUARDIAN_ATTACK", Integer.class);
99 attacker.attributes.put("STONE_GUARDIAN_ATTACK", count + 1);
100 }
101
102 @Override
103 public void block(Mob attacker, Npc defender, Hit hit, CombatType combatType) {
104 super.block(attacker, defender, hit, combatType);
105
106 if (!attacker.attributes.has("STON_GUARDIAN_BLOCK")) {
107 attacker.attributes.put("STON_GUARDIAN_BLOCK", 0);
108 return;
109 }
110
111 int count = attacker.attributes.get("STON_GUARDIAN_BLOCK", Integer.class);
112 attacker.attributes.put("STON_GUARDIAN_BLOCK", count + 1);
113
114 }
115
116 @Override
117 public int modifyAccuracy(Npc attacker, Mob defender, int roll) {
118 return roll + 10000;
119 }
120
121 @Override
122 public int modifyDefensive(Mob attacker, Npc defender, int roll) {
123 return roll + 500;
124 }
125
126 /** The transform strategy. */
127 private static class Transform extends NpcMagicStrategy {
129 super(CombatProjectile.getDefinition("EMPTY"));
130 }
131
132 @Override
133 public void hit(Npc attacker, Mob defender, Hit hit) {
134 }
135
136 @Override
137 public void attack(Npc attacker, Mob defender, Hit hit) {
138 }
139
140 @Override
141 public void start(Npc attacker, Mob defender, Hit[] hits) {
142 attacker.speak("AH!!! Give me a minute here...");
143 attacker.animate(new Animation(7924, UpdatePriority.VERY_HIGH));
144 attacker.graphic(new Graphic(1237, UpdatePriority.VERY_HIGH));
145 attacker.attributes.set("STONE_GUARDIAN_ATTACK", 0);
146 attacker.attributes.set("STONE_GUARDIAN_BLOCK", 0);
147 attacker.damageImmunity.reset(3_000);
148
149 World.schedule(5, () -> {
150 attacker.animate(new Animation(7927, UpdatePriority.VERY_HIGH));
151 attacker.speak("That feels better!");
152 attacker.transform(nextForm(attacker.id));
153 });
154 }
155
156 @Override
157 public CombatHit[] getHits(Npc attacker, Mob defender) {
158 CombatHit hit = nextMagicHit(attacker, defender, -1);
159 hit.setAccurate(false);
160 return new CombatHit[]{hit};
161 }
162
163 @Override
164 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
165 return 8;
166 }
167 }
168
169 private static class BoomAttack extends NpcMagicStrategy {
171 super(CombatProjectile.getDefinition("EMPTY"));
172 }
173
174 @Override
175 public void hit(Npc attacker, Mob defender, Hit hit) {
176 }
177
178 @Override
179 public void attack(Npc attacker, Mob defender, Hit hit) {
180 }
181
182 @Override
183 public void start(Npc attacker, Mob defender, Hit[] hits) {
184 attacker.speak("BOOM!");
185 attacker.animate(new Animation(7923, UpdatePriority.VERY_HIGH));
186 Position target = defender.getPosition();
187 Projectile projectile = new Projectile(1242, 10, 80, 45, 31);
188 projectile.send(attacker, target);
189
190 World.schedule(3, () -> {
191 for (Player player : attacker.getRegion().getPlayers(attacker.getHeight())) {
192 if (player != null && !player.isDead() && player.getPosition().equals(target)) {
193 int damage = player.prayer.isActive(Prayer.PROTECT_FROM_MELEE) ? 30 : 60;
194 player.writeDamage(new Hit(Utility.random(15, damage)));
195 player.graphic(new Graphic(659, false, UpdatePriority.VERY_HIGH));
196 }
197 }
198 });
199 }
200
201 @Override
202 public CombatHit[] getHits(Npc attacker, Mob defender) {
203 CombatHit hit = nextMagicHit(attacker, defender, -1);
204 hit.setAccurate(false);
205 return new CombatHit[]{hit};
206 }
207
208 @Override
209 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
210 return 4;
211 }
212 }
213
214 /** The barrage strategy. */
215 private static class BarrageAttack extends NpcMagicStrategy {
217 super(CombatProjectile.getDefinition("EMPTY"));
218 }
219
220 @Override
221 public void hit(Npc attacker, Mob defender, Hit hit) {
222 }
223
224 @Override
225 public void attack(Npc attacker, Mob defender, Hit hit) {
226 }
227
228 @Override
229 public void start(Npc attacker, Mob defender, Hit[] hits) {
230 attacker.speak("GET READY FOR A CHILL!!");
231 attacker.animate(new Animation(7923, UpdatePriority.VERY_HIGH));
232 Projectile projectile = new Projectile(1456, 10, 65, 45, 31);
233
234 CombatUtil.areaAction(defender, mob -> {
235 projectile.send(attacker, defender);
236
237 World.schedule(2, () -> {
238 if (mob.isPlayer() && !mob.locking.locked(LockType.FREEZE)) {
239 mob.getPlayer().message(true, "The stone guardian has frozen you!");
240 mob.graphic(new Graphic(369, false, UpdatePriority.VERY_HIGH));
241 mob.damage(nextMagicHit(attacker, defender, 30));
242 mob.locking.lock(25, LockType.FREEZE);
243 mob.graphic(new Graphic(1457, true, UpdatePriority.VERY_HIGH));
244 } else {
245 mob.writeDamage(new Hit(0));
246 }
247 });
248 });
249 }
250
251 @Override
252 public CombatHit[] getHits(Npc attacker, Mob defender) {
253 CombatHit hit = nextMagicHit(attacker, defender, -1);
254 hit.setAccurate(false);
255 return new CombatHit[]{hit};
256 }
257
258 @Override
259 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
260 return 4;
261 }
262 }
263
264 /** The prayer strategy. */
265 private static class PrayerAttack extends NpcMagicStrategy {
267 super(CombatProjectile.getDefinition("EMPTY"));
268 }
269
270 @Override
271 public void hit(Npc attacker, Mob defender, Hit hit) {
272 }
273
274 @Override
275 public void attack(Npc attacker, Mob defender, Hit hit) {
276 }
277
278 @Override
279 public void start(Npc attacker, Mob defender, Hit[] hits) {
280 attacker.speak("YOUR GODS CAN'T SAVE YOU!");
281 attacker.animate(new Animation(7923, UpdatePriority.VERY_HIGH));
282 Projectile projectile = new Projectile(1471, 10, 65, 45, 31);
283
284 CombatUtil.areaAction(defender, mob -> {
285 projectile.send(attacker, defender);
286
287 World.schedule(2, () -> {
288 if (mob.isPlayer() && mob.prayer.hasOverhead()) {
289 mob.prayer.deactivateOverhead();
290 mob.writeDamage(new Hit(Utility.random(15, 20)));
291 mob.getPlayer().message("The stone guardian has deactivated your overhead prayers!");
292 mob.graphic(new Graphic(1473, true, UpdatePriority.VERY_HIGH));
293 } else {
294 mob.writeDamage(new Hit(0));
295 }
296 });
297
298 });
299 }
300
301 @Override
302 public CombatHit[] getHits(Npc attacker, Mob defender) {
303 CombatHit hit = nextMagicHit(attacker, defender, -1);
304 hit.setAccurate(false);
305 return new CombatHit[]{hit};
306 }
307
308 @Override
309 public int getAttackDelay(Npc attacker, Mob defender, FightType fightType) {
310 return 4;
311 }
312 }
313
314 /** The magic strategy. */
315 private static class Magic extends NpcMagicStrategy {
316 public Magic() {
317 super(CombatProjectile.getDefinition("Stone guardian magic"));
318 }
319
320 @Override
321 public CombatHit[] getHits(Npc attacker, Mob defender) {
322 CombatHit hit = nextMagicHit(attacker, defender, 20);
323 hit.setAccurate(true);
324 return new CombatHit[]{hit};
325 }
326 }
327
328 /** The ranged strategy. */
329 private static class Ranged extends NpcRangedStrategy {
330 public Ranged() {
331 super(CombatProjectile.getDefinition("Stone guardian ranged"));
332 }
333
334 @Override
335 public CombatHit[] getHits(Npc attacker, Mob defender) {
336 CombatHit hit = nextMagicHit(attacker, defender, 20);
337 hit.setAccurate(true);
338 return new CombatHit[]{hit};
339 }
340 }
341}
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
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 nextMagicHit(T attacker, Mob defender)
void hit(T attacker, Mob defender, Hit hit)
Called when the attacking mob performs an attack on the defender.
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
int getAttackDelay(Npc attacker, Mob defender, FightType fightType)
void block(Mob attacker, Npc defender, Hit hit, CombatType combatType)
Handles the mob class.
Definition Mob.java:66
void speak(String forceChat)
Sets the mob's forced chat.
Definition Mob.java:127
void transform(int transformId)
Definition Mob.java:201
final GenericAttributes attributes
Definition Mob.java:95
Optional< Graphic > graphic
Definition Mob.java:91
Represents a non-player character in the in-game world.
Definition Npc.java:29
void unregister()
Unregisters an entity from the World.
Definition Npc.java:126
This class represents a character controlled by a player.
Definition Player.java:125
Represents a single tile on the game world.
Definition Position.java:14
Collection< Player > getPlayers(int height)
Definition Region.java:105
A static-util class that provides additional functionality for generating pseudo-random numbers.
static< T > T randomExclude(T[] array, T exclude)
Returns a pseudo-random int value between inclusive min and inclusive max excluding the specified num...
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
public< K, E > E get(K key)
Gets a generic attribute.
public< K, V > void put(K key, V value)
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
public< K > boolean has(K key)
Checks if a key is in the list of generic attribute.
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.