Converted EnchantedGemPlugin to Listener

Converted EnchantedGemDialogue to DialogueFile
This commit is contained in:
bushtail
2022-07-03 06:32:03 +00:00
committed by Ryan
parent c4781e8000
commit 16353eda20
4 changed files with 138 additions and 386 deletions
+72
View File
@@ -22,6 +22,7 @@ import core.game.node.entity.player.link.emote.Emotes
import core.game.node.entity.player.link.quest.QuestRepository
import core.game.node.entity.skill.Skills
import core.game.node.entity.skill.gather.SkillingTool
import core.game.node.entity.skill.slayer.Tasks
import core.game.node.entity.skill.summoning.familiar.BurdenBeast
import core.game.node.item.GroundItem
import core.game.node.item.GroundItemManager
@@ -41,6 +42,7 @@ import core.game.world.update.flag.chunk.AnimateObjectUpdateFlag
import core.game.world.update.flag.context.Animation
import core.game.world.update.flag.context.Graphics
import org.rs09.consts.Items
import org.rs09.consts.NPCs
import rs09.game.content.dialogue.DialogueFile
import rs09.game.content.dialogue.SkillDialogueHandler
import rs09.game.content.global.GlobalKillCounter
@@ -1589,6 +1591,15 @@ fun getPathableRandomLocalCoordinate(target: Entity, radius: Int, center: Locati
return target.location
}
/**
* Returns the player's active slayer task.
* @author bushtail
* @param player the player whose task we are checking.
* @return the slayer task.
*/
fun getSlayerTask(player : Player) : Tasks? {
return SlayerManager.getInstance(player).task
}
/**
* Returns the name of the player's active slayer task.
@@ -1608,4 +1619,65 @@ fun getSlayerTaskName(player : Player) : String {
*/
fun getSlayerTaskKillsRemaining(player : Player) : Int {
return SlayerManager.getInstance(player).amount
}
/**
* Returns the player's slayer master as npc.
* @author bushtail
* @param player the player whose master we are checking.
* @return the slayer master as NPC.
*/
fun getSlayerMaster(player : Player) : NPC {
return findNPC(SlayerManager.getInstance(player).master?.npc as Int) as NPC
}
/**
* Returns the player's slayer master location as string.
* @author bushtail
* @param player the player whose master we are checking.
* @return the slayer master location as String.
*/
fun getSlayerMasterLocation(player : Player) : String {
return when(getSlayerMaster(player).id) {
NPCs.CHAELDAR_1598 -> "Zanaris"
NPCs.DURADEL_8275 -> "Shilo Village"
NPCs.MAZCHNA_8274 -> "Canifis"
NPCs.TURAEL_8273 -> "Taverly"
NPCs.VANNAKA_1597 -> "Edgeville Dungeon"
else -> "The Backrooms"
}
}
/**
* Returns the player's slayer task tip as String.
* @author bushtail
* @param player the player whose task tip we are checking.
* @return the task tip as String.
*/
fun getSlayerTip(player : Player) : Array<out String> {
return if(hasSlayerTask(player)) {
SlayerManager.getInstance(player).task?.tip!!
} else {
arrayOf("You need something new to hunt.")
}
}
/**
* Returns the player's slayer task flags as Int.
* @author bushtail
* @param player the player whose task flags we are checking.
* @return the task flags as Int.
*/
fun getSlayerTaskFlags(player : Player) : Int {
return SlayerManager.getInstance(player).flags.taskFlags
}
/**
* Returns whether or not the player has a task.
* @author bushtail
* @param player the player whose task we are checking.
* @return has task as Boolean.
*/
fun hasSlayerTask(player : Player) : Boolean {
return SlayerManager.getInstance(player).hasTask()
}
@@ -0,0 +1,66 @@
package rs09.game.interaction.item
import api.*
import core.game.content.dialogue.FacialExpression
import core.game.node.entity.skill.slayer.Tasks
import org.rs09.consts.Items
import rs09.game.content.dialogue.DialogueFile
import rs09.game.content.dialogue.IfTopic
import rs09.game.content.dialogue.Topic
import rs09.game.interaction.InteractionListener
import rs09.tools.END_DIALOGUE
class EnchantedGemListener : InteractionListener {
override fun defineListeners() {
on(Items.ENCHANTED_GEM_4155, ITEM, "activate") { player, _ ->
openDialogue(player, EnchantedGemDialogue())
return@on true
}
}
}
class EnchantedGemDialogue() : DialogueFile() {
var firstRun = true
override fun handle(interfaceId: Int, buttonId: Int) {
npc = getSlayerMaster(player!!)
when(stage) {
0 -> npcl(FacialExpression.FRIENDLY, "Hello there ${player!!.username}, what can I help you with?").also { stage++ }
1 -> showTopics(
Topic(FacialExpression.ASKING, "How am I doing so far?", 100),
Topic(FacialExpression.HALF_ASKING, "Who are you?", 200),
Topic(FacialExpression.HALF_ASKING, "Where are you?", 300),
Topic(FacialExpression.FRIENDLY, "Got any tips for me?", 400),
IfTopic(FacialExpression.FRIENDLY, "Nothing really.", END_DIALOGUE, firstRun),
IfTopic(FacialExpression.HAPPY, "That's all thanks.", END_DIALOGUE, !firstRun)
)
100 -> {
firstRun = false
if(!hasSlayerTask(player!!)) {
npcl(FacialExpression.HALF_THINKING, "You need something new to hunt. Come and see me when you can and I'll give you a new task.").also { stage = 1 }
} else {
if(getSlayerTask(player!!) == Tasks.JAD) {
npcl(FacialExpression.FRIENDLY, "You're currently assigned to kill TzTok-Jad!")
} else {
npcl(FacialExpression.FRIENDLY, "You're currently assigned to kill ${getSlayerTaskName(player!!)}s; only ${getSlayerTaskKillsRemaining(player!!)} more to go.")
}
setVarbit(player!!, 2502, 0, getSlayerTaskFlags(player!!))
stage = 1
}
}
200 -> {
firstRun = false
npcl(FacialExpression.HAPPY, "My name's ${getSlayerMaster(player!!).name}, I'm the Slayer Master best able to train you.").also { stage = 1 }
}
300 -> {
firstRun = false
npcl(FacialExpression.HAPPY, "You'll find me in ${getSlayerMasterLocation(player!!)}, I'll be here when you need a new task.").also { stage = 1 }
}
400 -> {
firstRun = false
npc(FacialExpression.FRIENDLY, *getSlayerTip(player!!))
stage++
}
401 -> player(FacialExpression.HAPPY, "Great, thanks!").also { stage = 1 }
}
}
}