RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Slayer.java
1package com.osroyale.content.skill.impl.slayer;
2
3import com.osroyale.Config;
4import com.osroyale.content.achievement.AchievementHandler;
5import com.osroyale.content.achievement.AchievementKey;
6import com.osroyale.content.skillcape.SkillCape;
7import com.osroyale.content.store.StoreItem;
8import com.osroyale.game.world.entity.mob.npc.Npc;
9import com.osroyale.game.world.entity.mob.player.Player;
10import com.osroyale.game.world.entity.mob.player.PlayerRight;
11import com.osroyale.game.world.entity.skill.Skill;
12import com.osroyale.game.world.items.Item;
13import com.osroyale.net.packet.out.SendString;
14import com.osroyale.util.Utility;
15
16import java.util.HashSet;
17import java.util.LinkedList;
18import java.util.List;
19import java.util.Set;
20
62
63public class Slayer {
65 private Player player;
66
68 private int points;
69
71 private SlayerTask task;
72
74 private int assigned;
75
77 private int amount;
78
80 private int totalAssigned;
81
83 private int totalCompleted;
84
86 private int totalCancelled;
87
89 private int totalPoints;
90
92 private List<SlayerTask> blocked = new LinkedList<>();
93
95 private Set<SlayerUnlockable> unlocked = new HashSet<>(SlayerUnlockable.values().length);
96
98 public Slayer(Player player) {
99 this.player = player;
100 }
101
103 public void open(SlayerTab tab) {
104 SlayerTab.refresh(player, tab);
105 player.attributes.set("SLAYER_KEY", tab);
106 player.interfaceManager.open(tab.getIdentification());
107 }
108
110 public void assign(TaskDifficulty difficulty) {
111 if (task != null) {
112 player.message("You currently have a task assigned!");
113 return;
114 }
115
116 SlayerTask toAssign = SlayerTask.assign(player, difficulty);
117
118 if (toAssign == null) {
119 player.dialogueFactory.sendNpcChat(6797, "There are no tasks available for you!", "This can be because you do not have a valid", "slayer level or you haven't unlocked any tasks.");
120 return;
121 }
122
123 int assignment = 0;
124 if (toAssign.getDifficulty() == TaskDifficulty.EASY) {
125 assignment = Utility.random(35, 75);
126 } else if (toAssign.getDifficulty() == TaskDifficulty.MEDIUM) {
127 assignment = Utility.random(45, 80);
128 } else if (toAssign.getDifficulty() == TaskDifficulty.HARD) {
129 assignment = Utility.random(60, 100);
130 } else if (toAssign.getDifficulty() == TaskDifficulty.BOSS) {
131 assignment = Utility.random(30, 50);
132 }
133
134 totalAssigned++;
135 task = toAssign;
136 amount = assignment;
137 SlayerTab.refresh(player, player.attributes.get("SLAYER_KEY", SlayerTab.class));
138 player.message("You have been assigned " + amount + "x " + task.getName() + ".");
139 }
140
142 public boolean cancel(boolean requiresCost) {
143 if (task == null) {
144 player.message("You do not have a task to cancel.");
145 return false;
146 }
147
148 if (requiresCost) {
149 int cost = PlayerRight.isDonator(player) ? 20 : 25;
150 if (points < cost) {
151 player.message("You need " + cost + " slayer points to cancel a task.");
152 return false;
153 }
154 points -= cost;
155 }
156 task = null;
157 amount = 0;
158 totalCancelled++;
159 SlayerTab.refresh(player, player.attributes.get("SLAYER_KEY", SlayerTab.class));
160 player.message("Your task has been cancelled.");
161 return true;
162 }
163
165 public void block() {
166 if (task == null) {
167 player.message("You do not have a task to block.");
168 return;
169 }
170
171 if (points < 100) {
172 player.message("You need 100 slayer points to block a task.");
173 return;
174 }
175
176 if (blocked.size() >= 5) {
177 player.message("You can only block up to 5 tasks.");
178 return;
179 }
180
181 if (blocked.contains(task)) {
182 player.message("This task is already blocked... but how did you get it again? mmm...");
183 return;
184 }
185
186 blocked.add(task);
187 points -= 100;
188 task = null;
189 amount = 0;
190 totalCancelled++;
191 SlayerTab.refresh(player, player.attributes.get("SLAYER_KEY", SlayerTab.class));
192 player.message("Your task has been blocked.");
193 }
194
196 public void unblock(int index) {
197 if (!blocked.isEmpty() && index < blocked.size()) {
198 SlayerTask task = blocked.get(index);
199 blocked.remove(task);
200 SlayerTab.refresh(player, player.attributes.get("SLAYER_KEY", SlayerTab.class));
201 player.message("You have unblocked the task " + task.getName() + ".");
202 return;
203 }
204 player.message("There is no task to unblock.");
205 }
206
208 public void activate(Npc npc, int killAmount) {
209 if (task != null && task.valid(npc.getName())) {
210 amount -= killAmount;
211 if (amount <= 0) {
212 int rewardPoints = SlayerTask.getPoints(task.getDifficulty());
213 points += rewardPoints;
214 player.skills.addExperience(Skill.SLAYER, SlayerTask.getCompletionExperience(task.getDifficulty()));
215 task = null;
216 amount = 0;
217 totalCompleted++;
218 player.message("Congratulations, you have completed your assigned task! You have earned " + rewardPoints + " slayer points!");
219 AchievementHandler.activate(player, AchievementKey.SLAYER_TASKS);
220 return;
221 }
222 player.skills.addExperience(Skill.SLAYER, npc.getMaximumHealth() * Config.SLAYER_MODIFICATION);
223 }
224 }
225
227 public void confirm(int button) {
228 int index = Math.abs((-18625 - button) / 6);
229 if (!SlayerUnlockable.get(index).isPresent())
230 return;
231 SlayerUnlockable unlockable = SlayerUnlockable.get(index).get();
232 player.attributes.set("SLAYER_CONFIRM_KEY", unlockable);
234 }
235
237 public void purchase() {
238 SlayerUnlockable unlockable = player.attributes.get("SLAYER_CONFIRM_KEY", SlayerUnlockable.class);
239
240 if (points < unlockable.getCost()) {
242 player.message("You do not have enough points to purchase this!");
243 return;
244 }
245
246 if (unlocked.contains(unlockable)) {
248 player.message("You have already activated this perk!");
249 return;
250 }
251
252 points -= unlockable.getCost();
253 unlocked.add(unlockable);
254 player.message("You have purchased the " + unlockable.getName() + " Slayer perk.");
256 }
257
258 private final static StoreItem[] STORE_ITEMS = {
259 new StoreItem(4155, 1, 0),
260 new StoreItem(11941, 1, 150),
261 new StoreItem(11866, 1, 75),
262 new StoreItem(4166, 1, 5),
263 new StoreItem(4168, 1, 5),
264 new StoreItem(4164, 1, 5),
265 new StoreItem(4551, 1, 5),
266 new StoreItem(8901, 1, 200),
267 new StoreItem(10551, 1, 200),
268 new StoreItem(11738, 1, 25),
269 new StoreItem(13116, 1, 200),
270 new StoreItem(25781, 1, 200)
271 };
272
273 static Item[] ITEMS = new Item[STORE_ITEMS.length];
274
275 static {
276 int index = 0;
277 for (StoreItem storeItem : STORE_ITEMS) {
278 ITEMS[index] = new Item(storeItem.getId(), storeItem.getAmount());
279 index++;
280 }
281 }
282
284 public void store(int slot, int amount, boolean value) {
285 if (slot < 0 && slot > STORE_ITEMS.length) {
286 return;
287 }
288
289 StoreItem item = STORE_ITEMS[slot];
290 int cost = item.getShopValue();
291
292 if (value) {
293 String price = cost == 0 ? "is free!" : "costs " + Utility.formatDigits(cost) + " slayer points.";
294 player.message(item.getName() + " " + price);
295 return;
296 }
297
298 if (player.inventory.remaining() == 0) {
299 player.message("You do not have enough inventory space to buy that.");
300 return;
301 }
302
303 if (!item.isStackable()) {
304 if (amount > player.inventory.remaining()) {
305 amount = player.inventory.remaining();
306 }
307 } else {
308 amount *= item.getAmount();
309 }
310
311 int price = cost * amount;
312
313 if (getPoints() < price) {
314 player.message("You do not have enough slayer points to make this purchase!");
315 return;
316 }
317
318 item.setAmount(amount);
319 points -= price;
320 player.inventory.add(item);
321 player.send(new SendString(Utility.formatDigits(points) + "\\nPoints", 46714));
322 }
323
324 public int getPoints() {
325 return points;
326 }
327
328 public void setPoints(int points) {
329 this.points = points;
330 }
331
332 public SlayerTask getTask() {
333 return task;
334 }
335
336 public void setTask(SlayerTask task) {
337 this.task = task;
338 }
339
340 public int getAmount() {
341 return amount;
342 }
343
344 public void setAmount(int amount) {
345 this.amount = amount;
346 }
347
348 public int getAssigned() {
349 return assigned;
350 }
351
352 public void setAssigned(int assigned) {
353 this.assigned = assigned;
354 }
355
356 public int getTotalAssigned() {
357 return totalAssigned;
358 }
359
360 public void setTotalAssigned(int totalAssigned) {
361 this.totalAssigned = totalAssigned;
362 }
363
364 public int getTotalCompleted() {
365 return totalCompleted;
366 }
367
368 public void setTotalCompleted(int totalCompleted) {
369 this.totalCompleted = totalCompleted;
370 }
371
372 public int getTotalCancelled() {
373 return totalCancelled;
374 }
375
376 public void setTotalCancelled(int totalCancelled) {
377 this.totalCancelled = totalCancelled;
378 }
379
380 public int getTotalPoints() {
381 return totalPoints;
382 }
383
384 public void setTotalPoints(int totalPoints) {
385 this.totalPoints = totalPoints;
386 }
387
388 public List<SlayerTask> getBlocked() {
389 return blocked;
390 }
391
392 public void setBlocked(List<SlayerTask> blocked) {
393 this.blocked = blocked;
394 }
395
396 public Set<SlayerUnlockable> getUnlocked() {
397 return unlocked;
398 }
399
400 public void setUnlocked(Set<SlayerUnlockable> unlocked) {
401 this.unlocked = unlocked;
402 }
403}
static final double SLAYER_MODIFICATION
Definition Config.java:322
static void activate(Player player, AchievementKey achievement)
void assign(TaskDifficulty difficulty)
Definition Slayer.java:110
void activate(Npc npc, int killAmount)
Definition Slayer.java:208
boolean cancel(boolean requiresCost)
Definition Slayer.java:142
void store(int slot, int amount, boolean value)
Definition Slayer.java:284
static String formatDigits(final int amount)
Definition Utility.java:78
static void refresh(Player player, SlayerTab tab)
static SlayerTask assign(Player player, TaskDifficulty difficulty)
static Optional< SlayerUnlockable > get(int ordinal)