Random Events should now spawn correctly

Fixed an issue that was causing tick event hooks to not fire
This commit is contained in:
Ceikry
2022-05-16 12:22:29 +00:00
committed by Ryan
parent 8835799230
commit 07065c7e79
8 changed files with 67 additions and 9 deletions
+1 -1
View File
@@ -13,4 +13,4 @@ data class InteractionEvent(val target: Node, val option: String) : Event
data class ButtonClickedEvent(val iface: Int, val buttonId: Int) : Event
data class UsedWithEvent(val used: Int, val with: Int) : Event
data class SelfDeath(val killer: Entity) : Event
data class TickEvent(val source: Entity) : Event
data class TickEvent(val worldTicks: Int) : Event
@@ -14,9 +14,6 @@ import rs09.game.system.SystemLogger
import rs09.game.world.GameWorld
import kotlin.random.Random
private const val AVG_DELAY_TICKS = 6000 // 60 minutes
private const val MIN_DELAY_TICKS = AVG_DELAY_TICKS / 2
private const val MAX_DELAY_TICKS = MIN_DELAY_TICKS + AVG_DELAY_TICKS // window of 60 min centered on 60 min (30 to 90 min)
class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<TickEvent> {
var event: RandomEventNPC? = null
var enabled: Boolean = false
@@ -47,7 +44,7 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<
return
}
if (getAttribute<RandomEventNPC?>(player, "re-npc", null) != null) return
val currentAction = player.pulseManager.current.toString()
val currentAction = player.pulseManager.current?.toString() ?: "None"
val ame: RandomEvents = if(currentAction.contains("WoodcuttingSkillPulse") && Random.nextBoolean()){
RandomEvents.TREE_SPIRIT
} else if(currentAction.contains("FishingPulse") && Random.nextBoolean()){
@@ -62,6 +59,7 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<
event = ame.npc.create(player,ame.loot,ame.type)
if (event!!.spawnLocation == null) {
nextSpawn = GameWorld.ticks + 3000
SystemLogger.logWarn("Tried to spawn random event for ${player.username} but spawn location was null!")
return
}
event!!.init()
@@ -74,6 +72,10 @@ class RandomEventManager(val player: Player? = null) : LoginListener, EventHook<
}
companion object {
const val AVG_DELAY_TICKS = 6000 // 60 minutes
const val MIN_DELAY_TICKS = AVG_DELAY_TICKS / 2
const val MAX_DELAY_TICKS = MIN_DELAY_TICKS + AVG_DELAY_TICKS // window of 60 min centered on 60 min (30 to 90 min)
@JvmStatic fun getInstance(player: Player): RandomEventManager?
{
return getAttribute(player, "random-manager", null)
@@ -9,6 +9,7 @@ import core.tools.RandomFunction
import org.rs09.consts.Items
import rs09.game.content.ame.RandomEventNPC
import rs09.game.content.global.WeightBasedTable
import java.lang.Integer.max
val ids = 2463..2468
@@ -18,7 +19,7 @@ class EvilChickenNPC(override var loot: WeightBasedTable? = null) : RandomEventN
override fun init() {
super.init()
val index = (player.properties.combatLevel / 20) - 1
val index = max(0, (player.properties.combatLevel / 20) - 1)
val id = ids.toList()[index]
this.transform(id)
this.attack(player)
@@ -38,7 +38,7 @@ class UpdateSequence
playersList = renderablePlayers
npcList = Repository.renderableNpcs
lobbyList!!.map{ PacketRepository.send(ClearMinimapFlag::class.java, PlayerContext(it)) }
playersList!!.forEach(Player::tick)
renderablePlayers.forEach(Player::tick)
npcList!!.forEach(NPC::tick)
}