From 94a55190ee10e709d5d973ec87f75b0d17aa66ea Mon Sep 17 00:00:00 2001 From: Trevor Date: Wed, 4 Oct 2023 23:48:51 +0000 Subject: [PATCH] Barbarian potion refactor Fixed barbarian potions that can take either a roe or caviar from consuming both Corrected level requirement and product potion id for hunter and antifire mixes Corrected input potion id for fishing mix Implemented antidote+ mix Fixed level requirement for super energy mix Fixed duration of antipoison mix (now 90 seconds) --- .../content/data/consumables/Consumables.java | 4 +- .../skill/herblore/BarbarianMixListener.kt | 59 ++++++++++ .../skill/herblore/BarbarianMixPlugin.java | 62 ---------- .../skill/herblore/BarbarianPotion.java | 103 ----------------- .../global/skill/herblore/BarbarianPotion.kt | 108 ++++++++++++++++++ 5 files changed, 170 insertions(+), 166 deletions(-) create mode 100644 Server/src/main/content/global/skill/herblore/BarbarianMixListener.kt delete mode 100644 Server/src/main/content/global/skill/herblore/BarbarianMixPlugin.java delete mode 100644 Server/src/main/content/global/skill/herblore/BarbarianPotion.java create mode 100644 Server/src/main/content/global/skill/herblore/BarbarianPotion.kt diff --git a/Server/src/main/content/data/consumables/Consumables.java b/Server/src/main/content/data/consumables/Consumables.java index c70db0b5f..b8d3b4cf9 100644 --- a/Server/src/main/content/data/consumables/Consumables.java +++ b/Server/src/main/content/data/consumables/Consumables.java @@ -350,7 +350,7 @@ public enum Consumables { PRAYERMIX(new BarbarianMix(new int[] {11465, 11467}, new MultiEffect(new PrayerEffect(7, 0.25), new HealingEffect(6)))), ZAMMY_MIX(new BarbarianMix(new int[] {11521, 11523}, new MultiEffect(new DamageEffect(10, true), new SkillEffect(Skills.ATTACK, 0, 0.15), new SkillEffect(Skills.STRENGTH, 0, 0.25), new SkillEffect(Skills.DEFENCE, 0, -0.1), new RandomPrayerEffect(0, 10)))), ATT_MIX(new BarbarianMix(new int[] {11429, 11431}, new MultiEffect(new SkillEffect(Skills.ATTACK, 3, 0.1), new HealingEffect(3)))), - ANTIP_MIX(new BarbarianMix(new int[] {11433, 11435}, new MultiEffect(new AddTimerEffect("poison:immunity", 143), new HealingEffect(3)))), + ANTIP_MIX(new BarbarianMix(new int[] {11433, 11435}, new MultiEffect(new AddTimerEffect("poison:immunity", secondsToTicks(90)), new HealingEffect(3)))), RELIC_MIX(new BarbarianMix(new int[] {11437, 11439}, new MultiEffect(new RemoveTimerEffect("disease"), new SetAttributeEffect("disease:immunity", 300), new HealingEffect(3)))), STR_MIX(new BarbarianMix(new int[] {11443, 11441}, new MultiEffect(new SkillEffect(Skills.STRENGTH, 3, 0.1), new HealingEffect(3)))), RESTO_MIX(new BarbarianMix(new int[] {11449, 11451}, new MultiEffect(new RestoreEffect(10, 0.3), new HealingEffect(3)))), @@ -364,6 +364,8 @@ public enum Consumables { SUPER_ENERGY_MIX(new BarbarianMix(new int[] {11481, 11483}, new MultiEffect(new EnergyEffect(20), new HealingEffect(6)))), HUNTING_MIX(new BarbarianMix(new int[] {11517, 11519}, new MultiEffect(new SkillEffect(Skills.HUNTER, 3, 0), new HealingEffect(6)))), SUPER_STR_MIX(new BarbarianMix(new int[] {11485, 11487}, new MultiEffect(new SkillEffect(Skills.STRENGTH, 5, 0.15), new HealingEffect(6)))), + ANTIDOTE_PLUS_MIX(new BarbarianMix(new int[] {11501, 11503}, new MultiEffect(new AddTimerEffect("poison:immunity", minutesToTicks(9)), new RandomHealthEffect(3, 7)))), + ANTIP_SUPERMIX(new BarbarianMix(new int[] {11473, 11475}, new MultiEffect(new AddTimerEffect("poison:immunity", minutesToTicks(6)), new RandomHealthEffect(3, 7)))), /** Stealing creation potions */ SC_PRAYER(new Potion(new int[] {14207, 14209, 14211, 14213, 14215}, new PrayerEffect(7, 0.25))), diff --git a/Server/src/main/content/global/skill/herblore/BarbarianMixListener.kt b/Server/src/main/content/global/skill/herblore/BarbarianMixListener.kt new file mode 100644 index 000000000..20077f2d3 --- /dev/null +++ b/Server/src/main/content/global/skill/herblore/BarbarianMixListener.kt @@ -0,0 +1,59 @@ +package content.global.skill.herblore + +import content.global.skill.herblore.BarbarianPotion +import core.game.node.entity.skill.Skills +import core.game.node.entity.player.Player +import core.game.node.item.Item +import core.game.node.Node +import core.game.interaction.InteractionListener +import core.game.interaction.IntType +import core.api.hasLevelStat +import core.api.sendMessage +import core.api.removeItem +import core.api.addItem +import core.api.rewardXP + +/** + * Represents the barbarian mixing listener. + * @author 'Vexia + * @author treevar + * @version 2.0 + */ + +class BarbarianMixListener : InteractionListener { + override fun defineListeners(){ + for (potion in BarbarianPotion.values()) { + if (potion.isBoth()) { + onUseWith(IntType.ITEM, potion.getItem(), 11324) { player, used, with -> //Roe + handle(player, used, with); + } + } + onUseWith(IntType.ITEM, potion.getItem(), 11326) { player, used, with -> //Caviar + handle(player, used, with); + } + } + } + + fun handle(player: Player, inputPotion: Node, egg: Node): Boolean { + val potion: BarbarianPotion? = BarbarianPotion.forId(inputPotion.getId()) + if(potion == null){ + return false + } + + if (!hasLevelStat(player, Skills.HERBLORE, potion.getLevel())) { + sendMessage(player, "You need a herblore level of " + potion.getLevel().toString() + " to make this mix.") + return true + } + + if(!removeItem(player, potion.getItem())) { //Remove input potion + return false + } + if(!removeItem(player, egg.getId())) { //Remove egg used + addItem(player, potion.getItem()) //Add potion back to inventory if we can't remove the egg + return false + } + addItem(player, potion.getProduct()) //Add output potion + rewardXP(player, Skills.HERBLORE, potion.getExp()) //Add exp + return true + } +} diff --git a/Server/src/main/content/global/skill/herblore/BarbarianMixPlugin.java b/Server/src/main/content/global/skill/herblore/BarbarianMixPlugin.java deleted file mode 100644 index f82eda97c..000000000 --- a/Server/src/main/content/global/skill/herblore/BarbarianMixPlugin.java +++ /dev/null @@ -1,62 +0,0 @@ -package content.global.skill.herblore; - -import core.game.node.entity.skill.Skills; -import core.game.interaction.NodeUsageEvent; -import core.game.interaction.UseWithHandler; -import core.game.node.entity.player.Player; -import core.game.node.item.Item; -import core.plugin.Initializable; -import core.plugin.Plugin; - -/** - * Represents the barbarian mixing plugin. - * @author 'Vexia - * @version 1.0 - */ -@Initializable -public final class BarbarianMixPlugin extends UseWithHandler { - - /** - * Constructs a new {@code BarbarianMixPlugin} {@Code Object}. - */ - public BarbarianMixPlugin() { - super(123, 177, 4846, 117, 129, 3012, 135, 3036, 9743, 141, 147, 183, 143, 3020, 10002, 159, 3028, 165, 2456, 171, 3044, 191); - } - - @Override - public Plugin newInstance(Object arg) throws Throwable { - addHandler(11324, ITEM_TYPE, this); - addHandler(11326, ITEM_TYPE, this); - return this; - } - - @Override - public boolean handle(NodeUsageEvent event) { - final Player player = event.getPlayer(); - if (player == null) { - return true; - } - final BarbarianPotion potion = BarbarianPotion.forId(((Item) event.getUsedWith()).getId()); - if (potion == null) { - return true; - } - if (!potion.isBoth() && event.getUsedItem().getId() == 11324 || ((Item) event.getUsedWith()).getId() == 11324) { - return true; - } - if (player.getSkills().getLevel(Skills.HERBLORE) < potion.getLevel()) { - player.getPacketDispatch().sendMessage("You need a herblore level of " + potion.getLevel() + " to make this mix."); - return true; - } - if (potion.getItem() == event.getUsedItem().getId() || potion.getItem() == ((Item) event.getUsedWith()).getId()) { - player.getInventory().remove(new Item(potion.getItem(), 1)); - player.getInventory().add(new Item(potion.getProduct(), 1)); - player.getSkills().addExperience(Skills.HERBLORE, potion.getExp(), true); - if (potion.isBoth()) { - player.getInventory().remove(new Item(11324, 1)); - } - player.getInventory().remove(new Item(11326, 1)); - } - return true; - } - -} diff --git a/Server/src/main/content/global/skill/herblore/BarbarianPotion.java b/Server/src/main/content/global/skill/herblore/BarbarianPotion.java deleted file mode 100644 index 623df9590..000000000 --- a/Server/src/main/content/global/skill/herblore/BarbarianPotion.java +++ /dev/null @@ -1,103 +0,0 @@ -package content.global.skill.herblore; - -/** - * Represents the barbarian potion. - * @author 'Vexia - */ -public enum BarbarianPotion { - ATTACK_POTION(123, 4, 11429, 8, true), ANTI_POISION_POTION(177, 6, 11433, 12, true), RELIC(4846, 9, 11437, 14, true), STRENGTH_POTION(117, 14, 11443, 17, true), RESTORE_POTION(129, 24, 11449, 21, true), ENERGY_POTION(3012, 29, 11453, 23, false), DEFENCE_POTION(135, 33, 11457, 25, false), AGILITY_POTION(3036, 37, 11461, 27, false), COMBAT_POTION(9743, 40, 11445, 28, false), PRAYER_POTION(141, 42, 11465, 29, false), SUPER_ATTACK_POTION(147, 47, 11469, 33, false), SUPER_ANTIPOISION_POTION(183, 51, 11473, 35, false), FISHING_POTION(143, 53, 11477, 38, false), SUPER_ENERGY_POTION(3020, 59, 11481, 42, false), HUNTER_POTION(10002, 11517, 58, 40, false), SUPER_STRENGTH_POTION(159, 59, 11485, 42, false), SUPER_RESTORE(3028, 67, 11493, 48, false), SUPER_DEFENCE_POTION(165, 71, 11497, 50, false), ANTIFIRE_POTION(2456, 11505, 75, 53, false), RANGING_POTION(171, 80, 11509, 54, false), MAGIC_POTION(3044, 83, 11513, 57, false), ZAMORAK_BREW(191, 85, 11521, 58, false); - - /** - * Constructs a new {@code BarbarianPotion} {@Code Object}. - * @param item the item. - * @param product the product. - * @param exp the exp. - * @param both if both can be added(roe, cavier). - */ - BarbarianPotion(int item, int level, int product, double exp, boolean both) { - this.item = item; - this.level = level; - this.product = product; - this.exp = exp; - this.both = both; - } - - /** - * The item id. - */ - private int item; - - /** - * The product item id. - */ - private int product; - - /** - * The level required. - */ - private int level; - - /** - * the exp gained. - */ - private double exp; - - /** - * Represents if both Roe & Cavier can be added. - */ - private boolean both; - - /** - * Gets the item. - * @return The item. - */ - public int getItem() { - return item; - } - - /** - * Gets the product. - * @return The product. - */ - public int getProduct() { - return product; - } - - /** - * Gets the level. - * @return The level. - */ - public int getLevel() { - return level; - } - - /** - * Gets the exp. - * @return The exp. - */ - public double getExp() { - return exp; - } - - /** - * Gets the both. - * @return The both. - */ - public boolean isBoth() { - return both; - } - - /** - * Gets the value from the id. - * @param id the id. - * @return the value. - */ - public static BarbarianPotion forId(int id) { - for (BarbarianPotion pot : BarbarianPotion.values()) { - if (pot.getItem() == id) { - return pot; - } - } - return null; - } -} diff --git a/Server/src/main/content/global/skill/herblore/BarbarianPotion.kt b/Server/src/main/content/global/skill/herblore/BarbarianPotion.kt new file mode 100644 index 000000000..5876c4018 --- /dev/null +++ b/Server/src/main/content/global/skill/herblore/BarbarianPotion.kt @@ -0,0 +1,108 @@ +package content.global.skill.herblore; + +/** + * Represents the barbarian potion. + * @author 'Vexia + * @author treevar + */ +public enum class BarbarianPotion { + ATTACK_POTION(123, 4, 11429, 8.0, true), ANTI_POISION_POTION(177, 6, 11433, 12.0, true), RELIC(4846, 9, 11437, 14.0, true), STRENGTH_POTION(117, 14, 11443, 17.0, true), RESTORE_POTION(129, 24, 11449, 21.0, true), ENERGY_POTION(3012, 29, 11453, 23.0, false), DEFENCE_POTION(135, 33, 11457, 25.0, false), AGILITY_POTION(3036, 37, 11461, 27.0, false), COMBAT_POTION(9743, 40, 11445, 28.0, false), PRAYER_POTION(141, 42, 11465, 29.0, false), SUPER_ATTACK_POTION(147, 47, 11469, 33.0, false), SUPER_ANTIPOISION_POTION(183, 51, 11473, 35.0, false), FISHING_POTION(153, 53, 11477, 38.0, false), SUPER_ENERGY_POTION(3020, 56, 11481, 42.0, false), HUNTER_POTION(10002, 58, 11517, 40.0, false), SUPER_STRENGTH_POTION(159, 59, 11485, 42.0, false), SUPER_RESTORE(3028, 67, 11493, 48.0, false), SUPER_DEFENCE_POTION(165, 71, 11497, 50.0, false), ANTIDOTE_PLUS(5947, 74, 11501, 52.0, false), ANTIFIRE_POTION(2456, 75, 11505, 53.0, false), RANGING_POTION(171, 80, 11509, 54.0, false), MAGIC_POTION(3044, 83, 11513, 57.0, false), ZAMORAK_BREW(191, 85, 11521, 58.0, false); + + /** + * Constructs a new {@code BarbarianPotion} {@Code Object}. + * @param item the input potion id. + * @param level the level requirement to make. + * @param product the product potion id. + * @param exp the exp rewarded. + * @param both if both can be added(roe, cavier). + */ + constructor(item: Int, level: Int, product: Int, exp: Double, both: Boolean) { + this.item = item; + this.level = level; + this.product = product; + this.exp = exp; + this.both = both; + } + + /** + * The item id. + */ + private val item: Int; + + /** + * The product item id. + */ + private val product: Int; + + /** + * The level required. + */ + private val level: Int; + + /** + * the exp gained. + */ + private val exp: Double; + + /** + * Represents if both Roe & Cavier can be added. + */ + private val both: Boolean; + + /** + * Gets the item. + * @return The item. + */ + fun getItem(): Int { + return item; + } + + /** + * Gets the product. + * @return The product. + */ + fun getProduct(): Int { + return product; + } + + /** + * Gets the level. + * @return The level. + */ + fun getLevel(): Int { + return level; + } + + /** + * Gets the exp. + * @return The exp. + */ + fun getExp(): Double { + return exp; + } + + /** + * Gets whether roe and caviar can be used. + * @return true if both, false if only caviar. + */ + fun isBoth(): Boolean { + return both; + } + + companion object { + /** + * Gets the barbarian potion from the input potion id + * @param id the id of the input potion. + * @return the barbarian potion that takes the id as input. + */ + @JvmStatic + fun forId(id: Int): BarbarianPotion? { + for (pot in BarbarianPotion.values()) { + if (pot.getItem() == id) { + return pot; + } + } + return null; + } + } +}