Fixed shooting star resetting on server shutdown

This commit is contained in:
Player Name
2025-02-13 11:30:02 +00:00
committed by Ryan
parent 62a7dd4324
commit 618d39d73c
5 changed files with 64 additions and 35 deletions
@@ -11,12 +11,13 @@ import core.ServerStore.Companion.getString
import content.global.bots.ShootingStarBot
import core.game.world.repository.Repository
import core.tools.RandomFunction
/**
* Represents a shooting star object (Only ever initialized once) (ideally)
* @author Ceikry
*/
class ShootingStar(var level: ShootingStarType = ShootingStarType.values().random()){
class ShootingStar(var level: ShootingStarType = ShootingStarType.values().random()) {
val crash_locations = mapOf(
"East of Dark Wizards' Tower" to Location.create(2925, 3339, 0), // East of Dark Wizards' Tower
"Crafting Guild" to Location.create(2940, 3280, 0), // Crafting Guild Mine
@@ -79,22 +80,15 @@ class ShootingStar(var level: ShootingStarType = ShootingStarType.values().rando
* Degrades a ShootingStar (or removes the starObject and spawns a Star Sprite if it's the last star)
*/
fun degrade() {
if(level.ordinal == 0){
selfBots.filter { it.isMining() }.forEach { it.sleep() }
SceneryBuilder.remove(starObject)
isSpawned = false
starSprite.location = starObject.location
starSprite.init()
spriteSpawned = true
ShootingStarPlugin.getStoreFile().clear()
if(level.ordinal == 0) {
spawnSprite()
return
}
level = getNextType()
maxDust = level.totalStardust
dustLeft = level.totalStardust
ShootingStarPlugin.getStoreFile()["level"] = level.ordinal
ShootingStarPlugin.getStoreFile()["isDiscovered"] = isDiscovered
ShootingStarPlugin.getStoreFile()["dustLeft"] = dustLeft
val newStar = Scenery(level.objectId, starObject.location)
SceneryBuilder.replace(starObject, newStar)
@@ -110,7 +104,6 @@ class ShootingStar(var level: ShootingStarType = ShootingStarType.values().rando
*/
fun fire() {
SceneryBuilder.remove(starObject)
rebuildVars()
clearSprite()
SceneryBuilder.add(starObject)
if(!isSpawned) {
@@ -123,37 +116,54 @@ class ShootingStar(var level: ShootingStarType = ShootingStarType.values().rando
}
isSpawned = true
Repository.sendNews("A shooting star level ${level.ordinal + 1} just crashed near ${location}!")
ShootingStarPlugin.getStoreFile()["level"] = level.ordinal
ShootingStarPlugin.getStoreFile()["location"] = location
ShootingStarPlugin.getStoreFile()["isDiscovered"] = isDiscovered
ShootingStarPlugin.getStoreFile()["dustLeft"] = dustLeft
}
/**
* Rebuilds some of the variables with new information.
*/
fun rebuildVars(){
if(firstStar && ShootingStarPlugin.getStoreFile().isNotEmpty()){
level = ShootingStarType.values()[ShootingStarPlugin.getStoreFile().getInt("level")]
location = ShootingStarPlugin.getStoreFile().getString("location")
isDiscovered = ShootingStarPlugin.getStoreFile().getBoolean("isDiscovered")
} else {
level = ShootingStarType.values().random()
location = crash_locations.entries.random().key
isDiscovered = false
// Defaults
var levelOrd = RandomFunction.random(9)
level = ShootingStarType.values()[levelOrd]
location = crash_locations.entries.random().key
isDiscovered = false
dustLeft = level.totalStardust
ticks = 0
spriteSpawned = false
if (firstStar && ShootingStarPlugin.getStoreFile().isNotEmpty()) {
// Replace default with stored values, if any
levelOrd = ShootingStarPlugin.getStoreFile().getInt("level", levelOrd)
level = ShootingStarType.values()[levelOrd]
location = ShootingStarPlugin.getStoreFile().getString("location", location)
isDiscovered = ShootingStarPlugin.getStoreFile().getBoolean("isDiscovered", false)
dustLeft = ShootingStarPlugin.getStoreFile().getInt("dustLeft", dustLeft)
ticks = ShootingStarPlugin.getStoreFile().getInt("ticks", ticks)
spriteSpawned = ShootingStarPlugin.getStoreFile().getBoolean("spriteSpawned", false)
}
maxDust = level.totalStardust
dustLeft = level.totalStardust
starObject = Scenery(level.objectId, crash_locations.get(location))
}
ShootingStarPlugin.getStoreFile()["level"] = level.ordinal
ShootingStarPlugin.getStoreFile()["location"] = location
ShootingStarPlugin.getStoreFile()["isDiscovered"] = false
ticks = 0
firstStar = false
fun spawnSprite() {
selfBots.filter { it.isMining() }.forEach { it.sleep() }
SceneryBuilder.remove(starObject)
isSpawned = false
starSprite.location = starObject.location
starSprite.init()
spriteSpawned = true
ShootingStarPlugin.getStoreFile()["spriteSpawned"] = spriteSpawned
}
fun clearSprite() {
starSprite.clear()
spriteSpawned = false
ShootingStarPlugin.getStoreFile()["spriteSpawned"] = spriteSpawned
}
/**
@@ -161,6 +171,7 @@ class ShootingStar(var level: ShootingStarType = ShootingStarType.values().rando
*/
fun decDust() {
if(--dustLeft <= 0) degrade()
ShootingStarPlugin.getStoreFile()["dustLeft"] = dustLeft
}
/**
@@ -51,6 +51,7 @@ class ShootingStarMiningPulse(player: Player?, node: Scenery?, val star: Shootin
player.sendMessage("You have ${player.skills.experienceMultiplier * player.getAttribute("shooting-star:bonus-xp", 0).toDouble()} bonus xp towards mining stardust.")
ShootingStarPlugin.submitScoreBoard(player)
star.isDiscovered = true
ShootingStarPlugin.getStoreFile()["isDiscovered"] = star.isDiscovered
return player.skills.getLevel(Skills.MINING) >= star.miningLevel
}
@@ -27,14 +27,30 @@ class ShootingStarPlugin : LoginListener, InteractionListener, TickListener, Com
override fun tick() {
++star.ticks
// Check if the current star sprite should expire
val maxDelay = tickDelay + (tickDelay / 3)
if(star.ticks > maxDelay && star.spriteSpawned){
star.clearSprite()
}
if ((star.ticks >= tickDelay && !star.spriteSpawned) || (!star.isSpawned && !star.spriteSpawned)) {
if (star.firstStar && !star.isSpawned && !star.spriteSpawned) {
// Apparently, the server has only just booted
star.rebuildVars()
if (star.spriteSpawned) {
star.spawnSprite()
} else {
star.fire()
}
star.firstStar = false
}
// Check if it's time to fire a new one
if (star.ticks >= tickDelay && !star.spriteSpawned) {
star.rebuildVars()
star.fire()
}
getStoreFile()["ticks"] = star.ticks
}
override fun defineListeners() {
@@ -122,6 +138,7 @@ class ShootingStarPlugin : LoginListener, InteractionListener, TickListener, Com
}
define("submit", Privilege.ADMIN) { _, _ ->
star.rebuildVars()
star.fire()
}
@@ -267,7 +267,7 @@ public final class ChaosTunnelZone extends MapZone implements Plugin<Object> {
* @param player The player.
*/
private void commenceBorkBattle(Player player) {
if (ServerStore.getBoolean(getStoreFile(), player.getUsername().toLowerCase()) && GameWorld.getSettings().isHosted()) {
if (ServerStore.getBoolean(getStoreFile(), player.getUsername().toLowerCase(), false) && GameWorld.getSettings().isHosted()) {
player.getPacketDispatch().sendMessage("The portal's magic is too weak to teleport you right now.");
return;
}
+6 -6
View File
@@ -113,18 +113,18 @@ class ServerStore : PersistWorld {
}
@JvmStatic
fun JSONObject.getString(key: String): String {
return this[key] as? String ?: "nothing"
fun JSONObject.getString(key: String, default: String = "nothing"): String {
return this[key] as? String ?: default
}
@JvmStatic
fun JSONObject.getLong(key: String): Long {
return this[key] as? Long ?: 0L
fun JSONObject.getLong(key: String, default: Long = 0L): Long {
return this[key] as? Long ?: default
}
@JvmStatic
fun JSONObject.getBoolean(key: String): Boolean {
return this[key] as? Boolean ?: false
fun JSONObject.getBoolean(key: String, default: Boolean = false): Boolean {
return this[key] as? Boolean ?: default
}
fun List<Int>.toJSONArray(): JSONArray{