- Add HookSabotage system for survivors to disable hooks temporarily - Add GeneratorKick killer ability to regress generator progress - Add PlayerJumpListener to track survivor jump actions - Add BossBarManager for displaying game state and objectives - Update generator regression logic to support killer kick mechanic - Update KillerController to integrate generator kick ability - Update PlayerInteractListener to handle new interaction types - Refactor game phases to use BossBarManager for UI updates - Update .gitignore to exclude compiled bin/ directory - Simplify PLAN.md documentation for easier maintenance
112 lines
3.4 KiB
Java
112 lines
3.4 KiB
Java
package dev.loki.hook;
|
|
|
|
import dev.loki.config.GameConfig;
|
|
import dev.loki.mdbd;
|
|
import dev.loki.player.PlayerState;
|
|
import dev.loki.player.Survivor;
|
|
import dev.loki.ui.TitleUI;
|
|
import org.bukkit.scheduler.BukkitTask;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
public class HookStruggle {
|
|
private final mdbd plugin;
|
|
private final TitleUI titleUI;
|
|
private final Map<UUID, BukkitTask> struggleTasks;
|
|
private final Map<UUID, Integer> struggleProgress;
|
|
private final int struggleIntervalTicks;
|
|
private static final int STRUGGLE_WINDOW_TICKS = 20;
|
|
|
|
public HookStruggle(mdbd plugin, TitleUI titleUI) {
|
|
this(plugin, titleUI, null);
|
|
}
|
|
|
|
public HookStruggle(mdbd plugin, TitleUI titleUI, GameConfig config) {
|
|
this.plugin = plugin;
|
|
this.titleUI = titleUI;
|
|
this.struggleTasks = new HashMap<>();
|
|
this.struggleProgress = new HashMap<>();
|
|
// Читаем из конфига: struggle-interval в секундах → тики
|
|
this.struggleIntervalTicks = (config != null)
|
|
? config.getStruggleInterval() * 20
|
|
: 40; // дефолт 2 сек
|
|
}
|
|
|
|
public void startStruggle(Survivor survivor, Hook hook) {
|
|
UUID uuid = survivor.getUuid();
|
|
if (struggleTasks.containsKey(uuid)) return;
|
|
|
|
BukkitTask task = plugin.getServer().getScheduler().runTaskTimer(
|
|
plugin,
|
|
() -> triggerSkillCheck(survivor, hook),
|
|
struggleIntervalTicks,
|
|
struggleIntervalTicks
|
|
);
|
|
struggleTasks.put(uuid, task);
|
|
struggleProgress.put(uuid, 0);
|
|
}
|
|
|
|
public void stopStruggle(Survivor survivor) {
|
|
UUID uuid = survivor.getUuid();
|
|
BukkitTask task = struggleTasks.remove(uuid);
|
|
if (task != null) {
|
|
task.cancel();
|
|
}
|
|
struggleProgress.remove(uuid);
|
|
}
|
|
|
|
private void triggerSkillCheck(Survivor survivor, Hook hook) {
|
|
UUID uuid = survivor.getUuid();
|
|
var player = survivor.getPlayer();
|
|
if (player == null || !player.isOnline()) {
|
|
stopStruggle(survivor);
|
|
return;
|
|
}
|
|
|
|
if (hook.getCurrentStage() != HookStage.STAGE_2) {
|
|
stopStruggle(survivor);
|
|
return;
|
|
}
|
|
|
|
titleUI.showSkillCheck(player, STRUGGLE_WINDOW_TICKS, (success) -> {
|
|
if (success) {
|
|
incrementProgress(survivor);
|
|
} else {
|
|
failStruggle(survivor);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void incrementProgress(Survivor survivor) {
|
|
Integer progress = struggleProgress.getOrDefault(survivor.getUuid(), 0);
|
|
struggleProgress.put(survivor.getUuid(), progress + 1);
|
|
}
|
|
|
|
private void failStruggle(Survivor survivor) {
|
|
UUID uuid = survivor.getUuid();
|
|
struggleProgress.put(uuid, struggleProgress.getOrDefault(uuid, 0) - 2);
|
|
}
|
|
|
|
public void sacrifice(Survivor survivor) {
|
|
stopStruggle(survivor);
|
|
survivor.setState(PlayerState.DEAD);
|
|
var player = survivor.getPlayer();
|
|
if (player != null) {
|
|
player.setHealth(0);
|
|
}
|
|
}
|
|
|
|
public int getStruggleProgress(UUID uuid) {
|
|
return struggleProgress.getOrDefault(uuid, 0);
|
|
}
|
|
|
|
public void clear() {
|
|
for (BukkitTask task : struggleTasks.values()) {
|
|
task.cancel();
|
|
}
|
|
struggleTasks.clear();
|
|
struggleProgress.clear();
|
|
}
|
|
}
|