Skip to content

Commit

Permalink
LS: Show CPE announcement message when 10 seconds or less left until …
Browse files Browse the repository at this point in the history
…flood
  • Loading branch information
UnknownShadow200 committed Dec 23, 2022
1 parent 7839bf3 commit b9eb9f4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
10 changes: 9 additions & 1 deletion MCGalaxy/Games/LavaSurvival/LSGame.Physics.cs
Expand Up @@ -23,9 +23,17 @@ namespace MCGalaxy.Games
{
public sealed partial class LSGame : RoundsGame
{
void UpdateBlockHandlers() {
Map.UpdateBlockHandlers(Block.Water);
Map.UpdateBlockHandlers(Block.Deadly_ActiveWater);
Map.UpdateBlockHandlers(Block.Lava);
Map.UpdateBlockHandlers(Block.Deadly_ActiveLava);
Map.UpdateBlockHandlers(Block.FastLava);
Map.UpdateBlockHandlers(Block.Deadly_FastLava);
}

void HandleBlockHandlersUpdated(Level lvl, BlockID block) {
if (lvl != Map) return;
if (!Running || lvl != Map) return;

switch (block)
{
Expand Down
26 changes: 16 additions & 10 deletions MCGalaxy/Games/LavaSurvival/LSGame.Round.cs
Expand Up @@ -34,17 +34,11 @@ public sealed partial class LSGame : RoundsGame
RoundStart = DateTime.UtcNow;
RoundInProgress = true;
Map.SetPhysics(destroyMode ? 2 : 1);

Map.UpdateBlockHandlers(Block.Water);
Map.UpdateBlockHandlers(Block.Deadly_ActiveWater);
Map.UpdateBlockHandlers(Block.Lava);
Map.UpdateBlockHandlers(Block.Deadly_ActiveLava);
Map.UpdateBlockHandlers(Block.FastLava);
Map.UpdateBlockHandlers(Block.Deadly_FastLava);
UpdateBlockHandlers();

while (RoundInProgress && roundSecs < roundTotalSecs) {
if (!Running) return;
if ((roundSecs % 60) == 0 && !flooded) { Map.Message(FloodTimeLeftMessage()); }
if (!flooded) AnnounceFloodTime();

if (roundSecs >= floodDelaySecs) {
if (layerMode && (layerSecs % layerIntervalSecs) == 0 && curLayer <= cfg.LayerCount) {
Expand Down Expand Up @@ -75,14 +69,26 @@ public sealed partial class LSGame : RoundsGame
Map.Message("The round has ended!");
}

void AnnounceFloodTime() {
int left = floodDelaySecs - roundSecs;

if (left == 0) {
MessageMap(CpeMessageType.Announcement, "");
} else if (left <= 10) {
MessageCountdown("&3{0} &Sseconds until the flood", left, 10);
} else if ((roundSecs % 60) == 0) {
Map.Message(FloodTimeLeftMessage());
}
}

string FloodTimeLeftMessage() {
TimeSpan left = TimeSpan.FromSeconds(floodDelaySecs - roundSecs);
return "&3" + left.Shorten(true) + " &Suntil the flood.";
return "&3" + left.Shorten(true) + " &Suntil the flood starts";
}

string RoundTimeLeftMessage() {
TimeSpan left = TimeSpan.FromSeconds(roundTotalSecs - roundSecs);
return "&3" + left.Shorten(true) + " &Suntil the round ends.";
return "&3" + left.Shorten(true) + " &Suntil the round ends";
}

public override void OutputStatus(Player p) {
Expand Down
13 changes: 9 additions & 4 deletions MCGalaxy/Games/LavaSurvival/LSGame.cs
Expand Up @@ -19,12 +19,15 @@
using System.Collections.Generic;
using BlockID = System.UInt16;

namespace MCGalaxy.Games {
internal sealed class LSData {
namespace MCGalaxy.Games
{
internal sealed class LSData
{
public int TimesDied;
}

public sealed partial class LSGame : RoundsGame {
public sealed partial class LSGame : RoundsGame
{
LSMapConfig cfg = new LSMapConfig();
public static LSConfig Config = new LSConfig();
public override string GameName { get { return "Lava survival"; } }
Expand Down Expand Up @@ -86,6 +89,7 @@ public sealed partial class LSGame : RoundsGame {
protected override void EndGame() {
flooded = false;
ResetPlayerDeaths();
if (Map != null) UpdateBlockHandlers();
}

public bool IsPlayerDead(Player p) {
Expand All @@ -94,7 +98,8 @@ public sealed partial class LSGame : RoundsGame {

void ResetPlayerDeaths() {
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
foreach (Player p in players)
{
if (p.level == Map) Get(p).TimesDied = 0;
}
}
Expand Down
24 changes: 15 additions & 9 deletions MCGalaxy/Games/RoundsGame/RoundsGame.cs
Expand Up @@ -136,17 +136,23 @@ public abstract partial class RoundsGame : IGame
}

protected void DoCountdown(string format, int delay, int minThreshold) {
const CpeMessageType type = CpeMessageType.Announcement;
for (int i = delay; i > 0 && Running; i--) {
if (i == 1) {
MessageMap(type, String.Format(format, i)
.Replace("seconds", "second"));
} else if (i < minThreshold || (i % 10) == 0) {
MessageMap(type, String.Format(format, i));
}
for (int i = delay; i > 0 && Running; i--)
{
MessageCountdown(format, i, minThreshold);
Thread.Sleep(1000);
}
MessageMap(type, "");
MessageMap(CpeMessageType.Announcement, "");
}

protected void MessageCountdown(string format, int i, int minThreshold) {
const CpeMessageType type = CpeMessageType.Announcement;

if (i == 1) {
MessageMap(type, String.Format(format, i)
.Replace("seconds", "second"));
} else if (i < minThreshold || (i % 10) == 0) {
MessageMap(type, String.Format(format, i));
}
}

protected List<Player> DoRoundCountdown(int delay) {
Expand Down

0 comments on commit b9eb9f4

Please sign in to comment.