From e6ce55fba09c4f300dffc05ffaa32436d674566f Mon Sep 17 00:00:00 2001 From: bushtail Date: Tue, 12 Jul 2022 13:14:58 +0000 Subject: [PATCH] Rewrote String Jewellery lunar spell --- .../magic/lunar/StringJewellerySpell.java | 166 ------------------ .../node/entity/skill/magic/LunarListeners.kt | 68 ++++++- .../node/entity/skill/magic/SpellListener.kt | 4 +- .../entity/skill/magic/spellconsts/Lunar.kt | 1 + 4 files changed, 69 insertions(+), 170 deletions(-) delete mode 100644 Server/src/main/java/core/game/node/entity/skill/magic/lunar/StringJewellerySpell.java diff --git a/Server/src/main/java/core/game/node/entity/skill/magic/lunar/StringJewellerySpell.java b/Server/src/main/java/core/game/node/entity/skill/magic/lunar/StringJewellerySpell.java deleted file mode 100644 index 20853206d..000000000 --- a/Server/src/main/java/core/game/node/entity/skill/magic/lunar/StringJewellerySpell.java +++ /dev/null @@ -1,166 +0,0 @@ -package core.game.node.entity.skill.magic.lunar; - -import core.game.node.entity.skill.SkillPulse; -import core.game.node.entity.skill.Skills; -import core.game.node.entity.skill.magic.MagicSpell; -import core.game.node.entity.skill.magic.Runes; -import core.game.node.Node; -import core.game.node.entity.Entity; -import core.game.node.entity.combat.equipment.SpellType; -import core.game.node.entity.player.Player; -import core.game.node.entity.player.link.audio.Audio; -import core.game.node.entity.player.link.SpellBookManager.SpellBook; -import core.game.node.item.Item; -import core.game.world.update.flag.context.Animation; -import core.game.world.update.flag.context.Graphics; -import core.plugin.Initializable; -import core.plugin.Plugin; - -/** - * Represents the jewllery stringing spell. - * @author 'Vexia - * @version 1.0 - */ -@Initializable -public final class StringJewellerySpell extends MagicSpell { - - /** - * Represents the animation of this spell. - */ - private static final Animation ANIMATION = Animation.create(4412); - - /** - * Represents the graphic of this spell. - */ - private static final Graphics GRAPHIC = new Graphics(728, 100); - - /** - * Represents the array of unstrung jewellery. - */ - private static final int[] UNSTRUNG = { 1673, 1675, 1677, 1679, 1681, 1683, 1714 }; - - /** - * Represents an array of strung jewellery. - */ - private static final int[] STRUNG = { 1692, 1694, 1696, 1698, 1700, 1702, 1718 }; - - /** - * Constructs a new {@code CureOtherSpell} {@code Object}. - */ - public StringJewellerySpell() { - super(SpellBook.LUNAR, 80, 87, 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(), 5) }); - } - - @Override - public Plugin newInstance(SpellType arg) throws Throwable { - SpellBook.LUNAR.register(22, this); - return this; - } - - @Override - public boolean cast(Entity entity, Node target) { - final Player p = (Player) entity; - boolean contains = false; - Item item = null; - for (int i : UNSTRUNG) { - if (p.getInventory().contains(i, 1)) { - contains = true; - item = new Item(i); - break; - } - } - if (!contains) { - p.getPacketDispatch().sendMessage("You need jewellery in order to use this spell."); - return false; - } - if (!meetsRequirements(entity, true, false)) { - return false; - } - p.getPulseManager().run(new LunarStringPulse(p, item)); - return true; - } - - /** - * Represents the skill pulse used to string a jewellery. - * @author 'Vexia - */ - public class LunarStringPulse extends SkillPulse { - - /** - * Constructs a new {@code LunarStringPulse} {@code Object}. - * @param player the player. - * @param node the node. - */ - public LunarStringPulse(final Player player, final Item node) { - super(player, node); - } - - @Override - public boolean checkRequirements() { - if (!player.getInventory().containsItem(node)) { - stop(); - return false; - } - return true; - } - - @Override - public void animate() { - player.animate(ANIMATION); - player.graphics(GRAPHIC); - } - - @Override - public boolean reward() { - if (getDelay() == 1) { - setDelay(2); - return false; - } - if (meetsRequirements(player, true, true) && player.getInventory().remove(node)) { - player.getAudioManager().send(2903, 1, 1); - player.getInventory().add(new Item(STRUNG[getIndex()])); - player.getSkills().addExperience(Skills.CRAFTING, 4, true); - player.getSkills().addExperience(Skills.MAGIC, 83, true); - } else { - return true; - } - return nextItem() == null; - } - - @Override - public void stop() { - super.stop(); - player.graphics(new Graphics(-1)); - } - - @Override - public void message(int type) { - } - - /** - * Method used to get index. - * @return the index. - */ - public int getIndex() { - for (int i = 0; i < UNSTRUNG.length; i++) { - if (node.getId() == UNSTRUNG[i]) { - return i; - } - } - return -1; - } - - /** - * Method used to get the next string. - * @return the string. - */ - public Item nextItem() { - for (int i : UNSTRUNG) { - if (player.getInventory().contains(i, 1)) { - node = new Item(i); - } - } - return node; - } - } -} diff --git a/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/LunarListeners.kt b/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/LunarListeners.kt index f2a169491..db9cd93e4 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/LunarListeners.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/LunarListeners.kt @@ -2,7 +2,6 @@ package rs09.game.node.entity.skill.magic import api.* import core.game.component.Component -import core.game.node.Node import core.game.node.scenery.Scenery import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player @@ -19,8 +18,10 @@ import core.game.world.update.flag.context.Graphics import org.rs09.consts.Components import org.rs09.consts.Items import rs09.game.node.entity.skill.farming.FarmingPatch +import rs09.game.node.entity.skill.magic.LunarListeners.JewelleryString.Companion.productOfString import rs09.game.node.entity.skill.magic.spellconsts.Lunar import rs09.game.system.config.NPCConfigParser +import java.util.Deque class LunarListeners : SpellListener("lunar") { private val BAKE_PIE_ANIM = Animation(4413) @@ -33,6 +34,8 @@ class LunarListeners : SpellListener("lunar") { private val NPC_CONTACT_GFX = Graphics(730,130) private val PLANK_MAKE_ANIM = Animation(6298) private val PLANK_MAKE_GFX = Graphics(1063, 120) + private val STRING_JEWELLERY_ANIM = Animation(4412) + private val STRING_JEWELLERY_GFX = Graphics(728, 100) override fun defineListeners() { @@ -161,6 +164,10 @@ class LunarListeners : SpellListener("lunar") { requires(player, 86, arrayOf(Item(Items.ASTRAL_RUNE_9075, 2), Item(Items.NATURE_RUNE_561, 1), Item(Items.EARTH_RUNE_557, 15))) plankMake(player, node!!.asItem()) } + + onCast(Lunar.STRING_JEWELLERY, NONE) { player, _ -> + stringJewellery(player) + } } private fun plankMake(player: Player, item: Item) { @@ -263,7 +270,7 @@ class LunarListeners : SpellListener("lunar") { for(item in player.inventory.toArray()){ if(item == null) continue val pie = CookableItems.forId(item.id) ?: continue - if(!pie.name.toLowerCase().contains("pie")) continue + if(!pie.name.lowercase().contains("pie")) continue if(player.skills.getLevel(Skills.COOKING) < pie.level) continue playerPies.add(item) } @@ -319,4 +326,61 @@ class LunarListeners : SpellListener("lunar") { } sendTeleport(player,xp,loc) } + + private fun stringJewellery(player: Player) { + val playerJewellery = ArrayDeque() + + for(item in player.inventory.toArray()) { + if(item == null) continue + if(!JewelleryString.unstrungContains(item.id)) continue + playerJewellery.add(item) + } + + + + player.pulseManager.run(object : Pulse() { + var counter = 0 + override fun pulse(): Boolean { + removeAttribute(player, "spell:runes") + requires(player, 80, arrayOf(Item(Items.ASTRAL_RUNE_9075, 2), Item(Items.EARTH_RUNE_557, 10), Item(Items.WATER_RUNE_555, 5))) + if(counter == 0) delay = animationDuration(STRING_JEWELLERY_ANIM) + 1 + val item = playerJewellery[0] + val strung = JewelleryString.forId(item.id) + setDelay(player,false) + if(removeItem(player, item) && addItem(player, strung)) { + removeRunes(player, true) + visualizeSpell(player, STRING_JEWELLERY_ANIM, STRING_JEWELLERY_GFX, 2903) + rewardXP(player, Skills.CRAFTING, 4.0) + addXP(player, 83.0) + playerJewellery.remove(item) + } + counter++ + return playerJewellery.isEmpty() + } + }) + } + + private enum class JewelleryString(val unstrung : Int, val strung : Int) { + GOLD(Items.GOLD_AMULET_1673, Items.GOLD_AMULET_1692), + SAPPHIRE(Items.SAPPHIRE_AMULET_1675, Items.SAPPHIRE_AMULET_1694), + EMERALD(Items.EMERALD_AMULET_1677, Items.EMERALD_AMULET_1696), + RUBY(Items.RUBY_AMULET_1679, Items.RUBY_AMULET_1698), + DIAMOND(Items.DIAMOND_AMULET_1681, Items.DIAMOND_AMULET_1700), + DRAGONSTONE(Items.DRAGONSTONE_AMMY_1683, Items.DRAGONSTONE_AMMY_1702), + ONYX(Items.ONYX_AMULET_6579, Items.ONYX_AMULET_6581), + SALVE(Items.SALVE_SHARD_4082, Items.SALVE_AMULET_4081), + HOLY(Items.UNSTRUNG_SYMBOL_1714, Items.UNBLESSED_SYMBOL_1716), + UNHOLY(Items.UNSTRUNG_EMBLEM_1720, Items.UNPOWERED_SYMBOL_1722); + companion object { + val productOfString = values().associate { it.unstrung to it.strung } + fun forId(id : Int) : Int { + return productOfString[id]!! + } + + fun unstrungContains(id : Int) : Boolean { + return productOfString.contains(id) + } + + } + } } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/SpellListener.kt b/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/SpellListener.kt index dad5e5c8b..060c5c814 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/SpellListener.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/SpellListener.kt @@ -33,7 +33,7 @@ abstract class SpellListener(val bookName: String) : Listener { SpellListeners.add(spellID,type,ids,bookName,method) } - fun requires(player: Player, magicLevel: Int = 0, runes: Array = arrayOf(), specialEquipment: IntArray = intArrayOf()){ + fun requires(player: Player, magicLevel: Int = 0, runes: Array = arrayOf(), specialEquipment: IntArray = intArrayOf()) { if(player.getAttribute("magic-delay",0) > GameWorld.ticks){ throw IllegalStateException() } @@ -46,7 +46,7 @@ abstract class SpellListener(val bookName: String) : Listener { } for(rune in runes){ if(!SpellUtils.hasRune(player,rune)){ - player.sendMessage("You don't have enough ${rune.definition.name.toLowerCase()}s to cast this spell.") + player.sendMessage("You don't have enough ${rune.definition.name.lowercase()}s to cast this spell.") throw IllegalStateException() } } diff --git a/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/spellconsts/Lunar.kt b/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/spellconsts/Lunar.kt index 04a1f8ecb..3836e8952 100644 --- a/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/spellconsts/Lunar.kt +++ b/Server/src/main/kotlin/rs09/game/node/entity/skill/magic/spellconsts/Lunar.kt @@ -11,6 +11,7 @@ object Lunar { const val KHAZARD_TELEPORT = 18 const val MOONCLAN_TELEPORT = 20 const val CATHERBY_TELEPORT = 21 + const val STRING_JEWELLERY = 22 const val WATERBIRTH_TELEPORT = 24 const val ICE_PLATEAU_TELEPORT = 28 const val OURANIA_TELEPORT = 31