Skip to content
Permalink
Browse files

Use named magic constant instead of hardcoding 51/64 everywhere.

  • Loading branch information...
UnknownShadow200 committed May 21, 2017
1 parent 8541f96 commit 29cf24e7d8ecf9fd64322d5dc2c949b4b52a2caf
Showing with 11 additions and 8 deletions.
  1. +5 −5 fCraft/Commands/ModerationCommands.cs
  2. +4 −1 fCraft/Player/Player.cs
  3. +1 −1 fCraft/Portals/Portal.cs
  4. +1 −1 fCraft/Zone/SpecialZone.Move.cs
@@ -1413,7 +1413,7 @@ static void UnfreezeHandler(Player player, CommandReader cmd)

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 + (51 + 1));
Position zPos = new Position(P.X * 32 + 16, P.Y * 32 + 16, P.Z * 32 + Player.CharacterHeight);
if (player.World != null) {
player.LastWorld = player.World;
player.LastPosition = player.Position;
@@ -1427,7 +1427,7 @@ 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 - 51) / 32;
int z = (player.Position.Z - Player.CharacterHeight) / 32;
Vector3I P = player.WorldMap.HighestFreeSpace(x, y, z);

if (player.World != null) {
@@ -1437,7 +1437,7 @@ static void UnfreezeHandler(Player player, CommandReader cmd)
player.TeleportTo(new Position {
X = (P.X * 32 + 16),
Y = (P.Y * 32 + 16),
Z = (P.Z * 32 + (51 + 1)),
Z = (P.Z * 32 + Player.CharacterHeight),
R = player.Position.R,
L = player.Position.L
});
@@ -1672,13 +1672,13 @@ 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 - 51) / 32;
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 + (51 + 1)),
Z = (P.Z * 32 + Player.CharacterHeight),
R = player.Position.R,
L = player.Position.L
});
@@ -41,6 +41,9 @@ public sealed partial class Player : IClassy {
/// Note that Player.Console.World is always null,
/// and that prevents console from calling certain commands (like /TP). </summary>
public static Player Console, AutoRank;

/// <summary> Height of in-game player model, necessary as Position works in head position. </summary>
public const byte CharacterHeight = 51;


#region Properties
@@ -267,7 +270,7 @@ public FontFamily LoadFontFamily(string fileName)
bb = new BoundingBox(Vector3I.Zero, Vector3I.Zero);
bb.XMin = Position.X - 6; bb.XMax = Position.X + 6;
bb.YMin = Position.Y - 6; bb.YMax = Position.Y + 6;
bb.ZMin = Position.Z - 51; bb.ZMax = Position.Z;
bb.ZMin = Position.Z - CharacterHeight; bb.ZMax = Position.Z;
return bb;
}
}
@@ -50,7 +50,7 @@ public class Portal {
return new Position(TeleportPosX, TeleportPosY, TeleportPosZ, TeleportPosR, TeleportPosL);
}
public Position tpPosition() {
return new Position(TeleportPosX, TeleportPosY, TeleportPosZ + 64, TeleportPosR, TeleportPosL);
return new Position(TeleportPosX, TeleportPosY, TeleportPosZ + Player.CharacterHeight, TeleportPosR, TeleportPosL);
}

public bool IsInRange(Player player) {
@@ -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 + 64);
Position centre = new Position(zone.Bounds.XCentre * 32 + 16, zone.Bounds.YCentre * 32 + 16, zone.Bounds.ZCentre * 32 + Player.CharacterHeight);
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 29cf24e

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