Revert "Converted all item on item plugins to listeners"

This reverts commit 4a0dfed1
This commit is contained in:
ceikry
2021-12-27 18:18:43 -06:00
parent b89ec2f2cd
commit 7b1faf317c
33 changed files with 2399 additions and 617 deletions
@@ -1,24 +0,0 @@
package api
import core.game.node.item.Item
fun IntRange.toIntArray(): IntArray {
if (last < first)
return IntArray(0)
val result = IntArray(last - first + 1)
var index = 0
for (element in this)
result[index++] = element
return result
}
fun Int.asItem() : Item {
return Item(this)
}
fun Collection<IntArray>.toIntArray() : IntArray {
val list = ArrayList<Int>()
this.forEach { arr -> arr.forEach { list.add(it) } }
return list.toIntArray()
}
@@ -1,33 +0,0 @@
package rs09.game.interaction.item.withitem
import api.*
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
class ChiselOnGranite : InteractionListener() {
override fun defineListeners() {
val granite = intArrayOf(Items.GRANITE_5KG_6983, Items.GRANITE_2KG_6981)
onUseWith(ITEM, granite, Items.CHISEL_1755) {player, used, _ ->
if (freeSlots(player) < 3) {
sendMessage(player, "You need four inventory slots to do this.")
} else {
if(removeItem(player, used, Container.INVENTORY)) {
when (used.id) {
Items.GRANITE_5KG_6983 -> {
sendMessage(player, "You chisel the 5kg granite into four smaller pieces.")
addItemOrDrop(player, Items.GRANITE_2KG_6981, 2)
addItemOrDrop(player, Items.GRANITE_500G_6979, 2)
}
Items.GRANITE_2KG_6981 -> {
sendMessage(player, "You chisel the 2kg granite into four smaller pieces.")
addItemOrDrop(player, Items.GRANITE_500G_6979, 4)
}
}
}
}
return@onUseWith true
}
}
}
@@ -1,31 +0,0 @@
package rs09.game.interaction.item.withitem
import api.addItem
import api.removeItem
import api.runTask
import api.sendMessage
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
class ClaySoftener : InteractionListener() {
override fun defineListeners() {
val sources = intArrayOf(Items.JUG_OF_WATER_1937, Items.BUCKET_OF_WATER_1929, Items.BOWL_OF_WATER_1921)
onUseWith(ITEM, sources, Items.CLAY_434){player, used, with ->
val returnItem = when(used.id){
Items.JUG_OF_WATER_1937 -> Items.EMPTY_JUG_3732
Items.BUCKET_OF_WATER_1929 -> Items.EMPTY_BUCKET_3727
else -> Items.BOWL_1923
}
runTask(player, 2){
if(removeItem(player, used.asItem()) && removeItem(player, with.asItem())){
addItem(player, Items.SOFT_CLAY_1761)
addItem(player, returnItem)
sendMessage(player, "You mix the clay and water. You now have some soft, workable clay.")
}
}
return@onUseWith true
}
}
}
@@ -1,17 +0,0 @@
package rs09.game.interaction.item.withitem
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
import api.*
class CombineCrystalKey : InteractionListener() {
override fun defineListeners() {
onUseWith(ITEM, Items.LOOP_HALF_OF_A_KEY_987, Items.TOOTH_HALF_OF_A_KEY_985){player, used, with ->
if(removeItem(player, used, Container.INVENTORY) && removeItem(player,with,Container.INVENTORY)) {
addItem(player, Items.CRYSTAL_KEY_989)
sendMessage(player, "You join the loop half of a key and the tooth half of a key to make a crystal key.")
}
return@onUseWith true
}
}
}
@@ -1,55 +0,0 @@
package rs09.game.interaction.item.withitem
import api.*
import core.game.node.item.Item
import org.rs09.consts.Items
import org.rs09.consts.Items.LEMON_CHUNKS_2104
import org.rs09.consts.Items.LIME_2120
import org.rs09.consts.Items.LIME_CHUNKS_2122
import org.rs09.consts.Items.LIME_SLICES_2124
import rs09.game.content.dialogue.DialogueFile
import rs09.game.interaction.InteractionListener
class FruitSlicing : InteractionListener() {
override fun defineListeners() {
val fruits = Fruit.values().map { it.base.id } .toIntArray()
onUseWith(ITEM, fruits, Items.KNIFE_946) {player, used, with ->
val fruit = Fruit.forBase(used.id) ?: return@onUseWith false
if ((fruit == Fruit.BANANA || fruit == Fruit.LEMON)) {
if (removeItem(player, used.asItem(), Container.INVENTORY)) {
lock(player, 2)
animate(player, 1192)
addItem(player, fruit.sliced.id, fruit.sliced.amount)
sendMessage(player, "You deftly chop the " + fruit.name.toLowerCase() + " into slices.")
}
} else {
//TODO: Below Dialogue is still located in FruitCuttingDialogue.java. Convert to DialogueFile and make this not so garbage.
openDialogue(player,31237434, fruit)
}
return@onUseWith true
}
}
enum class Fruit(val base: Item, val diced: Item?, val sliced: Item) {
PINEAPPLE(Item(2114), Item(2116), Item(2118, 4)),
BANANA(Item(1963), null, Item(3162)),
LEMON(Item(2102), Item(LEMON_CHUNKS_2104), Item(2106)),
LIME(Item(LIME_2120), Item(LIME_CHUNKS_2122), Item(LIME_SLICES_2124)),
ORANGE(Item(2108), Item(2110), Item(2112));
companion object {
val fruitMap = values().map { it.base.id to it }.toMap()
/**
* Method used to get the fruit for the base item.
* @param item the item.
* @return the fruit.
*/
fun forBase(item: Int): Fruit? {
return fruitMap[item]
}
}
}
}
@@ -1,22 +0,0 @@
package rs09.game.interaction.item.withitem
import api.*
import core.tools.StringUtils
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
class HiltOnBlade : InteractionListener() {
override fun defineListeners() {
val HILTS = intArrayOf(Items.ARMADYL_HILT_11702, Items.ZAMORAK_HILT_11708, Items.BANDOS_HILT_11704, Items.SARADOMIN_HILT_11706)
onUseWith(ITEM, HILTS, Items.GODSWORD_BLADE_11690) {player, used, with ->
if (removeItem(player, used.asItem(), Container.INVENTORY) && removeItem(player, with.asItem(), Container.INVENTORY)) {
val godsword = if(used.id > 11690) used.id - 8 else with.id - 8
addItem(player, godsword)
sendMessage(player, "You attach the hilt to the blade and make a ${if(StringUtils.isPlusN(getItemName(godsword))) "an" else "a"} ${getItemName(godsword)}.")
}
return@onUseWith true
}
}
}
@@ -1,22 +0,0 @@
package rs09.game.interaction.item.withitem
import api.*
import org.rs09.consts.Items
import org.rs09.consts.Scenery
import rs09.game.interaction.InteractionListener
class KeyOnPirateChest : InteractionListener() {
override fun defineListeners() {
onUseWith(SCENERY, Items.CHEST_KEY_432, Scenery.CHEST_2079){player, used, with ->
val scenery = with as core.game.node.scenery.Scenery
if(removeItem(player, used, Container.INVENTORY)){
replaceScenery(scenery, 2080, 3)
addItemOrDrop(player, Items.PIRATE_MESSAGE_433)
sendMessage(player, "You unlock the chest.")
sendMessage(player, "All that's in the chest is a message...")
sendMessage(player, "You take the message from the chest.")
}
return@onUseWith true
}
}
}
@@ -1,98 +0,0 @@
package rs09.game.interaction.item.withitem
import api.*
import core.game.node.entity.player.Player
import org.rs09.consts.Items
import org.rs09.consts.Scenery
import rs09.game.interaction.InteractionListener
class OilStillListeners : InteractionListener() {
override fun defineListeners() {
val flowers = (Items.FLOWERS_2460..Items.FLOWERS_2477).toIntArray()
val stills = intArrayOf(*getChildren(5908), 5909)
val fillableItems = mapOf(
Items.OIL_LAMP_4525 to Items.OIL_LAMP_4522,
Items.OIL_LANTERN_4535 to Items.OIL_LANTERN_4537,
Items.BULLSEYE_LANTERN_4546 to Items.BULLSEYE_LANTERN_4548,
Items.SAPPHIRE_LANTERN_4700 to Items.SAPPHIRE_LANTERN_4701
)
onUseWith(ITEM, flowers, Items.ANCHOVY_OIL_11264) { player, used, with ->
if (removeItem(player, used, Container.INVENTORY)) {
replaceSlot(player, with.asItem().slot, Items.IMP_REPELLENT_11262.asItem())
sendMessage(player, "You mix the flower petals with the anchovy oil to make a very strange-smelling concoction.")
}
return@onUseWith true
}
onUseWith(SCENERY, Items.SWAMP_TAR_1939, *stills) {player, used, _ ->
if(checkStillEmpty(player)){
removeItem(player, used)
setVarbit(player, 425, 4, 2, save = true)
sendMessage(player, "You refine some swamp tar into lamp oil.")
} else {
sendStillFull(player)
}
return@onUseWith true
}
onUseWith(SCENERY, fillableItems.keys.toIntArray(), *stills){player, used, _ ->
when {
checkStillEmpty(player) -> sendMessage(player, "There is no oil in the sill.")
getStillState(player) == 2 -> {
val replacement = fillableItems[used.id]?.asItem() ?: return@onUseWith false
replaceSlot(player, used.asItem().slot, replacement)
setVarbit(player, 425, 4, 0)
sendMessage(player, "You fill the ${replacement.name.toLowerCase()} with oil.")
}
else -> sendMessage(player, "There is refined imp repellent in this still, not lamp oil.")
}
return@onUseWith true
}
onUseWith(SCENERY, Items.IMP_REPELLENT_11262, *stills){player, used, _ ->
when {
checkStillEmpty(player) -> {
replaceSlot(player, used.asItem().slot, Items.VIAL_229.asItem())
sendMessage(player, "You refine some imp repellent.")
setVarbit(player, 425, 4, 4)
}
else -> sendStillFull(player)
}
return@onUseWith true
}
onUseWith(SCENERY, Items.BUTTERFLY_JAR_10012, *stills){player, used, _ ->
when {
checkStillEmpty(player) -> sendMessage(player, "There is no refined imp repellent in the still.")
getStillState(player) == 2 -> {
replaceSlot(player, used.asItem().slot, Items.IMPLING_JAR_11260.asItem())
setVarbit(player, 425, 4, 0)
sendMessage(player, "You turn the butterfly jar into an impling jar.")
}
else -> sendMessage(player, "There is lamp oil in this still, not refined imp repellent.")
}
return@onUseWith true
}
}
private fun checkStillEmpty(player: Player) : Boolean {
val stillState = getStillState(player)
return stillState == 0
}
private fun sendStillFull(player: Player) {
val stillState = getStillState(player)
if(stillState != 0) {
when(stillState) {
2 -> sendMessage(player, "There is already lamp oil in the still.")
4 -> sendMessage(player, "There is already imp repellent in the still.")
}
}
}
private fun getStillState(player: Player): Int {
return getVarbitValue(player, 425, 4)
}
}
@@ -1,94 +0,0 @@
package rs09.game.interaction.item.withitem
import api.*
import core.game.node.item.Item
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
import kotlin.collections.toIntArray
import kotlin.math.min
class PoisonedWeaponListeners : InteractionListener() {
override fun defineListeners() {
val poisons = intArrayOf(Items.WEAPON_POISON_187, Items.WEAPON_POISON_PLUS_5937, Items.WEAPON_POISON_PLUS_PLUS_5940)
val poisonableItems = PoisonSets.itemMap.keys.toIntArray()
val poisonedItems = PoisonSets.itemMap.values.toIntArray()
onUseWith(ITEM, poisons, *poisonableItems){player, used, with ->
val index = poisons.indexOf(used.id)
val product = PoisonSets.itemMap[with.id]!![index]
val amt = min(5, with.asItem().amount)
if(removeItem(player, Item(with.id, amt))) {
addItemOrDrop(player, product, amt)
addItemOrDrop(player, Items.VIAL_229)
sendMessage(player, "You poison the ${with.name.toLowerCase()}.")
}
return@onUseWith true
}
onUseWith(ITEM, Items.CLEANING_CLOTH_3188, *poisonedItems) {player, _, with ->
val base = PoisonSets.getBase(with.id) ?: return@onUseWith false
val amt = min(5, with.asItem().amount)
removeItem(player, Item(with.id, amt))
addItemOrDrop(player, base, amt)
return@onUseWith true
}
}
//below enum copied from old file, some data is probably wrong.
internal enum class PoisonSets(val base: Int, val p: Int, val pp: Int, val ppp: Int){
BRONZE_ARROW(882, 883, 5616, 883),
IRON_ARROW(884, 885, 5617, 885),
STEEL_ARROW(886, 887, 5618, 887),
MITHRIL_ARROW(888, 889, 5619, 889),
ADAMANT_ARROW(890, 891, 5620, 891),
RUNE_ARROW(892, 893, 5621, 893),
IRON_KNIFE(863, 871, 5655, 5662),
RONZE_KNIFE(864, 870, 5654, 5661),
STEEL_KNIFE(865, 872, 5656, 5663),
MITHRIL_KNIFE(866, 873, 5657, 5664),
ADAMANT_KNIFE(867, 875, 5659, 5666),
RUNE_KNIFE(868, 876, 5660, 5667),
BLACK_KNIFE(869, 874, 5658, 5665),
BRONZE_DART(806, 812, 5628, 5635),
IRON_DART(807, 813, 5629, 5636),
STEEL_DART(808, 814, 5630, 5637),
BLACK_DART(3093, 3094, 5631, 5638),
MITHRIL_DART(809, 815, 5632, 5639),
ADAMANT_DART(810, 816, 5633, 5640),
RUNE_DART(811, 817, 5634, 5641),
IRON_JAVELIN(825, 831, 5641, 5648),
BRONZE_JAVELIN(826, 832, 5642, 5649),
STEEL_JAVELIN(827, 833, 5643, 5650),
MITHRIL_JAVELIN(828, 834, 5644, 5651),
ADAMANT_JAVELIN(829, 835, 5645, 5652),
RUNE_JAVELIN(830, 836, 5646, 5653),
IRON_DAGGER(1203, 1219, 5668, 5686),
BRONZE_DAGGER(1205, 1221, 5670, 5688),
STEEL_DAGGER(1207, 1223, 5672, 5690),
MITHRIL_DAGGER(1209, 1225, 5674, 5692),
ADAMANT_DAGGER(1211, 1227, 5676, 5694),
RUNE_DAGGER(1213, 1229, 5678, 5696),
DRAGON_DAGGER(1215, 1231, 5680, 5698),
BLACK_DAGGER(1217, 1233, 5682, 5700),
BRONZE_SPEAR(1237, 1251, 5704, 5618),
IRON_SPEAR(1239, 1253, 5706, 5620),
STEEL_SPEAR(1241, 1255, 5708, 5622),
MITHRIL_SPEAR(1243, 1257, 5710, 5624),
ADAMANT_SPEAR(1245, 1259, 5712, 5626),
RUNE_SPEAR(1247, 1261, 5714, 5628),
DRAGON_SPEAR(1249, 1263, 5716, 5730),
BLACK_SPEAR(4580, 4582, 5734, 5636);
companion object {
val itemMap = values().map { it.base to intArrayOf(it.p,it.pp,it.ppp) }.toMap()
fun getBase(poisoned: Int) : Int? {
for ((base,set) in itemMap.entries) {
if (set.contains(poisoned)) return base
}
return null
}
}
}
}
@@ -1,19 +0,0 @@
package rs09.game.interaction.item.withitem
import api.addItem
import api.removeItem
import api.sendDialogue
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
class SardineSeasoner : InteractionListener() {
override fun defineListeners() {
onUseWith(ITEM, Items.DOOGLE_LEAVES_1573, Items.RAW_SARDINE_327) {player, used, with ->
if(removeItem(player, used.asItem()) && removeItem(player, with.asItem())){
addItem(player, Items.DOOGLE_SARDINE_1552)
sendDialogue(player, "You rub the doogle leaves over the sardine.")
}
return@onUseWith true
}
}
}
@@ -1,17 +0,0 @@
package rs09.game.interaction.item.withitem
import api.asItem
import api.replaceSlot
import api.sendMessage
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
class SilkRumListener : InteractionListener() {
override fun defineListeners() {
onUseWith(ITEM, Items.KARAMJAN_RUM_431, Items.SILK_950){player, _, with ->
replaceSlot(player, with.asItem().slot, Items.CLEANING_CLOTH_3188.asItem())
sendMessage(player, "You pour some of the Karamjan rum over the silk.")
return@onUseWith true
}
}
}
@@ -1,35 +0,0 @@
package rs09.game.interaction.item.withitem
import api.addItem
import api.removeItem
import api.sendDialogue
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
class SkullSceptreCombiner : InteractionListener() {
override fun defineListeners() {
onUseWith(ITEM, Items.LEFT_SKULL_HALF_9008, Items.RIGHT_SKULL_HALF_9007) {player, used, with ->
if(removeItem(player, used.asItem()) && removeItem(player, with.asItem())){
addItem(player, Items.STRANGE_SKULL_9009)
sendDialogue(player, "The two halves of the skull fit perfectly.")
}
return@onUseWith true
}
onUseWith(ITEM, Items.BOTTOM_OF_SCEPTRE_9011, Items.TOP_OF_SCEPTRE_9010) {player, used, with ->
if(removeItem(player, used.asItem()) && removeItem(player, with.asItem())){
addItem(player, Items.RUNED_SCEPTRE_9012)
sendDialogue(player, "The two halves of the sceptre fit perfectly.")
}
return@onUseWith true
}
onUseWith(ITEM, Items.RUNED_SCEPTRE_9012, Items.STRANGE_SKULL_9009) {player, used, with ->
if(removeItem(player, used.asItem()) && removeItem(player, with.asItem())){
addItem(player, Items.SKULL_SCEPTRE_9013)
sendDialogue(player,"The skull fits perfectly on top of the sceptre.")
}
return@onUseWith true
}
}
}