-
Notifications
You must be signed in to change notification settings - Fork 16
/
MapInteractionController.cs
181 lines (167 loc) · 8.38 KB
/
MapInteractionController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using AutomaticTypeMapper;
using EndlessClient.ControlSets;
using EndlessClient.Dialogs.Actions;
using EndlessClient.Dialogs.Factories;
using EndlessClient.HUD;
using EndlessClient.HUD.Controls;
using EndlessClient.HUD.Inventory;
using EndlessClient.HUD.Panels;
using EndlessClient.Input;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.Factories;
using EOLib.Domain.Character;
using EOLib.Domain.Interact;
using EOLib.Domain.Item;
using EOLib.Domain.Map;
using EOLib.IO.Map;
using EOLib.Localization;
using Optional;
using Optional.Collections;
using System;
namespace EndlessClient.Controllers
{
[AutoMappedType]
public class MapInteractionController : IMapInteractionController
{
private readonly IMapActions _mapActions;
private readonly ICharacterActions _characterActions;
private readonly IInGameDialogActions _inGameDialogActions;
private readonly IPaperdollActions _paperdollActions;
private readonly ICurrentMapStateProvider _currentMapStateProvider;
private readonly ICharacterProvider _characterProvider;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly IInventorySpaceValidator _inventorySpaceValidator;
private readonly IHudControlProvider _hudControlProvider;
private readonly ICharacterRendererProvider _characterRendererProvider;
private readonly IContextMenuRepository _contextMenuRepository;
private readonly IUserInputTimeRepository _userInputTimeRepository;
private readonly IEOMessageBoxFactory _eoMessageBoxFactory;
private readonly IContextMenuRendererFactory _contextMenuRendererFactory;
public MapInteractionController(IMapActions mapActions,
ICharacterActions characterActions,
IInGameDialogActions inGameDialogActions,
IPaperdollActions paperdollActions,
ICurrentMapStateProvider currentMapStateProvider,
ICharacterProvider characterProvider,
IStatusLabelSetter statusLabelSetter,
IInventorySpaceValidator inventorySpaceValidator,
IHudControlProvider hudControlProvider,
ICharacterRendererProvider characterRendererProvider,
IContextMenuRepository contextMenuRepository,
IUserInputTimeRepository userInputTimeRepository,
IEOMessageBoxFactory eoMessageBoxFactory,
IContextMenuRendererFactory contextMenuRendererFactory)
{
_mapActions = mapActions;
_characterActions = characterActions;
_inGameDialogActions = inGameDialogActions;
_paperdollActions = paperdollActions;
_currentMapStateProvider = currentMapStateProvider;
_characterProvider = characterProvider;
_statusLabelSetter = statusLabelSetter;
_inventorySpaceValidator = inventorySpaceValidator;
_hudControlProvider = hudControlProvider;
_characterRendererProvider = characterRendererProvider;
_contextMenuRepository = contextMenuRepository;
_userInputTimeRepository = userInputTimeRepository;
_eoMessageBoxFactory = eoMessageBoxFactory;
_contextMenuRendererFactory = contextMenuRendererFactory;
}
public void LeftClick(IMapCellState cellState, IMouseCursorRenderer mouseRenderer)
{
if (!InventoryPanel.NoItemsDragging())
{
return;
}
var optionalItem = cellState.Items.FirstOrNone();
if (optionalItem.HasValue)
{
var item = optionalItem.ValueOr(Item.None);
if (!_inventorySpaceValidator.ItemFits(item))
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_INFORMATION, EOResourceID.STATUS_LABEL_ITEM_PICKUP_NO_SPACE_LEFT);
else
HandlePickupResult(_mapActions.PickUpItem(item), item);
}
else if (cellState.Sign.HasValue)
{
var sign = cellState.Sign.ValueOr(Sign.None);
var messageBox = _eoMessageBoxFactory.CreateMessageBox(sign.Message, sign.Title);
messageBox.ShowDialog();
}
else if (cellState.TileSpec == TileSpec.Chest)
{
// todo: chest request, show dialog
}
else if (_characterProvider.MainCharacter.RenderProperties.SitState != SitState.Standing)
{
_characterActions.ToggleSit();
}
else if (cellState.InBounds && !cellState.Character.HasValue && !cellState.NPC.HasValue)
{
mouseRenderer.AnimateClick();
_hudControlProvider.GetComponent<ICharacterAnimator>(HudControlIdentifier.CharacterAnimator)
.StartMainCharacterWalkAnimation(Option.Some(cellState.Coordinate));
}
// todo: board, jukebox
_userInputTimeRepository.LastInputTime = DateTime.Now;
}
// todo: move to new controller for character interaction
public void RightClick(IMapCellState cellState)
{
if (!cellState.Character.HasValue)
return;
cellState.Character.MatchSome(c =>
{
if (c == _characterProvider.MainCharacter)
{
_paperdollActions.RequestPaperdoll(_characterProvider.MainCharacter.ID);
_inGameDialogActions.ShowPaperdollDialog(_characterProvider.MainCharacter, isMainCharacter: true);
_userInputTimeRepository.LastInputTime = DateTime.Now;
}
else if (_characterRendererProvider.CharacterRenderers.ContainsKey(c.ID))
{
_contextMenuRepository.ContextMenu = _contextMenuRepository.ContextMenu.Match(
some: cmr =>
{
cmr.Dispose();
return Option.Some(_contextMenuRendererFactory.CreateContextMenuRenderer(_characterRendererProvider.CharacterRenderers[c.ID]));
},
none: () => Option.Some(_contextMenuRendererFactory.CreateContextMenuRenderer(_characterRendererProvider.CharacterRenderers[c.ID])));
_contextMenuRepository.ContextMenu.MatchSome(r => r.Initialize());
}
});
}
private void HandlePickupResult(ItemPickupResult pickupResult, IItem item)
{
switch (pickupResult)
{
case ItemPickupResult.DropProtection:
var message = EOResourceID.STATUS_LABEL_ITEM_PICKUP_PROTECTED;
var extra = string.Empty;
item.OwningPlayerID.MatchSome(playerId =>
{
message = EOResourceID.STATUS_LABEL_ITEM_PICKUP_PROTECTED_BY;
if (_currentMapStateProvider.Characters.ContainsKey(playerId))
{
extra = _currentMapStateProvider.Characters[playerId].Name;
}
});
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_INFORMATION, message, extra);
break;
case ItemPickupResult.TooHeavy:
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.DIALOG_ITS_TOO_HEAVY_WEIGHT);
break;
case ItemPickupResult.TooFar:
case ItemPickupResult.Ok: break;
default: throw new ArgumentOutOfRangeException(nameof(pickupResult), pickupResult, null);
}
}
private InventoryPanel InventoryPanel => _hudControlProvider.GetComponent<InventoryPanel>(HudControlIdentifier.InventoryPanel);
}
public interface IMapInteractionController
{
void LeftClick(IMapCellState cellState, IMouseCursorRenderer mouseRenderer);
void RightClick(IMapCellState cellState);
}
}