Updated SpiritShieldBless plugin to listener
Updated ContentAPI to include a couple of new methods for handling dialogue options and actions
This commit is contained in:
-116
@@ -1,116 +0,0 @@
|
|||||||
package core.game.interaction.item.withobject;
|
|
||||||
|
|
||||||
import core.game.content.dialogue.DialogueAction;
|
|
||||||
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 rs09.game.world.repository.Repository;
|
|
||||||
import core.game.world.update.flag.context.Animation;
|
|
||||||
import core.plugin.Plugin;
|
|
||||||
import core.plugin.Initializable;
|
|
||||||
import rs09.plugin.ClassScanner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the blessing of Spirit shields.
|
|
||||||
* @author Splinter
|
|
||||||
*/
|
|
||||||
@Initializable
|
|
||||||
public class SpiritShieldBlessPlugin extends UseWithHandler {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new {@code SpiritShieldMakePlugin} {@code Object}
|
|
||||||
*/
|
|
||||||
public SpiritShieldBlessPlugin() {
|
|
||||||
super(13754, 13734);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
|
||||||
addHandler(24343, OBJECT_TYPE, this);
|
|
||||||
ClassScanner.definePlugin(new SpiritShieldMakePlugin());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(NodeUsageEvent event) {
|
|
||||||
final Player player = event.getPlayer();
|
|
||||||
if(!player.getInventory().containItems(13754, 13734)){
|
|
||||||
player.sendMessage("You need a holy elixir and an unblessed spirit shield in order to do this.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(player.getSkills().getLevel(Skills.PRAYER) < 85){
|
|
||||||
player.sendMessage("You need a Prayer level of 85 in order to bless the shield.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(player.getInventory().remove(new Item(13754, 1), new Item(13734, 1))){
|
|
||||||
player.getInventory().add(new Item(13736, 1));
|
|
||||||
player.sendMessage("You successfully bless the shield using the holy elixir.");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the attaching of sigils to the blessed spirit shield.
|
|
||||||
* @author Splinter
|
|
||||||
*/
|
|
||||||
public class SpiritShieldMakePlugin extends UseWithHandler {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new {@code SpiritShieldMakePlugin} {@code Object}
|
|
||||||
*/
|
|
||||||
public SpiritShieldMakePlugin() {
|
|
||||||
super(13746, 13748, 13750, 13752);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
|
||||||
addHandler(2782, OBJECT_TYPE, this);
|
|
||||||
addHandler(2783, OBJECT_TYPE, this);
|
|
||||||
addHandler(4306, OBJECT_TYPE, this);
|
|
||||||
addHandler(6150, OBJECT_TYPE, this);
|
|
||||||
addHandler(22725, OBJECT_TYPE, this);
|
|
||||||
addHandler(26817, OBJECT_TYPE, this);
|
|
||||||
addHandler(37622, OBJECT_TYPE, this);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(final NodeUsageEvent event) {
|
|
||||||
final Player player = event.getPlayer();
|
|
||||||
final Item used = event.getUsedItem();
|
|
||||||
final Item result = new Item(used.getId() - 8, 1);
|
|
||||||
if(used.getId() > 13752 || used.getId() < 13746){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(!player.getInventory().containsItem(new Item(13736))){
|
|
||||||
player.sendMessage("You need a blessed spirit shield in order to continue.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(player.getSkills().getLevel(Skills.PRAYER) < 90 || player.getSkills().getLevel(Skills.SMITHING) < 85){
|
|
||||||
player.sendMessage("You need a Prayer level of 90 and a Smithing of 85 in order to attach the sigil.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
player.getDialogueInterpreter().sendOptions("Combine the two?", "Yes", "No");
|
|
||||||
player.getDialogueInterpreter().addAction(new DialogueAction() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(Player player, int buttonId) {
|
|
||||||
switch (buttonId) {
|
|
||||||
case 2:
|
|
||||||
if(player.getInventory().remove(used, new Item(13736, 1))){
|
|
||||||
player.getInventory().add(result);
|
|
||||||
player.animate(new Animation(898));
|
|
||||||
player.getDialogueInterpreter().sendItemMessage(result.getId(), "You successfully attach the "+used.getName().toLowerCase()+" to the blessed", "spirit shield.");
|
|
||||||
Repository.sendNews(player.getUsername()+" has just made the "+result.getName()+".");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,6 +7,7 @@ import core.cache.def.impl.SceneryDefinition
|
|||||||
import core.cache.def.impl.VarbitDefinition
|
import core.cache.def.impl.VarbitDefinition
|
||||||
import core.game.component.Component
|
import core.game.component.Component
|
||||||
import core.game.container.impl.EquipmentContainer
|
import core.game.container.impl.EquipmentContainer
|
||||||
|
import core.game.content.dialogue.DialogueAction
|
||||||
import core.game.content.dialogue.FacialExpression
|
import core.game.content.dialogue.FacialExpression
|
||||||
import core.game.content.global.action.SpecialLadders
|
import core.game.content.global.action.SpecialLadders
|
||||||
import core.game.node.Node
|
import core.game.node.Node
|
||||||
@@ -660,6 +661,16 @@ fun sendDialogueLines(player: Player, vararg message: String) {
|
|||||||
player.dialogueInterpreter.sendDialogue(*message)
|
player.dialogueInterpreter.sendDialogue(*message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends options dialogue to the given player.
|
||||||
|
* @param player the player to send the options to.
|
||||||
|
* @param title the title of the dialogue options
|
||||||
|
* @param options the options to present to the player
|
||||||
|
*/
|
||||||
|
fun sendDialogueOptions(player: Player, title: String, vararg options: String) {
|
||||||
|
player.dialogueInterpreter.sendOptions(title, *options)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plays an animation on the entity
|
* Plays an animation on the entity
|
||||||
* @param entity the entity to animate
|
* @param entity the entity to animate
|
||||||
@@ -2200,4 +2211,13 @@ fun isPlayer(node: Node) : Boolean {
|
|||||||
return (node is Player)
|
return (node is Player)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a dialogue action to the player's dialogue interpreter
|
||||||
|
* @param player the player to add the dialogue action to
|
||||||
|
* @param action the dialogue action to add
|
||||||
|
*/
|
||||||
|
fun addDialogueAction(player: Player, action: DialogueAction) {
|
||||||
|
player.dialogueInterpreter.addAction(action)
|
||||||
|
}
|
||||||
|
|
||||||
private class ContentAPI
|
private class ContentAPI
|
||||||
+124
@@ -0,0 +1,124 @@
|
|||||||
|
package rs09.game.interaction.item.withobject
|
||||||
|
|
||||||
|
import api.*
|
||||||
|
import core.game.node.entity.skill.Skills
|
||||||
|
import core.game.node.item.Item
|
||||||
|
import core.game.world.update.flag.context.Animation
|
||||||
|
import org.rs09.consts.Items
|
||||||
|
import org.rs09.consts.Scenery
|
||||||
|
import rs09.game.interaction.IntType
|
||||||
|
import rs09.game.interaction.InteractionListener
|
||||||
|
import rs09.game.world.repository.Repository.sendNews
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener for blessing spirit shield and attaching sigils
|
||||||
|
* @author Byte
|
||||||
|
*/
|
||||||
|
@Suppress("unused")
|
||||||
|
class SpiritShieldBlessListener : InteractionListener {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val REQUIRED_PRAYER_LEVEL_TO_BLESS_SHIELD = 85
|
||||||
|
private const val REQUIRED_PRAYER_LEVEL_TO_ATTACH_SIGIL = 90
|
||||||
|
private const val REQUIRED_SMITHING_LEVEL_TO_ATTACH_SIGIL = 85
|
||||||
|
|
||||||
|
private val ANIMATION = Animation(898)
|
||||||
|
|
||||||
|
private val COMPONENTS = intArrayOf(
|
||||||
|
Items.HOLY_ELIXIR_13754,
|
||||||
|
Items.SPIRIT_SHIELD_13734
|
||||||
|
)
|
||||||
|
|
||||||
|
private val ALTARS = intArrayOf(
|
||||||
|
Scenery.ALTAR_409,
|
||||||
|
Scenery.ALTAR_2640,
|
||||||
|
Scenery.ALTAR_4008,
|
||||||
|
Scenery.ALTAR_18254,
|
||||||
|
Scenery.ALTAR_19145,
|
||||||
|
Scenery.ALTAR_24343,
|
||||||
|
Scenery.SARADOMIN_ALTAR_26287,
|
||||||
|
Scenery.ALTAR_27661,
|
||||||
|
Scenery.ALTAR_34616,
|
||||||
|
Scenery.ALTAR_36972,
|
||||||
|
Scenery.ALTAR_39842
|
||||||
|
)
|
||||||
|
|
||||||
|
private val SIGILS_SHIELDS_MAP = mapOf(
|
||||||
|
Items.ARCANE_SIGIL_13746 to Items.ARCANE_SPIRIT_SHIELD_13738,
|
||||||
|
Items.DIVINE_SIGIL_13748 to Items.DIVINE_SPIRIT_SHIELD_13740,
|
||||||
|
Items.ELYSIAN_SIGIL_13750 to Items.ELYSIAN_SPIRIT_SHIELD_13742,
|
||||||
|
Items.SPECTRAL_SIGIL_13752 to Items.SPECTRAL_SPIRIT_SHIELD_13744
|
||||||
|
)
|
||||||
|
|
||||||
|
private val ANVILS = intArrayOf(
|
||||||
|
Scenery.ANVIL_2782,
|
||||||
|
Scenery.ANVIL_2783,
|
||||||
|
Scenery.ANVIL_4306,
|
||||||
|
Scenery.ANVIL_6150,
|
||||||
|
Scenery.ANVIL_22725,
|
||||||
|
Scenery.LATHE_26817,
|
||||||
|
Scenery.ANVIL_37622
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun defineListeners() {
|
||||||
|
onUseWith(IntType.SCENERY, COMPONENTS, *ALTARS) { player, _, _ ->
|
||||||
|
if (!inInventory(player, Items.HOLY_ELIXIR_13754) || !inInventory(player, Items.SPIRIT_SHIELD_13734)) {
|
||||||
|
sendMessage(player, "You need a holy elixir and an unblessed spirit shield in order to do this.")
|
||||||
|
return@onUseWith true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasLevelDyn(player, Skills.PRAYER, REQUIRED_PRAYER_LEVEL_TO_BLESS_SHIELD)) {
|
||||||
|
sendMessage(player, "You need a Prayer level of $REQUIRED_PRAYER_LEVEL_TO_BLESS_SHIELD in order to bless the shield.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!removeItem(player, Items.HOLY_ELIXIR_13754)) {
|
||||||
|
return@onUseWith false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!removeItem(player, Items.SPIRIT_SHIELD_13734)) {
|
||||||
|
return@onUseWith false
|
||||||
|
}
|
||||||
|
|
||||||
|
addItem(player, Items.BLESSED_SPIRIT_SHIELD_13736)
|
||||||
|
sendMessage(player, "You successfully bless the shield using the holy elixir.")
|
||||||
|
|
||||||
|
return@onUseWith true
|
||||||
|
}
|
||||||
|
|
||||||
|
onUseWith(IntType.SCENERY, SIGILS_SHIELDS_MAP.keys.toIntArray(), *ANVILS) { player, used, _ ->
|
||||||
|
if (!inInventory(player, Items.BLESSED_SPIRIT_SHIELD_13736)) {
|
||||||
|
sendMessage(player, "You need a blessed spirit shield in order to continue.")
|
||||||
|
return@onUseWith true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasLevelDyn(player, Skills.PRAYER, REQUIRED_PRAYER_LEVEL_TO_ATTACH_SIGIL) || !hasLevelDyn(player, Skills.SMITHING, REQUIRED_SMITHING_LEVEL_TO_ATTACH_SIGIL)) {
|
||||||
|
sendMessage(player, "You need a Prayer level of $REQUIRED_PRAYER_LEVEL_TO_ATTACH_SIGIL and a Smithing level of $REQUIRED_SMITHING_LEVEL_TO_ATTACH_SIGIL in order to attach the sigil.")
|
||||||
|
return@onUseWith true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inInventory(player, Items.HAMMER_2347)) {
|
||||||
|
sendMessage(player, "You need a hammer in order to do this.")
|
||||||
|
return@onUseWith true
|
||||||
|
}
|
||||||
|
|
||||||
|
sendDialogueOptions(player, "Combine the two?", "Yes", "No")
|
||||||
|
addDialogueAction(player) { _, buttonId ->
|
||||||
|
when (buttonId) {
|
||||||
|
2 -> {
|
||||||
|
if (removeItem(player, used) && removeItem(player, Items.BLESSED_SPIRIT_SHIELD_13736)) {
|
||||||
|
val product = Item(SIGILS_SHIELDS_MAP[used.id]!!)
|
||||||
|
addItem(player, product.id)
|
||||||
|
animate(player, ANIMATION)
|
||||||
|
sendItemDialogue(player, product.id, "You successfully attach the " + used.name.lowercase(Locale.getDefault()) + " to the blessed spirit shield.")
|
||||||
|
sendNews(player.username + " has just made the " + product.name + ".")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return@onUseWith true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user