Al Kharid warriors now help each other in combat

This commit is contained in:
GregF 2024-03-17 07:58:17 +00:00 committed by Ryan
parent 60e6049971
commit ed47883bea

View file

@ -1,16 +1,14 @@
package content.region.desert.alkharid.handlers 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.Node
import core.game.node.entity.Entity 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.npc.AbstractNPC
import core.game.node.entity.player.Player import core.game.node.entity.player.Player
import core.game.world.map.Location import core.game.world.map.Location
import core.game.world.map.RegionManager import core.game.world.map.RegionManager
import core.plugin.Initializable import core.plugin.Initializable
import core.plugin.Plugin import org.rs09.consts.NPCs
import core.plugin.ClassScanner
/** /**
* Handles the Al-Kharid Warrior * Handles the Al-Kharid Warrior
@ -19,6 +17,7 @@ import core.plugin.ClassScanner
@Initializable @Initializable
class AlKharidWarriorNPC : AbstractNPC { class AlKharidWarriorNPC : AbstractNPC {
var target: Player? = null var target: Player? = null
private val supportRange: Int = 5
//Constructor spaghetti because Arios I guess //Constructor spaghetti because Arios I guess
constructor() : super(18, null, true) {} constructor() : super(18, null, true) {}
@ -27,11 +26,6 @@ class AlKharidWarriorNPC : AbstractNPC {
return AlKharidWarriorNPC(id, location) return AlKharidWarriorNPC(id, location)
} }
override fun newInstance(arg: Any?): Plugin<Any?> {
ClassScanner.definePlugin(WarriorOptionPlugin())
return super.newInstance(arg)
}
//Maintains target combat (resolves issue where they would just give up/walk away) //Maintains target combat (resolves issue where they would just give up/walk away)
override fun tick() { override fun tick() {
if(target != null && !inCombat() && skills.lifepoints > 0){ if(target != null && !inCombat() && skills.lifepoints > 0){
@ -42,43 +36,38 @@ class AlKharidWarriorNPC : AbstractNPC {
//Clear target on death //Clear target on death
override fun finalizeDeath(killer: Entity?) { override fun finalizeDeath(killer: Entity?) {
super.finalizeDeath(killer)
target = null 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 { override fun getIds(): IntArray {
return ID return ID
} }
inner class WarriorOptionPlugin : OptionHandler() {
override fun newInstance(arg: Any?): Plugin<Any?> {
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 { companion object {
/** /**
* The NPC ids of NPCs using this plugin. * The NPC ids of NPCs using this plugin.
*/ */
private val ID = intArrayOf(18) private val ID = intArrayOf(NPCs.AL_KHARID_WARRIOR_18)
} }
} }