mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-09 16:45:44 -07:00
Al Kharid warriors now help each other in combat
This commit is contained in:
parent
60e6049971
commit
ed47883bea
1 changed files with 25 additions and 36 deletions
|
|
@ -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<Any?> {
|
||||
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<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 {
|
||||
/**
|
||||
* The NPC ids of NPCs using this plugin.
|
||||
*/
|
||||
private val ID = intArrayOf(18)
|
||||
private val ID = intArrayOf(NPCs.AL_KHARID_WARRIOR_18)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue