From e91e102899e21f937b2db493f986fa2a1e4c1b5e Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Sat, 9 Apr 2022 18:19:10 -0700 Subject: [PATCH] Extract ChestActions out of MapActions --- EOLib/Domain/Map/ChestActions.cs | 52 +++++++++++++++++++ EOLib/Domain/Map/MapActions.cs | 27 ---------- .../Controllers/InventoryController.cs | 8 +-- EndlessClient/Dialogs/ChestDialog.cs | 8 +-- .../Dialogs/Factories/ChestDialogFactory.cs | 8 +-- EndlessClient/Old/PacketAPICallbackManager.cs | 16 ------ 6 files changed, 64 insertions(+), 55 deletions(-) create mode 100644 EOLib/Domain/Map/ChestActions.cs diff --git a/EOLib/Domain/Map/ChestActions.cs b/EOLib/Domain/Map/ChestActions.cs new file mode 100644 index 000000000..49a045ca6 --- /dev/null +++ b/EOLib/Domain/Map/ChestActions.cs @@ -0,0 +1,52 @@ +using AutomaticTypeMapper; +using EOLib.Domain.Character; +using EOLib.Net; +using EOLib.Net.Communication; + +namespace EOLib.Domain.Map +{ + [AutoMappedType] + public class ChestActions : IChestActions + { + private readonly IPacketSendService _packetSendService; + private readonly IChestDataProvider _chestDataProvider; + + public ChestActions(IPacketSendService packetSendService, + IChestDataProvider chestDataProvider) + { + _packetSendService = packetSendService; + _chestDataProvider = chestDataProvider; + } + + public void AddItemToChest(IInventoryItem item) + { + var packet = new PacketBuilder(PacketFamily.Chest, PacketAction.Add) + .AddChar((byte)_chestDataProvider.Location.X) + .AddChar((byte)_chestDataProvider.Location.Y) + .AddShort(item.ItemID) + .AddThree(item.Amount) + .Build(); + + _packetSendService.SendPacket(packet); + } + + public void TakeItemFromChest(short itemId) + { + var packet = new PacketBuilder(PacketFamily.Chest, PacketAction.Take) + .AddChar((byte)_chestDataProvider.Location.X) + .AddChar((byte)_chestDataProvider.Location.Y) + .AddShort(itemId) + .Build(); + + _packetSendService.SendPacket(packet); + } + } + + public interface IChestActions + { + + void AddItemToChest(IInventoryItem item); + + void TakeItemFromChest(short itemId); + } +} diff --git a/EOLib/Domain/Map/MapActions.cs b/EOLib/Domain/Map/MapActions.cs index 0e70035c0..cc00330f1 100644 --- a/EOLib/Domain/Map/MapActions.cs +++ b/EOLib/Domain/Map/MapActions.cs @@ -69,29 +69,6 @@ public void OpenChest(byte x, byte y) _packetSendService.SendPacket(packet); } - - public void AddItemToChest(IInventoryItem item) - { - var packet = new PacketBuilder(PacketFamily.Chest, PacketAction.Add) - .AddChar((byte)_chestDataProvider.Location.X) - .AddChar((byte)_chestDataProvider.Location.Y) - .AddShort(item.ItemID) - .AddThree(item.Amount) - .Build(); - - _packetSendService.SendPacket(packet); - } - - public void TakeItemFromChest(short itemId) - { - var packet = new PacketBuilder(PacketFamily.Chest, PacketAction.Take) - .AddChar((byte)_chestDataProvider.Location.X) - .AddChar((byte)_chestDataProvider.Location.Y) - .AddShort(itemId) - .Build(); - - _packetSendService.SendPacket(packet); - } } public interface IMapActions @@ -103,9 +80,5 @@ public interface IMapActions void OpenDoor(IWarp warp); void OpenChest(byte x, byte y); - - void AddItemToChest(IInventoryItem item); - - void TakeItemFromChest(short itemId); } } diff --git a/EndlessClient/Controllers/InventoryController.cs b/EndlessClient/Controllers/InventoryController.cs index 99fb2e50b..1835c58dd 100644 --- a/EndlessClient/Controllers/InventoryController.cs +++ b/EndlessClient/Controllers/InventoryController.cs @@ -27,7 +27,7 @@ public class InventoryController : IInventoryController private readonly IItemActions _itemActions; private readonly IInGameDialogActions _inGameDialogActions; private readonly IPaperdollActions _paperdollActions; - private readonly IMapActions _mapActions; + private readonly IChestActions _chestActions; private readonly IItemEquipValidator _itemEquipValidator; private readonly IItemDropValidator _itemDropValidator; private readonly ICharacterProvider _characterProvider; @@ -43,7 +43,7 @@ public class InventoryController : IInventoryController public InventoryController(IItemActions itemActions, IInGameDialogActions inGameDialogActions, IPaperdollActions paperdollActions, - IMapActions mapActions, + IChestActions chestActions, IItemEquipValidator itemEquipValidator, IItemDropValidator itemDropValidator, ICharacterProvider characterProvider, @@ -59,7 +59,7 @@ public InventoryController(IItemActions itemActions, _itemActions = itemActions; _inGameDialogActions = inGameDialogActions; _paperdollActions = paperdollActions; - _mapActions = mapActions; + _chestActions = chestActions; _itemEquipValidator = itemEquipValidator; _itemDropValidator = itemDropValidator; _characterProvider = characterProvider; @@ -228,7 +228,7 @@ public void DropItemInChest(EIFRecord itemData, IInventoryItem inventoryItem) } else { - DoItemDrop(itemData, inventoryItem, a => _mapActions.AddItemToChest(inventoryItem.WithAmount(a))); + DoItemDrop(itemData, inventoryItem, a => _chestActions.AddItemToChest(inventoryItem.WithAmount(a))); } } diff --git a/EndlessClient/Dialogs/ChestDialog.cs b/EndlessClient/Dialogs/ChestDialog.cs index e370e0e65..37152af9b 100644 --- a/EndlessClient/Dialogs/ChestDialog.cs +++ b/EndlessClient/Dialogs/ChestDialog.cs @@ -21,7 +21,7 @@ namespace EndlessClient.Dialogs { public class ChestDialog : ScrollingListDialog { - private readonly IMapActions _mapActions; + private readonly IChestActions _chestActions; private readonly IEOMessageBoxFactory _messageBoxFactory; private readonly IStatusLabelSetter _statusLabelSetter; private readonly ILocalizedStringFinder _localizedStringFinder; @@ -36,7 +36,7 @@ public class ChestDialog : ScrollingListDialog private HashSet _cachedItems; public ChestDialog(INativeGraphicsManager nativeGraphicsManager, - IMapActions mapActions, + IChestActions chestActions, IEOMessageBoxFactory messageBoxFactory, IEODialogButtonService dialogButtonService, IStatusLabelSetter statusLabelSetter, @@ -49,7 +49,7 @@ public ChestDialog(INativeGraphicsManager nativeGraphicsManager, ICharacterProvider characterProvider) : base(nativeGraphicsManager, dialogButtonService, dialogSize: ScrollingListDialogSize.LargeNoScroll) { - _mapActions = mapActions; + _chestActions = chestActions; _messageBoxFactory = messageBoxFactory; _statusLabelSetter = statusLabelSetter; _localizedStringFinder = localizedStringFinder; @@ -123,7 +123,7 @@ private void TakeItem(IInventoryItem item, EIFRecord itemData) } else { - _mapActions.TakeItemFromChest(item.ItemID); + _chestActions.TakeItemFromChest(item.ItemID); } } } diff --git a/EndlessClient/Dialogs/Factories/ChestDialogFactory.cs b/EndlessClient/Dialogs/Factories/ChestDialogFactory.cs index 6d6896146..3c39106d7 100644 --- a/EndlessClient/Dialogs/Factories/ChestDialogFactory.cs +++ b/EndlessClient/Dialogs/Factories/ChestDialogFactory.cs @@ -16,7 +16,7 @@ namespace EndlessClient.Dialogs.Factories public class ChestDialogFactory : IChestDialogFactory { private readonly INativeGraphicsManager _nativeGraphicsManager; - private readonly IMapActions _mapActions; + private readonly IChestActions _chestActions; private readonly IEOMessageBoxFactory _messageBoxFactory; private readonly IEODialogButtonService _dialogButtonService; private readonly IStatusLabelSetter _statusLabelSetter; @@ -29,7 +29,7 @@ public class ChestDialogFactory : IChestDialogFactory private readonly ICharacterProvider _characterProvider; public ChestDialogFactory(INativeGraphicsManager nativeGraphicsManager, - IMapActions mapActions, + IChestActions chestActions, IEOMessageBoxFactory messageBoxFactory, IEODialogButtonService dialogButtonService, IStatusLabelSetter statusLabelSetter, @@ -42,7 +42,7 @@ public ChestDialogFactory(INativeGraphicsManager nativeGraphicsManager, ICharacterProvider characterProvider) { _nativeGraphicsManager = nativeGraphicsManager; - _mapActions = mapActions; + _chestActions = chestActions; _messageBoxFactory = messageBoxFactory; _dialogButtonService = dialogButtonService; _statusLabelSetter = statusLabelSetter; @@ -58,7 +58,7 @@ public ChestDialogFactory(INativeGraphicsManager nativeGraphicsManager, public ChestDialog Create() { return new ChestDialog(_nativeGraphicsManager, - _mapActions, + _chestActions, _messageBoxFactory, _dialogButtonService, _statusLabelSetter, diff --git a/EndlessClient/Old/PacketAPICallbackManager.cs b/EndlessClient/Old/PacketAPICallbackManager.cs index ffb1a8356..8f6dab2a7 100644 --- a/EndlessClient/Old/PacketAPICallbackManager.cs +++ b/EndlessClient/Old/PacketAPICallbackManager.cs @@ -34,8 +34,6 @@ public void AssignCallbacks() m_packetAPI.OnBankChange += _bankChange; //locker - m_packetAPI.OnLockerOpen += _lockerOpen; - m_packetAPI.OnLockerItemChange += _lockerItemChange; m_packetAPI.OnLockerUpgrade += _lockerUpgrade; //party @@ -102,20 +100,6 @@ private void _bankChange(int gold, int bankGold) BankAccountDialog.Instance.AccountBalance = $"{bankGold}"; } - private void _lockerOpen(byte x, byte y, List items) - { - if (LockerDialog.Instance == null || LockerDialog.Instance.X != x || LockerDialog.Instance.Y != y) - return; - LockerDialog.Instance.SetLockerData(items); - } - - private void _lockerItemChange(short id, int amount, byte weight, byte maxWeight, bool existingAmount, List items) - { - if (LockerDialog.Instance == null) return; - //OldWorld.Instance.MainPlayer.ActiveCharacter.UpdateInventoryItem(id, amount, weight, maxWeight, existingAmount); - LockerDialog.Instance.SetLockerData(items); - } - private void _lockerUpgrade(int remaining, byte upgrades) { if (BankAccountDialog.Instance == null) return;