Skip to content

Commit

Permalink
Fixes for Walk and IsWalkable
Browse files Browse the repository at this point in the history
- re-added IsWalkable check to creature.Walk
- added an optional option for Walk to ignoreBlockingReactors, where the default is the current behavior (only aislings can walk on blocking reactors)
  • Loading branch information
Sichii committed May 1, 2024
1 parent fd02817 commit e16adf0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
31 changes: 24 additions & 7 deletions Chaos/Collections/MapInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,19 +611,36 @@ public bool IsReactor(IPoint point)
=> Objects.AtPoint<ReactorTile>(point)
.Any();

public bool IsWalkable(IPoint point, CreatureType creatureType)
/// <summary>
/// Determines if a point is walkable
/// </summary>
/// <param name="point">
/// The point to check
/// </param>
/// <param name="creatureType">
/// The type of the creature
/// </param>
/// <param name="ignoreBlockingReactors">
/// Whether to ignore blocking reactors. Default behavior ignores blocking reactors only for Aislings
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// </exception>
public bool IsWalkable(IPoint point, CreatureType creatureType, bool? ignoreBlockingReactors = null)
{
ignoreBlockingReactors ??= creatureType == CreatureType.Aisling;

var creatures = Objects.AtPoint<Creature>(point)
.ToList();

if (!ignoreBlockingReactors.Value && IsBlockingReactor(point))
return false;

return creatureType switch
{
CreatureType.Normal => !IsBlockingReactor(point) && !IsWall(point) && !creatures.Any(c => creatureType.WillCollideWith(c)),
CreatureType.WalkThrough => !IsBlockingReactor(point)
&& IsWithinMap(point)
&& !creatures.Any(c => creatureType.WillCollideWith(c)),
CreatureType.Merchant => !IsBlockingReactor(point) && !IsWall(point) && !creatures.Any(c => creatureType.WillCollideWith(c)),
CreatureType.WhiteSquare => !IsBlockingReactor(point) && !IsWall(point) && !creatures.Any(c => creatureType.WillCollideWith(c)),
CreatureType.Normal => !IsWall(point) && !creatures.Any(c => creatureType.WillCollideWith(c)),
CreatureType.WalkThrough => IsWithinMap(point) && !creatures.Any(c => creatureType.WillCollideWith(c)),
CreatureType.Merchant => !IsWall(point) && !creatures.Any(c => creatureType.WillCollideWith(c)),
CreatureType.WhiteSquare => !IsWall(point) && !creatures.Any(c => creatureType.WillCollideWith(c)),
CreatureType.Aisling => !IsWall(point) && !creatures.Any(c => creatureType.WillCollideWith(c)),
_ => throw new ArgumentOutOfRangeException(nameof(creatureType), creatureType, null)
};
Expand Down
7 changes: 6 additions & 1 deletion Chaos/Models/World/Abstractions/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,10 @@ public virtual void Turn(Direction direction)
Trackers.LastTurn = DateTime.UtcNow;
}

public virtual void Walk(Direction direction)
public virtual void Walk(Direction direction, bool? ignoreBlockingReactors = null)
{
ignoreBlockingReactors ??= Type == CreatureType.Aisling;

if (!Script.CanMove())
return;

Expand All @@ -584,6 +586,9 @@ public virtual void Walk(Direction direction)
var startPoint = Point.From(this);
var endPoint = ((IPoint)this).DirectionalOffset(direction);

if (!MapInstance.IsWalkable(endPoint, Type, ignoreBlockingReactors))
return;

var visibleBefore = MapInstance.GetEntitiesWithinRange<Creature>(this)
.ToList();

Expand Down
6 changes: 4 additions & 2 deletions Chaos/Models/World/Aisling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,10 @@ public override void Update(TimeSpan delta)
base.Update(delta);
}

public override void Walk(Direction direction)
public override void Walk(Direction direction, bool? ignoreBlockingReactors = null)
{
ignoreBlockingReactors ??= true;

if (!Script.CanMove() || ((direction != Direction) && !Script.CanTurn()) || !ShouldWalk)
{
Refresh(true);
Expand All @@ -1077,7 +1079,7 @@ public override void Walk(Direction direction)
}

//otherwise, check if the point is walkable
else if (!MapInstance.IsWalkable(endPoint, Type))
else if (!MapInstance.IsWalkable(endPoint, Type, ignoreBlockingReactors))
{
Refresh(true);

Expand Down

0 comments on commit e16adf0

Please sign in to comment.