RuneHive-Game
Loading...
Searching...
No Matches
FightCaves.java
Go to the documentation of this file.
1package com.runehive.content.activity.impl.fightcaves;
2
3import com.runehive.content.ActivityLog;
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.content.activity.panel.ActivityPanel;
9import com.runehive.content.pet.PetData;
10import com.runehive.content.pet.Pets;
11import com.runehive.game.Animation;
12import com.runehive.game.Graphic;
13import com.runehive.game.world.World;
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.items.Item;
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.RandomUtils;
23import com.runehive.util.Utility;
24
25import java.util.HashSet;
26import java.util.Optional;
27import java.util.Set;
28
29/** @author Daniel */
30public class FightCaves extends Activity {
31
32 /** The player in the cave. */
33 private final Player player;
34
35 /** The activity completed flag. */
36 private boolean completed;
37
38 /** The amount of tokkuls the player has acquired. */
39 private int tokkuls;
40
41 /** A set of npcs in this activity. */
42 public final Set<Npc> npcs = new HashSet<>();
43
44 /** The current wave of this activity. */
46
47 /** The combat listener to add for all mobs. */
49
50 /** Constructs a new {@code FightCaves} object for a {@code player} and an {@code instance}. */
52 super(10, instance);
53 this.player = player;
54 }
55
56 public static FightCaves create(Player player) {
57 FightCaves minigame = new FightCaves(player, player.playerAssistant.instance());
58 player.move(new Position(2398, 5083, player.getHeight()));
59 ActivityPanel.update(player, -1, "Fight Caves", "Activity Completion:", "Good Luck, " + player.getName() + "!");
60 player.dialogueFactory.sendNpcChat(2180, "Welcome to the Fight Caves, #name.", "There are a total of 15 waves, Tz-Tok Jad being the last.", "Use your activity panel (bottom left tab) for wave information.", "Good luck!").execute();
61 minigame.add(player);
62 minigame.resetCooldown();
63 player.gameRecord.start();
64 return minigame;
65 }
66
67 /** Handles what happens to a mob when they die in the activity. */
68 void handleDeath(Mob dead) {
69 if (dead.isPlayer() && dead.equals(player)) {
70 finish();
71 return;
72 }
73 if (dead.isNpc() && npcs.contains(dead)) {
74 if (dead.id == 2191) {
75 remove(dead);
76 npcs.remove(dead);
77 for (int index = 0; index < 2; index++) {
78 Position position = new Position(dead.getX() + (index == 0 ? -1 : + 1), dead.getY(), dead.getHeight());
79 Npc TzKet = new Npc(2192, position);
80 add(TzKet);
81 npcs.add(TzKet);
82 TzKet.getCombat().attack(player);
83 }
84 return;
85 }
86
87 npcs.remove(dead);
88 remove(dead);
89 tokkuls += Utility.random(100, 500);
90 if (npcs.isEmpty()) {
91 wave = TzhaarData.WaveData.getNext(wave.ordinal());
92 if (wave == null) {
93 completed = true;
94 player.send(new SendMessage("You have finished the activity!"));
95 } else {
96 player.send(new SendMessage("The next wave will commence soon."));
97 }
99 return;
100 }
101 }
102 }
103
104 @Override
105 protected void start() {
106 if (wave == null) {
107 finish();
108 return;
109 }
110 if (player.locking.locked()) {
111 return;
112 }
113
114 Position spawn = new Position(2398, 5083, player.getHeight());
115 Position[] boundaries = Utility.getInnerBoundaries(spawn, 8, 8);
116
117 for (int id : wave.getMonster()) {
118 Npc npc = new Npc(id, RandomUtils.random(boundaries));
119 npc.owner = player;
120 add(npc);
121 npcs.add(npc);
122 npc.getCombat().attack(player);
123 }
124 pause();
125 }
126
127 @Override
128 public void onDeath(Mob mob) {
129 if (mob.isNpc()) {
130 World.schedule(new NpcDeath(mob.getNpc()));
131 } else if (mob.isPlayer()) {
132 mob.move(new Position(2438, 5169, 0));
133 mob.animate(Animation.RESET, true);
134 mob.graphic(Graphic.RESET, true);
135 finish();
136 }
137 }
138
139 @Override
140 public void finish() {
141 cleanup();
142 remove(player);
143
144 if (completed) {
145 long time = player.gameRecord.end(ActivityType.FIGHT_CAVES);
146 player.dialogueFactory.sendNpcChat(2180, "You have defeated Tztok-Jad, I am most impressed!", "Please accept this gift, young thug.").execute();
147 tokkuls += 3500;
148 player.inventory.addOrDrop(new Item(6570));
150 player.send(new SendMessage("You have completed the Fight Caves activity. Final time: @red@" + Utility.getTime(time) + "</col>."));
151 player.activityLogger.add(ActivityLog.FIGHT_CAVES);
152 return;
153 }
154
155 if (tokkuls <= 0)
156 tokkuls = 1;
157
158 player.inventory.addOrDrop(new Item(6529, tokkuls));
159 player.dialogueFactory.sendNpcChat(2180, "Better luck next time!", "Take these tokkuls as a reward.").execute();
160 }
161
162 @Override
163 public void cleanup() {
165 if (!npcs.isEmpty())
166 npcs.forEach(this::remove);
167 }
168
169 @Override
170 public void update() {
171 if (wave == null) {
172 ActivityPanel.update(player, 100, "Fight Caves", new Item(6570), "Congratulations, you have", "completed the Fight Caves", "activity!");
173 return;
174 }
175 int progress = (int)Utility.getPercentageAmount(wave.ordinal() + 1, TzhaarData.WaveData.values().length);
176 if (progress >= 100 && !completed)
177 progress = 99;
178 ActivityPanel.update(player, progress, "Fight Caves", new Item(6570), "</col>Wave: <col=FF5500>" + (wave.ordinal() + 1) + "/" + (TzhaarData.WaveData.values().length), "</col>Monsters Left: <col=FF5500>" + npcs.size(), "</col>Tokkuls Gained: <col=FF5500>" + Utility.formatDigits(tokkuls));
179 }
180
181 @Override
182 public boolean canTeleport(Player player) {
183 return true;
184 }
185
186 @Override
188 if (!Area.inFightCaves(player)) {
189 cleanup();
190 remove(player);
191 }
192 }
193
194 @Override
195 public void onLogout(Player player) {
196 finish();
197 remove(player);
198 }
199
200 @Override
202 return ActivityDeathType.SAFE;
203 }
204
205 @Override
208 }
209
210 @Override
211 public Optional<? extends ActivityListener<? extends Activity>> getListener() {
212 return Optional.of(listener);
213 }
214}
Activity(int cooldown, int instance)
Constructs a new SequencedMinigame object.
Definition Activity.java:55
final void resetCooldown()
Resets the remaining ticks to the cached cooldown ticks.
int instance
The activity instance level.
Definition Activity.java:46
final void pause()
Sets the cooldown flag to PAUSE.
void add(Mob mob)
Adds a mob to the activity.
boolean canTeleport(Player player)
Called when the player attempts to teleport.
void cleanup()
Cleans up the activity when finished.
FightCaves(Player player, int instance)
Constructs a new FightCaves object for a player and an instance.
final Set< Npc > npcs
A set of npcs in this activity.
void onRegionChange(Player player)
Called when the player changes region.
void start()
Starts the next activity stage.
final FightCavesListener listener
The combat listener to add for all mobs.
void handleDeath(Mob dead)
Handles what happens to a mob when they die in the activity.
TzhaarData.WaveData wave
The current wave of this activity.
void onDeath(Mob mob)
Called when the player die.
Optional<? extends ActivityListener<? extends Activity > > getListener()
Gets an Optional of the ActivityListener for this activity.
int tokkuls
The amount of tokkuls the player has acquired.
void onLogout(Player player)
Called when the player logs out.
boolean completed
The activity completed flag.
The FightCaves combat listener for all mobs in the activity.
static void update(Player player, int amount, String title, String footer, String... strings)
Sends all the information for the activity panel.
static void clear(Player player)
Clears the activity panel.
Handles spawning, rewarding and picking up of pets.
Definition Pets.java:27
static void onReward(Player player, int item, int chance)
Handles calculating the chance of a player receiving a skilling pet.
Definition Pets.java:33
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)
Handles the mob class.
Definition Mob.java:66
void move(Position position)
Moves the mob to a set position.
Definition Mob.java:340
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
Optional< Graphic > graphic
Definition Mob.java:91
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
The container class that represents an item that can be interacted with.
Definition Item.java:21
Handles checking if mobs are in a certain area.
Definition Area.java:13
static boolean inFightCaves(Interactable entity)
Definition Area.java:129
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 random(T[] array)
Pseudo-randomly retrieves a element from array.
Handles miscellaneous methods.
Definition Utility.java:27
static int random(int bound)
Definition Utility.java:239
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
static double getPercentageAmount(int progress, int total)
Gets a percentage amount.
Definition Utility.java:36
static Position[] getInnerBoundaries(Position position, int width, int length)
Definition Utility.java:621
static String getTime()
Gets the current server time and formats it.
Definition Utility.java:141
The activity log class.
Holds all activity types that are timed.
Holds the data for pets.
Definition PetData.java:14