-
Notifications
You must be signed in to change notification settings - Fork 57
/
CCharact.cpp
3993 lines (3516 loc) · 115 KB
/
CCharact.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
//
// CCharAct.cpp
//
#include "graysvr.h" // predef header.
#include "CClient.h"
#include "../network/network.h"
#include "../network/send.h"
// "GONAME", "GOTYPE", "GOCHAR"
// 0 = object name
// 1 = char
// 2 = item type
bool CChar::TeleportToObj( int iType, TCHAR * pszArgs )
{
ADDTOCALLSTACK("CChar::TeleportToObj");
DWORD dwUID = m_Act_Targ.GetObjUID() &~ UID_F_ITEM;
DWORD dwTotal = g_World.GetUIDCount();
DWORD dwCount = dwTotal-1;
int iArg = 0;
if ( iType )
{
if ( pszArgs[0] && iType == 1 )
dwUID = 0;
iArg = RES_GET_INDEX( Exp_GetVal( pszArgs ));
}
while ( dwCount-- )
{
if ( ++dwUID >= dwTotal )
{
dwUID = 1;
}
CObjBase * pObj = g_World.FindUID(dwUID);
if ( pObj == NULL )
continue;
switch ( iType )
{
case 0:
{
MATCH_TYPE match = Str_Match( pszArgs, pObj->GetName());
if ( match != MATCH_VALID )
continue;
}
break;
case 1: // char
{
if ( ! pObj->IsChar())
continue;
if ( iArg-- > 0 )
continue;
}
break;
case 2: // item type
{
if ( ! pObj->IsItem())
continue;
CItem * pItem = dynamic_cast <CItem*>(pObj);
if ( ! pItem->IsType(static_cast<IT_TYPE>(iArg)))
continue;
}
break;
case 3: // char id
{
if ( ! pObj->IsChar())
continue;
CChar * pChar = dynamic_cast <CChar*>(pObj);
if ( pChar->GetID() != iArg )
continue;
}
break;
case 4: // item id
{
if ( ! pObj->IsItem())
continue;
CItem * pItem = dynamic_cast <CItem*>(pObj);
if ( pItem->GetID() != iArg )
continue;
}
break;
}
CObjBaseTemplate * pObjTop = pObj->GetTopLevelObj();
if ( pObjTop == NULL || pObjTop == this )
continue;
if ( pObjTop->IsChar() )
{
if ( ! CanDisturb( dynamic_cast<CChar*>(pObjTop)))
continue;
}
m_Act_Targ = pObj->GetUID();
Spell_Teleport( pObjTop->GetTopPoint(), true, false );
return( true );
}
return( false );
}
// GoCli
bool CChar::TeleportToCli( int iType, int iArgs )
{
ADDTOCALLSTACK("CChar::TeleportToCli");
ClientIterator it;
for (CClient* pClient = it.next(); pClient != NULL; pClient = it.next())
{
if ( ! iType )
{
if ( pClient->GetSocketID() != iArgs )
continue;
}
CChar * pChar = pClient->GetChar();
if ( pChar == NULL )
continue;
if ( ! CanDisturb( pChar ))
continue;
if ( iType )
{
if ( iArgs-- )
continue;
}
m_Act_Targ = pChar->GetUID();
Spell_Teleport( pChar->GetTopPoint(), true, false );
return( true );
}
return( false );
}
void CChar::Jail( CTextConsole *pSrc, bool fSet, int iCell )
{
ADDTOCALLSTACK("CChar::Jail");
if ( IsTrigUsed(TRIGGER_JAILED) )
{
CScriptTriggerArgs Args(fSet ? 1 : 0, static_cast<INT64>(iCell), static_cast<INT64>(0));
if ( OnTrigger(CTRIG_Jailed, pSrc, &Args) == TRIGRET_RET_TRUE )
return;
}
if ( fSet )
{
if ( m_pPlayer )
{
CAccount *pAccount = m_pPlayer->GetAccount();
ASSERT(pAccount);
pAccount->SetPrivFlags(PRIV_JAILED);
pAccount->m_TagDefs.SetNum("JailCell", iCell, true);
}
TCHAR szJailName[128];
if ( iCell )
sprintf(szJailName, "jail%d", iCell);
else
strcpy(szJailName, "jail");
CPointMap ptJail = g_Cfg.GetRegionPoint(szJailName);
if ( ptJail.IsValidPoint() && (GetTopPoint().GetRegion(REGION_TYPE_AREA) != ptJail.GetRegion(REGION_TYPE_AREA)) )
Spell_Teleport(ptJail, true, false);
SysMessageDefault(DEFMSG_MSG_JAILED);
}
else
{
if ( m_pPlayer )
{
CAccount *pAccount = m_pPlayer->GetAccount();
ASSERT(pAccount);
if ( !pAccount->IsPriv(PRIV_JAILED) )
return;
pAccount->ClearPrivFlags(PRIV_JAILED);
pAccount->m_TagDefs.DeleteKey("JailCell");
}
SysMessageDefault(DEFMSG_MSG_FORGIVEN);
}
}
// A vendor is giving me gold. put it in my pack or other place.
void CChar::AddGoldToPack( int iAmount, CItemContainer *pPack )
{
ADDTOCALLSTACK("CChar::AddGoldToPack");
if ( !pPack )
pPack = GetContainerCreate(LAYER_PACK);
CItem *pGold = NULL;
int iGoldStack = 0;
while ( iAmount > 0 )
{
iGoldStack = minimum(iAmount, g_Cfg.m_iItemsMaxAmount);
pGold = CItem::CreateScript(ITEMID_GOLD_C1, this);
pGold->SetAmount(iGoldStack);
pPack->ContentAdd(pGold);
iAmount -= iGoldStack;
}
if ( pGold && (pPack->GetEquipLayer() == LAYER_PACK) )
Sound(pGold->GetDropSound(pPack));
}
// add equipped items.
// check for item already in that layer ?
// NOTE: This could be part of the Load as well so it may not truly be being "equipped" at this time.
// OnTrigger for equip is done by ItemEquip()
void CChar::LayerAdd( CItem * pItem, LAYER_TYPE layer )
{
ADDTOCALLSTACK("CChar::LayerAdd");
if ( pItem == NULL )
return;
if ( pItem->GetParent() == this &&
pItem->GetEquipLayer() == layer )
{
return;
}
if ( layer == LAYER_DRAGGING )
{
pItem->RemoveSelf(); // remove from where i am before add so UNEQUIP effect takes.
// NOTE: CanEquipLayer may bounce an item . If it stacks with this we are in trouble !
}
if ( g_Serv.IsLoading() == false )
{
// This takes care of any conflicting items in the slot !
layer = CanEquipLayer(pItem, layer, NULL, false);
if ( layer == LAYER_NONE )
{
// we should not allow non-layered stuff to be put here ?
// Put in pack instead ?
ItemBounce( pItem );
return;
}
if (!pItem->IsTypeSpellable() && !pItem->m_itSpell.m_spell && !pItem->IsType(IT_WAND)) // can this item have a spell effect ? If so we do not send
{
if ((IsTrigUsed(TRIGGER_MEMORYEQUIP)) || (IsTrigUsed(TRIGGER_ITEMMEMORYEQUIP)))
{
CScriptTriggerArgs pArgs;
pArgs.m_iN1 = layer;
if (pItem->OnTrigger(ITRIG_MemoryEquip, this, &pArgs) == TRIGRET_RET_TRUE)
{
pItem->Delete();
return;
}
}
}
}
if ( layer == LAYER_SPECIAL )
{
if ( pItem->IsType( IT_EQ_TRADE_WINDOW ))
layer = LAYER_NONE;
}
CContainer::ContentAddPrivate( pItem );
pItem->SetEquipLayer( layer );
// update flags etc for having equipped this.
switch ( layer )
{
case LAYER_HAND1:
case LAYER_HAND2:
// If weapon
if ( pItem->IsTypeWeapon())
{
m_uidWeapon = pItem->GetUID();
if ( Fight_IsActive() )
Skill_Start(Fight_GetWeaponSkill()); // update char action
}
else if ( pItem->IsTypeArmor())
{
// Shield of some sort.
m_defense = static_cast<WORD>(CalcArmorDefense());
StatFlag_Set( STATF_HasShield );
UpdateStatsFlag();
}
break;
case LAYER_SHOES:
case LAYER_PANTS:
case LAYER_SHIRT:
case LAYER_HELM: // 6
case LAYER_GLOVES: // 7
case LAYER_COLLAR: // 10 = gorget or necklace.
case LAYER_HALF_APRON:
case LAYER_CHEST: // 13 = armor chest
case LAYER_TUNIC: // 17 = jester suit
case LAYER_ARMS: // 19 = armor
case LAYER_CAPE: // 20 = cape
case LAYER_ROBE: // 22 = robe over all.
case LAYER_SKIRT:
case LAYER_LEGS:
// If armor or clothing = change in defense rating.
m_defense = static_cast<WORD>(CalcArmorDefense());
UpdateStatsFlag();
break;
// These effects are not magical. (make them spells !)
case LAYER_FLAG_Criminal:
StatFlag_Set( STATF_Criminal );
NotoSave_Update();
return;
case LAYER_FLAG_SpiritSpeak:
StatFlag_Set( STATF_SpiritSpeak );
return;
case LAYER_FLAG_Stuck:
StatFlag_Set( STATF_Freeze );
if ( IsClient() )
GetClient()->addBuff(BI_PARALYZE, 1075827, 1075828, static_cast<WORD>(pItem->GetTimerAdjusted()));
break;
default:
break;
}
if ( layer != LAYER_DRAGGING )
{
switch ( pItem->GetType())
{
case IT_EQ_SCRIPT: // pure script.
break;
case IT_EQ_MEMORY_OBJ:
{
CItemMemory *pMemory = dynamic_cast<CItemMemory *>( pItem );
if (pMemory != NULL)
Memory_UpdateFlags(pMemory);
break;
}
case IT_EQ_HORSE:
StatFlag_Set(STATF_OnHorse);
break;
case IT_COMM_CRYSTAL:
StatFlag_Set(STATF_COMM_CRYSTAL);
break;
default:
break;
}
}
pItem->Update();
}
// Unequip the item.
// This may be a delete etc. It can not FAIL !
// Removing 'Equip beneficts' from this item
void CChar::OnRemoveOb( CGObListRec* pObRec ) // Override this = called when removed from list.
{
ADDTOCALLSTACK("CChar::OnRemoveOb");
CItem *pItem = static_cast<CItem *>(pObRec);
if ( !pItem )
return;
LAYER_TYPE layer = pItem->GetEquipLayer();
if (( IsTrigUsed(TRIGGER_UNEQUIP) ) || ( IsTrigUsed(TRIGGER_ITEMUNEQUIP) ))
{
if ( layer != LAYER_DRAGGING && ! g_Serv.IsLoading())
pItem->OnTrigger( ITRIG_UNEQUIP, this );
}
CContainer::OnRemoveOb( pObRec );
// remove equipped items effects
switch ( layer )
{
case LAYER_HAND1:
case LAYER_HAND2: // other hand = shield
if ( pItem->IsTypeWeapon())
{
m_uidWeapon.InitUID();
if ( Fight_IsActive() )
Skill_Start(Fight_GetWeaponSkill()); // update char action
}
else if ( pItem->IsTypeArmor())
{
// Shield
m_defense = static_cast<WORD>(CalcArmorDefense());
StatFlag_Clear( STATF_HasShield );
UpdateStatsFlag();
}
if ( (m_Act_SkillCurrent == SKILL_MINING) || (m_Act_SkillCurrent == SKILL_FISHING) || (m_Act_SkillCurrent == SKILL_LUMBERJACKING) )
Skill_Cleanup();
break;
case LAYER_SHOES:
case LAYER_PANTS:
case LAYER_SHIRT:
case LAYER_HELM: // 6
case LAYER_GLOVES: // 7
case LAYER_COLLAR: // 10 = gorget or necklace.
case LAYER_CHEST: // 13 = armor chest
case LAYER_TUNIC: // 17 = jester suit
case LAYER_ARMS: // 19 = armor
case LAYER_CAPE: // 20 = cape
case LAYER_ROBE: // 22 = robe over all.
case LAYER_SKIRT:
case LAYER_LEGS:
m_defense = static_cast<WORD>(CalcArmorDefense());
UpdateStatsFlag();
break;
case LAYER_FLAG_Criminal:
StatFlag_Clear( STATF_Criminal );
NotoSave_Update();
break;
case LAYER_FLAG_SpiritSpeak:
StatFlag_Clear( STATF_SpiritSpeak );
break;
case LAYER_FLAG_Stuck:
StatFlag_Clear( STATF_Freeze );
if ( IsClient() )
{
GetClient()->removeBuff(BI_PARALYZE);
GetClient()->addCharMove(this); // immediately tell the client that now he's able to move (without this, it will be able to move only on next tick update)
}
break;
default:
break;
}
// Items with magic effects.
if ( layer != LAYER_DRAGGING )
{
switch ( pItem->GetType())
{
case IT_COMM_CRYSTAL:
if ( ContentFind( RESOURCE_ID( RES_TYPEDEF,IT_COMM_CRYSTAL ), 0, 0 ) == NULL )
{
StatFlag_Clear(STATF_COMM_CRYSTAL);
}
break;
case IT_EQ_HORSE:
StatFlag_Clear(STATF_OnHorse);
break;
case IT_EQ_MEMORY_OBJ:
{
// Clear the associated flags.
CItemMemory *pMemory = dynamic_cast<CItemMemory*>(pItem);
if (pMemory != NULL)
Memory_UpdateClearTypes( pMemory, 0xFFFF );
break;
}
default:
break;
}
if ( pItem->IsTypeArmorWeapon() )
{
SetDefNum("DAMPHYSICAL", GetDefNum("DAMPHYSICAL", true) - pItem->GetDefNum("DAMPHYSICAL", true, true));
SetDefNum("DAMFIRE", GetDefNum("DAMFIRE", true) - pItem->GetDefNum("DAMFIRE", true, true));
SetDefNum("DAMCOLD", GetDefNum("DAMCOLD", true) - pItem->GetDefNum("DAMCOLD", true, true));
SetDefNum("DAMPOISON", GetDefNum("DAMPOISON", true) - pItem->GetDefNum("DAMPOISON", true, true));
SetDefNum("DAMENERGY", GetDefNum("DAMENERGY", true) - pItem->GetDefNum("DAMENERGY", true, true));
SetDefNum("RESPHYSICAL", GetDefNum("RESPHYSICAL", true) - pItem->GetDefNum("RESPHYSICAL", true, true));
SetDefNum("RESFIRE", GetDefNum("RESFIRE", true) - pItem->GetDefNum("RESFIRE", true, true));
SetDefNum("RESCOLD", GetDefNum("RESCOLD", true) - pItem->GetDefNum("RESCOLD", true, true));
SetDefNum("RESPOISON", GetDefNum("RESPOISON", true) - pItem->GetDefNum("RESPOISON", true, true));
SetDefNum("RESENERGY", GetDefNum("RESENERGY", true) - pItem->GetDefNum("RESENERGY", true, true));
}
if ( pItem->IsTypeWeapon() )
{
CItem * pCursedMemory = LayerFind(LAYER_SPELL_Curse_Weapon); // Remove the cursed state from SPELL_Curse_Weapon.
if (pCursedMemory)
pItem->SetDefNum("HitLeechLife", pItem->GetDefNum("HitLeechLife", true) - pCursedMemory->m_itSpell.m_spelllevel, true);
}
short iStrengthBonus = static_cast<short>(pItem->GetDefNum("BONUSSTR", true, true));
if (iStrengthBonus != 0)
Stat_SetMod(STAT_STR, Stat_GetMod(STAT_STR) - iStrengthBonus);
short iDexterityBonus = static_cast<short>(pItem->GetDefNum("BONUSDEX", true, true));
if (iDexterityBonus != 0)
Stat_SetMod(STAT_DEX, Stat_GetMod(STAT_DEX) - iDexterityBonus);
short iIntelligenceBonus = static_cast<short>(pItem->GetDefNum("BONUSINT", true, true));
if (iIntelligenceBonus != 0)
Stat_SetMod(STAT_INT, Stat_GetMod(STAT_INT) - iIntelligenceBonus);
short iHitpointIncrease = static_cast<short>(pItem->GetDefNum("BONUSHITS", true, true));
if (iHitpointIncrease != 0)
Stat_SetMax(STAT_STR, Stat_GetMax(STAT_STR) - iHitpointIncrease);
short iStaminaIncrease = static_cast<short>(pItem->GetDefNum("BONUSSTAM", true, true));
if (iStaminaIncrease != 0)
Stat_SetMax(STAT_DEX, Stat_GetMax(STAT_DEX) - iStaminaIncrease);
short iManaIncrease = static_cast<short>(pItem->GetDefNum("BONUSMANA", true, true));
if (iManaIncrease != 0)
Stat_SetMax(STAT_INT, Stat_GetMax(STAT_INT) - iManaIncrease);
INT64 iDamageIncrease = pItem->GetDefNum("INCREASEDAM", true, true);
if ( iDamageIncrease != 0 )
SetDefNum("INCREASEDAM", GetDefNum("INCREASEDAM", true) - iDamageIncrease);
INT64 iDefenseChanceIncrease = pItem->GetDefNum("INCREASEDEFCHANCE", true, true);
if ( iDefenseChanceIncrease != 0 )
SetDefNum("INCREASEDEFCHANCE", GetDefNum("INCREASEDEFCHANCE", true) - iDefenseChanceIncrease);
INT64 iFasterCasting = pItem->GetDefNum("FASTERCASTING", true, true);
if ( iFasterCasting != 0 )
SetDefNum("FASTERCASTING", GetDefNum("FASTERCASTING", true) - iFasterCasting);
INT64 iHitChanceIncrease = pItem->GetDefNum("INCREASEHITCHANCE", true, true);
if ( iHitChanceIncrease != 0 )
SetDefNum("INCREASEHITCHANCE", GetDefNum("INCREASEHITCHANCE", true) - iHitChanceIncrease);
INT64 iSpellDamageIncrease = pItem->GetDefNum("INCREASESPELLDAM", true, true);
if ( iSpellDamageIncrease != 0 )
SetDefNum("INCREASESPELLDAM", GetDefNum("INCREASESPELLDAM", true) - iSpellDamageIncrease);
INT64 iSwingSpeedIncrease = pItem->GetDefNum("INCREASESWINGSPEED", true, true);
if ( iSwingSpeedIncrease != 0 )
SetDefNum("INCREASESWINGSPEED", GetDefNum("INCREASESWINGSPEED", true) - iSwingSpeedIncrease);
INT64 iEnhancePotions = pItem->GetDefNum("ENHANCEPOTIONS", true, true);
if (iEnhancePotions != 0)
SetDefNum("ENHANCEPOTIONS", GetDefNum("ENHANCEPOTIONS", true) - iEnhancePotions);
INT64 iLowerManaCost = pItem->GetDefNum("LOWERMANACOST", true, true);
if (iLowerManaCost != 0)
SetDefNum("LOWERMANACOST", GetDefNum("LOWERMANACOST", true) - iLowerManaCost);
INT64 iLuck = pItem->GetDefNum("LUCK", true, true);
if ( iLuck != 0 )
SetDefNum("LUCK", GetDefNum("LUCK", true) - iLuck);
if ( pItem->GetDefNum("NIGHTSIGHT", true, true))
{
StatFlag_Mod( STATF_NightSight, 0 );
if ( IsClient() )
m_pClient->addLight();
}
// If items are magical then remove effect here.
Spell_Effect_Remove(pItem);
}
}
// shrunk or died. (or sleeping)
void CChar::DropAll( CItemContainer * pCorpse, DWORD dwAttr )
{
ADDTOCALLSTACK("CChar::DropAll");
if ( IsStatFlag( STATF_Conjured ))
return; // drop nothing.
CItemContainer *pPack = GetContainer(LAYER_PACK);
if ( pPack )
{
if ( pCorpse )
pPack->ContentsTransfer(pCorpse, true);
else
pPack->ContentsDump(GetTopPoint(), dwAttr);
}
// transfer equipped items to corpse or your pack (if newbie).
UnEquipAllItems( pCorpse );
}
// We morphed, sleeping, died or became a GM.
// Pets can be told to "Drop All"
// drop item that is up in the air as well.
// pDest = Container to place items in
// bLeaveHands = true to leave items in hands; otherwise, false
void CChar::UnEquipAllItems( CItemContainer * pDest, bool bLeaveHands )
{
ADDTOCALLSTACK("CChar::UnEquipAllItems");
if ( GetCount() <= 0 )
return;
CItemContainer *pPack = GetContainerCreate(LAYER_PACK);
CItem *pItemNext = NULL;
for ( CItem *pItem = GetContentHead(); pItem != NULL; pItem = pItemNext )
{
pItemNext = pItem->GetNext();
LAYER_TYPE layer = pItem->GetEquipLayer();
switch ( layer )
{
case LAYER_NONE:
pItem->Delete(); // Get rid of any trades.
continue;
case LAYER_FLAG_Poison:
case LAYER_FLAG_Hallucination:
case LAYER_FLAG_Potion:
case LAYER_FLAG_Drunk:
case LAYER_FLAG_Stuck:
case LAYER_FLAG_PotionUsed:
if ( IsStatFlag(STATF_DEAD) )
pItem->Delete();
continue;
case LAYER_PACK:
case LAYER_HORSE:
continue;
case LAYER_HAIR:
case LAYER_BEARD:
// Copy hair and beard to corpse.
if ( pDest && pDest->IsType(IT_CORPSE) )
{
CItem *pDupe = CItem::CreateDupeItem(pItem);
pDest->ContentAdd(pDupe);
// Equip layer only matters on a corpse.
pDupe->SetContainedLayer(static_cast<BYTE>(layer));
}
continue;
case LAYER_DRAGGING:
layer = LAYER_NONE;
break;
case LAYER_HAND1:
case LAYER_HAND2:
if ( bLeaveHands )
continue;
break;
default:
// can't transfer this to corpse.
if ( !CItemBase::IsVisibleLayer(layer) )
continue;
break;
}
if ( pDest && !pItem->IsAttr(ATTR_NEWBIE|ATTR_MOVE_NEVER|ATTR_BLESSED|ATTR_INSURED|ATTR_NODROPTRADE) )
{
// Move item to dest (corpse usually)
pDest->ContentAdd(pItem);
if ( pDest->IsType(IT_CORPSE) )
{
// Equip layer only matters on a corpse.
pItem->SetContainedLayer(static_cast<BYTE>(layer));
}
}
else if ( pPack )
{
// Move item to char pack.
pPack->ContentAdd(pItem);
}
}
}
// Show the world that I am picking up or putting down this object.
// NOTE: This makes people disapear.
void CChar::UpdateDrag( CItem * pItem, CObjBase * pCont, CPointMap * pt )
{
ADDTOCALLSTACK("CChar::UpdateDrag");
if ( pCont && pCont->GetTopLevelObj() == this ) // moving to my own backpack
return;
if ( !pCont && !pt && pItem->GetTopLevelObj() == this ) // doesn't work for ground objects
return;
PacketDragAnimation* cmd = new PacketDragAnimation(this, pItem, pCont, pt);
UpdateCanSee(cmd, m_pClient);
}
// Push status change to all who can see us.
// For Weight, AC, Gold must update all
// Just flag the stats to be updated later if possible.
void CChar::UpdateStatsFlag() const
{
ADDTOCALLSTACK("CChar::UpdateStatsFlag");
if ( g_Serv.IsLoading() )
return;
if ( IsClient() )
GetClient()->addUpdateStatsFlag();
}
// queue updates
void CChar::UpdateHitsFlag()
{
ADDTOCALLSTACK("CChar::UpdateHitsFlag");
if ( g_Serv.IsLoading() )
return;
m_fStatusUpdate |= SU_UPDATE_HITS;
if ( IsClient() )
GetClient()->addUpdateHitsFlag();
}
void CChar::UpdateModeFlag()
{
ADDTOCALLSTACK("CChar::UpdateModeFlag");
if ( g_Serv.IsLoading() )
return;
m_fStatusUpdate |= SU_UPDATE_MODE;
}
void CChar::UpdateManaFlag() const
{
ADDTOCALLSTACK("CChar::UpdateManaFlag");
if ( g_Serv.IsLoading() )
return;
if ( IsClient() )
GetClient()->addUpdateManaFlag();
}
void CChar::UpdateStamFlag() const
{
ADDTOCALLSTACK("CChar::UpdateStamFlag");
if ( g_Serv.IsLoading() )
return;
if ( IsClient() )
GetClient()->addUpdateStamFlag();
}
void CChar::UpdateRegenTimers(STAT_TYPE iStat, short iVal)
{
ADDTOCALLSTACK("CChar::UpdateRegenTimers");
m_Stat[iStat].m_regen = iVal;
}
void CChar::UpdateStatVal( STAT_TYPE type, short iChange, short iLimit )
{
ADDTOCALLSTACK("CChar::UpdateStatVal");
short iValPrev = Stat_GetVal(type);
short iVal = iValPrev + iChange;
if ( !iLimit )
iLimit = Stat_GetMax(type);
if ( iVal < 0 )
iVal = 0;
else if ( iVal > iLimit )
iVal = iLimit;
if ( iVal == iValPrev )
return;
Stat_SetVal(type, iVal);
switch ( type )
{
case STAT_STR:
UpdateHitsFlag();
break;
case STAT_INT:
UpdateManaFlag();
break;
case STAT_DEX:
UpdateStamFlag();
break;
}
}
// Calculate the action to be used to call UpdateAnimate() with it
ANIM_TYPE CChar::GenerateAnimate(ANIM_TYPE action, bool fTranslate, bool fBackward, BYTE iFrameDelay, BYTE iAnimLen)
{
ADDTOCALLSTACK("CChar::UpdateAnimate");
UNREFERENCED_PARAMETER(iAnimLen);
if ( action < 0 || action >= ANIM_QTY )
return static_cast<ANIM_TYPE>(-1);
//Begin old client animation behaviour
if ( fBackward && iFrameDelay ) // backwards and delayed just dont work ! = invis
iFrameDelay = 0;
if ( fTranslate )
{
CCharBase *pCharDef = Char_GetDef();
if ( action == ANIM_ATTACK_WEAPON )
{
CItem *pWeapon = m_uidWeapon.ItemFind();
if ( pWeapon )
{
// action depends on weapon type (skill) and 2 Hand type.
LAYER_TYPE layer = pWeapon->Item_GetDef()->GetEquipLayer();
switch ( pWeapon->GetType() )
{
case IT_WEAPON_MACE_CROOK: // sheperds crook
case IT_WEAPON_MACE_SMITH: // smith/sledge hammer
case IT_WEAPON_MACE_STAFF:
case IT_WEAPON_MACE_SHARP: // war axe can be used to cut/chop trees.
action = (layer == LAYER_HAND2) ? ANIM_ATTACK_2H_BASH : ANIM_ATTACK_1H_BASH;
break;
case IT_WEAPON_SWORD:
case IT_WEAPON_AXE:
case IT_WEAPON_MACE_PICK: // pickaxe
action = (layer == LAYER_HAND2) ? ANIM_ATTACK_2H_SLASH : ANIM_ATTACK_1H_SLASH;
break;
case IT_WEAPON_FENCE:
action = (layer == LAYER_HAND2) ? ANIM_ATTACK_2H_PIERCE : ANIM_ATTACK_1H_PIERCE;
break;
case IT_WEAPON_THROWING:
action = ANIM_ATTACK_1H_SLASH;
break;
case IT_WEAPON_BOW:
action = ANIM_ATTACK_BOW;
break;
case IT_WEAPON_XBOW:
action = ANIM_ATTACK_XBOW;
break;
default:
break;
}
}
else
{
action = ANIM_ATTACK_WRESTLE;
}
}
if ( IsStatFlag(STATF_OnHorse) )
{
// Horse back anims are dif.
switch ( action )
{
case ANIM_WALK_UNARM:
case ANIM_WALK_ARM:
case ANIM_WALK_WAR:
return ANIM_HORSE_RIDE_SLOW;
case ANIM_RUN_UNARM:
case ANIM_RUN_ARMED:
return ANIM_HORSE_RIDE_FAST;
case ANIM_STAND:
case ANIM_STAND_WAR_1H:
case ANIM_STAND_WAR_2H:
return ANIM_HORSE_STAND;
case ANIM_ATTACK_1H_SLASH:
case ANIM_ATTACK_1H_PIERCE:
case ANIM_ATTACK_1H_BASH:
case ANIM_CAST_DIR:
case ANIM_ATTACK_WRESTLE:
return ANIM_HORSE_ATTACK;
case ANIM_FIDGET1:
case ANIM_FIDGET_YAWN:
case ANIM_ATTACK_2H_BASH:
case ANIM_ATTACK_2H_SLASH:
case ANIM_ATTACK_2H_PIERCE:
case ANIM_GET_HIT:
case ANIM_BLOCK:
return ANIM_HORSE_SLAP;
case ANIM_CAST_AREA:
case ANIM_ATTACK_BOW:
return ANIM_HORSE_ATTACK_BOW;
case ANIM_ATTACK_XBOW:
case ANIM_BOW:
case ANIM_SALUTE:
case ANIM_EAT:
return ANIM_HORSE_ATTACK_XBOW;
default:
return ANIM_HORSE_STAND;
}
}
else if ( !IsPlayableCharacter() ) //( GetDispID() < CREID_MAN ) Possible fix for anims not being displayed above 400
{
// Animals have certain anims. Monsters have others.
if ( GetDispID() >= CREID_HORSE1 )
{
// All animals have all these anims thankfully
switch ( action )
{
case ANIM_WALK_UNARM:
case ANIM_WALK_ARM:
case ANIM_WALK_WAR:
return ANIM_ANI_WALK;
case ANIM_RUN_UNARM:
case ANIM_RUN_ARMED:
return ANIM_ANI_RUN;
case ANIM_STAND:
case ANIM_STAND_WAR_1H:
case ANIM_STAND_WAR_2H:
case ANIM_FIDGET1:
return ANIM_ANI_FIDGET1;
case ANIM_FIDGET_YAWN:
return ANIM_ANI_FIDGET2;
case ANIM_CAST_DIR:
return ANIM_ANI_ATTACK1;
case ANIM_CAST_AREA:
case ANIM_EAT:
return ANIM_ANI_EAT;
case ANIM_GET_HIT:
return ANIM_ANI_GETHIT;
case ANIM_ATTACK_1H_SLASH:
case ANIM_ATTACK_1H_PIERCE:
case ANIM_ATTACK_1H_BASH:
case ANIM_ATTACK_2H_BASH:
case ANIM_ATTACK_2H_SLASH:
case ANIM_ATTACK_2H_PIERCE:
case ANIM_ATTACK_BOW:
case ANIM_ATTACK_XBOW:
case ANIM_ATTACK_WRESTLE:
switch ( Calc_GetRandVal(2) )
{
case 0: return ANIM_ANI_ATTACK1;
case 1: return ANIM_ANI_ATTACK2;
}
case ANIM_DIE_BACK:
return ANIM_ANI_DIE1;
case ANIM_DIE_FORWARD:
return ANIM_ANI_DIE2;
case ANIM_BLOCK:
case ANIM_BOW:
case ANIM_SALUTE:
return ANIM_ANI_SLEEP;
default:
break;
}
while ( action != ANIM_WALK_UNARM && !(pCharDef->m_Anims & (1 << action)) )
{
// This anim is not supported. Try to use one that is.
switch ( action )
{
case ANIM_ANI_SLEEP: // All have this.
return ANIM_ANI_EAT;
default:
return ANIM_WALK_UNARM;
}
}
}
else
{
// Monsters don't have all the anims.
switch ( action )
{
case ANIM_CAST_DIR:
return ANIM_MON_Stomp;
case ANIM_CAST_AREA:
return ANIM_MON_PILLAGE;
case ANIM_DIE_BACK:
return ANIM_MON_DIE1;
case ANIM_DIE_FORWARD:
return ANIM_MON_DIE2;
case ANIM_GET_HIT:
switch ( Calc_GetRandVal(3) )
{
case 0: return ANIM_MON_GETHIT;
case 1: return ANIM_MON_BlockRight;
case 2: return ANIM_MON_BlockLeft;
}
break;
case ANIM_ATTACK_1H_SLASH:
case ANIM_ATTACK_1H_PIERCE:
case ANIM_ATTACK_1H_BASH:
case ANIM_ATTACK_2H_BASH:
case ANIM_ATTACK_2H_PIERCE:
case ANIM_ATTACK_2H_SLASH:
case ANIM_ATTACK_BOW:
case ANIM_ATTACK_XBOW:
case ANIM_ATTACK_WRESTLE:
switch ( Calc_GetRandVal(3) )
{
case 0: return ANIM_MON_ATTACK1;
case 1: return ANIM_MON_ATTACK2;
case 2: return ANIM_MON_ATTACK3;
}
default:
return ANIM_WALK_UNARM;
}
// NOTE: Available actions depend HEAVILY on creature type !
// ??? Monsters don't have all anims in common !
// translate these !
while ( action != ANIM_WALK_UNARM && !(pCharDef->m_Anims & (1 << action)) )
{
// This anim is not supported. Try to use one that is.
switch ( action )
{
case ANIM_MON_ATTACK1: // All have this.
DEBUG_ERR(("Anim 0%x This is wrong! Invalid SCP file data.\n", GetDispID()));
return ANIM_WALK_UNARM;
case ANIM_MON_ATTACK2: // Dolphins, Eagles don't have this.
case ANIM_MON_ATTACK3:
return ANIM_MON_ATTACK1; // ALL creatures have at least this attack.
case ANIM_MON_Cast2: // Trolls, Spiders, many others don't have this.
return ANIM_MON_BlockRight; // Birds don't have this !
case ANIM_MON_BlockRight:
return ANIM_MON_BlockLeft;
case ANIM_MON_BlockLeft:
return ANIM_MON_GETHIT;
case ANIM_MON_GETHIT:
if ( pCharDef->m_Anims & (1 << ANIM_MON_Cast2) )
return ANIM_MON_Cast2;
else
return ANIM_WALK_UNARM;
case ANIM_MON_Stomp:
return ANIM_MON_PILLAGE;
case ANIM_MON_AttackBow:
case ANIM_MON_AttackXBow:
case ANIM_MON_PILLAGE:
return ANIM_MON_ATTACK3;
case ANIM_MON_AttackThrow:
return ANIM_MON_AttackXBow;
default:
DEBUG_ERR(("Anim Unsupported 0%x for 0%x\n", action, GetDispID()));
return ANIM_WALK_UNARM;
}
}
}