Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force start after 30 seconds #42

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions src/main/java/net/minestom/arena/game/mob/MobArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minestom.arena.Messenger;
import net.minestom.arena.feature.Feature;
import net.minestom.arena.feature.Features;
import net.minestom.arena.game.ArenaManager;
import net.minestom.arena.game.Generator;
import net.minestom.arena.game.SingleInstanceArena;
import net.minestom.arena.group.Group;
Expand Down Expand Up @@ -149,6 +150,9 @@ public final class MobArena implements SingleInstanceArena {

private static final int SPAWN_RADIUS = 10;
private static final int HEIGHT = 16;

private static final Duration ROUND_WAIT_TIME = Duration.ofSeconds(30);

private final AtomicInteger mobCount = new AtomicInteger();
private boolean stageInProgress;
private int initialMobCount;
Expand Down Expand Up @@ -365,8 +369,40 @@ private void onStageCleared() {
bossBar.color(BossBar.Color.GREEN);

group().playSound(Sound.sound(SoundEvent.UI_TOAST_CHALLENGE_COMPLETE, Sound.Source.MASTER, 0.5f, 1), Sound.Emitter.self());
arenaInstance.showTitle(Title.title(
Component.text("Stage Cleared", NamedTextColor.GREEN),
Component.text(ROUND_WAIT_TIME.getSeconds() + " seconds to prepare for next stage"),
Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ofMillis(300))
));
Messenger.info(group(), "Stage " + stage + " cleared! Talk to the NPC to continue to the next stage");
new NextStageNPC().setInstance(arenaInstance, new Pos(0.5, HEIGHT, 0.5));

startForceContinueCountdown();
}

private void startForceContinueCountdown() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also display the countdown in an action bar? Just an idea, not a must.

final AtomicInteger countdown = new AtomicInteger((int) ROUND_WAIT_TIME.getSeconds());
MinecraftServer.getSchedulerManager().submitTask(() -> {
final int count = countdown.getAndDecrement();

if (stageInProgress() || !ArenaManager.list().contains(this)) {
return TaskSchedule.stop();
}
if (count == 0) {
continueToNextStage(false);
return TaskSchedule.stop();
}

if (count > 3) {
if (count % 10 == 0) {
Messenger.info(group(), count + " seconds remain to prepare for the next stage.");
}
} else {
Messenger.info(group(), count + " seconds remain.");
}

return TaskSchedule.seconds(1);
});
}

public void continueToNextStage(Player player) {
Expand All @@ -381,13 +417,8 @@ public void continueToNextStage(Player player) {
if (untilStart <= 0) {
Messenger.info(group(), player.getUsername() + " has continued. Starting the next wave.");

bossBar.name(Component.text("Wave starting..."));
bossBar.progress(1);
bossBar.color(BossBar.Color.BLUE);
continueToNextStage(true);

Messenger.countdown(group(), 3)
.thenRun(this::nextStage)
.thenRun(continued::clear);
} else {
Messenger.info(group(), player.getUsername() + " has continued. " + untilStart + " more players must continue to start the next wave.");

Expand All @@ -398,6 +429,20 @@ public void continueToNextStage(Player player) {
}
}

private void continueToNextStage(boolean showCountdown) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the showCountdown? If you don't want to show the countdown, just call nextStage()

bossBar.name(Component.text("Wave starting..."));
bossBar.progress(1);
bossBar.color(BossBar.Color.BLUE);
continued.clear();

if (showCountdown) {
Messenger.countdown(group(), 3)
.thenRun(this::nextStage);
} else {
nextStage();
}
}

public int stage() {
return stage;
}
Expand Down Expand Up @@ -439,7 +484,8 @@ public void nextStage() {

arenaInstance.showTitle(Title.title(
Component.text("Stage " + stage, NamedTextColor.GREEN),
Component.text(initialMobCount + mobOrMobs)
Component.text(initialMobCount + mobOrMobs),
Title.Times.times(Duration.ofMillis(500), Duration.ofSeconds(1), Duration.ofMillis(500))
));

arenaInstance.playSound(Sound.sound(SoundEvent.BLOCK_NOTE_BLOCK_PLING, Sound.Source.MASTER, 1f, 2f));
Expand Down