Rewrote hunter kit spell in kotlin

This commit is contained in:
bushtail
2023-03-01 08:35:00 +00:00
committed by Ryan
parent bcb2a9386d
commit 9020d1e474
3 changed files with 46 additions and 98 deletions
@@ -1,97 +0,0 @@
package content.global.skill.magic.lunar;
import core.cache.def.impl.ItemDefinition;
import core.plugin.Initializable;
import core.game.node.entity.combat.spell.MagicSpell;
import core.game.node.entity.combat.spell.Runes;
import core.game.interaction.OptionHandler;
import core.game.node.Node;
import core.game.node.entity.Entity;
import core.game.node.entity.combat.spell.SpellType;
import core.game.node.entity.player.Player;
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.Plugin;
/**
* Represents the hunter kit spell.
* @author 'Vexia
* @version 1.0
*/
@Initializable
public final class HunterKitSpell extends MagicSpell {
/**
* Represents the hunter kit.
*/
private static final Item KIT = new Item(11159);
/**
* Represents the animation of this graphics.
*/
private static final Animation ANIMATION = new Animation(6303);
/**
* Repesents the graphick, next spells of this spell.
*/
private static final Graphics GRAPHIC = new Graphics(1074);
/**
* Constructs a new {@code CureOtherSpell} {@code Object}.
*/
public HunterKitSpell() {
super(SpellBook.LUNAR, 71, 70, null, null, null, new Item[] { new Item(Runes.ASTRAL_RUNE.getId(), 2), new Item(Runes.EARTH_RUNE.getId(), 2) });
}
@Override
public Plugin<SpellType> newInstance(SpellType arg) throws Throwable {
SpellBook.LUNAR.register(8, this);
ItemDefinition.forId(KIT.getId()).getHandlers().put("option:open", new OptionHandler() {
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
return this;
}
@Override
public boolean handle(Player player, Node node, String option) {
if (player.getInventory().freeSlots() < 7) {
player.getPacketDispatch().sendMessage("You don't have enough inventory space.");
return true;
}
if (player.getInventory().remove((Item) node)) {
player.getInventory().add(new Item[] { new Item(10150), new Item(10010), new Item(10006), new Item(10031), new Item(10029), new Item(596), new Item(10008) });
}
return true;
}
@Override
public boolean isWalk() {
return false;
}
});
return this;
}
@Override
public boolean cast(Entity entity, Node target) {
Player p = (Player) entity;
if (p.getInventory().freeSlots() == 0) {
p.getPacketDispatch().sendMessage("Not enough inventory space!");
return false;
}
if (!meetsRequirements(entity, true, true)) {
return false;
}
if (p.getInventory().add(KIT)) {
p.lock(5);
p.animate(ANIMATION);
p.graphics(GRAPHIC);
p.getAudioManager().send(3615, 1, 1);
}
return true;
}
}
@@ -1,5 +1,9 @@
package content.global.skill.magic.lunar
import core.api.*
import core.game.interaction.IntType
import core.game.interaction.InteractionListener
import core.game.node.item.Item
import core.game.world.update.flag.context.Animation
import core.game.world.update.flag.context.Graphics
import org.rs09.consts.Items
@@ -17,7 +21,7 @@ val CURE_ME_ANIM = Animation(4411)
val CURE_GROUP_ANIM = Animation(4409)
val CURE_OTHER_ANIM = Animation(4411)
val ENERGY_TRANSFER_ANIM = Animation(4411)
val HUNTER_KIT_ANIM = Animation(6303)
// Graphics
val BAKE_PIE_GFX = Graphics(746,75)
@@ -32,6 +36,31 @@ val CURE_ME_GFX = Graphics(731, 90)
val CURE_GROUP_GFX = Graphics(751, 130)
val CURE_OTHER_GFX = Graphics(738, 130)
val ENERGY_TRANSFER_GFX = Graphics(738, 90)
val HUNTER_KIT_GFX = Graphics(1024)
private val HunterKitContents = intArrayOf(
Items.NOOSE_WAND_10150,
Items.BUTTERFLY_NET_10010,
Items.BIRD_SNARE_10006,
Items.RABBIT_SNARE_10031,
Items.TEASING_STICK_10029,
Items.UNLIT_TORCH_596,
Items.BOX_TRAP_10008
)
class HunterKitInteraction : InteractionListener {
override fun defineListeners() {
on(Items.HUNTER_KIT_11159, IntType.ITEM, "open") { player, _ ->
if(freeSlots(player) < 6) sendMessage(player, "You don't have enough inventory space.").also { return@on false }
if(removeItem(player, Items.HUNTER_KIT_11159)) {
for(item in HunterKitContents) {
addItemOrDrop(player, item)
}
}
return@on true
}
}
}
enum class JewelleryString(val unstrung: Int, val strung: Int) {
GOLD(Items.GOLD_AMULET_1673, Items.GOLD_AMULET_1692),
@@ -55,3 +84,4 @@ enum class JewelleryString(val unstrung: Int, val strung: Int) {
}
}
}
@@ -188,6 +188,11 @@ class LunarListeners : SpellListener("lunar"), Commands {
onCast(Lunar.ENERGY_TRANSFER, PLAYER) { player, node ->
node?.let { energyTransfer(player, node) }
}
onCast(Lunar.HUNTER_KIT, NONE) { player, _ ->
if(freeSlots(player) == 0) sendMessage(player, "Not enough inventory space!").also { return@onCast }
hunterKit(player)
}
}
// Lunar spellbook-related debug commands
@@ -581,6 +586,16 @@ class LunarListeners : SpellListener("lunar"), Commands {
removeRunes(player, true)
addXP(player, 100.0)
}
private fun hunterKit(player: Player) {
requires(player, 71, arrayOf(Item(Items.ASTRAL_RUNE_9075, 2), Item(Items.EARTH_RUNE_557, 2)))
removeRunes(player, true)
if(addItem(player, Items.HUNTER_KIT_11159)) {
visualizeSpell(player, HUNTER_KIT_ANIM, HUNTER_KIT_GFX, 3615)
addXP(player, 70.0)
setDelay(player, 2)
}
}
}