mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-14 10:30:20 -07:00
Kotlin object handlers converted to listeners
This commit is contained in:
parent
19e20d9dc9
commit
a2a8d32d4b
5 changed files with 91 additions and 121 deletions
|
|
@ -1,38 +1,31 @@
|
|||
package rs09.game.interaction.`object`
|
||||
|
||||
import core.cache.def.impl.ObjectDefinition
|
||||
import core.game.interaction.OptionHandler
|
||||
import core.game.node.Node
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.entity.player.link.diary.DiaryType
|
||||
import core.game.node.entity.player.link.emote.Emotes
|
||||
import core.game.world.map.RegionManager
|
||||
import core.plugin.Initializable
|
||||
import core.plugin.Plugin
|
||||
import rs09.game.interaction.OptionListener
|
||||
|
||||
@Initializable
|
||||
/**
|
||||
* Handles taunting of the demon in the wizard's tower
|
||||
* @author afaroutdude / Ceikry
|
||||
*/
|
||||
class DemonTauntHandler : OptionHandler(){
|
||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||
ObjectDefinition.forId(37668).handlers["option:taunt-through"] = this
|
||||
return this
|
||||
}
|
||||
private const val BARS = 37668
|
||||
class DemonTauntHandler : OptionListener(){
|
||||
|
||||
override fun handle(player: Player?, node: Node?, option: String?): Boolean {
|
||||
player ?: return false
|
||||
player.packetDispatch.sendMessage("You taunt the demon, making it growl.")
|
||||
val localNpcs = RegionManager.getLocalNpcs(player)
|
||||
player.animator.animate(Emotes.RASPBERRY.animation)
|
||||
for (npc in localNpcs) {
|
||||
if (npc.id == 82) {
|
||||
npc.sendChat("Graaaagh!", 1)
|
||||
player.faceLocation(npc.location)
|
||||
override fun defineListeners() {
|
||||
on(BARS,OBJECT,"taunt-through"){player,_ ->
|
||||
player.packetDispatch.sendMessage("You taunt the demon, making it growl.")
|
||||
val localNpcs = RegionManager.getLocalNpcs(player)
|
||||
player.animator.animate(Emotes.RASPBERRY.animation)
|
||||
for (npc in localNpcs) {
|
||||
if (npc.id == 82) {
|
||||
npc.sendChat("Graaaagh!", 1)
|
||||
player.faceLocation(npc.location)
|
||||
}
|
||||
}
|
||||
player.achievementDiaryManager.finishTask(player, DiaryType.LUMBRIDGE, 1, 13)
|
||||
return@on true
|
||||
}
|
||||
player.achievementDiaryManager.finishTask(player, DiaryType.LUMBRIDGE, 1, 13)
|
||||
return true
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,10 @@
|
|||
package rs09.game.interaction.`object`
|
||||
|
||||
import core.cache.def.impl.ObjectDefinition
|
||||
import core.game.component.Component
|
||||
import core.game.interaction.OptionHandler
|
||||
import core.game.node.Node
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.entity.player.link.TeleportManager.TeleportType
|
||||
import core.game.world.map.Location
|
||||
import core.plugin.Initializable
|
||||
import core.plugin.Plugin
|
||||
import rs09.game.interaction.OptionListener
|
||||
|
||||
/**
|
||||
* Handles interactions with fairy rings
|
||||
|
|
@ -19,30 +15,28 @@ private val RINGS = intArrayOf(12003, 12094, 12095, 14058, 14061, 14064, 14067,
|
|||
private const val MAIN_RING = 12128
|
||||
|
||||
|
||||
@Initializable
|
||||
class FairyRingPlugin : OptionHandler() {
|
||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||
for (i in RINGS) {
|
||||
ObjectDefinition.forId(i).handlers["option:use"] = this
|
||||
}
|
||||
ObjectDefinition.forId(MAIN_RING).handlers["option:use"] = this
|
||||
return this
|
||||
}
|
||||
class FairyRingPlugin : OptionListener() {
|
||||
|
||||
override fun handle(player: Player, node: Node, option: String): Boolean {
|
||||
when (option) {
|
||||
"use" -> {
|
||||
if (!player.equipment.contains(772, 1) && !player.equipment.contains(9084, 1)) {
|
||||
player.sendMessage("The fairy ring only works for those who wield fairy magic.")
|
||||
return true
|
||||
}
|
||||
when (node.id) {
|
||||
MAIN_RING -> openFairyRing(player)
|
||||
else -> player.teleporter.send(Location.create(2412, 4434, 0), TeleportType.FAIRY_RING)
|
||||
}
|
||||
override fun defineListeners() {
|
||||
|
||||
on(RINGS,OBJECT,"use"){player,_ ->
|
||||
if (!player.equipment.contains(772, 1) && !player.equipment.contains(9084, 1)) {
|
||||
player.sendMessage("The fairy ring only works for those who wield fairy magic.")
|
||||
return@on true
|
||||
}
|
||||
player.teleporter.send(Location.create(2412, 4434, 0), TeleportType.FAIRY_RING)
|
||||
return@on true
|
||||
}
|
||||
return true
|
||||
|
||||
on(MAIN_RING,OBJECT,"use"){player,_ ->
|
||||
if (!player.equipment.contains(772, 1) && !player.equipment.contains(9084, 1)) {
|
||||
player.sendMessage("The fairy ring only works for those who wield fairy magic.")
|
||||
return@on true
|
||||
}
|
||||
openFairyRing(player)
|
||||
return@on true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun reset(player: Player) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
package rs09.game.interaction.`object`
|
||||
|
||||
import core.cache.def.impl.ObjectDefinition
|
||||
import core.game.interaction.OptionHandler
|
||||
import core.game.node.Node
|
||||
import core.game.node.`object`.GameObject
|
||||
import core.game.node.`object`.ObjectBuilder
|
||||
import core.game.node.entity.npc.NPC
|
||||
|
|
@ -11,24 +8,22 @@ import core.game.node.item.GroundItemManager
|
|||
import core.game.node.item.Item
|
||||
import core.game.system.task.Pulse
|
||||
import core.game.world.update.flag.context.Animation
|
||||
import core.plugin.Initializable
|
||||
import core.plugin.Plugin
|
||||
import org.rs09.consts.Items
|
||||
import rs09.game.interaction.OptionListener
|
||||
import rs09.game.world.GameWorld
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@Initializable
|
||||
class GutanothChestOptionHandler : OptionHandler(){
|
||||
override fun handle(player: Player?, node: Node?, option: String?): Boolean {
|
||||
player ?: return false
|
||||
val delay = player.getAttribute("gutanoth-chest-delay", 0L)
|
||||
GameWorld.Pulser.submit(ChestPulse(player,System.currentTimeMillis() > delay, node as GameObject))
|
||||
return true
|
||||
}
|
||||
private const val CHEST = 2827
|
||||
class GutanothChestOptionHandler : OptionListener(){
|
||||
|
||||
override fun defineListeners() {
|
||||
|
||||
on(CHEST,OBJECT,"open"){player,node ->
|
||||
val delay = player.getAttribute("gutanoth-chest-delay", 0L)
|
||||
GameWorld.Pulser.submit(ChestPulse(player,System.currentTimeMillis() > delay, node as GameObject))
|
||||
return@on true
|
||||
}
|
||||
|
||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||
ObjectDefinition.forId(2827).handlers["option:open"] = this
|
||||
return this
|
||||
}
|
||||
|
||||
class ChestPulse(val player: Player, val isLoot: Boolean, val chest: GameObject): Pulse(){
|
||||
|
|
|
|||
|
|
@ -1,57 +1,49 @@
|
|||
package rs09.game.interaction.`object`
|
||||
|
||||
import core.cache.def.impl.ObjectDefinition
|
||||
import core.game.interaction.OptionHandler
|
||||
import core.game.node.Node
|
||||
import core.game.node.`object`.GameObject
|
||||
import core.game.node.`object`.ObjectBuilder
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.Item
|
||||
import core.game.system.task.Pulse
|
||||
import core.game.world.update.flag.context.Animation
|
||||
import core.plugin.Initializable
|
||||
import core.plugin.Plugin
|
||||
import org.rs09.consts.Items
|
||||
import rs09.game.interaction.OptionListener
|
||||
import rs09.game.world.GameWorld
|
||||
|
||||
/**
|
||||
* Handles the chopping down of dense jungle, mainly to grant access to the Kharazi Jungle.
|
||||
* @author Ceikry
|
||||
*/
|
||||
@Initializable
|
||||
class JungleBushHandler : OptionHandler(){
|
||||
class JungleBushHandler : OptionListener(){
|
||||
val chopped_bush = 2895
|
||||
val chop_a = Animation(910)
|
||||
val chop_b = Animation(2382)
|
||||
val ids = intArrayOf(2892,2893)
|
||||
|
||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||
ObjectDefinition.forId(2892).handlers["option:chop-down"] = this
|
||||
ObjectDefinition.forId(2893).handlers["option:chop-down"] = this
|
||||
return this
|
||||
}
|
||||
override fun defineListeners() {
|
||||
|
||||
override fun handle(player: Player?, node: Node?, option: String?): Boolean {
|
||||
player ?: return false
|
||||
node ?: return false
|
||||
val toChop = node.asObject()
|
||||
if(checkRequirement(player)){
|
||||
GameWorld.Pulser.submit(object : Pulse(0){
|
||||
var ticks = 0
|
||||
override fun pulse(): Boolean {
|
||||
when(ticks++){
|
||||
0 -> player.animator.animate(chop_a).also { player.lock() }
|
||||
1 -> player.animator.animate(chop_b)
|
||||
2 -> ObjectBuilder.replace(toChop, GameObject(chopped_bush, toChop.location, toChop.rotation),20)
|
||||
3 -> {player.walkingQueue.reset(); player.walkingQueue.addPath(toChop.location.x, toChop.location.y,true)}
|
||||
4 -> player.unlock().also { return true }
|
||||
on(ids,OBJECT,"chop-down"){player,node ->
|
||||
val toChop = node.asObject()
|
||||
if(checkRequirement(player)){
|
||||
GameWorld.Pulser.submit(object : Pulse(0){
|
||||
var ticks = 0
|
||||
override fun pulse(): Boolean {
|
||||
when(ticks++){
|
||||
0 -> player.animator.animate(chop_a).also { player.lock() }
|
||||
1 -> player.animator.animate(chop_b)
|
||||
2 -> ObjectBuilder.replace(toChop, GameObject(chopped_bush, toChop.location, toChop.rotation),20)
|
||||
3 -> {player.walkingQueue.reset(); player.walkingQueue.addPath(toChop.location.x, toChop.location.y,true)}
|
||||
4 -> player.unlock().also { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
})
|
||||
} else {
|
||||
player.sendMessage("You need a machete to get through this dense jungle.")
|
||||
})
|
||||
} else {
|
||||
player.sendMessage("You need a machete to get through this dense jungle.")
|
||||
}
|
||||
return@on true
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
fun checkRequirement(player: Player): Boolean{
|
||||
|
|
|
|||
|
|
@ -1,47 +1,43 @@
|
|||
package rs09.game.interaction.`object`
|
||||
|
||||
import core.cache.def.impl.ObjectDefinition
|
||||
import core.game.interaction.OptionHandler
|
||||
import core.game.node.Node
|
||||
import core.game.node.`object`.GameObject
|
||||
import core.game.node.`object`.ObjectBuilder
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.item.GroundItemManager
|
||||
import core.game.node.item.Item
|
||||
import core.game.world.update.flag.context.Animation
|
||||
import core.plugin.Initializable
|
||||
import core.plugin.Plugin
|
||||
import org.rs09.consts.Items
|
||||
import rs09.game.interaction.OptionListener
|
||||
|
||||
@Initializable
|
||||
/**
|
||||
* Handles the muddy chest
|
||||
* @author Ceikry
|
||||
*/
|
||||
class MuddyChestHandler : OptionHandler() {
|
||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
||||
ObjectDefinition.forId(170).handlers["option:open"] = this
|
||||
return this
|
||||
}
|
||||
class MuddyChestHandler : OptionListener() {
|
||||
|
||||
override fun handle(player: Player?, node: Node?, option: String?): Boolean {
|
||||
player ?: return false
|
||||
node ?: return false
|
||||
val key = Item(Items.MUDDY_KEY_991)
|
||||
if(player.inventory.containsItem(key)){
|
||||
player.inventory.remove(key)
|
||||
player.animator.animate(Animation(536))
|
||||
ObjectBuilder.replace(node.asObject(),GameObject(171, node.location, node.asObject().rotation),3)
|
||||
for(item in chestLoot){
|
||||
if(!player.inventory.add(item)) GroundItemManager.create(item,player)
|
||||
private val CHEST = 170
|
||||
|
||||
override fun defineListeners() {
|
||||
|
||||
on(CHEST,OBJECT,"open"){player,node ->
|
||||
val key = Item(Items.MUDDY_KEY_991)
|
||||
if(player.inventory.containsItem(key)){
|
||||
player.inventory.remove(key)
|
||||
player.animator.animate(Animation(536))
|
||||
ObjectBuilder.replace(node.asObject(),GameObject(171, node.location, node.asObject().rotation),3)
|
||||
for(item in chestLoot){
|
||||
if(!player.inventory.add(item)) GroundItemManager.create(item,player)
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("This chest is locked and needs some sort of key.")
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("This chest is locked and needs some sort of key.")
|
||||
return@on true
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
val chestLoot = arrayListOf(
|
||||
val chestLoot = arrayOf(
|
||||
Item(Items.UNCUT_RUBY_1619),
|
||||
Item(Items.MITHRIL_BAR_2359),
|
||||
Item(Items.MITHRIL_DAGGER_1209),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue