Update game states & world management

This commit is contained in:
Laurin
2025-12-06 05:41:42 +01:00
parent 2c10e3e7fd
commit 590318772f
14 changed files with 1105 additions and 362 deletions

View File

@@ -1,13 +1,28 @@
package club.mcscrims.speedhg.game
import club.mcscrims.speedhg.SpeedHG
import club.mcscrims.speedhg.game.impl.BattleState
import club.mcscrims.speedhg.game.impl.FeastState
import club.mcscrims.speedhg.game.impl.ImmunityState
import club.mcscrims.speedhg.game.impl.PreStartState
import club.mcscrims.speedhg.game.impl.WaitingState
import org.bukkit.Location
import org.bukkit.entity.Player
import org.bukkit.util.BoundingBox
import java.util.concurrent.ConcurrentHashMap
class GameManager(
private val plugin: SpeedHG
) {
private var currentState: GameState? = null
private val gameStateTypes = ConcurrentHashMap<GameStateTypes, GameState>()
private val winners = ArrayList<Player>()
internal lateinit var feastLocation: Location
internal lateinit var feastBox: BoundingBox
internal var feastHeight: Int = 1
fun initialize()
{
@@ -24,12 +39,21 @@ class GameManager(
plugin.logger.severe("Error during onEnter for state ${currentState?.name}: ${e.message}")
e.printStackTrace()
}
gameStateTypes[ GameStateTypes.WAITING ] = currentState!!
gameStateTypes[ GameStateTypes.PRE_START ] = PreStartState( this, plugin, plugin.schedulerManager, plugin.pluginConfig.data.getDuration( "pre_start" ).seconds )
gameStateTypes[ GameStateTypes.IMMUNITY ] = ImmunityState( this, plugin, plugin.schedulerManager, plugin.pluginConfig.data.getDuration( "immunity" ).seconds )
gameStateTypes[ GameStateTypes.BATTLE ] = BattleState( this, plugin, plugin.schedulerManager, plugin.pluginConfig.data.getDuration( "battle" ).seconds )
gameStateTypes[ GameStateTypes.FEAST ] = FeastState( this, plugin, plugin.schedulerManager, plugin.pluginConfig.data.getDuration( "feast" ).seconds )
gameStateTypes[ GameStateTypes.DEATHMATCH ] = TODO()
gameStateTypes[ GameStateTypes.END ] = TODO()
}
fun transitionTo(
nextState: GameState
stateType: GameStateTypes
) {
val previousState = currentState
val nextState = gameStateTypes[ stateType ]!!
try {
currentState?.onExit( nextState )
@@ -38,6 +62,13 @@ class GameManager(
e.printStackTrace()
}
if ( nextState is FeastState )
{
feastLocation = nextState.feastLocation
feastBox = nextState.feastBox
feastHeight = nextState.feastHeight
}
currentState = nextState
try {
@@ -48,8 +79,33 @@ class GameManager(
}
}
fun addWinners(
vararg winners: Player
) {
winners.forEach { this.winners.add( it ) }
}
fun getCurrentState(): GameState? = currentState
fun getCurrentStateType(): GameStateTypes? = gameStateTypes.filter { it.value.name == currentState?.name }.keys.firstOrNull()
fun isRunning(): Boolean
{
return getCurrentStateType() == GameStateTypes.IMMUNITY ||
getCurrentStateType() == GameStateTypes.BATTLE ||
getCurrentStateType() == GameStateTypes.FEAST ||
getCurrentStateType() == GameStateTypes.DEATHMATCH
}
fun isBeforeFeast(): Boolean
{
return getCurrentStateType() == GameStateTypes.WAITING ||
getCurrentStateType() == GameStateTypes.PRE_START ||
getCurrentStateType() == GameStateTypes.IMMUNITY ||
(getCurrentStateType() == GameStateTypes.BATTLE &&
!( currentState as BattleState ).afterFeast )
}
fun shutdown()
{
currentState?.onExit( null )
@@ -57,3 +113,7 @@ class GameManager(
}
}
enum class GameStateTypes {
WAITING, PRE_START, IMMUNITY, BATTLE, FEAST, DEATHMATCH, END
}