Skip to content

Commit

Permalink
Merge pull request #175 from ethanmoffat/fix_chest_key_check
Browse files Browse the repository at this point in the history
Fix chest key validation and key name display in status bar
  • Loading branch information
ethanmoffat authored Apr 10, 2022
2 parents 808a435 + 36ce0af commit a707282
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
20 changes: 14 additions & 6 deletions EndlessClient/Controllers/MapInteractionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class MapInteractionController : IMapInteractionController
private readonly ICharacterActions _characterActions;
private readonly IInGameDialogActions _inGameDialogActions;
private readonly IPaperdollActions _paperdollActions;
private readonly IUnwalkableTileActions _unwalkableTileActions;
private readonly ICurrentMapStateProvider _currentMapStateProvider;
private readonly ICharacterProvider _characterProvider;
private readonly IStatusLabelSetter _statusLabelSetter;
Expand All @@ -37,13 +38,14 @@ public class MapInteractionController : IMapInteractionController
private readonly ICharacterRendererProvider _characterRendererProvider;
private readonly IContextMenuRepository _contextMenuRepository;
private readonly IUserInputTimeRepository _userInputTimeRepository;
private readonly IEOMessageBoxFactory _eoMessageBoxFactory;
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly IContextMenuRendererFactory _contextMenuRendererFactory;

public MapInteractionController(IMapActions mapActions,
ICharacterActions characterActions,
IInGameDialogActions inGameDialogActions,
IPaperdollActions paperdollActions,
IUnwalkableTileActions unwalkableTileActions,
ICurrentMapStateProvider currentMapStateProvider,
ICharacterProvider characterProvider,
IStatusLabelSetter statusLabelSetter,
Expand All @@ -52,13 +54,14 @@ public MapInteractionController(IMapActions mapActions,
ICharacterRendererProvider characterRendererProvider,
IContextMenuRepository contextMenuRepository,
IUserInputTimeRepository userInputTimeRepository,
IEOMessageBoxFactory eoMessageBoxFactory,
IEOMessageBoxFactory messageBoxFactory,
IContextMenuRendererFactory contextMenuRendererFactory)
{
_mapActions = mapActions;
_characterActions = characterActions;
_inGameDialogActions = inGameDialogActions;
_paperdollActions = paperdollActions;
_unwalkableTileActions = unwalkableTileActions;
_currentMapStateProvider = currentMapStateProvider;
_characterProvider = characterProvider;
_statusLabelSetter = statusLabelSetter;
Expand All @@ -67,7 +70,7 @@ public MapInteractionController(IMapActions mapActions,
_characterRendererProvider = characterRendererProvider;
_contextMenuRepository = contextMenuRepository;
_userInputTimeRepository = userInputTimeRepository;
_eoMessageBoxFactory = eoMessageBoxFactory;
_messageBoxFactory = messageBoxFactory;
_contextMenuRendererFactory = contextMenuRendererFactory;
}

Expand All @@ -90,7 +93,7 @@ public void LeftClick(IMapCellState cellState, IMouseCursorRenderer mouseRendere
else if (cellState.Sign.HasValue)
{
var sign = cellState.Sign.ValueOr(Sign.None);
var messageBox = _eoMessageBoxFactory.CreateMessageBox(sign.Message, sign.Title);
var messageBox = _messageBoxFactory.CreateMessageBox(sign.Message, sign.Title);
messageBox.ShowDialog();
}
else if (_characterProvider.MainCharacter.RenderProperties.SitState != SitState.Standing)
Expand All @@ -99,12 +102,17 @@ public void LeftClick(IMapCellState cellState, IMouseCursorRenderer mouseRendere
}
else if (InteractableTileSpec(cellState.TileSpec) && CharacterIsCloseEnough(cellState.Coordinate))
{
var unwalkableAction = _unwalkableTileActions.HandleUnwalkableTile(cellState);

switch (cellState.TileSpec)
{
// todo: implement for other clickable tile specs (locker, jukebox, etc)
case TileSpec.Chest:
_mapActions.OpenChest((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowChestDialog();
if (unwalkableAction == UnwalkableTileAction.Chest)
{
_mapActions.OpenChest((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowChestDialog();
}
break;
}
}
Expand Down
27 changes: 20 additions & 7 deletions EndlessClient/Input/UnwalkableTileActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,28 @@ public UnwalkableTileActions(IMapCellStateProvider mapCellStateProvider,

public (UnwalkableTileAction, IMapCellState) HandleUnwalkableTile()
{
if (MainCharacter.RenderProperties.SitState != SitState.Standing)
return (UnwalkableTileAction.None, new MapCellState());

var destX = MainCharacter.RenderProperties.GetDestinationX();
var destY = MainCharacter.RenderProperties.GetDestinationY();
return HandleUnwalkableTile(destX, destY);
}

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

var cellState = _mapCellStateProvider.GetCellStateAt(destX, destY);
var action = cellState.Character.Match(
public UnwalkableTileAction HandleUnwalkableTile(IMapCellState cellState)
{
if (MainCharacter.RenderProperties.SitState != SitState.Standing)
return UnwalkableTileAction.None;

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

private UnwalkableTileAction HandleWalkThroughOtherCharacter(ICharacter c)
Expand Down Expand Up @@ -131,7 +140,7 @@ private UnwalkableTileAction HandleWalkToTileSpec(IMapCellState cellState)
dlg.ShowDialog();

var requiredKey = _unlockChestValidator.GetRequiredKeyName(key);
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_THE_CHEST_IS_LOCKED_EXCLAMATION, " - " + requiredKey);
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_THE_CHEST_IS_LOCKED_EXCLAMATION, requiredKey.Match(x => $" - {x}", () => string.Empty));
return UnwalkableTileAction.None;
}
else
Expand Down Expand Up @@ -172,5 +181,9 @@ private UnwalkableTileAction HandleWalkToTileSpec(IMapCellState cellState)
public interface IUnwalkableTileActions
{
(UnwalkableTileAction, IMapCellState) HandleUnwalkableTile();

(UnwalkableTileAction, IMapCellState) HandleUnwalkableTile(int x, int y);

UnwalkableTileAction HandleUnwalkableTile(IMapCellState mapCellState);
}
}

0 comments on commit a707282

Please sign in to comment.