Skip to content

Commit 29cf24e

Browse files
Use named magic constant instead of hardcoding 51/64 everywhere.
1 parent 8541f96 commit 29cf24e

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

fCraft/Commands/ModerationCommands.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ private static void TeleportHandler(Player player, CommandReader cmd) {
14131413

14141414
Vector3I P = player.World.map.HighestFreeSpace(zone.Bounds.XCentre,
14151415
zone.Bounds.YCentre, zone.Bounds.ZCentre);
1416-
Position zPos = new Position(P.X * 32 + 16, P.Y * 32 + 16, P.Z * 32 + (51 + 1));
1416+
Position zPos = new Position(P.X * 32 + 16, P.Y * 32 + 16, P.Z * 32 + Player.CharacterHeight);
14171417
if (player.World != null) {
14181418
player.LastWorld = player.World;
14191419
player.LastPosition = player.Position;
@@ -1427,7 +1427,7 @@ private static void TeleportHandler(Player player, CommandReader cmd) {
14271427
Random rand = new Random();
14281428
int x = rand.Next(0, player.WorldMap.Width);
14291429
int y = rand.Next(0, player.WorldMap.Length);
1430-
int z = (player.Position.Z - 51) / 32;
1430+
int z = (player.Position.Z - Player.CharacterHeight) / 32;
14311431
Vector3I P = player.WorldMap.HighestFreeSpace(x, y, z);
14321432

14331433
if (player.World != null) {
@@ -1437,7 +1437,7 @@ private static void TeleportHandler(Player player, CommandReader cmd) {
14371437
player.TeleportTo(new Position {
14381438
X = (P.X * 32 + 16),
14391439
Y = (P.Y * 32 + 16),
1440-
Z = (P.Z * 32 + (51 + 1)),
1440+
Z = (P.Z * 32 + Player.CharacterHeight),
14411441
R = player.Position.R,
14421442
L = player.Position.L
14431443
});
@@ -1672,13 +1672,13 @@ static void TeleportPHandler(Player player, CommandReader cmd) {
16721672
static void TopHandler(Player player, CommandReader cmd) {
16731673
int x = player.Position.BlockX;
16741674
int y = player.Position.BlockY;
1675-
int z = (player.Position.Z - 51) / 32;
1675+
int z = (player.Position.Z - Player.CharacterHeight) / 32;
16761676
Vector3I P = player.World.map.HighestFreeSpace(x, y, z);
16771677

16781678
player.TeleportTo(new Position {
16791679
X = (P.X * 32 + 16),
16801680
Y = (P.Y * 32 + 16),
1681-
Z = (P.Z * 32 + (51 + 1)),
1681+
Z = (P.Z * 32 + Player.CharacterHeight),
16821682
R = player.Position.R,
16831683
L = player.Position.L
16841684
});

fCraft/Player/Player.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public sealed partial class Player : IClassy {
4141
/// Note that Player.Console.World is always null,
4242
/// and that prevents console from calling certain commands (like /TP). </summary>
4343
public static Player Console, AutoRank;
44+
45+
/// <summary> Height of in-game player model, necessary as Position works in head position. </summary>
46+
public const byte CharacterHeight = 51;
4447

4548

4649
#region Properties
@@ -267,7 +270,7 @@ public BoundingBox Bounds {
267270
bb = new BoundingBox(Vector3I.Zero, Vector3I.Zero);
268271
bb.XMin = Position.X - 6; bb.XMax = Position.X + 6;
269272
bb.YMin = Position.Y - 6; bb.YMax = Position.Y + 6;
270-
bb.ZMin = Position.Z - 51; bb.ZMax = Position.Z;
273+
bb.ZMin = Position.Z - CharacterHeight; bb.ZMax = Position.Z;
271274
return bb;
272275
}
273276
}

fCraft/Portals/Portal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Position position() {
5050
return new Position(TeleportPosX, TeleportPosY, TeleportPosZ, TeleportPosR, TeleportPosL);
5151
}
5252
public Position tpPosition() {
53-
return new Position(TeleportPosX, TeleportPosY, TeleportPosZ + 64, TeleportPosR, TeleportPosL);
53+
return new Position(TeleportPosX, TeleportPosY, TeleportPosZ + Player.CharacterHeight, TeleportPosR, TeleportPosL);
5454
}
5555

5656
public bool IsInRange(Player player) {

fCraft/Zone/SpecialZone.Move.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static bool HandleRespawn(Player p, Zone zone, ref bool deniedZone, Position new
6666
}
6767

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

0 commit comments

Comments
 (0)