Modularise whether a block is 'deadly', also make rocket use lava_fire instead of fire for its tail.

This commit is contained in:
UnknownShadow200 2016-07-18 14:25:20 +10:00
parent 90b8ab5cb8
commit 944fa5053f
8 changed files with 44 additions and 62 deletions

View File

@ -133,6 +133,7 @@ namespace MCGalaxy {
physicsHandlers[Block.leaf] = LeafPhysics.DoLeaf;
physicsHandlers[Block.shrub] = OtherPhysics.DoShrub;
physicsHandlers[Block.fire] = FirePhysics.Do;
physicsHandlers[Block.lava_fire] = FirePhysics.Do;
physicsHandlers[Block.sand] = OtherPhysics.DoFalling;
physicsHandlers[Block.gravel] = OtherPhysics.DoFalling;
physicsHandlers[Block.cobblestoneslab] = OtherPhysics.DoStairs;

View File

@ -49,7 +49,7 @@ namespace MCGalaxy.BlockBehaviour {
if ( b1 == Block.air && b2 == Block.air && p.level.CheckClear((ushort)( x + dx * 2 ), (ushort)( y + dy * 2 ), (ushort)( z + dz * 2 ))
&& p.level.CheckClear((ushort)( x + dx ), (ushort)( y + dy ), (ushort)( z + dz )) ) {
p.level.Blockchange((ushort)( x + dx * 2 ), (ushort)( y + dy * 2 ), (ushort)( z + dz * 2 ), Block.rockethead);
p.level.Blockchange((ushort)( x + dx ), (ushort)( y + dy ), (ushort)( z + dz ), Block.fire);
p.level.Blockchange((ushort)( x + dx ), (ushort)( y + dy ), (ushort)( z + dz ), Block.lava_fire);
}
return true;
}

View File

@ -94,7 +94,7 @@ namespace MCGalaxy {
Props[leaf].LavaKills = true;
Props[red].IsRails = true; Props[op_air].IsRails = true;
SetupDefaultNames();
SetupDeathMessages();
SetupDefaultDeaths();
}
static void Door(byte doorId, byte airId, bool saveConvert = true) {
@ -202,27 +202,35 @@ namespace MCGalaxy {
Aliases["step"] = staircasestep; Aliases["double_step"] = staircasefull;
}
static void SetupDeathMessages() {
Props[Block.tntexplosion].DeathMessage = "{0} %S&cblew into pieces.";
Props[Block.deathair].DeathMessage = "{0} %Swalked into &cnerve gas and suffocated.";
Props[Block.deathwater].DeathMessage = "{0} %Sstepped in &dcold water and froze.";
Props[Block.activedeathwater].DeathMessage = Props[Block.deathwater].DeathMessage;
Props[Block.deathlava].DeathMessage = "{0} %Sstood in &cmagma and melted.";
Props[Block.activedeathlava].DeathMessage = Props[Block.deathlava].DeathMessage;
Props[Block.fastdeathlava].DeathMessage = Props[Block.deathlava].DeathMessage;
Props[Block.magma].DeathMessage = "{0} %Swas hit by &cflowing magma and melted.";
Props[Block.geyser].DeathMessage = "{0} %Swas hit by &cboiling water and melted.";
Props[Block.birdkill].DeathMessage = "{0} %Swas hit by a &cphoenix and burnt.";
Props[Block.train].DeathMessage = "{0} %Swas hit by a &ctrain.";
Props[Block.fishshark].DeathMessage = "{0} %Swas eaten by a &cshark.";
Props[Block.fire].DeathMessage = "{0} %Sburnt to a &ccrisp.";
Props[Block.rockethead].DeathMessage = "{0} %Swas &cin a fiery explosion.";
Props[Block.zombiebody].DeathMessage = "{0} %Sdied due to lack of &5brain.";
Props[Block.creeper].DeathMessage = "{0} %Swas killed &cb-SSSSSSSSSSSSSS";
Props[Block.air].DeathMessage = "{0} %Shit the floor &chard.";
Props[Block.water].DeathMessage = "{0} %S&cdrowned.";
Props[Block.Zero].DeathMessage = "{0} %Swas &cterminated";
Props[Block.fishlavashark].DeathMessage = "{0} %Swas eaten by a ... LAVA SHARK?!";
static void SetupDefaultDeaths() {
SetDeath(Block.tntexplosion, "{0} %S&cblew into pieces.");
SetDeath(Block.deathair, "{0} %Swalked into &cnerve gas and suffocated.");
SetDeath(Block.deathwater, "{0} %Sstepped in &dcold water and froze.");
SetDeath(Block.activedeathwater, Props[Block.deathwater].DeathMessage);
SetDeath(Block.deathlava, "{0} %Sstood in &cmagma and melted.");
SetDeath(Block.activedeathlava, Props[Block.deathlava].DeathMessage);
SetDeath(Block.fastdeathlava, Props[Block.deathlava].DeathMessage);
SetDeath(Block.magma, "{0} %Swas hit by &cflowing magma and melted.");
SetDeath(Block.geyser, "{0} %Swas hit by &cboiling water and melted.");
SetDeath(Block.birdkill, "{0} %Swas hit by a &cphoenix and burnt.");
SetDeath(Block.train, "{0} %Swas hit by a &ctrain.");
SetDeath(Block.fishshark, "{0} %Swas eaten by a &cshark.");
SetDeath(Block.lava_fire, "{0} %Sburnt to a &ccrisp.");
SetDeath(Block.rockethead, "{0} %Swas &cin a fiery explosion.");
SetDeath(Block.zombiebody, "{0} %Sdied due to lack of &5brain.");
SetDeath(Block.creeper, "{0} %Swas killed &cb-SSSSSSSSSSSSSS");
SetDeath(Block.fishlavashark, "{0} %Swas eaten by a ... LAVA SHARK?!");
SetDeath(Block.snake, "{0} %Swas bit by a deadly snake.");
SetDeath(Block.air, "{0} %Shit the floor &chard.", false);
SetDeath(Block.water, "{0} %S&cdrowned.", false);
SetDeath(Block.Zero, "{0} %Swas &cterminated.", false);
}
static void SetDeath(byte block, string message, bool collideKill = true) {
Props[block].DeathMessage = message;
Props[block].CollisionDeath = collideKill;
}
}
}

View File

@ -97,38 +97,7 @@ namespace MCGalaxy
public static bool OPBlocks(byte type) { return Props[type].OPBlock; }
public static bool Death(byte type)
{
switch (type)
{
case tntexplosion:
case deathwater:
case deathlava:
case deathair:
case activedeathlava:
case activedeathwater:
case fastdeathlava:
case magma:
case geyser:
case birdkill:
case fishshark:
case fishlavashark:
case train:
case snake:
case lava_fire:
case rockethead:
case creeper:
case zombiebody:
//case zombiehead:
return true;
}
return false;
}
public static bool Death(byte type) { return Props[type].CollisionDeath; }
public static bool BuildIn(byte type) {
if (type == op_water || type == op_lava || portal(type) || mb(type)) return false;

View File

@ -33,8 +33,12 @@ namespace MCGalaxy.Blocks {
/// <summary> Block name used for in commands. </summary>
public string Name;
/// <summary> Message shown to the level when the player is killed by this block. Can be null. </summary>
public string DeathMessage;
/// <summary> Whether colliding with this block kills the player. </summary>
public bool CollisionDeath;
/// <summary> Whether this block is considered a tdoor. </summary>
public bool IsTDoor;
/// <summary> Block id this block is converted to when toggled by a neighbouring door. </summary>

View File

@ -80,7 +80,7 @@ namespace MCGalaxy.BlockPhysics {
if (unblocked) {
lvl.AddUpdate(b1, Block.rockethead);
lvl.AddUpdate(b2, Block.fire);
lvl.AddUpdate(b2, Block.lava_fire);
}
} else if (b == Block.firework) {
int b1 = lvl.IntOffset(C.b, xx, yy + 1, zz);

View File

@ -34,7 +34,7 @@ namespace MCGalaxy.BlockPhysics {
for (int cz = -dirZ; cz != 2 * dirZ; cz += dirZ)
{
byte rocketTail = lvl.GetTile((ushort)(x + cx), (ushort)(y + cy), (ushort)(z + cz));
if (rocketTail != Block.fire) continue;
if (rocketTail != Block.lava_fire) continue;
int headIndex = lvl.PosToInt((ushort)(x - cx), (ushort)(y - cy), (ushort)(z - cz));
byte rocketHead = headIndex < 0 ? Block.Zero : lvl.blocks[headIndex];
@ -43,13 +43,13 @@ namespace MCGalaxy.BlockPhysics {
if (unblocked && (rocketHead == Block.air || rocketHead == Block.rocketstart)) {
lvl.AddUpdate(headIndex, Block.rockethead);
lvl.AddUpdate(C.b, Block.fire);
} else if (rocketHead == Block.fire) {
lvl.AddUpdate(C.b, Block.lava_fire);
} else if (rocketHead == Block.lava_fire) {
} else {
if (lvl.physics > 2)
lvl.MakeExplosion(x, y, z, 2);
else
lvl.AddUpdate(C.b, Block.fire);
lvl.AddUpdate(C.b, Block.lava_fire);
}
}
}

View File

@ -817,7 +817,6 @@ return;
}
public void HandleDeath(byte b, string customMessage = "", bool explode = false, bool immediate = false) {
ushort x = (ushort)(pos[0] / 32), y = (ushort)(pos[1] / 32), z = (ushort)(pos[2] / 32);
if (OnDeath != null) OnDeath(this, b);
if (PlayerDeath != null) PlayerDeath(this, b);
OnPlayerDeathEvent.Call(this, b);
@ -825,7 +824,8 @@ return;
if (Server.lava.active && Server.lava.HasPlayer(this) && Server.lava.IsPlayerDead(this)) return;
if (!immediate && lastDeath.AddSeconds(2) > DateTime.UtcNow) return;
if (!level.Killer || invincible || hidden) return;
ushort x = (ushort)(pos[0] / 32), y = (ushort)(pos[1] / 32), z = (ushort)(pos[2] / 32);
string deathMsg = Block.Props[b].DeathMessage;
if (deathMsg != null) Chat.GlobalChatLevel(this, String.Format(deathMsg, ColoredName), false);
if (b == Block.rockethead) level.MakeExplosion(x, y, z, 0);