RuneHive-Game
Loading...
Searching...
No Matches
ObjectOptionEvent.kt
Go to the documentation of this file.
1package org.jire.runehiveps.event.`object`
2
3import com.runehive.content.combat.cannon.CannonManager
4import com.runehive.content.event.EventDispatcher
5import com.runehive.content.event.impl.ObjectInteractionEvent
6import com.runehive.game.event.impl.ObjectClickEvent
7import com.runehive.game.plugin.PluginManager
8import com.runehive.game.world.World
9import com.runehive.game.world.entity.mob.data.PacketType
10import com.runehive.game.world.entity.mob.player.Player
11import com.runehive.game.world.`object`.GameObject
12import com.runehive.game.world.`object`.GameObjectDefinition
13import com.runehive.game.world.position.Position
14import org.jire.runehiveps.WorldTask
15import java.util.*
16
17/**
18 * @author Jire
19 */
20class ObjectOptionEvent(
21 val option: Int,
22 val id: Int,
23 val x: Int, val y: Int,
24 val createInteractionEvent: (GameObject) -> ObjectInteractionEvent?,
25) : ObjectEvent {
26
27 override fun canHandle(player: Player) = super.canHandle(player)
28 && !player.locking.locked(PacketType.CLICK_OBJECT)
29
30 override fun handle(player: Player) {
31 GameObjectDefinition.forId(id) ?: return
32
33 val position = Position(x, y, player.height)
34
35 var objectId = id
36 for (playerBirdHouseData in player.birdHouseData) {
37 if (playerBirdHouseData.birdhousePosition == position) {
38 objectId = playerBirdHouseData.oldObjectId
39 break
40 }
41 }
42
43 /* Dialogues */
44 if (player.dialogue.isPresent) {
45 player.dialogue = Optional.empty()
46 }
47
48 /* Dialogue factory */
49 if (!player.dialogueFactory.chain.isEmpty()) {
50 player.dialogueFactory.clear()
51 }
52
53 /* Dialogue options */
54 if (player.optionDialogue.isPresent) {
55 player.optionDialogue = Optional.empty()
56 }
57
58 if (!player.interfaceManager.isMainClear) {
59 player.interfaceManager.close()
60 }
61
62 if (!player.interfaceManager.isDialogueClear) {
63 player.dialogueFactory.clear()
64 }
65
66 val region = World.getRegions().getRegion(position)
67
68 when (objectId) {
69 6 -> {
70 when(option) {
71 1 -> CannonManager.load(player)
72 2 -> CannonManager.pickup(player)
73 3 -> CannonManager.empty(player)
74 }
75
76 };
77 }
78
79 val obj = region.getGameObject(objectId, position) ?: region.getCustomObject(objectId, position) ?: return
80 handleObj(player, obj)
81 }
82
83 private fun handleObj(player: Player, obj: GameObject) = player.walkTo(obj) {
84 player.movement.reset()
85 player.locking.lock(1)
86 player.face(obj)
87
89 player.face(obj)
90 if (!EventDispatcher.execute(player, createInteractionEvent(obj))) {
91 PluginManager.getDataBus().publish(player, ObjectClickEvent(option, obj))
92 }
93 }
94 }
95
96}
inline fun schedule(delay:Int=1, crossinline execute:() -> Unit)
Definition WorldTask.kt:11