Skip to content

Commit

Permalink
unify countdown speed handling
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Sep 13, 2021
1 parent 4ac53c1 commit ac245d4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
14 changes: 3 additions & 11 deletions MCGalaxy/Commands/Fun/CmdCountdown.cs
Expand Up @@ -75,20 +75,12 @@ public sealed class CmdCountdown : RoundsGameCmd {
string speed = args.Length > 1 ? args[1] : "";
string mode = args.Length > 2 ? args[2] : "";

switch (speed) {
case "slow": game.Interval = 800; break;
case "normal": game.Interval = 650; break;
case "fast": game.Interval = 500; break;
case "extreme": game.Interval = 300; break;
case "ultimate": game.Interval = 150; break;

default:
p.Message("No speed specified, playing at 'normal' speed.");
game.Interval = 650; speed = "normal"; break;
if (!game.SetSpeed(speed)) {
p.Message("No speed specified, playing at 'normal' speed.");
game.SetSpeed("normal");
}

game.FreezeMode = mode == "freeze" || mode == "frozen";
game.SpeedType = speed;
game.Start(p, "countdown", int.MaxValue);
}

Expand Down
8 changes: 4 additions & 4 deletions MCGalaxy/Games/Countdown/CountdownGame.Plugin.cs
Expand Up @@ -19,10 +19,10 @@
using MCGalaxy.Events.LevelEvents;
using MCGalaxy.Events.PlayerEvents;

namespace MCGalaxy.Games {

public sealed partial class CountdownGame : RoundsGame {

namespace MCGalaxy.Games
{
public sealed partial class CountdownGame : RoundsGame
{
protected override void HookEventHandlers() {
OnPlayerMoveEvent.Register(HandlePlayerMove, Priority.High);
OnPlayerSpawningEvent.Register(HandlePlayerSpawning, Priority.High);
Expand Down
18 changes: 11 additions & 7 deletions MCGalaxy/Games/Countdown/CountdownGame.Round.cs
Expand Up @@ -25,9 +25,16 @@
using MCGalaxy.Network;
using BlockID = System.UInt16;

namespace MCGalaxy.Games {

public sealed partial class CountdownGame : RoundsGame {
namespace MCGalaxy.Games
{
public sealed partial class CountdownGame : RoundsGame
{
struct SquarePos
{
public ushort X, Z;
public SquarePos(int x, int z) { X = (ushort)x; Z = (ushort)z; }
}

List<SquarePos> squaresLeft = new List<SquarePos>();
BufferedBlockSender bulk = new BufferedBlockSender();

Expand Down Expand Up @@ -63,10 +70,7 @@ public sealed partial class CountdownGame : RoundsGame {
}

void BeginRound() {
if (SpeedType == null || SpeedType == "" || Interval == 0) {
Interval = 650;
SpeedType = "normal";
}
if (Interval == 0) SetSpeed("normal");
string modeSuffix = FreezeMode ? " in freeze mode" : "";
Map.Message("Starting " + SpeedType + " speed Countdown" + modeSuffix);

Expand Down
27 changes: 19 additions & 8 deletions MCGalaxy/Games/Countdown/CountdownGame.cs
Expand Up @@ -25,9 +25,10 @@
using MCGalaxy.Network;
using BlockID = System.UInt16;

namespace MCGalaxy.Games {

public sealed class CountdownConfig : RoundsGameConfig {
namespace MCGalaxy.Games
{
public sealed class CountdownConfig : RoundsGameConfig
{
public override bool AllowAutoload { get { return true; } }
protected override string GameName { get { return "Countdown"; } }
protected override string PropsPath { get { return "properties/countdown.properties"; } }
Expand All @@ -38,7 +39,8 @@ public sealed class CountdownConfig : RoundsGameConfig {
}
}

public sealed partial class CountdownGame : RoundsGame {
public sealed partial class CountdownGame : RoundsGame
{
public VolatileArray<Player> Players = new VolatileArray<Player>();
public VolatileArray<Player> Remaining = new VolatileArray<Player>();

Expand Down Expand Up @@ -131,10 +133,19 @@ public sealed partial class CountdownGame : RoundsGame {
protected override string FormatStatus2(Player p) {
return RoundInProgress ? Remaining.Count + " players left" : "";
}

struct SquarePos {
public ushort X, Z;
public SquarePos(int x, int z) { X = (ushort)x; Z = (ushort)z; }

public bool SetSpeed(string speed) {
switch (speed) {
case "slow": Interval = 800; break;
case "normal": Interval = 650; break;
case "fast": Interval = 500; break;
case "extreme": Interval = 300; break;
case "ultimate": Interval = 150; break;
default: return false;
}

SpeedType = speed;
return true;
}
}
}
10 changes: 5 additions & 5 deletions MCGalaxy/Games/Countdown/CountdownMap.cs
Expand Up @@ -17,11 +17,11 @@
*/
using System;

namespace MCGalaxy.Games {
/// <summary> Generates a map for countdown. </summary>
public static class CountdownMapGen {

namespace MCGalaxy.Games
{
/// <summary> Generates a map for countdown </summary>
public static class CountdownMapGen
{
public static Level Generate(int width, int height, int length) {
Level lvl = new Level("countdown", (ushort)width, (ushort)height, (ushort)length);
MakeBoundaries(lvl);
Expand Down

0 comments on commit ac245d4

Please sign in to comment.