-
Notifications
You must be signed in to change notification settings - Fork 16
/
FacePlayerHandler.cs
49 lines (39 loc) · 1.47 KB
/
FacePlayerHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using AutomaticTypeMapper;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Net;
using EOLib.Net.Handlers;
namespace EOLib.PacketHandlers.Face
{
/// <summary>
/// Player changing direction
/// </summary>
[AutoMappedType]
public class FacePlayerHandler : InGameOnlyPacketHandler
{
private readonly ICurrentMapStateRepository _mapStateRepository;
public override PacketFamily Family => PacketFamily.Face;
public override PacketAction Action => PacketAction.Player;
public FacePlayerHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateRepository mapStateRepository)
: base(playerInfoProvider)
{
_mapStateRepository = mapStateRepository;
}
public override bool HandlePacket(IPacket packet)
{
var id = packet.ReadShort();
var direction = (EODirection)packet.ReadChar();
if (!_mapStateRepository.Characters.ContainsKey(id))
{
_mapStateRepository.UnknownPlayerIDs.Add(id);
return true;
}
var character = _mapStateRepository.Characters[id];
var newRenderProps = character.RenderProperties.WithDirection(direction);
var newCharacter = character.WithRenderProperties(newRenderProps);
_mapStateRepository.Characters.Update(character, newCharacter);
return true;
}
}
}