Skip to content

Commit

Permalink
Fix crash in NPCLeaveMapHandler when there's no character matching pl…
Browse files Browse the repository at this point in the history
…ayer ID
  • Loading branch information
ethanmoffat committed May 11, 2021
1 parent 8db36a2 commit ce4c534
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions EOLib/PacketHandlers/NPCLeaveMapHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.Extensions;
using EOLib.Net;
using EOLib.Net.Handlers;

Expand Down Expand Up @@ -109,12 +110,16 @@ private void UpdatePlayerDirection(short playerID, EODirection playerDirection)
}
else
{
var character = _currentMapStateRepository.Characters.Single(x => x.ID == playerID);
var updatedRenderProps = character.RenderProperties.WithDirection(playerDirection);
var updatedCharacter = character.WithRenderProperties(updatedRenderProps);
var character = _currentMapStateRepository.Characters.OptionalSingle(x => x.ID == playerID);

_currentMapStateRepository.Characters.Remove(character);
_currentMapStateRepository.Characters.Add(updatedCharacter);
if (character.HasValue)
{
var updatedRenderProps = character.Value.RenderProperties.WithDirection(playerDirection);
var updatedCharacter = character.Value.WithRenderProperties(updatedRenderProps);

_currentMapStateRepository.Characters.Remove(character.Value);
_currentMapStateRepository.Characters.Add(updatedCharacter);
}
}
}

Expand Down

0 comments on commit ce4c534

Please sign in to comment.