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,38 +2,45 @@ 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
fun tick(){ fun tick() {
if(player.isArtificial) return if (player.isArtificial) return
if(GameWorld.ticks > nextSpawn) fireEvent() if (GameWorld.ticks > nextSpawn) fireEvent()
} }
fun fireEvent(){ fun fireEvent() {
if(player.zoneMonitor.isRestricted(ZoneRestriction.RANDOM_EVENTS)){ if (player.zoneMonitor.isRestricted(ZoneRestriction.RANDOM_EVENTS)) {
nextSpawn = GameWorld.ticks + 3000 nextSpawn = GameWorld.ticks + 3000
return return
} }
val ame = RandomEvents.values().random() val ame = RandomEvents.values().random()
event = ame.npc.create(player,ame.loot,ame.type) event = ame.npc.create(player,ame.loot,ame.type)
if(event!!.spawnLocation == null){ if (event!!.spawnLocation == null) {
nextSpawn = GameWorld.ticks + 3000 nextSpawn = GameWorld.ticks + 3000
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)
}
} }