Skip to content

Commit

Permalink
Implement handler for StatskillTake for learning skills
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 13, 2022
1 parent bbe6283 commit 4792118
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
13 changes: 0 additions & 13 deletions EOLib/Net/API/StatSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,19 @@ internal StatResetData(OldPacket pkt)
}

public delegate void SpellLearnErrorEvent(SkillMasterReply reply, short classID);
public delegate void SpellLearnSuccessEvent(short spellID, int goldRemaining);
public delegate void SpellForgetEvent(short spellID);
public delegate void SpellTrainEvent(short skillPtsRemaining, short spellID, short spellLevel);

partial class PacketAPI
{
public event Action<SkillmasterData> OnSkillmasterOpen;
public event SpellLearnErrorEvent OnSpellLearnError;
public event SpellLearnSuccessEvent OnSpellLearnSuccess;
public event SpellForgetEvent OnSpellForget;
public event Action<StatResetData> OnCharacterStatsReset;

private void _createStatSkillMembers()
{
m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.StatSkill, PacketAction.Open), _handleStatSkillOpen, true);
m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.StatSkill, PacketAction.Reply), _handleStatSkillReply, true);
m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.StatSkill, PacketAction.Take), _handleStatSkillTake, true);
m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.StatSkill, PacketAction.Remove), _handleStatSkillRemove, true);
m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.StatSkill, PacketAction.Junk), _handleStatSkillJunk, true);
}
Expand Down Expand Up @@ -214,15 +210,6 @@ private void _handleStatSkillReply(OldPacket pkt)
OnSpellLearnError((SkillMasterReply)pkt.GetShort(), pkt.GetShort());
}

//success learning a skill
private void _handleStatSkillTake(OldPacket pkt)
{
//short - spell id
//int - character gold remaining
if (OnSpellLearnSuccess != null)
OnSpellLearnSuccess(pkt.GetShort(), pkt.GetInt());
}

//forgetting a skill
private void _handleStatSkillRemove(OldPacket pkt)
{
Expand Down
45 changes: 45 additions & 0 deletions EOLib/PacketHandlers/Skill/StatskillTake.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Net;
using EOLib.Net.Handlers;
using System.Linq;

namespace EOLib.PacketHandlers.Skill
{
/// <summary>
/// Sent when learning a skill, either via $learn command or from skillmaster
/// </summary>
[AutoMappedType]
public class StatskillTake : InGameOnlyPacketHandler
{
private readonly ICharacterInventoryRepository _characterInventoryRepository;

public override PacketFamily Family => PacketFamily.StatSkill;

public override PacketAction Action => PacketAction.Take;

public StatskillTake(IPlayerInfoProvider playerInfoProvider,
ICharacterInventoryRepository characterInventoryRepository)
: base(playerInfoProvider)
{
_characterInventoryRepository = characterInventoryRepository;
}

public override bool HandlePacket(IPacket packet)
{
var spellId = packet.ReadShort();
var characterGold = packet.ReadInt();

if (!_characterInventoryRepository.SpellInventory.Any(x => x.ID == spellId))
{
_characterInventoryRepository.SpellInventory.Add(new InventorySpell(spellId, 0));
}

_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1);
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(1, characterGold));

return true;
}
}
}
10 changes: 0 additions & 10 deletions EndlessClient/Old/PacketAPICallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void AssignCallbacks()
//skills
m_packetAPI.OnSkillmasterOpen += _skillmasterOpen;
m_packetAPI.OnSpellLearnError += _statskillLearnError;
m_packetAPI.OnSpellLearnSuccess += _statskillLearnSpellSuccess;
m_packetAPI.OnSpellForget += _statskillForgetSpell;
m_packetAPI.OnCharacterStatsReset += _statskillReset;

Expand Down Expand Up @@ -197,15 +196,6 @@ private void _statskillLearnError(SkillMasterReply reply, short id)
}
}

private void _statskillLearnSpellSuccess(short id, int remaining)
{
OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.Add(new InventorySpell(id, 0));
if (SkillmasterDialog.Instance != null)
SkillmasterDialog.Instance.RemoveSkillByIDFromLearnList(id);
//OldWorld.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(1, remaining);
//m_game.Hud.AddNewSpellToActiveSpellsByID(id);
}

private void _statskillForgetSpell(short id)
{
OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.RemoveAll(_spell => _spell.ID == id);
Expand Down

0 comments on commit 4792118

Please sign in to comment.