From ed47883bea94c860c521d46911b3c58ee6f3df97 Mon Sep 17 00:00:00 2001 From: GregF Date: Sun, 17 Mar 2024 07:58:17 +0000 Subject: [PATCH] Al Kharid warriors now help each other in combat --- .../alkharid/handlers/AlKharidWarriorNPC.kt | 61 ++++++++----------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/Server/src/main/content/region/desert/alkharid/handlers/AlKharidWarriorNPC.kt b/Server/src/main/content/region/desert/alkharid/handlers/AlKharidWarriorNPC.kt index 7f6cc4b4d..ba1b4662d 100644 --- a/Server/src/main/content/region/desert/alkharid/handlers/AlKharidWarriorNPC.kt +++ b/Server/src/main/content/region/desert/alkharid/handlers/AlKharidWarriorNPC.kt @@ -1,16 +1,14 @@ package content.region.desert.alkharid.handlers -import core.cache.def.impl.NPCDefinition -import core.game.interaction.OptionHandler import core.game.node.Node import core.game.node.entity.Entity +import core.game.node.entity.combat.BattleState import core.game.node.entity.npc.AbstractNPC import core.game.node.entity.player.Player import core.game.world.map.Location import core.game.world.map.RegionManager import core.plugin.Initializable -import core.plugin.Plugin -import core.plugin.ClassScanner +import org.rs09.consts.NPCs /** * Handles the Al-Kharid Warrior @@ -19,6 +17,7 @@ import core.plugin.ClassScanner @Initializable class AlKharidWarriorNPC : AbstractNPC { var target: Player? = null + private val supportRange: Int = 5 //Constructor spaghetti because Arios I guess constructor() : super(18, null, true) {} @@ -27,11 +26,6 @@ class AlKharidWarriorNPC : AbstractNPC { return AlKharidWarriorNPC(id, location) } - override fun newInstance(arg: Any?): Plugin { - ClassScanner.definePlugin(WarriorOptionPlugin()) - return super.newInstance(arg) - } - //Maintains target combat (resolves issue where they would just give up/walk away) override fun tick() { if(target != null && !inCombat() && skills.lifepoints > 0){ @@ -42,43 +36,38 @@ class AlKharidWarriorNPC : AbstractNPC { //Clear target on death override fun finalizeDeath(killer: Entity?) { - super.finalizeDeath(killer) target = null + super.finalizeDeath(killer) + } + + override fun attack(node: Node?) { + if (node is Player) target = node + super.attack(node) + } + + override fun onImpact(entity: Entity?, state: BattleState?) { + if (entity is Player) { + if (target == null) { + target = entity + RegionManager.getLocalNpcs(entity, supportRange).forEach { + if (it.id == NPCs.AL_KHARID_WARRIOR_18 && !it.properties.combatPulse.isAttacking && it != this) { + it.sendChat("Brother, I shall help thee with this infidel!") + it.attack(entity) + } + } + } + } + super.onImpact(entity, state) } override fun getIds(): IntArray { return ID } - inner class WarriorOptionPlugin : OptionHandler() { - override fun newInstance(arg: Any?): Plugin { - for (id in ID) { - NPCDefinition.forId(id).handlers["option:attack"] = this - } - return this - } - - override fun handle(player: Player, node: Node, option: String): Boolean { - RegionManager.getLocalNpcs(player,6).forEach{ - if(it.id == 18 && it != node.asNpc() && !it.properties.combatPulse.isAttacking){ - it.sendChat("Brother, I shall help thee with this infidel!") - (it as AlKharidWarriorNPC).target = player - it.attack(player) - } - } - player.attack(node.asNpc()) - return true - } - - override fun isWalk(): Boolean { - return false - } - } - companion object { /** * The NPC ids of NPCs using this plugin. */ - private val ID = intArrayOf(18) + private val ID = intArrayOf(NPCs.AL_KHARID_WARRIOR_18) } } \ No newline at end of file