From c54abe696c00996f3a5ca26ac5af9955c2b5d48b Mon Sep 17 00:00:00 2001 From: Coaltong Date: Mon, 13 Jun 2022 05:02:23 +0000 Subject: [PATCH] Implemented Falador farm sheepdog interactions, can now be fed bones and meat --- .../java/core/game/content/global/Bones.kt | 2 +- .../java/core/game/content/global/Meat.kt | 53 +++++++++++++++++++ .../game/interaction/InteractionListener.kt | 5 +- .../game/interaction/InteractionListeners.kt | 9 +++- .../item/withnpc/FeedFaladorSheepdog.kt | 50 +++++++++++++++++ 5 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 Server/src/main/java/core/game/content/global/Meat.kt create mode 100644 Server/src/main/kotlin/rs09/game/interaction/item/withnpc/FeedFaladorSheepdog.kt diff --git a/Server/src/main/java/core/game/content/global/Bones.kt b/Server/src/main/java/core/game/content/global/Bones.kt index c163d99d9..f82954d6d 100644 --- a/Server/src/main/java/core/game/content/global/Bones.kt +++ b/Server/src/main/java/core/game/content/global/Bones.kt @@ -26,7 +26,7 @@ enum class Bones BONES(2530, 4.5), BONES_2(526, 4.5), WOLF_BONES(2859, 4.5), - BURNST_BONES(528, 4.5), + BURNT_BONES(528, 4.5), MONKEY_BONES(3183, 5.0), MONKEY_BONES2(3179, 5.0), BAT_BONES(530, 5.3), diff --git a/Server/src/main/java/core/game/content/global/Meat.kt b/Server/src/main/java/core/game/content/global/Meat.kt new file mode 100644 index 000000000..5248986bc --- /dev/null +++ b/Server/src/main/java/core/game/content/global/Meat.kt @@ -0,0 +1,53 @@ +package core.game.content.global + +import java.util.ArrayList + +enum class MeatState { + INEDIBLE_RAW, + INEDIBLE_BURNT, + INEDIBLE_SPECIAL, // could be a quest item + EDIBLE_COOKED, +} + +enum class Meat(val id: Int, val state: MeatState) { + ENCHANTED_BEEF(522, MeatState.INEDIBLE_SPECIAL), + ENCHANTED_RAT_MEAT(523, MeatState.INEDIBLE_SPECIAL), + ENCHANTED_BEAR_MEAT(524, MeatState.INEDIBLE_SPECIAL), + ENCHANTED_CHICKEN(525, MeatState.INEDIBLE_SPECIAL), + RAW_UGTHANKI_MEAT(1859, MeatState.INEDIBLE_RAW), + UGTHANKI_MEAT(1861, MeatState.EDIBLE_COOKED), + RAW_BEEF(2132, MeatState.INEDIBLE_RAW), + RAW_RAT_MEAT(2134, MeatState.INEDIBLE_RAW), + RAW_BEAR_MEAT(2136, MeatState.INEDIBLE_RAW), + RAW_CHICKEN(2138, MeatState.INEDIBLE_RAW), + COOKED_CHICKEN(2140, MeatState.EDIBLE_COOKED), + BURNT_CHICKEN(2140, MeatState.INEDIBLE_BURNT), + COOKED_MEAT(2142, MeatState.EDIBLE_COOKED), + BURNT_MEAT(2146, MeatState.INEDIBLE_BURNT), + THIN_SNAIL_MEAT(3369, MeatState.EDIBLE_COOKED), + LEAN_SNAIL_MEAT(3371, MeatState.EDIBLE_COOKED), + FAT_SNAIL_MEAT(3373, MeatState.EDIBLE_COOKED), + RAW_BEEF_UNDEAD(4287, MeatState.INEDIBLE_RAW), + RAW_CHICKEN_UNDEAD(4289, MeatState.INEDIBLE_RAW), + COOKED_CHICKEN_UNDEAD(4291, MeatState.EDIBLE_COOKED), + COOKED_MEAT_UNDEAD(4293, MeatState.EDIBLE_COOKED), + RAW_CRAB_MEAT(7518, MeatState.INEDIBLE_RAW), + BURNT_CRAB_MEAT(7520, MeatState.INEDIBLE_BURNT), + COOKED_CRAB_MEAT_5(7521, MeatState.EDIBLE_COOKED), + COOKED_CRAB_MEAT_4(7523, MeatState.EDIBLE_COOKED), + COOKED_CRAB_MEAT_3(7524, MeatState.EDIBLE_COOKED), + COOKED_CRAB_MEAT_2(7525, MeatState.EDIBLE_COOKED), + COOKED_CRAB_MEAT_1(7526, MeatState.EDIBLE_COOKED), + GROUND_CRAB_MEAT(7527, MeatState.INEDIBLE_RAW), + LOCUST_MEAT(9052, MeatState.EDIBLE_COOKED), + RAW_BIRD_MEAT(9978, MeatState.INEDIBLE_RAW), + ROAST_BIRD_MEAT(9980, MeatState.EDIBLE_COOKED), + BURNT_BIRD_MEAT(9982, MeatState.INEDIBLE_BURNT), + SKEWERED_BIRD_MEAT(9982, MeatState.INEDIBLE_RAW), + RAW_BEAST_MEAT(9986, MeatState.INEDIBLE_RAW), + ROAST_BEAST_MEAT(9988, MeatState.EDIBLE_COOKED), + BURNT_BEAST_MEAT(9990, MeatState.INEDIBLE_BURNT), + RAW_YAK_MEAT(10816, MeatState.INEDIBLE_RAW), + RAW_PAWYA_MEAT(12535, MeatState.INEDIBLE_RAW), + ENCHANTED_PAWYA_MEAT(12546, MeatState.INEDIBLE_SPECIAL); +} \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/interaction/InteractionListener.kt b/Server/src/main/kotlin/rs09/game/interaction/InteractionListener.kt index 9edab7521..ec7cfa173 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/InteractionListener.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/InteractionListener.kt @@ -34,6 +34,9 @@ interface InteractionListener : ContentInterface{ fun onUseWith(type: Int, used: IntArray, vararg with: Int, handler: (player: Player, used: Node, with: Node) -> Boolean){ InteractionListeners.add(type,used,with,handler) } + fun onUseAnyWith(type: Int, vararg with: Int, handler: (player: Player, used: Node, with: Node) -> Boolean) { + InteractionListeners.add(type, with, handler) + } // Note: wildcard listeners incur overhead on every use-with interaction, only use them as a space-time tradeoff when something // is actually supposed to have a response to every item used with it (e.g. imp boxes, certain quest npcs) fun onUseWithWildcard(type: Int, predicate: (used: Int, with: Int) -> Boolean, handler: (player: Player, used: Node, with: Node) -> Boolean) { @@ -53,7 +56,7 @@ interface InteractionListener : ContentInterface{ ids.forEach{ id -> InteractionListeners.addUnequip(id,handler) } } - open fun defineDestinationOverrides(){} + fun defineDestinationOverrides(){} fun setDest(type: Int, id: Int,handler: (Entity, Node) -> Location){ InteractionListeners.addDestOverride(type,id,handler) diff --git a/Server/src/main/kotlin/rs09/game/interaction/InteractionListeners.kt b/Server/src/main/kotlin/rs09/game/interaction/InteractionListeners.kt index 7c17868b8..760029d67 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/InteractionListeners.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/InteractionListeners.kt @@ -14,6 +14,7 @@ import rs09.game.system.SystemLogger object InteractionListeners { private val listeners = HashMap Boolean>(1000) private val useWithListeners = HashMap Boolean>(1000) + private val useAnyWithListeners = HashMap Boolean>(10) private val useWithWildcardListeners = HashMap Boolean, (Player, Node, Node) -> Boolean>>>(10) private val destinationOverrides = HashMap Location>(100) private val equipListeners = HashMap Boolean>(10) @@ -88,7 +89,7 @@ object InteractionListeners { @JvmStatic fun get(used: Int, with: Int, type: Int): ((Player,Node,Node) -> Boolean)? { - var method = useWithListeners["$used:$with:$type"] + val method = useWithListeners["$used:$with:$type"] ?: useAnyWithListeners["$with:$type"] if(method != null) { return method } @@ -250,4 +251,10 @@ object InteractionListeners { } } } + + fun add(type: Int, with: IntArray, handler: (Player, Node, Node) -> Boolean) { + for (w in with) { + useAnyWithListeners["$w:$type"] = handler + } + } } diff --git a/Server/src/main/kotlin/rs09/game/interaction/item/withnpc/FeedFaladorSheepdog.kt b/Server/src/main/kotlin/rs09/game/interaction/item/withnpc/FeedFaladorSheepdog.kt new file mode 100644 index 000000000..f007ab93b --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/interaction/item/withnpc/FeedFaladorSheepdog.kt @@ -0,0 +1,50 @@ +package rs09.game.interaction.item.withnpc + +import api.* +import core.game.content.global.Bones +import core.game.content.global.Meat +import core.game.content.global.MeatState +import core.game.world.update.flag.context.Animation +import org.rs09.consts.Animations +import org.rs09.consts.Items +import org.rs09.consts.NPCs +import rs09.game.interaction.InteractionListener + +class FeedFaladorSheepdog : InteractionListener { + companion object { + private const val SHEEP_DOG_NPC = NPCs.SHEEPDOG_2311 + private val FEED_ANIMATION = Animation(Animations.HUMAN_BURYING_BONES_827) + private val CONSUMABLE_BONES = Bones.array + .filter { it != Items.BURNT_BONES_528 } + .toHashSet() + private val CONSUMABLE_MEATS = Meat.values() + .filter { it.state == MeatState.INEDIBLE_RAW || it.state == MeatState.EDIBLE_COOKED } + .map { it.id } + .toHashSet() + } + + override fun defineListeners() { + onUseAnyWith(NPC, SHEEP_DOG_NPC) { player, used, with -> + if (CONSUMABLE_BONES.contains(used.id)) { + if (!removeItem(player, used.asItem())) { + return@onUseAnyWith true + } + sendDialogue(player, "You give the dog some nice ${used.name.toLowerCase()}. It happily gnaws on them.") + } else if (CONSUMABLE_MEATS.contains(used.id)) { + if (!removeItem(player, used.asItem())) { + return@onUseAnyWith true + } + sendDialogue(player, "You give the dog a nice piece of meat. It gobbles it up.") + } else { + sendMessage(player, "The dog doesn't seem interested in that.") + sendChat(with.asNpc(), "Grrrr!") + return@onUseAnyWith true + } + + animate(player, FEED_ANIMATION) + sendChat(with.asNpc(), "Woof woof!") + + return@onUseAnyWith true + } + } +} \ No newline at end of file