-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Law + priest interaction implementation
- Loading branch information
1 parent
eeed6fc
commit c7decf9
Showing
25 changed files
with
849 additions
and
13 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
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,49 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Net; | ||
using EOLib.Net.Communication; | ||
|
||
namespace EOLib.Domain.Interact.Law | ||
{ | ||
[AutoMappedType] | ||
public class LawActions : ILawActions | ||
{ | ||
private readonly ILawSessionProvider _lawSessionProvider; | ||
private readonly IPacketSendService _packetSendService; | ||
|
||
public LawActions(ILawSessionProvider lawSessionProvider, | ||
IPacketSendService packetSendService) | ||
{ | ||
_lawSessionProvider = lawSessionProvider; | ||
_packetSendService = packetSendService; | ||
} | ||
|
||
public void RequestMarriage(string partner) | ||
{ | ||
SendShared(MarriageRequestType.Marriage, partner); | ||
} | ||
|
||
public void RequestDivorce(string partner) | ||
{ | ||
SendShared(MarriageRequestType.Divorce, partner); | ||
} | ||
|
||
private void SendShared(MarriageRequestType requestType, string partner) | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Marriage, PacketAction.Request) | ||
.AddChar((int)requestType) | ||
.AddInt(_lawSessionProvider.SessionID) | ||
.AddByte(255) | ||
.AddString(partner) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
} | ||
|
||
public interface ILawActions | ||
{ | ||
void RequestMarriage(string partner); | ||
|
||
void RequestDivorce(string partner); | ||
} | ||
} |
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,25 @@ | ||
using AutomaticTypeMapper; | ||
|
||
namespace EOLib.Domain.Interact.Law | ||
{ | ||
public interface ILawSessionProvider | ||
{ | ||
int SessionID { get; } | ||
} | ||
|
||
public interface ILawSessionRepository | ||
{ | ||
int SessionID { get; set; } | ||
} | ||
|
||
[AutoMappedType(IsSingleton = true)] | ||
public class LawSessionRepository : ILawSessionRepository, ILawSessionProvider | ||
{ | ||
public int SessionID { get; set; } | ||
|
||
public LawSessionRepository() | ||
{ | ||
SessionID = 0; | ||
} | ||
} | ||
} |
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,13 @@ | ||
namespace EOLib.Domain.Interact.Law | ||
{ | ||
public enum MarriageReply | ||
{ | ||
AlreadyMarried = 1, | ||
NotMarried = 2, | ||
Success = 3, | ||
NotEnoughGold = 4, | ||
WrongName = 5, | ||
ServiceBusy = 6, | ||
DivorceNotification = 7 | ||
} | ||
} |
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,8 @@ | ||
namespace EOLib.Domain.Interact.Law | ||
{ | ||
public enum MarriageRequestType | ||
{ | ||
Marriage = 1, | ||
Divorce = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Net; | ||
using EOLib.Net.Communication; | ||
|
||
namespace EOLib.Domain.Interact.Priest | ||
{ | ||
[AutoMappedType] | ||
public class PriestActions : IPriestActions | ||
{ | ||
private readonly IPriestSessionProvider _priestSessionProvider; | ||
private readonly IPacketSendService _packetSendService; | ||
|
||
public PriestActions(IPriestSessionProvider priestSessionProvider, | ||
IPacketSendService packetSendService) | ||
{ | ||
_priestSessionProvider = priestSessionProvider; | ||
_packetSendService = packetSendService; | ||
} | ||
|
||
public void AcceptRequest() | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Priest, PacketAction.Accept) | ||
.AddShort(_priestSessionProvider.SessionID) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
|
||
public void RequestMarriage(string partner) | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Priest, PacketAction.Request) | ||
.AddInt(_priestSessionProvider.SessionID) | ||
.AddByte(255) | ||
.AddString(partner) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
|
||
public void ConfirmMarriage() | ||
{ | ||
var packet = new PacketBuilder(PacketFamily.Priest, PacketAction.Use) | ||
.AddInt(_priestSessionProvider.SessionID) | ||
.Build(); | ||
|
||
_packetSendService.SendPacket(packet); | ||
} | ||
} | ||
|
||
public interface IPriestActions | ||
{ | ||
void AcceptRequest(); | ||
|
||
void RequestMarriage(string partner); | ||
|
||
void ConfirmMarriage(); | ||
} | ||
} |
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,14 @@ | ||
namespace EOLib.Domain.Interact.Priest | ||
{ | ||
public enum PriestReply | ||
{ | ||
NotDressed = 1, | ||
LowLevel = 2, | ||
PartnerNotPresent = 3, | ||
PartnerNotDressed = 4, | ||
Busy = 5, | ||
DoYou = 6, | ||
PartnerAlreadyMarried = 7, | ||
NoPermission = 8 | ||
} | ||
} |
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,25 @@ | ||
using AutomaticTypeMapper; | ||
|
||
namespace EOLib.Domain.Interact.Priest | ||
{ | ||
public interface IPriestSessionProvider | ||
{ | ||
int SessionID { get; } | ||
} | ||
|
||
public interface IPriestSessionRepository | ||
{ | ||
int SessionID { get; set; } | ||
} | ||
|
||
[AutoMappedType(IsSingleton = true)] | ||
public class PriestSessionRepository : IPriestSessionProvider, IPriestSessionRepository | ||
{ | ||
public int SessionID { get; set; } | ||
|
||
public PriestSessionRepository() | ||
{ | ||
SessionID = 0; | ||
} | ||
} | ||
} |
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,40 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Interact; | ||
using EOLib.Domain.Interact.Law; | ||
using EOLib.Domain.Login; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.Marriage | ||
{ | ||
[AutoMappedType] | ||
public class MarriageOpenHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ILawSessionRepository _lawSessionRepository; | ||
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.Marriage; | ||
|
||
public override PacketAction Action => PacketAction.Open; | ||
|
||
public MarriageOpenHandler(IPlayerInfoProvider playerInfoProvider, | ||
ILawSessionRepository lawSessionRepository, | ||
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers) | ||
: base(playerInfoProvider) | ||
{ | ||
_lawSessionRepository = lawSessionRepository; | ||
_npcInteractionNotifiers = npcInteractionNotifiers; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
_lawSessionRepository.SessionID = packet.ReadThree(); | ||
|
||
foreach (var notifier in _npcInteractionNotifiers) | ||
notifier.NotifyInteractionFromNPC(IO.NPCType.Law); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using AutomaticTypeMapper; | ||
using EOLib.Domain.Character; | ||
using EOLib.Domain.Interact; | ||
using EOLib.Domain.Interact.Law; | ||
using EOLib.Domain.Login; | ||
using EOLib.Net; | ||
using EOLib.Net.Handlers; | ||
using System.Collections.Generic; | ||
|
||
namespace EOLib.PacketHandlers.Marriage | ||
{ | ||
[AutoMappedType] | ||
public class MarriageReplyHandler : InGameOnlyPacketHandler | ||
{ | ||
private readonly ICharacterInventoryRepository _characterInventoryRepository; | ||
private readonly IEnumerable<INPCInteractionNotifier> _npcInteractionNotifiers; | ||
|
||
public override PacketFamily Family => PacketFamily.Marriage; | ||
|
||
public override PacketAction Action => PacketAction.Reply; | ||
|
||
public MarriageReplyHandler(IPlayerInfoProvider playerInfoProvider, | ||
ICharacterInventoryRepository characterInventoryRepository, | ||
IEnumerable<INPCInteractionNotifier> npcInteractionNotifiers) | ||
: base(playerInfoProvider) | ||
{ | ||
_characterInventoryRepository = characterInventoryRepository; | ||
_npcInteractionNotifiers = npcInteractionNotifiers; | ||
} | ||
|
||
public override bool HandlePacket(IPacket packet) | ||
{ | ||
var replyCode = (MarriageReply)packet.ReadShort(); | ||
|
||
if (replyCode == MarriageReply.Success) | ||
{ | ||
var goldAmount = packet.ReadInt(); | ||
|
||
_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1); | ||
_characterInventoryRepository.ItemInventory.Add(new InventoryItem(1, goldAmount)); | ||
} | ||
|
||
foreach (var notifier in _npcInteractionNotifiers) | ||
notifier.NotifyMarriageReply(replyCode); | ||
|
||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.