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