Skip to content

Commit

Permalink
Update UnwalkableTileActions to return a list of actions.
Browse files Browse the repository at this point in the history
Fixes issue where tiles with both a tilespec and a door were ignoring the tilespec action.
  • Loading branch information
ethanmoffat committed Sep 8, 2022
1 parent 4acf7af commit 0b7730d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
28 changes: 16 additions & 12 deletions EndlessClient/Controllers/ArrowKeyController.cs
Expand Up @@ -109,19 +109,23 @@ private void AttemptToStartWalking()
{
if (!_walkValidationActions.CanMoveToDestinationCoordinates())
{
var (unwalkableAction, cellState) = _unwalkableTileActions.HandleUnwalkableTile();
switch (unwalkableAction)
var (unwalkableActions, cellState) = _unwalkableTileActions.HandleUnwalkableTile();

foreach (var action in unwalkableActions)
{
case UnwalkableTileAction.Chest:
_mapActions.OpenChest((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowChestDialog();
break;
case UnwalkableTileAction.Locker:
_mapActions.OpenLocker((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowLockerDialog();
break;
case UnwalkableTileAction.Chair: _characterActions.SitInChair(); break;
case UnwalkableTileAction.Door: cellState.Warp.MatchSome(w => _mapActions.OpenDoor(w)); break;
switch (action)
{
case UnwalkableTileAction.Chest:
_mapActions.OpenChest((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowChestDialog();
break;
case UnwalkableTileAction.Locker:
_mapActions.OpenLocker((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowLockerDialog();
break;
case UnwalkableTileAction.Chair: _characterActions.SitInChair(); break;
case UnwalkableTileAction.Door: cellState.Warp.MatchSome(w => _mapActions.OpenDoor(w)); break;
}
}
}
else
Expand Down
41 changes: 22 additions & 19 deletions EndlessClient/Controllers/MapInteractionController.cs
Expand Up @@ -125,29 +125,32 @@ public void LeftClick(IMapCellState cellState, Option<IMouseCursorRenderer> mous
}
else if (InteractableTileSpec(cellState.TileSpec) && CharacterIsCloseEnough(cellState.Coordinate))
{
var unwalkableAction = _unwalkableTileActions.HandleUnwalkableTile(cellState);
var unwalkableActions = _unwalkableTileActions.HandleUnwalkableTile(cellState);

switch (cellState.TileSpec)
foreach (var unwalkableAction in unwalkableActions)
{
// todo: implement for other clickable tile specs (board, jukebox, etc)
case TileSpec.Chest:
if (unwalkableAction == UnwalkableTileAction.Chest)
{
_mapActions.OpenChest((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowChestDialog();
switch (cellState.TileSpec)
{
// todo: implement for other clickable tile specs (board, jukebox, etc)
case TileSpec.Chest:
if (unwalkableAction == UnwalkableTileAction.Chest)
{
_mapActions.OpenChest((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowChestDialog();

_userInputRepository.ClickHandled = true;
}
break;
case TileSpec.BankVault:
if (unwalkableAction == UnwalkableTileAction.Locker)
{
_mapActions.OpenLocker((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowLockerDialog();
_userInputRepository.ClickHandled = true;
}
break;
case TileSpec.BankVault:
if (unwalkableAction == UnwalkableTileAction.Locker)
{
_mapActions.OpenLocker((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowLockerDialog();

_userInputRepository.ClickHandled = true;
}
break;
_userInputRepository.ClickHandled = true;
}
break;
}
}
}
else if (cellState.InBounds && !cellState.Character.HasValue && !cellState.NPC.HasValue)
Expand Down
21 changes: 11 additions & 10 deletions EndlessClient/Input/UnwalkableTileActions.cs
Expand Up @@ -6,6 +6,7 @@
using EOLib.Domain.Map;
using EOLib.IO.Map;
using EOLib.Localization;
using System.Collections.Generic;

namespace EndlessClient.Input
{
Expand Down Expand Up @@ -49,30 +50,30 @@ public class UnwalkableTileActions : IUnwalkableTileActions
_messageBoxFactory = messageBoxFactory;
}

public (UnwalkableTileAction, IMapCellState) HandleUnwalkableTile()
public (IReadOnlyList<UnwalkableTileAction>, IMapCellState) HandleUnwalkableTile()
{
var destX = MainCharacter.RenderProperties.GetDestinationX();
var destY = MainCharacter.RenderProperties.GetDestinationY();
return HandleUnwalkableTile(destX, destY);
}

public (UnwalkableTileAction, IMapCellState) HandleUnwalkableTile(int x, int y)
public (IReadOnlyList<UnwalkableTileAction>, IMapCellState) HandleUnwalkableTile(int x, int y)
{
var cellState = _mapCellStateProvider.GetCellStateAt(x, y);
var action = HandleUnwalkableTile(cellState);
return (action, cellState);
}

public UnwalkableTileAction HandleUnwalkableTile(IMapCellState cellState)
public IReadOnlyList<UnwalkableTileAction> HandleUnwalkableTile(IMapCellState cellState)
{
if (MainCharacter.RenderProperties.SitState != SitState.Standing)
return UnwalkableTileAction.None;
return new[] { UnwalkableTileAction.None };

return cellState.Character.Match(
some: c => HandleWalkThroughOtherCharacter(c), //todo: walk through players after certain elapsed time (3-5sec?)
some: c => new[] { HandleWalkThroughOtherCharacter(c) }, //todo: walk through players after certain elapsed time (3-5sec?)
none: () => cellState.Warp.Match(
some: w => HandleWalkToWarpTile(w),
none: () => HandleWalkToTileSpec(cellState)));
some: w => new[] { HandleWalkToWarpTile(w), HandleWalkToTileSpec(cellState) },
none: () => new[] { HandleWalkToTileSpec(cellState) }));
}

private UnwalkableTileAction HandleWalkThroughOtherCharacter(Character c)
Expand Down Expand Up @@ -176,10 +177,10 @@ private UnwalkableTileAction HandleWalkToTileSpec(IMapCellState cellState)

public interface IUnwalkableTileActions
{
(UnwalkableTileAction, IMapCellState) HandleUnwalkableTile();
(IReadOnlyList<UnwalkableTileAction>, IMapCellState) HandleUnwalkableTile();

(UnwalkableTileAction, IMapCellState) HandleUnwalkableTile(int x, int y);
(IReadOnlyList<UnwalkableTileAction>, IMapCellState) HandleUnwalkableTile(int x, int y);

UnwalkableTileAction HandleUnwalkableTile(IMapCellState mapCellState);
IReadOnlyList<UnwalkableTileAction> HandleUnwalkableTile(IMapCellState mapCellState);
}
}

0 comments on commit 0b7730d

Please sign in to comment.