-
Notifications
You must be signed in to change notification settings - Fork 16
/
OldCharacter.cs
509 lines (442 loc) · 19.6 KB
/
OldCharacter.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
using System;
using System.Collections.Generic;
using System.Linq;
using EndlessClient.Dialogs;
using EndlessClient.Rendering;
using EOLib;
using EOLib.Domain.Character;
using EOLib.IO;
using EOLib.IO.Map;
using EOLib.IO.Pub;
using EOLib.Localization;
using EOLib.Net.API;
using Microsoft.Xna.Framework;
using XNAControls.Old;
namespace EndlessClient.Old
{
/// <summary>
/// This is data used to render the character in CharacterRenderer.cs
/// The values represented here are for loading GFX and do NOT represent IDs of items, etc.
/// </summary>
public class CharRenderData
{
private readonly object frameLocker = new object();
public string name;
public int id;
public byte level, hairstyle, haircolor, race, admin;
/// <summary>
/// 0 == female and 1 == male
/// </summary>
public byte gender;
public short boots, armor, hat, shield, weapon;
public int walkFrame, attackFrame, emoteFrame = -1;
public EODirection facing;
public SitState sitting;
public bool hidden;
public bool update;
public bool hairNeedRefresh;
public bool dead;
public Emote emote;
public CharRenderData() { name = ""; }
public void SetHairColor(byte color) { haircolor = color; update = true; }
public void SetHairStyle(byte style) { hairstyle = style; update = true; }
public void SetRace(byte newrace) { race = newrace; update = true; }
public void SetGender(byte newgender) { gender = newgender; update = true; }
public void SetDirection(EODirection direction) { facing = direction; update = true; }
public void SetSitting(SitState sits) { sitting = sits; update = true; }
public void SetHidden(bool hiding) { hidden = hiding; update = true; }
public void SetShield(short newshield) { shield = newshield; update = true; }
public void SetArmor(short newarmor) { armor = newarmor; update = true; }
public void SetWeapon(short newweap) { weapon = newweap; update = true; }
public void SetHat(short newhat)
{
if (hat != 0 && newhat == 0)
hairNeedRefresh = true;
hat = newhat; update = true;
}
public void SetBoots(short newboots) { boots = newboots; update = true; }
public void SetWalkFrame(int wf) { lock (frameLocker) walkFrame = wf; update = true; }
public void SetAttackFrame(int af) { lock (frameLocker) attackFrame = af; update = true; }
public void SetEmoteFrame(int ef) { lock (frameLocker) emoteFrame = ef; update = true; }
public void SetUpdate(bool shouldUpdate) { update = shouldUpdate; }
public void SetHairNeedRefresh(bool shouldRefresh) { hairNeedRefresh = shouldRefresh; }
public void SetDead(bool isDead) { dead = isDead; update = true; }
public void SetEmote(Emote which) { emote = which; update = true; }
}
/// <summary>
/// This is data used to track the stats of a player as a single, logically cohesive unit
/// </summary>
public class CharStatData
{
public byte Level { get; set; }
public int Experience { get; set; }
public int Usage { get; set; }
public short HP { get; set; }
public short MaxHP { get; set; }
public short TP { get; set; }
public short MaxTP { get; set; }
public short SP { get; set; }
public short MaxSP { get; set; }
public short StatPoints { get; set; }
public short SkillPoints { get; set; }
public short Karma { get; set; }
public short MinDam { get; set; }
public short MaxDam { get; set; }
public short Accuracy { get; set; }
public short Evade { get; set; }
public short Armor { get; set; }
public short Str { get; set; }
public short Int { get; set; }
public short Wis { get; set; }
public short Agi { get; set; }
public short Con { get; set; }
public short Cha { get; set; }
}
/// <summary>
/// Note: since a lot of calls are made asynchronously, there could be issues with
/// <para>data races to the properties that are here. However, since it is updating</para>
/// <para>and redrawing so fast, I don't think it will matter all that much.</para>
/// </summary>
public class OldCharacter
{
public int ID { get; }
/// <summary>
/// x*32 - y*32 + ViewAdjustX
/// </summary>
public int OffsetX => X*32 - Y*32 + ViewAdjustX;
/// <summary>
/// x*16 + y*16 + ViewAdjustY
/// </summary>
public int OffsetY => X*16 + Y*16 + ViewAdjustY;
public byte DestX { get; private set; }
public byte DestY { get; private set; }
public int ViewAdjustX { get; set; }
public int ViewAdjustY { get; set; }
public bool CanAttack => Weight <= MaxWeight && Stats.SP > 0;
public CharacterActionState State { get; private set; }
//paperdoll info
public string Name { get; set; }
public string Title { get; set; }
public string GuildName { get; set; }
// ReSharper disable UnusedAutoPropertyAccessor.Global
public string GuildRankStr { get; set; }
public byte Class { get; set; }
public string PaddedGuildTag { get; set; }
// ReSharper restore UnusedAutoPropertyAccessor.Global
public AdminLevel AdminLevel { get; set; }
public byte Weight { get; set; }
public byte MaxWeight { get; set; }
public short[] PaperDoll { get; }
public List<InventoryItem> Inventory { get; }
public List<InventorySpell> Spells { get; private set; }
public CharStatData Stats { get; set; }
public CharRenderData RenderData { get; }
public short CurrentMap { get; set; }
public int X { get; }
public int Y { get; }
public int SelectedSpell { get; private set; }
public bool PreparingSpell { get; private set; }
public bool NeedsSpellTarget
{
get
{
var target = OldWorld.Instance.ESF[SelectedSpell].Target;
return SelectedSpell > 0 &&
target == EOLib.IO.SpellTarget.Normal &&
SpellTarget == null;
}
}
public DrawableGameComponent SpellTarget { get; private set; }
public byte GuildRankNum { private get; set; }
public int TodayExp { get; private set; }
public int TodayBestKill { get; private set; }
public int TodayLastKill { get; private set; }
public bool IsDrunk { get; set; }
private readonly PacketAPI m_packetAPI;
public OldCharacter()
{
//mock all members with non-null fields
//PacketAPI cannot be mocked...
Inventory = new List<InventoryItem>();
Spells = new List<InventorySpell>();
PaperDoll = new short[(int)EquipLocation.PAPERDOLL_MAX];
Stats = new CharStatData();
RenderData = new CharRenderData();
Name = PaddedGuildTag = GuildName = GuildRankStr = "";
}
public OldCharacter(PacketAPI api, int id, CharRenderData data)
{
m_packetAPI = api;
ID = id;
RenderData = data ?? new CharRenderData();
Inventory = new List<InventoryItem>();
Spells = new List<InventorySpell>();
PaperDoll = new short[(int)EquipLocation.PAPERDOLL_MAX];
}
//constructs a character from a packet sent from the server
public OldCharacter(PacketAPI api, CharacterData data)
{
//initialize lists
m_packetAPI = api;
Inventory = new List<InventoryItem>();
Spells = new List<InventorySpell>();
PaperDoll = new short[(int)EquipLocation.PAPERDOLL_MAX];
Name = data.Name;
ID = data.ID;
CurrentMap = data.Map;
X = data.X;
Y = data.Y;
PaddedGuildTag = data.GuildTag;
RenderData = new CharRenderData
{
facing = data.Direction,
level = data.Level,
gender = data.Gender,
hairstyle = data.HairStyle,
haircolor = data.HairColor,
race = data.Race
};
Stats = new CharStatData
{
MaxHP = data.MaxHP,
HP = data.HP,
MaxTP = data.MaxTP,
TP = data.TP
};
EquipItem(ItemType.Boots, 0, data.Boots, true);
EquipItem(ItemType.Armor, 0, data.Armor, true);
EquipItem(ItemType.Hat, 0, data.Hat, true);
EquipItem(ItemType.Shield, 0, data.Shield, true);
EquipItem(ItemType.Weapon, 0, data.Weapon, true);
RenderData.SetSitting(data.Sitting);
RenderData.SetHidden(data.Hidden);
}
public void UnequipItem(ItemType type, byte subLoc)
{
EquipItem(type, 0, 0, true, (sbyte)subLoc);
}
public bool EquipItem(ItemType type, short id = 0, short graphic = 0, bool rewrite = false, sbyte subloc = -1)
{
switch (type)
{
case ItemType.Weapon:
if (PaperDoll[(int)EquipLocation.Weapon] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Weapon] = id;
RenderData.SetWeapon(graphic);
break;
case ItemType.Shield:
if (PaperDoll[(int)EquipLocation.Shield] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Shield] = id;
RenderData.SetShield(graphic);
break;
case ItemType.Armor:
if (PaperDoll[(int)EquipLocation.Armor] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Armor] = id;
RenderData.SetArmor(graphic);
break;
case ItemType.Hat:
if (PaperDoll[(int)EquipLocation.Hat] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Hat] = id;
RenderData.SetHat(graphic);
break;
case ItemType.Boots:
if (PaperDoll[(int)EquipLocation.Boots] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Boots] = id;
RenderData.SetBoots(graphic);
break;
case ItemType.Gloves:
if (PaperDoll[(int)EquipLocation.Gloves] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Gloves] = id;
break;
case ItemType.Accessory:
if (PaperDoll[(int)EquipLocation.Accessory] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Accessory] = id;
break;
case ItemType.Belt:
if (PaperDoll[(int)EquipLocation.Belt] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Belt] = id;
break;
case ItemType.Necklace:
if (PaperDoll[(int) EquipLocation.Necklace] != 0 && !rewrite) return false;
PaperDoll[(int) EquipLocation.Necklace] = id;
break;
case ItemType.Ring:
if (subloc != -1)
{
//subloc was explicitly specified
if (!rewrite && PaperDoll[(int) EquipLocation.Ring1 + subloc] != 0)
return false;
PaperDoll[(int) EquipLocation.Ring1 + subloc] = id;
}
else
{
if (PaperDoll[(int) EquipLocation.Ring1] != 0 && PaperDoll[(int) EquipLocation.Ring2] != 0 && !rewrite)
return false;
if (PaperDoll[(int) EquipLocation.Ring1] != 0 && PaperDoll[(int) EquipLocation.Ring2] == 0)
PaperDoll[(int) EquipLocation.Ring2] = id;
else
PaperDoll[(int) EquipLocation.Ring1] = id;
}
break;
case ItemType.Armlet:
if (subloc != -1)
{
//subloc was explicitly specified
if (!rewrite && PaperDoll[(int) EquipLocation.Armlet1 + subloc] != 0)
return false;
PaperDoll[(int) EquipLocation.Armlet1 + subloc] = id;
}
else
{
if (PaperDoll[(int) EquipLocation.Armlet1] != 0 && PaperDoll[(int) EquipLocation.Armlet2] != 0 && !rewrite)
return false;
if (PaperDoll[(int) EquipLocation.Armlet1] != 0 && PaperDoll[(int) EquipLocation.Armlet2] == 0)
PaperDoll[(int) EquipLocation.Armlet2] = id;
else
PaperDoll[(int) EquipLocation.Armlet1] = id;
}
break;
case ItemType.Bracer:
if (subloc != -1)
{
//subloc was explicitly specified
if (!rewrite && PaperDoll[(int) EquipLocation.Bracer1 + subloc] != 0)
return false;
PaperDoll[(int) EquipLocation.Bracer1 + subloc] = id;
}
else
{
if (PaperDoll[(int) EquipLocation.Bracer1] != 0 && PaperDoll[(int) EquipLocation.Bracer2] != 0 && !rewrite)
return false;
if (PaperDoll[(int) EquipLocation.Bracer1] != 0 && PaperDoll[(int) EquipLocation.Bracer2] == 0)
PaperDoll[(int) EquipLocation.Bracer2] = id;
else
PaperDoll[(int) EquipLocation.Bracer1] = id;
}
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), "Invalid item type for equip!");
}
return true;
}
public void DoneAttacking()
{
State = CharacterActionState.Standing;
RenderData.SetAttackFrame(0);
}
public void Emote(Emote whichEmote)
{
if (this == OldWorld.Instance.MainPlayer.ActiveCharacter &&
whichEmote != EOLib.Domain.Character.Emote.LevelUp &&
whichEmote != EOLib.Domain.Character.Emote.Trade)
{
if (m_packetAPI.ReportEmote(whichEmote))
RenderData.SetEmote(whichEmote);
else
EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
}
RenderData.SetEmoteFrame(0);
RenderData.SetEmote(whichEmote);
}
public void DoneEmote()
{
RenderData.SetEmoteFrame(-1);
}
public ChestKey CanOpenChest(ChestSpawnMapEntity chest)
{
ChestKey permission = chest.Key;
EIFRecord rec;
switch (permission) //note - it would be nice to be able to send the Item IDs of the keys in the welcome packet or something
{
case ChestKey.Normal:
rec = OldWorld.Instance.EIF.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "normal key");
break;
case ChestKey.Crystal:
rec = OldWorld.Instance.EIF.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "crystal key");
break;
case ChestKey.Silver:
rec = OldWorld.Instance.EIF.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "silver key");
break;
case ChestKey.Wraith:
rec = OldWorld.Instance.EIF.Single(_rec => _rec.Name != null && _rec.Name.ToLower() == "wraith key");
break;
default:
return permission;
}
if (rec != null && Inventory.FindIndex(_ii => _ii.ItemID == rec.ID) >= 0)
permission = ChestKey.None;
else if (rec == null) //show a warning saying that this chest is perma-locked. Non-standard pub files will cause this.
EOMessageBox.Show(
$"Unable to find key for {Enum.GetName(typeof(ChestKey), permission)} in EIF. This chest will never be opened!", "Warning", EODialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);
return permission;
}
public void SelectSpell(int id)
{
//right now this is just a setter for SelectedSpell
if (SelectedSpell != id)
{
SelectedSpell = id;
}
}
public void PrepareSpell(int id)
{
//if (SelectedSpell <= 0)
// return;
//if (!m_packetAPI.PrepareCastSpell((short) id))
// EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
//PreparingSpell = true;
}
public void CastSpell(int id)
{
//if (SelectedSpell <= 0)
// return;
//var data = OldWorld.Instance.ESF[id];
//bool result = false;
//switch (data.Target)
//{
// case EOLib.IO.SpellTarget.Normal:
// var targetAsNPC = SpellTarget as OldNPCRenderer;
// var targetAsChar = SpellTarget as OldCharacterRenderer;
// if (targetAsNPC != null)
// result = m_packetAPI.DoCastTargetSpell((short) id, true, targetAsNPC.NPC.Index);
// else if (targetAsChar != null)
// result = m_packetAPI.DoCastTargetSpell((short) id, false, (short) targetAsChar.Character.ID);
// break;
// case EOLib.IO.SpellTarget.Self:
// result = m_packetAPI.DoCastSelfSpell((short) id);
// break;
// case EOLib.IO.SpellTarget.Unknown1:
// throw new Exception("What even is this");
// case EOLib.IO.SpellTarget.Group:
// result = m_packetAPI.DoCastGroupSpell((short) id);
// break;
// default:
// throw new ArgumentOutOfRangeException();
//}
//SetSpellCastStart();
//if (!result)
// EOGame.Instance.DoShowLostConnectionDialogAndReturnToMainMenu();
}
public void SetSpellTarget(DrawableGameComponent target)
{
if (target != null && !(target is OldNPCRenderer || target is OldCharacterRenderer)) //don't set target when it isn't valid!
return;
SpellTarget = target;
}
public void CancelSpellPrepare()
{
PreparingSpell = false;
}
public void SetSpellCastStart()
{
//PreparingSpell = false;
//State = CharacterActionState.SpellCast;
//RenderData.SetUpdate(true);
}
public void SetSpellCastComplete()
{
State = CharacterActionState.Standing;
RenderData.SetUpdate(true);
}
}
}