RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
FightCaves.java
1package com.osroyale.content.activity.impl.fightcaves;
2
3import com.osroyale.content.ActivityLog;
4import com.osroyale.content.activity.Activity;
5import com.osroyale.content.activity.ActivityDeathType;
6import com.osroyale.content.activity.ActivityListener;
7import com.osroyale.content.activity.ActivityType;
8import com.osroyale.content.activity.panel.ActivityPanel;
9import com.osroyale.content.pet.PetData;
10import com.osroyale.content.pet.Pets;
11import com.osroyale.game.Animation;
12import com.osroyale.game.Graphic;
13import com.osroyale.game.world.World;
14import com.osroyale.game.world.entity.mob.Mob;
15import com.osroyale.game.world.entity.mob.npc.Npc;
16import com.osroyale.game.world.entity.mob.npc.NpcDeath;
17import com.osroyale.game.world.entity.mob.player.Player;
18import com.osroyale.game.world.items.Item;
19import com.osroyale.game.world.position.Area;
20import com.osroyale.game.world.position.Position;
21import com.osroyale.net.packet.out.SendMessage;
22import com.osroyale.util.RandomUtils;
23import com.osroyale.util.Utility;
24
25import java.util.HashSet;
26import java.util.Optional;
27import java.util.Set;
28
66
67public class FightCaves extends Activity {
68
70 private final Player player;
71
73 private boolean completed;
74
76 private int tokkuls;
77
79 public final Set<Npc> npcs = new HashSet<>();
80
82 private TzhaarData.WaveData wave = TzhaarData.WaveData.WAVE_1;
83
85 private final FightCavesListener listener = new FightCavesListener(this);
86
88 private FightCaves(Player player, int instance) {
89 super(10, instance);
90 this.player = player;
91 }
92
93 public static FightCaves create(Player player) {
94 FightCaves minigame = new FightCaves(player, player.playerAssistant.instance());
95 player.move(new Position(2398, 5083, player.getHeight()));
96 ActivityPanel.update(player, -1, "Fight Caves", "Activity Completion:", "Good Luck, " + player.getName() + "!");
97 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();
98 minigame.add(player);
99 minigame.resetCooldown();
100 player.gameRecord.start();
101 return minigame;
102 }
103
105 void handleDeath(Mob dead) {
106 if (dead.isPlayer() && dead.equals(player)) {
107 finish();
108 return;
109 }
110 if (dead.isNpc() && npcs.contains(dead)) {
111 if (dead.id == 2191) {
112 remove(dead);
113 npcs.remove(dead);
114 for (int index = 0; index < 2; index++) {
115 Position position = new Position(dead.getX() + (index == 0 ? -1 : + 1), dead.getY(), dead.getHeight());
116 Npc TzKet = new Npc(2192, position);
117 add(TzKet);
118 npcs.add(TzKet);
119 TzKet.getCombat().attack(player);
120 }
121 return;
122 }
123
124 npcs.remove(dead);
125 remove(dead);
126 tokkuls += Utility.random(100, 500);
127 if (npcs.isEmpty()) {
128 wave = TzhaarData.WaveData.getNext(wave.ordinal());
129 if (wave == null) {
130 completed = true;
131 player.send(new SendMessage("You have finished the activity!"));
132 } else {
133 player.send(new SendMessage("The next wave will commence soon."));
134 }
136 return;
137 }
138 }
139 }
140
141 @Override
142 protected void start() {
143 if (wave == null) {
144 finish();
145 return;
146 }
147 if (player.locking.locked()) {
148 return;
149 }
150
151 Position spawn = new Position(2398, 5083, player.getHeight());
152 Position[] boundaries = Utility.getInnerBoundaries(spawn, 8, 8);
153
154 for (int id : wave.getMonster()) {
155 Npc npc = new Npc(id, RandomUtils.random(boundaries));
156 npc.owner = player;
157 add(npc);
158 npcs.add(npc);
159 npc.getCombat().attack(player);
160 }
161 pause();
162 }
163
164 @Override
165 public void onDeath(Mob mob) {
166 if (mob.isNpc()) {
167 World.schedule(new NpcDeath(mob.getNpc()));
168 } else if (mob.isPlayer()) {
169 mob.move(new Position(2438, 5169, 0));
170 mob.animate(Animation.RESET, true);
171 mob.graphic(Graphic.RESET, true);
172 finish();
173 }
174 }
175
176 @Override
177 public void finish() {
178 cleanup();
179 remove(player);
180
181 if (completed) {
182 long time = player.gameRecord.end(ActivityType.FIGHT_CAVES);
183 player.dialogueFactory.sendNpcChat(2180, "You have defeated Tztok-Jad, I am most impressed!", "Please accept this gift, young thug.").execute();
184 tokkuls += 3500;
185 player.inventory.addOrDrop(new Item(6570));
186 Pets.onReward(player, PetData.JAD);
187 player.send(new SendMessage("You have completed the Fight Caves activity. Final time: @red@" + Utility.getTime(time) + "</col>."));
188 player.activityLogger.add(ActivityLog.FIGHT_CAVES);
189 return;
190 }
191
192 if (tokkuls <= 0)
193 tokkuls = 1;
194
195 player.inventory.addOrDrop(new Item(6529, tokkuls));
196 player.dialogueFactory.sendNpcChat(2180, "Better luck next time!", "Take these tokkuls as a reward.").execute();
197 }
198
199 @Override
200 public void cleanup() {
201 ActivityPanel.clear(player);
202 if (!npcs.isEmpty())
203 npcs.forEach(this::remove);
204 }
205
206 @Override
207 public void update() {
208 if (wave == null) {
209 ActivityPanel.update(player, 100, "Fight Caves", new Item(6570), "Congratulations, you have", "completed the Fight Caves", "activity!");
210 return;
211 }
212 int progress = (int)Utility.getPercentageAmount(wave.ordinal() + 1, TzhaarData.WaveData.values().length);
213 if (progress >= 100 && !completed)
214 progress = 99;
215 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));
216 }
217
218 @Override
219 public boolean canTeleport(Player player) {
220 return true;
221 }
222
223 @Override
224 public void onRegionChange(Player player) {
225 if (!Area.inFightCaves(player)) {
226 cleanup();
227 remove(player);
228 }
229 }
230
231 @Override
232 public void onLogout(Player player) {
233 finish();
234 remove(player);
235 }
236
237 @Override
238 public ActivityDeathType deathType() {
239 return ActivityDeathType.SAFE;
240 }
241
242 @Override
243 public ActivityType getType() {
244 return ActivityType.FIGHT_CAVES;
245 }
246
247 @Override
248 public Optional<? extends ActivityListener<? extends Activity>> getListener() {
249 return Optional.of(listener);
250 }
251}
Activity(int cooldown, int instance)
Definition Activity.java:92
Optional<? extends ActivityListener<? extends Activity > > getListener()
static void update(Player player, int amount, String title, String footer, String... strings)
final DialogueFactory sendNpcChat(int id, String... lines)
static void onReward(Player player, int item, int chance)
Definition Pets.java:70
static void schedule(Task task)
Definition World.java:284
void move(Position position)
Definition Mob.java:377
static String formatDigits(final int amount)
Definition Utility.java:78
static String getTime()
Definition Utility.java:178
static double getPercentageAmount(int progress, int total)
Definition Utility.java:73