RuneHive-Game
Loading...
Searching...
No Matches
ZulrahActivity.java
Go to the documentation of this file.
1package com.runehive.content.activity.impl.zulrah;
2
3
4import com.runehive.content.activity.Activity;
5import com.runehive.content.activity.ActivityDeathType;
6import com.runehive.content.activity.ActivityListener;
7import com.runehive.content.activity.ActivityType;
8import com.runehive.game.Animation;
9import com.runehive.game.Graphic;
10import com.runehive.game.world.World;
11import com.runehive.game.world.entity.combat.hit.Hit;
12import com.runehive.game.world.entity.combat.hit.Hitsplat;
13import com.runehive.game.world.entity.combat.strategy.npc.boss.Zulrah;
14import com.runehive.game.world.entity.mob.Mob;
15import com.runehive.game.world.entity.mob.npc.Npc;
16import com.runehive.game.world.entity.mob.npc.NpcDeath;
17import com.runehive.game.world.entity.mob.player.Player;
18import com.runehive.game.world.object.CustomGameObject;
19import com.runehive.game.world.object.GameObject;
20import com.runehive.game.world.position.Area;
21import com.runehive.game.world.position.Position;
22import com.runehive.net.packet.out.SendMessage;
23import com.runehive.util.RandomUtils;
24import com.runehive.util.Stopwatch;
25import com.runehive.util.Utility;
26
27import java.util.*;
28
29public class ZulrahActivity extends Activity {
30 /** The player instance for this activity. */
31 protected final Player player;
32
33 /** The Zulrah npc for this activity. */
34 protected Npc zulrah;
35
36 /** The activity stopwatch. */
38
39 /** The activity count. */
40 protected int count;
41
42 /** The current zulrah target position. */
44
45 /** The current zulrah phase. */
47
48 /** The currently spawned snakes. */
49 List<Npc> snakes = new ArrayList<>();
50
51 /** The currently spawned clouds. */
52 List<CustomGameObject> clouds = new ArrayList<>();
53
54 /** The combat listener for this activity. */
56
57 /** Constructs a new <code>ZulrahActivity</code>. */
59 super(1, instance);
60 this.player = player;
61 }
62
63 /** Creates a new Zulrah activity for the player. */
65 ZulrahActivity activity = new ZulrahActivity(player, player.playerAssistant.instance());
66 activity.add(player);
67 activity.resetCooldown();
68 player.gameRecord.start();
69 player.dialogueFactory.sendStatement("Welcome to Zulrah's shrine.").execute();
70 return activity;
71 }
72
73 /** Increments the activity count. */
74 void increment() {
75 count++;
76 }
77
78 /** Resets the Zulrah phase. */
79 void reset() {
80 player.getCombat().reset();
81 zulrah.getCombat().reset();
82 zulrah.resetFace();
83 stopwatch.reset();
84 count = -1;
85 }
86
87 /** Gets the next Zulrah form. */
88 int nextForm() {
90 if (next == 2042) {
91 ((Zulrah) zulrah.getStrategy()).setRanged();
92 } else if (next == 2043) {
93 ((Zulrah) zulrah.getStrategy()).setMelee();
94 } else if (next == 2044) {
95 ((Zulrah) zulrah.getStrategy()).setMagic();
96 }
97 return next;
98 }
99
100 /** Gets the next Zulrah phase. */
102 if (zulrah.id == 2043) {
103 return ZulrahPhase.ATTACKING;
104 }
105 Set<ZulrahPhase> states = new HashSet<>();
106 states.add(ZulrahPhase.ATTACKING);
108 states.add(ZulrahPhase.POISONOUS_CLOUD);
109 }
111 states.add(ZulrahPhase.SNAKELINGS);
112 }
113 return Utility.randomElement(states);
114 }
115
116 /** Gets the snakeling position. */
118 Set<Position> positions = new HashSet<>(Arrays.asList(ZulrahConstants.SNAKELINGS_POSITIONS));
119 for (Npc snake : snakes) {
120 if (positions.contains(snake.getPosition())) {
121 positions.remove(snake.getPosition());
122 }
123 }
124 return Utility.randomElement(positions);
125 }
126
127 /** Gets the cloud position. */
129 Set<Position> positions = new HashSet<>(Arrays.asList(ZulrahConstants.CLOUD_POSITIONS));
130 for (GameObject cloud : clouds) {
131 if (positions.contains(cloud.getPosition())) {
132 positions.remove(cloud.getPosition());
133 }
134 }
135 return Utility.randomElement(positions);
136 }
137
138 /** Handles the cloud effect. */
139 private void cloudEffect() {
140 for (CustomGameObject cloud : clouds) {
141 if (Utility.inside(cloud.getPosition(), 2, 2, player.getPosition(), 1, 1))
142 player.damage(new Hit(RandomUtils.inclusive(1, 5), Hitsplat.VENOM));
143 }
144 }
145
146 @Override
147 protected void start() {
148 cloudEffect();
149
150 boolean valid = zulrah != null;
151
152 if (valid && zulrah.isDead()) {
153 return;
154 }
155
156 phase.execute(this);
157
158 if (valid) {
159 zulrah.getCombat().cooldown(2);
160 }
161 }
162
163 @Override
164 public void finish() {
165 cleanup();
166 remove(player);
167 player.animate(Animation.RESET, true);
168 player.graphic(Graphic.RESET, true);
169 if (zulrah.isDead()) {
170 player.send(new SendMessage("Fight duration: @red@" + Utility.getTime(player.gameRecord.end(ActivityType.ZULRAH)) + "</col>."));
171 }
172 }
173
174 @Override
175 public void cleanup() {
176 if (zulrah != null) {
177 remove(zulrah);
178 }
179 for (Npc snakeling : snakes) {
180 remove(snakeling);
181 }
182 for (GameObject cloud : clouds) {
183 cloud.unregister();
184 }
185 snakes.clear();
186 clouds.clear();
187 }
188
189 @Override
191 if (!Area.inZulrah(player)) {
192 cleanup();
193 remove(player);
194 player.animate(Animation.RESET, true);
195 player.graphic(Graphic.RESET, true);
196
197 }
198 }
199
200 @Override
201 public void onDeath(Mob mob) {
202 if (mob.isNpc()) {
203 Npc npc = mob.getNpc();
204
205 if (mob.equals(zulrah)) {
206 World.schedule(new NpcDeath(npc, this::finish));
207 }
208
209 if (snakes.contains(npc)) {
210 World.schedule(new NpcDeath(npc, () -> {
211 remove(npc);
212 snakes.remove(npc);
213 }));
214 }
215
216 return;
217 }
218
219 super.onDeath(mob);
220 }
221
222 @Override
224 return ActivityType.ZULRAH;
225 }
226
227 @Override
228 public boolean canTeleport(Player player) {
229 return true;
230 }
231
232 @Override
236
237 @Override
238 protected Optional<? extends ActivityListener<? extends Activity>> getListener() {
239 return Optional.of(LISTENER);
240 }
241
242}
Activity(int cooldown, int instance)
Constructs a new SequencedMinigame object.
Definition Activity.java:55
int instance
The activity instance level.
Definition Activity.java:46
A combat listener that is applied to all mobs added to (or removed from) the activity.
ZulrahPhase nextPhase()
Gets the next Zulrah phase.
List< Npc > snakes
The currently spawned snakes.
static ZulrahActivity create(Player player)
Creates a new Zulrah activity for the player.
Position target
The current zulrah target position.
List< CustomGameObject > clouds
The currently spawned clouds.
void onRegionChange(Player player)
Called when the player changes region.
void cleanup()
Cleans up the activity when finished.
final Player player
The player instance for this activity.
ZulrahActivity(Player player, int instance)
Constructs a new ZulrahActivity.
boolean canTeleport(Player player)
Called when the player attempts to teleport.
Optional<? extends ActivityListener<? extends Activity > > getListener()
Gets an Optional of the ActivityListener for this activity.
final ActivityListener<? extends Activity > LISTENER
The combat listener for this activity.
Position getSnakelingPosition()
Gets the snakeling position.
void onDeath(Mob mob)
Called when the player die.
static final Position[] CLOUD_POSITIONS
All the possible positions zulrah can spawn his clouds for.
static final int MAXIMUM_CLOUDS
The maximum amount of clouds that zulrah can spawn at a time.
static final int MAXIMUM_SNAKELINGS
The maximum amount of snakelings that zulrah can spawn at a time.
static final Integer[] ZULRAH_IDS
The zulrah identifications.
Class that models a single animation used by an entity.
static final Animation RESET
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
static final Graphic RESET
Definition Graphic.java:17
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
abstract boolean equals(Object obj)
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
Handles the mob class.
Definition Mob.java:66
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
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
Represents a static game object loaded from the map fs.
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inZulrah(Interactable entity)
Definition Area.java:320
Represents a single tile on the game world.
Definition Position.java:14
The OutgoingPacket that sends a message to a Players chatbox in the client.
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...
static int inclusive(int min, int max)
Returns a pseudo-random int value between inclusive min and inclusive max.
static Stopwatch start()
Handles miscellaneous methods.
Definition Utility.java:27
static boolean inside(Interactable source, Interactable target)
Definition Utility.java:783
static< T > T randomElement(Collection< T > collection)
Picks a random element out of any array type.
Definition Utility.java:248
static String getTime()
Gets the current server time and formats it.
Definition Utility.java:141
Holds all activity types that are timed.
Handles all the activity phases for zulrah.