RuneHive-Game
Loading...
Searching...
No Matches
KrakenActivity.java
Go to the documentation of this file.
1package com.runehive.content.activity.impl.kraken;
2
3
4import com.runehive.Config;
5import com.runehive.content.achievement.AchievementHandler;
6import com.runehive.content.achievement.AchievementKey;
7import com.runehive.content.activity.Activity;
8import com.runehive.content.activity.ActivityType;
9import com.runehive.content.event.impl.ObjectInteractionEvent;
10import com.runehive.content.skill.impl.magic.teleport.Teleportation;
11import com.runehive.content.skill.impl.magic.teleport.TeleportationData;
12import com.runehive.game.Animation;
13import com.runehive.game.UpdatePriority;
14import com.runehive.game.world.World;
15import com.runehive.game.world.entity.mob.Mob;
16import com.runehive.game.world.entity.mob.npc.Npc;
17import com.runehive.game.world.entity.mob.npc.NpcDeath;
18import com.runehive.game.world.entity.mob.player.Player;
19import com.runehive.game.world.position.Area;
20import com.runehive.game.world.position.Position;
21import com.runehive.net.packet.out.SendMessage;
22import com.runehive.util.Utility;
23
24import java.util.HashSet;
25import java.util.Iterator;
26import java.util.Optional;
27import java.util.Set;
28
29/**
30 * Handles the Kraken boss.
31 *
32 * @author Daniel
33 */
34public class KrakenActivity extends Activity {
35
36 /** The player fighting the Kraken. */
37 private final Player player;
38
39 /** The Kraken npc. */
40 public Npc kraken = null;
41
42 /** The whirlpool activated count. */
43 public int count = 0;
44
45 /** Flag if kraken has been defeated. */
46 private boolean completed;
47
48 /** Set of npc tentacles. */
49 private Set<Npc> tentacles = new HashSet<>();
50
51 /** The Kraken activity listener. */
53
54 /** Holds all the monster spawn information. */
55 private static final int[][] SPAWN = {
56 {493, 2276, 10038},
57 {493, 2276, 10034},
58 {496, 2278, 10035},
59 {493, 2283, 10038},
60 {493, 2283, 10034},
61 };
62
63 /** Constructs a new <code>KrakenActivity</code>. */
65 super(1, instance);
66 this.player = player;
67 }
68
69 /** Creates a new Kraken activity. */
71 KrakenActivity minigame = new KrakenActivity(player, player.playerAssistant.instance());
72 minigame.add(player);
73 player.gameRecord.start();
74 minigame.count = 0;
75 return minigame;
76 }
77
78 /** Handles transforming a Npc. */
79 public void transform(Npc npc, int transform) {
81 npc.npcAssistant.login();
82 if (transform == 5535)
83 count++;
84 if (transform == 494)
85 npc.animate(new Animation(7135, UpdatePriority.HIGH));
86 npc.getCombat().attack(player);
87 }
88
89 @Override
90 public void onDeath(Mob mob) {
91 if (mob.isPlayer() && mob.equals(player)) {
92 player.send(new SendMessage("Better luck next time old chap!"));
93 cleanup();
94 remove(player);
95 return;
96 }
97 if (mob.isNpc() && mob.getNpc().id == 494) {
98 World.schedule(new NpcDeath(mob.getNpc(), () -> {
99 completed = true;
100 finish();
101 }));
102 return;
103 }
104 super.onDeath(mob);
105 }
106
107 @Override
108 public void add(Mob mob) {
109 super.add(mob);
110 if (mob.isNpc()) {
111 if (mob.getNpc().id == 496) {
112 kraken = mob.getNpc();
113 } else {
114 tentacles.add(mob.getNpc());
115 }
116 mob.locking.lock();
117 }
118 }
119
120 @Override
121 public void remove(Mob mob) {
122 if (!mob.isNpc()) {
123 super.remove(mob);
124 return;
125 }
126 int id = mob.getNpc().id;
127 if (id == 496) {
128 kraken = null;
129 } else {
130 tentacles.remove(mob.getNpc());
131 }
132 super.remove(mob);
133 }
134
135 @Override
136 protected void start() {
137 for (int[] aSPAWN : SPAWN) {
138 Npc npc = new Npc(aSPAWN[0], new Position(aSPAWN[1], aSPAWN[2]));
139 npc.owner = player;
140 add(npc);
141 }
142 player.face(kraken.getPosition());
143 pause();
144 }
145
146 @Override
147 public void onLogout(Player player) {
149 cleanup();
150 finish();
151 }
152
153 @Override
155 if (!Area.inKraken(player)) {
156 cleanup();
157 finish();
158 }
159 }
160
161 @Override
162 public boolean canTeleport(Player player) {
163 return true;
164 }
165
166 @Override
167 public void finish() {
168 cleanup();
169
170 if (completed) {
172 player.send(new SendMessage("Congratulations, you have killed the Kraken. Fight duration: @red@" + Utility.getTime(player.gameRecord.end(ActivityType.KRAKEN)) + "</col>."));
173 } else {
174 player.gameRecord.end(ActivityType.KRAKEN, false);
175 }
176
177 remove(player);
178 World.schedule(10, () -> {
179 if(Area.inKraken(player)) {
180 KrakenActivity.create(player);
181 }
182 });
183 }
184
185 @Override
186 public void cleanup() {
187 count = 0;
188 if (kraken != null && kraken.isRegistered())
189 kraken.unregister();
190 Iterator<Npc> it = tentacles.iterator();
191 while (it.hasNext()) {
192 Npc npc = it.next();
194 World.schedule(3, npc::unregister);
195 it.remove();
196 }
197 }
198
199 @Override
201 if (event.getObject().getId() != 538)
202 return false;
203 player.dialogueFactory.sendOption("Restart Kraken instance", () -> {
204 remove(player);
206 }, "Leave Kraken Instance", () -> {
207 remove(player);
209 }).execute();
210 return true;
211 }
212
213 @Override
215 return ActivityType.KRAKEN;
216 }
217
218 @Override
219 protected Optional<KrakenActivityListener> getListener() {
220 return Optional.of(listener);
221 }
222}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final Position DEFAULT_POSITION
The default, i.e.
Definition Config.java:197
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
Activity(int cooldown, int instance)
Constructs a new SequencedMinigame object.
Definition Activity.java:55
int instance
The activity instance level.
Definition Activity.java:46
final void pause()
Sets the cooldown flag to PAUSE.
void onLogout(Player player)
Called when the player logs out.
KrakenActivity(Player player, int instance)
Constructs a new KrakenActivity.
void onRegionChange(Player player)
Called when the player changes region.
static final int[][] SPAWN
Holds all the monster spawn information.
void cleanup()
Cleans up the activity when finished.
final KrakenActivityListener listener
The Kraken activity listener.
void onDeath(Mob mob)
Called when the player die.
void transform(Npc npc, int transform)
Handles transforming a Npc.
boolean completed
Flag if kraken has been defeated.
static KrakenActivity create(Player player)
Creates a new Kraken activity.
final Player player
The player fighting the Kraken.
Optional< KrakenActivityListener > getListener()
Gets an Optional of the ActivityListener for this activity.
boolean clickObject(Player player, ObjectInteractionEvent event)
boolean canTeleport(Player player)
Called when the player attempts to teleport.
static boolean teleport(Player player, Position position)
static void activateOverride(Mob mob, Position position, TeleportationData teleport)
Class that models a single animation used by an entity.
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)
Handles the mob class.
Definition Mob.java:66
void transform(int transformId)
Definition Mob.java:201
final boolean isNpc()
Check if an entity is an npc.
Definition Mob.java:550
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
void login()
Handles initializing all the npc assistant methods on login.
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
This class represents a character controlled by a player.
Definition Player.java:125
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inKraken(Interactable entity)
Definition Area.java:237
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.
Handles miscellaneous methods.
Definition Utility.java:27
static String getTime()
Gets the current server time and formats it.
Definition Utility.java:141
Holds all activity types that are timed.
Represents different priorities for updating.