Skip to content

Commit

Permalink
Implement LOCKER_SPEC packet handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 31, 2024
1 parent 817e9d2 commit 5d1ccc5
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
15 changes: 15 additions & 0 deletions EOLib/Domain/Notifiers/ILockerEventNotifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using AutomaticTypeMapper;

namespace EOLib.Domain.Notifiers
{
public interface ILockerEventNotifier
{
void NotifyLockerFull(int maxItems);
}

[AutoMappedType]
public class NoOpLockerEventNotifier : ILockerEventNotifier
{
public void NotifyLockerFull(int maxItems) { }
}
}
37 changes: 37 additions & 0 deletions EOLib/PacketHandlers/Locker/LockerSpecHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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;
using System.Collections.Generic;

namespace EOLib.PacketHandlers.Locker
{
[AutoMappedType]
public class LockerSpecHandler : InGameOnlyPacketHandler<LockerSpecServerPacket>
{
private readonly IEnumerable<ILockerEventNotifier> _lockerEventNotifiers;

public override PacketFamily Family => PacketFamily.Locker;

public override PacketAction Action => PacketAction.Spec;

public LockerSpecHandler(IPlayerInfoProvider playerInfoProvider,
IEnumerable<ILockerEventNotifier> lockerEventNotifiers)
: base(playerInfoProvider)
{
_lockerEventNotifiers = lockerEventNotifiers;
}

public override bool HandlePacket(LockerSpecServerPacket packet)
{
foreach (var notifier in _lockerEventNotifiers)
{
notifier.NotifyLockerFull(packet.LockerMaxItems);
}

return true;
}
}
}
30 changes: 30 additions & 0 deletions EndlessClient/Subscribers/LockerEventSubscriber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Factories;
using EOLib.Domain.Notifiers;
using EOLib.Localization;

namespace EndlessClient.Subscribers
{
[AutoMappedType]
public class LockerEventSubscriber : ILockerEventNotifier
{
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly ILocalizedStringFinder _localizedStringFinder;

public LockerEventSubscriber(IEOMessageBoxFactory messageBoxFactory,
ILocalizedStringFinder localizedStringFinder)
{
_messageBoxFactory = messageBoxFactory;
_localizedStringFinder = localizedStringFinder;
}

public void NotifyLockerFull(int maxItems)
{
var message = _localizedStringFinder.GetString(DialogResourceID.LOCKER_FULL_DIFF_ITEMS_MAX + 1);
var caption = _localizedStringFinder.GetString(DialogResourceID.LOCKER_FULL_DIFF_ITEMS_MAX);

var dlg = _messageBoxFactory.CreateMessageBox(message.Replace("25", $"{maxItems}"), caption);
dlg.ShowDialog();
}
}
}

0 comments on commit 5d1ccc5

Please sign in to comment.