Skip to content

Commit

Permalink
Add door validation for click to open and fix character taking a step…
Browse files Browse the repository at this point in the history
… when clicking an unwalkable tile.
  • Loading branch information
ethanmoffat committed Sep 16, 2022
1 parent 3dcda22 commit bf737a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
14 changes: 12 additions & 2 deletions EndlessClient/Controllers/MapInteractionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.Factories;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
using EOLib.Domain.Interact;
using EOLib.Domain.Item;
using EOLib.Domain.Map;
Expand All @@ -33,6 +34,7 @@ public class MapInteractionController : IMapInteractionController
private readonly ICharacterActions _characterActions;
private readonly IInGameDialogActions _inGameDialogActions;
private readonly IPaperdollActions _paperdollActions;
private readonly IWalkValidationActions _walkValidationActions;
private readonly IUnwalkableTileActions _unwalkableTileActions;
private readonly ICharacterAnimationActions _characterAnimationActions;
private readonly ISpellCastValidationActions _spellCastValidationActions;
Expand All @@ -54,6 +56,7 @@ public MapInteractionController(IMapActions mapActions,
ICharacterActions characterActions,
IInGameDialogActions inGameDialogActions,
IPaperdollActions paperdollActions,
IWalkValidationActions walkValidationActions,
IUnwalkableTileActions unwalkableTileActions,
ICharacterAnimationActions characterAnimationActions,
ISpellCastValidationActions spellCastValidationActions,
Expand All @@ -75,6 +78,7 @@ public MapInteractionController(IMapActions mapActions,
_characterActions = characterActions;
_inGameDialogActions = inGameDialogActions;
_paperdollActions = paperdollActions;
_walkValidationActions = walkValidationActions;
_unwalkableTileActions = unwalkableTileActions;
_characterAnimationActions = characterAnimationActions;
_spellCastValidationActions = spellCastValidationActions;
Expand Down Expand Up @@ -153,7 +157,9 @@ public void LeftClick(IMapCellState cellState, Option<IMouseCursorRenderer> mous
}
}
}
else if (cellState.InBounds && !cellState.Character.HasValue && !cellState.NPC.HasValue)
else if (cellState.InBounds && !cellState.Character.HasValue && !cellState.NPC.HasValue
&& _walkValidationActions.IsCellStateWalkable(cellState)
&& _characterProvider.MainCharacter.RenderProperties.IsActing(CharacterActionState.Standing))
{
mouseRenderer.MatchSome(r => r.AnimateClick());
_hudControlProvider.GetComponent<ICharacterAnimator>(HudControlIdentifier.CharacterAnimator)
Expand All @@ -167,7 +173,11 @@ public void LeftClick(IMapCellState cellState, Option<IMouseCursorRenderer> mous
w.SomeWhen(d => d.DoorType != DoorSpec.NoDoor)
.MatchSome(d =>
{
_mapActions.OpenDoor(d);
if (_unwalkableTileActions.HandleUnwalkableTile(cellState).Any(x => x == UnwalkableTileAction.Door))
{
_mapActions.OpenDoor(d);
}

_userInputRepository.ClickHandled = true;
});
});
Expand Down
49 changes: 30 additions & 19 deletions EndlessClient/Rendering/Character/CharacterAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,32 +101,43 @@ public void MainCharacterFace(EODirection direction)
public void StartMainCharacterWalkAnimation(Option<MapCoordinate> targetCoordinate)
{
_walkPath.Clear();
targetCoordinate.MatchSome(tc =>
{
_targetCoordinate = targetCoordinate;

var rp = _characterRepository.MainCharacter.RenderProperties;
var characterCoord = new MapCoordinate(rp.MapX, rp.MapY);
targetCoordinate.Match(
some: tc =>
{
_targetCoordinate = targetCoordinate;

_walkPath = _pathFinder.FindPath(characterCoord, tc);
var rp = _characterRepository.MainCharacter.RenderProperties;
var characterCoord = new MapCoordinate(rp.MapX, rp.MapY);

if (!_otherPlayerStartWalkingTimes.ContainsKey(_characterRepository.MainCharacter.ID) && _walkPath.Any())
{
rp = FaceTarget(characterCoord, _walkPath.Peek(), rp);
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithRenderProperties(rp);
}
});
_walkPath = _pathFinder.FindPath(characterCoord, tc);

if (_otherPlayerStartWalkingTimes.ContainsKey(_characterRepository.MainCharacter.ID))
if (_walkPath.Any())
{
if (!_otherPlayerStartWalkingTimes.ContainsKey(_characterRepository.MainCharacter.ID))
{
rp = FaceTarget(characterCoord, _walkPath.Peek(), rp);
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithRenderProperties(rp);
}

doTheWalk();
}
},
none: doTheWalk);

void doTheWalk()
{
_otherPlayerStartWalkingTimes[_characterRepository.MainCharacter.ID].Replay = true;
return;
}
if (_otherPlayerStartWalkingTimes.ContainsKey(_characterRepository.MainCharacter.ID))
{
_otherPlayerStartWalkingTimes[_characterRepository.MainCharacter.ID].Replay = true;
return;
}

var startWalkingTime = new RenderFrameActionTime(_characterRepository.MainCharacter.ID);
_otherPlayerStartWalkingTimes.Add(_characterRepository.MainCharacter.ID, startWalkingTime);
var startWalkingTime = new RenderFrameActionTime(_characterRepository.MainCharacter.ID);
_otherPlayerStartWalkingTimes.Add(_characterRepository.MainCharacter.ID, startWalkingTime);

_characterActions.Walk();
_characterActions.Walk();
}
}

public void StartMainCharacterAttackAnimation()
Expand Down

0 comments on commit bf737a2

Please sign in to comment.