Converted all item -> withnpc plugins to listeners

This commit is contained in:
Ceikry
2021-12-19 23:47:14 +00:00
parent ea1db77145
commit a8b00c25a2
13 changed files with 192 additions and 364 deletions
+29
View File
@@ -18,6 +18,7 @@ import core.game.node.entity.player.Player
import core.game.node.entity.player.link.TeleportManager
import core.game.node.entity.player.link.audio.Audio
import core.game.node.entity.player.link.emote.Emotes
import core.game.node.entity.player.link.quest.QuestRepository
import core.game.node.entity.skill.gather.SkillingTool
import core.game.node.item.GroundItem
import core.game.node.item.GroundItemManager
@@ -775,6 +776,20 @@ fun location(x: Int, y: Int, z: Int): Location{
return Location.create(x,y,z)
}
/**
* Checks if the given entity is within the given ZoneBorders
*/
fun inBorders(entity: Entity, borders: ZoneBorders): Boolean{
return borders.insideBorder(entity)
}
/**
* Checks if the given entity is within the given borders
*/
fun inBorders(entity: Entity, swX: Int, swY: Int, neX: Int, neY: Int): Boolean {
return ZoneBorders(swX,swY,neX,neY).insideBorder(entity)
}
/**
* AHeals the given entity for the given number of hitpoints
*/
@@ -1248,6 +1263,20 @@ fun getQP(player: Player): Int{
return player.questRepository.points
}
/**
* Gets the stage for the given quest for the given player
*/
fun questStage(player: Player, quest: String): Int{
return player.questRepository.getStage(quest)
}
/**
* Sets the stage for the given quest for the given player
*/
fun setQuestStage(player: Player, quest: String, stage: Int) {
player.questRepository.setStage(QuestRepository.getQuests()[quest]!!, stage)
}
/**
* Gets a scenery definition from the given ID
* @param id the ID of the scenery to get the definition for.
@@ -0,0 +1,25 @@
package rs09.game.interaction.item.withnpc
import api.removeItem
import api.sendChat
import api.sendMessage
import core.game.content.global.Bones
import core.game.node.entity.player.link.diary.DiaryType
import org.rs09.consts.NPCs
import rs09.game.interaction.InteractionListener
class BonesOnStrayDog : InteractionListener() {
override fun defineListeners() {
val bones = Bones.array
val dogs = intArrayOf(NPCs.STRAY_DOG_4766, NPCs.STRAY_DOG_4767, NPCs.STRAY_DOG_5917, NPCs.STRAY_DOG_5918)
onUseWith(NPC, bones, *dogs){player, used, with ->
if(removeItem(player, used.asItem())){
sendMessage(player, "You feed your dog bones.")
sendChat(with.asNpc(), "Woof")
player.achievementDiaryManager.finishTask(player, DiaryType.VARROCK, 0, 8)
}
return@onUseWith true
}
}
}
@@ -0,0 +1,20 @@
package rs09.game.interaction.item.withnpc
import api.inBorders
import api.openDialogue
import org.rs09.consts.Items
import rs09.game.interaction.InteractionListener
class CiderOnForester : InteractionListener() {
override fun defineListeners() {
val ids = intArrayOf(1,2,3,4,5)
onUseWith(NPC, Items.CIDER_5763, *ids){player, used, with ->
if(inBorders(player, 2689, 3488, 2700, 3498)){
openDialogue(player, with.id, with.asNpc(), used.asItem())
return@onUseWith true
}
return@onUseWith false
}
}
}
@@ -0,0 +1,75 @@
package rs09.game.interaction.item.withnpc
import api.*
import core.game.system.task.Pulse
import core.game.world.map.Location
import core.game.world.map.path.Path
import core.game.world.map.path.Pathfinder
import org.rs09.consts.Items
import org.rs09.consts.NPCs
import rs09.game.interaction.InteractionListener
import rs09.game.world.World.Pulser
class GCItemOnCat : InteractionListener() {
override fun defineListeners() {
val GERTCAT = "Gertrude's Cat"
val BEND_DOWN = 827
onUseWith(NPC, Items.BUCKET_OF_MILK_1927, NPCs.GERTRUDES_CAT_2997) {player, used, with ->
if(questStage(player, GERTCAT) == 20 && removeItem(player, used.asItem())){
addItem(player, Items.EMPTY_BUCKET_3727)
animate(player, BEND_DOWN) //bend down
sendChat(with.asNpc(), "Mew!")
setQuestStage(player, GERTCAT, 30)
}
return@onUseWith true
}
onUseWith(NPC, Items.DOOGLE_SARDINE_1552, NPCs.GERTRUDES_CAT_2997){player, used, with ->
if(questStage(player, GERTCAT) == 30 && removeItem(player, used.asItem())){
animate(player, BEND_DOWN)
sendChat(with.asNpc(), "Mew!")
setQuestStage(player, GERTCAT, 40)
}
return@onUseWith true
}
onUseWith(NPC, Items.RAW_SARDINE_327, NPCs.GERTRUDES_CAT_2997){player, _, _ ->
sendMessage(player, "The cat doesn't seem interested in that.")
return@onUseWith true
}
onUseWith(NPC, Items.THREE_LITTLE_KITTENS_13236, NPCs.GERTRUDES_CAT_2997){player, used, with ->
if(removeItem(player, used.asItem())){
//below copied verbatim from original, I don't like it.
Pulser.submit(object : Pulse(1) {
var count = 0
val kitten = core.game.node.entity.npc.NPC.create(761, player.location)
override fun pulse(): Boolean {
when (count) {
0 -> {
kitten.init()
kitten.face(with.asNpc())
with.asNpc().face(kitten)
with.asNpc().sendChat("Pur...")
kitten.sendChat("Pur...")
val path: Path = Pathfinder.find(with.asNpc(), Location(3310, 3510, 1))
path.walk(with.asNpc())
val pathh = Pathfinder.find(kitten, Location(3310, 3510, 1))
pathh.walk(kitten)
}
5 -> {
kitten.clear()
player.setAttribute("hidefluff", System.currentTimeMillis() + 60000)
}
}
count++
return count == 6
}
})
}
return@onUseWith true
}
}
}
@@ -0,0 +1,15 @@
package rs09.game.interaction.item.withnpc
import api.openDialogue
import org.rs09.consts.Items
import org.rs09.consts.NPCs
import rs09.game.interaction.InteractionListener
class PoisonChaliceOnKingArthur : InteractionListener() {
override fun defineListeners() {
onUseWith(NPC, Items.POISON_CHALICE_197, NPCs.KING_ARTHUR_251){player, used, with ->
openDialogue(player, with.id, with.asNpc(), used.asItem())
return@onUseWith true
}
}
}
@@ -0,0 +1,27 @@
package rs09.game.interaction.item.withnpc
import api.*
import org.rs09.consts.Items
import org.rs09.consts.NPCs
import rs09.game.interaction.InteractionListener
class RopeOnLadyKeli : InteractionListener() {
override fun defineListeners() {
val PAR = "Prince Ali Rescue"
onUseWith(NPC, Items.ROPE_954, NPCs.LADY_KELI_919) {player, used, with ->
if(questStage(player, PAR) in 40..50 && getAttribute(player, "guard-drunk", false)){
if(removeItem(player, used.asItem())){
sendDialogue(player, "You overpower Keli, tie her up, and put her in a cupboard.")
setQuestStage(player, PAR, 50)
setAttribute(player, "keli-gone", getWorldTicks() + 350)
}
} else {
if (questStage(player, PAR) == 40){
sendMessage(player, "You need to do something about the guard first.")
}
}
return@onUseWith true
}
}
}