@@ -1442,23 +1442,39 @@ public void HotbarSwap(int index, int swapIndex)
14421442 // Change the dimension if the player is on a gateway
14431443 private void TryToChangeDimension ( )
14441444 {
1445- if ( X < Options . Instance . Map . MapWidth && X >= 0 )
1445+ var tileX = TileX ;
1446+ if ( tileX >= MapWidth || tileX < 0 )
14461447 {
1447- if ( Y < Options . Instance . Map . MapHeight && Y >= 0 )
1448- {
1449- if ( Maps . MapInstance . Get ( MapId ) != null && Maps . MapInstance . Get ( MapId ) . Attributes [ X , Y ] != null )
1450- {
1451- if ( Maps . MapInstance . Get ( MapId ) . Attributes [ X , Y ] . Type == MapAttributeType . ZDimension )
1452- {
1453- if ( ( ( MapZDimensionAttribute ) Maps . MapInstance . Get ( MapId ) . Attributes [ X , Y ] ) . GatewayTo > 0 )
1454- {
1455- Z = ( byte ) ( ( ( MapZDimensionAttribute ) Maps . MapInstance . Get ( MapId ) . Attributes [ X , Y ] )
1456- . GatewayTo -
1457- 1 ) ;
1458- }
1459- }
1460- }
1461- }
1448+ return ;
1449+ }
1450+
1451+ var tileY = TileY ;
1452+ if ( tileY >= MapHeight || tileY < 0 )
1453+ {
1454+ return ;
1455+ }
1456+
1457+ if ( ! Maps . MapInstance . TryGet ( MapId , out var mapInstance ) )
1458+ {
1459+ return ;
1460+ }
1461+
1462+ var mapAttribute = mapInstance . Attributes [ tileX , tileY ] ;
1463+ if ( mapAttribute is not MapZDimensionAttribute { Type : MapAttributeType . ZDimension } zAttribute )
1464+ {
1465+ return ;
1466+ }
1467+
1468+ var gatewayZ = zAttribute . GatewayTo - 1 ;
1469+ if ( gatewayZ < 0 )
1470+ {
1471+ return ;
1472+ }
1473+
1474+ var tileZ = TileZ ;
1475+ if ( tileZ != gatewayZ )
1476+ {
1477+ Position = Position with { Z = zAttribute . GatewayTo - 1 } ;
14621478 }
14631479 }
14641480
@@ -1619,12 +1635,12 @@ protected int GetDistanceTo(IEntity target)
16191635 if ( myMap != null && targetMap != null )
16201636 {
16211637 //Calculate World Tile of Me
1622- var x1 = X + myMap . GridX * Options . Instance . Map . MapWidth ;
1623- var y1 = Y + myMap . GridY * Options . Instance . Map . MapHeight ;
1638+ var x1 = X + myMap . GridX * MapWidth ;
1639+ var y1 = Y + myMap . GridY * MapHeight ;
16241640
16251641 //Calculate world tile of target
1626- var x2 = target . X + targetMap . GridX * Options . Instance . Map . MapWidth ;
1627- var y2 = target . Y + targetMap . GridY * Options . Instance . Map . MapHeight ;
1642+ var x2 = target . X + targetMap . GridX * MapWidth ;
1643+ var y2 = target . Y + targetMap . GridY * MapHeight ;
16281644
16291645 return ( int ) Math . Sqrt ( Math . Pow ( x1 - x2 , 2 ) + Math . Pow ( y1 - y2 , 2 ) ) ;
16301646 }
@@ -2047,25 +2063,25 @@ public bool TryGetRealLocation(ref int x, ref int y, ref Guid mapId)
20472063
20482064 if ( x < 0 )
20492065 {
2050- tmpX = Options . Instance . Map . MapWidth - x * - 1 ;
2066+ tmpX = MapWidth - x * - 1 ;
20512067 gridX -- ;
20522068 }
20532069
20542070 if ( y < 0 )
20552071 {
2056- tmpY = Options . Instance . Map . MapHeight - y * - 1 ;
2072+ tmpY = MapHeight - y * - 1 ;
20572073 gridY -- ;
20582074 }
20592075
2060- if ( y > Options . Instance . Map . MapHeight - 1 )
2076+ if ( y > MapHeight - 1 )
20612077 {
2062- tmpY = y - Options . Instance . Map . MapHeight ;
2078+ tmpY = y - MapHeight ;
20632079 gridY ++ ;
20642080 }
20652081
2066- if ( x > Options . Instance . Map . MapWidth - 1 )
2082+ if ( x > MapWidth - 1 )
20672083 {
2068- tmpX = x - Options . Instance . Map . MapWidth ;
2084+ tmpX = x - MapWidth ;
20692085 gridX ++ ;
20702086 }
20712087
@@ -2106,17 +2122,17 @@ public bool TryTarget()
21062122
21072123 foreach ( MapInstance map in Maps . MapInstance . Lookup . Values . Cast < MapInstance > ( ) )
21082124 {
2109- if ( x >= map . X && x <= map . X + Options . Instance . Map . MapWidth * Options . Instance . Map . TileWidth )
2125+ if ( x >= map . X && x <= map . X + MapWidth * TileWidth )
21102126 {
2111- if ( y >= map . Y && y <= map . Y + Options . Instance . Map . MapHeight * Options . Instance . Map . TileHeight )
2127+ if ( y >= map . Y && y <= map . Y + MapHeight * TileHeight )
21122128 {
21132129 //Remove the offsets to just be dealing with pixels within the map selected
21142130 x -= ( int ) map . X ;
21152131 y -= ( int ) map . Y ;
21162132
21172133 //transform pixel format to tile format
2118- x /= Options . Instance . Map . TileWidth ;
2119- y /= Options . Instance . Map . TileHeight ;
2134+ x /= TileWidth ;
2135+ y /= TileHeight ;
21202136 var mapId = map . Id ;
21212137
21222138 if ( TryGetRealLocation ( ref x , ref y , ref mapId ) )
@@ -2490,7 +2506,7 @@ private void ProcessDirectionalInput()
24902506 }
24912507 else
24922508 {
2493- OffsetX = delta . X > 0 ? - Options . Instance . Map . TileWidth : Options . Instance . Map . TileWidth ;
2509+ OffsetX = delta . X > 0 ? - TileWidth : TileWidth ;
24942510 }
24952511
24962512 if ( delta . Y == 0 )
@@ -2499,7 +2515,7 @@ private void ProcessDirectionalInput()
24992515 }
25002516 else
25012517 {
2502- OffsetY = delta . Y > 0 ? - Options . Instance . Map . TileHeight : Options . Instance . Map . TileHeight ;
2518+ OffsetY = delta . Y > 0 ? - TileHeight : TileHeight ;
25032519 }
25042520
25052521 break ;
@@ -2513,16 +2529,16 @@ private void ProcessDirectionalInput()
25132529
25142530 if ( IsMoving )
25152531 {
2516- if ( position . X < 0 || position . Y < 0 || position . X > Options . Instance . Map . MapWidth - 1 || position . Y > Options . Instance . Map . MapHeight - 1 )
2532+ if ( position . X < 0 || position . Y < 0 || position . X > MapWidth - 1 || position . Y > MapHeight - 1 )
25172533 {
25182534 var gridX = Maps . MapInstance . Get ( Globals . Me . MapId ) . GridX ;
25192535 var gridY = Maps . MapInstance . Get ( Globals . Me . MapId ) . GridY ;
25202536 if ( position . X < 0 )
25212537 {
25222538 gridX -- ;
2523- X = ( byte ) ( Options . Instance . Map . MapWidth - 1 ) ;
2539+ X = ( byte ) ( MapWidth - 1 ) ;
25242540 }
2525- else if ( position . X >= Options . Instance . Map . MapWidth )
2541+ else if ( position . X >= MapWidth )
25262542 {
25272543 X = 0 ;
25282544 gridX ++ ;
@@ -2535,9 +2551,9 @@ private void ProcessDirectionalInput()
25352551 if ( position . Y < 0 )
25362552 {
25372553 gridY -- ;
2538- Y = ( byte ) ( Options . Instance . Map . MapHeight - 1 ) ;
2554+ Y = ( byte ) ( MapHeight - 1 ) ;
25392555 }
2540- else if ( position . Y >= Options . Instance . Map . MapHeight )
2556+ else if ( position . Y >= MapHeight )
25412557 {
25422558 Y = 0 ;
25432559 gridY ++ ;
@@ -2876,10 +2892,10 @@ public void DrawTargets()
28762892 var mouseInWorld = Graphics . ConvertToWorldPoint ( Globals . InputManager . GetMousePosition ( ) ) ;
28772893 foreach ( MapInstance map in Maps . MapInstance . Lookup . Values . Cast < MapInstance > ( ) )
28782894 {
2879- if ( mouseInWorld . X >= map . X && mouseInWorld . X <= map . X + Options . Instance . Map . MapWidth * Options . Instance . Map . TileWidth )
2895+ if ( mouseInWorld . X >= map . X && mouseInWorld . X <= map . X + MapWidth * TileWidth )
28802896 {
28812897 if ( mouseInWorld . Y >= map . Y &&
2882- mouseInWorld . Y <= map . Y + Options . Instance . Map . MapHeight * Options . Instance . Map . TileHeight )
2898+ mouseInWorld . Y <= map . Y + MapHeight * TileHeight )
28832899 {
28842900 var mapId = map . Id ;
28852901
0 commit comments