From 6dc849a2471d7031709aef4ff0e78b342ad1ac21 Mon Sep 17 00:00:00 2001 From: ellieisjelly Date: Thu, 4 Jan 2024 19:59:29 -0300 Subject: [PATCH] Remove unused imports and add grace period countdown --- .../Sabotage/game/phase/SabotageActive.java | 15 ++++++++++++--- .../Sabotage/game/phase/SabotageWaiting.java | 15 +++++++-------- src/main/resources/data/sabotage/lang/en_us.json | 3 +++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/ellieis/Sabotage/game/phase/SabotageActive.java b/src/main/java/me/ellieis/Sabotage/game/phase/SabotageActive.java index 06a7774..296acb9 100644 --- a/src/main/java/me/ellieis/Sabotage/game/phase/SabotageActive.java +++ b/src/main/java/me/ellieis/Sabotage/game/phase/SabotageActive.java @@ -1,6 +1,8 @@ package me.ellieis.Sabotage.game.phase; import com.google.common.collect.ImmutableSet; +import eu.pb4.sidebars.api.Sidebar; +import eu.pb4.sidebars.api.lines.SidebarLine; import me.ellieis.Sabotage.game.SabotageConfig; import me.ellieis.Sabotage.game.map.SabotageMap; import net.minecraft.network.packet.s2c.play.PositionFlag; @@ -102,6 +104,7 @@ public void pickRoles() { this.detectives.showTitle(Text.translatable("sabotage.role_reveal", Text.translatable("sabotage.detective").formatted(Formatting.DARK_BLUE)), 10, 80, 10); this.detectives.playSound(SoundEvents.BLOCK_AMETHYST_BLOCK_CHIME); this.saboteurs.showTitle(Text.translatable("sabotage.role_reveal", Text.translatable("sabotage.saboteur").formatted(Formatting.RED)), 10, 80, 10); + this.saboteurs.playSound(SoundEvents.ENTITY_ILLUSIONER_CAST_SPELL); this.saboteurs.playSound(SoundEvents.AMBIENT_SOUL_SAND_VALLEY_MOOD.value()); } public void Start() { @@ -114,8 +117,11 @@ public static void Open(GameSpace gameSpace, ServerWorld world, SabotageMap map, SabotageActive game = new SabotageActive(config, gameSpace, map, world); game.startTime = world.getTime(); game.countdown = true; + game.activity = activity; game.widgets = GlobalWidgets.addTo(activity); - game.globalSidebar = game.widgets.addSidebar(Text.translatable("gameType.sabotage.sabotage")); + game.globalSidebar = game.widgets.addSidebar(Text.translatable("gameType.sabotage.sabotage").formatted(Formatting.GOLD)); + game.globalSidebar.setPriority(Sidebar.Priority.LOW); + game.globalSidebar.setLine(SidebarLine.create(0, Text.translatable("sabotage.sidebar.countdown"))); rules(activity); activity.listen(GameActivityEvents.TICK, game::onTick); @@ -127,7 +133,6 @@ public static void Open(GameSpace gameSpace, ServerWorld world, SabotageMap map, game.map.spawnEntity(world, plr); game.globalSidebar.addPlayer(plr); }); - }); } @@ -160,8 +165,12 @@ public void onTick() { } else { // to-do: implement grace period int secondsSinceStart = (int) Math.floor((time / 20) - (this.startTime / 20)) - this.config.getCountdownTime(); - if (secondsSinceStart >= this.config.getGracePeriod()) { + int gracePeriod = this.config.getGracePeriod(); + if (secondsSinceStart >= gracePeriod) { Start(); + } else { + int secondsLeft = gracePeriod - secondsSinceStart; + this.globalSidebar.setLine(SidebarLine.create(0, Text.translatable("sabotage.sidebar.grace_period." + ((secondsLeft == 1) ? "singular" : "plural"), secondsLeft))); } } } else { diff --git a/src/main/java/me/ellieis/Sabotage/game/phase/SabotageWaiting.java b/src/main/java/me/ellieis/Sabotage/game/phase/SabotageWaiting.java index d7876f6..4487353 100644 --- a/src/main/java/me/ellieis/Sabotage/game/phase/SabotageWaiting.java +++ b/src/main/java/me/ellieis/Sabotage/game/phase/SabotageWaiting.java @@ -1,34 +1,33 @@ package me.ellieis.Sabotage.game.phase; -import eu.pb4.sidebars.api.lines.SidebarLine; import me.ellieis.Sabotage.game.SabotageConfig; import me.ellieis.Sabotage.game.map.SabotageMap; import me.ellieis.Sabotage.game.map.SabotageMapBuilder; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; import xyz.nucleoid.fantasy.RuntimeWorldConfig; -import xyz.nucleoid.plasmid.game.*; + +import xyz.nucleoid.plasmid.game.GameActivity; +import xyz.nucleoid.plasmid.game.GameOpenContext; +import xyz.nucleoid.plasmid.game.GameOpenProcedure; +import xyz.nucleoid.plasmid.game.GameSpace; +import xyz.nucleoid.plasmid.game.GameResult; import xyz.nucleoid.plasmid.game.common.GameWaitingLobby; -import xyz.nucleoid.plasmid.game.common.GlobalWidgets; -import xyz.nucleoid.plasmid.game.common.widget.SidebarWidget; import xyz.nucleoid.plasmid.game.event.GameActivityEvents; import xyz.nucleoid.plasmid.game.event.GamePlayerEvents; import xyz.nucleoid.plasmid.game.player.PlayerOffer; import xyz.nucleoid.plasmid.game.player.PlayerOfferResult; import xyz.nucleoid.plasmid.game.rule.GameRuleType; -import xyz.nucleoid.stimuli.Stimuli; public class SabotageWaiting { private final SabotageConfig config; private final GameSpace gameSpace; private final SabotageMap map; private final ServerWorld world; - private int playerCount; + public SabotageWaiting(SabotageConfig config, GameSpace gameSpace, SabotageMap map, ServerWorld world) { this.config = config; this.gameSpace = gameSpace; diff --git a/src/main/resources/data/sabotage/lang/en_us.json b/src/main/resources/data/sabotage/lang/en_us.json index bb08a4c..643bc2c 100644 --- a/src/main/resources/data/sabotage/lang/en_us.json +++ b/src/main/resources/data/sabotage/lang/en_us.json @@ -2,6 +2,9 @@ "gameType.sabotage.sabotage": "Sabotage", "sabotage.waiting": "Waiting for players.", "sabotage.full": "Game is full.", + "sabotage.sidebar.countdown": "Get ready!", + "sabotage.sidebar.grace_period.plural": "You have %s seconds left.", + "sabotage.sidebar.grace_period.singular": "You have %s second left.", "sabotage.game_start": "The game has started! You have %s seconds to collect items, gear, or hide. Your roles will be selected after the grace period.", "sabotage.role_reveal": "You are a %s", "sabotage.innocent": "Innocent",