Skip to content

Commit

Permalink
Implement 'Set Member Rank' and 'Update Guild Ranks' functions in Gui…
Browse files Browse the repository at this point in the history
…ldDialog (#388)

* Reorder GuildReply replycode handlers to match integer ids; stub out IDs missing from eoserv with todo action items

* Handle setting GuildRankID during login

* Implement set member rank and update rank list functions in GuildDialog
  • Loading branch information
ethanmoffat authored Oct 27, 2024
1 parent 8deaf27 commit efde12a
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 77 deletions.
15 changes: 10 additions & 5 deletions EOLib.Localization/EOResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public enum EOResourceID
GUILD_REMOVE_A_MEMBER_FROM_GUILD = 203,
GUILD_YOU_ARE_ABOUT_TO_JOIN_A_GUILD = 204,
GUILD_JOINING_A_GUILD_IS_FREE = 205,

// GUILD_RECRUITER_MUST_BE_PRESENT = 206, // not used anymore?
GUILD_PLEASE_CONSIDER_CAREFULLY = 207,
GUILD_CLICK_HERE_TO_JOIN_A_GUILD = 208,
GUILD_YOU_ARE_ABOUT_TO_LEAVE_THE_GUILD = 209,
Expand All @@ -207,7 +207,8 @@ public enum EOResourceID
GUILD_GUILD_TAG = 217,
GUILD_GUILD_NAME = 218,
GUILD_WORD_DESCRIPTION = 219,

// GUILD_RANKING = 220 // duplicate of 193
// GUILD_HERE_YOU_CAN_JOIN = 221 // not used anymore?
GUILD_PLEASE_WAIT_FOR_ALL_MEMBERS_TO_JOIN = 222,
GUILD_DO_YOU_ACCEPT = 223,
GUILD_RECRUITER = 224,
Expand All @@ -218,11 +219,11 @@ public enum EOResourceID
GUILD_GUILD_DESCRIPTION = 229,
GUILD_RANKING_SYSTEM = 230,
GUILD_LEADERS = 231,

// GUILD_RECRUITERS = 232 // not used anymore?
GUILD_ASSIGN_RANK_TO_MEMBER = 233,
GUILD_CURRENT_DESCRIPTION = 234,
GUILD_CLICK_HERE_TO_CHANGE_THE_DESCRIPTION = 235,

GUILD_ENTER_YOUR_RANKINGS = 236,
GUILD_DISBAND_DESCRIPTION_1 = 237,
GUILD_DISBAND_DESCRIPTION_2 = 238,
GUILD_DISBAND_DESCRIPTION_3 = 239,
Expand All @@ -234,7 +235,11 @@ public enum EOResourceID
GUILD_BANK_DESCRIPTION_1 = 245,
GUILD_BANK_DESCRIPTION_2 = 246,
GUILD_BANK_DESCRIPTION_3 = 247,

GUILD_RANK_DESCRIPTION_1 = 248,
GUILD_RANK_DESCRIPTION_2 = 249,
GUILD_RANK_DESCRIPTION_3 = 250,
GUILD_RANK_ASSIGN_NAME = 251,
GUILD_RANK_ASSIGN_RANK = 252,
SETTING_KEYBOARD_ENGLISH = 253,
SETTING_KEYBOARD_DUTCH = 254,
SETTING_KEYBOARD_SWEDISH = 255,
Expand Down
2 changes: 2 additions & 0 deletions EOLib/Domain/Character/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public sealed partial class Character : ISpellTargetable

public string GuildRank { get; }

public int GuildRankID { get; }

public string GuildTag { get; }

public bool InGuild => GuildTag != " ";
Expand Down
63 changes: 60 additions & 3 deletions EOLib/Domain/Interact/Guild/GuildActions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Extensions;
Expand Down Expand Up @@ -46,11 +47,11 @@ public void GetGuildDescription(string guildTag)

public void SetGuildDescription(string description)
{
_packetSendService.SendPacket(new GuildAgreeClientPacket()
_packetSendService.SendPacket(new GuildAgreeClientPacket
{
SessionId = _guildSessionRepository.SessionID,
InfoType = GuildInfoType.Description,
InfoTypeData = new GuildAgreeClientPacket.InfoTypeDataDescription()
InfoTypeData = new GuildAgreeClientPacket.InfoTypeDataDescription
{
Description = description
}
Expand All @@ -76,6 +77,48 @@ public void BankDeposit(int depositAmount)
});
}

public void GetGuildRanks(string guildTag)
{
_packetSendService.SendPacket(new GuildTakeClientPacket
{
SessionId = _guildSessionRepository.SessionID,
InfoType = GuildInfoType.Ranks,
GuildTag = guildTag
});

}

public void SetGuildRanks(IReadOnlyList<string> ranks)
{
var ranksList = ranks.ToList();
while (ranksList.Count != 9)
{
ranksList.Add(string.Empty);
}

_packetSendService.SendPacket(new GuildAgreeClientPacket
{
SessionId = _guildSessionRepository.SessionID,
InfoType = GuildInfoType.Ranks,
InfoTypeData = new GuildAgreeClientPacket.InfoTypeDataRanks
{
Ranks = ranksList
}
});
}

public void AssignRank(string playerName, int rank)
{
_guildSessionRepository.GuildPlayerModifyCandidate = playerName.Capitalize();

_packetSendService.SendPacket(new GuildRankClientPacket
{
SessionId = _guildSessionRepository.SessionID,
MemberName = playerName,
Rank = rank
});
}

public void RequestToJoinGuild(string guildTag, string recruiterName)
{
_packetSendService.SendPacket(new GuildPlayerClientPacket { SessionId = _guildSessionRepository.SessionID, GuildTag = guildTag, RecruiterName = recruiterName });
Expand Down Expand Up @@ -127,7 +170,7 @@ public void CancelGuildCreate()

public void KickMember(string member)
{
_guildSessionRepository.RemoveCandidate = member.Capitalize();
_guildSessionRepository.GuildPlayerModifyCandidate = member.Capitalize();

_packetSendService.SendPacket(new GuildKickClientPacket
{
Expand All @@ -140,6 +183,12 @@ public void DisbandGuild()
{
_packetSendService.SendPacket(new GuildJunkClientPacket { SessionId = _guildSessionRepository.SessionID });
}

public void ClearLocalState()
{
_guildSessionRepository.GuildMembers.Clear();
_guildSessionRepository.GuildInfo = Option.None<GuildInfo>();
}
}

public interface IGuildActions
Expand All @@ -156,6 +205,12 @@ public interface IGuildActions

void BankDeposit(int depositAmount);

void GetGuildRanks(string guildTag);

void SetGuildRanks(IReadOnlyList<string> ranks);

void AssignRank(string playerName, int rank);

void RequestToJoinGuild(string guildTag, string recruiterName);

void LeaveGuild();
Expand All @@ -169,5 +224,7 @@ public interface IGuildActions
void KickMember(string responseText);

void DisbandGuild();

void ClearLocalState();
}
}
8 changes: 4 additions & 4 deletions EOLib/Domain/Interact/Guild/GuildSessionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IGuildSessionProvider

IReadOnlyList<GuildMember> GuildMembers { get; }

string RemoveCandidate { get; }
string GuildPlayerModifyCandidate { get; }
}

public interface IGuildSessionRepository : IResettable
Expand All @@ -36,7 +36,7 @@ public interface IGuildSessionRepository : IResettable

List<GuildMember> GuildMembers { get; set; }

string RemoveCandidate { get; set; }
string GuildPlayerModifyCandidate { get; set; }
}

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

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

public string RemoveCandidate { get; set; }
public string GuildPlayerModifyCandidate { get; set; }

IReadOnlyList<GuildMember> IGuildSessionProvider.GuildMembers => GuildMembers;

Expand All @@ -71,7 +71,7 @@ public void ResetState()
GuildBalance = 0;
GuildInfo = Option.None<GuildInfo>();
GuildMembers = new List<GuildMember>();
RemoveCandidate = string.Empty;
GuildPlayerModifyCandidate = string.Empty;
}
}
}
1 change: 1 addition & 0 deletions EOLib/Domain/Login/LoginActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public async Task<int> RequestCharacterLogin(Character.Character character)
.WithName(data.Name.Capitalize())
.WithTitle(data.Title)
.WithGuildName(data.GuildName.Capitalize())
.WithGuildRankID(data.GuildRank)
.WithGuildRank(data.GuildRankName.Capitalize())
.WithGuildTag(data.GuildTag.ToUpper())
.WithClassID(data.ClassId)
Expand Down
6 changes: 5 additions & 1 deletion EOLib/Domain/Notifiers/IGuildNotifier.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutomaticTypeMapper;
using System.Collections.Generic;
using AutomaticTypeMapper;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;

namespace EOLib.Domain.Notifiers
Expand All @@ -16,6 +17,8 @@ public interface IGuildNotifier
void NotifyNewGuildBankBalance(int balance);

void NotifyAcceptedIntoGuild();

void NotifyRanks(IReadOnlyList<string> ranks);
}

[AutoMappedType]
Expand All @@ -27,5 +30,6 @@ public void NotifyGuildReply(GuildReply reply) { }
public void NotifyConfirmCreateGuild() { }
public void NotifyNewGuildBankBalance(int balance) { }
public void NotifyAcceptedIntoGuild() { }
public void NotifyRanks(IReadOnlyList<string> ranks) { }
}
}
32 changes: 32 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildAcceptHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 GuildAcceptHandler : InGameOnlyPacketHandler<GuildAcceptServerPacket>
{
private readonly ICharacterRepository _characterRepository;

public override PacketFamily Family => PacketFamily.Guild;

public override PacketAction Action => PacketAction.Accept;

public GuildAcceptHandler(IPlayerInfoProvider playerInfoProvider,
ICharacterRepository characterRepository)
: base(playerInfoProvider)
{
_characterRepository = characterRepository;
}

public override bool HandlePacket(GuildAcceptServerPacket packet)
{
_characterRepository.MainCharacter = _characterRepository.MainCharacter.WithGuildRankID(packet.Rank);
return true;
}
}
}
35 changes: 35 additions & 0 deletions EOLib/PacketHandlers/Guild/GuildRankHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using AutomaticTypeMapper;
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 GuildRankHandler : InGameOnlyPacketHandler<GuildRankServerPacket>
{
private readonly IEnumerable<IGuildNotifier> _guildNotifiers;

public override PacketFamily Family => PacketFamily.Guild;

public override PacketAction Action => PacketAction.Rank;

public GuildRankHandler(IPlayerInfoProvider playerInfoProvider,
IEnumerable<IGuildNotifier> guildNotifiers)
: base(playerInfoProvider)
{
_guildNotifiers = guildNotifiers;
}

public override bool HandlePacket(GuildRankServerPacket packet)
{
foreach (var notifier in _guildNotifiers)
notifier.NotifyRanks(packet.Ranks);

return true;
}
}
}
51 changes: 29 additions & 22 deletions EOLib/PacketHandlers/Guild/GuildReplyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,26 @@ public override bool HandlePacket(GuildReplyServerPacket packet)
{
switch (packet.ReplyCode)
{
case GuildReply.JoinRequest:
{
var data = (GuildReplyServerPacket.ReplyCodeDataJoinRequest)(packet.ReplyCodeData);
foreach (var notifier in _guildNotifiers)
notifier.NotifyRequestToJoinGuild(data.PlayerId, data.Name);
break;
}
case GuildReply.Updated:
case GuildReply.NotFound:
case GuildReply.Busy:
case GuildReply.NotApproved:
case GuildReply.AlreadyMember:
case GuildReply.NoCandidates:
case GuildReply.Exists:
case GuildReply.RecruiterOffline:
case GuildReply.RecruiterNotHere:
case GuildReply.RecruiterWrongGuild:
case GuildReply.NotRecruiter:
case GuildReply.NotApproved:
case GuildReply.Exists:
case GuildReply.NoCandidates:
case GuildReply.Busy:
case GuildReply.NotPresent:
case GuildReply.AccountLow:
case GuildReply.Accepted:
case GuildReply.NotFound:
case GuildReply.Updated:
case GuildReply.RanksUpdated:
case GuildReply.RemoveLeader:
case GuildReply.RemoveNotMember:
case GuildReply.Removed:
case GuildReply.Accepted:
case GuildReply.RankingLeader:
case GuildReply.RankingNotMember:
{
foreach (var notifier in _guildNotifiers)
notifier.NotifyGuildReply(packet.ReplyCode);
Expand All @@ -67,30 +66,38 @@ public override bool HandlePacket(GuildReplyServerPacket packet)
});
break;
}
case GuildReply.CreateAdd:
case GuildReply.CreateAddConfirm:
{
_guildSessionRepository.CreationSession.MatchSome(creationSession =>
{
var data = (GuildReplyServerPacket.ReplyCodeDataCreateAdd)packet.ReplyCodeData;
var data = (GuildReplyServerPacket.ReplyCodeDataCreateAddConfirm)packet.ReplyCodeData;
var updatedMemberList = new HashSet<string>(creationSession.Members) { data.Name };
_guildSessionRepository.CreationSession = Option.Some(creationSession.WithMembers(updatedMemberList));

foreach (var notifier in _guildNotifiers)
notifier.NotifyConfirmCreateGuild();
});

break;
}
case GuildReply.CreateAddConfirm:
case GuildReply.CreateAdd:
{
_guildSessionRepository.CreationSession.MatchSome(creationSession =>
{
var data = (GuildReplyServerPacket.ReplyCodeDataCreateAddConfirm)packet.ReplyCodeData;
var data = (GuildReplyServerPacket.ReplyCodeDataCreateAdd)packet.ReplyCodeData;
var updatedMemberList = new HashSet<string>(creationSession.Members) { data.Name };
_guildSessionRepository.CreationSession = Option.Some(creationSession.WithMembers(updatedMemberList));

foreach (var notifier in _guildNotifiers)
notifier.NotifyConfirmCreateGuild();
});

break;
}
case GuildReply.JoinRequest:
{
var data = (GuildReplyServerPacket.ReplyCodeDataJoinRequest)(packet.ReplyCodeData);
foreach (var notifier in _guildNotifiers)
notifier.NotifyRequestToJoinGuild(data.PlayerId, data.Name);
break;
}

}

return true;
Expand Down
Loading

0 comments on commit efde12a

Please sign in to comment.