Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Domain model and packet handling for skillmaster dialogs
- Loading branch information
1 parent
d12b7a1
commit fbcdbc2
Showing
10 changed files
with
174 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Amadevus.RecordGenerator; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Interact.Skill | ||
{ | ||
[Record] | ||
public sealed partial class Skill | ||
{ | ||
public short Id { get; } | ||
|
||
public byte LevelRequirement { get; } | ||
|
||
public byte ClassRequirement { get; } | ||
|
||
public int GoldRequirement { get; } | ||
|
||
public IReadOnlyList<short> SkillRequirements { get; } | ||
|
||
public short StrRequirement { get; } | ||
|
||
public short IntRequirement { get; } | ||
|
||
public short WisRequirement { get; } | ||
|
||
public short AgiRequirement { get; } | ||
|
||
public short ConRequirement { get; } | ||
|
||
public short ChaRequirement { get; } | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using AutomaticTypeMapper; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.Domain.Interact.Skill | ||
{ | ||
public interface ISkillDataRepository : IResettable | ||
{ | ||
short ID { get; set; } | ||
|
||
string Title { get; set; } | ||
|
||
HashSet<Skill> Skills { get; set; } | ||
} | ||
|
||
public interface ISkillDataProvider : IResettable | ||
{ | ||
short ID { get; } | ||
|
||
string Title { get; } | ||
|
||
IReadOnlyCollection<Skill> Skills { get; } | ||
} | ||
|
||
[AutoMappedType(IsSingleton = true)] | ||
public class SkillDataRepository : ISkillDataRepository, ISkillDataProvider | ||
{ | ||
public short ID { get; set; } | ||
|
||
public string Title { get; set; } | ||
|
||
public HashSet<Skill> Skills { get; set; } | ||
|
||
IReadOnlyCollection<Skill> ISkillDataProvider.Skills => Skills; | ||
|
||
public SkillDataRepository() | ||
{ | ||
ResetState(); | ||
} | ||
|
||
public void ResetState() | ||
{ | ||
ID = 0; | ||
Title = string.Empty; | ||
Skills = new HashSet<Skill>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace EOLib.Domain.Interact.Skill | ||
{ | ||
public enum SkillmasterReply | ||
{ | ||
ErrorRemoveItems = 1, | ||
ErrorWrongClass = 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Interact; | ||
using EOLib.Domain.Interact.Skill; | ||
using EOLib.Domain.Login; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.Skill | ||
{ | ||
[AutoMappedType] | ||
public class StatskillOpenHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ISkillDataRepository _skillDataRepository; | ||
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.StatSkill; | ||
|
||
public override PacketAction Action => PacketAction.Open; | ||
|
||
public StatskillOpenHandler(IPlayerInfoProvider playerInfoProvider, | ||
ISkillDataRepository skillDataRepository, | ||
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers) | ||
: base(playerInfoProvider) | ||
{ | ||
_skillDataRepository = skillDataRepository; | ||
_npcInteractionNotifiers = npcInteractionNotifiers; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
_skillDataRepository.ID = packet.ReadShort(); | ||
_skillDataRepository.Title = packet.ReadBreakString(); | ||
_skillDataRepository.Skills.Clear(); | ||
|
||
while (packet.ReadPosition < packet.Length) | ||
{ | ||
var skill = new Domain.Interact.Skill.Skill.Builder | ||
{ | ||
Id = packet.ReadShort(), | ||
LevelRequirement = packet.ReadChar(), | ||
ClassRequirement = packet.ReadChar(), | ||
GoldRequirement = packet.ReadInt(), | ||
SkillRequirements = new List<short> | ||
{ | ||
packet.ReadShort(), | ||
packet.ReadShort(), | ||
packet.ReadShort(), | ||
packet.ReadShort() | ||
}, | ||
StrRequirement = packet.ReadShort(), | ||
IntRequirement = packet.ReadShort(), | ||
WisRequirement = packet.ReadShort(), | ||
AgiRequirement = packet.ReadShort(), | ||
ConRequirement = packet.ReadShort(), | ||
ChaRequirement = packet.ReadShort() | ||
}.ToImmutable(); | ||
|
||
_skillDataRepository.Skills.Add(skill); | ||
} | ||
|
||
foreach (var notifier in _npcInteractionNotifiers) | ||
notifier.NotifyInteractionFromNPC(IO.NPCType.Skills); | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters