fix
This commit is contained in:
parent
89dc9eb00d
commit
957ab4a5a2
149 changed files with 5379 additions and 3263 deletions
|
|
@ -6,7 +6,6 @@ import dev.loki.hatch.Hatch;
|
|||
import dev.loki.hatch.HatchCondition;
|
||||
import dev.loki.hatch.HatchEscape;
|
||||
import dev.loki.player.BasePlayer;
|
||||
import dev.loki.player.Killer;
|
||||
import dev.loki.player.PlayerState;
|
||||
import dev.loki.player.Survivor;
|
||||
import dev.loki.ui.Sidebar;
|
||||
|
|
@ -23,27 +22,22 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class EndgamePhase implements Phase {
|
||||
private int collapseSeconds;
|
||||
private final int openTicks;
|
||||
|
||||
private int remainingTicks;
|
||||
private boolean complete;
|
||||
private boolean gatesActivated;
|
||||
private boolean killerWin; // true если маньяк убил всех — пропускаем геймплей эндгейма
|
||||
private GateManager gateManager;
|
||||
private Hatch hatch;
|
||||
private HatchCondition hatchCondition;
|
||||
private HatchEscape hatchEscape;
|
||||
private Sidebar sidebar;
|
||||
|
||||
/** Default constructor — reads collapseSeconds from config on enter() */
|
||||
public EndgamePhase() {
|
||||
this.collapseSeconds = -1; // resolved in enter()
|
||||
this.openTicks = 20 * 20;
|
||||
}
|
||||
|
||||
public EndgamePhase(int collapseSeconds, GateManager gateManager,
|
||||
public EndgamePhase(GateManager gateManager,
|
||||
Hatch hatch, HatchCondition hatchCondition) {
|
||||
this.collapseSeconds = collapseSeconds;
|
||||
this.openTicks = 20 * 20;
|
||||
this.gateManager = gateManager;
|
||||
this.hatch = hatch;
|
||||
|
|
@ -57,20 +51,33 @@ public class EndgamePhase implements Phase {
|
|||
|
||||
@Override
|
||||
public void enter(GameSession session) {
|
||||
// Read collapseSeconds from config if not explicitly set
|
||||
if (collapseSeconds < 0) {
|
||||
collapseSeconds = session.getConfig().getCollapseSeconds();
|
||||
}
|
||||
this.remainingTicks = collapseSeconds * 20;
|
||||
this.complete = false;
|
||||
this.gatesActivated = false;
|
||||
this.killerWin = false;
|
||||
|
||||
// Проверяем: если все выжившие мертвы/на крюке — это killer win,
|
||||
// показываем результаты сразу, без геймплея эндгейма
|
||||
int aliveCount = 0;
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
if (!bp.isKiller() && bp.getState() != PlayerState.DEAD && bp.getState() != PlayerState.ESCAPED) {
|
||||
aliveCount++;
|
||||
}
|
||||
}
|
||||
if (aliveCount == 0) {
|
||||
this.killerWin = true;
|
||||
this.complete = true;
|
||||
// Показываем результаты и телепортируем всех в лобби
|
||||
announceEndgameEnd(session);
|
||||
teleportAllToLobby(session);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pick up GateManager from session if not injected via constructor
|
||||
if (gateManager == null) {
|
||||
gateManager = session.getGateManager();
|
||||
}
|
||||
|
||||
// Set up sidebar with endgame timer
|
||||
// Set up sidebar
|
||||
sidebar = new Sidebar();
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
Player p = bp.getPlayer();
|
||||
|
|
@ -83,12 +90,8 @@ public class EndgamePhase implements Phase {
|
|||
|
||||
@Override
|
||||
public void tick(GameSession session) {
|
||||
remainingTicks--;
|
||||
int secondsLeft = remainingTicks / 20;
|
||||
|
||||
// Update sidebar every second
|
||||
if (remainingTicks % 20 == 0 && sidebar != null) {
|
||||
sidebar.setEndgameTimer(secondsLeft);
|
||||
// Update sidebar stats every 40 ticks
|
||||
if (session.getTicksElapsed() % 40 == 0 && sidebar != null) {
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
Player p = bp.getPlayer();
|
||||
if (p != null && p.isOnline()) {
|
||||
|
|
@ -100,32 +103,61 @@ public class EndgamePhase implements Phase {
|
|||
updateGates(session);
|
||||
updateHatch(session);
|
||||
checkWinConditions(session);
|
||||
sendCountdown(session, secondsLeft);
|
||||
|
||||
if (remainingTicks <= 0) {
|
||||
triggerCollapse(session);
|
||||
complete = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit(GameSession session) {
|
||||
if (sidebar != null) {
|
||||
for (BasePlayer bp : session.getPlayers().values()) {
|
||||
Player p = bp.getPlayer();
|
||||
if (p != null && p.isOnline()) {
|
||||
sidebar.disableTimerObjective(p);
|
||||
}
|
||||
}
|
||||
sidebar.clear();
|
||||
sidebar = null;
|
||||
}
|
||||
announceEndgameEnd(session);
|
||||
|
||||
if (hatch != null) {
|
||||
hatch.reset();
|
||||
}
|
||||
|
||||
// Для killer_win: результаты уже показаны и телепорт выполнен в enter(),
|
||||
// здесь просто останавливаем сессию
|
||||
if (killerWin) {
|
||||
session.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
// Нормальный эндгейм: показываем результаты и телепортируем всех в лобби
|
||||
announceEndgameEnd(session);
|
||||
teleportAllToLobby(session);
|
||||
}
|
||||
|
||||
/**
|
||||
* Телепортирует всех игроков в лобби и останавливает сессию.
|
||||
*/
|
||||
private void teleportAllToLobby(GameSession session) {
|
||||
List<BasePlayer> playersToTeleport = new ArrayList<>(session.getPlayers().values());
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (BasePlayer bp : playersToTeleport) {
|
||||
Player p = bp.getPlayer();
|
||||
if (p != null && p.isOnline()) {
|
||||
p.setGameMode(org.bukkit.GameMode.ADVENTURE);
|
||||
p.getInventory().clear();
|
||||
try {
|
||||
var attr = p.getAttribute(org.bukkit.attribute.Attribute.SCALE);
|
||||
if (attr != null) attr.setBaseValue(1.0);
|
||||
} catch (Exception ignored) {}
|
||||
session.getPlugin().getLobbyManager().teleportToLobby(p);
|
||||
}
|
||||
}
|
||||
session.stop();
|
||||
}
|
||||
}.runTaskLater(session.getPlugin(), 100L);
|
||||
}.runTaskLater(session.getPlugin(), 60L);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -133,10 +165,6 @@ public class EndgamePhase implements Phase {
|
|||
return complete;
|
||||
}
|
||||
|
||||
public int getRemainingSeconds() {
|
||||
return remainingTicks / 20;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Private helpers
|
||||
// -------------------------------------------------------------------------
|
||||
|
|
@ -175,7 +203,7 @@ public class EndgamePhase implements Phase {
|
|||
if (p == null) continue;
|
||||
Title title = Title.title(
|
||||
Component.text("ЭНДГЕЙМ!").color(TextColor.color(0xCC0000)),
|
||||
Component.text("Коллапс через " + collapseSeconds + " сек!").color(NamedTextColor.RED),
|
||||
Component.text("Ворота открыты! Бегите!").color(NamedTextColor.GREEN),
|
||||
Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(500))
|
||||
);
|
||||
p.showTitle(title);
|
||||
|
|
@ -214,42 +242,6 @@ public class EndgamePhase implements Phase {
|
|||
}
|
||||
}
|
||||
|
||||
private void sendCountdown(GameSession session, int secondsLeft) {
|
||||
if (secondsLeft > 0 && secondsLeft <= 10) {
|
||||
for (BasePlayer player : session.getPlayers().values()) {
|
||||
Player p = player.getPlayer();
|
||||
if (p == null) continue;
|
||||
Title t = Title.title(
|
||||
Component.text(String.valueOf(secondsLeft)).color(TextColor.color(0xFF2222)),
|
||||
Component.empty(),
|
||||
Title.Times.times(Duration.ZERO, Duration.ofSeconds(1), Duration.ofMillis(200))
|
||||
);
|
||||
p.showTitle(t);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_HAT, 0.5f, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void triggerCollapse(GameSession session) {
|
||||
for (BasePlayer player : session.getPlayers().values()) {
|
||||
if (player.getState() == PlayerState.DEAD || player.getState() == PlayerState.ESCAPED) continue;
|
||||
Player p = player.getPlayer();
|
||||
if (p == null) continue;
|
||||
if (!player.isKiller()) {
|
||||
p.setHealth(0);
|
||||
player.setState(PlayerState.DEAD);
|
||||
} else {
|
||||
((Killer) player).setCarrying(false);
|
||||
}
|
||||
Title t = Title.title(
|
||||
Component.text("КОЛЛАПС!").color(TextColor.color(0xFF0000)),
|
||||
Component.text("Карта разрушена!").color(NamedTextColor.RED),
|
||||
Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(3), Duration.ofMillis(500))
|
||||
);
|
||||
p.showTitle(t);
|
||||
}
|
||||
}
|
||||
|
||||
private void announceEndgameEnd(GameSession session) {
|
||||
List<String> results = new ArrayList<>();
|
||||
results.add("§6§l=== РЕЗУЛЬТАТЫ ===");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue