-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathCharacterComponent.h
More file actions
638 lines (511 loc) · 15.9 KB
/
CharacterComponent.h
File metadata and controls
638 lines (511 loc) · 15.9 KB
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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
#ifndef CHARACTERCOMPONENT_H
#define CHARACTERCOMPONENT_H
#include "dCommonVars.h"
#include "RakNetTypes.h"
#include "Character.h"
#include "Component.h"
#include <string>
#include "CDMissionsTable.h"
#include "tinyxml2.h"
#include "eReplicaComponentType.h"
#include <array>
#include <set>
#include "Loot.h"
enum class eGameActivity : uint32_t;
class Item;
namespace GameMessages {
struct GetObjectReportInfo;
}
/**
* The statistics that can be achieved per zone
*/
struct ZoneStatistics {
uint64_t m_AchievementsCollected;
int64_t m_BricksCollected;
uint64_t m_CoinsCollected;
uint64_t m_EnemiesSmashed;
uint64_t m_QuickBuildsCompleted;
bool operator==(const ZoneStatistics& rhs) const = default;
};
/**
* The IDs of each of the possible statistics
*/
enum StatisticID {
CurrencyCollected = 1,
BricksCollected,
SmashablesSmashed,
QuickBuildsCompleted,
EnemiesSmashed,
RocketsUsed,
MissionsCompleted,
PetsTamed,
ImaginationPowerUpsCollected,
LifePowerUpsCollected,
ArmorPowerUpsCollected,
MetersTraveled,
TimesSmashed,
TotalDamageTaken,
TotalDamageHealed,
TotalArmorRepaired,
TotalImaginationRestored,
TotalImaginationUsed,
DistanceDriven,
TimeAirborneInCar,
RacingImaginationPowerUpsCollected,
RacingImaginationCratesSmashed,
RacingCarBoostsActivated,
RacingTimesWrecked,
RacingSmashablesSmashed,
RacesFinished,
FirstPlaceRaceFinishes,
};
/**
* Represents a character, including their rockets and stats
*/
class CharacterComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::CHARACTER;
CharacterComponent(Entity* parent, const int32_t componentID, Character* character, const SystemAddress& systemAddress);
~CharacterComponent() override;
void LoadFromXml(const tinyxml2::XMLDocument& doc) override;
void UpdateXml(tinyxml2::XMLDocument& doc) override;
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
/**
* Updates the rocket configuration using a LOT string separated by commas
* @param config the rocket config to use
*/
void SetLastRocketConfig(std::u16string config);
/**
* Find a player's rocket
* @param player the entity that triggered the event
* @return rocket
*/
Item* GetRocket(Entity* player);
/**
* Equip a player's rocket
* @param player the entity that triggered the event
* @return rocket
*/
Item* RocketEquip(Entity* player);
/**
* Find a player's rocket and unequip it
* @param player the entity that triggered the event
*/
void RocketUnEquip(Entity* player);
/**
* Gets the universe score of the entity
* @return the universe score of the entity
*/
const int64_t GetUScore() const { return m_Uscore; }
/**
* Sets the universe score for this entity
* @param uscore the universe score to set
*/
void SetUScore(int64_t uscore) { m_Uscore = uscore; }
/**
* Gets the current activity that the character is partaking in, see ScriptedActivityComponent for more details
* @return the current activity that the character is partaking in
*/
const eGameActivity GetCurrentActivity() const { return m_CurrentActivity; }
/**
* Set the current activity of the character, see ScriptedActivityComponent for more details
* @param currentActivity the activity to set
*/
void SetCurrentActivity(eGameActivity currentActivity) { m_CurrentActivity = currentActivity; m_DirtyCurrentActivity = true; }
/**
* Gets if the entity is currently racing
* @return whether the entity is currently racing
*/
const bool GetIsRacing() const { return m_IsRacing; }
/**
* Sets the state of whether the character is racing
* @param isRacing whether the character is racing
*/
void SetIsRacing(bool isRacing) { m_IsRacing = isRacing; }
/**
* Gets whether this character has PvP enabled, allowing combat between players
* @return
*/
bool GetPvpEnabled() const;
/**
* Returns the characters lifetime reputation
* @return The lifetime reputation of this character.
*/
int64_t GetReputation() { return m_Reputation; };
/**
* Sets the lifetime reputation of the character to newValue
* @param newValue the value to set reputation to
*/
void SetReputation(int64_t newValue) { m_Reputation = newValue; };
/**
* Sets the current value of PvP combat being enabled
* @param value whether to enable PvP combat
*/
void SetPvpEnabled(bool value);
/**
* Gets the object ID of the rocket that was last used, allowing it to be rendered on launch pads
* @return the object ID of the rocket that was last used, if available
*/
LWOOBJID GetLastRocketItemID() const { return m_LastRocketItemID; }
/**
* Sets the object ID of the last used rocket
* @param lastRocketItemID the object ID of the last used rocket
*/
void SetLastRocketItemID(LWOOBJID lastRocketItemID) { m_LastRocketItemID = lastRocketItemID; }
/**
* Gets the name of this character
* @return the name of this character
*/
std::string GetName() const { return m_Character->GetName(); }
/**
* Sets the GM level of the character, should be called in the entity. Here it's set for serialization
* @param gmlevel the gm level to set
*/
void SetGMLevel(eGameMasterLevel gmlevel);
/**
* Initializes the player statistics from the string stored in the XML
* @param statisticsString the string to parse
*/
void InitializeStatisticsFromString(const std::string& statisticsString);
/**
* Initializes all the statistics with empty stats when there's no stats available up until that point
*/
void InitializeEmptyStatistics();
/**
* Turns character statistics into a stats string
* @return the statistics of the character as a string, in order, split by semicolon (;)
*/
std::string StatisticsToString() const;
/**
* Updates the statistics for when a user completes a mission
* @param mission the mission info to track
*/
void TrackMissionCompletion(bool isAchievement);
/**
* Handles statistics related to collecting heart flags and imagination bricks
* @param lot the lot of the object that was collected
*/
void TrackLOTCollection(LOT lot);
/**
* Handles a change in health and updates the statistics
* @param health the health delta
*/
void TrackHealthDelta(int32_t health);
/**
* Handles a change in imagination and updates the statistics
* @param imagination the imagination delta
*/
void TrackImaginationDelta(int32_t imagination);
/**
* Handles a change in armor and updates the statistics
* @param armor the armor delta
*/
void TrackArmorDelta(int32_t armor);
/**
* Handles completing a rebuild by updating the statistics
*/
void TrackQuickBuildComplete();
/**
* Tracks a player completing the race, also updates stats
* @param won whether the player won the race
*/
void TrackRaceCompleted(bool won);
/**
* Tracks an updated position for a player
*/
void TrackPositionUpdate(const NiPoint3& newPosition);
/**
* Handles a zone statistic update
* @param zoneID the zone that the stat belongs to
* @param name the name of the stat
* @param value the delta update for the stat
*/
void HandleZoneStatisticsUpdate(LWOMAPID zoneID, const std::u16string& name, int32_t value);
/**
* Allows one to generically update a statistic
* @param updateID the 1-indexed ID of the statistic in the order of definition below
* @param updateValue the value to update the statistic with
*/
void UpdatePlayerStatistic(StatisticID updateID, uint64_t updateValue = 1);
/**
* Add a venture vision effect to the player minimap.
*/
void AddVentureVisionEffect(std::string ventureVisionType);
/**
* Remove a venture vision effect from the player minimap.
* When an effect hits 0 active effects, it is deactivated.
*/
void RemoveVentureVisionEffect(std::string ventureVisionType);
/**
* Update the client minimap to reveal the specified factions
*/
void UpdateClientMinimap(bool showFaction, std::string ventureVisionType) const;
void SetCurrentInteracting(LWOOBJID objectID) { m_CurrentInteracting = objectID; };
LWOOBJID GetCurrentInteracting() { return m_CurrentInteracting; };
/**
* Sends a player to another zone with an optional clone ID
*
* @param zoneId zoneID for the new instance.
* @param cloneId cloneID for the new instance.
*/
void SendToZone(LWOMAPID zoneId, LWOCLONEID cloneId = 0) const;
const SystemAddress& GetSystemAddress() const;
const NiPoint3& GetRespawnPosition() const { return m_respawnPos; };
void SetRespawnPos(const NiPoint3& position);
const NiQuaternion& GetRespawnRotation() const { return m_respawnRot; };
void SetRespawnRot(const NiQuaternion& rotation);
std::map<LWOOBJID, Loot::Info>& GetDroppedLoot() { return m_DroppedLoot; };
uint64_t GetDroppedCoins() const { return m_DroppedCoins; };
void SetDroppedCoins(const uint64_t value) { m_DroppedCoins = value; };
const std::array<uint64_t, 4>& GetClaimCodes() const { return m_ClaimCodes; };
const std::map<LWOMAPID, ZoneStatistics>& GetZoneStatistics() const { return m_ZoneStatistics; };
const std::u16string& GetLastRocketConfig() const { return m_LastRocketConfig; };
uint64_t GetTotalTimePlayed() const { return m_TotalTimePlayed; };
/**
* Character info regarding this character, including clothing styles, etc.
*/
Character* m_Character;
/* Saves the provided zoneID as a visited level. Ignores InstanceID */
void AddVisitedLevel(const LWOZONEID zoneID);
/* Updates the VisitedLevels (vl) node of the charxml */
void UpdateVisitedLevelsXml(tinyxml2::XMLElement& doc);
/* Reads the VisitedLevels (vl) node of the charxml */
void LoadVisitedLevelsXml(const tinyxml2::XMLElement& doc);
private:
bool OnGetObjectReportInfo(GameMessages::GetObjectReportInfo& reportInfo);
/**
* The map of active venture vision effects
*/
std::map<std::string, uint32_t> m_ActiveVentureVisionEffects;
/**
* Whether this character is racing
*/
bool m_IsRacing;
/**
* Possessible type, used by the shooting gallery
*/
uint8_t m_PossessableType = 1;
/**
* Universe score of the entity
*/
int64_t m_Uscore;
/**
* The lifetime reputation earned by the entity
*/
int64_t m_Reputation;
/**
* Whether the character is landing by rocket
*/
bool m_IsLanding;
/**
* The configuration of the last used rocket, essentially a string of LOTs separated by commas
*/
std::u16string m_LastRocketConfig;
/**
* Whether the GM info has been changed
*/
bool m_DirtyGMInfo = false;
/**
* Whether PvP is enabled for this entity
*/
bool m_PvpEnabled;
/**
* Whether this entity is a GM
*/
bool m_IsGM;
/**
* The current GM level of this character (anything > 0 counts as a GM)
*/
eGameMasterLevel m_GMLevel;
/**
* Whether the character has HF enabled
*/
bool m_EditorEnabled;
/**
* The level of the character in HF
*/
eGameMasterLevel m_EditorLevel;
/**
* Whether the currently active activity has been changed
*/
bool m_DirtyCurrentActivity = false;
/**
* The ID of the curently active activity
*/
eGameActivity m_CurrentActivity;
/**
* Whether the social info has been changed
*/
bool m_DirtySocialInfo = false;
/**
* The guild this character is in
*/
LWOOBJID m_GuildID;
/**
* The name of the guild this character is in
*/
std::u16string m_GuildName;
/**
* Whether this character is a lego club member
*/
bool m_IsLEGOClubMember;
/**
* The country code that the character is from
*/
int m_CountryCode;
/**
* Returns whether the landing animation is enabled for a certain zone
* @param zoneID the zone to check for
* @return whether the landing animation is enabled for that zone
*/
bool LandingAnimDisabled(int zoneID);
/**
* Returns the statistics for a certain statistics ID, from a statistics string
* @param split the statistics string to look in
* @param index the statistics ID in the string
* @return the integer value of this statistic, parsed from the string
*/
static uint64_t GetStatisticFromSplit(std::vector<std::string> split, uint32_t index);
/**
* Gets all the statistics for a certain map, if it doesn't exist, it creates empty stats
* @param mapID the ID of the zone to get statistics for
* @return the statistics for the zone
*/
ZoneStatistics& GetZoneStatisticsForMap(const LWOMAPID mapID);
/**
* The last time we saved this character, used to update the total time played
*/
time_t m_LastUpdateTimestamp;
/**
* The total time the character has played, in MS
*/
uint64_t m_TotalTimePlayed;
/**
* The total amount of currency collected by this character
*/
uint64_t m_CurrencyCollected;
/**
* The total amount of bricks collected by this character
*/
int64_t m_BricksCollected;
/**
* The total amount of entities smashed by this character
*/
uint64_t m_SmashablesSmashed;
/**
* The total amount of quickbuilds completed by this character
*/
uint64_t m_QuickBuildsCompleted;
/**
* The total amount of enemies killd by this character
*/
uint64_t m_EnemiesSmashed;
/**
* The total amount of rockets used by this character
*/
uint64_t m_RocketsUsed;
/**
* The total amount of missions completed by this character
*/
uint64_t m_MissionsCompleted;
/**
* The total number of pets tamed by this character
*/
uint64_t m_PetsTamed;
/**
* The total amount of imagination powerups collected by this character, this includes the ones in racing
*/
uint64_t m_ImaginationPowerUpsCollected;
/**
* The total amount of life powerups collected (note: not the total amount of life gained)
*/
uint64_t m_LifePowerUpsCollected;
/**
* The total amount of armor powerups collected (note: not the total amount of armor gained)
*/
uint64_t m_ArmorPowerUpsCollected;
/**
* Total amount of meters traveled by this character
*/
uint64_t m_MetersTraveled;
/**
* Total amount of times this character was smashed, either by other entities or by going out of bounds
*/
uint64_t m_TimesSmashed;
/**
* The total amount of damage inflicted on this character
*/
uint64_t m_TotalDamageTaken;
/**
* The total amount of damage healed by this character (excludes armor polish, etc)
*/
uint64_t m_TotalDamageHealed;
/**
* Total amount of armor repaired by this character
*/
uint64_t m_TotalArmorRepaired;
/**
* Total amount of imagination resored by this character
*/
uint64_t m_TotalImaginationRestored;
/**
* Total amount of imagination used by this character
*/
uint64_t m_TotalImaginationUsed;
/**
* Amount of distance driven, mutually exclusively tracked to meters travelled based on whether the charcter
* is currently driving
*/
uint64_t m_DistanceDriven;
/**
* Time airborne in a car, currently untracked.
* Honestly, who even cares about this.
*/
uint64_t m_TimeAirborneInCar;
/**
* Amount of imagination powerups found on racing tracks being collected, generally triggered by scripts
*/
uint64_t m_RacingImaginationPowerUpsCollected;
/**
* Total amount of racing imagination crates smashed, generally tracked by scripts
*/
uint64_t m_RacingImaginationCratesSmashed;
/**
* The amount of times this character triggered a car boost
*/
uint64_t m_RacingCarBoostsActivated;
/**
* The amount of times a car of this character was wrecked
*/
uint64_t m_RacingTimesWrecked;
/**
* The amount of entities smashed by the character while driving
*/
uint64_t m_RacingSmashablesSmashed;
/**
* The total amount of races completed by this character
*/
uint64_t m_RacesFinished;
/**
* The total amount of races won by this character
*/
uint64_t m_FirstPlaceRaceFinishes;
/**
* Special stats which are tracked per zone
*/
std::map<LWOMAPID, ZoneStatistics> m_ZoneStatistics{};
/**
* ID of the last rocket used
*/
LWOOBJID m_LastRocketItemID = LWOOBJID_EMPTY;
LWOOBJID m_CurrentInteracting = LWOOBJID_EMPTY;
std::array<uint64_t, 4> m_ClaimCodes{};
void AwardClaimCodes();
SystemAddress m_SystemAddress;
NiPoint3 m_respawnPos;
NiQuaternion m_respawnRot = QuatUtils::IDENTITY;
std::map<LWOOBJID, Loot::Info> m_DroppedLoot;
uint64_t m_DroppedCoins = 0;
std::set<LWOZONEID> m_VisitedLevels;
};
#endif // CHARACTERCOMPONENT_H