-
Notifications
You must be signed in to change notification settings - Fork 16
/
AttackPlayerHandler.cs
57 lines (49 loc) · 2.11 KB
/
AttackPlayerHandler.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
50
51
52
53
54
55
56
57
using AutomaticTypeMapper;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.Net;
using EOLib.Net.Handlers;
using System.Collections.Generic;
namespace EOLib.PacketHandlers.Attack
{
/// <summary>
/// Sent when another player attacks
/// </summary>
[AutoMappedType]
public class PlayerAttackHandler : InGameOnlyPacketHandler
{
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IEnumerable<IOtherCharacterAnimationNotifier> _otherCharacterAnimationNotifiers;
public override PacketFamily Family => PacketFamily.Attack;
public override PacketAction Action => PacketAction.Player;
public PlayerAttackHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateRepository currentMapStateRepository,
IEnumerable<IOtherCharacterAnimationNotifier> otherCharacterAnimationNotifiers)
: base(playerInfoProvider)
{
_currentMapStateRepository = currentMapStateRepository;
_otherCharacterAnimationNotifiers = otherCharacterAnimationNotifiers;
}
public override bool HandlePacket(IPacket packet)
{
var playerID = packet.ReadShort();
var direction = (EODirection)packet.ReadChar();
if (_currentMapStateRepository.Characters.TryGetValue(playerID, out var character))
{
if (character.RenderProperties.Direction != direction)
{
var renderProperties = character.RenderProperties.WithDirection(direction);
_currentMapStateRepository.Characters.Update(character, character.WithRenderProperties(renderProperties));
}
foreach (var notifier in _otherCharacterAnimationNotifiers)
notifier.StartOtherCharacterAttackAnimation(playerID);
}
else
{
_currentMapStateRepository.UnknownPlayerIDs.Add(playerID);
}
return true;
}
}
}