Skip to content

Commit

Permalink
Add request of board and display of board dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed May 16, 2023
1 parent 10491f9 commit 2205483
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 40 deletions.
19 changes: 19 additions & 0 deletions EOLib.IO/Extensions/TileSpecExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using EOLib.IO.Map;

namespace EOLib.IO.Extensions
{
public static class TileSpecExtensions
{
public static bool IsBoard(this TileSpec tileSpec)
{
return tileSpec == TileSpec.Board1 ||
tileSpec == TileSpec.Board2 ||
tileSpec == TileSpec.Board3 ||
tileSpec == TileSpec.Board4 ||
tileSpec == TileSpec.Board5 ||
tileSpec == TileSpec.Board6 ||
tileSpec == TileSpec.Board7 ||
tileSpec == TileSpec.Board8;
}
}
}
17 changes: 13 additions & 4 deletions EOLib/Domain/Map/MapActions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Item;
using EOLib.IO.Map;
using EOLib.Net;
using EOLib.Net.Communication;

Expand All @@ -13,19 +14,16 @@ public class MapActions : IMapActions
private readonly IItemPickupValidator _itemPickupValidator;
private readonly ICharacterProvider _characterProvider;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IChestDataProvider _chestDataProvider;

public MapActions(IPacketSendService packetSendService,
IItemPickupValidator itemPickupValidator,
ICharacterProvider characterProvider,
ICurrentMapStateRepository currentMapStateRepository,
IChestDataProvider chestDataProvider)
ICurrentMapStateRepository currentMapStateRepository)
{
_packetSendService = packetSendService;
_itemPickupValidator = itemPickupValidator;
_characterProvider = characterProvider;
_currentMapStateRepository = currentMapStateRepository;
_chestDataProvider = chestDataProvider;
}

public void RequestRefresh()
Expand Down Expand Up @@ -84,6 +82,15 @@ public void OpenLocker(MapCoordinate location)

_packetSendService.SendPacket(packet);
}

public void OpenBoard(TileSpec boardSpec)
{
var packet = new PacketBuilder(PacketFamily.Board, PacketAction.Open)
.AddShort(boardSpec - TileSpec.Board1)
.Build();

_packetSendService.SendPacket(packet);
}
}

public interface IMapActions
Expand All @@ -97,5 +104,7 @@ public interface IMapActions
void OpenChest(MapCoordinate location);

void OpenLocker(MapCoordinate location);

void OpenBoard(TileSpec boardSpec);
}
}
17 changes: 15 additions & 2 deletions EndlessClient/Controllers/MapInteractionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using EOLib.Domain.Item;
using EOLib.Domain.Map;
using EOLib.Domain.Spells;
using EOLib.IO.Extensions;
using EOLib.IO.Map;
using EOLib.Localization;
using Optional;
Expand Down Expand Up @@ -121,20 +122,29 @@ public void LeftClick(IMapCellState cellState)
var sign = cellState.Sign.ValueOr(Sign.None);
var messageBox = _messageBoxFactory.CreateMessageBox(sign.Message, sign.Title);
messageBox.ShowDialog();
_sfxPlayer.PlaySfx(SoundEffectID.ChestOpen);
}
// vanilla client prioritizes standing first, then board interaction
else if (_characterProvider.MainCharacter.RenderProperties.SitState != SitState.Standing)
{
_characterActions.ToggleSit();
}
else if (InteractableTileSpec(cellState.TileSpec) && CharacterIsCloseEnough(cellState.Coordinate))
else if (InteractableTileSpec(cellState.TileSpec) && (cellState.TileSpec.IsBoard() || CharacterIsCloseEnough(cellState.Coordinate)))
{
var unwalkableActions = _unwalkableTileActions.GetUnwalkableTileActions(cellState);

foreach (var unwalkableAction in unwalkableActions)
{

if (cellState.TileSpec.IsBoard())
{
_mapActions.OpenBoard(cellState.TileSpec);
_inGameDialogActions.ShowBoardDialog();
continue;
}

switch (cellState.TileSpec)
{
// todo: implement for other clickable tile specs (board, jukebox, etc)
case TileSpec.Chest:
if (unwalkableAction == UnwalkableTileAction.Chest)
{
Expand All @@ -149,6 +159,9 @@ public void LeftClick(IMapCellState cellState)
_inGameDialogActions.ShowLockerDialog();
}
break;
case TileSpec.Jukebox:
// todo
break;
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions EndlessClient/Dialogs/Actions/InGameDialogActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class InGameDialogActions : IInGameDialogActions
private readonly IBardDialogFactory _bardDialogFactory;
private readonly IScrollingListDialogFactory _scrollingListDialogFactory;
private readonly ITradeDialogFactory _tradeDialogFactory;
private readonly IBoardDialogFactory _boardDialogFactory;
private readonly ISfxPlayer _sfxPlayer;
private readonly IShopDialogFactory _shopDialogFactory;
private readonly IQuestDialogFactory _questDialogFactory;
Expand All @@ -51,6 +52,7 @@ public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialog
IBardDialogFactory bardDialogFactory,
IScrollingListDialogFactory scrollingListDialogFactory,
ITradeDialogFactory tradeDialogFactory,
IBoardDialogFactory boardDialogFactory,
ISfxPlayer sfxPlayer)
{
_friendIgnoreListDialogFactory = friendIgnoreListDialogFactory;
Expand All @@ -68,6 +70,7 @@ public InGameDialogActions(IFriendIgnoreListDialogFactory friendIgnoreListDialog
_bardDialogFactory = bardDialogFactory;
_scrollingListDialogFactory = scrollingListDialogFactory;
_tradeDialogFactory = tradeDialogFactory;
_boardDialogFactory = boardDialogFactory;
_sfxPlayer = sfxPlayer;
_shopDialogFactory = shopDialogFactory;
_questDialogFactory = questDialogFactory;
Expand Down Expand Up @@ -303,6 +306,20 @@ public void CloseTradeDialog()
_activeDialogRepository.TradeDialog.MatchSome(dlg => dlg.Close());
}

public void ShowBoardDialog()
{
_activeDialogRepository.BoardDialog.MatchNone(() =>
{
var dlg = _boardDialogFactory.Create();
dlg.DialogClosed += (_, _) => _activeDialogRepository.BoardDialog = Option.None<BoardDialog>();
_activeDialogRepository.BoardDialog = Option.Some(dlg);

UseDefaultDialogSounds(dlg);

dlg.Show();
});
}

private void UseDefaultDialogSounds(ScrollingListDialog dialog)
{
UseDefaultDialogSounds((BaseEODialog)dialog);
Expand Down Expand Up @@ -360,5 +377,7 @@ public interface IInGameDialogActions
void ShowTradeDialog();

void CloseTradeDialog();

void ShowBoardDialog();
}
}
43 changes: 28 additions & 15 deletions EndlessClient/Dialogs/ActiveDialogRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public interface IActiveDialogProvider : IDisposable

Option<EOMessageBox> MessageBox { get; }

Option<BoardDialog> BoardDialog { get; }

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

Expand Down Expand Up @@ -70,6 +72,8 @@ public interface IActiveDialogRepository : IDisposable

Option<EOMessageBox> MessageBox { get; set; }

Option<BoardDialog> BoardDialog { get; set; }

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

Expand Down Expand Up @@ -104,27 +108,35 @@ public class ActiveDialogRepository : IActiveDialogRepository, IActiveDialogProv

public Option<EOMessageBox> MessageBox { get; set; }

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

IReadOnlyList<Option<IXNADialog>> ActiveDialogs
{
get
{
return new[]
return new Option<IXNADialog>[]
{
FriendIgnoreDialog.Map(d => (IXNADialog)d),
SessionExpDialog.Map(d => (IXNADialog)d),
QuestStatusDialog.Map(d => (IXNADialog)d),
PaperdollDialog.Map(d => (IXNADialog)d),
ShopDialog.Map(d => (IXNADialog)d),
QuestDialog.Map(d => (IXNADialog)d),
ChestDialog.Map(d => (IXNADialog)d),
LockerDialog.Map(d => (IXNADialog)d),
BankAccountDialog.Map(d => (IXNADialog)d),
SkillmasterDialog.Map(d => (IXNADialog)d),
BardDialog.Map(d => (IXNADialog)d),
MessageDialog.Map(d => (IXNADialog)d),
TradeDialog.Map(d => (IXNADialog)d),
MessageBox.Map(d => (IXNADialog)d),
FriendIgnoreDialog.Map(Map),
SessionExpDialog.Map(Map),
QuestStatusDialog.Map(Map),
PaperdollDialog.Map(Map),
ShopDialog.Map(Map),
QuestDialog.Map(Map),
ChestDialog.Map(Map),
LockerDialog.Map(Map),
BankAccountDialog.Map(Map),
SkillmasterDialog.Map(Map),
BardDialog.Map(Map),
MessageDialog.Map(Map),
TradeDialog.Map(Map),
MessageBox.Map(Map),
BoardDialog.Map(Map),
}.ToList();

static IXNADialog Map(object d)
{
return (IXNADialog)d;
}
}
}

Expand All @@ -151,6 +163,7 @@ public void Dispose()
MessageDialog = Option.None<ScrollingListDialog>();
TradeDialog = Option.None<TradeDialog>();
MessageBox = Option.None<EOMessageBox>();
BoardDialog = Option.None<BoardDialog>();
}
}
}
14 changes: 14 additions & 0 deletions EndlessClient/Dialogs/BoardDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using EndlessClient.Dialogs.Services;
using EOLib.Graphics;

namespace EndlessClient.Dialogs
{
public class BoardDialog : ScrollingListDialog
{
public BoardDialog(INativeGraphicsManager nativeGraphicsManager,
IEODialogButtonService dialogButtonService)
: base(nativeGraphicsManager, dialogButtonService, ScrollingListDialogSize.MediumWithHeader)
{
}
}
}
30 changes: 30 additions & 0 deletions EndlessClient/Dialogs/Factories/BoardDialogFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Services;
using EOLib.Graphics;

namespace EndlessClient.Dialogs.Factories
{
[AutoMappedType]
public class BoardDialogFactory : IBoardDialogFactory
{
private readonly INativeGraphicsManager _nativeGraphicsManager;
private readonly IEODialogButtonService _eoDialogButtonService;

public BoardDialogFactory(INativeGraphicsManager nativeGraphicsManager,
IEODialogButtonService eoDialogButtonService)
{
_nativeGraphicsManager = nativeGraphicsManager;
_eoDialogButtonService = eoDialogButtonService;
}

public BoardDialog Create()
{
return new BoardDialog(_nativeGraphicsManager, _eoDialogButtonService);
}
}

public interface IBoardDialogFactory
{
BoardDialog Create();
}
}
Loading

0 comments on commit 2205483

Please sign in to comment.