Skip to content

Commit

Permalink
Extract ChestActions out of MapActions
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 10, 2022
1 parent a707282 commit e91e102
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 55 deletions.
52 changes: 52 additions & 0 deletions EOLib/Domain/Map/ChestActions.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
27 changes: 0 additions & 27 deletions EOLib/Domain/Map/MapActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions EndlessClient/Controllers/InventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -59,7 +59,7 @@ public InventoryController(IItemActions itemActions,
_itemActions = itemActions;
_inGameDialogActions = inGameDialogActions;
_paperdollActions = paperdollActions;
_mapActions = mapActions;
_chestActions = chestActions;
_itemEquipValidator = itemEquipValidator;
_itemDropValidator = itemDropValidator;
_characterProvider = characterProvider;
Expand Down Expand Up @@ -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)));
}
}

Expand Down
8 changes: 4 additions & 4 deletions EndlessClient/Dialogs/ChestDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +36,7 @@ public class ChestDialog : ScrollingListDialog
private HashSet<IInventoryItem> _cachedItems;

public ChestDialog(INativeGraphicsManager nativeGraphicsManager,
IMapActions mapActions,
IChestActions chestActions,
IEOMessageBoxFactory messageBoxFactory,
IEODialogButtonService dialogButtonService,
IStatusLabelSetter statusLabelSetter,
Expand All @@ -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;
Expand Down Expand Up @@ -123,7 +123,7 @@ private void TakeItem(IInventoryItem item, EIFRecord itemData)
}
else
{
_mapActions.TakeItemFromChest(item.ItemID);
_chestActions.TakeItemFromChest(item.ItemID);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions EndlessClient/Dialogs/Factories/ChestDialogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -42,7 +42,7 @@ public ChestDialogFactory(INativeGraphicsManager nativeGraphicsManager,
ICharacterProvider characterProvider)
{
_nativeGraphicsManager = nativeGraphicsManager;
_mapActions = mapActions;
_chestActions = chestActions;
_messageBoxFactory = messageBoxFactory;
_dialogButtonService = dialogButtonService;
_statusLabelSetter = statusLabelSetter;
Expand All @@ -58,7 +58,7 @@ public ChestDialogFactory(INativeGraphicsManager nativeGraphicsManager,
public ChestDialog Create()
{
return new ChestDialog(_nativeGraphicsManager,
_mapActions,
_chestActions,
_messageBoxFactory,
_dialogButtonService,
_statusLabelSetter,
Expand Down
16 changes: 0 additions & 16 deletions EndlessClient/Old/PacketAPICallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,20 +100,6 @@ private void _bankChange(int gold, int bankGold)
BankAccountDialog.Instance.AccountBalance = $"{bankGold}";
}

private void _lockerOpen(byte x, byte y, List<InventoryItem> 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<InventoryItem> 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;
Expand Down

0 comments on commit e91e102

Please sign in to comment.