Skip to content

Commit

Permalink
Player walk handler updates other player position/direction if they a…
Browse files Browse the repository at this point in the history
…ren't walking
  • Loading branch information
ethanmoffat committed Mar 8, 2022
1 parent a10e8fb commit e96cb13
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 1 addition & 3 deletions EOLib/PacketHandlers/PlayerAttackHandler.cs
Expand Up @@ -39,9 +39,7 @@ public override bool HandlePacket(IPacket packet)
if (character.RenderProperties.Direction != direction)
{
var renderProperties = character.RenderProperties.WithDirection(direction);
var newCharacter = character.WithRenderProperties(renderProperties);

_currentMapStateRepository.Characters[playerID] = newCharacter;
_currentMapStateRepository.Characters[playerID] = character.WithRenderProperties(renderProperties);
}

foreach (var notifier in _otherCharacterAnimationNotifiers)
Expand Down
26 changes: 26 additions & 0 deletions EOLib/PacketHandlers/PlayerWalkHandler.cs
Expand Up @@ -34,14 +34,40 @@ public class PlayerWalkHandler : InGameOnlyPacketHandler
public override bool HandlePacket(IPacket packet)
{
var characterID = packet.ReadShort();

if (!_currentMapStateRepository.Characters.ContainsKey(characterID))
return false;

var dir = (EODirection)packet.ReadChar();
var x = packet.ReadChar();
var y = packet.ReadChar();

var character = _currentMapStateRepository.Characters[characterID];

// if character is walking, that means animator is handling position of character
// if character is not walking (this is true in EOBot), update the domain model here
if (!character.RenderProperties.IsActing(CharacterActionState.Walking))
{
var renderProperties = EnsureCorrectXAndY(character.RenderProperties.WithDirection(dir), x, y);
_currentMapStateRepository.Characters[characterID] = character.WithRenderProperties(renderProperties);
}

foreach (var notifier in _otherCharacterAnimationNotifiers)
notifier.StartOtherCharacterWalkAnimation(characterID, x, y, dir);

return true;
}

private static ICharacterRenderProperties EnsureCorrectXAndY(ICharacterRenderProperties renderProperties, byte x, byte y)
{
var opposite = renderProperties.Direction.Opposite();
var tempRenderProperties = renderProperties
.WithDirection(opposite)
.WithMapX(x)
.WithMapY(y);
return renderProperties
.WithMapX(tempRenderProperties.GetDestinationX())
.WithMapY(tempRenderProperties.GetDestinationY());
}
}
}

0 comments on commit e96cb13

Please sign in to comment.