Skip to content

Commit

Permalink
Show/interact with locker dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 10, 2022
1 parent 14503ab commit 63b4416
Show file tree
Hide file tree
Showing 19 changed files with 317 additions and 309 deletions.
11 changes: 10 additions & 1 deletion EOLib/Domain/Map/LockerActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EOLib.Domain.Character;
using EOLib.Net;
using EOLib.Net.Communication;
using Optional.Collections;

namespace EOLib.Domain.Map
{
Expand Down Expand Up @@ -40,13 +41,21 @@ public void TakeItemFromLocker(short itemId)

_packetSendService.SendPacket(packet);
}

public int GetNewItemAmount(short itemId, int amount)
{
return _lockerDataProvider.Items
.SingleOrNone(x => x.ItemID == itemId)
.Match(item => item.Amount + amount, () => amount);
}
}

public interface ILockerActions
{

void AddItemToLocker(IInventoryItem item);

void TakeItemFromLocker(short itemId);

int GetNewItemAmount(short itemId, int amount);
}
}
2 changes: 1 addition & 1 deletion EOLib/PacketHandlers/Locker/LockerGetHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override bool HandlePacket(IPacket packet)
_characterInventoryRepository.ItemInventory.Remove(existing);
if (amount > 0 || itemId == 1)
{
_characterInventoryRepository.ItemInventory.Add(existing.WithAmount(existing.Amount + (Action == PacketAction.Get ? amount : -amount)));
_characterInventoryRepository.ItemInventory.Add(existing.WithAmount(Action == PacketAction.Get ? existing.Amount + amount : amount));
}
},
none: () =>
Expand Down
4 changes: 4 additions & 0 deletions EndlessClient/Controllers/ArrowKeyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ private void AttemptToStartWalking()
_mapActions.OpenChest((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowChestDialog();
break;
case UnwalkableTileAction.Locker:
_mapActions.OpenLocker((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowLockerDialog();
break;
case UnwalkableTileAction.Chair: _characterActions.SitInChair(); break;
case UnwalkableTileAction.Door: cellState.Warp.MatchSome(w => _mapActions.OpenDoor(w)); break;
}
Expand Down
42 changes: 38 additions & 4 deletions EndlessClient/Controllers/InventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EndlessClient.HUD.Controls;
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.Map;
using EOLib;
using EOLib.Domain.Character;
using EOLib.Domain.Interact;
using EOLib.Domain.Item;
Expand All @@ -28,6 +29,7 @@ public class InventoryController : IInventoryController
private readonly IInGameDialogActions _inGameDialogActions;
private readonly IPaperdollActions _paperdollActions;
private readonly IChestActions _chestActions;
private readonly ILockerActions _lockerActions;
private readonly IItemEquipValidator _itemEquipValidator;
private readonly IItemDropValidator _itemDropValidator;
private readonly ICharacterProvider _characterProvider;
Expand All @@ -44,6 +46,7 @@ public InventoryController(IItemActions itemActions,
IInGameDialogActions inGameDialogActions,
IPaperdollActions paperdollActions,
IChestActions chestActions,
ILockerActions lockerActions,
IItemEquipValidator itemEquipValidator,
IItemDropValidator itemDropValidator,
ICharacterProvider characterProvider,
Expand All @@ -60,6 +63,7 @@ public InventoryController(IItemActions itemActions,
_inGameDialogActions = inGameDialogActions;
_paperdollActions = paperdollActions;
_chestActions = chestActions;
_lockerActions = lockerActions;
_itemEquipValidator = itemEquipValidator;
_itemDropValidator = itemDropValidator;
_characterProvider = characterProvider;
Expand Down Expand Up @@ -223,7 +227,7 @@ public void DropItemInChest(EIFRecord itemData, IInventoryItem inventoryItem)

if (validationResult == ItemDropResult.Lore)
{
var msgBox = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.ITEM_IS_LORE_ITEM, EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
var msgBox = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.ITEM_IS_LORE_ITEM);
msgBox.ShowDialog();
}
else
Expand All @@ -232,6 +236,32 @@ public void DropItemInChest(EIFRecord itemData, IInventoryItem inventoryItem)
}
}

public void DropItemInLocker(EIFRecord itemData, IInventoryItem inventoryItem)
{
if (inventoryItem.ItemID == 1)
{
var dlg = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.LOCKER_DEPOSIT_GOLD_ERROR);
dlg.ShowDialog();
}
else
{
DoItemDrop(itemData, inventoryItem, a =>
{
if (_lockerActions.GetNewItemAmount(inventoryItem.ItemID, a) > Constants.LockerMaxSingleItemAmount)
{
var dlg = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.LOCKER_FULL_SINGLE_ITEM_MAX);
dlg.ShowDialog();
}
else
{
_lockerActions.AddItemToLocker(inventoryItem.WithAmount(a));
}
},
ItemTransferDialog.TransferType.ShopTransfer,
EOResourceID.DIALOG_TRANSFER_TRANSFER);
}
}

public void JunkItem(EIFRecord itemData, IInventoryItem inventoryItem)
{
if (inventoryItem.Amount > 1)
Expand All @@ -256,15 +286,17 @@ public void JunkItem(EIFRecord itemData, IInventoryItem inventoryItem)
}
}

private void DoItemDrop(EIFRecord itemData, IInventoryItem inventoryItem, Action<int> dropAction)
private void DoItemDrop(EIFRecord itemData, IInventoryItem inventoryItem, Action<int> dropAction,
ItemTransferDialog.TransferType transferType = ItemTransferDialog.TransferType.DropItems,
EOResourceID message = EOResourceID.DIALOG_TRANSFER_DROP)
{
if (inventoryItem.Amount > 1)
{
var transferDialog = _itemTransferDialogFactory.CreateItemTransferDialog(
itemData.Name,
ItemTransferDialog.TransferType.DropItems,
transferType,
inventoryItem.Amount,
EOResourceID.DIALOG_TRANSFER_DROP);
message);
transferDialog.DialogClosing += (sender, e) =>
{
if (e.Result == XNADialogResult.OK)
Expand Down Expand Up @@ -308,6 +340,8 @@ public interface IInventoryController

void DropItemInChest(EIFRecord itemData, IInventoryItem inventoryItem);

void DropItemInLocker(EIFRecord itemData, IInventoryItem inventoryItem);

void JunkItem(EIFRecord itemData, IInventoryItem inventoryItem);
}
}
10 changes: 8 additions & 2 deletions EndlessClient/Controllers/MapInteractionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,21 @@ public void LeftClick(IMapCellState cellState, IMouseCursorRenderer mouseRendere

switch (cellState.TileSpec)
{
// todo: implement for other clickable tile specs (locker, jukebox, etc)
// todo: implement for other clickable tile specs (board, jukebox, etc)
case TileSpec.Chest:
if (unwalkableAction == UnwalkableTileAction.Chest)
{
_mapActions.OpenChest((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowChestDialog();
}
break;
case TileSpec.BankVault:
if (unwalkableAction == UnwalkableTileAction.Locker)
{
_mapActions.OpenLocker((byte)cellState.Coordinate.X, (byte)cellState.Coordinate.Y);
_inGameDialogActions.ShowLockerDialog();
}
break;
}
}
else if (cellState.InBounds && !cellState.Character.HasValue && !cellState.NPC.HasValue)
Expand All @@ -122,7 +129,6 @@ public void LeftClick(IMapCellState cellState, IMouseCursorRenderer mouseRendere
_hudControlProvider.GetComponent<ICharacterAnimator>(HudControlIdentifier.CharacterAnimator)
.StartMainCharacterWalkAnimation(Option.Some(cellState.Coordinate));
}
// todo: board, jukebox

_userInputTimeRepository.LastInputTime = DateTime.Now;
}
Expand Down
19 changes: 18 additions & 1 deletion EndlessClient/Dialogs/Actions/InGameDialogActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class InGameDialogActions : IInGameDialogActions, INPCInteractionNotifier
private readonly IShopDataRepository _shopDataRepository;
private readonly IQuestDataRepository _questDataRepository;
private readonly IChestDialogFactory _chestDialogFactory;
private readonly ILockerDialogFactory _lockerDialogFactory;
private readonly IShopDialogFactory _shopDialogFactory;
private readonly IQuestDialogFactory _questDialogFactory;

Expand All @@ -33,7 +34,8 @@ public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialog
IActiveDialogRepository activeDialogRepository,
IShopDataRepository shopDataRepository,
IQuestDataRepository questDataRepository,
IChestDialogFactory chestDialogFactory)
IChestDialogFactory chestDialogFactory,
ILockerDialogFactory lockerDialogFactory)
{
_friendIgnoreListDialogFactory = friendIgnoreListDialogFactory;
_paperdollDialogFactory = paperdollDialogFactory;
Expand All @@ -43,6 +45,7 @@ public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialog
_shopDataRepository = shopDataRepository;
_questDataRepository = questDataRepository;
_chestDialogFactory = chestDialogFactory;
_lockerDialogFactory = lockerDialogFactory;
_shopDialogFactory = shopDialogFactory;
_questDialogFactory = questDialogFactory;
}
Expand Down Expand Up @@ -163,6 +166,18 @@ public void ShowChestDialog()
dlg.Show();
});
}

public void ShowLockerDialog()
{
_activeDialogRepository.LockerDialog.MatchNone(() =>
{
var dlg = _lockerDialogFactory.Create();
dlg.DialogClosed += (_, _) => _activeDialogRepository.LockerDialog = Option.None<LockerDialog>();
_activeDialogRepository.LockerDialog = Option.Some(dlg);

dlg.Show();
});
}
}

public interface IInGameDialogActions
Expand All @@ -182,5 +197,7 @@ public interface IInGameDialogActions
void ShowQuestDialog();

void ShowChestDialog();

void ShowLockerDialog();
}
}
10 changes: 9 additions & 1 deletion EndlessClient/Dialogs/ActiveDialogRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface IActiveDialogProvider : IDisposable

Option<ChestDialog> ChestDialog { get; }

Option<LockerDialog> LockerDialog { get; }

IReadOnlyList<Option<IXNADialog>> ActiveDialogs { get; }
}

Expand All @@ -40,7 +42,9 @@ public interface IActiveDialogRepository : IDisposable

Option<QuestDialog> QuestDialog { get; set; }

Option<ChestDialog> ChestDialog { get; set; }
Option<ChestDialog> ChestDialog { get; set; }

Option<LockerDialog> LockerDialog { get; set; }

IReadOnlyList<Option<IXNADialog>> ActiveDialogs { get; }
}
Expand All @@ -62,6 +66,8 @@ public class ActiveDialogRepository : IActiveDialogRepository, IActiveDialogProv

public Option<ChestDialog> ChestDialog { get; set; }

public Option<LockerDialog> LockerDialog { get; set; }

IReadOnlyList<Option<IXNADialog>> ActiveDialogs
{
get
Expand All @@ -75,6 +81,7 @@ IReadOnlyList<Option<IXNADialog>> ActiveDialogs
ShopDialog.Map(d => (IXNADialog)d),
QuestDialog.Map(d => (IXNADialog)d),
ChestDialog.Map(d => (IXNADialog)d),
LockerDialog.Map(d => (IXNADialog)d),
}.ToList();
}
}
Expand All @@ -95,6 +102,7 @@ public void Dispose()
ShopDialog = Option.None<ShopDialog>();
QuestDialog = Option.None<QuestDialog>();
ChestDialog = Option.None<ChestDialog>();
LockerDialog = Option.None<LockerDialog>();
}
}
}
2 changes: 1 addition & 1 deletion EndlessClient/Dialogs/ChestDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void RefreshItemList()

private void TakeItem(IInventoryItem item, EIFRecord itemData)
{
if (!_inventorySpaceValidator.ItemFits(itemData.Size))
if (!_inventorySpaceValidator.ItemFits(item.ItemID))
{
var dlg = _messageBoxFactory.CreateMessageBox(EOResourceID.STATUS_LABEL_ITEM_PICKUP_NO_SPACE_LEFT, EOResourceID.STATUS_LABEL_TYPE_WARNING);
dlg.ShowDialog();
Expand Down
74 changes: 74 additions & 0 deletions EndlessClient/Dialogs/Factories/LockerDialogFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using AutomaticTypeMapper;
using EndlessClient.ControlSets;
using EndlessClient.Dialogs.Services;
using EndlessClient.HUD;
using EndlessClient.HUD.Inventory;
using EOLib.Domain.Character;
using EOLib.Domain.Map;
using EOLib.Graphics;
using EOLib.IO.Repositories;
using EOLib.Localization;

namespace EndlessClient.Dialogs.Factories
{
[AutoMappedType]
public class LockerDialogFactory : ILockerDialogFactory
{
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly ILockerActions _lockerActions;
private readonly IEODialogButtonService _dialogButtonService;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly IInventorySpaceValidator _inventorySpaceValidator;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly ICharacterProvider _characterProvider;
private readonly ILockerDataProvider _lockerDataProvider;
private readonly IHudControlProvider _hudControlProvider;
private readonly IEIFFileProvider _eifFileProvider;

public LockerDialogFactory(INativeGraphicsManager nativeGraphicsManager,
ILockerActions lockerActions,
IEODialogButtonService dialogButtonService,
ILocalizedStringFinder localizedStringFinder,
IInventorySpaceValidator inventorySpaceValidator,
IStatusLabelSetter statusLabelSetter,
IEOMessageBoxFactory messageBoxFactory,
ICharacterProvider characterProvider,
ILockerDataProvider lockerDataProvider,
IHudControlProvider hudControlProvider,
IEIFFileProvider eifFileProvider)
{
_nativeGraphicsManager = nativeGraphicsManager;
_lockerActions = lockerActions;
_dialogButtonService = dialogButtonService;
_localizedStringFinder = localizedStringFinder;
_inventorySpaceValidator = inventorySpaceValidator;
_statusLabelSetter = statusLabelSetter;
_messageBoxFactory = messageBoxFactory;
_characterProvider = characterProvider;
_lockerDataProvider = lockerDataProvider;
_hudControlProvider = hudControlProvider;
_eifFileProvider = eifFileProvider;
}

public LockerDialog Create()
{
return new LockerDialog(_nativeGraphicsManager,
_lockerActions,
_dialogButtonService,
_localizedStringFinder,
_inventorySpaceValidator,
_statusLabelSetter,
_messageBoxFactory,
_characterProvider,
_lockerDataProvider,
_hudControlProvider,
_eifFileProvider);
}
}

public interface ILockerDialogFactory
{
LockerDialog Create();
}
}
Loading

0 comments on commit 63b4416

Please sign in to comment.