Skip to content

Commit

Permalink
Handle main player avatar change
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Jan 22, 2021
1 parent 863ab4a commit ac44d39
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace EOLib.PacketHandlers
public class PlayerAvatarChangeHandler : InGameOnlyPacketHandler
{
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly ICharacterRepository _characterRepository;
private readonly IEIFFileProvider _eifFileProvider;

public override PacketFamily Family => PacketFamily.Avatar;
Expand All @@ -23,22 +24,32 @@ public class PlayerAvatarChangeHandler : InGameOnlyPacketHandler

public PlayerAvatarChangeHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateRepository currentMapStateRepository,
ICharacterRepository characterRepository,
IEIFFileProvider eifFileProvider)
: base(playerInfoProvider)
{
_currentMapStateRepository = currentMapStateRepository;
_characterRepository = characterRepository;
_eifFileProvider = eifFileProvider;
}

public override bool HandlePacket(IPacket packet)
{
var playerID = packet.ReadShort();
ICharacter currentCharacter;
try

if (_characterRepository.MainCharacter.ID == playerID)
{
currentCharacter = _characterRepository.MainCharacter;
}
else
{
currentCharacter = _currentMapStateRepository.Characters.Single(x => x.ID == playerID);
try
{
currentCharacter = _currentMapStateRepository.Characters.Single(x => x.ID == playerID);
}
catch (InvalidOperationException) { return false; }
}
catch (InvalidOperationException) { return false; }

var currentRenderProps = currentCharacter.RenderProperties;

Expand Down Expand Up @@ -85,8 +96,16 @@ public override bool HandlePacket(IPacket packet)
}

var updatedCharacter = currentCharacter.WithRenderProperties(currentRenderProps);
_currentMapStateRepository.Characters.Remove(currentCharacter);
_currentMapStateRepository.Characters.Add(updatedCharacter);

if (_characterRepository.MainCharacter.ID == playerID)
{
_characterRepository.MainCharacter = updatedCharacter;
}
else
{
_currentMapStateRepository.Characters.Remove(currentCharacter);
_currentMapStateRepository.Characters.Add(updatedCharacter);
}

return true;
}
Expand Down

0 comments on commit ac44d39

Please sign in to comment.