random events are now unpredictably timed

This commit is contained in:
Ryan
2022-01-23 11:16:22 +00:00
parent f038acfe33
commit b0b6a5fdd1
@@ -2,10 +2,13 @@ package rs09.game.content.ame
import core.game.node.entity.player.Player import core.game.node.entity.player.Player
import core.game.world.map.zone.ZoneRestriction import core.game.world.map.zone.ZoneRestriction
import core.tools.RandomFunction
import rs09.game.system.SystemLogger import rs09.game.system.SystemLogger
import rs09.game.world.GameWorld import rs09.game.world.GameWorld
private const val DELAY_TICKS = 6000 //60 minutes 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) { class RandomEventManager(val player: Player) {
var event: RandomEventNPC? = null var event: RandomEventNPC? = null
var nextSpawn = 0 var nextSpawn = 0
@@ -27,13 +30,17 @@ class RandomEventManager(val player: Player) {
return return
} }
event!!.init() event!!.init()
nextSpawn = GameWorld.ticks + DELAY_TICKS rollNextSpawn()
SystemLogger.logRE("Fired ${event!!.name} for ${player.username}") SystemLogger.logRE("Fired ${event!!.name} for ${player.username}")
} }
fun init() { fun init() {
if (player.isArtificial) return if (player.isArtificial) return
nextSpawn = GameWorld.ticks + DELAY_TICKS rollNextSpawn()
SystemLogger.logRE("Initialized REManager for ${player.username}") SystemLogger.logRE("Initialized REManager for ${player.username}")
} }
private fun rollNextSpawn() {
nextSpawn = GameWorld.ticks + RandomFunction.random(MIN_DELAY_TICKS, MAX_DELAY_TICKS)
}
} }