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

Guild administration menu #374

Merged
merged 13 commits into from
Oct 23, 2024
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
5 changes: 2 additions & 3 deletions EOLib.Localization/DialogResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public enum DialogResourceID
TRADE_OTHER_PLAYER_TRICK_YOU = 126,
GUILD_CREATE_TAG_FIELD_EMPTY = 128,
GUILD_CREATE_NAME_FIELD_EMPTY = 130,
GUILD_WRONG_INPUT = 132,
GUILD_CREATE_TAG_TOO_SHORT = 133,
GUILD_CREATE_TAG_TOO_SHORT = 132,
GUILD_CREATE_NAME_TOO_SHORT = 134,
GUILD_CREATE_NAME_NOT_APPROVED = 136,
GUILD_CREATE_NO_CANDIDATES = 138,
Expand All @@ -86,7 +85,7 @@ public enum DialogResourceID
GUILD_INVITATION = 152,
GUILD_INVITES_YOU_TO_JOIN = 153,
GUILD_TAG_NAME_LETTER_MUST_MATCH = 154,
GUILD_PROMPT_FOR_RECRUITER = 156,
GUILD_JOIN_GUILD = 156,
GUILD_PROMPT_LEAVE_GUILD = 158,
GUILD_RECRUITER_NOT_FOUND = 160,
GUILD_RECRUITER_NOT_HERE = 162,
Expand Down
20 changes: 16 additions & 4 deletions EOLib.Localization/EOResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,26 @@ public enum EOResourceID
GUILD_WITHDRAW_FUNDS_FROM_GUILD = 201,
GUILD_REMOVE_MEMBER = 202,
GUILD_REMOVE_A_MEMBER_FROM_GUILD = 203,

GUILD_YOU_ARE_ABOUT_TO_JOIN_A_GUILD = 204,
GUILD_JOINING_A_GUILD_IS_FREE = 205,

GUILD_PLEASE_CONSIDER_CAREFULLY = 207,
GUILD_DESCRIPTION = 219,

GUILD_CLICK_HERE_TO_JOIN_A_GUILD = 208,
GUILD_YOU_ARE_ABOUT_TO_LEAVE_THE_GUILD = 209,
GUILD_REMEMBER_THAT_AFTER_YOU_HAVE_LEFT_THE_GUILD = 210,
GUILD_CLICK_HERE_TO_LEAVE_YOUR_GUILD = 211,
GUILD_YOU_ARE_ABOUT_TO_CREATE_A_GUILD = 212,
GUILD_YOU_NEED_TO_HAVE_AT_LEAST_TEN_MEMBERS = 213,
GUILD_THE_GUILD_MASTER_WILL_ASK_A_FEE = 214,
GUILD_CLICK_HERE_TO_REGISTER_A_GUILD = 215,
GUILD_ENTER_YOUR_GUILD_DETAILS = 216,
GUILD_GUILD_TAG = 217,
GUILD_GUILD_NAME = 218,
GUILD_GUILD_DESCRIPTION = 219,

GUILD_PLEASE_WAIT_FOR_ALL_MEMBERS_TO_JOIN = 222,
GUILD_DO_YOU_ACCEPT = 223,

GUILD_RECRUITER = 224,
GUILD_YOUR_ACCOUNT_WILL_BE_CHARGED = 225,
GUILD_PLEASE_CONSIDER_CAREFULLY_RECRUIT = 226,
GUILD_TO_VIEW_INFORMATION_ABOUT_A_GUILD_ENTER_ITS_TAG = 227,
Expand Down
84 changes: 75 additions & 9 deletions EOLib/Domain/Interact/Guild/GuildActions.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
using AutomaticTypeMapper;
using System.Collections.Generic;
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Notifiers;
using EOLib.Net.Communication;
using Moffat.EndlessOnline.SDK.Protocol.Net.Client;
using Optional;

namespace EOLib.Domain.Interact.Guild
{
[AutoMappedType]
public class GuildActions : IGuildActions
{
private readonly IGuildSessionProvider _guildSessionProvider;
private readonly IGuildSessionRepository _guildSessionRepository;
private readonly IPacketSendService _packetSendService;
private readonly ICharacterRepository _characterRepository;

public GuildActions(IGuildSessionProvider guildSessionProvider,
IPacketSendService packetSendService)
public GuildActions(IGuildSessionRepository guildSessionRespository,
IPacketSendService packetSendService,
ICharacterRepository characterRepository)
{
_guildSessionProvider = guildSessionProvider;
_guildSessionRepository = guildSessionRespository;
_packetSendService = packetSendService;
_characterRepository = characterRepository;
}

public void Lookup(string identity)
{
_packetSendService.SendPacket(new GuildReportClientPacket { SessionId = _guildSessionProvider.SessionID, GuildIdentity = identity });
_packetSendService.SendPacket(new GuildReportClientPacket { SessionId = _guildSessionRepository.SessionID, GuildIdentity = identity });
}

public void ViewMembers(string identity)
{
_packetSendService.SendPacket(new GuildTellClientPacket { SessionId = _guildSessionProvider.SessionID, GuildIdentity = identity });
_packetSendService.SendPacket(new GuildTellClientPacket { SessionId = _guildSessionRepository.SessionID, GuildIdentity = identity });
}

public void GetGuildDescription(string guildTag)
{
_packetSendService.SendPacket(new GuildTakeClientPacket
{
SessionId = _guildSessionProvider.SessionID,
SessionId = _guildSessionRepository.SessionID,
InfoType = GuildInfoType.Description,
GuildTag = guildTag
});
Expand All @@ -41,14 +48,63 @@ public void SetGuildDescription(string description)
{
_packetSendService.SendPacket(new GuildAgreeClientPacket()
{
SessionId = _guildSessionProvider.SessionID,
SessionId = _guildSessionRepository.SessionID,
InfoType = GuildInfoType.Description,
InfoTypeData = new GuildAgreeClientPacket.InfoTypeDataDescription()
{
Description = description
}
});
}

public void RequestToJoinGuild(string guildTag, string recruiterName)
{
_packetSendService.SendPacket(new GuildPlayerClientPacket { SessionId = _guildSessionRepository.SessionID, GuildTag = guildTag, RecruiterName = recruiterName });
}

public void LeaveGuild()
{
_packetSendService.SendPacket(new GuildRemoveClientPacket { SessionId = _guildSessionRepository.SessionID });
_characterRepository.MainCharacter = _characterRepository.MainCharacter
.WithGuildTag(" ")
.WithGuildName(string.Empty)
.WithGuildRank(string.Empty);
}

public void RequestToCreateGuild(string guildTag, string guildName, string guildDescription)
{
_guildSessionRepository.CreationSession = Option.Some(
new GuildCreationSession.Builder
{
Tag = guildTag,
Name = guildName,
Description = guildDescription,
Members = new HashSet<string>()
}.ToImmutable());

_packetSendService.SendPacket(new GuildRequestClientPacket
{
SessionId = _guildSessionRepository.SessionID,
GuildTag = guildTag,
GuildName = guildName,
});
}

public void ConfirmGuildCreate(GuildCreationSession creationSession)
{
_packetSendService.SendPacket(new GuildCreateClientPacket
{
SessionId = _guildSessionRepository.SessionID,
GuildTag = creationSession.Tag,
GuildName = creationSession.Name,
Description = creationSession.Description,
});
}

public void CancelGuildCreate()
{
_guildSessionRepository.CreationSession = Option.None<GuildCreationSession>();
}
}

public interface IGuildActions
Expand All @@ -60,5 +116,15 @@ public interface IGuildActions
void GetGuildDescription(string guildTag);

void SetGuildDescription(string description);

void RequestToJoinGuild(string guildTag, string recruiterName);

void LeaveGuild();

void RequestToCreateGuild(string guildTag, string guildName, string guildDescription);

void ConfirmGuildCreate(GuildCreationSession creationSession);

void CancelGuildCreate();
}
}
19 changes: 19 additions & 0 deletions EOLib/Domain/Interact/Guild/GuildCreationSession.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using Amadevus.RecordGenerator;

namespace EOLib.Domain.Interact.Guild
{
[Record]
public sealed partial class GuildCreationSession
{
public string Tag { get; }

public string Name { get; }

public string Description { get; }

public IReadOnlyCollection<string> Members { get; } = new HashSet<string>();

public bool Approved { get; }
}
}
9 changes: 8 additions & 1 deletion EOLib/Domain/Interact/Guild/GuildSessionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface IGuildSessionProvider
{
int SessionID { get; }

Option<GuildCreationSession> CreationSession { get; }

string GuildDescription { get; }

Option<GuildInfo> GuildInfo { get; }
Expand All @@ -20,9 +22,11 @@ public interface IGuildSessionRepository : IResettable
{
int SessionID { get; set; }

Option<GuildCreationSession> CreationSession { get; set; }

string GuildDescription { get; set; }

Option<GuildInfo >GuildInfo { get; set; }
Option<GuildInfo> GuildInfo { get; set; }

List<GuildMember> GuildMembers { get; set; }
}
Expand All @@ -32,6 +36,8 @@ public class GuildSessionRepository : IGuildSessionRepository, IGuildSessionProv
{
public int SessionID { get; set; }

public Option<GuildCreationSession> CreationSession { get; set; }

public string GuildDescription { get; set; }

public Option<GuildInfo> GuildInfo { get; set; }
Expand All @@ -48,6 +54,7 @@ public GuildSessionRepository()
public void ResetState()
{
SessionID = 0;
CreationSession = Option.None<GuildCreationSession>();
GuildDescription = string.Empty;
GuildInfo = Option.None<GuildInfo>();
GuildMembers = new List<GuildMember>();
Expand Down
3 changes: 3 additions & 0 deletions EOLib/Domain/Notifiers/IGuildNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface IGuildNotifier
void NotifyRequestToJoinGuild(int playerId, string name);

void NotifyGuildReply(GuildReply reply);

void NotifyConfirmCreateGuild();
}

[AutoMappedType]
Expand All @@ -18,5 +20,6 @@ public class NoOpGuildNotifier : IGuildNotifier
public void NotifyGuildCreationRequest(int creatorPlayerID, string guildIdentity) { }
public void NotifyRequestToJoinGuild(int playerId, string name) { }
public void NotifyGuildReply(GuildReply reply) { }
public void NotifyConfirmCreateGuild() { }
}
}
50 changes: 50 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildAgreeHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Domain.Notifiers;
using EOLib.Net.Handlers;
using Moffat.EndlessOnline.SDK.Protocol.Net;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;

namespace EOLib.PacketHandlers.Guild
{
[AutoMappedType]

public class GuildAgreeHandler : InGameOnlyPacketHandler<GuildAgreeServerPacket>
{
private const byte JoinGuildSfx = 18;
ethanmoffat marked this conversation as resolved.
Show resolved Hide resolved

private readonly ICharacterRepository _characterRepository;
private readonly IEnumerable<IGuildNotifier> _guildNotifiers;
private readonly IEnumerable<ISoundNotifier> _soundNotifiers;

public override PacketFamily Family => PacketFamily.Guild;

public override PacketAction Action => PacketAction.Agree;

public GuildAgreeHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterRepository characterRepository,
IEnumerable<IGuildNotifier> guildNotifiers,
IEnumerable<ISoundNotifier> soundNotifiers)
: base(playerInfoProvider)
{
_characterRepository = characterRepository;
_guildNotifiers = guildNotifiers;
_soundNotifiers = soundNotifiers;
}

public override bool HandlePacket(GuildAgreeServerPacket packet)
{
_characterRepository.MainCharacter = _characterRepository.MainCharacter
.WithGuildTag(packet.GuildTag)
.WithGuildName(packet.GuildName)
.WithGuildRank(packet.RankName);

foreach (var notifier in _soundNotifiers)
notifier.NotifySoundEffect(JoinGuildSfx);

return true;
}
}
}
61 changes: 61 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildCreateHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections.Generic;
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Interact.Guild;
using EOLib.Domain.Login;
using EOLib.Domain.Notifiers;
using EOLib.Net.Handlers;
using Moffat.EndlessOnline.SDK.Protocol.Net;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;
using Optional;

namespace EOLib.PacketHandlers.Guild
{
[AutoMappedType]

public class GuildCreateHandler : InGameOnlyPacketHandler<GuildCreateServerPacket>
{
private const byte JoinGuildSfx = 18;
ethanmoffat marked this conversation as resolved.
Show resolved Hide resolved

private readonly ICharacterRepository _characterRepository;
private readonly IGuildSessionRepository _guildSessionRepository;
private readonly ICharacterInventoryRepository _characterInventoryRepository;
private readonly IEnumerable<ISoundNotifier> _soundNotifiers;

public override PacketFamily Family => PacketFamily.Guild;

public override PacketAction Action => PacketAction.Create;

public GuildCreateHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterRepository characterRepository,
IGuildSessionRepository guildSessionRepository,
ICharacterInventoryRepository characterInventoryRepository,
IEnumerable<ISoundNotifier> soundNotifiers)
: base(playerInfoProvider)
{
_characterRepository = characterRepository;
_guildSessionRepository = guildSessionRepository;
_characterInventoryRepository = characterInventoryRepository;
_soundNotifiers = soundNotifiers;
}

public override bool HandlePacket(GuildCreateServerPacket packet)
{
var gold = new InventoryItem(1, packet.GoldAmount);
_characterInventoryRepository.ItemInventory.RemoveWhere(x => x.ItemID == 1);
ethanmoffat marked this conversation as resolved.
Show resolved Hide resolved
_characterInventoryRepository.ItemInventory.Add(gold);

_characterRepository.MainCharacter = _characterRepository.MainCharacter
.WithGuildTag(packet.GuildTag)
.WithGuildName(packet.GuildName)
.WithGuildRank(packet.RankName);

_guildSessionRepository.CreationSession = Option.None<GuildCreationSession>();

foreach (var notifier in _soundNotifiers)
notifier.NotifySoundEffect(JoinGuildSfx);

return true;
}
}
}
Loading