From 0c948f081f08a8cd15a88fa9a19b01dbe1b8dcf2 Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Wed, 15 Feb 2017 17:34:50 -0800 Subject: [PATCH] Issue #71: Handle PLAYER_RECOVER packet in new code --- EOLib/EOLib.csproj | 1 + EOLib/Net/API/Recover.cs | 8 ---- .../PacketHandlerDependencyContainer.cs | 3 +- EOLib/PacketHandlers/PlayerRecoverHandler.cs | 40 +++++++++++++++++++ EndlessClient/Old/PacketAPICallbackManager.cs | 9 ----- 5 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 EOLib/PacketHandlers/PlayerRecoverHandler.cs diff --git a/EOLib/EOLib.csproj b/EOLib/EOLib.csproj index e174cb65f..d2a3bf25c 100644 --- a/EOLib/EOLib.csproj +++ b/EOLib/EOLib.csproj @@ -291,6 +291,7 @@ + diff --git a/EOLib/Net/API/Recover.cs b/EOLib/Net/API/Recover.cs index bfe03606b..9446aec6e 100644 --- a/EOLib/Net/API/Recover.cs +++ b/EOLib/Net/API/Recover.cs @@ -12,23 +12,15 @@ namespace EOLib.Net.API partial class PacketAPI { - public event PlayerRecoverEvent OnPlayerRecover; public event RecoverReplyEvent OnRecoverReply; public event PlayerHealEvent OnPlayerHeal; private void _createRecoverMembers() { - m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.Recover, PacketAction.Player), _handleRecoverPlayer, true); m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.Recover, PacketAction.Reply), _handleRecoverReply, true); m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.Recover, PacketAction.Agree), _handleRecoverAgree, true); } - private void _handleRecoverPlayer(OldPacket pkt) - { - if (OnPlayerRecover != null) - OnPlayerRecover(pkt.GetShort(), pkt.GetShort()); //HP - TP - } - private void _handleRecoverReply(OldPacket pkt) { if (OnRecoverReply == null) return; diff --git a/EOLib/PacketHandlers/PacketHandlerDependencyContainer.cs b/EOLib/PacketHandlers/PacketHandlerDependencyContainer.cs index 88b4fedf7..6a21da95f 100644 --- a/EOLib/PacketHandlers/PacketHandlerDependencyContainer.cs +++ b/EOLib/PacketHandlers/PacketHandlerDependencyContainer.cs @@ -47,7 +47,8 @@ public void RegisterDependencies(IUnityContainer container) .RegisterVaried() .RegisterVaried() .RegisterVaried() - .RegisterVaried(); + .RegisterVaried() + .RegisterVaried(); //npcs container.RegisterVaried() diff --git a/EOLib/PacketHandlers/PlayerRecoverHandler.cs b/EOLib/PacketHandlers/PlayerRecoverHandler.cs new file mode 100644 index 000000000..e86317f79 --- /dev/null +++ b/EOLib/PacketHandlers/PlayerRecoverHandler.cs @@ -0,0 +1,40 @@ +// Original Work Copyright (c) Ethan Moffat 2014-2017 +// This file is subject to the GPL v2 License +// For additional details, see the LICENSE file + +using EOLib.Domain.Character; +using EOLib.Domain.Login; +using EOLib.Net; +using EOLib.Net.Handlers; + +namespace EOLib.PacketHandlers +{ + public class PlayerRecoverHandler : InGameOnlyPacketHandler + { + private readonly ICharacterRepository _characterRepository; + + public override PacketFamily Family => PacketFamily.Recover; + public override PacketAction Action => PacketAction.Player; + + public PlayerRecoverHandler(IPlayerInfoProvider playerInfoProvider, + ICharacterRepository characterRepository) + : base(playerInfoProvider) + { + _characterRepository = characterRepository; + } + + public override bool HandlePacket(IPacket packet) + { + var newHP = packet.ReadShort(); + var newTP = packet.ReadShort(); + + var stats = _characterRepository.MainCharacter.Stats + .WithNewStat(CharacterStat.HP, newHP) + .WithNewStat(CharacterStat.TP, newTP); + + _characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats); + + return true; + } + } +} diff --git a/EndlessClient/Old/PacketAPICallbackManager.cs b/EndlessClient/Old/PacketAPICallbackManager.cs index 37e78d3ae..dfa0d0258 100644 --- a/EndlessClient/Old/PacketAPICallbackManager.cs +++ b/EndlessClient/Old/PacketAPICallbackManager.cs @@ -43,7 +43,6 @@ public void AssignCallbacks() m_packetAPI.OnChestGetItem += _chestGetItem; //recovery related - m_packetAPI.OnPlayerRecover += _playerRecover; m_packetAPI.OnRecoverReply += _recoverReply; m_packetAPI.OnPlayerHeal += _playerHeal; @@ -208,14 +207,6 @@ private void _chestGetItem(short id, int amount, byte weight, byte maxWeight, Ch m_game.Hud.RefreshStats(); } - private void _playerRecover(short hp, short tp) - { - OldWorld.Instance.MainPlayer.ActiveCharacter.Stats.HP = hp; - OldWorld.Instance.MainPlayer.ActiveCharacter.Stats.TP = tp; - if (m_game.Hud != null) - m_game.Hud.RefreshStats(); - } - private void _recoverReply(int exp, short karma, byte level, short statpoints, short skillpoints) { OldWorld.Instance.MainPlayer.ActiveCharacter.Stats.Experience = exp;