Skip to content

Commit aa62096

Browse files
authored
feat: block diagonal movement through double-blocks (AscensionGameDev#2111)
1 parent e409073 commit aa62096

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

Intersect (Core)/Config/MapOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public partial class MapOptions
2020
/// </summary>
2121
public bool DisablePlayerDropsInArenaMaps { get; set; } = false;
2222

23+
/// <summary>
24+
/// Controls whether two block attributes placed diagonally block or not.
25+
/// </summary>
26+
public bool EnableCrossingDiagonalBlocks { get; set; }
27+
2328
/// <summary>
2429
/// Indicates whether or not diagonal movement is enabled for entities within the map.
2530
/// </summary>

Intersect (Core)/Logging/Output/FileOutput.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,15 @@ private void InternalWrite(
111111
params object[] args
112112
)
113113
{
114+
string? line = default;
114115
try
115116
{
116117
if (LogLevel < logLevel)
117118
{
118119
return;
119120
}
120121

121-
var line = configuration.Formatter.Format(
122+
line = configuration.Formatter.Format(
122123
configuration,
123124
logLevel,
124125
DateTime.UtcNow,
@@ -133,7 +134,11 @@ params object[] args
133134
}
134135
catch (Exception exceptionWhileWriting)
135136
{
136-
Console.WriteLine(exceptionWhileWriting);
137+
Console.WriteLine(
138+
"Exception occurred while writing to file:\n\t{0}\n\t{1}",
139+
line,
140+
exceptionWhileWriting
141+
);
137142
}
138143
}
139144

Intersect.Client/Entities/Player.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,8 @@ private void ProcessDirectionalInput()
22232223
var dir = Dir;
22242224
var moveDir = MoveDir;
22252225

2226+
var enableCrossingDiagonalBlocks = Options.Instance.MapOpts.EnableCrossingDiagonalBlocks;
2227+
22262228
if (moveDir != Direction.None)
22272229
{
22282230
List<Direction> possibleDirections = new(4) { moveDir };
@@ -2246,6 +2248,16 @@ private void ProcessDirectionalInput()
22462248
continue;
22472249
}
22482250

2251+
if (!enableCrossingDiagonalBlocks && possibleDirection.IsDiagonal())
2252+
{
2253+
if (possibleDirection.GetComponentDirections()
2254+
.Select(componentDirection => componentDirection.GetDeltaPoint() + position)
2255+
.All(componentTarget => IsTileBlocked(componentTarget, Z, MapId, ref blockedBy) != -1))
2256+
{
2257+
continue;
2258+
}
2259+
}
2260+
22492261
position.X += delta.X;
22502262
position.Y += delta.Y;
22512263
IsMoving = true;

Intersect.Server.Core/Entities/Entity.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,14 +456,41 @@ out EntityType entityType
456456
return false;
457457
}
458458

459-
var mapController = MapController.Get(tileHelper.GetMapId());
459+
if (!MapController.TryGet(tileHelper.GetMapId(), out var mapController))
460+
{
461+
blockerType = MovementBlockerType.OutOfBounds;
462+
return false;
463+
}
464+
460465
int tileX = tileHelper.GetX();
461466
int tileY = tileHelper.GetY();
467+
462468
if (IsBlockedByMapAttribute(direction, mapController.Attributes[tileX, tileY], out blockerType))
463469
{
464470
return false;
465471
}
466472

473+
var enableCrossingDiagonalBlocks = Options.Instance.MapOpts.EnableCrossingDiagonalBlocks;
474+
if (!enableCrossingDiagonalBlocks && direction.IsDiagonal())
475+
{
476+
MovementBlockerType componentBlockerType = default;
477+
EntityType componentBlockingEntityType = default;
478+
479+
if (direction.GetComponentDirections()
480+
.All(
481+
componentDirection => !CanMoveInDirection(
482+
componentDirection,
483+
out componentBlockerType,
484+
out componentBlockingEntityType
485+
)
486+
))
487+
{
488+
blockerType = componentBlockerType;
489+
entityType = componentBlockingEntityType;
490+
return false;
491+
}
492+
}
493+
467494
if (Passable)
468495
{
469496
return !TryGetBlockerOnTile(

0 commit comments

Comments
 (0)