forked from SteamWar/SteamWar
Migrate FightSystem modes and countdowns to GameCore
- Move shared arena-mode abstractions into GameCore - Adapt fight countdowns and APIs to the shared model - Add SteamWar issue audit workflow and SQL language settings
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
|
||||
package de.steamwar.towerrun.config;
|
||||
|
||||
import de.steamwar.gamecore.ArenaMode;
|
||||
import de.steamwar.gamecore.config.GameRuntimeProperties;
|
||||
import de.steamwar.sql.Event;
|
||||
import de.steamwar.sql.EventFight;
|
||||
import de.steamwar.towerrun.TowerRun;
|
||||
@@ -35,6 +37,9 @@ import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
public class Config {
|
||||
public static final GameRuntimeProperties RUNTIME_PROPERTIES = GameRuntimeProperties.load();
|
||||
public static final ArenaMode MODE = ArenaMode.from(RUNTIME_PROPERTIES);
|
||||
|
||||
public static final int MIN_PLAYERS;
|
||||
public static final int LOBBY_TIMER;
|
||||
public static final Set<Material> DESTROYABLE_BLOCKS;
|
||||
@@ -64,7 +69,7 @@ public class Config {
|
||||
GAME_ESCAPE_TIMER = config.getInt("gameEscapeTimer", 60);
|
||||
DESTROYABLE_BLOCKS = EnumSet.copyOf(config.getStringList("destroyable").stream().map(Material::valueOf).collect(Collectors.toSet()));
|
||||
|
||||
EVENT_KAMPF_ID = Integer.parseInt(System.getProperty("fightID", "0"));
|
||||
EVENT_KAMPF_ID = RUNTIME_PROPERTIES.getFightId();
|
||||
|
||||
if (event()) {
|
||||
EVENT_FIGHT = EventFight.byId(EVENT_KAMPF_ID);
|
||||
@@ -89,10 +94,10 @@ public class Config {
|
||||
}
|
||||
|
||||
public static boolean test() {
|
||||
return EVENT_KAMPF_ID == -1;
|
||||
return MODE == ArenaMode.TEST;
|
||||
}
|
||||
|
||||
public static boolean event() {
|
||||
return EVENT_KAMPF_ID > 0;
|
||||
return MODE == ArenaMode.EVENT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,18 +23,14 @@ import de.steamwar.towerrun.TowerRun;
|
||||
import de.steamwar.towerrun.state.GameStateToggleListener;
|
||||
import de.steamwar.towerrun.state.GameStates;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public abstract class Countdown extends GameStateToggleListener {
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
protected int time = defaultTime();
|
||||
protected BukkitTask task;
|
||||
private de.steamwar.gamecore.countdown.Countdown countdown;
|
||||
|
||||
protected Countdown(EnumSet<GameStates> enabledStates) {
|
||||
super(enabledStates);
|
||||
@@ -60,30 +56,48 @@ public abstract class Countdown extends GameStateToggleListener {
|
||||
void timerReset() {
|
||||
}
|
||||
|
||||
private void timer() {
|
||||
if (timerShouldCancel()) {
|
||||
time = defaultTime();
|
||||
timerReset();
|
||||
} else {
|
||||
if (time == defaultTime()) {
|
||||
timerStart();
|
||||
}
|
||||
if (time == 0) {
|
||||
timerEnd();
|
||||
return;
|
||||
}
|
||||
run();
|
||||
time--;
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
if (countdown != null) {
|
||||
countdown.setRemainingTime(time + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
task = Bukkit.getScheduler().runTaskTimer(TowerRun.getInstance(), this::timer, 0, 20);
|
||||
countdown = new de.steamwar.gamecore.countdown.Countdown(
|
||||
TowerRun.getInstance(), defaultTime() + 1, 0, 20, false
|
||||
) {
|
||||
@Override
|
||||
protected void onTick(int remaining) {
|
||||
time = remaining;
|
||||
if (timerShouldCancel()) {
|
||||
reset();
|
||||
time = defaultTime();
|
||||
timerReset();
|
||||
return;
|
||||
}
|
||||
if (time == defaultTime()) {
|
||||
timerStart();
|
||||
}
|
||||
if (time > 0) {
|
||||
run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinished() {
|
||||
timerEnd();
|
||||
}
|
||||
};
|
||||
countdown.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
task.cancel();
|
||||
if (countdown != null) {
|
||||
countdown.disable();
|
||||
countdown = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package de.steamwar.towerrun.game;
|
||||
|
||||
import de.steamwar.core.CraftbukkitWrapper;
|
||||
import de.steamwar.gamecore.wincondition.GameResult;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.towerrun.TowerRun;
|
||||
import de.steamwar.towerrun.config.Config;
|
||||
@@ -119,6 +120,14 @@ public class TowerRunGame {
|
||||
}
|
||||
}
|
||||
|
||||
public static void complete(GameResult<TowerRunPlayer> result) {
|
||||
if (result instanceof GameResult.Winner<TowerRunPlayer> winner) {
|
||||
win(winner.getWinner());
|
||||
} else {
|
||||
tie();
|
||||
}
|
||||
}
|
||||
|
||||
public static void win(TowerRunPlayer tPlayer) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.setGameMode(GameMode.SPECTATOR));
|
||||
PLAYERS_ALIVE.clear();
|
||||
|
||||
@@ -19,41 +19,30 @@
|
||||
|
||||
package de.steamwar.towerrun.state;
|
||||
|
||||
import lombok.Getter;
|
||||
import de.steamwar.gamecore.state.GameStateMachine;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@UtilityClass
|
||||
public class GameState {
|
||||
@Getter
|
||||
private static GameStates currentState = GameStates.WAITING;
|
||||
private static final List<GameStateListener> gameStateListeners = new ArrayList<>();
|
||||
private static final GameStateMachine<GameStates> state = new GameStateMachine<>(GameStates.WAITING);
|
||||
|
||||
public static void addGameStateListener(GameStateListener gameStateListener) {
|
||||
gameStateListeners.add(gameStateListener);
|
||||
public static GameStateMachine<GameStates> getLifecycle() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public static GameStates getCurrentState() {
|
||||
return state.getCurrentState();
|
||||
}
|
||||
|
||||
public static void nextState() {
|
||||
final GameStates oldState = currentState;
|
||||
currentState = currentState.getNextState();
|
||||
gameStateChanges(oldState, currentState);
|
||||
state.transitionTo(state.getCurrentState().getNextState());
|
||||
}
|
||||
|
||||
static void setState(final GameStates newState) {
|
||||
final GameStates oldState = currentState;
|
||||
currentState = newState;
|
||||
gameStateChanges(oldState, currentState);
|
||||
state.transitionTo(newState);
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
final GameStates oldState = currentState;
|
||||
currentState = GameStates.WAITING;
|
||||
gameStateChanges(oldState, currentState);
|
||||
}
|
||||
|
||||
private static void gameStateChanges(GameStates oldState, GameStates newState) {
|
||||
gameStateListeners.forEach(gameStateListener -> gameStateListener.onGameStateChange(oldState, newState));
|
||||
state.transitionTo(GameStates.WAITING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2025 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.towerrun.state;
|
||||
|
||||
public abstract class GameStateListener {
|
||||
|
||||
protected GameStateListener() {
|
||||
GameState.addGameStateListener(this);
|
||||
}
|
||||
|
||||
public abstract void onGameStateChange(GameStates oldState, GameStates newState);
|
||||
}
|
||||
@@ -21,28 +21,14 @@ package de.steamwar.towerrun.state;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public abstract class GameStateToggleListener extends GameStateListener {
|
||||
|
||||
private final EnumSet<GameStates> enabledStates;
|
||||
public abstract class GameStateToggleListener extends de.steamwar.gamecore.state.StateDependent<GameStates> {
|
||||
|
||||
protected GameStateToggleListener(EnumSet<GameStates> enabledStates) {
|
||||
super();
|
||||
this.enabledStates = enabledStates;
|
||||
if (enabledStates.contains(GameState.getCurrentState())) {
|
||||
enable();
|
||||
}
|
||||
super(GameState.getLifecycle(), true, enabledStates);
|
||||
register();
|
||||
}
|
||||
|
||||
public abstract void enable();
|
||||
|
||||
public abstract void disable();
|
||||
|
||||
@Override
|
||||
public void onGameStateChange(GameStates oldState, GameStates newState) {
|
||||
if (enabledStates.contains(newState) && !enabledStates.contains(oldState)) {
|
||||
enable();
|
||||
} else if (!enabledStates.contains(newState) && enabledStates.contains(oldState)) {
|
||||
disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class LastRemainingWincondition extends WinCondition {
|
||||
TowerRunGame.PLAYERS_ALIVE.remove(tPlayer);
|
||||
TowerRunGame.PLAYERS_ESCAPED.remove(tPlayer);
|
||||
tPlayer.player().setGameMode(GameMode.SPECTATOR);
|
||||
if (TowerRunGame.PLAYERS_ALIVE.size() == 1 && TowerRunGame.PLAYERS_ESCAPED.isEmpty()) {
|
||||
TowerRunGame.win(TowerRunGame.PLAYERS_ALIVE.get(0));
|
||||
if (TowerRunGame.PLAYERS_ESCAPED.isEmpty() && TowerRunGame.PLAYERS_ALIVE.size() == 1) {
|
||||
TowerRunGame.complete(de.steamwar.gamecore.wincondition.WinConditions.lastRemaining(TowerRunGame.PLAYERS_ALIVE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +50,8 @@ public class LastRemainingWincondition extends WinCondition {
|
||||
if (TowerRunGame.isAlive(tPlayer)) {
|
||||
TowerRunGame.PLAYERS_ALIVE.remove(tPlayer);
|
||||
TowerRunGame.PLAYERS_ESCAPED.remove(tPlayer);
|
||||
if (TowerRunGame.PLAYERS_ALIVE.size() == 1 && TowerRunGame.PLAYERS_ESCAPED.isEmpty()) {
|
||||
TowerRunGame.win(TowerRunGame.PLAYERS_ALIVE.get(0));
|
||||
if (TowerRunGame.PLAYERS_ESCAPED.isEmpty() && TowerRunGame.PLAYERS_ALIVE.size() == 1) {
|
||||
TowerRunGame.complete(de.steamwar.gamecore.wincondition.WinConditions.lastRemaining(TowerRunGame.PLAYERS_ALIVE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.towerrun.winconditions;
|
||||
|
||||
import de.steamwar.towerrun.game.TowerRunPlayer;
|
||||
import de.steamwar.towerrun.state.GameStateBukkitListener;
|
||||
import de.steamwar.towerrun.state.GameStates;
|
||||
import lombok.Getter;
|
||||
@@ -27,7 +28,7 @@ import lombok.Setter;
|
||||
import java.util.EnumSet;
|
||||
|
||||
@Getter
|
||||
public abstract class WinCondition extends GameStateBukkitListener {
|
||||
public abstract class WinCondition extends GameStateBukkitListener implements de.steamwar.gamecore.wincondition.WinCondition<TowerRunPlayer> {
|
||||
|
||||
private final String name;
|
||||
@Setter
|
||||
@@ -38,6 +39,16 @@ public abstract class WinCondition extends GameStateBukkitListener {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean active() {
|
||||
return active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
if (active) {
|
||||
|
||||
@@ -2,4 +2,4 @@ name: TowerRun
|
||||
version: 1.0.0
|
||||
main: de.steamwar.towerrun.TowerRun
|
||||
api-version: 1.21
|
||||
depend: [ SpigotCore ]
|
||||
depend: [ GameCore, SpigotCore ]
|
||||
|
||||
Reference in New Issue
Block a user