Skip to content

Commit

Permalink
Packet handling and domain changes for forgetting skill and resetting…
Browse files Browse the repository at this point in the history
… stats
  • Loading branch information
ethanmoffat committed Apr 21, 2022
1 parent 3a6ff4c commit ea276ef
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 148 deletions.
8 changes: 8 additions & 0 deletions EOLib/Domain/Interact/INPCInteractionNotifier.cs
Expand Up @@ -9,6 +9,10 @@ public interface INPCInteractionNotifier
void NotifyInteractionFromNPC(NPCType npcType);

void NotifySkillLearnFail(SkillmasterReply skillmasterReply, short classId);

void NotifySkillForget();

void NotifyStatReset();
}

[AutoMappedType]
Expand All @@ -17,5 +21,9 @@ public class NoOpNPCInteractionNotifier : INPCInteractionNotifier
public void NotifyInteractionFromNPC(NPCType npcType) { }

public void NotifySkillLearnFail(SkillmasterReply skillmasterReply, short classId) { }

public void NotifySkillForget() { }

public void NotifyStatReset() { }
}
}
23 changes: 23 additions & 0 deletions EOLib/Domain/Interact/Skill/SkillmasterActions.cs
Expand Up @@ -26,10 +26,33 @@ public void LearnSkill(short spellId)

_packetSendService.SendPacket(packet);
}

public void ForgetSkill(short spellId)
{
var packet = new PacketBuilder(PacketFamily.StatSkill, PacketAction.Remove)
.AddInt(_skillDataProvider.ID)
.AddShort(spellId)
.Build();

_packetSendService.SendPacket(packet);
}

public void ResetCharacter()
{
var packet = new PacketBuilder(PacketFamily.StatSkill, PacketAction.Junk)
.AddInt(_skillDataProvider.ID)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface ISkillmasterActions
{
void LearnSkill(short spellId);

void ForgetSkill(short spellId);

void ResetCharacter();
}
}
1 change: 0 additions & 1 deletion EOLib/Net/API/PacketAPI.cs
Expand Up @@ -25,7 +25,6 @@ public PacketAPI(EOClient client)
_createPartyMembers();
_createNPCMembers();
_createSpellMembers();
_createStatSkillMembers();
_createTradeMembers();
}

Expand Down
107 changes: 0 additions & 107 deletions EOLib/Net/API/StatSkill.cs

This file was deleted.

67 changes: 67 additions & 0 deletions EOLib/PacketHandlers/Skill/StatskillJunkHandler.cs
@@ -0,0 +1,67 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Interact;
using EOLib.Domain.Login;
using EOLib.Net;
using EOLib.Net.Handlers;
using System.Collections.Generic;

namespace EOLib.PacketHandlers.Skill
{
/// <summary>
/// Sent when resetting a character's stats/skills
/// </summary>
[AutoMappedType]
public class StatskillJunkHandler : InGameOnlyPacketHandler
{
private readonly ICharacterInventoryRepository _characterInventoryRepository;
private readonly ICharacterRepository _characterRepository;
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers;

public override PacketFamily Family => PacketFamily.StatSkill;

public override PacketAction Action => PacketAction.Junk;

public StatskillJunkHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterInventoryRepository characterInventoryRepository,
ICharacterRepository characterRepository,
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers)
: base(playerInfoProvider)
{
_characterInventoryRepository = characterInventoryRepository;
_characterRepository = characterRepository;
_npcInteractionNotifiers = npcInteractionNotifiers;
}

public override bool HandlePacket(IPacket packet)
{
var stats = _characterRepository.MainCharacter.Stats
.WithNewStat(CharacterStat.StatPoints, packet.ReadShort())
.WithNewStat(CharacterStat.SkillPoints, packet.ReadShort())
.WithNewStat(CharacterStat.HP, packet.ReadShort())
.WithNewStat(CharacterStat.MaxHP, packet.ReadShort())
.WithNewStat(CharacterStat.TP, packet.ReadShort())
.WithNewStat(CharacterStat.MaxTP, packet.ReadShort())
.WithNewStat(CharacterStat.MaxSP, packet.ReadShort())
.WithNewStat(CharacterStat.Strength, packet.ReadShort())
.WithNewStat(CharacterStat.Intelligence, packet.ReadShort())
.WithNewStat(CharacterStat.Wisdom, packet.ReadShort())
.WithNewStat(CharacterStat.Agility, packet.ReadShort())
.WithNewStat(CharacterStat.Constituion, packet.ReadShort())
.WithNewStat(CharacterStat.Charisma, packet.ReadShort())
.WithNewStat(CharacterStat.MinDam, packet.ReadShort())
.WithNewStat(CharacterStat.MaxDam, packet.ReadShort())
.WithNewStat(CharacterStat.Accuracy, packet.ReadShort())
.WithNewStat(CharacterStat.Evade, packet.ReadShort())
.WithNewStat(CharacterStat.Armor, packet.ReadShort());
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithStats(stats);

_characterInventoryRepository.SpellInventory.Clear();

foreach (var notifier in _npcInteractionNotifiers)
notifier.NotifyStatReset();

return true;
}
}
}
45 changes: 45 additions & 0 deletions EOLib/PacketHandlers/Skill/StatskillRemoveHandler.cs
@@ -0,0 +1,45 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Interact;
using EOLib.Domain.Login;
using EOLib.Net;
using EOLib.Net.Handlers;
using System.Collections.Generic;
using System.Linq;

namespace EOLib.PacketHandlers.Skill
{
/// <summary>
/// Sent when forgetting a skill
/// </summary>
[AutoMappedType]
public class StatskillRemoveHandler : InGameOnlyPacketHandler
{
private readonly ICharacterInventoryRepository _characterInventoryRepository;
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers;

public override PacketFamily Family => PacketFamily.StatSkill;

public override PacketAction Action => PacketAction.Remove;

public StatskillRemoveHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterInventoryRepository characterInventoryRepository,
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers)
: base(playerInfoProvider)
{
_characterInventoryRepository = characterInventoryRepository;
_npcInteractionNotifiers = npcInteractionNotifiers;
}

public override bool HandlePacket(IPacket packet)
{
var spellId = packet.ReadShort();
_characterInventoryRepository.SpellInventory.RemoveWhere(x => x.ID == spellId);

foreach (var notifier in _npcInteractionNotifiers)
notifier.NotifySkillForget();

return true;
}
}
}
12 changes: 12 additions & 0 deletions EndlessClient/Dialogs/Actions/NpcInteractionActions.cs
Expand Up @@ -57,5 +57,17 @@ public void NotifySkillLearnFail(SkillmasterReply skillmasterReply, short classI
break;
}
}

public void NotifySkillForget()
{
var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.SKILL_FORGET_SUCCESS);
dlg.ShowDialog();
}

public void NotifyStatReset()
{
var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.SKILL_RESET_CHARACTER_COMPLETE);
dlg.ShowDialog();
}
}
}
40 changes: 0 additions & 40 deletions EndlessClient/Old/PacketAPICallbackManager.cs
Expand Up @@ -45,10 +45,6 @@ public void AssignCallbacks()
m_packetAPI.OnTradeOfferUpdate += _tradeOfferUpdate;
m_packetAPI.OnTradeCompleted += _tradeCompleted;

//skills
m_packetAPI.OnSpellForget += _statskillForgetSpell;
m_packetAPI.OnCharacterStatsReset += _statskillReset;

m_packetAPI.OnPlaySoundEffect += _playSoundEffect;

//spell casting
Expand Down Expand Up @@ -174,42 +170,6 @@ private void _tradeCompleted(short id1, List<InventoryItem> items1, short id2, L
TradeDialog.Instance.CompleteTrade(id1, items1, id2, items2);
}

private void _statskillForgetSpell(short id)
{
OldWorld.Instance.MainPlayer.ActiveCharacter.Spells.RemoveAll(_spell => _spell.ID == id);
EOMessageBox.Show(DialogResourceID.SKILL_FORGET_SUCCESS, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);

//m_game.Hud.RemoveSpellFromActiveSpellsByID(id);
}

private void _statskillReset(StatResetData data)
{
OldCharacter c;
(c = OldWorld.Instance.MainPlayer.ActiveCharacter).Spells.Clear();
EOMessageBox.Show(DialogResourceID.SKILL_RESET_CHARACTER_COMPLETE, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
c.Stats.StatPoints = data.StatPoints;
c.Stats.SkillPoints = data.SkillPoints;
c.Stats.HP = data.HP;
c.Stats.MaxHP = data.MaxHP;
c.Stats.TP = data.TP;
c.Stats.MaxTP = data.MaxTP;
c.Stats.SP = data.MaxSP;
c.Stats.MaxSP = data.MaxSP;
c.Stats.Str = data.Str;
c.Stats.Int = data.Int;
c.Stats.Wis = data.Wis;
c.Stats.Agi = data.Agi;
c.Stats.Con = data.Con;
c.Stats.Cha = data.Cha;
c.Stats.MinDam = data.MinDam;
c.Stats.MaxDam = data.MaxDam;
c.Stats.Accuracy = data.Accuracy;
c.Stats.Evade = data.Evade;
c.Stats.Armor = data.Armor;
//m_game.Hud.RefreshStats();
//m_game.Hud.RemoveAllSpells();
}

private void _playSoundEffect(int effectID)
{
try
Expand Down

0 comments on commit ea276ef

Please sign in to comment.