Skip to content

Commit

Permalink
Issue #71: Handle PLAYER_RECOVER packet in new code
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Feb 16, 2017
1 parent d5bcce9 commit 0c948f0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
1 change: 1 addition & 0 deletions EOLib/EOLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
<Compile Include="PacketHandlers\PlayerEnterMapHandler.cs" />
<Compile Include="PacketHandlers\PlayerLeaveMapHandler.cs" />
<Compile Include="PacketHandlers\PlayerLevelUpHandler.cs" />
<Compile Include="PacketHandlers\PlayerRecoverHandler.cs" />
<Compile Include="PacketHandlers\PlayerWalkHandler.cs" />
<Compile Include="PacketHandlers\BeginPlayerWarpHandler.cs" />
<Compile Include="PacketHandlers\RecoverStatListHandler.cs" />
Expand Down
8 changes: 0 additions & 8 deletions EOLib/Net/API/Recover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion EOLib/PacketHandlers/PacketHandlerDependencyContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void RegisterDependencies(IUnityContainer container)
.RegisterVaried<IPacketHandler, PlayerLevelUpHandler>()
.RegisterVaried<IPacketHandler, PlayerLevelUpFromSpellCastHandler>()
.RegisterVaried<IPacketHandler, StatTrainingHandler>()
.RegisterVaried<IPacketHandler, RecoverStatListHandler>();
.RegisterVaried<IPacketHandler, RecoverStatListHandler>()
.RegisterVaried<IPacketHandler, PlayerRecoverHandler>();

//npcs
container.RegisterVaried<IPacketHandler, NPCActionHandler>()
Expand Down
40 changes: 40 additions & 0 deletions EOLib/PacketHandlers/PlayerRecoverHandler.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
9 changes: 0 additions & 9 deletions EndlessClient/Old/PacketAPICallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0c948f0

Please sign in to comment.