RuneHive-Game
Loading...
Searching...
No Matches
ItemOnObjectEvent.kt
Go to the documentation of this file.
1package org.jire.runehiveps.event.`object`
2
3import com.runehive.content.event.EventDispatcher
4import com.runehive.content.event.impl.ItemOnObjectInteractionEvent
5import com.runehive.game.event.impl.ItemOnObjectEvent
6import com.runehive.game.plugin.PluginManager
7import com.runehive.game.world.InterfaceConstants
8import com.runehive.game.world.World
9import com.runehive.game.world.entity.mob.player.Player
10import com.runehive.game.world.position.Position
11import com.runehive.net.packet.out.SendMessage
12
13/**
14 * @author Jire
15 */
16class ItemOnObjectEvent(
17 val interfaceType: Int,
18 val itemId: Int,
19 val slot: Int,
20 val objectId: Int,
21 val x: Int, val y: Int
22) : ObjectEvent {
23
24 override fun handle(player: Player) {
25 val used = player.inventory[slot] ?: return
26 if (!used.matchesId(itemId)) return
27
28 val position = Position(x, y, player.height)
29
30 var id = objectId
31
32 for (playerBirdHouseData in player.birdHouseData) {
33 if (playerBirdHouseData.birdhousePosition == position) {
34 id = playerBirdHouseData.oldObjectId
35 break
36 }
37 }
38
39 val region = World.getRegions().getRegion(position)
40 val obj = region.getGameObject(id, position) ?: return
41
42 player.walkTo(obj) {
43 if (interfaceType == InterfaceConstants.INVENTORY_INTERFACE) {
44 player.face(obj)
45 if (EventDispatcher.execute(player, ItemOnObjectInteractionEvent(used, obj))) return@walkTo
46 if (!PluginManager.getDataBus().publish(player, ItemOnObjectEvent(used, slot, obj))) {
47 player.send(SendMessage("Nothing interesting happens."))
48 }
49 }
50 }
51 }
52
53}