mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-19 21:10:17 -07:00
HunterTalismanHandler -> HunterTalismanListener.kt
This commit is contained in:
parent
5f70aa801c
commit
7cc0a782fb
1 changed files with 40 additions and 57 deletions
|
|
@ -1,21 +1,54 @@
|
|||
package rs09.game.content.quest.members.thefremenniktrials
|
||||
|
||||
import core.cache.def.impl.ItemDefinition
|
||||
import core.game.interaction.OptionHandler
|
||||
import core.game.node.Node
|
||||
import core.game.node.entity.Entity
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.Item
|
||||
import core.game.system.task.Pulse
|
||||
import rs09.game.world.GameWorld
|
||||
import core.game.world.map.Location
|
||||
import core.plugin.Initializable
|
||||
import core.plugin.Plugin
|
||||
import org.rs09.consts.Items
|
||||
import rs09.game.interaction.InteractionListener
|
||||
import rs09.game.world.GameWorld.Pulser
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.atan2
|
||||
|
||||
@Initializable
|
||||
class TalismanHandler : OptionHandler() {
|
||||
class HunterTalismanListener : InteractionListener() {
|
||||
|
||||
val TALISMAN = Items.HUNTERS_TALISMAN_3696
|
||||
|
||||
override fun defineListeners() {
|
||||
|
||||
on(TALISMAN,ITEM,"locate"){player,_ ->
|
||||
var locationString = player?.getAttribute("fremtrials:draugen-loc","none")
|
||||
if(locationString == "none"){
|
||||
val newLoc = possibleLocations.random()
|
||||
player?.setAttribute("/save:fremtrials:draugen-loc","${newLoc.x},${newLoc.y}")
|
||||
locationString = "${newLoc.x},${newLoc.y}"
|
||||
}
|
||||
val locationComponents = locationString?.split(",")
|
||||
val draugenLoc = Location(Integer.parseInt(locationComponents?.get(0)),Integer.parseInt(locationComponents?.get(1)))
|
||||
|
||||
if(player.location?.withinDistance(draugenLoc,5)!!){
|
||||
player.dialogueInterpreter.sendDialogue("The Draugen is nearby, be careful!")
|
||||
Pulser.submit(DraugenPulse(player))
|
||||
} else {
|
||||
val neededDirection = draugenLoc.getDirection(player as Entity)
|
||||
player.sendMessage("The talisman pulls you to the $neededDirection")
|
||||
}
|
||||
return@on true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DraugenPulse(val player: Player?) : Pulse(){
|
||||
var count = 0
|
||||
override fun pulse(): Boolean {
|
||||
when(count++){
|
||||
3 -> Draugen(player).init().also { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
val possibleLocations = listOf(Location(2625,3608),
|
||||
Location(2602,3628),
|
||||
|
|
@ -67,54 +100,4 @@ class TalismanHandler : OptionHandler() {
|
|||
fun diff(x: Double,y: Double): Double{
|
||||
return abs(x - y)
|
||||
}
|
||||
|
||||
override fun fireEvent(identifier: String?, vararg args: Any?): Any {
|
||||
return Unit
|
||||
}
|
||||
|
||||
override fun handle(player: Player?, node: Node?, option: String?): Boolean {
|
||||
|
||||
class DraugenPulse(player: Player?) : Pulse(){
|
||||
var count = 0
|
||||
override fun pulse(): Boolean {
|
||||
when(count++){
|
||||
3 -> Draugen(player).init().also { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var item: Item? = Item(0)
|
||||
if(node is Item){
|
||||
item = node
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
if(item.id == 3696){
|
||||
var locationString = player?.getAttribute("fremtrials:draugen-loc","none")
|
||||
if(locationString == "none"){
|
||||
val newLoc = possibleLocations.random()
|
||||
player?.setAttribute("/save:fremtrials:draugen-loc","${newLoc.x},${newLoc.y}")
|
||||
locationString = "${newLoc.x},${newLoc.y}"
|
||||
}
|
||||
val locationComponents = locationString?.split(",")
|
||||
val draugenLoc = Location(Integer.parseInt(locationComponents?.get(0)),Integer.parseInt(locationComponents?.get(1)))
|
||||
|
||||
if(player?.location?.withinDistance(draugenLoc,5)!!){
|
||||
player.dialogueInterpreter.sendDialogue("The Draugen is nearby, be careful!")
|
||||
GameWorld.submit(DraugenPulse(player))
|
||||
} else {
|
||||
val neededDirection = draugenLoc.getDirection(player as Entity)
|
||||
player.sendMessage("The talisman pulls you to the $neededDirection")
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||
ItemDefinition.forId(3696).handlers["option:locate"] = this
|
||||
return this
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue