Skip to content

Commit

Permalink
Implement guild not found message (#381)
Browse files Browse the repository at this point in the history
Use shared notifier method for guild replies. Don't change to information/member list state until the provider data is different from the cached data
  • Loading branch information
ethanmoffat authored Oct 22, 2024
1 parent 985c8e4 commit 206b88f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
3 changes: 1 addition & 2 deletions EOLib.Localization/DialogResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ public enum DialogResourceID
GUILD_MEMBER_HAS_BEEN_ACCEPTED = 174,
GUILD_DOES_NOT_EXIST = 176,
GUILD_YOU_HAVE_BEEN_ACCEPTED = 178,
GUILD_ACCEPTED = 180,
GUILD_DETAILS_HAVE_BEEN_UPDATED = 181,
GUILD_DETAILS_UPDATED = 180,
GUILD_PROMPT_DISBAND_GUILD = 182,
GUILD_REMOVE_MEMBER_WHO = 184,
GUILD_REMOVE_PLAYER_NOT_MEMBER = 186,
Expand Down
9 changes: 7 additions & 2 deletions EOLib/Domain/Interact/Guild/GuildSessionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IGuildSessionProvider
IReadOnlyList<GuildMember> GuildMembers { get; }
}

public interface IGuildSessionRepository
public interface IGuildSessionRepository : IResettable
{
int SessionID { get; set; }

Expand All @@ -41,9 +41,14 @@ public class GuildSessionRepository : IGuildSessionRepository, IGuildSessionProv
IReadOnlyList<GuildMember> IGuildSessionProvider.GuildMembers => GuildMembers;

public GuildSessionRepository()
{
ResetState();
}

public void ResetState()
{
SessionID = 0;
GuildDescription = "";
GuildDescription = string.Empty;
GuildInfo = Option.None<GuildInfo>();
GuildMembers = new List<GuildMember>();
}
Expand Down
7 changes: 5 additions & 2 deletions EOLib/Domain/Notifiers/IGuildNotifier.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using AutomaticTypeMapper;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;

namespace EOLib.Domain.Notifiers
{
public interface IGuildNotifier
{
void NotifyGuildCreationRequest(int creatorPlayerID, string guildIdentity);

void NotifyRequestToJoinGuild(int playerId, string name);
void NotifyGuildDetailsUpdated();

void NotifyGuildReply(GuildReply reply);
}

[AutoMappedType]
public class NoOpGuildNotifier : IGuildNotifier
{
public void NotifyGuildCreationRequest(int creatorPlayerID, string guildIdentity) { }
public void NotifyRequestToJoinGuild(int playerId, string name) { }
public void NotifyGuildDetailsUpdated() { }
public void NotifyGuildReply(GuildReply reply) { }
}
}
3 changes: 1 addition & 2 deletions EOLib/PacketHandlers/Guild/GuildOpenHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
using EOLib.Domain.Interact;
using EOLib.Domain.Interact.Guild;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Net.Handlers;
using Moffat.EndlessOnline.SDK.Protocol.Net;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;
using Optional;

namespace EOLib.PacketHandlers.Guild
{
Expand All @@ -34,6 +32,7 @@ public GuildOpenHandler(IPlayerInfoProvider playerInfoProvider,

public override bool HandlePacket(GuildOpenServerPacket packet)
{
_guildSessionRepository.ResetState();
_guildSessionRepository.SessionID = packet.SessionId;

foreach (var notifier in _npcInteractionNotifiers)
Expand Down
3 changes: 2 additions & 1 deletion EOLib/PacketHandlers/Guild/GuildReplyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public override bool HandlePacket(GuildReplyServerPacket packet)
notifier.NotifyRequestToJoinGuild(joinRequestData.PlayerId, joinRequestData.Name);
break;
case GuildReply.Updated:
case GuildReply.NotFound:
foreach (var notifier in _guildNotifiers)
notifier.NotifyGuildDetailsUpdated();
notifier.NotifyGuildReply(packet.ReplyCode);
break;
}

Expand Down
11 changes: 4 additions & 7 deletions EndlessClient/Dialogs/GuildDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected override void OnUpdateControl(GameTime gameTime)
});
break;

case GuildDialogState.Lookup:
case GuildDialogState.Information:
_cachedGuildInfo.Match(
some: cachedGuildInfo =>
{
Expand All @@ -182,11 +182,10 @@ protected override void OnUpdateControl(GameTime gameTime)
},
none: () => _guildSessionProvider.GuildInfo.MatchSome(CacheAndSetGuildInfo)
);
break;

case GuildDialogState.ViewMembers:
if (!_cachedMembers.SetEquals(_guildSessionProvider.GuildMembers))
{
SetState(State.ViewMembers);
ClearItemList();

_cachedMembers = _guildSessionProvider.GuildMembers.ToHashSet();
Expand All @@ -202,6 +201,8 @@ protected override void OnUpdateControl(GameTime gameTime)

void CacheAndSetGuildInfo(GuildInfo guildInfo)
{
SetState(State.Information);

_cachedGuildInfo = Option.Some(guildInfo);

ClearItemList();
Expand Down Expand Up @@ -236,8 +237,6 @@ void CacheAndSetGuildInfo(GuildInfo guildInfo)
private void GoBack()
{
_modifyGuildDescriptionListItem = Option.None<ListDialogItem>();
_cachedGuildInfo = Option.None<GuildInfo>();
_cachedMembers.Clear();

SetState(_stateStack.Count > 0 ? _stateStack.Pop() : State.Initial, pushState: false);
}
Expand Down Expand Up @@ -356,7 +355,6 @@ void GuildLookup_Click(object sender, MouseEventArgs e)
}
else
{
SetState(State.GuildLookup);
_guildActions.Lookup(dlg.ResponseText);
}
};
Expand All @@ -383,7 +381,6 @@ void ViewMembers_Click(object sender, MouseEventArgs e)
}
else
{
SetState(State.ViewMembers);
_guildActions.ViewMembers(dlg.ResponseText);
}
};
Expand Down
17 changes: 12 additions & 5 deletions EndlessClient/Subscribers/GuildEventSubscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using EOLib.Localization;
using EOLib.Net.Communication;
using Moffat.EndlessOnline.SDK.Protocol.Net.Client;
using Moffat.EndlessOnline.SDK.Protocol.Net.Server;

namespace EndlessClient.Subscribers
{
Expand Down Expand Up @@ -80,13 +81,19 @@ public void NotifyRequestToJoinGuild(int playerId, string name)
dlg.ShowDialog();
}

public void NotifyGuildDetailsUpdated()
public void NotifyGuildReply(GuildReply reply)
{
var dlg = _messageBoxFactory.CreateMessageBox(_localizedStringFinder.GetString(DialogResourceID.GUILD_DETAILS_HAVE_BEEN_UPDATED),
caption: _localizedStringFinder.GetString(DialogResourceID.GUILD_ACCEPTED),
whichButtons: Dialogs.EODialogButtons.Ok,
style: Dialogs.EOMessageBoxStyle.SmallDialogSmallHeader);
var dialogMessage = reply switch
{
GuildReply.Updated => DialogResourceID.GUILD_DETAILS_UPDATED,
GuildReply.NotFound => DialogResourceID.GUILD_DOES_NOT_EXIST,
_ => default
};

if (dialogMessage == default)
return;

var dlg = _messageBoxFactory.CreateMessageBox(dialogMessage);
dlg.ShowDialog();
}
}
Expand Down

0 comments on commit 206b88f

Please sign in to comment.