Skip to content

Commit

Permalink
Add handling for sit/stand from chairs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Jan 27, 2021
1 parent 33f01f7 commit e5b8084
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
13 changes: 9 additions & 4 deletions EOLib/Domain/Character/CharacterActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ public void Attack()
_packetSendService.SendPacket(packet);
}

public void Sit()
public void ToggleSit()
{
var sitAction = _characterProvider.MainCharacter.RenderProperties.SitState == SitState.Standing
var renderProperties = _characterProvider.MainCharacter.RenderProperties;
var sitAction = renderProperties.SitState == SitState.Standing
? SitAction.Sit
: SitAction.Stand;

var packet = new PacketBuilder(PacketFamily.Sit, PacketAction.Request)
var packetFamily = renderProperties.SitState == SitState.Chair
? PacketFamily.Chair
: PacketFamily.Sit;

var packet = new PacketBuilder(packetFamily, PacketAction.Request)
.AddChar((byte)sitAction)
.Build();

Expand All @@ -76,6 +81,6 @@ public interface ICharacterActions

void Attack();

void Sit();
void ToggleSit();
}
}
6 changes: 4 additions & 2 deletions EOLib/Domain/Character/WalkValidationActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public bool CanMoveToDestinationCoordinates()
if (_currentMapStateProvider.MapWarpState == WarpState.WarpStarted)
return false;

var mainCharacter = _characterProvider.MainCharacter;
var renderProperties = mainCharacter.RenderProperties;
var renderProperties = _characterProvider.MainCharacter.RenderProperties;
var destX = renderProperties.GetDestinationX();
var destY = renderProperties.GetDestinationY();

Expand All @@ -43,6 +42,9 @@ public bool CanMoveToCoordinates(int gridX, int gridY)
{
var mainCharacter = _characterProvider.MainCharacter;

if (mainCharacter.RenderProperties.SitState != SitState.Standing)
return false;

var cellState = _mapCellStateProvider.GetCellStateAt(gridX, gridY);

if (cellState.Character.HasValue) //todo: walk through players after certain elapsed time
Expand Down
11 changes: 11 additions & 0 deletions EOLib/PacketHandlers/PlayerStandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,15 @@ public class MainPlayerStandHandler : PlayerStandHandler
ICurrentMapStateRepository currentMapStateRepository)
: base(playerInfoProvider, characterRepository, currentMapStateRepository) { }
}

[AutoMappedType]
public class MainPlayerStandFromChairHandler : MainPlayerStandHandler
{
public override PacketFamily Family => PacketFamily.Chair;

public MainPlayerStandFromChairHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterRepository characterRepository,
ICurrentMapStateRepository currentMapStateRepository)
: base(playerInfoProvider, characterRepository, currentMapStateRepository) { }
}
}
2 changes: 1 addition & 1 deletion EndlessClient/Controllers/FunctionKeyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FunctionKeyController : IFunctionKeyController

public bool Sit()
{
_characterActions.Sit();
_characterActions.ToggleSit();
return true;
}

Expand Down
13 changes: 13 additions & 0 deletions EndlessClient/Controllers/MapInteractionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using EndlessClient.HUD.Inventory;
using EndlessClient.Input;
using EndlessClient.Rendering;
using EOLib.Domain.Character;
using EOLib.Domain.Item;
using EOLib.Domain.Map;
using EOLib.Extensions;
Expand All @@ -19,21 +20,27 @@ namespace EndlessClient.Controllers
public class MapInteractionController : IMapInteractionController
{
private readonly IMapActions _mapActions;
private readonly ICharacterActions _characterActions;
private readonly ICurrentMapStateProvider _currentMapStateProvider;
private readonly ICharacterProvider _characterProvider;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly IInventorySpaceValidator _inventorySpaceValidator;
private readonly IHudControlProvider _hudControlProvider;
private readonly IEOMessageBoxFactory _eoMessageBoxFactory;

public MapInteractionController(IMapActions mapActions,
ICharacterActions characterActions,
ICurrentMapStateProvider currentMapStateProvider,
ICharacterProvider characterProvider,
IStatusLabelSetter statusLabelSetter,
IInventorySpaceValidator inventorySpaceValidator,
IHudControlProvider hudControlProvider,
IEOMessageBoxFactory eoMessageBoxFactory)
{
_mapActions = mapActions;
_characterActions = characterActions;
_currentMapStateProvider = currentMapStateProvider;
_characterProvider = characterProvider;
_statusLabelSetter = statusLabelSetter;
_inventorySpaceValidator = inventorySpaceValidator;
_hudControlProvider = hudControlProvider;
Expand All @@ -42,6 +49,12 @@ public class MapInteractionController : IMapInteractionController

public async Task LeftClickAsync(IMapCellState cellState, IMouseCursorRenderer mouseRenderer)
{
if (_characterProvider.MainCharacter.RenderProperties.SitState != SitState.Standing)
{
_characterActions.ToggleSit();
return;
}

var item = cellState.Items.OptionalFirst();
if (item.HasValue)
{
Expand Down
20 changes: 19 additions & 1 deletion EndlessClient/Input/UnwalkableTileActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class UnwalkableTileActions : IUnwalkableTileActions

public void HandleUnwalkableTile()
{
if (MainCharacter.RenderProperties.SitState != SitState.Standing)
return;

var destX = MainCharacter.RenderProperties.GetDestinationX();
var destY = MainCharacter.RenderProperties.GetDestinationY();

Expand Down Expand Up @@ -104,13 +107,14 @@ private void HandleWalkToTileSpec(IMapCellState cellState)
{
switch (cellState.TileSpec)
{
case TileSpec.ChairDown: //todo: chairs
case TileSpec.ChairDown:
case TileSpec.ChairLeft:
case TileSpec.ChairRight:
case TileSpec.ChairUp:
case TileSpec.ChairDownRight:
case TileSpec.ChairUpLeft:
case TileSpec.ChairAll:
HandleWalkToChair();
break;
case TileSpec.Chest: //todo: chests
//if (!walkValid)
Expand Down Expand Up @@ -164,6 +168,20 @@ private void HandleWalkToTileSpec(IMapCellState cellState)
}
}

private void HandleWalkToChair()
{
// server validates that chair direction is OK and that no one is already sitting there
var rp = _characterProvider.MainCharacter.RenderProperties;
var action = rp.SitState == SitState.Chair ? SitAction.Stand : SitAction.Sit;
var packet = new PacketBuilder(PacketFamily.Chair, PacketAction.Request)
.AddChar((byte)action)
.AddChar((byte)rp.GetDestinationX())
.AddChar((byte)rp.GetDestinationY())
.Build();

_packetSendService.SendPacket(packet);
}

private ICharacter MainCharacter => _characterProvider.MainCharacter;
}

Expand Down

0 comments on commit e5b8084

Please sign in to comment.