mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2026-08-21 18:35:11 -06:00
Runner behavior
This commit is contained in:
parent
374d0ef8a5
commit
c316929e65
3 changed files with 76 additions and 55 deletions
|
|
@ -6,14 +6,12 @@ import core.game.node.item.Item
|
|||
import core.game.world.GameWorld
|
||||
|
||||
import core.game.world.map.Location
|
||||
class BAGroundSpawn(private var session: BarbassaultSession, private var respawnRate: Int, item: Item?, location: Location?,
|
||||
var flag: Boolean? = null,lureRange: Int = 4) : GroundItem(item, location) {
|
||||
class BAGroundSpawn(private var session: BarbassaultSession, private var respawnRate: Int, item: Item?, location: Location?, var flag: Boolean? = null, private var lureRange: Int = 4) : GroundItem(item, location) {
|
||||
|
||||
private var active = true
|
||||
private var autoSpawn = true
|
||||
|
||||
override fun toString(): String {
|
||||
return "SessionGroundSpawn [name=$name, respawnRate=$respawnRate, loc=$location, flag = $flag]"
|
||||
}
|
||||
override fun toString(): String = "SessionGroundSpawn [name=$name, respawnRate=$respawnRate, loc=$location, flag = $flag]"
|
||||
|
||||
fun init(): GroundItem {
|
||||
val thisGroundItem = GroundItemManager.create(this)
|
||||
|
|
@ -21,30 +19,21 @@ class BAGroundSpawn(private var session: BarbassaultSession, private var respawn
|
|||
return thisGroundItem
|
||||
}
|
||||
|
||||
override fun isActive(): Boolean {
|
||||
return active
|
||||
}
|
||||
override fun isActive(): Boolean = active
|
||||
override fun setActive(value: Boolean) { active = value }
|
||||
|
||||
override fun setActive(value: Boolean) {
|
||||
active = value
|
||||
}
|
||||
override fun isPrivate(): Boolean = false
|
||||
|
||||
override fun isPrivate(): Boolean {
|
||||
return false
|
||||
}
|
||||
override fun isAutoSpawn(): Boolean = autoSpawn
|
||||
fun setAutoSpawn(value: Boolean) { autoSpawn = value }
|
||||
fun setRespawnRate(rate: Int) { respawnRate = rate }
|
||||
|
||||
override fun isAutoSpawn(): Boolean {
|
||||
return autoSpawn
|
||||
}
|
||||
|
||||
fun setAutoSpawn(value: Boolean) {
|
||||
autoSpawn = value
|
||||
}
|
||||
fun getLureRange():Int = lureRange
|
||||
fun addLureRange(addRange: Int) { lureRange += addRange }
|
||||
|
||||
override fun respawn() {
|
||||
if (!autoSpawn || respawnRate < 0) {
|
||||
return
|
||||
}
|
||||
if (!autoSpawn || respawnRate < 0)
|
||||
|
||||
GameWorld.Pulser.submit(object : Pulse(respawnRate) {
|
||||
override fun pulse(): Boolean {
|
||||
GroundItemManager.create(this@BAGroundSpawn)
|
||||
|
|
@ -53,9 +42,4 @@ class BAGroundSpawn(private var session: BarbassaultSession, private var respawn
|
|||
})
|
||||
}
|
||||
|
||||
fun setRespawnRate(rate: Int) {
|
||||
respawnRate = rate
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -251,18 +251,14 @@ class BarbassaultSession( val activity: BAActivity ? = null) :LogoutListener, M
|
|||
}
|
||||
|
||||
fun findClosestLure(target: Location): BAGroundSpawn? {
|
||||
fun distance(a: Location, b: Location): Int =Math.abs(a.x - b.x) + Math.abs(a.y - b.y)
|
||||
return BAgroundItems
|
||||
.asSequence()
|
||||
.filter { it.id in LureItems }
|
||||
.minByOrNull { node ->
|
||||
val dx = node.location.x - target.x
|
||||
val dy = node.location.y - target.y
|
||||
Math.abs(dx) + Math.abs(dy)
|
||||
}
|
||||
.map { it to distance(it.location, target) }
|
||||
.filter { (node, dist) -> node.id in LureItems && dist <= node.getLureRange() }
|
||||
.minByOrNull { (_, dist) -> dist }?.first
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun forfeit(){ state = BarbassaultState.FORFEIT }
|
||||
fun isInBarbAssaultGame() = state == BarbassaultState.IN_ARENA
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ import content.minigame.barbassault.arena.*
|
|||
import content.minigame.barbassault.getBASession
|
||||
|
||||
import core.api.forceWalk
|
||||
import core.api.removeGroundItem
|
||||
import core.api.sendChat
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.world.map.RegionManager
|
||||
|
||||
|
||||
val PENANCE_RUNNER_IDS = listOf(
|
||||
|
|
@ -32,6 +32,9 @@ class PenanceRunnerNPC : NPCBehavior(*PENANCE_RUNNER_IDS.toIntArray()) {
|
|||
val BAD_EAT = "Blurghh"
|
||||
val TRAP_HIT = "Urghhh!"
|
||||
val ESCAPE = "Raaa!!"
|
||||
var actionState = ACTION_STATE.SEEK_FOOD
|
||||
|
||||
enum class ACTION_STATE { SEEK_FOOD, SEEK_PLAYER, STALLED, SEEK_ESCAPE, EATING, THINKING }
|
||||
|
||||
override fun getXpMultiplier(self: NPC, attacker: Entity): Double {
|
||||
return 0.0
|
||||
|
|
@ -44,28 +47,66 @@ class PenanceRunnerNPC : NPCBehavior(*PENANCE_RUNNER_IDS.toIntArray()) {
|
|||
self.setAttribute("barbass-role", BarbRole.DEFENDER)
|
||||
|
||||
}
|
||||
|
||||
var stateTicks = 0
|
||||
override fun tick(self: NPC): Boolean {
|
||||
val session = self.getAttribute<BarbassaultSession>(BA_SESSION_KEY)
|
||||
if (session == null) return false
|
||||
seekFood(self,session)
|
||||
val session = self.getAttribute<BarbassaultSession>(BA_SESSION_KEY) ?: return false
|
||||
|
||||
stateTicks++
|
||||
|
||||
if (stateTicks >= 6) {
|
||||
stateTicks = 0
|
||||
pickNewState()
|
||||
}
|
||||
|
||||
when (actionState) {
|
||||
ACTION_STATE.SEEK_FOOD -> seekFood(self, session)
|
||||
ACTION_STATE.SEEK_PLAYER -> seekPlayers(self, session)
|
||||
ACTION_STATE.SEEK_ESCAPE -> escape(self, session)
|
||||
ACTION_STATE.STALLED -> stalled(self)
|
||||
ACTION_STATE.EATING -> eating(self)
|
||||
ACTION_STATE.THINKING -> self.resetWalk()
|
||||
}
|
||||
|
||||
self.shouldPreventStacking(self)
|
||||
return true
|
||||
}
|
||||
|
||||
fun seekFood(self:NPC,session: BarbassaultSession) {
|
||||
val groundItem = session.findClosestLure(self.location)
|
||||
if (groundItem != null) {
|
||||
forceWalk(self,groundItem.location ,"DUMB")
|
||||
if (self.location == groundItem.location) {
|
||||
sendChat(self,if (groundItem.flag == true) GOOD_EAT else BAD_EAT)
|
||||
session.destroyGroundItem(groundItem)
|
||||
self.resetWalk()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
fun nosyTowardPlayers(self: NPC,session: BarbassaultSession) {
|
||||
fun seekFood(self: NPC, session: BarbassaultSession) {
|
||||
val groundItem = session.findClosestLure(self.location) ?: return
|
||||
val target = groundItem.location
|
||||
val occupied = RegionManager.getLocalEntitys(target, 0).any { it != self && it.location == target }
|
||||
|
||||
if (occupied) {
|
||||
val adjacent = target.getCardinalTiles().firstOrNull { it.isNextTo(self) }
|
||||
if (adjacent != null) { forceWalk(self, adjacent, "DUMB") }
|
||||
|
||||
self.resetWalk()
|
||||
self.faceLocation(target)
|
||||
return
|
||||
}
|
||||
|
||||
forceWalk(self, target, "DUMB")
|
||||
|
||||
if (self.location == target) {
|
||||
sendChat(self, if (groundItem.flag == true) GOOD_EAT else BAD_EAT)
|
||||
session.destroyGroundItem(groundItem)
|
||||
self.resetWalk()
|
||||
}
|
||||
}
|
||||
fun pickNewState() {
|
||||
actionState = when ((0..2).random()) {
|
||||
0 -> ACTION_STATE.SEEK_FOOD
|
||||
1 -> ACTION_STATE.SEEK_PLAYER
|
||||
else -> ACTION_STATE.SEEK_ESCAPE
|
||||
}
|
||||
}
|
||||
private fun escape(self: NPC, session1: BarbassaultSession) { }
|
||||
private fun stalled(self: NPC) { }
|
||||
private fun eating(self:NPC){ }
|
||||
|
||||
|
||||
fun seekPlayers(self: NPC,session: BarbassaultSession) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue