Skip to content
Permalink
Browse files

Fix /top and /setspawn random not moving you to right height

  • Loading branch information...
UnknownShadow200 committed Sep 1, 2018
1 parent 6d31b59 commit f5f946e82bb207941a4cf4ac8d3b884aab35b22d
Showing with 41 additions and 38 deletions.
  1. +25 −30 fCraft/Commands/ModerationCommands.cs
  2. +4 −0 fCraft/Player/Position.cs
  3. +11 −7 fCraft/World/Map.cs
  4. +1 −1 fCraft/Zone/SpecialZone.Move.cs
@@ -1316,15 +1316,18 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
return;
}

Vector3I P = player.World.map.HighestFreeSpace(zone.Bounds.XCentre,
zone.Bounds.YCentre, zone.Bounds.ZCentre);
Position zPos = new Position(P.X * 32 + 16, P.Y * 32 + 16, P.Z * 32 + Player.CharacterHeight);
int x = zone.Bounds.XCentre, y = zone.Bounds.YCentre;
int z = player.WorldMap.HighestFreeSpace(x, y, zone.Bounds.ZCentre);

if (player.World != null) {
player.LastWorld = player.World;
player.LastPosition = player.Position;
}

player.TeleportTo((zPos));
Position pos = new Position(x, y, z);
pos.R = player.Position.R;
pos.L = player.Position.L;
player.TeleportTo(pos);
player.Message("Teleporting you to zone " + zone.ClassyName);
}

@@ -1333,20 +1336,18 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
Random rand = new Random();
int x = rand.Next(0, player.WorldMap.Width);
int y = rand.Next(0, player.WorldMap.Length);
int z = (player.Position.Z - Player.CharacterHeight) / 32;
Vector3I P = player.WorldMap.HighestFreeSpace(x, y, z);
int z = player.Position.BlockFeetZ;
z = player.WorldMap.HighestFreeSpace(x, y, z);

if (player.World != null) {
player.LastWorld = player.World;
player.LastPosition = player.Position;
}
player.TeleportTo(new Position {
X = (P.X * 32 + 16),
Y = (P.Y * 32 + 16),
Z = (P.Z * 32 + Player.CharacterHeight),
R = player.Position.R,
L = player.Position.L
});

Position pos = new Position(x, y, z);
pos.R = player.Position.R;
pos.L = player.Position.L;
player.TeleportTo(pos);
player.Message("Teleported to: ({0}, {1}, {2})", x, y, z);
}

@@ -1376,13 +1377,11 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
player.LastWorld = player.World;
player.LastPosition = player.Position;
}
player.TeleportTo(new Position {
X = (x*32 + 16),
Y = (y*32 + 16),
Z = (z*32 + Player.CharacterHeight),
R = (byte) rot,
L = (byte) lot
});

Position pos = new Position(x, y, z);
pos.R = (byte)rot;
pos.L = (byte)lot;
player.TeleportTo(pos);
} else {
CdTeleport.PrintUsage(player);
}
@@ -1552,16 +1551,12 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
static void TopHandler(Player player, CommandReader cmd) {
int x = player.Position.BlockX;
int y = player.Position.BlockY;
int z = (player.Position.Z - Player.CharacterHeight) / 32;
Vector3I P = player.World.map.HighestFreeSpace(x, y, z);

player.TeleportTo(new Position {
X = (P.X * 32 + 16),
Y = (P.Y * 32 + 16),
Z = (P.Z * 32 + Player.CharacterHeight),
R = player.Position.R,
L = player.Position.L
});
int z = player.WorldMap.HighestFreeZ(x, y);

Position pos = new Position(x, y, z);
pos.R = player.Position.R;
pos.L = player.Position.L;
player.TeleportTo(pos);
player.Message("Teleported to top");
}

@@ -98,6 +98,10 @@ public struct Position : IEquatable<Position> {
return X + "_" + Y + "_" + Z + "_" + R + "_" + L;
}

public static Position FromFeet(int x, int y, int z) {
return new Position(x * 32 + 16, y * 32 + 16, z * 32 + Player.CharacterHeight);
}

public static Position FromString(string text) {
Position pos = new Position();

@@ -111,16 +111,14 @@ static void DefineFallbackBlocks()
public Position getSpawnIfRandom() {
if (spawn == Position.RandomSpawn) {
Random rnd = new Random();
Vector3I P = HighestFreeSpace(rnd.Next(Width), rnd.Next(Length), Height);
return new Position(P.X * 32, P.Y * 32, P.Z * 32, 0, 0);
int x = rnd.Next(Width), y = rnd.Next(Length);
return Position.FromFeet(x, y, HighestFreeZ(x, y));
}
return spawn;
}

public Vector3I HighestFreeSpace(int x, int y, int z) {
while (z > 0 && GetBlock(x, y, z) != Block.Air) {
z--;
}
public int HighestFreeSpace(int x, int y, int z) {
while (z > 0 && GetBlock(x, y, z) != Block.Air) z--;

while (z < Height) {
Block bFeet = GetBlock(x, y, z), bHead = GetBlock(x, y, z + 1);
@@ -130,7 +128,13 @@ static void DefineFallbackBlocks()
if (freeFeet && freeHead) break;
z++;
}
return new Vector3I(x, y, z);
return z;
}

public int HighestFreeZ(int x, int y) {
int z = Bounds.ZMax;
while (z > 0 && GetBlock(x, y, z) == Block.Air) z--;
return z + 1;
}

/// <summary> Resets spawn to the default location (top center of the map). </summary>
@@ -66,7 +66,7 @@ public static partial class SpecialZone {
}

static bool HandleCheckpoint(Player p, Zone zone, ref bool deniedZone, Position newPos) {
Position centre = new Position(zone.Bounds.XCentre * 32 + 16, zone.Bounds.YCentre * 32 + 16, zone.Bounds.ZCentre * 32 + Player.CharacterHeight);
Position centre = Position.FromFeet(zone.Bounds.XCentre, zone.Bounds.YCentre, zone.Bounds.ZCentre);
if (p.CheckPoint == centre) return false;
if (zone.Bounds.Contains(newPos.BlockX, newPos.BlockY, (newPos.Z - 32) / 32)) {
SendZoneMessage(p, "&aCheckPoint &Sreached! This is now your respawn point.");

0 comments on commit f5f946e

Please sign in to comment.
You can’t perform that action at this time.