Implemented Falador farm sheepdog interactions, can now be fed bones and meat
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -14,6 +14,7 @@ import rs09.game.system.SystemLogger
|
||||
object InteractionListeners {
|
||||
private val listeners = HashMap<String,(Player, Node) -> Boolean>(1000)
|
||||
private val useWithListeners = HashMap<String,(Player,Node,Node) -> Boolean>(1000)
|
||||
private val useAnyWithListeners = HashMap<String, (Player, Node, Node) -> Boolean>(10)
|
||||
private val useWithWildcardListeners = HashMap<Int, ArrayList<Pair<(Int, Int) -> Boolean, (Player, Node, Node) -> Boolean>>>(10)
|
||||
private val destinationOverrides = HashMap<String,(Entity, Node) -> Location>(100)
|
||||
private val equipListeners = HashMap<String,(Player,Node) -> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user