Skip to content

Commit

Permalink
LS: Prevent placing blocks next to lava spawn by default
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jan 29, 2023
1 parent 9a42403 commit be9b827
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
5 changes: 5 additions & 0 deletions MCGalaxy/Modules/Games/LavaSurvival/LSConfig.cs
Expand Up @@ -44,6 +44,11 @@ public sealed class LSConfig : RoundsGameConfig
[ConfigTimespan("default-flood-time", "Defaults", 5, true)]
public TimeSpan DefaultFloodTime = TimeSpan.FromMinutes(5);

[ConfigBool("lava-spawn-protection", "Protection", true)]
public bool SpawnProtection = true;
[ConfigInt("lava-spawn-protection-radius", "Protection", 5)]
public int SpawnProtectionRadius = 5;

public override bool AllowAutoload { get { return false; } }
protected override string GameName { get { return "Lava Survival"; } }

Expand Down
23 changes: 18 additions & 5 deletions MCGalaxy/Modules/Games/LavaSurvival/LSGame.Plugin.cs
Expand Up @@ -21,6 +21,7 @@
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Events.LevelEvents;
using MCGalaxy.Games;
using MCGalaxy.Maths;
using BlockID = System.UInt16;

namespace MCGalaxy.Modules.Games.LS
Expand Down Expand Up @@ -66,13 +67,19 @@ public sealed partial class LSGame : RoundsGame

void HandleBlockChanging(Player p, ushort x, ushort y, ushort z, BlockID block, bool placing, ref bool cancel) {
if (p.level != Map || !(placing || p.painting)) return;

if (Config.SpawnProtection && NearLavaSpawn(x, y, z)) {
p.Message("You can't place blocks so close to the {0} spawn", FloodBlockName());
p.RevertBlock(x, y, z);
cancel = true; return;
}

block = p.GetHeldBlock();
if (block != Block.Sponge) return;
LSData data = Get(p);

if (!p.Game.Referee && data.SpongesLeft <= 0) {
p.Message("You have no sponges left.");
p.Message("You have no sponges left");
p.RevertBlock(x, y, z);
cancel = true; return;
}
Expand All @@ -91,9 +98,15 @@ public sealed partial class LSGame : RoundsGame
p.Message("Sponges Left: &4" + data.SpongesLeft);
}
}

/*bool NearLavaSpawn(ushort x, ushort y, ushort z) {
cfg.FloodPos
}*/

bool NearLavaSpawn(ushort x, ushort y, ushort z) {
Vec3U16 pos = layerMode ? CurrentLayerPos() : cfg.FloodPos;
int dist = Config.SpawnProtectionRadius;

int dx = Math.Abs(x - pos.X);
int dy = Math.Abs(y - pos.Y);
int dz = Math.Abs(z - pos.Z);
return dx <= dist && dy <= dist && dz <= dist;
}
}
}
16 changes: 6 additions & 10 deletions MCGalaxy/Modules/Games/LavaSurvival/LSGame.Round.cs
Expand Up @@ -47,7 +47,6 @@ public sealed partial class LSGame : RoundsGame
RoundInProgress = true;
UpdateBlockHandlers();
Map.SetPhysics(destroyMode ? 2 : 1);
Vec3U16 pos;

while (RoundInProgress && roundSecs < roundTotalSecs) {
if (!Running) return;
Expand All @@ -57,9 +56,7 @@ public sealed partial class LSGame : RoundsGame
if (!layerMode && roundSecs == floodDelaySecs) {
FloodFrom(cfg.FloodPos);
} else if (layerMode && (layerSecs % layerIntervalSecs) == 0 && curLayer <= cfg.LayerCount) {
pos = cfg.LayerPos;
pos.Y = (ushort)(pos.Y + ((cfg.LayerHeight * curLayer) - 1));
FloodFrom(pos);
FloodFrom(CurrentLayerPos());
curLayer++;
}

Expand Down Expand Up @@ -142,14 +139,13 @@ public sealed partial class LSGame : RoundsGame
}

void OutputRoundInfo(Player p) {
string block = waterMode ? "water" : "lava";

string block = FloodBlockName();
if (waterMode) p.Message("The map will be flooded with &9water &Sthis round!");
if (layerMode) p.Message("The " + block + " will &aflood in layers &Sthis round!");
if (layerMode) p.Message("The {0} will &aflood in layers &Sthis round!", block);

if (fastMode) p.Message("The lava will be &cfast &Sthis round!");
if (destroyMode) p.Message("The " + block + " will &cdestroy plants " + (waterMode ? "" : "and flammable blocks ") + "&Sthis round!");
if (floodUp) p.Message("The " + block + " will &cflood upwards &Sthis round!");
if (fastMode) p.Message("The {0} will be &cfast &Sthis round!", block);
if (destroyMode) p.Message("The {0} will &cdestroy plants " + (waterMode ? "" : "and flammable blocks ") + "&Sthis round!", block);
if (floodUp) p.Message("The {0} will &cflood upwards &Sthis round!", block);
}

public override void OutputTimeInfo(Player p) {
Expand Down
23 changes: 17 additions & 6 deletions MCGalaxy/Modules/Games/LavaSurvival/LSGame.cs
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using MCGalaxy.Games;
using MCGalaxy.Maths;
using BlockID = System.UInt16;

namespace MCGalaxy.Modules.Games.LS
Expand Down Expand Up @@ -76,7 +77,6 @@ public sealed partial class LSGame : RoundsGame
}
spreadDelay = fastMode ? 0 : 4;

curLayer = 1;
roundTotalSecs = (int)Config.GetRoundTime(cfg).TotalSeconds;
floodDelaySecs = (int)Config.GetFloodTime(cfg).TotalSeconds;
layerIntervalSecs = (int)Config.GetLayerInterval(cfg).TotalSeconds;
Expand Down Expand Up @@ -135,11 +135,6 @@ public sealed partial class LSGame : RoundsGame
if (p.level == Map) Get(p).TimesDied = 0;
}
}

bool InSafeZone(ushort x, ushort y, ushort z) {
return x >= cfg.SafeZoneMin.X && x <= cfg.SafeZoneMax.X && y >= cfg.SafeZoneMin.Y
&& y <= cfg.SafeZoneMax.Y && z >= cfg.SafeZoneMin.Z && z <= cfg.SafeZoneMax.Z;
}

public override void PlayerJoinedGame(Player p) {
bool announce = false;
Expand All @@ -149,5 +144,21 @@ public sealed partial class LSGame : RoundsGame
static void ResetRoundState(Player p, LSData data) {
data.SpongesLeft = 10;
}


bool InSafeZone(ushort x, ushort y, ushort z) {
return x >= cfg.SafeZoneMin.X && x <= cfg.SafeZoneMax.X && y >= cfg.SafeZoneMin.Y
&& y <= cfg.SafeZoneMax.Y && z >= cfg.SafeZoneMin.Z && z <= cfg.SafeZoneMax.Z;
}

Vec3U16 CurrentLayerPos() {
Vec3U16 pos = cfg.LayerPos;
pos.Y = (ushort)(pos.Y + ((cfg.LayerHeight * curLayer) - 1));
return pos;
}

string FloodBlockName() {
return waterMode ? "water" : "lava";
}
}
}

0 comments on commit be9b827

Please sign in to comment.