From 8deaf27007506a1d2b08553ecf8f2ee5e5bb1686 Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Fri, 25 Oct 2024 21:58:34 -0700 Subject: [PATCH] Implement Kick Member; fixup Guild Accept (#386) * Add overload to EOMessageBoxFactory for dialog resource ID, prepend, and append data. Use for guild create/join dialog messages. * Fix casing for guild display * Implement Guild Remove action in GuildDialog * More complete handling for accepting member into guild * Use Capitalize() extension method in more places * Use Capitalize method in even more places --- EOLib.Localization/DialogResourceID.cs | 4 +- EOLib.Localization/EOResourceID.cs | 5 +- EOLib/Domain/Interact/Guild/GuildActions.cs | 15 +++++ .../Interact/Guild/GuildSessionRepository.cs | 9 ++- EOLib/Domain/Login/LoginActions.cs | 15 ++--- EOLib/Domain/Notifiers/IGuildNotifier.cs | 3 + EOLib/Extensions/StringExtensions.cs | 16 +++++ .../PacketHandlers/Guild/GuildAgreeHandler.cs | 18 +++--- .../Guild/GuildCreateHandler.cs | 7 ++- .../PacketHandlers/Guild/GuildKickHandler.cs | 36 +++++++++++ .../PacketHandlers/Guild/GuildReplyHandler.cs | 4 ++ EndlessClient/Audio/SoundEffectID.cs | 1 + .../Dialogs/Factories/EOMessageBoxFactory.cs | 17 ++++++ .../Dialogs/Factories/IEOMessageBoxFactory.cs | 6 ++ EndlessClient/Dialogs/GuildDialog.cs | 46 +++++++++++++-- .../Subscribers/GuildEventSubscriber.cs | 59 ++++++++++++------- 16 files changed, 207 insertions(+), 54 deletions(-) create mode 100644 EOLib/Extensions/StringExtensions.cs create mode 100644 EOLib/PacketHandlers/Guild/GuildKickHandler.cs diff --git a/EOLib.Localization/DialogResourceID.cs b/EOLib.Localization/DialogResourceID.cs index 584aaa7fd..0958fb6d3 100644 --- a/EOLib.Localization/DialogResourceID.cs +++ b/EOLib.Localization/DialogResourceID.cs @@ -82,8 +82,7 @@ public enum DialogResourceID GUILD_TAG_OR_NAME_ALREADY_EXISTS = 146, GUILD_WILL_BE_CREATED = 148, GUILD_MASTER_IS_BUSY = 150, - GUILD_INVITATION = 152, - GUILD_INVITES_YOU_TO_JOIN = 153, + GUILD_INVITATION_INVITES_YOU = 152, GUILD_TAG_NAME_LETTER_MUST_MATCH = 154, GUILD_JOIN_GUILD = 156, GUILD_PROMPT_LEAVE_GUILD = 158, @@ -93,7 +92,6 @@ public enum DialogResourceID GUILD_RECRUITER_RANK_TOO_LOW = 166, GUILD_RECRUITER_INPUT_MISSING = 168, GUILD_PLAYER_WANTS_TO_JOIN = 170, - GUILD_REQUESTED_TO_JOIN = 171, GUILD_BANK_ACCOUNT_LOW = 172, GUILD_MEMBER_HAS_BEEN_ACCEPTED = 174, GUILD_DOES_NOT_EXIST = 176, diff --git a/EOLib.Localization/EOResourceID.cs b/EOLib.Localization/EOResourceID.cs index 2297e1a88..597ee6b1d 100644 --- a/EOLib.Localization/EOResourceID.cs +++ b/EOLib.Localization/EOResourceID.cs @@ -226,7 +226,10 @@ public enum EOResourceID GUILD_DISBAND_DESCRIPTION_1 = 237, GUILD_DISBAND_DESCRIPTION_2 = 238, GUILD_DISBAND_DESCRIPTION_3 = 239, - + GUILD_REMOVE_MEMBER_DESCRIPTION_1 = 240, + GUILD_REMOVE_MEMBER_DESCRIPTION_2 = 241, + GUILD_REMOVE_MEMBER_DESCRIPTION_3 = 242, + GUILD_WHO_DO_YOU_WANT_TO_REMOVE = 243, GUILD_BANK_STATUS = 244, GUILD_BANK_DESCRIPTION_1 = 245, GUILD_BANK_DESCRIPTION_2 = 246, diff --git a/EOLib/Domain/Interact/Guild/GuildActions.cs b/EOLib/Domain/Interact/Guild/GuildActions.cs index 75aed9573..2acd84539 100644 --- a/EOLib/Domain/Interact/Guild/GuildActions.cs +++ b/EOLib/Domain/Interact/Guild/GuildActions.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using AutomaticTypeMapper; using EOLib.Domain.Character; +using EOLib.Extensions; using EOLib.Net.Communication; using Moffat.EndlessOnline.SDK.Protocol.Net.Client; using Optional; @@ -124,6 +125,17 @@ public void CancelGuildCreate() _guildSessionRepository.CreationSession = Option.None(); } + public void KickMember(string member) + { + _guildSessionRepository.RemoveCandidate = member.Capitalize(); + + _packetSendService.SendPacket(new GuildKickClientPacket + { + SessionId = _guildSessionRepository.SessionID, + MemberName = member + }); + } + public void DisbandGuild() { _packetSendService.SendPacket(new GuildJunkClientPacket { SessionId = _guildSessionRepository.SessionID }); @@ -153,6 +165,9 @@ public interface IGuildActions void ConfirmGuildCreate(GuildCreationSession creationSession); void CancelGuildCreate(); + + void KickMember(string responseText); + void DisbandGuild(); } } diff --git a/EOLib/Domain/Interact/Guild/GuildSessionRepository.cs b/EOLib/Domain/Interact/Guild/GuildSessionRepository.cs index 43ff5766c..a790d9fdd 100644 --- a/EOLib/Domain/Interact/Guild/GuildSessionRepository.cs +++ b/EOLib/Domain/Interact/Guild/GuildSessionRepository.cs @@ -18,6 +18,8 @@ public interface IGuildSessionProvider Option GuildInfo { get; } IReadOnlyList GuildMembers { get; } + + string RemoveCandidate { get; } } public interface IGuildSessionRepository : IResettable @@ -33,6 +35,8 @@ public interface IGuildSessionRepository : IResettable Option GuildInfo { get; set; } List GuildMembers { get; set; } + + string RemoveCandidate { get; set; } } [AutoMappedType(IsSingleton = true)] @@ -48,7 +52,9 @@ public class GuildSessionRepository : IGuildSessionRepository, IGuildSessionProv public Option GuildInfo { get; set; } - public List GuildMembers { get; set; } + public List GuildMembers { get; set; } + + public string RemoveCandidate { get; set; } IReadOnlyList IGuildSessionProvider.GuildMembers => GuildMembers; @@ -65,6 +71,7 @@ public void ResetState() GuildBalance = 0; GuildInfo = Option.None(); GuildMembers = new List(); + RemoveCandidate = string.Empty; } } } diff --git a/EOLib/Domain/Login/LoginActions.cs b/EOLib/Domain/Login/LoginActions.cs index 98f18c94a..c62697c12 100644 --- a/EOLib/Domain/Login/LoginActions.cs +++ b/EOLib/Domain/Login/LoginActions.cs @@ -6,6 +6,7 @@ using EOLib.Domain.Character; using EOLib.Domain.Extensions; using EOLib.Domain.Map; +using EOLib.Extensions; using EOLib.IO; using EOLib.Net; using EOLib.Net.Communication; @@ -94,11 +95,11 @@ public async Task RequestCharacterLogin(Character.Character character) _characterRepository.MainCharacter = character .WithID(data.CharacterId) - .WithName(char.ToUpper(data.Name[0]) + data.Name.Substring(1)) + .WithName(data.Name.Capitalize()) .WithTitle(data.Title) - .WithGuildName(data.GuildName) - .WithGuildRank(data.GuildRankName) - .WithGuildTag(data.GuildTag) + .WithGuildName(data.GuildName.Capitalize()) + .WithGuildRank(data.GuildRankName.Capitalize()) + .WithGuildTag(data.GuildTag.ToUpper()) .WithClassID(data.ClassId) .WithMapID(data.MapId) .WithAdminLevel(data.Admin) @@ -111,10 +112,10 @@ public async Task RequestCharacterLogin(Character.Character character) _currentMapStateRepository.JailMapID = data.Settings.JailMap; _paperdollRepository.VisibleCharacterPaperdolls[data.SessionId] = new PaperdollData() - .WithName(char.ToUpper(data.Name[0]) + data.Name.Substring(1)) + .WithName(data.Name.Capitalize()) .WithTitle(data.Title) - .WithGuild(data.GuildName) - .WithRank(data.GuildRankName) + .WithGuild(data.GuildName.Capitalize()) + .WithRank(data.GuildRankName.Capitalize()) .WithClass(data.ClassId) .WithPlayerID(data.SessionId) .WithPaperdoll(data.Equipment.GetPaperdoll()); diff --git a/EOLib/Domain/Notifiers/IGuildNotifier.cs b/EOLib/Domain/Notifiers/IGuildNotifier.cs index f4c0268d7..8ee9dbe40 100644 --- a/EOLib/Domain/Notifiers/IGuildNotifier.cs +++ b/EOLib/Domain/Notifiers/IGuildNotifier.cs @@ -14,6 +14,8 @@ public interface IGuildNotifier void NotifyConfirmCreateGuild(); void NotifyNewGuildBankBalance(int balance); + + void NotifyAcceptedIntoGuild(); } [AutoMappedType] @@ -24,5 +26,6 @@ public void NotifyRequestToJoinGuild(int playerId, string name) { } public void NotifyGuildReply(GuildReply reply) { } public void NotifyConfirmCreateGuild() { } public void NotifyNewGuildBankBalance(int balance) { } + public void NotifyAcceptedIntoGuild() { } } } diff --git a/EOLib/Extensions/StringExtensions.cs b/EOLib/Extensions/StringExtensions.cs new file mode 100644 index 000000000..a3dd64e8b --- /dev/null +++ b/EOLib/Extensions/StringExtensions.cs @@ -0,0 +1,16 @@ +namespace EOLib.Extensions +{ + public static class StringExtensions + { + public static string Capitalize(this string str) + { + if (string.IsNullOrWhiteSpace(str)) + return str; + + if (str.Length == 1) + return str.ToUpperInvariant(); + + return char.ToUpperInvariant(str[0]) + str.Substring(1).ToLowerInvariant(); + } + } +} diff --git a/EOLib/PacketHandlers/Guild/GuildAgreeHandler.cs b/EOLib/PacketHandlers/Guild/GuildAgreeHandler.cs index 04a4ba70a..2932366c4 100644 --- a/EOLib/PacketHandlers/Guild/GuildAgreeHandler.cs +++ b/EOLib/PacketHandlers/Guild/GuildAgreeHandler.cs @@ -3,6 +3,7 @@ using EOLib.Domain.Character; using EOLib.Domain.Login; using EOLib.Domain.Notifiers; +using EOLib.Extensions; using EOLib.Net.Handlers; using Moffat.EndlessOnline.SDK.Protocol.Net; using Moffat.EndlessOnline.SDK.Protocol.Net.Server; @@ -13,11 +14,8 @@ namespace EOLib.PacketHandlers.Guild public class GuildAgreeHandler : InGameOnlyPacketHandler { - private const byte JoinGuildSfx = 18; - private readonly ICharacterRepository _characterRepository; private readonly IEnumerable _guildNotifiers; - private readonly IEnumerable _soundNotifiers; public override PacketFamily Family => PacketFamily.Guild; @@ -25,24 +23,22 @@ public class GuildAgreeHandler : InGameOnlyPacketHandler public GuildAgreeHandler(IPlayerInfoProvider playerInfoProvider, ICharacterRepository characterRepository, - IEnumerable guildNotifiers, - IEnumerable soundNotifiers) + IEnumerable guildNotifiers) : 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); + .WithGuildTag(packet.GuildTag.ToUpper()) + .WithGuildName(packet.GuildName.Capitalize()) + .WithGuildRank(packet.RankName.Capitalize()); - foreach (var notifier in _soundNotifiers) - notifier.NotifySoundEffect(JoinGuildSfx); + foreach (var notifier in _guildNotifiers) + notifier.NotifyAcceptedIntoGuild(); return true; } diff --git a/EOLib/PacketHandlers/Guild/GuildCreateHandler.cs b/EOLib/PacketHandlers/Guild/GuildCreateHandler.cs index 89bc68a3a..d2de5ef35 100644 --- a/EOLib/PacketHandlers/Guild/GuildCreateHandler.cs +++ b/EOLib/PacketHandlers/Guild/GuildCreateHandler.cs @@ -4,6 +4,7 @@ using EOLib.Domain.Interact.Guild; using EOLib.Domain.Login; using EOLib.Domain.Notifiers; +using EOLib.Extensions; using EOLib.Net.Handlers; using Moffat.EndlessOnline.SDK.Protocol.Net; using Moffat.EndlessOnline.SDK.Protocol.Net.Server; @@ -46,9 +47,9 @@ public override bool HandlePacket(GuildCreateServerPacket packet) _characterInventoryRepository.ItemInventory.Add(gold); _characterRepository.MainCharacter = _characterRepository.MainCharacter - .WithGuildTag(packet.GuildTag) - .WithGuildName(packet.GuildName) - .WithGuildRank(packet.RankName); + .WithGuildTag(packet.GuildTag.ToUpper()) + .WithGuildName(packet.GuildName.Capitalize()) + .WithGuildRank(packet.RankName.Capitalize()); _guildSessionRepository.CreationSession = Option.None(); diff --git a/EOLib/PacketHandlers/Guild/GuildKickHandler.cs b/EOLib/PacketHandlers/Guild/GuildKickHandler.cs new file mode 100644 index 000000000..c1c492378 --- /dev/null +++ b/EOLib/PacketHandlers/Guild/GuildKickHandler.cs @@ -0,0 +1,36 @@ +using AutomaticTypeMapper; +using EOLib.Domain.Character; +using EOLib.Domain.Login; +using EOLib.Net.Handlers; +using Moffat.EndlessOnline.SDK.Protocol.Net; +using Moffat.EndlessOnline.SDK.Protocol.Net.Server; + +namespace EOLib.PacketHandlers.Guild +{ + [AutoMappedType] + + public class GuildKickHandler : InGameOnlyPacketHandler + { + private readonly ICharacterRepository _characterRepository; + + public override PacketFamily Family => PacketFamily.Guild; + + public override PacketAction Action => PacketAction.Kick; + + public GuildKickHandler(IPlayerInfoProvider playerInfoProvider, + ICharacterRepository characterRepository) + : base(playerInfoProvider) + { + _characterRepository = characterRepository; + } + + public override bool HandlePacket(GuildKickServerPacket packet) + { + _characterRepository.MainCharacter = _characterRepository.MainCharacter + .WithGuildTag(" ") + .WithGuildName(string.Empty) + .WithGuildRank(string.Empty); + return true; + } + } +} diff --git a/EOLib/PacketHandlers/Guild/GuildReplyHandler.cs b/EOLib/PacketHandlers/Guild/GuildReplyHandler.cs index 33ea4e70f..3a3a24f26 100644 --- a/EOLib/PacketHandlers/Guild/GuildReplyHandler.cs +++ b/EOLib/PacketHandlers/Guild/GuildReplyHandler.cs @@ -50,6 +50,10 @@ public override bool HandlePacket(GuildReplyServerPacket packet) case GuildReply.Exists: case GuildReply.NoCandidates: case GuildReply.Busy: + case GuildReply.RemoveLeader: + case GuildReply.RemoveNotMember: + case GuildReply.Removed: + case GuildReply.Accepted: { foreach (var notifier in _guildNotifiers) notifier.NotifyGuildReply(packet.ReplyCode); diff --git a/EndlessClient/Audio/SoundEffectID.cs b/EndlessClient/Audio/SoundEffectID.cs index cfbdecfea..d2c98de96 100644 --- a/EndlessClient/Audio/SoundEffectID.cs +++ b/EndlessClient/Audio/SoundEffectID.cs @@ -33,6 +33,7 @@ public enum SoundEffectID TradeAccepted, JoinParty = TradeAccepted, GroupChatReceived, + JoinGuild = GroupChatReceived, PrivateMessageSent, InventoryPickup = 20, InventoryPlace, diff --git a/EndlessClient/Dialogs/Factories/EOMessageBoxFactory.cs b/EndlessClient/Dialogs/Factories/EOMessageBoxFactory.cs index 5b111cb19..cda836481 100644 --- a/EndlessClient/Dialogs/Factories/EOMessageBoxFactory.cs +++ b/EndlessClient/Dialogs/Factories/EOMessageBoxFactory.cs @@ -1,3 +1,4 @@ +using System.Text; using AutomaticTypeMapper; using EndlessClient.Audio; using EndlessClient.Dialogs.Services; @@ -89,6 +90,22 @@ public IXNADialog CreateMessageBox(DialogResourceID resource, style); } + public IXNADialog CreateMessageBox(string prependData, + DialogResourceID resource, + EODialogButtons whichButtons = EODialogButtons.Ok, + EOMessageBoxStyle style = EOMessageBoxStyle.SmallDialogSmallHeader, + params EOResourceID[] appendResources) + { + var message = new StringBuilder(prependData); + message.Append(_localizedStringFinder.GetString(resource + 1)); + foreach (var resourceId in appendResources) + message.Append(" " + _localizedStringFinder.GetString(resourceId)); + return CreateMessageBox(message.ToString(), + _localizedStringFinder.GetString(resource), + whichButtons, + style); + } + public IXNADialog CreateMessageBox(EOResourceID message, EOResourceID caption, EODialogButtons whichButtons = EODialogButtons.Ok, diff --git a/EndlessClient/Dialogs/Factories/IEOMessageBoxFactory.cs b/EndlessClient/Dialogs/Factories/IEOMessageBoxFactory.cs index e0b4c81c7..f9908ece0 100644 --- a/EndlessClient/Dialogs/Factories/IEOMessageBoxFactory.cs +++ b/EndlessClient/Dialogs/Factories/IEOMessageBoxFactory.cs @@ -24,6 +24,12 @@ IXNADialog CreateMessageBox(DialogResourceID resource, EODialogButtons whichButtons = EODialogButtons.Ok, EOMessageBoxStyle style = EOMessageBoxStyle.SmallDialogSmallHeader); + IXNADialog CreateMessageBox(string prependData, + DialogResourceID resource, + EODialogButtons whichButtons = EODialogButtons.Ok, + EOMessageBoxStyle style = EOMessageBoxStyle.SmallDialogSmallHeader, + params EOResourceID[] appendResources); + IXNADialog CreateMessageBox(EOResourceID message, EOResourceID caption, EODialogButtons whichButtons = EODialogButtons.Ok, diff --git a/EndlessClient/Dialogs/GuildDialog.cs b/EndlessClient/Dialogs/GuildDialog.cs index ef928b267..4ec42b3ae 100644 --- a/EndlessClient/Dialogs/GuildDialog.cs +++ b/EndlessClient/Dialogs/GuildDialog.cs @@ -8,6 +8,7 @@ using EOLib; using EOLib.Domain.Character; using EOLib.Domain.Interact.Guild; +using EOLib.Extensions; using EOLib.Graphics; using EOLib.IO.Repositories; using EOLib.Localization; @@ -103,6 +104,7 @@ private State(GuildDialogState dialogState) case GuildDialogState.LeaveGuild: case GuildDialogState.RegisterGuild: case GuildDialogState.WaitingForMembers: + case GuildDialogState.RemoveMember: case GuildDialogState.BankAccount: ListItemStyle = ListDialogItem.ListItemStyle.Small; break; @@ -205,6 +207,7 @@ public GuildDialog(INativeGraphicsManager nativeGraphicsManager, // Management state transitions { State.Modify, SetupModifyState }, // TODO: ranking states + { State.RemoveMember, SetupRemoveMemberState }, { State.Disband, SetupDisbandState }, }; @@ -252,7 +255,7 @@ protected override void OnUnconditionalUpdateControl(GameTime gameTime) _cachedMembers = _guildSessionProvider.GuildMembers.ToHashSet(); AddTextAsKeyValueListItems( - _cachedMembers.Select(x => ($"{x.Rank} {x.Name}", Capitalize(x.RankName))).ToArray() + _cachedMembers.Select(x => ($"{x.Rank} {x.Name}", x.RankName.Capitalize())).ToArray() ); } break; @@ -323,7 +326,7 @@ void CacheAndSetGuildInfo(GuildInfo guildInfo) guildInfo.Wealth, " ", _localizedStringFinder.GetString(EOResourceID.GUILD_RANKING_SYSTEM), - string.Join("\n", guildInfo.Ranks.Select((x, n) => $"{n + 1} {Capitalize(x)}")), + string.Join("\n", guildInfo.Ranks.Select((x, n) => $"{n + 1} {x.Capitalize()}")), " ", _localizedStringFinder.GetString(EOResourceID.GUILD_LEADERS), string.Join("\n", guildInfo.Staff.Select(x => $"{x.Name}{(x.Rank == 0 ? " (founder)" : string.Empty)}")), @@ -694,7 +697,7 @@ private void SetupWaitingForMembersState() new List { }, _localizedStringFinder.GetString(EOResourceID.GUILD_PLEASE_WAIT_FOR_ALL_MEMBERS_TO_JOIN), " ", - Capitalize(_characterProvider.MainCharacter.Name) + _characterProvider.MainCharacter.Name.Capitalize() ); } @@ -729,6 +732,40 @@ void ShowChangeDescriptionMessageBox() } } + private void SetupRemoveMemberState() + { + AddTextAsListItems( + _contentProvider.Fonts[Constants.FontSize08pt5], + insertLineBreaks: true, + new List { ShowRemoveMemberInputBox }, + _localizedStringFinder.GetString(EOResourceID.GUILD_REMOVE_MEMBER), + _localizedStringFinder.GetString(EOResourceID.GUILD_REMOVE_MEMBER_DESCRIPTION_1), + _localizedStringFinder.GetString(EOResourceID.GUILD_REMOVE_MEMBER_DESCRIPTION_2), + _localizedStringFinder.GetString(EOResourceID.GUILD_REMOVE_MEMBER_DESCRIPTION_3) + ); + + void ShowRemoveMemberInputBox() + { + var removeMemberInput = _textInputDialogFactory.Create(_localizedStringFinder.GetString(EOResourceID.GUILD_WHO_DO_YOU_WANT_TO_REMOVE)); + removeMemberInput.DialogClosing += (_, e) => + { + if (e.Result == XNADialogResult.OK) + { + if (removeMemberInput.ResponseText.Length < 4) + { + e.Cancel = true; + var tooShortDlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.CHARACTER_CREATE_NAME_TOO_SHORT); + tooShortDlg.ShowDialog(); + return; + } + + _guildActions.KickMember(removeMemberInput.ResponseText); + } + }; + removeMemberInput.ShowDialog(); + } + } + private void SetupDisbandState() { AddTextAsListItems( @@ -935,8 +972,5 @@ private void SetStateIfNotInGuild(State state) SetState(state); } - - private static string Capitalize(string input) => - string.IsNullOrEmpty(input) ? string.Empty : char.ToUpper(input[0]) + input[1..].ToLower(); } } diff --git a/EndlessClient/Subscribers/GuildEventSubscriber.cs b/EndlessClient/Subscribers/GuildEventSubscriber.cs index e009cc592..ddad0d2de 100644 --- a/EndlessClient/Subscribers/GuildEventSubscriber.cs +++ b/EndlessClient/Subscribers/GuildEventSubscriber.cs @@ -18,7 +18,6 @@ public class GuildEventSubscriber : IGuildNotifier { private readonly IEOMessageBoxFactory _messageBoxFactory; private readonly IGuildActions _guildActions; - private readonly ILocalizedStringFinder _localizedStringFinder; private readonly IPacketSendService _packetSendService; private readonly ISfxPlayer _sfxPlayer; private readonly IGuildSessionProvider _guildSessionProvider; @@ -26,7 +25,6 @@ public class GuildEventSubscriber : IGuildNotifier public GuildEventSubscriber(IEOMessageBoxFactory messageBoxFactory, IGuildActions guildActions, - ILocalizedStringFinder localizedStringFinder, IPacketSendService packetSendService, ISfxPlayer sfxPlayer, IGuildSessionProvider guildSessionProvider, @@ -34,7 +32,6 @@ public GuildEventSubscriber(IEOMessageBoxFactory messageBoxFactory, { _messageBoxFactory = messageBoxFactory; _guildActions = guildActions; - _localizedStringFinder = localizedStringFinder; _packetSendService = packetSendService; _sfxPlayer = sfxPlayer; _guildSessionProvider = guildSessionProvider; @@ -46,18 +43,17 @@ public void NotifyGuildCreationRequest(int creatorPlayerID, string guildIdentity _sfxPlayer.PlaySfx(SoundEffectID.ServerMessage); var dlg = _messageBoxFactory.CreateMessageBox( - $"{guildIdentity}" + - " " + _localizedStringFinder.GetString(DialogResourceID.GUILD_INVITES_YOU_TO_JOIN) + - " " + _localizedStringFinder.GetString(EOResourceID.GUILD_JOINING_A_GUILD_IS_FREE) + - " " + _localizedStringFinder.GetString(EOResourceID.GUILD_PLEASE_CONSIDER_CAREFULLY) + - " " + _localizedStringFinder.GetString(EOResourceID.GUILD_DO_YOU_ACCEPT), - caption: _localizedStringFinder.GetString(DialogResourceID.GUILD_INVITATION), - whichButtons: Dialogs.EODialogButtons.OkCancel, - style: Dialogs.EOMessageBoxStyle.LargeDialogSmallHeader); + prependData: $"{guildIdentity} ", + resource: DialogResourceID.GUILD_INVITATION_INVITES_YOU, + whichButtons: EODialogButtons.OkCancel, + style: EOMessageBoxStyle.LargeDialogSmallHeader, + EOResourceID.GUILD_JOINING_A_GUILD_IS_FREE, + EOResourceID.GUILD_PLEASE_CONSIDER_CAREFULLY, + EOResourceID.GUILD_DO_YOU_ACCEPT); dlg.DialogClosing += (_, e) => { - if (e.Result == XNAControls.XNADialogResult.OK) + if (e.Result == XNADialogResult.OK) { _packetSendService.SendPacket(new GuildAcceptClientPacket() { @@ -74,18 +70,17 @@ public void NotifyRequestToJoinGuild(int playerId, string name) _sfxPlayer.PlaySfx(SoundEffectID.ServerMessage); var dlg = _messageBoxFactory.CreateMessageBox( - $"{name}" + - " " + _localizedStringFinder.GetString(DialogResourceID.GUILD_REQUESTED_TO_JOIN) + - " " + _localizedStringFinder.GetString(EOResourceID.GUILD_YOUR_ACCOUNT_WILL_BE_CHARGED) + - " " + _localizedStringFinder.GetString(EOResourceID.GUILD_PLEASE_CONSIDER_CAREFULLY_RECRUIT) + - " " + _localizedStringFinder.GetString(EOResourceID.GUILD_DO_YOU_ACCEPT), - caption: _localizedStringFinder.GetString(DialogResourceID.GUILD_PLAYER_WANTS_TO_JOIN), - whichButtons: Dialogs.EODialogButtons.OkCancel, - style: Dialogs.EOMessageBoxStyle.LargeDialogSmallHeader); + prependData: $"{name} ", + resource: DialogResourceID.GUILD_PLAYER_WANTS_TO_JOIN, + whichButtons: EODialogButtons.OkCancel, + style: EOMessageBoxStyle.LargeDialogSmallHeader, + EOResourceID.GUILD_YOUR_ACCOUNT_WILL_BE_CHARGED, + EOResourceID.GUILD_PLEASE_CONSIDER_CAREFULLY_RECRUIT, + EOResourceID.GUILD_DO_YOU_ACCEPT); dlg.DialogClosing += (_, e) => { - if (e.Result == XNAControls.XNADialogResult.OK) + if (e.Result == XNADialogResult.OK) { _packetSendService.SendPacket(new GuildUseClientPacket() { @@ -111,13 +106,25 @@ public void NotifyGuildReply(GuildReply reply) GuildReply.NotApproved => DialogResourceID.GUILD_CREATE_NAME_NOT_APPROVED, GuildReply.Exists => DialogResourceID.GUILD_TAG_OR_NAME_ALREADY_EXISTS, GuildReply.NoCandidates => DialogResourceID.GUILD_CREATE_NO_CANDIDATES, + GuildReply.RemoveLeader => DialogResourceID.GUILD_REMOVE_PLAYER_IS_LEADER, + GuildReply.RemoveNotMember => DialogResourceID.GUILD_REMOVE_PLAYER_NOT_MEMBER, + GuildReply.Removed => DialogResourceID.GUILD_REMOVE_SUCCESS, + GuildReply.Accepted => DialogResourceID.GUILD_MEMBER_HAS_BEEN_ACCEPTED, _ => default }; + var prependData = reply switch + { + GuildReply.RemoveLeader or + GuildReply.RemoveNotMember or + GuildReply.Removed => $"{_guildSessionProvider.RemoveCandidate} ", + _ => string.Empty + }; + if (dialogMessage == default) return; - var dlg = _messageBoxFactory.CreateMessageBox(dialogMessage); + var dlg = _messageBoxFactory.CreateMessageBox(prependData, dialogMessage); dlg.ShowDialog(); } @@ -151,5 +158,13 @@ public void NotifyNewGuildBankBalance(int balance) var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.GUILD_DEPOSIT_NEW_BALANCE, $" {balance} {goldName}"); dlg.ShowDialog(); } + + public void NotifyAcceptedIntoGuild() + { + _sfxPlayer.PlaySfx(SoundEffectID.JoinGuild); + + var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.GUILD_YOU_HAVE_BEEN_ACCEPTED); + dlg.ShowDialog(); + } } }