From f5711fcf8fe31dfb98a08de12e7ab6ac4906ed00 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Tue, 6 Jun 2023 08:02:55 +0000 Subject: [PATCH] Fixed plank make without sufficient funds Fixed potions not taking doses in some cases --- .../skill/magic/lunar/LunarListeners.kt | 2 +- .../skill/magic/lunar/StatBoostSpell.java | 19 +++++---- .../skill/magic/lunar/StatRestoreSpell.java | 40 +++++++++---------- .../src/main/core/game/consumable/Potion.java | 4 +- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/Server/src/main/content/global/skill/magic/lunar/LunarListeners.kt b/Server/src/main/content/global/skill/magic/lunar/LunarListeners.kt index ba2ae6e9a..dbbc52752 100644 --- a/Server/src/main/content/global/skill/magic/lunar/LunarListeners.kt +++ b/Server/src/main/content/global/skill/magic/lunar/LunarListeners.kt @@ -224,7 +224,7 @@ class LunarListeners : SpellListener("lunar"), Commands { sendMessage(player, "You need to use this spell on logs.") return } - if (!removeItem(player, Item(Items.COINS_995, plankType.price))) { + if (amountInInventory(player, Items.COINS_995) < plankType.price || !removeItem(player, Item(Items.COINS_995, plankType.price))) { sendMessage(player, "You need ${plankType.price} coins to convert that log into a plank.") return } diff --git a/Server/src/main/content/global/skill/magic/lunar/StatBoostSpell.java b/Server/src/main/content/global/skill/magic/lunar/StatBoostSpell.java index 7e6d6d842..c77e03745 100644 --- a/Server/src/main/content/global/skill/magic/lunar/StatBoostSpell.java +++ b/Server/src/main/content/global/skill/magic/lunar/StatBoostSpell.java @@ -53,22 +53,16 @@ public final class StatBoostSpell extends MagicSpell { List pl = RegionManager.getLocalPlayers(player, 1); int plSize = pl.size() - 1; int doses = potion.getDose(item); - if (plSize > doses) { - player.getPacketDispatch().sendMessage("You don't have enough doses."); - return false; - } - if (doses > plSize) { - doses = plSize; - } if (pl.size() == 0) { return false; } if (!super.meetsRequirements(player, true, false)) { return false; } - int size = 1; + int size = 0; for (Player players : pl) { Player o = (Player) players; + if (size >= doses) break; if (!o.isActive() || o.getLocks().isInteractionLocked() || o == player) { continue; } @@ -80,7 +74,7 @@ public final class StatBoostSpell extends MagicSpell { potion.getEffect().activate(o); size++; } - if (size == 1) { + if (size == 0) { player.getPacketDispatch().sendMessage("There is nobody around that has accept aid on to share the potion with you."); return false; } @@ -90,7 +84,12 @@ public final class StatBoostSpell extends MagicSpell { player.animate(ANIMATION); player.graphics(GRAPHICS); player.getInventory().remove(item); - player.getInventory().add(new Item(potion.getIds()[size - 1])); + int newIndex = (potion.getIds().length - doses) + size; + if (newIndex > potion.getIds().length - 1) { + player.getInventory().add(new Item(229)); + return true; + } + player.getInventory().add(new Item(potion.getIds()[newIndex])); return true; } } diff --git a/Server/src/main/content/global/skill/magic/lunar/StatRestoreSpell.java b/Server/src/main/content/global/skill/magic/lunar/StatRestoreSpell.java index c56122ca3..6fad08ad4 100644 --- a/Server/src/main/content/global/skill/magic/lunar/StatRestoreSpell.java +++ b/Server/src/main/content/global/skill/magic/lunar/StatRestoreSpell.java @@ -25,8 +25,7 @@ public class StatRestoreSpell extends MagicSpell { private static final Animation ANIMATION = new Animation(4413); private static final Graphics GRAPHICS = new Graphics(733, 130); - - private static final int[] IDS = new int[] { 2434, 139, 141, 143, 2430, 127, 129, 131, 3024, 3026, 3028, 3030 }; + private static final Consumables[] acceptedPotions = new Consumables[] { Consumables.RESTORE, Consumables.SUPER_RESTO, Consumables.PRAYER, Consumables.ENERGY, Consumables.SUPER_ENERGY }; public StatRestoreSpell() { super(SpellBook.LUNAR, 81, 84, null, null, null, new Item[] { new Item(Runes.ASTRAL_RUNE.getId(), 2), new Item(Runes.EARTH_RUNE.getId(), 10), new Item(Runes.WATER_RUNE.getId(), 10) }); @@ -48,28 +47,22 @@ public class StatRestoreSpell extends MagicSpell { player.getPacketDispatch().sendMessage("You can only cast this spell on a potion."); return false; } - if (!item.getDefinition().isTradeable() || !isRestore(item.getId())) { + if (!item.getDefinition().isTradeable() || !isRestore(potion)) { player.getPacketDispatch().sendMessage("You can't cast this spell on that item."); return false; } - List pl = RegionManager.getLocalPlayers(player, 1); + List pl = RegionManager.getLocalPlayers(player, 2); int plSize = pl.size() - 1; int doses = potion.getDose(item); - if (plSize > doses) { - player.getPacketDispatch().sendMessage("You don't have enough doses."); - return false; - } - if (doses > plSize) { - doses = plSize; - } if (pl.size() == 0) { return false; } if (!super.meetsRequirements(player, true, false)) { return false; } - int size = 1; - for (Player players : pl) { + int size = 0; + for (Player players : pl) { + if (size >= doses) break; Player o = (Player) players; if (!o.isActive() || o.getLocks().isInteractionLocked() || o == player) { continue; @@ -78,11 +71,10 @@ public class StatRestoreSpell extends MagicSpell { continue; } o.graphics(GRAPHICS); - player.getPacketDispatch().sendMessage("You can only cast this spell on a potion."); potion.getEffect().activate(o); size++; } - if (size == 1) { + if (size == 0) { player.getPacketDispatch().sendMessage("There is nobody around that has accept aid on to share the potion with you."); return false; } @@ -92,16 +84,20 @@ public class StatRestoreSpell extends MagicSpell { player.animate(ANIMATION); player.graphics(GRAPHICS); player.getInventory().remove(item); - player.getInventory().add(new Item(potion.getIds()[size - 1])); + int newIndex = (potion.getIds().length - doses) + size; + if (newIndex > potion.getIds().length - 1) { + player.getInventory().add(new Item(229)); + return true; + } + player.getInventory().add(new Item(potion.getIds()[newIndex])); return true; } - private boolean isRestore(int id) { - for (int i : IDS) { - if (i == id) { - return true; - } - } + private boolean isRestore(Potion p) { + for (int i = 0; i < acceptedPotions.length; i++) { + if (p == acceptedPotions[i].getConsumable()) + return true; + } return false; } diff --git a/Server/src/main/core/game/consumable/Potion.java b/Server/src/main/core/game/consumable/Potion.java index a9f9506ad..e715c6f69 100644 --- a/Server/src/main/core/game/consumable/Potion.java +++ b/Server/src/main/core/game/consumable/Potion.java @@ -62,7 +62,9 @@ public class Potion extends Drink { } } - public static int getDose(Item potion){ + public int getDose(Item potion){ + for (int i = 0; i < ids.length; i++) + if (ids[i] == potion.getId()) return ids.length - i; return Integer.parseInt(potion.getName().replaceAll("[^\\d.]","")); }