RuneHive-Game
Loading...
Searching...
No Matches
MagicOnNpcEvent.kt
Go to the documentation of this file.
1package org.jire.runehiveps.event.npc
2
3import com.runehive.content.skill.impl.hunter.net.impl.Butterfly
4import com.runehive.content.skill.impl.hunter.net.impl.Impling
5import com.runehive.game.world.entity.combat.magic.CombatSpell
6import com.runehive.game.world.entity.mob.npc.Npc
7import com.runehive.game.world.entity.mob.player.Player
8import com.runehive.net.packet.out.SendMessage
9
10/**
11 * @author Jire
12 */
13class MagicOnNpcEvent(
14 override val slot: Int,
15 val spell: Int
16) : NpcClickEvent {
17
18 override fun handleNpc(player: Player, npc: Npc) {
19 val definition = CombatSpell.get(spell) ?: return
20 if (player.spellbook != definition.spellbook) return
21
22 if (!npc.definition.isAttackable
23
24 && !Impling.forId(npc.id).isPresent
25 && !Butterfly.forId(npc.id).isPresent
26 ) {
27 player.send(SendMessage("This npc can not be attacked!"))
28 return
29 }
30
31 player.setSingleCast(definition)
32
33 if (!player.combat.attack(npc)) {
34 player.setSingleCast(null)
35 player.resetFace()
36 }
37 }
38
39}