Skip to content

Commit

Permalink
Implement Kick Member; fixup Guild Accept (#386)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ethanmoffat authored Oct 26, 2024
1 parent e486caa commit 8deaf27
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 54 deletions.
4 changes: 1 addition & 3 deletions EOLib.Localization/DialogResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion EOLib.Localization/EOResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions EOLib/Domain/Interact/Guild/GuildActions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -124,6 +125,17 @@ public void CancelGuildCreate()
_guildSessionRepository.CreationSession = Option.None<GuildCreationSession>();
}

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 });
Expand Down Expand Up @@ -153,6 +165,9 @@ public interface IGuildActions
void ConfirmGuildCreate(GuildCreationSession creationSession);

void CancelGuildCreate();

void KickMember(string responseText);

void DisbandGuild();
}
}
9 changes: 8 additions & 1 deletion EOLib/Domain/Interact/Guild/GuildSessionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface IGuildSessionProvider
Option<GuildInfo> GuildInfo { get; }

IReadOnlyList<GuildMember> GuildMembers { get; }

string RemoveCandidate { get; }
}

public interface IGuildSessionRepository : IResettable
Expand All @@ -33,6 +35,8 @@ public interface IGuildSessionRepository : IResettable
Option<GuildInfo> GuildInfo { get; set; }

List<GuildMember> GuildMembers { get; set; }

string RemoveCandidate { get; set; }
}

[AutoMappedType(IsSingleton = true)]
Expand All @@ -48,7 +52,9 @@ public class GuildSessionRepository : IGuildSessionRepository, IGuildSessionProv

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

public List<GuildMember> GuildMembers { get; set; }
public List<GuildMember> GuildMembers { get; set; }

public string RemoveCandidate { get; set; }

IReadOnlyList<GuildMember> IGuildSessionProvider.GuildMembers => GuildMembers;

Expand All @@ -65,6 +71,7 @@ public void ResetState()
GuildBalance = 0;
GuildInfo = Option.None<GuildInfo>();
GuildMembers = new List<GuildMember>();
RemoveCandidate = string.Empty;
}
}
}
15 changes: 8 additions & 7 deletions EOLib/Domain/Login/LoginActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,11 +95,11 @@ public async Task<int> 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)
Expand All @@ -111,10 +112,10 @@ public async Task<int> 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());
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 @@ -14,6 +14,8 @@ public interface IGuildNotifier
void NotifyConfirmCreateGuild();

void NotifyNewGuildBankBalance(int balance);

void NotifyAcceptedIntoGuild();
}

[AutoMappedType]
Expand All @@ -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() { }
}
}
16 changes: 16 additions & 0 deletions EOLib/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
18 changes: 7 additions & 11 deletions EOLib/PacketHandlers/Guild/GuildAgreeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,36 +14,31 @@ namespace EOLib.PacketHandlers.Guild

public class GuildAgreeHandler : InGameOnlyPacketHandler<GuildAgreeServerPacket>
{
private const byte JoinGuildSfx = 18;

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)
IEnumerable<IGuildNotifier> 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;
}
Expand Down
7 changes: 4 additions & 3 deletions EOLib/PacketHandlers/Guild/GuildCreateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GuildCreationSession>();

Expand Down
36 changes: 36 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildKickHandler.cs
Original file line number Diff line number Diff line change
@@ -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<GuildKickServerPacket>
{
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;
}
}
}
4 changes: 4 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildReplyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions EndlessClient/Audio/SoundEffectID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum SoundEffectID
TradeAccepted,
JoinParty = TradeAccepted,
GroupChatReceived,
JoinGuild = GroupChatReceived,
PrivateMessageSent,
InventoryPickup = 20,
InventoryPlace,
Expand Down
17 changes: 17 additions & 0 deletions EndlessClient/Dialogs/Factories/EOMessageBoxFactory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text;
using AutomaticTypeMapper;
using EndlessClient.Audio;
using EndlessClient.Dialogs.Services;
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions EndlessClient/Dialogs/Factories/IEOMessageBoxFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 8deaf27

Please sign in to comment.