Skip to content

Commit 37b6d0d

Browse files
committed
instance readonly for MapWidth/MapHeight/TileWidth/TileHeight
1 parent 0b90a2b commit 37b6d0d

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Intersect.Client.Entities;
2+
3+
public partial class Entity
4+
{
5+
protected readonly int MapWidth = Options.Instance.Map.MapWidth;
6+
protected readonly int MapHeight = Options.Instance.Map.MapHeight;
7+
protected readonly int TileWidth = Options.Instance.Map.TileWidth;
8+
protected readonly int TileHeight = Options.Instance.Map.TileHeight;
9+
}

Intersect.Client.Core/Entities/Entity.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ public Vector3 Position
246246

247247
protected virtual void OnPositionChanged(Vector3 newPosition, Vector3 oldPosition) {}
248248

249+
public int TileX => (int)float.Floor(Position.X);
250+
public int TileY => (int)float.Floor(Position.Y);
251+
public int TileZ => (int)float.Floor(Position.Z);
252+
249253
//Location Info
250254
public byte X
251255
{
@@ -265,9 +269,6 @@ public byte Z
265269
set => Position = Position with { Z = value };
266270
}
267271

268-
protected readonly int TileWidth = Options.Instance.Map.TileWidth;
269-
protected readonly int TileHeight = Options.Instance.Map.TileHeight;
270-
271272
public float OffsetX { get; set; }
272273
// {
273274
// get => (Position.X % 1) * TileWidth;
@@ -701,7 +702,7 @@ public virtual bool Update()
701702
}
702703
else if (IsMoving)
703704
{
704-
var displacementTime = ecTime * Options.Instance.Map.TileHeight / GetMovementTime();
705+
var displacementTime = ecTime * TileHeight / GetMovementTime();
705706

706707
PickLastDirection(Dir);
707708

@@ -1132,18 +1133,18 @@ public virtual bool ShouldDrawName
11321133

11331134
if (y == gridY - 1)
11341135
{
1135-
entityY = Options.Instance.Map.MapHeight + Y;
1136+
entityY = MapHeight + Y;
11361137
}
11371138
else if (y == gridY)
11381139
{
1139-
entityY = Options.Instance.Map.MapHeight * 2 + Y;
1140+
entityY = MapHeight * 2 + Y;
11401141
}
11411142
else
11421143
{
1143-
entityY = Options.Instance.Map.MapHeight * 3 + Y;
1144+
entityY = MapHeight * 3 + Y;
11441145
}
11451146

1146-
entityY = (int)Math.Floor(entityY + OffsetY / Options.Instance.Map.TileHeight);
1147+
entityY = (int)Math.Floor(entityY + OffsetY / TileHeight);
11471148

11481149
var renderingEntities = Graphics.RenderingEntities;
11491150
if (priority >= renderingEntities.GetLength(0) || entityY >= renderingEntities.GetLength(1))
@@ -1227,10 +1228,10 @@ public virtual void Draw()
12271228
{
12281229
// We don't have a texture to render, but we still want this to be targetable.
12291230
WorldPos = new FloatRect(
1230-
map.X + X * Options.Instance.Map.TileWidth + OffsetX,
1231-
map.Y + Y * Options.Instance.Map.TileHeight + OffsetY,
1232-
Options.Instance.Map.TileWidth,
1233-
Options.Instance.Map.TileHeight);
1231+
map.X + X * TileWidth + OffsetX,
1232+
map.Y + Y * TileHeight + OffsetY,
1233+
TileWidth,
1234+
TileHeight);
12341235
return;
12351236
}
12361237

@@ -1519,8 +1520,8 @@ protected virtual void CalculateOrigin()
15191520
}
15201521

15211522
mOrigin = new Vector2(
1522-
LatestMap.X + X * Options.Instance.Map.TileWidth + OffsetX + Options.Instance.Map.TileWidth / 2,
1523-
LatestMap.Y + Y * Options.Instance.Map.TileHeight + OffsetY + Options.Instance.Map.TileHeight
1523+
LatestMap.X + X * TileWidth + OffsetX + TileWidth / 2,
1524+
LatestMap.Y + Y * TileHeight + OffsetY + TileHeight
15241525
);
15251526
}
15261527

@@ -2327,10 +2328,10 @@ public Direction DirectionToTarget(Entity en)
23272328
return Dir;
23282329
}
23292330

2330-
var originY = Y + originMapController.GridY * Options.Instance.Map.MapHeight;
2331-
var originX = X + originMapController.GridX * Options.Instance.Map.MapWidth;
2332-
var targetY = en.Y + targetMapController.GridY * Options.Instance.Map.MapHeight;
2333-
var targetX = en.X + targetMapController.GridX * Options.Instance.Map.MapWidth;
2331+
var originY = Y + originMapController.GridY * MapHeight;
2332+
var originX = X + originMapController.GridX * MapWidth;
2333+
var targetY = en.Y + targetMapController.GridY * MapHeight;
2334+
var targetX = en.X + targetMapController.GridX * MapWidth;
23342335

23352336
// Calculate the offset between origin and target along both of their axis.
23362337
var yDiff = originY - targetY;
@@ -2398,25 +2399,25 @@ public int IsTileBlocked(
23982399
if (delta.X < 0)
23992400
{
24002401
gridX--;
2401-
tmpX = Options.Instance.Map.MapWidth - delta.X * -1;
2402+
tmpX = MapWidth - delta.X * -1;
24022403
}
24032404

24042405
if (delta.Y < 0)
24052406
{
24062407
gridY--;
2407-
tmpY = Options.Instance.Map.MapHeight - delta.Y * -1;
2408+
tmpY = MapHeight - delta.Y * -1;
24082409
}
24092410

2410-
if (delta.X > Options.Instance.Map.MapWidth - 1)
2411+
if (delta.X > MapWidth - 1)
24112412
{
24122413
gridX++;
2413-
tmpX = delta.X - Options.Instance.Map.MapWidth;
2414+
tmpX = delta.X - MapWidth;
24142415
}
24152416

2416-
if (delta.Y > Options.Instance.Map.MapHeight - 1)
2417+
if (delta.Y > MapHeight - 1)
24172418
{
24182419
gridY++;
2419-
tmpY = delta.Y - Options.Instance.Map.MapHeight;
2420+
tmpY = delta.Y - MapHeight;
24202421
}
24212422

24222423
if (Globals.MapGrid == default || gridX < 0 || gridY < 0 || gridX >= Globals.MapGridWidth || gridY >= Globals.MapGridHeight)

0 commit comments

Comments
 (0)