RuneHive-Game
Loading...
Searching...
No Matches
Hydra.java
Go to the documentation of this file.
1package com.runehive.game.world.entity.combat.strategy.npc.boss;
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.Task;
8import com.runehive.game.world.World;
9import com.runehive.game.world.entity.combat.attack.FightType;
10import com.runehive.game.world.entity.combat.hit.CombatHit;
11import com.runehive.game.world.entity.combat.hit.Hit;
12import com.runehive.game.world.entity.combat.strategy.CombatStrategy;
13import com.runehive.game.world.entity.combat.strategy.npc.MultiStrategy;
14import com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy;
15import com.runehive.game.world.entity.combat.strategy.npc.NpcRangedStrategy;
16import com.runehive.game.world.entity.mob.Mob;
17import com.runehive.game.world.entity.mob.npc.Npc;
18import com.runehive.game.world.position.Position;
19import com.runehive.util.RandomUtils;
20import com.runehive.util.Utility;
21
22import java.util.*;
23
24import static com.runehive.game.world.entity.combat.CombatUtil.createStrategyArray;
25import static com.runehive.game.world.entity.combat.CombatUtil.randomStrategy;
26import static com.runehive.game.world.entity.combat.projectile.CombatProjectile.getDefinition;
27
28public class Hydra extends MultiStrategy {
29 private static final Magic MAGIC = new Magic();
30 private static final Ranged RANGED = new Ranged();
31 private static final CombatStrategy<Npc>[] STRATEGIES = createStrategyArray(MAGIC, RANGED);
32 private int attackCount = 0;
33
34 public Hydra() {
35 this.currentStrategy = randomStrategy(STRATEGIES);
36 }
37
41
42 @Override
43 public void hit(Npc attacker, Mob defender, Hit hit) {
44 super.hit(attacker, defender, hit);
46 if (attackCount > 2) {
47 if (Utility.hasOneOutOf(30)) {
48 poisonAttack(attacker, defender);
49 }
51 attackCount = 0;
52 }
53 }
54
55 private static void poisonAttack(Npc attacker, Mob defender) {
56 Position[] boundaries = Utility.getInnerBoundaries(defender.getPosition(), 5, 5);
57 List<Position> positions = Arrays.asList(boundaries);
58 Collections.shuffle(positions);
59
60 attacker.animate(new Animation(8262, UpdatePriority.VERY_HIGH));
61 World.sendProjectile(attacker, defender, new Projectile(1644, 37, 15, 42, 0));
62 attacker.attributes.set("HYDRA_POISON", Boolean.TRUE);
63
64 World.schedule(poisonTask(attacker, defender, defender.getPosition()));
65 World.schedule(poisonTask(attacker, defender, positions.get(0)));
66 World.schedule(poisonTask(attacker, defender, positions.get(1)));
67 }
68
69
70 private static Task poisonTask(Npc attacker, Mob defender, Position position) {
71 return new Task(1) {
72 int count = 0;
73
74 @Override
75 protected void execute() {
76 if (count == 0) {
78 } else if (count == 18) {
79 attacker.attributes.set("HYDRA_POISON", Boolean.FALSE);
80 cancel();
81 return;
82 }
83 if (count % 2 == 0 && defender.getPosition().equals(position)) {
84 var damage = 4;
85 if (defender.getPlayer().getPoisonImmunity().get() > 0) {
86 damage = Utility.random(1, 3, true);
87 defender.getPlayer().message("Your poison immunity reduces the damage taken from the acidic pool.");
88 }
89 defender.writeDamage(new Hit(damage));
90 }
91 count++;
92 }
93 };
94 }
95
96 private static class Magic extends NpcMagicStrategy {
97 private static final Animation ANIMATION = new Animation(8263, UpdatePriority.HIGH);
98
99 private Magic() {
100 super(getDefinition("Hydra Magic"));
101 }
102
103 @Override
104 public CombatHit[] getHits(Npc attacker, Mob defender) {
105 CombatHit combatHit = nextMagicHit(attacker, defender, 22);
106 combatHit.setAccurate(true);
107 return new CombatHit[]{combatHit};
108 }
109
110 @Override
111 public Animation getAttackAnimation(Npc attacker, Mob defender) {
112 return ANIMATION;
113 }
114
115 @Override
116 public int getAttackDistance(Npc attacker, FightType fightType) {
117 return 10;
118 }
119 }
120
121 private static class Ranged extends NpcRangedStrategy {
122 private static final Animation ANIMATION = new Animation(8261, UpdatePriority.HIGH);
123
124 private Ranged() {
125 super(getDefinition("Hydra Ranged"));
126 }
127
128 @Override
129 public CombatHit[] getHits(Npc attacker, Mob defender) {
130 return new CombatHit[]{nextRangedHit(attacker, defender, 22)};
131 }
132
133 @Override
134 public Animation getAttackAnimation(Npc attacker, Mob defender) {
135 return ANIMATION;
136 }
137
138 @Override
139 public int getAttackDistance(Npc attacker, FightType fightType) {
140 return 10;
141 }
142 }
143
144}
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
static void sendProjectile(Projectile projectile, Position position, int instance, int lock, byte offsetX, byte offsetY)
Sends a world projectile.
Definition World.java:295
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)
Animation getAttackAnimation(Npc attacker, Mob defender)
Definition Hydra.java:111
int getAttackDistance(Npc attacker, FightType fightType)
Definition Hydra.java:116
int getAttackDistance(Npc attacker, FightType fightType)
Definition Hydra.java:139
static Task poisonTask(Npc attacker, Mob defender, Position position)
Definition Hydra.java:70
static void poisonAttack(Npc attacker, Mob defender)
Definition Hydra.java:55
void hit(Npc attacker, Mob defender, Hit hit)
Definition Hydra.java:43
static final CombatStrategy< Npc >[] STRATEGIES
Definition Hydra.java:31
Handles the mob class.
Definition Mob.java:66
final GenericAttributes attributes
Definition Mob.java:95
Represents a non-player character in the in-game world.
Definition Npc.java:29
Represents a single tile on the game world.
Definition Position.java:14
int get()
Gets the value present within this counter.
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
static boolean hasOneOutOf(double chance)
Definition Utility.java:257
static Position[] getInnerBoundaries(Position position, int width, int length)
Definition Utility.java:621
public< K, E > void set(K key, E attribute)
Sets a generic attribute.
Represents different priorities for updating.
The enumerated type whose elements represent the fighting types.