Removed DestroyItemPlugin and bundled functionality into DropListener
This commit is contained in:
@@ -1,75 +0,0 @@
|
|||||||
package content.global.handlers.item;
|
|
||||||
|
|
||||||
import core.game.dialogue.DialoguePlugin;
|
|
||||||
import core.game.node.entity.player.Player;
|
|
||||||
import core.game.node.entity.player.link.audio.Audio;
|
|
||||||
import core.plugin.Initializable;
|
|
||||||
import core.game.node.item.Item;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the destroy item plugin.
|
|
||||||
* @author Vexia
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Initializable
|
|
||||||
public final class DestroyItemPlugin extends DialoguePlugin {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the sound to send for destroying an item.
|
|
||||||
*/
|
|
||||||
private static final Audio SOUND = new Audio(4500, 1, 0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the item parameter.
|
|
||||||
*/
|
|
||||||
private Item item;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new {@code DestroyItemPlugin} {@code Object}.
|
|
||||||
*/
|
|
||||||
public DestroyItemPlugin() {
|
|
||||||
/**
|
|
||||||
* empty.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a new {@code DestroyItemPlugin} {@code Object}.
|
|
||||||
* @param player the player.
|
|
||||||
*/
|
|
||||||
public DestroyItemPlugin(Player player) {
|
|
||||||
super(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DialoguePlugin newInstance(Player player) {
|
|
||||||
return new DestroyItemPlugin(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean open(Object... args) {
|
|
||||||
item = (Item) args[0];
|
|
||||||
interpreter.sendDestroyItem(item.getId(), item.getName());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handle(int interfaceId, int buttonId) {
|
|
||||||
if (buttonId == 2) {
|
|
||||||
if (player.getInventory().remove(item)) {
|
|
||||||
player.getAudioManager().send(SOUND);
|
|
||||||
end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (buttonId == 3) {
|
|
||||||
end();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] getIds() {
|
|
||||||
return new int[] { 9878 };
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -12,13 +12,21 @@ import core.game.node.entity.player.link.audio.Audio
|
|||||||
import core.game.node.item.GroundItemManager
|
import core.game.node.item.GroundItemManager
|
||||||
import core.game.node.item.Item
|
import core.game.node.item.Item
|
||||||
import core.game.system.config.ItemConfigParser
|
import core.game.system.config.ItemConfigParser
|
||||||
|
import org.rs09.consts.Items
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the item drop/destroy/dissolve handler.
|
||||||
|
* @author Ceikry, ovenbreado
|
||||||
|
*/
|
||||||
class DropListener : InteractionListener {
|
class DropListener : InteractionListener {
|
||||||
override fun defineListeners() {
|
override fun defineListeners() {
|
||||||
on(IntType.ITEM, "drop", "destroy", "dissolve", handler = ::handleDropAction)
|
on(IntType.ITEM, "drop", "destroy", "dissolve", handler = ::handleDropAction)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private val DROP_COINS_SOUND = Audio(10, 1, 0)
|
||||||
|
private val DROP_ITEM_SOUND = Audio(2739, 1, 0)
|
||||||
|
private val DESTROY_ITEM_SOUND = Audio(4500, 1, 0)
|
||||||
@JvmStatic fun drop(player: Player, item: Item) : Boolean {
|
@JvmStatic fun drop(player: Player, item: Item) : Boolean {
|
||||||
return handleDropAction(player, item)
|
return handleDropAction(player, item)
|
||||||
}
|
}
|
||||||
@@ -35,15 +43,22 @@ class DropListener : InteractionListener {
|
|||||||
|
|
||||||
queueScript (player, strength = QueueStrength.SOFT) {
|
queueScript (player, strength = QueueStrength.SOFT) {
|
||||||
if (player.inventory.replace(null, item.slot) != item) return@queueScript stopExecuting(player)
|
if (player.inventory.replace(null, item.slot) != item) return@queueScript stopExecuting(player)
|
||||||
item = item.dropItem
|
val droppedItem = item.dropItem
|
||||||
player.audioManager.send(Audio(if (item.id == 995) 10 else 2739, 1, 0))
|
if (droppedItem.id == Items.COINS_995) playAudio(player, DROP_COINS_SOUND) else playAudio(player, DROP_ITEM_SOUND)
|
||||||
GroundItemManager.create(item, player.location, player)
|
GroundItemManager.create(droppedItem, player.location, player)
|
||||||
setAttribute(player, "droppedItem:${item.id}", getWorldTicks() + 2)
|
setAttribute(player, "droppedItem:${droppedItem.id}", getWorldTicks() + 2)
|
||||||
PlayerParser.save(player)
|
PlayerParser.save(player)
|
||||||
return@queueScript stopExecuting(player)
|
return@queueScript stopExecuting(player)
|
||||||
}
|
}
|
||||||
} else if (option == "destroy" || option == "dissolve" || item.definition.handlers.getOrDefault(ItemConfigParser.DESTROY, false) as Boolean) {
|
} else if (option == "destroy" || option == "dissolve" || item.definition.handlers.getOrDefault(ItemConfigParser.DESTROY, false) as Boolean) {
|
||||||
player.dialogueInterpreter.open(9878, item)
|
player.dialogueInterpreter.sendDestroyItem(item.id, item.name)
|
||||||
|
addDialogueAction(player) { player, button ->
|
||||||
|
if (button == 3) {
|
||||||
|
if (removeItem(player, item)) {
|
||||||
|
playAudio(player, DESTROY_ITEM_SOUND)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user