RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
PotionData.java
1package com.osroyale.content.consume;
2
3import com.google.common.collect.ImmutableSet;
4import com.google.common.collect.Sets;
5import com.osroyale.game.task.impl.AntiVenomTask;
6import com.osroyale.game.task.impl.SuperAntipoisonTask;
7import com.osroyale.game.world.World;
8import com.osroyale.game.world.entity.combat.CombatUtil;
9import com.osroyale.game.world.entity.combat.PoisonType;
10import com.osroyale.game.world.entity.combat.effect.CombatEffectType;
11import com.osroyale.game.world.entity.combat.hit.Hit;
12import com.osroyale.game.world.entity.mob.player.Player;
13import com.osroyale.game.world.entity.skill.Skill;
14import com.osroyale.game.world.items.Item;
15import com.osroyale.net.packet.out.SendConfig;
16import com.osroyale.net.packet.out.SendMessage;
17import com.osroyale.net.packet.out.SendPoison;
18import com.osroyale.net.packet.out.SendRunEnergy;
19
20import java.util.EnumSet;
21import java.util.Optional;
22
49
50public enum PotionData {
51 STAMINA__POTION(12625, 12627, 12629, 12631) {
52 @Override
53 public void onEffect(Player player) {
54 PotionData.onEnergyEffect(player, true);
55 player.energyRate = 200;
56 }
57 },
58 SUPER_COMBAT_POTION(12695, 12697, 12699, 12701) {
59 @Override
60 public void onEffect(Player player) {
61 PotionData.onBasicEffect(player, Skill.ATTACK, BoostType.SUPER);
62 PotionData.onBasicEffect(player, Skill.STRENGTH, BoostType.SUPER);
63 PotionData.onBasicEffect(player, Skill.DEFENCE, BoostType.SUPER);
64 }
65 },
66 ZAMORAK_BREW(2450, 189, 191, 193) {
67 @Override
68 public void onEffect(Player player) {
69 PotionData.onZamorakEffect(player);
70 }
71 },
72 SARADOMIN_BREW(6685, 6687, 6689, 6691) {
73 @Override
74 public void onEffect(Player player) {
75 PotionData.onSaradominEffect(player);
76 }
77 },
78 ANTIDOTE_PLUS(5943, 5945, 5947, 5949) {
79 @Override
80 public void onEffect(Player player) {
81 PotionData.onAntiPoisonEffect(player, true, 1000);
82 }
83 },
84 ANTIDOTE_PLUS_PLUS(5952, 5954, 5956, 5958) {
85 @Override
86 public void onEffect(Player player) {
87 PotionData.onAntiPoisonEffect(player, true, 1200);
88 }
89 },
90 AGILITY_POTION(3032, 3034, 3036, 3038) {
91 @Override
92 public void onEffect(Player player) {
93 PotionData.onAgilityEffect(player);
94 }
95 },
96 FISHING_POTION(2438, 151, 153, 155) {
97 @Override
98 public void onEffect(Player player) {
99 PotionData.onFishingEffect(player);
100 }
101 },
102 RANGE_POTIONS(2444, 169, 171, 173) {
103 @Override
104 public void onEffect(Player player) {
105 PotionData.onBasicEffect(player, Skill.RANGED, BoostType.RANGING);
106 }
107 },
108 ENERGY_POTIONS(3008, 3010, 3012, 3014) {
109 @Override
110 public void onEffect(Player player) {
111 PotionData.onEnergyEffect(player, false);
112 }
113 },
114 SUPER_ENERGY_POTIONS(3016, 3018, 3020, 3022) {
115 @Override
116 public void onEffect(Player player) {
117 PotionData.onEnergyEffect(player, true);
118 }
119 },
120 MAGIC_POTIONS(3040, 3042, 3044, 3046) {
121 @Override
122 public void onEffect(Player player) {
123 PotionData.onBasicEffect(player, Skill.MAGIC, BoostType.MAGIC);
124 }
125 },
126 DEFENCE_POTIONS(2432, 133, 135, 137) {
127 @Override
128 public void onEffect(Player player) {
129 PotionData.onBasicEffect(player, Skill.DEFENCE, BoostType.NORMAL);
130 }
131 },
132 STRENGTH_POTIONS(113, 115, 117, 119) {
133 @Override
134 public void onEffect(Player player) {
135 PotionData.onBasicEffect(player, Skill.STRENGTH, BoostType.NORMAL);
136 }
137 },
138 ATTACK_POTIONS(2428, 121, 123, 125) {
139 @Override
140 public void onEffect(Player player) {
141 PotionData.onBasicEffect(player, Skill.ATTACK, BoostType.NORMAL);
142 }
143 },
144 SUPER_DEFENCE_POTIONS(2442, 163, 165, 167) {
145 @Override
146 public void onEffect(Player player) {
147 PotionData.onBasicEffect(player, Skill.DEFENCE, BoostType.SUPER);
148 }
149 },
150 SUPER_ATTACK_POTIONS(2436, 145, 147, 149) {
151 @Override
152 public void onEffect(Player player) {
153 PotionData.onBasicEffect(player, Skill.ATTACK, BoostType.SUPER);
154 }
155 },
156 SUPER_STRENGTH_POTIONS(2440, 157, 159, 161) {
157 @Override
158 public void onEffect(Player player) {
159 PotionData.onBasicEffect(player, Skill.STRENGTH, BoostType.SUPER);
160 }
161 },
162 RESTORE_POTIONS(2430, 127, 129, 131) {
163 @Override
164 public void onEffect(Player player) {
165 onRestoreEffect(player, false);
166 }
167 },
168 SUPER_RESTORE_POTIONS(3024, 3026, 3028, 3030) {
169 @Override
170 public void onEffect(Player player) {
171 PotionData.onRestoreEffect(player, true);
172 int realLevel = player.skills.getMaxLevel(Skill.PRAYER);
173 player.skills.get(Skill.PRAYER).modifyLevel(level -> level + (int) Math.floor(8 + (realLevel * 0.25)));
174 player.skills.refresh(Skill.PRAYER);
175 }
176 },
177 PRAYER_POTIONS(2434, 139, 141, 143) {
178 @Override
179 public void onEffect(Player player) {
180 PotionData.onPrayerEffect(player, false);
181 }
182 },
183 SUPER_PRAYER_POTIONS(15328, 15329, 15330, 15331) {
184 @Override
185 public void onEffect(Player player) {
186 PotionData.onPrayerEffect(player, true);
187 }
188 },
189 ANTIFIRE_POTIONS(2452, 2454, 2456, 2458) {
190 @Override
191 public void onEffect(Player player) {
192 PotionData.onAntiFireEffect(player, false);
193 }
194 },
195 SUPER_ANTIFIRE_POTIONS(15304, 15305, 15306, 15307) {
196 @Override
197 public void onEffect(Player player) {
198 PotionData.onAntiFireEffect(player, true);
199 }
200 },
201 ANTIPOISON_POTIONS(2446, 175, 177, 179) {
202 @Override
203 public void onEffect(Player player) {
204 PotionData.onAntiPoisonEffect(player, false, 0);
205 }
206 },
207 SUPER_ANTIPOISON_POTIONS(2448, 181, 183, 185) {
208 @Override
209 public void onEffect(Player player) {
210 PotionData.onAntiPoisonEffect(player, true, 500);
211 }
212 },
213 ANTI_VENOM(12905, 12907, 12909, 12911) {
214 @Override
215 public void onEffect(Player player) {
216 player.unvenom();
217 player.unpoison();
218
219 if (player.getPoisonImmunity().get() <= 0) {
220 player.send(new SendMessage("You have been granted immunity against poison."));
221 World.schedule(new SuperAntipoisonTask(player).attach(player));
222 } else if (player.getPoisonImmunity().get() > 0) {
223 player.send(new SendMessage("Your immunity against poison has been restored!"));
224 }
225 player.getPoisonImmunity().set(1200);
226
227 if (player.getVenomImmunity().get() <= 0) {
228 player.send(new SendMessage("You have been granted immunity against venom."));
229 World.schedule(new AntiVenomTask(player).attach(player));
230 } else if (player.getVenomImmunity().get() > 0) {
231 player.send(new SendMessage("Your immunity against venom has been restored!"));
232 }
233 player.getVenomImmunity().set(300);
234 }
235 },
236 ANTI_VENOM_PLUS(12913, 12915, 12917, 12919) {
237 @Override
238 public void onEffect(Player player) {
239 player.unvenom();
240 player.unpoison();
241
242 if (player.getPoisonImmunity().get() <= 0) {
243 player.send(new SendMessage("You have been granted immunity against poison."));
244 World.schedule(new SuperAntipoisonTask(player).attach(player));
245 } else if (player.getPoisonImmunity().get() > 0) {
246 player.send(new SendMessage("Your immunity against poison has been restored!"));
247 }
248 player.getPoisonImmunity().set(1500);
249
250 if (player.getVenomImmunity().get() <= 0) {
251 player.send(new SendMessage("You have been granted immunity against venom."));
252 World.schedule(new AntiVenomTask(player).attach(player));
253 } else if (player.getVenomImmunity().get() > 0) {
254 player.send(new SendMessage("Your immunity against venom has been restored!"));
255 }
256 player.getVenomImmunity().set(3000);
257 }
258 };
259
263 private static final ImmutableSet<PotionData> VALUES = Sets.immutableEnumSet(EnumSet.allOf(PotionData.class));
264
268 private static final Item VIAL = new Item(229);
269
273 private final int[] ids;
274
280 PotionData(int... ids) {
281 this.ids = ids;
282 }
283
289 private static void onFishingEffect(Player player) {
290 player.skills.get(Skill.FISHING).modifyLevel(level -> level + 3);
291 player.skills.refresh(Skill.FISHING);
292 }
293
299 private static void onAgilityEffect(Player player) {
300 player.skills.get(Skill.AGILITY).modifyLevel(level -> level + 3);
301 player.skills.refresh(Skill.AGILITY);
302 }
303
309 private static void onSaradominEffect(Player player) {
310 modifySkill(player, Skill.HITPOINTS, 0.15, 2);
311 modifySkill(player, Skill.DEFENCE, 0.20, 2);
312 modifySkill(player, Skill.ATTACK, -0.10, 2);
313 modifySkill(player, Skill.STRENGTH, -0.10, 2);
314 modifySkill(player, Skill.RANGED, -0.10, 2);
315 modifySkill(player, Skill.MAGIC, -0.10, 2);
316 }
317
323 private static void onZamorakEffect(Player player) {
324 modifySkill(player, Skill.ATTACK, 0.20, 2);
325 modifySkill(player, Skill.STRENGTH, 0.12, 2);
326 modifySkill(player, Skill.DEFENCE, -0.10, 2);
327 modifySkill(player, Skill.HITPOINTS, -0.10, 2);
328 modifySkill(player, Skill.PRAYER, 0.10, 0);
329 }
330
337 private static void onPrayerEffect(Player player, boolean superPrayer) {
338 int realLevel = player.skills.get(Skill.PRAYER).getMaxLevel();
339 player.skills.get(Skill.PRAYER).modifyLevel(level -> level + (int) Math.floor(7 + (realLevel * (superPrayer ? 0.35 : 0.25))));
340 player.skills.refresh(Skill.PRAYER);
341
342 }
343
352 public static void onAntiPoisonEffect(Player player, boolean superPotion, int length) {
353 if (player.isVenomed()) {
354 player.getVenomDamage().set(0);
356 player.poison(PoisonType.WEAK_NPC);
357 return;
358 }
359
360 if (player.isPoisoned()) {
361 player.getPoisonDamage().set(0);
363 player.send(new SendConfig(174, 0));
364 player.send(new SendMessage("You have been cured of your poison!"));
365 player.send(new SendPoison(SendPoison.PoisonType.NO_POISON));
366 }
367
368 if (superPotion) {
369 if (length > 0 && player.getPoisonImmunity().get() <= 0) {
370 player.send(new SendMessage("You have been granted immunity against poison."));
371 player.getPoisonImmunity().incrementAndGet(length);
372 World.schedule(new SuperAntipoisonTask(player).attach(player));
373 } else if (player.getPoisonImmunity().get() > 0) {
374 player.send(new SendMessage("Your immunity against poison has been restored!"));
375 player.getPoisonImmunity().set(length);
376 }
377 }
378 }
379
387 private static void onEnergyEffect(Player player, boolean superPotion) {
388 int amount = superPotion ? 20 : 10;
389 int energy = player.runEnergy;
390
391 if (amount + energy > 100) {
392 player.runEnergy = 100;
393 } else {
394 player.runEnergy += amount;
395 }
396
397 player.send(new SendRunEnergy());
398 }
399
405 private static void onRestoreEffect(Player player, boolean superRestore) {
406 for (int index = 0; index <= 6; index++) {
407 if ((index == Skill.PRAYER) || (index == Skill.HITPOINTS)) {
408 continue;
409 }
410
411 Skill skill = player.skills.get(index);
412 int realLevel = skill.getMaxLevel();
413
414 if (skill.getLevel() >= realLevel) {
415 continue;
416 }
417
418 int formula = superRestore ? (int) Math.floor(8 + (realLevel * 0.25)) : (int) Math.floor(10 + (realLevel * 0.30));
419 player.skills.get(index).modifyLevel(level -> level + formula);
420 player.skills.refresh(index);
421 }
422 }
423
430 private static void onAntiFireEffect(Player player, boolean superVariant) {
431 if (superVariant) {
432 CombatUtil.effect(player, CombatEffectType.SUPER_ANTIFIRE_POTION);
433 } else {
434 CombatUtil.effect(player, CombatEffectType.ANTIFIRE_POTION);
435 }
436 }
437
444 private static void onBasicEffect(Player player, int skill, BoostType type) {
445 modifySkill(player, skill, type.amount, type.base);
446 }
447
454 private static void modifySkill(Player player, int skill, double percentage, int base) {
455 Skill s = player.skills.get(skill);
456 int realLevel = s.getMaxLevel();
457
458 final int boostLevel = (int) (realLevel * percentage + base);
459
460 int cap = s.getLevel();
461 if (cap < realLevel + boostLevel) {
462 cap = realLevel + boostLevel;
463 }
464
465 if (skill == Skill.HITPOINTS && boostLevel < 0) {
466 int damage = boostLevel;
467 if (player.getCurrentHealth() + damage <= 0) damage = -player.getCurrentHealth() + 1;
468 player.damage(new Hit(-damage));
469 } else {
470 player.skills.get(skill).modifyLevel(level -> level + boostLevel, 0, cap);
471 }
472
473 player.skills.refresh(skill);
474 }
475
483 public static Item getReplacementItem(Item item) {
484 Optional<PotionData> potion = forId(item.getId());
485 if (potion.isPresent()) {
486 int length = potion.get().getIds().length;
487 for (int index = 0; index < length; index++) {
488 if (potion.get().getIds()[index] == item.getId() && index + 1 < length) {
489 return new Item(potion.get().getIds()[index + 1]);
490 }
491 }
492 }
493 return VIAL;
494 }
495
503 public static Optional<PotionData> forId(int id) {
504 for (PotionData potion : VALUES) {
505 for (int potionId : potion.getIds()) {
506 if (id == potionId) {
507 return Optional.of(potion);
508 }
509 }
510 }
511 return Optional.empty();
512 }
513
519 public abstract void onEffect(Player player);
520
526 public boolean canDrink(Player player) {
527 return true;
528 }
529
535 public final int[] getIds() {
536 return ids;
537 }
538
545 public int getIdForDose(int dose) {
546 return ids[ids.length - dose];
547 }
548
555 public enum BoostType {
556 NORMAL(3, .10F),
557 RANGING(4, .10F),
558 MAGIC(4, 0),
559 SUPER(5, .15F);
560
564 private final int base;
565
569 private final float amount;
570
576 BoostType(int base, float boostAmount) {
577 this.base = base;
578 this.amount = boostAmount;
579 }
580
586 public final int getBase() {
587 return base;
588 }
589
595 public final float getAmount() {
596 return amount;
597 }
598 }
599}
static void schedule(Task task)
Definition World.java:284
static boolean effect(Mob mob, CombatEffectType effect)
static boolean cancelEffect(Mob mob, CombatEffectType effect)
void poison(PoisonType type)
Definition Mob.java:537
void modifyLevel(Function< Integer, Integer > function)
Definition Skill.java:318
static void onAntiPoisonEffect(Player player, boolean superPotion, int length)
static Item getReplacementItem(Item item)
abstract void onEffect(Player player)
static Optional< PotionData > forId(int id)