RuneHive-Game
Loading...
Searching...
No Matches
Slayer.java
Go to the documentation of this file.
1package com.runehive.content.skill.impl.slayer;
2
3import com.runehive.Config;
4import com.runehive.content.achievement.AchievementHandler;
5import com.runehive.content.achievement.AchievementKey;
6import com.runehive.content.skillcape.SkillCape;
7import com.runehive.content.store.StoreItem;
8import com.runehive.game.world.entity.mob.npc.Npc;
9import com.runehive.game.world.entity.mob.player.Player;
10import com.runehive.game.world.entity.mob.player.PlayerRight;
11import com.runehive.game.world.entity.skill.Skill;
12import com.runehive.game.world.items.Item;
13import com.runehive.net.packet.out.SendString;
14import com.runehive.util.Utility;
15
16import java.util.HashSet;
17import java.util.LinkedList;
18import java.util.List;
19import java.util.Set;
20
21/**
22 * Handles the slayer skill.
23 *
24 * @author Daniel
25 */
26public class Slayer {
27 /** The player instance. */
28 private Player player;
29
30 /** The slayer points. */
31 private int points;
32
33 /** The slayer task. */
35
36 /** The slayer task assigned amount. */
37 private int assigned;
38
39 /** The current slayer task amount. */
40 private int amount;
41
42 /** The total tasks assigned. */
43 private int totalAssigned;
44
45 /** The total tasks completed. */
46 private int totalCompleted;
47
48 /** The total tasks cancelled. */
49 private int totalCancelled;
50
51 /** The total points accumulated. */
52 private int totalPoints;
53
54 /** The list of all blocked slayer tasks. */
55 private List<SlayerTask> blocked = new LinkedList<>();
56
57 /** The Set of all unlockable slayer perks. */
58 private Set<SlayerUnlockable> unlocked = new HashSet<>(SlayerUnlockable.values().length);
59
60 /** Constructs a new <code>Slayer<code>. */
62 this.player = player;
63 }
64
65 /** Opens the slayer itemcontainer. */
66 public void open(SlayerTab tab) {
68 player.attributes.set("SLAYER_KEY", tab);
69 player.interfaceManager.open(tab.getIdentification());
70 }
71
72 /** Assigns a slayer task to the player. */
73 public void assign(TaskDifficulty difficulty) {
74 if (task != null) {
75 player.message("You currently have a task assigned!");
76 return;
77 }
78
79 SlayerTask toAssign = SlayerTask.assign(player, difficulty);
80
81 if (toAssign == null) {
82 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.");
83 return;
84 }
85
86 int assignment = 0;
87 if (toAssign.getDifficulty() == TaskDifficulty.EASY) {
88 assignment = Utility.random(35, 75);
89 } else if (toAssign.getDifficulty() == TaskDifficulty.MEDIUM) {
90 assignment = Utility.random(45, 80);
91 } else if (toAssign.getDifficulty() == TaskDifficulty.HARD) {
92 assignment = Utility.random(60, 100);
93 } else if (toAssign.getDifficulty() == TaskDifficulty.BOSS) {
94 assignment = Utility.random(30, 50);
95 }
96
98 task = toAssign;
99 amount = assignment;
100 SlayerTab.refresh(player, player.attributes.get("SLAYER_KEY", SlayerTab.class));
101 player.message("You have been assigned " + amount + "x " + task.getName() + ".");
102 }
103
104 /** Cancel's the current assigned slayer task. */
105 public boolean cancel(boolean requiresCost) {
106 if (task == null) {
107 player.message("You do not have a task to cancel.");
108 return false;
109 }
110
111 if (requiresCost) {
112 int cost = PlayerRight.isDonator(player) ? 20 : 25;
113 if (points < cost) {
114 player.message("You need " + cost + " slayer points to cancel a task.");
115 return false;
116 }
117 points -= cost;
118 }
119 task = null;
120 amount = 0;
122 SlayerTab.refresh(player, player.attributes.get("SLAYER_KEY", SlayerTab.class));
123 player.message("Your task has been cancelled.");
124 return true;
125 }
126
127 /** Blocks the current assigned slayer task. */
128 public void block() {
129 if (task == null) {
130 player.message("You do not have a task to block.");
131 return;
132 }
133
134 if (points < 100) {
135 player.message("You need 100 slayer points to block a task.");
136 return;
137 }
138
139 if (blocked.size() >= 5) {
140 player.message("You can only block up to 5 tasks.");
141 return;
142 }
143
144 if (blocked.contains(task)) {
145 player.message("This task is already blocked... but how did you get it again? mmm...");
146 return;
147 }
148
149 blocked.add(task);
150 points -= 100;
151 task = null;
152 amount = 0;
154 SlayerTab.refresh(player, player.attributes.get("SLAYER_KEY", SlayerTab.class));
155 player.message("Your task has been blocked.");
156 }
157
158 /** Unblocks the slayer task. */
159 public void unblock(int index) {
160 if (!blocked.isEmpty() && index < blocked.size()) {
161 SlayerTask task = blocked.get(index);
162 blocked.remove(task);
163 SlayerTab.refresh(player, player.attributes.get("SLAYER_KEY", SlayerTab.class));
164 player.message("You have unblocked the task " + task.getName() + ".");
165 return;
166 }
167 player.message("There is no task to unblock.");
168 }
169
170 /** Activates killing a slayer npc. */
171 public void activate(Npc npc, int killAmount) {
172 if (task != null && task.valid(npc.getName())) {
173 amount -= killAmount;
174 if (amount <= 0) {
175 int rewardPoints = SlayerTask.getPoints(task.getDifficulty());
176 points += rewardPoints;
177 player.skills.addExperience(Skill.SLAYER, SlayerTask.getCompletionExperience(task.getDifficulty()));
178 task = null;
179 amount = 0;
181 player.message("Congratulations, you have completed your assigned task! You have earned " + rewardPoints + " slayer points!");
183 return;
184 }
185 player.skills.addExperience(Skill.SLAYER, npc.getMaximumHealth() * Config.SLAYER_MODIFICATION);
186 }
187 }
188
189 /** Opens the confirm itemcontainer for purchasing a perk. */
190 public void confirm(int button) {
191 int index = Math.abs((-18625 - button) / 6);
192 if (!SlayerUnlockable.get(index).isPresent())
193 return;
194 SlayerUnlockable unlockable = SlayerUnlockable.get(index).get();
195 player.attributes.set("SLAYER_CONFIRM_KEY", unlockable);
197 }
198
199 /** Handles purchasing a slayer perk. */
200 public void purchase() {
201 SlayerUnlockable unlockable = player.attributes.get("SLAYER_CONFIRM_KEY", SlayerUnlockable.class);
202
203 if (points < unlockable.getCost()) {
205 player.message("You do not have enough points to purchase this!");
206 return;
207 }
208
209 if (unlocked.contains(unlockable)) {
211 player.message("You have already activated this perk!");
212 return;
213 }
214
215 points -= unlockable.getCost();
216 unlocked.add(unlockable);
217 player.message("You have purchased the " + unlockable.getName() + " Slayer perk.");
219 }
220
221 private final static StoreItem[] STORE_ITEMS = {
222 new StoreItem(4155, 1, 0),
223 new StoreItem(11941, 1, 150),
224 new StoreItem(11866, 1, 75),
225 new StoreItem(4166, 1, 5),
226 new StoreItem(4168, 1, 5),
227 new StoreItem(4164, 1, 5),
228 new StoreItem(4551, 1, 5),
229 new StoreItem(8901, 1, 200),
230 new StoreItem(10551, 1, 200),
231 new StoreItem(11738, 1, 25),
232 new StoreItem(13116, 1, 200),
233 new StoreItem(25781, 1, 200)
234 };
235
236 static Item[] ITEMS = new Item[STORE_ITEMS.length];
237
238 static {
239 int index = 0;
240 for (StoreItem storeItem : STORE_ITEMS) {
241 ITEMS[index] = new Item(storeItem.getId(), storeItem.getAmount());
242 index++;
243 }
244 }
245
246 /** Handles purchasing items from the slayer shop. */
247 public void store(int slot, int amount, boolean value) {
248 if (slot < 0 && slot > STORE_ITEMS.length) {
249 return;
250 }
251
252 StoreItem item = STORE_ITEMS[slot];
253 int cost = item.getShopValue();
254
255 if (value) {
256 String price = cost == 0 ? "is free!" : "costs " + Utility.formatDigits(cost) + " slayer points.";
257 player.message(item.getName() + " " + price);
258 return;
259 }
260
261 if (player.inventory.remaining() == 0) {
262 player.message("You do not have enough inventory space to buy that.");
263 return;
264 }
265
266 if (!item.isStackable()) {
267 if (amount > player.inventory.remaining()) {
268 amount = player.inventory.remaining();
269 }
270 } else {
271 amount *= item.getAmount();
272 }
273
274 int price = cost * amount;
275
276 if (getPoints() < price) {
277 player.message("You do not have enough slayer points to make this purchase!");
278 return;
279 }
280
281 item.setAmount(amount);
282 points -= price;
283 player.inventory.add(item);
284 player.send(new SendString(Utility.formatDigits(points) + "\\nPoints", 46714));
285 }
286
287 public int getPoints() {
288 return points;
289 }
290
291 public void setPoints(int points) {
292 this.points = points;
293 }
294
296 return task;
297 }
298
299 public void setTask(SlayerTask task) {
300 this.task = task;
301 }
302
303 public int getAmount() {
304 return amount;
305 }
306
307 public void setAmount(int amount) {
308 this.amount = amount;
309 }
310
311 public int getAssigned() {
312 return assigned;
313 }
314
315 public void setAssigned(int assigned) {
316 this.assigned = assigned;
317 }
318
319 public int getTotalAssigned() {
320 return totalAssigned;
321 }
322
324 this.totalAssigned = totalAssigned;
325 }
326
327 public int getTotalCompleted() {
328 return totalCompleted;
329 }
330
332 this.totalCompleted = totalCompleted;
333 }
334
335 public int getTotalCancelled() {
336 return totalCancelled;
337 }
338
340 this.totalCancelled = totalCancelled;
341 }
342
343 public int getTotalPoints() {
344 return totalPoints;
345 }
346
347 public void setTotalPoints(int totalPoints) {
348 this.totalPoints = totalPoints;
349 }
350
351 public List<SlayerTask> getBlocked() {
352 return blocked;
353 }
354
355 public void setBlocked(List<SlayerTask> blocked) {
356 this.blocked = blocked;
357 }
358
359 public Set<SlayerUnlockable> getUnlocked() {
360 return unlocked;
361 }
362
363 public void setUnlocked(Set<SlayerUnlockable> unlocked) {
364 this.unlocked = unlocked;
365 }
366}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final double SLAYER_MODIFICATION
The experience modification for Slayer.
Definition Config.java:280
static void activate(Player player, AchievementKey achievement)
Activates the achievement for the individual player.
List< SlayerTask > blocked
The list of all blocked slayer tasks.
Definition Slayer.java:55
int totalCompleted
The total tasks completed.
Definition Slayer.java:46
int totalAssigned
The total tasks assigned.
Definition Slayer.java:43
void store(int slot, int amount, boolean value)
Handles purchasing items from the slayer shop.
Definition Slayer.java:247
boolean cancel(boolean requiresCost)
Cancel's the current assigned slayer task.
Definition Slayer.java:105
Player player
The player instance.
Definition Slayer.java:28
int totalPoints
The total points accumulated.
Definition Slayer.java:52
Set< SlayerUnlockable > unlocked
The Set of all unlockable slayer perks.
Definition Slayer.java:58
void purchase()
Handles purchasing a slayer perk.
Definition Slayer.java:200
void open(SlayerTab tab)
Opens the slayer itemcontainer.
Definition Slayer.java:66
void setUnlocked(Set< SlayerUnlockable > unlocked)
Definition Slayer.java:363
int assigned
The slayer task assigned amount.
Definition Slayer.java:37
void setTotalCompleted(int totalCompleted)
Definition Slayer.java:331
void setBlocked(List< SlayerTask > blocked)
Definition Slayer.java:355
Set< SlayerUnlockable > getUnlocked()
Definition Slayer.java:359
void confirm(int button)
Opens the confirm itemcontainer for purchasing a perk.
Definition Slayer.java:190
int amount
The current slayer task amount.
Definition Slayer.java:40
void activate(Npc npc, int killAmount)
Activates killing a slayer npc.
Definition Slayer.java:171
Slayer(Player player)
Constructs a new Slayer.
Definition Slayer.java:61
void unblock(int index)
Unblocks the slayer task.
Definition Slayer.java:159
int totalCancelled
The total tasks cancelled.
Definition Slayer.java:49
void setTotalCancelled(int totalCancelled)
Definition Slayer.java:339
void assign(TaskDifficulty difficulty)
Assigns a slayer task to the player.
Definition Slayer.java:73
void block()
Blocks the current assigned slayer task.
Definition Slayer.java:128
A simple wrapper class which holds extra attributes for the item object.
Represents a non-player character in the in-game world.
Definition Npc.java:29
String getName()
Gets the name of this entity.
Definition Npc.java:166
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
static final int SLAYER
The slayer skill id.
Definition Skill.java:75
The container class that represents an item that can be interacted with.
Definition Item.java:21
final void setAmount(int amount)
Sets the quantity of this item.
Definition Item.java:351
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
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
UNLOCK
The unlock itemcontainer - holds all the unlockable perks.
int getIdentification()
Gets the itemcontainer identification.
CONFIRM
The confirm itemcontainer - keeps player confirmation on purchase.
static void refresh(Player player, SlayerTab tab)
Refreshes the tab itemcontainer.
static int getPoints(TaskDifficulty difficulty)
TaskDifficulty getDifficulty()
Gets the difficulty of the slayer task.
static SlayerTask assign(Player player, TaskDifficulty difficulty)
Assigns a slayer task for the player.
static int getCompletionExperience(TaskDifficulty difficulty)
Holds all the unlockable slayer rewards and tasks.
static Optional< SlayerUnlockable > get(int ordinal)
Gets the slayer unlockable data based on the ordinal.
static boolean isDonator(Player player)
Checks if the player has donator status.