Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement law dialog (marriage registration/divorce) and marriage (interaction with priest) #321

Merged
merged 6 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 6 additions & 2 deletions EOLib/Domain/Chat/ChatData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ public sealed partial class ChatData

public bool Log { get; }

public bool Filter { get; }

public ChatData(ChatTab tab,
string who,
string message,
ChatIcon icon = ChatIcon.None,
ChatColor chatColor = ChatColor.Default,
bool log = true)
bool log = true,
bool filter = true)
{
if (who == null)
who = "";
Expand All @@ -41,13 +44,14 @@ public ChatData(ChatTab tab,
Message = message;
ChatColor = chatColor;
Log = log;
Filter = filter;

ChatTime = DateTime.Now;
}

public ChatData WithMessage(string message)
{
return new ChatData(Tab, Who, message, Icon, ChatColor, Log);
return new ChatData(Tab, Who, message, Icon, ChatColor, Log, Filter);
}
}
}
2 changes: 1 addition & 1 deletion EOLib/Domain/Chat/LoggingList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public LoggingList(IConfigurationProvider configurationProvider,

public void Add(ChatData item)
{
if (_configurationProvider.CurseFilterEnabled || _configurationProvider.StrictFilterEnabled)
if (item.Filter && (_configurationProvider.CurseFilterEnabled || _configurationProvider.StrictFilterEnabled))
{
var (ok, filtered) = _chatProcessor.FilterCurses(item.Message);
if (!ok)
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;
}
}
}
7 changes: 4 additions & 3 deletions EOLib/PacketHandlers/Chat/GroupChatHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public class GroupChatHandler : PlayerChatByIDHandler

public override PacketAction Action => PacketAction.Open;

public GroupChatHandler(ICurrentMapStateProvider currentMapStateProvider,
IPlayerInfoProvider playerInfoProvider,
public GroupChatHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateProvider currentMapStateProvider,
ICharacterProvider characterProvider,
IChatRepository chatRepository,
IEnumerable<IOtherCharacterEventNotifier> otherCharacterEventNotifiers,
IEnumerable<IChatEventNotifier> chatEventNotifiers)
: base(currentMapStateProvider, playerInfoProvider)
: base(playerInfoProvider, currentMapStateProvider, characterProvider)
{
_chatRepository = chatRepository;
_otherCharacterEventNotifiers = otherCharacterEventNotifiers;
Expand Down
18 changes: 14 additions & 4 deletions EOLib/PacketHandlers/Chat/PlayerChatByIDHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,31 @@ namespace EOLib.PacketHandlers.Chat
public abstract class PlayerChatByIDHandler : InGameOnlyPacketHandler
{
private readonly ICurrentMapStateProvider _currentMapStateProvider;
private readonly ICharacterProvider _characterProvider;

public override PacketFamily Family => PacketFamily.Talk;

protected PlayerChatByIDHandler(ICurrentMapStateProvider currentMapStateProvider,
IPlayerInfoProvider playerInfoProvider)
protected PlayerChatByIDHandler(IPlayerInfoProvider playerInfoProvider,
ICurrentMapStateProvider currentMapStateProvider,
ICharacterProvider characterProvider)
: base(playerInfoProvider)
{
_currentMapStateProvider = currentMapStateProvider;
_characterProvider = characterProvider;
}

public override bool HandlePacket(IPacket packet)
{
var fromPlayerID = packet.ReadShort();
if (!_currentMapStateProvider.Characters.TryGetValue(fromPlayerID, out var character))
return false;
if (!_currentMapStateProvider.Characters.TryGetValue(fromPlayerID, out var character) &&
_characterProvider.MainCharacter.ID != fromPlayerID)
{
_currentMapStateProvider.UnknownPlayerIDs.Add(fromPlayerID);
return true;
}

if (_characterProvider.MainCharacter.ID == fromPlayerID)
character = _characterProvider.MainCharacter;

DoTalk(packet, character);

Expand Down
Loading