Port NettleTeaPlugin.java and NettleWaterPlugin.java to TeaInteraction.kt

This commit is contained in:
gregf36665 2024-12-18 16:09:59 +00:00 committed by Syndromeramo
parent f9a3026fb3
commit dd444a2bf3
3 changed files with 27 additions and 99 deletions

View file

@ -1,61 +0,0 @@
package content.global.skill.cooking;
import core.game.interaction.NodeUsageEvent;
import core.game.interaction.UseWithHandler;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.plugin.Initializable;
import core.plugin.Plugin;
/**
* Represents the plugin used to create nettle tea in a cup.
* @author 'Vexia
* @version 1.0
*/
@Initializable
public final class NettleTeaPlugin extends UseWithHandler {
/**
* Represents the empty cup item.
*/
private static final Item EMPTY_CUP = new Item(1980, 1);
/**
* Represents the nettle tea item.
*/
private static final Item NETTLE_TEA = new Item(4239, 1);
/**
* Represents the bowl item.
*/
private static final Item BOWL = new Item(1923);
/**
* Represents the cup of tea item.
*/
private static final Item CUP_OF_TEA = new Item(4242, 1);
/**
* Constructs a new {@code NettleTeaPlugin} {@code Object}.
*/
public NettleTeaPlugin() {
super(1980);
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
addHandler(4239, ITEM_TYPE, this);
return this;
}
@Override
public boolean handle(NodeUsageEvent event) {
final Player player = event.getPlayer();
if (player.getInventory().remove(EMPTY_CUP) && player.getInventory().remove(NETTLE_TEA)) {
player.getInventory().add(BOWL);
player.getInventory().add(CUP_OF_TEA);
}
return true;
}
}

View file

@ -1,35 +0,0 @@
package content.global.skill.cooking;
import core.game.interaction.NodeUsageEvent;
import core.game.interaction.UseWithHandler;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.plugin.Initializable;
import core.plugin.Plugin;
/**
* @author Adam
*/
@Initializable
public class NettleWaterPlugin extends UseWithHandler {
public NettleWaterPlugin() {
super(1921);
}
@Override
public boolean handle(NodeUsageEvent event) {
final Player player = event.getPlayer();
player.getInventory().remove(new Item(1921, 1));
player.getInventory().remove(new Item(4241, 1));
player.getInventory().add(new Item(4237, 1));
return true;
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
addHandler(4241, ITEM_TYPE, this);
return this;
}
}

View file

@ -1,13 +1,16 @@
package content.global.skill.cooking
import core.api.addItem
import core.api.getDynLevel
import core.api.removeItem
import core.api.sendDialogue
import core.game.interaction.InteractionListener
import core.game.node.entity.skill.Skills
import org.rs09.consts.Items
/**
* This deals with all tea mixtures
* cup of tea
* cup of tea - done
* nettle tea
* nettle water
* nettle tea (cup)
@ -18,6 +21,7 @@ import org.rs09.consts.Items
*/
class TeaInteraction : InteractionListener {
private val teaMilkMap = mapOf(
Items.NETTLE_TEA_4239 to Items.NETTLE_TEA_4240,
Items.CUP_OF_TEA_4242 to Items.CUP_OF_TEA_4243,
Items.CUP_OF_TEA_4245 to Items.CUP_OF_TEA_4246,
Items.CUP_OF_TEA_7730 to Items.CUP_OF_TEA_7731,
@ -25,6 +29,12 @@ class TeaInteraction : InteractionListener {
Items.CUP_OF_TEA_7736 to Items.CUP_OF_TEA_7737,
)
private val teaCupMap = mapOf(
Items.NETTLE_TEA_4239 to Items.CUP_OF_TEA_4242,
Items.NETTLE_TEA_4240 to Items.CUP_OF_TEA_4246,
Items.BOWL_OF_HOT_WATER_4456 to Items.CUP_OF_HOT_WATER_4460
)
override fun defineListeners() {
onUseWith(ITEM, teaMilkMap.keys.toIntArray(), Items.BUCKET_OF_MILK_1927){ player, used, with ->
if (removeItem(player, used) && removeItem(player, with)){
@ -34,9 +44,23 @@ class TeaInteraction : InteractionListener {
return@onUseWith true
}
onUseWith(ITEM, Items.BOWL_OF_HOT_WATER_4456, Items.EMPTY_CUP_1980){ player, used, with ->
onUseWith(ITEM, teaCupMap.keys.toIntArray(), Items.EMPTY_CUP_1980){ player, used, with ->
if (used.id != Items.BOWL_OF_HOT_WATER_4456){
if (getDynLevel(player, Skills.COOKING) < 20){
sendDialogue(player, "You need a cooking level of 20 to make tea.")
return@onUseWith false
}
}
if (removeItem(player, used) && removeItem(player, with)) {
addItem(player, Items.CUP_OF_HOT_WATER_4460)
addItem(player, teaCupMap[used.id]!!)
addItem(player, Items.BOWL_1923)
}
return@onUseWith true
}
onUseWith(ITEM, Items.BOWL_OF_WATER_1921, Items.NETTLES_4241) { player, used, with ->
if (removeItem(player, used) && removeItem(player, with)){
addItem(player, Items.NETTLE_WATER_4237)
}
return@onUseWith true
}