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