-
Notifications
You must be signed in to change notification settings - Fork 16
/
UnwalkableTileActions.cs
199 lines (178 loc) · 8.6 KB
/
UnwalkableTileActions.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using AutomaticTypeMapper;
using EndlessClient.Audio;
using EndlessClient.Dialogs.Factories;
using EndlessClient.HUD;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
using EOLib.Domain.Map;
using EOLib.IO.Map;
using EOLib.Localization;
using System.Collections.Generic;
namespace EndlessClient.Input
{
public enum UnwalkableTileAction
{
None,
Chair,
Chest,
Door,
Locker,
Character,
Board,
Jukebox,
}
[AutoMappedType]
public class UnwalkableTileActions : IUnwalkableTileActions
{
private readonly IMapCellStateProvider _mapCellStateProvider;
private readonly ICharacterProvider _characterProvider;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly IUnlockDoorValidator _unlockDoorValidator;
private readonly IUnlockChestValidator _unlockChestValidator;
private readonly IEOMessageBoxFactory _eoMessageBoxFactory;
private readonly IEOMessageBoxFactory _messageBoxFactory;
private readonly ISfxPlayer _sfxPlayer;
public UnwalkableTileActions(IMapCellStateProvider mapCellStateProvider,
ICharacterProvider characterProvider,
IStatusLabelSetter statusLabelSetter,
ICurrentMapStateRepository currentMapStateRepository,
IUnlockDoorValidator unlockDoorValidator,
IUnlockChestValidator unlockChestValidator,
IEOMessageBoxFactory eoMessageBoxFactory,
IEOMessageBoxFactory messageBoxFactory,
ISfxPlayer sfxPlayer)
{
_mapCellStateProvider = mapCellStateProvider;
_characterProvider = characterProvider;
_statusLabelSetter = statusLabelSetter;
_currentMapStateRepository = currentMapStateRepository;
_unlockDoorValidator = unlockDoorValidator;
_unlockChestValidator = unlockChestValidator;
_eoMessageBoxFactory = eoMessageBoxFactory;
_messageBoxFactory = messageBoxFactory;
_sfxPlayer = sfxPlayer;
}
public (IReadOnlyList<UnwalkableTileAction>, IMapCellState) GetUnwalkableTileActions()
{
var destX = MainCharacter.RenderProperties.GetDestinationX();
var destY = MainCharacter.RenderProperties.GetDestinationY();
return GetUnwalkableTileActions(destX, destY);
}
public (IReadOnlyList<UnwalkableTileAction>, IMapCellState) GetUnwalkableTileActions(int x, int y)
{
var cellState = _mapCellStateProvider.GetCellStateAt(x, y);
var action = GetUnwalkableTileActions(cellState);
return (action, cellState);
}
public IReadOnlyList<UnwalkableTileAction> GetUnwalkableTileActions(IMapCellState cellState)
{
if (MainCharacter.RenderProperties.SitState != SitState.Standing)
return new[] { UnwalkableTileAction.None };
return cellState.Character.Match(
some: c => new[] { HandleWalkThroughOtherCharacter(c) }, //todo: walk through players after certain elapsed time (3-5sec?)
none: () => cellState.Warp.Match(
some: w => new[] { HandleWalkToWarpTile(w), HandleWalkToTileSpec(cellState) },
none: () => new[] { HandleWalkToTileSpec(cellState) }));
}
private UnwalkableTileAction HandleWalkThroughOtherCharacter(Character c)
{
// todo: caller handles this
// EOGame.Instance.Hud.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_ACTION,
// EOResourceID.STATUS_LABEL_KEEP_MOVING_THROUGH_PLAYER);
// if (_startWalkingThroughPlayerTime == null)
// _startWalkingThroughPlayerTime = DateTime.Now;
// else if ((DateTime.Now - _startWalkingThroughPlayerTime.Value).TotalSeconds > 5)
// {
// _startWalkingThroughPlayerTime = null;
// goto case TileInfoReturnType.IsTileSpec;
// }
return UnwalkableTileAction.Character;
}
private UnwalkableTileAction HandleWalkToWarpTile(Warp warp)
{
if (warp.DoorType != DoorSpec.NoDoor)
{
if (!_unlockDoorValidator.CanMainCharacterOpenDoor(warp))
{
var messageBox = _eoMessageBoxFactory.CreateMessageBox(DialogResourceID.DOOR_LOCKED);
messageBox.ShowDialog();
var requiredKey = _unlockDoorValidator.GetRequiredKey(warp);
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING,
EOResourceID.STATUS_LABEL_THE_DOOR_IS_LOCKED_EXCLAMATION,
requiredKey.Match(x => $" - {x}", () => string.Empty));
_sfxPlayer.PlaySfx(SoundEffectID.DoorOrChestLocked);
}
else if (!_currentMapStateRepository.OpenDoors.Contains(warp) &&
!_currentMapStateRepository.PendingDoors.Contains(warp))
{
return UnwalkableTileAction.Door;
}
}
else if (warp.LevelRequirement > 0 && MainCharacter.Stats[CharacterStat.Level] < warp.LevelRequirement)
{
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING,
EOResourceID.STATUS_LABEL_NOT_READY_TO_USE_ENTRANCE,
" - LVL " + warp.LevelRequirement);
}
return UnwalkableTileAction.None;
}
private UnwalkableTileAction HandleWalkToTileSpec(IMapCellState cellState)
{
switch (cellState.TileSpec)
{
case TileSpec.ChairDown:
case TileSpec.ChairLeft:
case TileSpec.ChairRight:
case TileSpec.ChairUp:
case TileSpec.ChairDownRight:
case TileSpec.ChairUpLeft:
case TileSpec.ChairAll:
return UnwalkableTileAction.Chair;
case TileSpec.Chest:
return cellState.ChestKey.Match(
some: key =>
{
if (!_unlockChestValidator.CanMainCharacterOpenChest(key))
{
var dlg = _messageBoxFactory.CreateMessageBox(DialogResourceID.CHEST_LOCKED);
dlg.ShowDialog();
var requiredKey = _unlockChestValidator.GetRequiredKeyName(key);
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_THE_CHEST_IS_LOCKED_EXCLAMATION, requiredKey.Match(x => $" - {x}", () => string.Empty));
_sfxPlayer.PlaySfx(SoundEffectID.DoorOrChestLocked);
return UnwalkableTileAction.None;
}
else
{
return UnwalkableTileAction.Chest;
}
},
none: () =>
{
return UnwalkableTileAction.Chest;
});
case TileSpec.BankVault:
return UnwalkableTileAction.Locker;
case TileSpec.Board1:
case TileSpec.Board2:
case TileSpec.Board3:
case TileSpec.Board4:
case TileSpec.Board5:
case TileSpec.Board6:
case TileSpec.Board7:
case TileSpec.Board8:
return UnwalkableTileAction.Board;
case TileSpec.Jukebox:
return UnwalkableTileAction.Jukebox;
}
return UnwalkableTileAction.None;
}
private Character MainCharacter => _characterProvider.MainCharacter;
}
public interface IUnwalkableTileActions
{
(IReadOnlyList<UnwalkableTileAction>, IMapCellState) GetUnwalkableTileActions();
(IReadOnlyList<UnwalkableTileAction>, IMapCellState) GetUnwalkableTileActions(int x, int y);
IReadOnlyList<UnwalkableTileAction> GetUnwalkableTileActions(IMapCellState mapCellState);
}
}