Updated SapCollect plugin to listener
Corrected sap collection interaction to require a knife instead of a bucket
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
package core.game.interaction.item.withobject;
|
||||
|
||||
import core.cache.def.impl.ItemDefinition;
|
||||
import core.game.interaction.NodeUsageEvent;
|
||||
import core.game.interaction.OptionHandler;
|
||||
import core.game.interaction.UseWithHandler;
|
||||
import core.game.node.Node;
|
||||
import core.game.node.entity.player.Player;
|
||||
import core.game.node.item.Item;
|
||||
import core.game.world.update.flag.context.Animation;
|
||||
import core.plugin.Initializable;
|
||||
import core.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Represents the plugin used to collect sap.
|
||||
* @author 'Vexia
|
||||
* @version 1.0
|
||||
*/
|
||||
@Initializable
|
||||
public final class SapCollectPlugin extends UseWithHandler {
|
||||
|
||||
/**
|
||||
* Represents the bucket of sap item.
|
||||
*/
|
||||
private static final Item BUCKET_OF_SAP = new Item(4687);
|
||||
|
||||
/**
|
||||
* Represents the bucket item.
|
||||
*/
|
||||
private static final Item BUCKET = new Item(1925);
|
||||
|
||||
/**
|
||||
* Represents the animation to use.
|
||||
*/
|
||||
private static final Animation ANIMATION = new Animation(2009);
|
||||
|
||||
/**
|
||||
* Represents the tree ids.
|
||||
*/
|
||||
private static final int[] IDS = new int[] { 1276, 1277, 1278, 1279, 1280, 1315, 1316, 1318, 1319, 1330, 1331, 1332, 3033, 3034, 3035, 3036, 3879, 3881, 3882, 3883, 10041, 14308, 14309, 30132, 30133, 37477, 37478, 37652 };
|
||||
|
||||
/**
|
||||
* Constructs a new {@code SapCollectPlugin} {@code Object}.
|
||||
*/
|
||||
public SapCollectPlugin() {
|
||||
super(946);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
||||
for (int i : IDS) {
|
||||
addHandler(i, OBJECT_TYPE, this);
|
||||
}
|
||||
new SapEmptyPlugin().newInstance(arg);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(NodeUsageEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (!player.getInventory().remove(BUCKET)) {
|
||||
player.getPacketDispatch().sendMessage("I need an empty bucket to collect the sap.");
|
||||
return true;
|
||||
}
|
||||
player.animate(ANIMATION);
|
||||
player.getInventory().remove(BUCKET);
|
||||
player.getInventory().add(BUCKET_OF_SAP);
|
||||
player.getPacketDispatch().sendMessage("You cut the tree and allow its sap to drip down into your bucket.");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents the plugin used to empty a bucket of sap.
|
||||
* @author 'Vexia
|
||||
* @version 1.0
|
||||
*/
|
||||
public static final class SapEmptyPlugin extends OptionHandler {
|
||||
|
||||
@Override
|
||||
public Plugin<Object> newInstance(Object arg) throws Throwable {
|
||||
ItemDefinition.forId(4687).getHandlers().put("option:empty", this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(Player player, Node node, String option) {
|
||||
Item item = (Item) node;
|
||||
if (item.getSlot() < 0) {
|
||||
return false;
|
||||
}
|
||||
player.getInventory().replace(BUCKET, item.getSlot());
|
||||
player.getPacketDispatch().sendMessage("You empty the contents of the bucket on the floor.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalk() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package rs09.game.interaction.item.withobject
|
||||
|
||||
import api.*
|
||||
import core.game.node.item.Item
|
||||
import core.game.system.task.Pulse
|
||||
import core.game.world.update.flag.context.Animation
|
||||
import org.rs09.consts.Animations
|
||||
import org.rs09.consts.Items
|
||||
import org.rs09.consts.Scenery
|
||||
import rs09.game.interaction.IntType
|
||||
import rs09.game.interaction.InteractionListener
|
||||
|
||||
/**
|
||||
* Listener for collecting buckets of sap from trees
|
||||
* @author Byte
|
||||
*/
|
||||
@Suppress("unused")
|
||||
class SapCollectListener : InteractionListener {
|
||||
|
||||
companion object {
|
||||
private val ANIMATION = Animation(Animations.HUMAN_FILL_BUCKET_WITH_SAP_2009)
|
||||
|
||||
private val TREES = intArrayOf(
|
||||
Scenery.TREE_1276,
|
||||
Scenery.TREE_1277,
|
||||
Scenery.TREE_1278,
|
||||
Scenery.TREE_1280,
|
||||
Scenery.EVERGREEN_1315,
|
||||
Scenery.EVERGREEN_1316,
|
||||
Scenery.EVERGREEN_1318,
|
||||
Scenery.EVERGREEN_1319,
|
||||
Scenery.TREE_1330,
|
||||
Scenery.TREE_1331,
|
||||
Scenery.TREE_1332,
|
||||
Scenery.TREE_3033,
|
||||
Scenery.TREE_3034,
|
||||
Scenery.TREE_3035,
|
||||
Scenery.TREE_3036,
|
||||
Scenery.TREE_3879,
|
||||
Scenery.TREE_3881,
|
||||
Scenery.TREE_3882,
|
||||
Scenery.TREE_3883,
|
||||
Scenery.TREE_10041,
|
||||
Scenery.TREE_14308,
|
||||
Scenery.TREE_14309,
|
||||
Scenery.TREE_30132,
|
||||
Scenery.TREE_30133,
|
||||
Scenery.TREE_37477,
|
||||
Scenery.TREE_37478,
|
||||
Scenery.TREE_37652
|
||||
)
|
||||
}
|
||||
|
||||
override fun defineListeners() {
|
||||
onUseWith(IntType.SCENERY, Items.KNIFE_946, *TREES) { player, _, _ ->
|
||||
if (!inInventory(player, Items.BUCKET_1925)) {
|
||||
sendMessage(player, "You need a bucket to do that.")
|
||||
}
|
||||
|
||||
submitIndividualPulse(player, object : Pulse(2) {
|
||||
override fun pulse(): Boolean {
|
||||
if (removeItem(player, Items.BUCKET_1925)) {
|
||||
animate(player, ANIMATION)
|
||||
sendMessage(player, "You cut the tree and allow its sap to drip down into your bucket.")
|
||||
addItem(player, Items.BUCKET_OF_SAP_4687)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
return@onUseWith true
|
||||
}
|
||||
|
||||
on(Items.BUCKET_OF_SAP_4687, IntType.ITEM, "empty") { player, node ->
|
||||
val item = node as Item
|
||||
|
||||
if (item.slot < 0) {
|
||||
return@on false
|
||||
}
|
||||
|
||||
replaceSlot(player, item.slot, Item(Items.BUCKET_1925))
|
||||
sendMessage(player, "You empty the contents of the bucket on the floor.")
|
||||
|
||||
return@on true
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user