Skip to content

Commit

Permalink
Law + priest interaction implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 26, 2023
1 parent eeed6fc commit c7decf9
Show file tree
Hide file tree
Showing 25 changed files with 849 additions and 13 deletions.
17 changes: 17 additions & 0 deletions EOLib.Localization/EOResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,23 @@ public enum EOResourceID
SPELL_ONLY_WORKS_ON_GROUP = 304,
STATUS_LABEL_THE_NPC_DROPPED = 305,

WEDDING_PLEASE_ENTER_NAME = 318,
WEDDING_IS_ASKING_YOU_TO_MARRY = 319,
WEDDING_REGISTRATION_SERVICE = 320,
WEDDING_REQUEST_MARRIAGE_OR_DIVORCE = 321,
WEDDING_MARRIAGE = 322,
WEDDING_REQUEST_WEDDING_APPROVAL = 323,
WEDDING_DIVORCE = 324,
WEDDING_BREAK_UP = 325,
WEDDING_REQUEST_TEXT_1 = 326,
WEDDING_REQUEST_TEXT_2 = 327,
WEDDING_REQUEST_TEXT_LINK = 328,
WEDDING_DIVORCE_TEXT_1 = 329,
WEDDING_DIVORCE_TEXT_2 = 330,
WEDDING_DIVORCE_TEXT_LINK = 331,
WEDDING_PROMPT_ENTER_NAME_MARRY = 332,
WEDDING_PROMPT_ENTER_NAME_DIVORCE = 333,

SKILLMASTER_WORD_LEARN = 334,
SKILLMASTER_ITEMS_TO_LEARN = 335,
SKILLMASTER_WORD_FORGET = 336,
Expand Down
14 changes: 14 additions & 0 deletions EOLib/Domain/Interact/INPCInteractionNotifier.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using AutomaticTypeMapper;
using EOLib.Domain.Interact.Citizen;
using EOLib.Domain.Interact.Law;
using EOLib.Domain.Interact.Priest;
using EOLib.Domain.Interact.Skill;
using EOLib.IO;

Expand All @@ -22,6 +24,12 @@ public interface INPCInteractionNotifier
void NotifyCitizenSignUp(int questionsWrong);

void NotifyCitizenRequestSleep(int sleepCost);

void NotifyPriestReply(PriestReply reply);

void NotifyPriestRequest(string partnerName);

void NotifyMarriageReply(MarriageReply reply);
}

[AutoMappedType]
Expand All @@ -42,5 +50,11 @@ public void NotifyCitizenUnsubscribe(CitizenUnsubscribeReply reply) { }
public void NotifyCitizenSignUp(int questionsWrong) { }

public void NotifyCitizenRequestSleep(int sleepCost) { }

public void NotifyPriestReply(PriestReply reply) { }

public void NotifyPriestRequest(string partnerName) { }

public void NotifyMarriageReply(MarriageReply reply) { }
}
}
49 changes: 49 additions & 0 deletions EOLib/Domain/Interact/Law/LawActions.cs
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);
}
}
25 changes: 25 additions & 0 deletions EOLib/Domain/Interact/Law/LawSessionRepository.cs
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;
}
}
}
13 changes: 13 additions & 0 deletions EOLib/Domain/Interact/Law/MarriageReply.cs
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
}
}
8 changes: 8 additions & 0 deletions EOLib/Domain/Interact/Law/MarriageRequestType.cs
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
}
}
22 changes: 22 additions & 0 deletions EOLib/Domain/Interact/MapNPCActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ public void RequestInnkeeper(NPC.NPC npc)

_packetSendService.SendPacket(packet);
}

public void RequestLaw(NPC.NPC npc)
{
var packet = new PacketBuilder(PacketFamily.Marriage, PacketAction.Open)
.AddShort(npc.Index)
.Build();

_packetSendService.SendPacket(packet);
}

public void RequestPriest(NPC.NPC npc)
{
var packet = new PacketBuilder(PacketFamily.Priest, PacketAction.Open)
.AddInt(npc.Index)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IMapNPCActions
Expand All @@ -85,5 +103,9 @@ public interface IMapNPCActions
void RequestSkillmaster(NPC.NPC npc);

void RequestInnkeeper(NPC.NPC npc);

void RequestLaw(NPC.NPC npc);

void RequestPriest(NPC.NPC npc);
}
}
58 changes: 58 additions & 0 deletions EOLib/Domain/Interact/Priest/PriestActions.cs
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();
}
}
14 changes: 14 additions & 0 deletions EOLib/Domain/Interact/Priest/PriestReply.cs
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
}
}
25 changes: 25 additions & 0 deletions EOLib/Domain/Interact/Priest/PriestSessionRepository.cs
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;
}
}
}
40 changes: 40 additions & 0 deletions EOLib/PacketHandlers/Marriage/MarriageOpenHandler.cs
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;
}
}
}
49 changes: 49 additions & 0 deletions EOLib/PacketHandlers/Marriage/MarriageReplyHandler.cs
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;
}
}
}
Loading

0 comments on commit c7decf9

Please sign in to comment.