RuneHive-Game
Loading...
Searching...
No Matches
PotionData.java
Go to the documentation of this file.
1package com.runehive.content.consume;
2
3import com.google.common.collect.ImmutableSet;
4import com.google.common.collect.Sets;
5import com.runehive.game.task.impl.AntiVenomTask;
6import com.runehive.game.task.impl.SuperAntipoisonTask;
7import com.runehive.game.world.World;
8import com.runehive.game.world.entity.combat.CombatUtil;
9import com.runehive.game.world.entity.combat.PoisonType;
10import com.runehive.game.world.entity.combat.effect.CombatEffectType;
11import com.runehive.game.world.entity.combat.hit.Hit;
12import com.runehive.game.world.entity.mob.player.Player;
13import com.runehive.game.world.entity.skill.Skill;
14import com.runehive.game.world.items.Item;
15import com.runehive.net.packet.out.SendConfig;
16import com.runehive.net.packet.out.SendMessage;
17import com.runehive.net.packet.out.SendPoison;
18import com.runehive.net.packet.out.SendRunEnergy;
19
20import java.util.EnumSet;
21import java.util.Optional;
22
23/**
24 * The enumerated type managing consumable potion types.
25 *
26 * @author Ryley Kimmel <ryley.kimmel@live.com>
27 * @author lare96 <http://github.com/lare96>
28 */
29public enum PotionData {
30 STAMINA__POTION(12625, 12627, 12629, 12631) {
31 @Override
32 public void onEffect(Player player) {
33 PotionData.onEnergyEffect(player, true);
34 player.energyRate = 200;
35 }
36 },
37 SUPER_COMBAT_POTION(12695, 12697, 12699, 12701) {
38 @Override
39 public void onEffect(Player player) {
40 PotionData.onBasicEffect(player, Skill.ATTACK, BoostType.SUPER);
41 PotionData.onBasicEffect(player, Skill.STRENGTH, BoostType.SUPER);
42 PotionData.onBasicEffect(player, Skill.DEFENCE, BoostType.SUPER);
43 }
44 },
45 ZAMORAK_BREW(2450, 189, 191, 193) {
46 @Override
47 public void onEffect(Player player) {
48 PotionData.onZamorakEffect(player);
49 }
50 },
51 SARADOMIN_BREW(6685, 6687, 6689, 6691) {
52 @Override
53 public void onEffect(Player player) {
54 PotionData.onSaradominEffect(player);
55 }
56 },
57 ANTIDOTE_PLUS(5943, 5945, 5947, 5949) {
58 @Override
59 public void onEffect(Player player) {
60 PotionData.onAntiPoisonEffect(player, true, 1000);
61 }
62 },
63 ANTIDOTE_PLUS_PLUS(5952, 5954, 5956, 5958) {
64 @Override
65 public void onEffect(Player player) {
66 PotionData.onAntiPoisonEffect(player, true, 1200);
67 }
68 },
69 AGILITY_POTION(3032, 3034, 3036, 3038) {
70 @Override
71 public void onEffect(Player player) {
72 PotionData.onAgilityEffect(player);
73 }
74 },
75 FISHING_POTION(2438, 151, 153, 155) {
76 @Override
77 public void onEffect(Player player) {
78 PotionData.onFishingEffect(player);
79 }
80 },
81 RANGE_POTIONS(2444, 169, 171, 173) {
82 @Override
83 public void onEffect(Player player) {
84 PotionData.onBasicEffect(player, Skill.RANGED, BoostType.RANGING);
85 }
86 },
87 ENERGY_POTIONS(3008, 3010, 3012, 3014) {
88 @Override
89 public void onEffect(Player player) {
90 PotionData.onEnergyEffect(player, false);
91 }
92 },
93 SUPER_ENERGY_POTIONS(3016, 3018, 3020, 3022) {
94 @Override
95 public void onEffect(Player player) {
96 PotionData.onEnergyEffect(player, true);
97 }
98 },
99 MAGIC_POTIONS(3040, 3042, 3044, 3046) {
100 @Override
101 public void onEffect(Player player) {
102 PotionData.onBasicEffect(player, Skill.MAGIC, BoostType.MAGIC);
103 }
104 },
105 DEFENCE_POTIONS(2432, 133, 135, 137) {
106 @Override
107 public void onEffect(Player player) {
108 PotionData.onBasicEffect(player, Skill.DEFENCE, BoostType.NORMAL);
109 }
110 },
111 STRENGTH_POTIONS(113, 115, 117, 119) {
112 @Override
113 public void onEffect(Player player) {
114 PotionData.onBasicEffect(player, Skill.STRENGTH, BoostType.NORMAL);
115 }
116 },
117 ATTACK_POTIONS(2428, 121, 123, 125) {
118 @Override
119 public void onEffect(Player player) {
120 PotionData.onBasicEffect(player, Skill.ATTACK, BoostType.NORMAL);
121 }
122 },
123 SUPER_DEFENCE_POTIONS(2442, 163, 165, 167) {
124 @Override
125 public void onEffect(Player player) {
126 PotionData.onBasicEffect(player, Skill.DEFENCE, BoostType.SUPER);
127 }
128 },
129 SUPER_ATTACK_POTIONS(2436, 145, 147, 149) {
130 @Override
131 public void onEffect(Player player) {
132 PotionData.onBasicEffect(player, Skill.ATTACK, BoostType.SUPER);
133 }
134 },
135 SUPER_STRENGTH_POTIONS(2440, 157, 159, 161) {
136 @Override
137 public void onEffect(Player player) {
138 PotionData.onBasicEffect(player, Skill.STRENGTH, BoostType.SUPER);
139 }
140 },
141 RESTORE_POTIONS(2430, 127, 129, 131) {
142 @Override
143 public void onEffect(Player player) {
144 onRestoreEffect(player, false);
145 }
146 },
147 SUPER_RESTORE_POTIONS(3024, 3026, 3028, 3030) {
148 @Override
149 public void onEffect(Player player) {
150 PotionData.onRestoreEffect(player, true);
151 int realLevel = player.skills.getMaxLevel(Skill.PRAYER);
152 player.skills.get(Skill.PRAYER).modifyLevel(level -> level + (int) Math.floor(8 + (realLevel * 0.25)));
153 player.skills.refresh(Skill.PRAYER);
154 }
155 },
156 PRAYER_POTIONS(2434, 139, 141, 143) {
157 @Override
158 public void onEffect(Player player) {
159 PotionData.onPrayerEffect(player, false);
160 }
161 },
162 SUPER_PRAYER_POTIONS(15328, 15329, 15330, 15331) {
163 @Override
164 public void onEffect(Player player) {
165 PotionData.onPrayerEffect(player, true);
166 }
167 },
168 ANTIFIRE_POTIONS(2452, 2454, 2456, 2458) {
169 @Override
170 public void onEffect(Player player) {
171 PotionData.onAntiFireEffect(player, false);
172 }
173 },
174 SUPER_ANTIFIRE_POTIONS(15304, 15305, 15306, 15307) {
175 @Override
176 public void onEffect(Player player) {
177 PotionData.onAntiFireEffect(player, true);
178 }
179 },
180 ANTIPOISON_POTIONS(2446, 175, 177, 179) {
181 @Override
182 public void onEffect(Player player) {
183 PotionData.onAntiPoisonEffect(player, false, 0);
184 }
185 },
186 SUPER_ANTIPOISON_POTIONS(2448, 181, 183, 185) {
187 @Override
188 public void onEffect(Player player) {
189 PotionData.onAntiPoisonEffect(player, true, 500);
190 }
191 },
192 ANTI_VENOM(12905, 12907, 12909, 12911) {
193 @Override
194 public void onEffect(Player player) {
195 player.unvenom();
196 player.unpoison();
197
198 if (player.getPoisonImmunity().get() <= 0) {
199 player.send(new SendMessage("You have been granted immunity against poison."));
200 World.schedule(new SuperAntipoisonTask(player).attach(player));
201 } else if (player.getPoisonImmunity().get() > 0) {
202 player.send(new SendMessage("Your immunity against poison has been restored!"));
203 }
204 player.getPoisonImmunity().set(1200);
205
206 if (player.getVenomImmunity().get() <= 0) {
207 player.send(new SendMessage("You have been granted immunity against venom."));
208 World.schedule(new AntiVenomTask(player).attach(player));
209 } else if (player.getVenomImmunity().get() > 0) {
210 player.send(new SendMessage("Your immunity against venom has been restored!"));
211 }
212 player.getVenomImmunity().set(300);
213 }
214 },
215 ANTI_VENOM_PLUS(12913, 12915, 12917, 12919) {
216 @Override
217 public void onEffect(Player player) {
218 player.unvenom();
219 player.unpoison();
220
221 if (player.getPoisonImmunity().get() <= 0) {
222 player.send(new SendMessage("You have been granted immunity against poison."));
223 World.schedule(new SuperAntipoisonTask(player).attach(player));
224 } else if (player.getPoisonImmunity().get() > 0) {
225 player.send(new SendMessage("Your immunity against poison has been restored!"));
226 }
227 player.getPoisonImmunity().set(1500);
228
229 if (player.getVenomImmunity().get() <= 0) {
230 player.send(new SendMessage("You have been granted immunity against venom."));
231 World.schedule(new AntiVenomTask(player).attach(player));
232 } else if (player.getVenomImmunity().get() > 0) {
233 player.send(new SendMessage("Your immunity against venom has been restored!"));
234 }
235 player.getVenomImmunity().set(3000);
236 }
237 };
238
239 /**
240 * Caches our enum values.
241 */
242 private static final ImmutableSet<PotionData> VALUES = Sets.immutableEnumSet(EnumSet.allOf(PotionData.class));
243
244 /**
245 * The default item representing the final potion dose.
246 */
247 private static final Item VIAL = new Item(229);
248
249 /**
250 * The identifiers which represent this potion type.
251 */
252 private final int[] ids;
253
254 /**
255 * Create a new {@link PotionData}.
256 *
257 * @param ids the identifiers which represent this potion type.
258 */
259 PotionData(int... ids) {
260 this.ids = ids;
261 }
262
263 /**
264 * The method that executes the fishing potion action.
265 *
266 * @param player the player to do this action for.
267 */
268 private static void onFishingEffect(Player player) {
269 player.skills.get(Skill.FISHING).modifyLevel(level -> level + 3);
270 player.skills.refresh(Skill.FISHING);
271 }
272
273 /**
274 * The method that executes the agility potion action.
275 *
276 * @param player the player to do this action for.
277 */
278 private static void onAgilityEffect(Player player) {
279 player.skills.get(Skill.AGILITY).modifyLevel(level -> level + 3);
280 player.skills.refresh(Skill.AGILITY);
281 }
282
283 /**
284 * The method that executes the Saradomin brew action.
285 *
286 * @param player the player to do this action for.
287 */
288 private static void onSaradominEffect(Player player) {
289 modifySkill(player, Skill.HITPOINTS, 0.15, 2);
290 modifySkill(player, Skill.DEFENCE, 0.20, 2);
291 modifySkill(player, Skill.ATTACK, -0.10, 2);
292 modifySkill(player, Skill.STRENGTH, -0.10, 2);
293 modifySkill(player, Skill.RANGED, -0.10, 2);
294 modifySkill(player, Skill.MAGIC, -0.10, 2);
295 }
296
297 /**
298 * The method that executes the Zamorak brew action.
299 *
300 * @param player the player to do this action for.
301 */
302 private static void onZamorakEffect(Player player) {
303 modifySkill(player, Skill.ATTACK, 0.20, 2);
304 modifySkill(player, Skill.STRENGTH, 0.12, 2);
305 modifySkill(player, Skill.DEFENCE, -0.10, 2);
306 modifySkill(player, Skill.HITPOINTS, -0.10, 2);
307 modifySkill(player, Skill.PRAYER, 0.10, 0);
308 }
309
310 /**
311 * The method that executes the prayer potion action.
312 *
313 * @param player the player to do this action for.
314 * @param superPrayer determines if this potion is a super prayer potion.
315 */
316 private static void onPrayerEffect(Player player, boolean superPrayer) {
317 int realLevel = player.skills.get(Skill.PRAYER).getMaxLevel();
318 player.skills.get(Skill.PRAYER).modifyLevel(level -> level + (int) Math.floor(7 + (realLevel * (superPrayer ? 0.35 : 0.25))));
319 player.skills.refresh(Skill.PRAYER);
320
321 }
322
323 /**
324 * The method that executes the anti-poison potion action.
325 *
326 * @param player the player to do this action for.
327 * @param superPotion {@code true} if this potion is a super potion, {@code
328 * false} otherwise.
329 * @param length the length that the effect lingers for.
330 */
331 public static void onAntiPoisonEffect(Player player, boolean superPotion, int length) {
332 if (player.isVenomed()) {
333 player.getVenomDamage().set(0);
335 player.poison(PoisonType.WEAK_NPC);
336 return;
337 }
338
339 if (player.isPoisoned()) {
340 player.getPoisonDamage().set(0);
342 player.send(new SendConfig(174, 0));
343 player.send(new SendMessage("You have been cured of your poison!"));
345 }
346
347 if (superPotion) {
348 if (length > 0 && player.getPoisonImmunity().get() <= 0) {
349 player.send(new SendMessage("You have been granted immunity against poison."));
350 player.getPoisonImmunity().incrementAndGet(length);
351 World.schedule(new SuperAntipoisonTask(player).attach(player));
352 } else if (player.getPoisonImmunity().get() > 0) {
353 player.send(new SendMessage("Your immunity against poison has been restored!"));
354 player.getPoisonImmunity().set(length);
355 }
356 }
357 }
358
359 /**
360 * The method that executes the energy potion action.
361 *
362 * @param player the player to do this action for.
363 * @param superPotion {@code true} if this potion is a super potion, {@code
364 * false} otherwise.
365 */
366 private static void onEnergyEffect(Player player, boolean superPotion) {
367 int amount = superPotion ? 20 : 10;
368 int energy = player.runEnergy;
369
370 if (amount + energy > 100) {
371 player.runEnergy = 100;
372 } else {
373 player.runEnergy += amount;
374 }
375
376 player.send(new SendRunEnergy());
377 }
378
379 /**
380 * The method that executes the restore potion action.
381 *
382 * @param player the player to do this action for.
383 */
384 private static void onRestoreEffect(Player player, boolean superRestore) {
385 for (int index = 0; index <= 6; index++) {
386 if ((index == Skill.PRAYER) || (index == Skill.HITPOINTS)) {
387 continue;
388 }
389
390 Skill skill = player.skills.get(index);
391 int realLevel = skill.getMaxLevel();
392
393 if (skill.getLevel() >= realLevel) {
394 continue;
395 }
396
397 int formula = superRestore ? (int) Math.floor(8 + (realLevel * 0.25)) : (int) Math.floor(10 + (realLevel * 0.30));
398 player.skills.get(index).modifyLevel(level -> level + formula);
399 player.skills.refresh(index);
400 }
401 }
402
403 /**
404 * The method that executes the anti-fireRunes potion action.
405 *
406 * @param player the player to do this action for.
407 * @param superVariant determines if this potion is the super variant.
408 */
409 private static void onAntiFireEffect(Player player, boolean superVariant) {
410 if (superVariant) {
412 } else {
414 }
415 }
416
417 /**
418 * The method that executes the basic effect potion action that will
419 * append the level of {@code skill}.
420 *
421 * @param player the player to do this action for.
422 */
423 private static void onBasicEffect(Player player, int skill, BoostType type) {
424 modifySkill(player, skill, type.amount, type.base);
425 }
426
427 /**
428 * The method that executes the basic effect potion action that will
429 * append the level of {@code skill}.
430 *
431 * @param player the player to do this action for.
432 */
433 private static void modifySkill(Player player, int skill, double percentage, int base) {
434 Skill s = player.skills.get(skill);
435 int realLevel = s.getMaxLevel();
436
437 final int boostLevel = (int) (realLevel * percentage + base);
438
439 int cap = s.getLevel();
440 if (cap < realLevel + boostLevel) {
441 cap = realLevel + boostLevel;
442 }
443
444 if (skill == Skill.HITPOINTS && boostLevel < 0) {
445 int damage = boostLevel;
446 if (player.getCurrentHealth() + damage <= 0) damage = -player.getCurrentHealth() + 1;
447 player.damage(new Hit(-damage));
448 } else {
449 player.skills.get(skill).modifyLevel(level -> level + boostLevel, 0, cap);
450 }
451
452 player.skills.refresh(skill);
453 }
454
455 /**
456 * Retrieves the replacement item for {@code item}.
457 *
458 * @param item the item to retrieve the replacement item for.
459 * @return the replacement item wrapped in an optional, or an empty optional
460 * if no replacement item is available.
461 */
462 public static Item getReplacementItem(Item item) {
463 Optional<PotionData> potion = forId(item.getId());
464 if (potion.isPresent()) {
465 int length = potion.get().getIds().length;
466 for (int index = 0; index < length; index++) {
467 if (potion.get().getIds()[index] == item.getId() && index + 1 < length) {
468 return new Item(potion.get().getIds()[index + 1]);
469 }
470 }
471 }
472 return VIAL;
473 }
474
475 /**
476 * Retrieves the potion consumable element for {@code id}.
477 *
478 * @param id the id that the potion consumable is attached to.
479 * @return the potion consumable wrapped in an optional, or an empty
480 * optional if no potion consumable was found.
481 */
482 public static Optional<PotionData> forId(int id) {
483 for (PotionData potion : VALUES) {
484 for (int potionId : potion.getIds()) {
485 if (id == potionId) {
486 return Optional.of(potion);
487 }
488 }
489 }
490 return Optional.empty();
491 }
492
493 /**
494 * The method executed when this potion type activated.
495 *
496 * @param player the player to execute this effect for.
497 */
498 public abstract void onEffect(Player player);
499
500 /**
501 * The method which determines if the {@code player} can drink the potion.
502 *
503 * @param player the player to determine this for.
504 */
505 public boolean canDrink(Player player) {
506 return true;
507 }
508
509 /**
510 * Gets the identifiers which represent this potion type.
511 *
512 * @return the identifiers for this potion.
513 */
514 public final int[] getIds() {
515 return ids;
516 }
517
518 /**
519 * Gets the item id for the specified dose.
520 *
521 * @param dose the dose to get the item id from.
522 * @return the item id.
523 */
524 public int getIdForDose(int dose) {
525 return ids[ids.length - dose];
526 }
527
528 /**
529 * The enumerated type whose elements represent the boost types for potions.
530 *
531 * @author Ryley Kimmel <ryley.kimmel@live.com>
532 * @author lare96 <http://github.com/lare96>
533 */
534 public enum BoostType {
535 NORMAL(3, .10F),
536 RANGING(4, .10F),
537 MAGIC(4, 0),
538 SUPER(5, .15F);
539
540 /**
541 * The base which we will append by.
542 */
543 private final int base;
544
545 /**
546 * The amount this type will boost by.
547 */
548 private final float amount;
549
550 /**
551 * Creates a new {@link BoostType}.
552 *
553 * @param boostAmount the amount this type will boost by.
554 */
555 BoostType(int base, float boostAmount) {
556 this.base = base;
557 this.amount = boostAmount;
558 }
559
560 /**
561 * Gets the base this type will boost by.
562 *
563 * @return the base amount.
564 */
565 public final int getBase() {
566 return base;
567 }
568
569 /**
570 * Gets the amount this type will boost by.
571 *
572 * @return the boost amount.
573 */
574 public final float getAmount() {
575 return amount;
576 }
577 }
578}
Represents the game world.
Definition World.java:46
static void schedule(Task task)
Submits a new event.
Definition World.java:247
A collection of util methods and constants related to combat.
static boolean cancelEffect(Mob mob, CombatEffectType effect)
Cancels the effect in any context.
static boolean effect(Mob mob, CombatEffectType effect)
Applies the effect in any context.
A Hit object holds the damage amount and hitsplat data.
Definition Hit.java:10
void poison(PoisonType type)
Applies poison with an intensity of type to the entity.
Definition Mob.java:500
final MutableNumber getPoisonDamage()
Definition Mob.java:628
This class represents a character controlled by a player.
Definition Player.java:125
Represents a trainable and usable skill.
Definition Skill.java:18
void modifyLevel(Function< Integer, Integer > function)
Modifies the current level with a given function.
Definition Skill.java:281
static final int PRAYER
The prayer skill id.
Definition Skill.java:36
static final int RANGED
The ranged skill id.
Definition Skill.java:33
static final int FISHING
The fishing skill id.
Definition Skill.java:51
static final int DEFENCE
The defence skill id.
Definition Skill.java:24
int getLevel()
Gets the current skill level.
Definition Skill.java:205
static final int MAGIC
The magic skill id.
Definition Skill.java:39
static final int ATTACK
The attack skill id.
Definition Skill.java:21
static final int AGILITY
The agility skill id.
Definition Skill.java:69
static final int STRENGTH
The strength skill id.
Definition Skill.java:27
int getMaxLevel()
Gets the maximum skill level.
Definition Skill.java:214
static final int HITPOINTS
The hitpoints skill id.
Definition Skill.java:30
int getMaxLevel(int id)
Gets the highest possible level of a skill.
Skill get(int id)
Gets the skill for an id.
void refresh()
Refreshes all the skills for the mob.
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
The OutgoingPacket responsible for changing settings on a client.
The OutgoingPacket that sends a message to a Players chatbox in the client.
int incrementAndGet(int amount, int maximum)
Increments the value within this counter by amount to a maximum of maximum and then returns it.
void set(int value)
Sets the value within this container to rarity.
int get()
Gets the value present within this counter.
The enumerated type whose elements represent the boost types for potions.
final float getAmount()
Gets the amount this type will boost by.
final float amount
The amount this type will boost by.
final int base
The base which we will append by.
final int getBase()
Gets the base this type will boost by.
BoostType(int base, float boostAmount)
Creates a new BoostType.
abstract void onEffect(Player player)
The method executed when this potion type activated.
static void onPrayerEffect(Player player, boolean superPrayer)
The method that executes the prayer potion action.
static void onRestoreEffect(Player player, boolean superRestore)
The method that executes the restore potion action.
static Item getReplacementItem(Item item)
Retrieves the replacement item for item.
PotionData(int... ids)
Create a new PotionData.
final int[] getIds()
Gets the identifiers which represent this potion type.
static final ImmutableSet< PotionData > VALUES
Caches our enum values.
int getIdForDose(int dose)
Gets the item id for the specified dose.
static final Item VIAL
The default item representing the final potion dose.
static void onFishingEffect(Player player)
The method that executes the fishing potion action.
static void onSaradominEffect(Player player)
The method that executes the Saradomin brew action.
static Optional< PotionData > forId(int id)
Retrieves the potion consumable element for id.
static void onAgilityEffect(Player player)
The method that executes the agility potion action.
static void onAntiPoisonEffect(Player player, boolean superPotion, int length)
The method that executes the anti-poison potion action.
boolean canDrink(Player player)
The method which determines if the player can drink the potion.
static void onBasicEffect(Player player, int skill, BoostType type)
The method that executes the basic effect potion action that will append the level of skill.
static void onAntiFireEffect(Player player, boolean superVariant)
The method that executes the anti-fireRunes potion action.
static void modifySkill(Player player, int skill, double percentage, int base)
The method that executes the basic effect potion action that will append the level of skill.
final int[] ids
The identifiers which represent this potion type.
static void onZamorakEffect(Player player)
The method that executes the Zamorak brew action.
static void onEnergyEffect(Player player, boolean superPotion)
The method that executes the energy potion action.
The enumerated type whose elements represent the different levels of poison.
WEAK_NPC
The default poison type for poisonous NPCs.
The enumerated type whose values represent the collection of different combat effect types.