RuneHive-Game
Loading...
Searching...
No Matches
NpcOptionEvent.kt
Go to the documentation of this file.
1package org.jire.runehiveps.event.npc
2
3import com.runehive.content.event.EventDispatcher
4import com.runehive.content.event.InteractionEvent
5import com.runehive.game.action.impl.NpcFaceAction
6import com.runehive.game.event.Event
7import com.runehive.game.event.impl.NpcClickEvent
8import com.runehive.game.plugin.PluginManager
9import com.runehive.game.world.entity.mob.npc.Npc
10import com.runehive.game.world.entity.mob.player.Player
11
12/**
13 * @author Jire
14 */
15open class NpcOptionEvent(
16 override val slot: Int,
17 val option: Int
18) : org.jire.runehiveps.event.npc.NpcClickEvent {
19
20 override fun handleNpc(player: Player, npc: Npc) {
21 player.walkTo(npc) {
22 npc.action.execute(createAction(player, npc), true)
23 val interactionEvent = createInteractionEvent(npc)
24 if (interactionEvent == null
25 || !EventDispatcher.execute(player, interactionEvent)
26 ) {
27 publishToPluginManager(player, npc)
28 }
29 }
30 }
31
32 open fun createAction(player: Player, npc: Npc) = NpcFaceAction(npc, player.position, option)
33
34 open fun createInteractionEvent(npc: Npc): InteractionEvent? = null
35
36 fun publishToPluginManager(player: Player, npc: Npc) =
37 PluginManager.getDataBus().publish(player, createEvent(npc))
38
39 open fun createEvent(npc: Npc): Event = NpcClickEvent(option + 1, npc)
40
41}