Add TowerRun module

This commit is contained in:
2024-08-05 09:02:07 +02:00
parent a760366d30
commit d4af6d9ddb
29 changed files with 2293 additions and 1 deletions
@@ -0,0 +1,35 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.winconditions;
import de.steamwar.towerrun.game.TowerRunGame;
import de.steamwar.towerrun.game.TowerRunPlayer;
import org.bukkit.entity.Player;
public class FirstOutsideWincondition extends OutsideWincondition {
public FirstOutsideWincondition() {
super("FIRST_OUTSIDE");
}
@Override
public void onPlayerOutside(Player player) {
TowerRunGame.win(TowerRunPlayer.get(player));
}
}
@@ -0,0 +1,53 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.winconditions;
import de.steamwar.towerrun.game.TowerRunGame;
import de.steamwar.towerrun.game.TowerRunPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PlayerDeathEvent;
public class LastOutsideWincondition extends OutsideWincondition {
public LastOutsideWincondition() {
super("LAST_OUTSIDE");
}
@Override
public void onPlayerOutside(Player player) {
TowerRunPlayer towerRunPlayer = TowerRunPlayer.get(player);
outside(towerRunPlayer);
if (TowerRunGame.PLAYERS_ALIVE.isEmpty()) {
TowerRunGame.win(towerRunPlayer);
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerDeath(PlayerDeathEvent event) {
if (TowerRunGame.PLAYERS_ALIVE.isEmpty()) {
if (TowerRunGame.PLAYERS_ESCAPED.isEmpty()) {
TowerRunGame.tie();
return;
}
TowerRunGame.win(TowerRunGame.PLAYERS_ESCAPED.get(TowerRunGame.PLAYERS_ESCAPED.size() - 1));
}
}
}
@@ -0,0 +1,58 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.winconditions;
import de.steamwar.towerrun.game.TowerRunGame;
import de.steamwar.towerrun.game.TowerRunPlayer;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class LastRemainingWincondition extends WinCondition {
public LastRemainingWincondition() {
super("LAST_REMAINING");
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getEntity());
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));
}
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerQuit(PlayerQuitEvent event) {
TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getPlayer());
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));
}
}
}
}
@@ -0,0 +1,73 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.winconditions;
import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.Config;
import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.game.TowerRunGame;
import de.steamwar.towerrun.game.TowerRunPlayer;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;
import java.util.Arrays;
public abstract class OutsideWincondition extends WinCondition {
protected OutsideWincondition(String name) {
super(name);
}
public abstract void onPlayerOutside(Player player);
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
if (event.getTo().getY() > WorldConfig.ESCAPE_HEIGHT) {
return;
}
TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getPlayer());
if (!TowerRunGame.isAlive(tPlayer)) {
return;
}
if (Arrays.stream(WorldConfig.REGIONS).anyMatch(region -> region.contains(event.getTo().toVector()))) {
return;
}
if (event.getTo().getY() - event.getFrom().getY() != 0) {
return;
}
onPlayerOutside(event.getPlayer());
}
protected void outside(TowerRunPlayer towerRunPlayer) {
TowerRunGame.PLAYERS_ESCAPED.add(towerRunPlayer);
TowerRunGame.PLAYERS_ALIVE.remove(towerRunPlayer);
towerRunPlayer.player().setGameMode(GameMode.SPECTATOR);
TowerRun.getMessage().broadcast("PLAYER_ESCAPE", towerRunPlayer.player().getName());
if (TowerRunGame.PLAYERS_ESCAPED.size() == 1) {
TowerRun.getGameCountdown().setTime(Config.GAME_ESCAPE_TIMER);
}
}
}
@@ -0,0 +1,54 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2023 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.winconditions;
import de.steamwar.towerrun.state.GameStateBukkitListener;
import de.steamwar.towerrun.state.GameStates;
import lombok.Getter;
import lombok.Setter;
import java.util.*;
@Getter
public abstract class WinCondition extends GameStateBukkitListener {
private final String name;
@Setter
private boolean active = false;
protected WinCondition(String name) {
super(EnumSet.of(GameStates.INGAME));
this.name = name;
}
@Override
public void enable() {
if (active) {
super.enable();
}
}
@Override
public void disable() {
if (active) {
super.disable();
}
}
}