-
Notifications
You must be signed in to change notification settings - Fork 16
/
CharacterAnimationActions.cs
309 lines (261 loc) · 12.7 KB
/
CharacterAnimationActions.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
using AutomaticTypeMapper;
using EndlessClient.Audio;
using EndlessClient.ControlSets;
using EndlessClient.HUD;
using EndlessClient.HUD.Controls;
using EndlessClient.Rendering.Map;
using EOLib;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.Domain.Spells;
using EOLib.IO;
using EOLib.IO.Map;
using EOLib.IO.Repositories;
using EOLib.Localization;
using Optional;
using Optional.Collections;
using System.Linq;
namespace EndlessClient.Rendering.Character
{
[AutoMappedType]
public class CharacterAnimationActions : ICharacterAnimationActions, IOtherCharacterAnimationNotifier, IEffectNotifier, IEmoteNotifier
{
private readonly IHudControlProvider _hudControlProvider;
private readonly ICharacterRepository _characterRepository;
private readonly ICurrentMapStateProvider _currentMapStateProvider;
private readonly ICharacterRendererProvider _characterRendererProvider;
private readonly ICurrentMapProvider _currentMapProvider;
private readonly ISpikeTrapActions _spikeTrapActions;
private readonly IPubFileProvider _pubFileProvider;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly ISfxPlayer _sfxPlayer;
public CharacterAnimationActions(IHudControlProvider hudControlProvider,
ICharacterRepository characterRepository,
ICurrentMapStateProvider currentMapStateProvider,
ICharacterRendererProvider characterRendererProvider,
ICurrentMapProvider currentMapProvider,
ISpikeTrapActions spikeTrapActions,
IPubFileProvider pubFileProvider,
IStatusLabelSetter statusLabelSetter,
ISfxPlayer sfxPlayer)
{
_hudControlProvider = hudControlProvider;
_characterRepository = characterRepository;
_currentMapStateProvider = currentMapStateProvider;
_characterRendererProvider = characterRendererProvider;
_currentMapProvider = currentMapProvider;
_spikeTrapActions = spikeTrapActions;
_pubFileProvider = pubFileProvider;
_statusLabelSetter = statusLabelSetter;
_sfxPlayer = sfxPlayer;
}
public void Face(EODirection direction)
{
if (!_hudControlProvider.IsInGame)
return;
CancelSpellPrep();
Animator.MainCharacterFace(direction);
}
public void StartWalking()
{
if (!_hudControlProvider.IsInGame)
return;
CancelSpellPrep();
Animator.StartMainCharacterWalkAnimation(Option.None<MapCoordinate>());
ShowWaterSplashiesIfNeeded(CharacterActionState.Walking, _characterRepository.MainCharacter.ID);
}
public void StartAttacking(int noteIndex = -1)
{
if (!_hudControlProvider.IsInGame)
return;
CancelSpellPrep();
if (noteIndex >= 0)
Animator.Emote(_characterRepository.MainCharacter.ID, EOLib.Domain.Character.Emote.MusicNotes);
Animator.StartMainCharacterAttackAnimation();
ShowWaterSplashiesIfNeeded(CharacterActionState.Attacking, _characterRepository.MainCharacter.ID);
PlayWeaponSound(_characterRepository.MainCharacter, noteIndex);
}
public bool PrepareMainCharacterSpell(int spellId, ISpellTargetable spellTarget)
{
if (!_hudControlProvider.IsInGame)
return false;
var spellData = _pubFileProvider.ESFFile[spellId];
_characterRendererProvider.MainCharacterRenderer.MatchSome(r => r.ShoutSpellPrep(spellData.Shout));
return Animator.MainCharacterShoutSpellPrep(spellData, spellTarget);
}
public void Emote(Emote whichEmote)
{
if (!_hudControlProvider.IsInGame)
return;
Animator.Emote(_characterRepository.MainCharacter.ID, whichEmote);
}
public void StartOtherCharacterWalkAnimation(int characterID, byte destinationX, byte destinationY, EODirection direction)
{
if (!_hudControlProvider.IsInGame)
return;
Animator.StartOtherCharacterWalkAnimation(characterID, destinationX, destinationY, direction);
ShowWaterSplashiesIfNeeded(CharacterActionState.Walking, characterID);
_spikeTrapActions.HideSpikeTrap(characterID);
_spikeTrapActions.ShowSpikeTrap(characterID);
}
public void StartOtherCharacterAttackAnimation(int characterID, int noteIndex = -1)
{
if (!_hudControlProvider.IsInGame)
return;
if (noteIndex >= 0)
Animator.Emote(characterID, EOLib.Domain.Character.Emote.MusicNotes);
Animator.StartOtherCharacterAttackAnimation(characterID);
ShowWaterSplashiesIfNeeded(CharacterActionState.Attacking, characterID);
if (_currentMapStateProvider.Characters.ContainsKey(characterID))
PlayWeaponSound(_currentMapStateProvider.Characters[characterID], noteIndex);
}
public void NotifyWarpLeaveEffect(short characterId, WarpAnimation anim)
{
if (anim == WarpAnimation.Admin)
_characterRendererProvider.CharacterRenderers[characterId].ShowWarpLeave();
}
public void NotifyWarpEnterEffect(short characterId, WarpAnimation anim)
{
if (anim == WarpAnimation.Admin)
{
if (!_characterRendererProvider.CharacterRenderers.ContainsKey(characterId))
_characterRendererProvider.NeedsWarpArriveAnimation.Add(characterId);
else
_characterRendererProvider.CharacterRenderers[characterId].ShowWarpArrive();
}
}
public void NotifyPotionEffect(short playerId, int effectId)
{
if (playerId == _characterRepository.MainCharacter.ID)
_characterRendererProvider.MainCharacterRenderer.MatchSome(cr => cr.ShowPotionAnimation(effectId));
else if (_characterRendererProvider.CharacterRenderers.ContainsKey(playerId))
_characterRendererProvider.CharacterRenderers[playerId].ShowPotionAnimation(effectId);
}
public void NotifyStartSpellCast(short playerId, short spellId)
{
var shoutName = _pubFileProvider.ESFFile[spellId].Shout;
_characterRendererProvider.CharacterRenderers[playerId].ShoutSpellPrep(shoutName.ToLower());
}
public void NotifySelfSpellCast(short playerId, short spellId, int spellHp, byte percentHealth)
{
var spellGraphic = _pubFileProvider.ESFFile[spellId].Graphic;
if (playerId == _characterRepository.MainCharacter.ID)
{
_characterRendererProvider.MainCharacterRenderer.MatchSome(cr =>
{
cr.ShoutSpellCast();
cr.ShowSpellAnimation(spellGraphic);
cr.ShowDamageCounter(spellHp, percentHealth, isHeal: true);
});
}
else
{
Animator.StartOtherCharacterSpellCast(playerId);
_characterRendererProvider.CharacterRenderers[playerId].ShoutSpellCast();
_characterRendererProvider.CharacterRenderers[playerId].ShowSpellAnimation(spellGraphic);
_characterRendererProvider.CharacterRenderers[playerId].ShowDamageCounter(spellHp, percentHealth, isHeal: true);
}
}
public void NotifyTargetOtherSpellCast(short sourcePlayerID, short targetPlayerID, short spellId, int recoveredHP, byte targetPercentHealth)
{
if (sourcePlayerID == _characterRepository.MainCharacter.ID)
{
_characterRendererProvider.MainCharacterRenderer.MatchSome(cr => cr.ShoutSpellCast());
}
else
{
Animator.StartOtherCharacterSpellCast(sourcePlayerID);
_characterRendererProvider.CharacterRenderers[sourcePlayerID].ShoutSpellCast();
}
var spellData = _pubFileProvider.ESFFile[spellId];
if (targetPlayerID == _characterRepository.MainCharacter.ID)
{
_characterRendererProvider.MainCharacterRenderer.MatchSome(cr =>
{
cr.ShowSpellAnimation(spellData.Graphic);
cr.ShowDamageCounter(recoveredHP, targetPercentHealth, isHeal: spellData.Type == EOLib.IO.SpellType.Heal);
});
}
else
{
_characterRendererProvider.CharacterRenderers[targetPlayerID].ShowSpellAnimation(spellData.Graphic);
_characterRendererProvider.CharacterRenderers[targetPlayerID].ShowDamageCounter(recoveredHP, targetPercentHealth, isHeal: spellData.Type == EOLib.IO.SpellType.Heal);
}
}
public void NotifyEarthquake(byte strength)
{
var mapRenderer = _hudControlProvider.GetComponent<IMapRenderer>(HudControlIdentifier.MapRenderer);
mapRenderer.StartEarthquake(strength);
}
public void NotifyEmote(short playerId, Emote emote)
{
Animator.Emote(playerId, emote);
}
public void MakeMainPlayerDrunk()
{
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.STATUS_LABEL_ITEM_USE_DRUNK);
}
private void ShowWaterSplashiesIfNeeded(CharacterActionState action, int characterID)
{
var character = characterID == _characterRepository.MainCharacter.ID
? Option.Some(_characterRepository.MainCharacter)
: _currentMapStateProvider.Characters.ContainsKey(characterID)
? Option.Some(_currentMapStateProvider.Characters[characterID])
: Option.None<ICharacter>();
var characterRenderer = characterID == _characterRepository.MainCharacter.ID
? _characterRendererProvider.MainCharacterRenderer
: _characterRendererProvider.CharacterRenderers.ContainsKey(characterID)
? Option.Some(_characterRendererProvider.CharacterRenderers[characterID])
: Option.None<ICharacterRenderer>();
character.MatchSome(c =>
{
var rp = c.RenderProperties;
characterRenderer.MatchSome(cr =>
{
if (action == CharacterActionState.Attacking)
{
if (_currentMapProvider.CurrentMap.Tiles[rp.MapY, rp.MapX] == TileSpec.Water)
cr.ShowWaterSplashies();
}
else if (action == CharacterActionState.Walking)
{
if (_currentMapProvider.CurrentMap.Tiles[rp.GetDestinationY(), rp.GetDestinationX()] == TileSpec.Water)
cr.ShowWaterSplashies();
}
});
});
}
private void CancelSpellPrep()
{
Animator.MainCharacterCancelSpellPrep();
_characterRendererProvider.MainCharacterRenderer.MatchSome(r => r.StopShout());
}
private void PlayWeaponSound(ICharacter character, int noteIndex = -1)
{
_pubFileProvider.EIFFile.SingleOrNone(x => x.Type == ItemType.Weapon && x.DollGraphic == character.RenderProperties.WeaponGraphic)
.MatchSome(x =>
{
var ndx = Constants.InstrumentIDs.ToList().FindIndex(y => y == x.ID);
if (ndx >= 0 && (noteIndex < 0 || noteIndex >= 36))
return;
switch (ndx)
{
case 0: _sfxPlayer.PlayHarpNote(noteIndex); break;
case 1: _sfxPlayer.PlayGuitarNote(noteIndex); break;
default: break; // todo: melee/bow/gun sounds
}
});
}
private ICharacterAnimator Animator => _hudControlProvider.GetComponent<ICharacterAnimator>(HudControlIdentifier.CharacterAnimator);
}
public interface ICharacterAnimationActions
{
void Face(EODirection direction);
void StartWalking();
void StartAttacking(int noteIndex = -1);
bool PrepareMainCharacterSpell(int spellId, ISpellTargetable spellTarget);
void Emote(Emote whichEmote);
}
}