Readd rainbow/explode block physics entries for /rp (Thanks FabTheZen), fix message about missing old blockdefs on fresh server start (Thanks venom983).

This commit is contained in:
UnknownShadow200 2016-02-13 09:12:44 +11:00
parent f47d84b732
commit f82df7a926
3 changed files with 73 additions and 33 deletions

View File

@ -47,8 +47,10 @@ namespace MCGalaxy.Commands
switch (s) switch (s)
{ {
case "drop": case "drop":
case "explode":
case "dissipate": case "dissipate":
case "wait": case "wait":
case "rainbow":
break; break;
case "revert": case "revert":
if (skip) break; if (skip) break;
@ -93,7 +95,7 @@ namespace MCGalaxy.Commands
{ {
Player.SendMessage(p, "/restartphysics ([type] [num]) ([type2] [num2]) (...) - Restarts every physics block in an area"); Player.SendMessage(p, "/restartphysics ([type] [num]) ([type2] [num2]) (...) - Restarts every physics block in an area");
Player.SendMessage(p, "[type] will set custom physics for selected blocks"); Player.SendMessage(p, "[type] will set custom physics for selected blocks");
Player.SendMessage(p, "Possible [types]: drop, dissipate, wait, revert"); Player.SendMessage(p, "Possible [types]: drop, explode, dissipate, wait, rainbow, revert");
Player.SendMessage(p, "/rp revert takes block names"); Player.SendMessage(p, "/rp revert takes block names");
} }
public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType) public void Blockchange1(Player p, ushort x, ushort y, ushort z, byte type, byte extType)

View File

@ -55,9 +55,10 @@ namespace MCGalaxy {
GlobalDefs[0].Name = "Air fallback"; GlobalDefs[0].Name = "Air fallback";
try { try {
if (File.Exists(GlobalBackupPath)) if (File.Exists(GlobalPath) && File.Exists(GlobalBackupPath)) {
File.Delete(GlobalBackupPath); File.Delete(GlobalBackupPath);
File.Copy(GlobalPath, GlobalBackupPath); File.Copy(GlobalPath, GlobalBackupPath);
}
} catch (Exception ex) { } catch (Exception ex) {
Server.ErrorLog(ex); Server.ErrorLog(ex);
} }

View File

@ -23,8 +23,8 @@ namespace MCGalaxy.BlockPhysics {
public static class ExtraInfoPhysics { public static class ExtraInfoPhysics {
public static bool DoDoorsOnly(Level lvl, Check C, Random rand) { public static bool DoDoorsOnly(Level lvl, Check C, Random rand) {
string info = C.data as string; string info = C.data as string;
if (info == null) return true; if (info == null) return true;
if (!info.Contains("wait") && lvl.blocks[C.b] == Block.air) if (!info.Contains("wait") && lvl.blocks[C.b] == Block.air)
C.data = ""; C.data = "";
@ -77,13 +77,12 @@ namespace MCGalaxy.BlockPhysics {
} }
public static bool DoComplex(Level lvl, Check C, Random rand) { public static bool DoComplex(Level lvl, Check C, Random rand) {
string info = C.data as string; string info = C.data as string;
if (info == null) return true; if (info == null) return true;
if (!info.Contains("wait") && lvl.blocks[C.b] == Block.air) if (!info.Contains("wait") && lvl.blocks[C.b] == Block.air)
C.data = ""; C.data = "";
bool wait = false, drop = false, dissipate = false, revert = false, door = false; ExtraInfoArgs args = default(ExtraInfoArgs);
int waitTime = 0, dropnum = 0, dissipatenum = 0; byte reverttype = 0;
string[] parts = info.Split(' '); string[] parts = info.Split(' ');
for (int i = 0; i < parts.Length; i++) { for (int i = 0; i < parts.Length; i++) {
@ -91,24 +90,30 @@ namespace MCGalaxy.BlockPhysics {
switch (parts[i]) { switch (parts[i]) {
case "wait": case "wait":
waitTime = int.Parse(parts[i + 1]); args.WaitTime = int.Parse(parts[i + 1]);
wait = true; break; args.Wait = true; break;
case "drop": case "drop":
dropnum = int.Parse(parts[i + 1]); args.DropNum = int.Parse(parts[i + 1]);
drop = true; break; args.Drop = true; break;
case "dissipate": case "dissipate":
dissipatenum = int.Parse(parts[i + 1]); args.DissipateNum = int.Parse(parts[i + 1]);
dissipate = true; break; args.Dissipate = true; break;
case "revert": case "revert":
reverttype = byte.Parse(parts[i + 1]); args.RevertType = byte.Parse(parts[i + 1]);
revert = true; break; args.Revert = true; break;
case "door": case "door":
door = true; break; args.Door = true; break;
case "explode":
args.ExplodeNum = int.Parse(parts[i + 1]);
args.Explode = true; break;
case "rainbow":
args.RainbowNum = int.Parse(parts[i + 1]);
args.Rainbow = true; break;
} }
} }
if (wait) { if (args.Wait) {
if (door && C.time < 2) { if (args.Door && C.time < 2) {
Checktdoor(lvl, lvl.IntOffset(C.b, -1, 0, 0)); Checktdoor(lvl, lvl.IntOffset(C.b, -1, 0, 0));
Checktdoor(lvl, lvl.IntOffset(C.b, 1, 0, 0)); Checktdoor(lvl, lvl.IntOffset(C.b, 1, 0, 0));
Checktdoor(lvl, lvl.IntOffset(C.b, 0, -1, 0)); Checktdoor(lvl, lvl.IntOffset(C.b, 0, -1, 0));
@ -117,50 +122,76 @@ namespace MCGalaxy.BlockPhysics {
Checktdoor(lvl, lvl.IntOffset(C.b, 0, 0, 1)); Checktdoor(lvl, lvl.IntOffset(C.b, 0, 0, 1));
} }
if (C.time > waitTime) { if (C.time > args.WaitTime) {
int waitIndex = info.IndexOf("wait "); int waitIndex = info.IndexOf("wait ");
C.data = C.data =
info.Substring(0, waitIndex) + info.Substring(0, waitIndex) +
info.Substring(info.IndexOf(' ', waitIndex + 5) + 1); info.Substring(info.IndexOf(' ', waitIndex + 5) + 1);
DoOther(lvl, C, rand, revert, dissipate, drop, reverttype, dissipatenum, dropnum); DoOther(lvl, C, rand, ref args);
return false; return false;
} }
C.time++; C.time++;
return true; return true;
} }
DoOther(lvl, C, rand, revert, dissipate, drop, reverttype, dissipatenum, dropnum); DoOther(lvl, C, rand, ref args);
return false; return false;
} }
static void DoOther(Level lvl, Check C, Random rand, bool revert, bool dissipate, static void DoOther(Level lvl, Check C, Random rand, ref ExtraInfoArgs args) {
bool drop, byte reverttype, int dissipatenum, int dropnum) {
ushort x, y, z; ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z); lvl.IntToPos(C.b, out x, out y, out z);
if (revert) {
lvl.AddUpdate(C.b, reverttype); if (args.Rainbow) {
DoRainbow(lvl, C, rand, args.RainbowNum); return;
}
if (args.Revert) {
lvl.AddUpdate(C.b, args.RevertType);
C.data = ""; C.data = "";
} }
// Not setting drop = false can cause occasional leftover blocks, since C.extraInfo is emptied, so // Not setting drop = false can cause occasional leftover blocks, since C.extraInfo is emptied, so
// drop can generate another block with no dissipate/explode information. // drop can generate another block with no dissipate/explode information.
if (dissipate && rand.Next(1, 100) <= dissipatenum) { if (args.Dissipate && rand.Next(1, 100) <= args.DissipateNum) {
if (!lvl.ListUpdate.Exists(Update => Update.b == C.b)) { if (!lvl.ListUpdate.Exists(Update => Update.b == C.b)) {
lvl.AddUpdate(C.b, Block.air); lvl.AddUpdate(C.b, Block.air);
C.data = ""; C.data = "";
drop = false; args.Drop = false;
} else { } else {
lvl.AddUpdate(C.b, lvl.blocks[C.b], false, C.data); lvl.AddUpdate(C.b, lvl.blocks[C.b], false, C.data);
} }
} }
if (drop && rand.Next(1, 100) <= dropnum) if (args.Explode && rand.Next(1, 100) <= args.ExplodeNum) {
DoDrop(lvl, C, rand, dropnum, x, y, z); lvl.MakeExplosion(x, y, z, 0);
C.data = "";
args.Drop = false;
}
if (args.Drop && rand.Next(1, 100) <= args.DropNum)
DoDrop(lvl, C, rand, args.DropNum, x, y, z);
}
static void DoRainbow(Level lvl, Check C, Random rand, int rainbownum) {
if (C.time < 4) {
C.time++; return;
}
if (rainbownum > 2) {
byte block = lvl.blocks[C.b];
if (block < Block.red || block > Block.darkpink) {
lvl.AddUpdate(C.b, Block.red, true);
} else {
byte next = block == Block.darkpink ? Block.red : (byte)(block + 1);
lvl.AddUpdate(C.b, next);
}
} else {
lvl.AddUpdate(C.b, rand.Next(Block.red, Block.darkpink + 1));
}
} }
static void DoDrop(Level lvl, Check C, Random rand, int dropnum, ushort x, ushort y, ushort z) { static void DoDrop(Level lvl, Check C, Random rand, int dropnum, ushort x, ushort y, ushort z) {
int index = lvl.PosToInt(x, (ushort)(y - 1), z); int index = lvl.PosToInt(x, (ushort)(y - 1), z);
if (index < 0) if (index < 0) return;
return;
byte below = lvl.blocks[index]; byte below = lvl.blocks[index];
if (!(below == Block.air || below == Block.lava || below == Block.water)) if (!(below == Block.air || below == Block.lava || below == Block.water))
@ -171,5 +202,11 @@ namespace MCGalaxy.BlockPhysics {
C.data = ""; C.data = "";
} }
} }
struct ExtraInfoArgs {
public bool Wait, Drop, Dissipate, Revert, Door, Explode, Rainbow;
public int WaitTime, DropNum, DissipateNum, ExplodeNum, RainbowNum;
public byte RevertType;
}
} }
} }