-
Notifications
You must be signed in to change notification settings - Fork 16
/
EffectSpriteManager.cs
285 lines (269 loc) · 12.3 KB
/
EffectSpriteManager.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
using System;
using System.Collections.Generic;
using System.Linq;
using EOLib.Graphics;
using Microsoft.Xna.Framework.Graphics;
namespace EndlessClient.Rendering.Effects
{
//todo: it would be cool to load this from a config file instead of having it hard-coded
public partial class EffectSpriteManager
{
private enum HardCodedSpellGraphic
{
FIRE = 1,
HEAL = 10,
THUNDER = 11,
ULTIMA_BLAST = 13,
FIRE_BALL = 14,
SHIELD = 15,
RING_OF_FIRE = 16,
ICE_BLAST_1 = 17,
ENERGY_BALL = 18,
WHIRL = 19,
AURA = 20,
BOULDER = 21,
HEAVEN = 22,
ICE_BLAST_2 = 23,
DARK_BEAM = 24,
DARK_HAND = 26,
DARK_SKULL = 27,
FIRE_BLAST = 28,
TENTACLES = 29,
POWER_WIND = 30,
MAGIC_WHIRL = 31,
DARK_BITE = 32,
SHELL = 33,
GREEN_FLAME = 34
}
private Dictionary<HardCodedPotionEffect, IList<IEffectSpriteInfo>> _potionEffects;
private Dictionary<HardCodedSpellGraphic, IList<IEffectSpriteInfo>> _spellEffects;
private readonly INativeGraphicsManager _graphicsManager;
public EffectSpriteManager(INativeGraphicsManager graphicsManager)
{
_graphicsManager = graphicsManager;
CreatePotionEffectDictionary();
CreateSpellEffectDictionary();
}
public IList<IEffectSpriteInfo> GetEffectInfo(EffectType effectType, int effectID)
{
switch (effectType)
{
case EffectType.Potion: return ResolvePotionEffect((HardCodedPotionEffect)effectID);
case EffectType.Spell: return ResolveSpellEffect((HardCodedSpellGraphic)effectID);
case EffectType.WarpOriginal:
case EffectType.WarpDestination: return GetWarpEffect(effectType);
case EffectType.WaterSplashies: return GetWaterEffect();
default: throw new ArgumentOutOfRangeException(nameof(effectType), effectType, null);
}
}
private IList<IEffectSpriteInfo> ResolvePotionEffect(HardCodedPotionEffect effect)
{
if (_potionEffects.ContainsKey(effect))
{
var retList = _potionEffects[effect];
foreach (var item in retList)
item.Restart();
return new List<IEffectSpriteInfo>(retList);
}
// potion graphics that aren't in the hard-coded list here use the same formula as spell graphics
return ResolveSpellEffect((HardCodedSpellGraphic)effect+1);
}
private IList<IEffectSpriteInfo> ResolveSpellEffect(HardCodedSpellGraphic effect)
{
if (_spellEffects.ContainsKey(effect))
{
var retList = _spellEffects[effect];
foreach (var item in retList)
item.Restart();
return new List<IEffectSpriteInfo>(retList);
}
// not implemented spell graphics have a default rendering set
// spell effects seem to start at GFX 128 and go in sets of 3, indexed on (spellGraphic - 10)
// first gfx is behind character, other 2 are in front
// 255 alpha assumed until proven otherwise
// 4 frames assumed until proven otherwise
return new List<IEffectSpriteInfo>
{
new CustomEffectSpriteInfo(4, 2, false, 255, GetGraphic(((int)effect - 9)*3 + 128)),
new CustomEffectSpriteInfo(4, 2, true, 255, GetGraphic(((int)effect - 9)*3 + 129)),
new CustomEffectSpriteInfo(4, 2, true, 255, GetGraphic(((int)effect - 9)*3 + 130))
};
}
private IList<IEffectSpriteInfo> GetWarpEffect(EffectType warpEffect)
{
int[] gfxIDs;
switch (warpEffect)
{
case EffectType.WarpOriginal: gfxIDs = new[] {108, 109}; break;
case EffectType.WarpDestination: gfxIDs = new[] {112}; break;
default: throw new ArgumentOutOfRangeException(nameof(warpEffect), warpEffect, null);
}
return gfxIDs.Select(id => new EffectSpriteInfo(8, 1, true, 255, GetGraphic(id)))
.OfType<IEffectSpriteInfo>()
.ToList();
}
private IList<IEffectSpriteInfo> GetWaterEffect()
{
return new List<IEffectSpriteInfo>
{
new EffectSpriteInfo(6, 1, false, 255, GetGraphic(125))
};
}
private Texture2D GetGraphic(int actualResourceID)
{
return _graphicsManager.TextureFromResource(GFXTypes.Spells, actualResourceID - 100, true);
}
private void CreatePotionEffectDictionary()
{
_potionEffects = new Dictionary<HardCodedPotionEffect, IList<IEffectSpriteInfo>>(6)
{
{
HardCodedPotionEffect.FLAMES,
CreateList(new EffectSpriteInfo(4, 2, false, 255, GetGraphic(101)),
new EffectSpriteInfo(4, 2, true, 128, GetGraphic(102)),
new EffectSpriteInfo(4, 2, true, 255, GetGraphic(103)))
},
{
HardCodedPotionEffect.LOVE,
CreateList(new EffectSpriteInfo(4, 4, true, 255, GetGraphic(106)))
},
{
HardCodedPotionEffect.CELEBRATE,
CreateList(new EffectSpriteInfo(7, 2, true, 255, GetGraphic(115)))
},
{
HardCodedPotionEffect.SPARKLES,
CreateList(new EffectSpriteInfo(5, 1, true, 128, GetGraphic(117)),
new EffectSpriteInfo(5, 1, true, 128, GetGraphic(118)))
},
{
HardCodedPotionEffect.EVIL,
CreateList(new EffectSpriteInfo(4, 4, false, 255, GetGraphic(119)))
},
{
HardCodedPotionEffect.TERROR,
CreateList(new EffectSpriteInfo(4, 4, false, 255, GetGraphic(122)))
}
};
}
private void CreateSpellEffectDictionary()
{
_spellEffects = new Dictionary<HardCodedSpellGraphic, IList<IEffectSpriteInfo>>(32)
{
{ HardCodedSpellGraphic.FIRE, _potionEffects[HardCodedPotionEffect.FLAMES] },
{ HardCodedSpellGraphic.HEAL,
CreateList(new EffectSpriteInfo(5, 1, false, 128, GetGraphic(129)),
new EffectSpriteInfo(5, 1, true, 255, GetGraphic(130)))
},
{
HardCodedSpellGraphic.THUNDER,
CreateList(new EffectSpriteInfo(4, 1, true, 255, GetGraphic(133)))
},
{
HardCodedSpellGraphic.ULTIMA_BLAST,
CreateList(new EffectSpriteInfo(4, 3, true, 255, GetGraphic(137)),
new EffectSpriteInfo(4, 3, true, 128, GetGraphic(138)))
},
{
HardCodedSpellGraphic.FIRE_BALL,
CreateList(new FallingEffectSpriteInfo(6, 1, false, 255, GetGraphic(140)),
new FallingEffectSpriteInfo(6, 1, true, 128, GetGraphic(141)))
},
{
HardCodedSpellGraphic.SHIELD,
CreateList(new EffectSpriteInfo(6, 1, false, 128, GetGraphic(144)),
new EffectSpriteInfo(6, 1, true, 255, GetGraphic(145)))
},
{
HardCodedSpellGraphic.RING_OF_FIRE,
CreateList(new EffectSpriteInfo(4, 3, false, 255, GetGraphic(146)),
new EffectSpriteInfo(4, 3, true, 128, GetGraphic(148)))
},
{
HardCodedSpellGraphic.ICE_BLAST_1,
CreateList(new EffectSpriteInfo(7, 1 ,false, 128, GetGraphic(150)),
new EffectSpriteInfo(7, 1, true, 255, GetGraphic(151)))
},
{
HardCodedSpellGraphic.ENERGY_BALL,
CreateList(new EnergyBallEffectSpriteInfo(7, 1, true, 255, GetGraphic(154)))
},
{
HardCodedSpellGraphic.WHIRL,
CreateList(new EffectSpriteInfo(4, 2, false, 255, GetGraphic(155)),
new EffectSpriteInfo(4, 2, true, 128, GetGraphic(156)),
new EffectSpriteInfo(4, 2, true, 255, GetGraphic(157)))
},
{
HardCodedSpellGraphic.AURA,
CreateList(new AuraEffectSpriteInfo(GetGraphic(159)))
},
{
HardCodedSpellGraphic.BOULDER,
CreateList(new FallingEffectSpriteInfo(7, 1, true, 255, GetGraphic(163)))
},
//{
// HardCodedSpellGraphic.HEAVEN, //todo: this isn't quite right yet...
// CreateList(new HeavenEffectSpriteInfo(false, 255, GetGraphic(164)),
// new HeavenEffectSpriteInfo(true, 128, GetGraphic(165)))
//},
{
HardCodedSpellGraphic.ICE_BLAST_2,
CreateList(new FallingEffectSpriteInfo(6, 1, false, 255, GetGraphic(167)),
new FallingEffectSpriteInfo(6, 1, true, 255, GetGraphic(168)))
},
//{
// HardCodedSpellGraphic.DARK_BEAM, //todo: figure this out...
//}
{
HardCodedSpellGraphic.DARK_HAND,
CreateList(new EffectSpriteInfo(5, 2, false, 255, GetGraphic(176)),
new EffectSpriteInfo(5, 2, true, 128, GetGraphic(177)))
},
{
HardCodedSpellGraphic.DARK_SKULL,
CreateList(new EffectSpriteInfo(5, 2, false, 255, GetGraphic(179)),
new EffectSpriteInfo(5, 2, true, 128, GetGraphic(180)))
},
{
HardCodedSpellGraphic.FIRE_BLAST,
CreateList(new EffectSpriteInfo(4, 1, true, 192, GetGraphic(184)))
},
{
HardCodedSpellGraphic.TENTACLES,
CreateList(new EffectSpriteInfo(5, 2, false, 255, GetGraphic(185)),
new EffectSpriteInfo(5, 2, true, 255, GetGraphic(187)))
},
{
HardCodedSpellGraphic.POWER_WIND,
CreateList(new EffectSpriteInfo(6, 2, false, 255, GetGraphic(188)),
new EffectSpriteInfo(6, 2, true, 255, GetGraphic(190)))
},
{
HardCodedSpellGraphic.MAGIC_WHIRL,
CreateList(new BottomAlignedEffectSpriteInfo(15, 1, false, 255, GetGraphic(191)),
new BottomAlignedEffectSpriteInfo(15, 1, true, 128, GetGraphic(193)))
},
{
HardCodedSpellGraphic.DARK_BITE,
CreateList(new EffectSpriteInfo(6, 2, false, 255, GetGraphic(194)),
new EffectSpriteInfo(6, 2, true, 128, GetGraphic(195)))
},
{
HardCodedSpellGraphic.SHELL, //todo: why isn't this rendering correctly?
CreateList(new EffectSpriteInfo(4, 4, false, 255, GetGraphic(197)),
new EffectSpriteInfo(4, 4, true, 128, GetGraphic(198)))
},
{
HardCodedSpellGraphic.GREEN_FLAME,
CreateList(new BottomAlignedEffectSpriteInfo(5, 1, false, 255, GetGraphic(200)),
new BottomAlignedEffectSpriteInfo(5, 1, true, 128, GetGraphic(201)))
}
};
}
private IList<IEffectSpriteInfo> CreateList(params IEffectSpriteInfo[] effects)
{
return effects.ToList();
}
}
}