/
corpse.cpp
2439 lines (2107 loc) · 61 KB
/
corpse.cpp
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef _WINDOWS
#if (!defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1900))
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#endif
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#endif
#include "../common/data_verification.h"
#include "../common/global_define.h"
#include "../common/eqemu_logsys.h"
#include "../common/rulesys.h"
#include "../common/strings.h"
#include "../common/say_link.h"
#include "corpse.h"
#include "entity.h"
#include "expedition.h"
#include "groups.h"
#include "mob.h"
#include "raids.h"
#include "bot.h"
#include "quest_parser_collection.h"
#include "string_ids.h"
#include "worldserver.h"
#include "../common/events/player_event_logs.h"
#include "../common/repositories/character_corpses_repository.h"
#include "../common/repositories/character_corpse_items_repository.h"
#include <iostream>
extern EntityList entity_list;
extern Zone *zone;
extern WorldServer worldserver;
extern npcDecayTimes_Struct npcCorpseDecayTimes[100];
void Corpse::SendEndLootErrorPacket(Client *client)
{
auto outapp = new EQApplicationPacket(OP_LootComplete, 0);
client->QueuePacket(outapp);
safe_delete(outapp);
}
void Corpse::SendLootReqErrorPacket(Client *client, LootResponse response)
{
auto outapp = new EQApplicationPacket(OP_MoneyOnCorpse, sizeof(moneyOnCorpseStruct));
auto *d = (moneyOnCorpseStruct *) outapp->pBuffer;
d->response = static_cast<uint8>(response);
d->unknown1 = 0x5a;
d->unknown2 = 0x40;
client->QueuePacket(outapp);
safe_delete(outapp);
}
Corpse::Corpse(
NPC *npc,
LootItems *item_list,
uint32 npc_type_id,
const NPCType **npc_type_data,
uint32 decay_time
) : Mob(
"Unnamed_Corpse", // in_name
"", // in_lastname
0, // in_cur_hp
0, // in_max_hp
npc->GetGender(), // in_gender
npc->GetRace(), // in_race
npc->GetClass(), // in_class
BT_Humanoid, // in_bodytype
npc->GetDeity(), // in_deity
npc->GetLevel(), // in_level
npc->GetNPCTypeID(), // in_npctype_id
npc->GetSize(), // in_size
0.0f, // in_runspeed
npc->GetPosition(), // position
npc->GetInnateLightType(), // in_light
npc->GetTexture(), // in_texture
npc->GetHelmTexture(), // in_helmtexture
0, // in_ac
0, // in_atk
0, // in_str
0, // in_sta
0, // in_dex
0, // in_agi
0, // in_int
0, // in_wis
0, // in_cha
0, // in_haircolor
0, // in_beardcolor
0, // in_eyecolor1
0, // in_eyecolor2
0, // in_hairstyle
0, // in_luclinface
0, // in_beard
0, // in_drakkin_heritage
0, // in_drakkin_tattoo
0, // in_drakkin_details
EQ::TintProfile(), // in_armor_tint
0xFF, // in_aa_title
0, // in_see_invis
0, // in_see_invis_undead
0, // in_see_hide
0, // in_see_improved_hide
0, // in_hp_regen
0, // in_mana_regen
0, // in_qglobal
0, // in_maxlevel
0, // in_scalerate
0, // in_armtexture
0, // in_bracertexture
0, // in_handtexture
0, // in_legtexture
0, // in_feettexture
(*npc_type_data)->use_model, // in_usemodel
false, // in_always_aggros_foes
0, // in_heroic_strikethrough
false // in_keeps_sold_items
),
m_corpse_decay_timer(decay_time),
m_corpse_rezzable_timer(0),
m_corpse_delay_timer(RuleI(NPC, CorpseUnlockTimer)),
m_corpse_graveyard_timer(0),
m_loot_cooldown_timer(10)
{
m_corpse_graveyard_timer.Disable();
m_is_corpse_changed = false;
m_is_player_corpse = false;
m_is_locked = false;
m_being_looted_by_entity_id = 0xFFFFFFFF;
if (item_list) {
m_item_list = *item_list;
item_list->clear();
}
SetCash(npc->GetCopper(), npc->GetSilver(), npc->GetGold(), npc->GetPlatinum());
npctype_id = npc_type_id;
SetPlayerKillItemID(0);
m_character_id = 0;
m_corpse_db_id = 0;
m_player_corpse_depop = false;
strcpy(corpse_name, npc->GetName());
strcpy(name, npc->GetName());
for (auto &npcCorpseDecayTime: npcCorpseDecayTimes) {
if (
EQ::ValueWithin(
level,
npcCorpseDecayTime.minlvl,
npcCorpseDecayTime.maxlvl
)
) {
m_corpse_decay_timer.SetTimer(npcCorpseDecayTime.seconds * 1000);
break;
}
}
if (IsEmpty()) {
m_corpse_decay_timer.SetTimer(RuleI(NPC, EmptyNPCCorpseDecayTime) + 1000);
}
if (npc->HasPrivateCorpse()) {
m_corpse_delay_timer.SetTimer(m_corpse_decay_timer.GetRemainingTime() + 1000);
}
for (int &allowed_looter: m_allowed_looters) {
allowed_looter = 0;
}
m_rezzed_experience = 0;
UpdateEquipmentLight();
UpdateActiveLight();
m_loot_request_type = LootRequestType::Forbidden;
}
Corpse::Corpse(Client *c, int32 rez_exp, KilledByTypes in_killed_by) : Mob(
"Unnamed_Corpse", // in_name
"", // in_lastname
0, // in_cur_hp
0, // in_max_hp
c->GetGender(), // in_gender
c->GetRace(), // in_race
c->GetClass(), // in_class
BT_Humanoid, // in_bodytype
c->GetDeity(), // in_deity
c->GetLevel(), // in_level
0, // in_npctype_id
c->GetSize(), // in_size
0, // in_runspeed
c->GetPosition(), // position
c->GetInnateLightType(), // in_light
c->GetTexture(), // in_texture
c->GetHelmTexture(), // in_helmtexture
0, // in_ac
0, // in_atk
0, // in_str
0, // in_sta
0, // in_dex
0, // in_agi
0, // in_int
0, // in_wis
0, // in_cha
c->GetPP().haircolor, // in_haircolor
c->GetPP().beardcolor, // in_beardcolor
c->GetPP().eyecolor1, // in_eyecolor1
c->GetPP().eyecolor2, // in_eyecolor2
c->GetPP().hairstyle, // in_hairstyle
c->GetPP().face, // in_luclinface
c->GetPP().beard, // in_beard
c->GetPP().drakkin_heritage, // in_drakkin_heritage
c->GetPP().drakkin_tattoo, // in_drakkin_tattoo
c->GetPP().drakkin_details, // in_drakkin_details
EQ::TintProfile(), // in_armor_tint
0xff, // in_aa_title
0, // in_see_invis
0, // in_see_invis_undead
0, // in_see_hide
0, // in_see_improved_hide
0, // in_hp_regen
0, // in_mana_regen
0, // in_qglobal
0, // in_maxlevel
0, // in_scalerate
0, // in_armtexture
0, // in_bracertexture
0, // in_handtexture
0, // in_legtexture
0, // in_feettexture
0, // in_usemodel
false, // in_always_aggro
0, // in_heroic_strikethrough
false // in_keeps_sold_items
)
{
PlayerProfile_Struct *pp = &c->GetPP();
EQ::ItemInstance *item = nullptr;
if (!zone->HasGraveyard()) {
m_corpse_graveyard_timer.Disable();
}
for (int &allowed_looter: m_allowed_looters) {
allowed_looter = 0;
}
if (c->AutoConsentGroupEnabled()) {
auto *g = c->GetGroup();
m_consented_group_id = g ? g->GetID() : 0;
}
if (c->AutoConsentRaidEnabled()) {
auto *r = c->GetRaid();
m_consented_raid_id = r ? r->GetID() : 0;
}
m_consented_guild_id = c->AutoConsentGuildEnabled() ? c->GuildID() : 0;
m_is_corpse_changed = true;
m_rezzed_experience = rez_exp;
m_is_player_corpse = true;
m_is_locked = false;
m_being_looted_by_entity_id = 0xFFFFFFFF;
m_character_id = c->CharacterID();
m_corpse_db_id = 0;
m_player_corpse_depop = false;
m_copper = 0;
m_silver = 0;
m_gold = 0;
m_platinum = 0;
m_killed_by_type = (uint8) in_killed_by;
m_is_rezzable = true;
m_remaining_rez_time = 0;
m_is_owner_online = false;
m_account_id = c->AccountID();
// timers
m_corpse_decay_timer.SetTimer(RuleI(Character, CorpseDecayTime));
m_corpse_rezzable_timer.SetTimer(RuleI(Character, CorpseResTime));
m_corpse_delay_timer.SetTimer(RuleI(NPC, CorpseUnlockTimer));
m_corpse_graveyard_timer.SetTimer(RuleI(Zone, GraveyardTimeMS));
m_loot_cooldown_timer.SetTimer(10);
m_check_rezzable_timer.SetTimer(1000);
m_check_owner_online_timer.SetTimer(RuleI(Character, CorpseOwnerOnlineTime));
m_corpse_rezzable_timer.Disable();
SetRezTimer(true);
strcpy(corpse_name, pp->name);
strcpy(name, pp->name);
/* become_npc was not being initialized which led to some pretty funky things with newly created corpses */
m_become_npc = false;
SetPlayerKillItemID(0);
/* Check Rule to see if we can leave corpses */
if (
(!RuleB(Character, LeaveNakedCorpses) || RuleB(Character, LeaveCorpses)) &&
GetLevel() >= RuleI(Character, DeathItemLossLevel)
) {
// cash
// Let's not move the cash when 'RespawnFromHover = true' && 'client->GetClientVersion() < EQClientSoF' since the client doesn't.
// (change to first client that supports 'death hover' mode, if not SoF.)
if (!RuleB(Character, RespawnFromHover) || c->ClientVersion() < EQ::versions::ClientVersion::SoF) {
auto corpse_copper = pp->copper;
auto corpse_silver = pp->silver;
auto corpse_gold = pp->gold;
auto corpse_platinum = pp->platinum;
pp->copper = 0;
pp->silver = 0;
pp->gold = 0;
pp->platinum = 0;
if (RuleB(Character, LeaveCursorMoneyOnCorpse)) {
corpse_copper += pp->copper_cursor;
corpse_silver += pp->silver_cursor;
corpse_gold += pp->gold_cursor;
corpse_platinum += pp->platinum_cursor;
pp->copper_cursor = 0;
pp->silver_cursor = 0;
pp->gold_cursor = 0;
pp->platinum_cursor = 0;
}
SetCash(corpse_copper, corpse_silver, corpse_gold, corpse_platinum);
}
// get their tints
memcpy(&m_item_tint.Slot, &c->GetPP().item_tint, sizeof(m_item_tint));
// TODO soulbound items need not be added to corpse, but they need
// to go into the regular slots on the player, out of bags
std::list<uint32> removed_list;
// ideally, we would start at invslot::slotGeneral1 and progress to invslot::slotCursor..
// ..then regress and process invslot::EQUIPMENT_BEGIN through invslot::EQUIPMENT_END...
// without additional work to database loading of player corpses, this order is not
// currently preserved and a re-work of this processing loop is not warranted.
for (int i = EQ::invslot::POSSESSIONS_BEGIN; i <= EQ::invslot::POSSESSIONS_END; ++i) {
item = c->GetInv().GetItem(i);
if (!item) {
continue;
}
if (!c->IsBecomeNPC() || (c->IsBecomeNPC() && !item->GetItem()->NoRent)) {
MoveItemToCorpse(c, item, i, removed_list);
}
}
database.TransactionBegin();
// this should not be modified to include the entire range of invtype::TYPE_POSSESSIONS slots by default..
// ..due to the possibility of 'hidden' items from client version bias..or, possibly, soul-bound items (WoW?)
if (!removed_list.empty()) {
auto iter = removed_list.begin();
if (iter != removed_list.end()) {
std::stringstream ss("");
ss << "DELETE FROM `inventory` WHERE `charid` = " << c->CharacterID();
ss << " AND `slotid` IN (" << (*iter);
++iter;
while (iter != removed_list.end()) {
ss << ", " << (*iter);
++iter;
}
ss << ")";
database.QueryDatabase(ss.str().c_str());
}
}
auto start = c->GetInv().cursor_cbegin();
auto finish = c->GetInv().cursor_cend();
database.SaveCursor(c->CharacterID(), start, finish);
c->CalcBonuses();
c->Save();
IsRezzed(false);
Save();
database.TransactionCommit();
UpdateEquipmentLight();
UpdateActiveLight();
return;
}
UpdateEquipmentLight();
UpdateActiveLight();
m_loot_request_type = LootRequestType::Forbidden;
IsRezzed(false);
Save();
}
void Corpse::MoveItemToCorpse(Client *client, EQ::ItemInstance *inst, int16 equipSlot, std::list<uint32> &removedList)
{
AddItem(
inst->GetItem()->ID,
inst->GetCharges(),
equipSlot,
inst->GetAugmentItemID(0),
inst->GetAugmentItemID(1),
inst->GetAugmentItemID(2),
inst->GetAugmentItemID(3),
inst->GetAugmentItemID(4),
inst->GetAugmentItemID(5),
inst->IsAttuned(),
inst->GetCustomDataString(),
inst->GetOrnamentationIcon(),
inst->GetOrnamentationIDFile(),
inst->GetOrnamentHeroModel()
);
removedList.push_back(equipSlot);
while (true) {
if (!inst->IsClassBag()) { break; }
if (equipSlot < EQ::invslot::GENERAL_BEGIN || equipSlot > EQ::invslot::slotCursor) { break; }
for (int16 sub_index = EQ::invbag::SLOT_BEGIN; sub_index <= EQ::invbag::SLOT_END; ++sub_index) {
int16 real_bag_slot = EQ::InventoryProfile::CalcSlotId(equipSlot, sub_index);
auto bag_inst = client->GetInv().GetItem(real_bag_slot);
if (bag_inst == nullptr) { continue; }
AddItem(
bag_inst->GetItem()->ID,
bag_inst->GetCharges(),
real_bag_slot,
bag_inst->GetAugmentItemID(0),
bag_inst->GetAugmentItemID(1),
bag_inst->GetAugmentItemID(2),
bag_inst->GetAugmentItemID(3),
bag_inst->GetAugmentItemID(4),
bag_inst->GetAugmentItemID(5),
bag_inst->IsAttuned(),
bag_inst->GetCustomDataString(),
bag_inst->GetOrnamentationIcon(),
bag_inst->GetOrnamentationIDFile(),
bag_inst->GetOrnamentHeroModel()
);
removedList.push_back(real_bag_slot);
client->DeleteItemInInventory(real_bag_slot, 0, true, false);
}
break;
}
client->DeleteItemInInventory(equipSlot, 0, true, false);
}
// To be called from LoadFromDBData
Corpse::Corpse(
uint32 corpse_id,
uint32 character_id,
const char *character_name,
LootItems *item_list,
uint32 copper,
uint32 silver,
uint32 gold,
uint32 platinum,
const glm::vec4 &position,
float size,
uint8 gender,
uint16 race,
uint8 class_,
uint8 deity,
uint8 level,
uint8 texture,
uint8 helm_texture,
uint32 rez_exp,
uint32 gm_rez_exp,
KilledByTypes killed_by,
bool is_rezzable,
uint32 rez_remaining_time,
bool was_at_graveyard
) : Mob(
"Unnamed_Corpse", // in_name
"", // in_lastname
0, // in_cur_hp
0, // in_max_hp
gender, // in_gender
race, // in_race
class_, // in_class
BT_Humanoid, // in_bodytype
deity, // in_deity
level, // in_level
0, // in_npctype_id
size, // in_size
0.0f, // in_runspeed
position, // position
0, // in_light
texture, // in_texture
helm_texture, // in_helmtexture
0, // in_ac
0, // in_atk
0, // in_str
0, // in_sta
0, // in_dex
0, // in_agi
0, // in_int
0, // in_wis
0, // in_cha
0, // in_haircolor
0, // in_beardcolor
0, // in_eyecolor1
0, // in_eyecolor2
0, // in_hairstyle
0, // in_luclinface
0, // in_beard
0, // in_drakkin_heritage
0, // in_drakkin_tattoo
0, // in_drakkin_details
EQ::TintProfile(), // in_armor_tint
0xFF, // in_aa_title
0, // in_see_invis
0, // in_see_invis_undead
0, // in_see_hide
0, // in_see_improved_hide
0, // in_hp_regen
0, // in_mana_regen
0, // in_qglobal
0, // in_maxlevel
0, // in_scalerate
0, // in_armtexture
0, // in_bracertexture
0, // in_handtexture
0, // in_legtexture
0, // in_feettexture
0, // in_usemodel
false, // in_always_aggros_foes
0, // in_heroic_strikethrough
false // in_keeps_sold_items
)
{
LoadPlayerCorpseDecayTime(corpse_id);
if (!zone->HasGraveyard() || was_at_graveyard) {
m_corpse_graveyard_timer.Disable();
}
strcpy(corpse_name, character_name);
strcpy(name, character_name);
m_copper = copper;
m_silver = silver;
m_gold = gold;
m_platinum = platinum;
m_rezzed_experience = rez_exp;
m_gm_rezzed_experience = gm_rez_exp;
m_killed_by_type = (uint8) killed_by;
m_is_rezzable = is_rezzable;
m_remaining_rez_time = rez_remaining_time;
m_is_owner_online = false;
m_is_corpse_changed = false;
m_is_player_corpse = true;
m_is_locked = false;
m_being_looted_by_entity_id = 0xFFFFFFFF;
m_corpse_db_id = corpse_id;
m_player_corpse_depop = false;
m_character_id = character_id;
m_item_list = *item_list;
item_list->clear();
// timers
m_corpse_decay_timer.SetTimer(RuleI(Character, CorpseDecayTime));
m_corpse_rezzable_timer.SetTimer(RuleI(Character, CorpseResTime));
m_corpse_delay_timer.SetTimer(RuleI(NPC, CorpseUnlockTimer));
m_corpse_graveyard_timer.SetTimer(RuleI(Zone, GraveyardTimeMS));
m_loot_cooldown_timer.SetTimer(10);
m_check_owner_online_timer.SetTimer(RuleI(Character, CorpseOwnerOnlineTime));
m_check_rezzable_timer.SetTimer(1000);
m_corpse_rezzable_timer.Disable();
SetRezTimer();
for (int &allowed_looter: m_allowed_looters) {
allowed_looter = 0;
}
SetPlayerKillItemID(0);
UpdateEquipmentLight();
UpdateActiveLight();
m_loot_request_type = LootRequestType::Forbidden;
}
Corpse::~Corpse()
{
if (m_is_player_corpse && !(m_player_corpse_depop && m_corpse_db_id == 0)) {
Save();
}
LootItems::iterator cur, end;
cur = m_item_list.begin();
end = m_item_list.end();
for (; cur != end; ++cur) {
LootItem *item = *cur;
safe_delete(item);
}
m_item_list.clear();
}
/*
this needs to be called AFTER the entity_id is set
the client does this too, so it's unchangable
*/
void Corpse::CalcCorpseName()
{
EntityList::RemoveNumbers(name);
char tmp[64];
if (m_is_player_corpse) {
snprintf(tmp, sizeof(tmp), "'s corpse%d", GetID());
}
else {
snprintf(tmp, sizeof(tmp), "`s_corpse%d", GetID());
}
name[(sizeof(name) - 1) - strlen(tmp)] = 0;
strcat(name, tmp);
}
bool Corpse::Save()
{
if (!m_is_player_corpse) {
return true;
}
if (!m_is_corpse_changed) {
return true;
}
CharacterCorpseEntry ce;
ce.size = size;
ce.locked = m_is_locked;
ce.copper = m_copper;
ce.silver = m_silver;
ce.gold = m_gold;
ce.plat = m_platinum;
ce.race = race;
ce.class_ = class_;
ce.gender = gender;
ce.deity = deity;
ce.level = level;
ce.texture = texture;
ce.helmtexture = helmtexture;
ce.exp = m_rezzed_experience;
ce.gm_exp = m_gm_exp;
ce.killed_by = m_killed_by_type;
ce.rezzable = m_is_rezzable;
ce.rez_time = m_remaining_rez_time;
ce.item_tint = m_item_tint;
ce.haircolor = haircolor;
ce.beardcolor = beardcolor;
ce.eyecolor2 = eyecolor1;
ce.hairstyle = hairstyle;
ce.face = luclinface;
ce.beard = beard;
ce.drakkin_heritage = drakkin_heritage;
ce.drakkin_tattoo = drakkin_tattoo;
ce.drakkin_details = drakkin_details;
for (auto &item: m_item_list) {
CharacterCorpseItemEntry e;
e.item_id = item->item_id;
e.equip_slot = item->equip_slot;
e.charges = item->charges;
e.lootslot = item->lootslot;
e.aug_1 = item->aug_1;
e.aug_2 = item->aug_2;
e.aug_3 = item->aug_3;
e.aug_4 = item->aug_4;
e.aug_5 = item->aug_5;
e.aug_6 = item->aug_6;
e.attuned = item->attuned;
e.custom_data = item->custom_data;
e.ornamenticon = item->ornamenticon;
e.ornamentidfile = item->ornamentidfile;
e.ornament_hero_model = item->ornament_hero_model;
ce.items.emplace_back(std::move(e));
}
if (m_corpse_db_id == 0) {
m_corpse_db_id = database.SaveCharacterCorpse(
m_character_id,
corpse_name,
zone->GetZoneID(),
zone->GetInstanceID(),
ce,
m_Position,
m_consented_guild_id
);
}
else {
m_corpse_db_id = database.UpdateCharacterCorpse(
m_corpse_db_id,
m_character_id,
corpse_name,
zone->GetZoneID(),
zone->GetInstanceID(),
ce,
m_Position,
m_consented_guild_id,
IsRezzed()
);
}
return true;
}
void Corpse::Delete()
{
if (IsPlayerCorpse() && m_corpse_db_id != 0) {
database.DeleteCharacterCorpse(m_corpse_db_id);
}
m_corpse_db_id = 0;
m_player_corpse_depop = true;
}
void Corpse::Bury()
{
if (IsPlayerCorpse() && m_corpse_db_id != 0) {
database.BuryCharacterCorpse(m_corpse_db_id);
}
m_corpse_db_id = 0;
m_player_corpse_depop = true;
}
void Corpse::DepopNPCCorpse()
{
if (IsNPCCorpse()) {
m_player_corpse_depop = true;
}
}
void Corpse::DepopPlayerCorpse()
{
m_player_corpse_depop = true;
}
void Corpse::AddConsentName(const std::string &consent_player_name)
{
for (const auto &consented_player_name: m_consented_player_names) {
if (strcasecmp(consented_player_name.c_str(), consent_player_name.c_str()) == 0) {
return;
}
}
m_consented_player_names.emplace_back(consent_player_name);
}
void Corpse::RemoveConsentName(const std::string &consent_player_name)
{
m_consented_player_names.erase(
std::remove_if(
m_consented_player_names.begin(), m_consented_player_names.end(),
[consent_player_name](const std::string &consented_player_name) {
return strcasecmp(consented_player_name.c_str(), consent_player_name.c_str()) == 0;
}
), m_consented_player_names.end()
);
}
uint32 Corpse::CountItems()
{
return m_item_list.size();
}
void Corpse::AddItem(
uint32 itemnum,
uint16 charges,
int16 slot,
uint32 aug1,
uint32 aug2,
uint32 aug3,
uint32 aug4,
uint32 aug5,
uint32 aug6,
bool attuned,
const std::string &custom_data,
uint32 ornamenticon,
uint32 ornamentidfile,
uint32 ornament_hero_model
)
{
if (!database.GetItem(itemnum)) {
return;
}
m_is_corpse_changed = true;
auto i = new LootItem;
i->item_id = itemnum;
i->charges = charges;
i->equip_slot = slot;
i->aug_1 = aug1;
i->aug_2 = aug2;
i->aug_3 = aug3;
i->aug_4 = aug4;
i->aug_5 = aug5;
i->aug_6 = aug6;
i->attuned = attuned;
i->custom_data = custom_data;
i->ornamenticon = ornamenticon;
i->ornamentidfile = ornamentidfile;
i->ornament_hero_model = ornament_hero_model;
m_item_list.push_back(i);
UpdateEquipmentLight();
}
LootItem *Corpse::GetItem(uint16 lootslot, LootItem **bag_item_data)
{
LootItem *sitem = nullptr;
LootItem *sitem2 = nullptr;
for (const auto &item: m_item_list) {
if (item->lootslot == lootslot) {
sitem = item;
break;
}
}
if (sitem && bag_item_data && EQ::InventoryProfile::SupportsContainers(sitem->equip_slot)) {
int16 bagstart = EQ::InventoryProfile::CalcSlotId(sitem->equip_slot, EQ::invbag::SLOT_BEGIN);
// convert above code to for loop
for (const auto &item: m_item_list) {
if (item->equip_slot >= bagstart && item->equip_slot < bagstart + 10) {
bag_item_data[item->equip_slot - bagstart] = item;
}
}
}
return sitem;
}
uint32 Corpse::GetWornItem(int16 equip_slot) const
{
for (const auto &item: m_item_list) {
if (item->equip_slot == equip_slot) {
return item->item_id;
}
}
return 0;
}
void Corpse::RemoveItem(uint16 lootslot)
{
if (lootslot == 0xFFFF) {
return;
}
for (const auto &item: m_item_list) {
if (item->lootslot == lootslot) {
RemoveItem(item);
return;
}
}
}
void Corpse::RemoveItem(LootItem *item_data)
{
for (auto iter = m_item_list.begin(); iter != m_item_list.end(); ++iter) {
auto sitem = *iter;
if (sitem != item_data) { continue; }
m_is_corpse_changed = true;
m_item_list.erase(iter);
uint8 material = EQ::InventoryProfile::CalcMaterialFromSlot(sitem->equip_slot); // autos to unsigned char
if (material != EQ::textures::materialInvalid) {
SendWearChange(material);
}
UpdateEquipmentLight();
if (UpdateActiveLight()) {
SendAppearancePacket(AppearanceType::Light, GetActiveLightType());
}
safe_delete(sitem);
return;
}
}
void Corpse::RemoveItemByID(uint32 item_id, int quantity)
{
if (!database.GetItem(item_id)) {
return;
}
if (!HasItem(item_id)) {
return;
}
int removed_count = 0;
for (auto current_item = m_item_list.begin(); current_item != m_item_list.end(); ++current_item) {
LootItem *sitem = *current_item;
if (removed_count == quantity) {
break;
}
if (sitem && sitem->item_id == item_id) {
int stack_size = sitem->charges > 1 ? sitem->charges : 1;
if ((removed_count + stack_size) <= quantity) {
removed_count += stack_size;
m_is_corpse_changed = true;
m_item_list.erase(current_item);
}
else {
int amount_left = (quantity - removed_count);
if (amount_left > 0) {
if (stack_size > amount_left) {
removed_count += amount_left;
sitem->charges -= amount_left;
m_is_corpse_changed = true;
}
else if (stack_size == amount_left) {
removed_count += amount_left;
m_item_list.erase(current_item);
}
}
}
}
}
}
void Corpse::SetCash(uint32 in_copper, uint32 in_silver, uint32 in_gold, uint32 in_platinum)
{
m_copper = in_copper;
m_silver = in_silver;
m_gold = in_gold;
m_platinum = in_platinum;
m_is_corpse_changed = true;
}
void Corpse::RemoveCash()
{
m_copper = 0;
m_silver = 0;
m_gold = 0;
m_platinum = 0;
m_is_corpse_changed = true;
}
bool Corpse::IsEmpty() const
{
if (m_copper != 0 || m_silver != 0 || m_gold != 0 || m_platinum != 0) {
return false;
}
return m_item_list.empty();
}
bool Corpse::Process()
{
if (m_player_corpse_depop) {
return false;
}
if (m_check_owner_online_timer.Check() && m_is_rezzable) {
CheckIsOwnerOnline();
}
if (m_corpse_delay_timer.Check()) {
for (int &allowed_looter: m_allowed_looters) {
allowed_looter = 0;
}
m_corpse_delay_timer.Disable();
return true;
}
if (m_corpse_graveyard_timer.Check()) {
if (MovePlayerCorpseToGraveyard()) {
m_corpse_graveyard_timer.Disable();
return false;
}
return true; // If the corpse was not moved, continue the corpse in the process rather than put in limbo
}