Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcharacter.cpp
More file actions
2295 lines (1957 loc) · 65.4 KB
/
Copy pathcharacter.cpp
File metadata and controls
2295 lines (1957 loc) · 65.4 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
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
/* Copyright (C) 2009,2010,2011 Dawn - 2D roleplaying game
This file is a part of the dawn-rpg project <https://github.com/frusen/Dawn>.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "character.h"
#include <cassert>
#include "drawinghelpers.h"
#include "spell.h"
#include "interface.h"
#include "groundloot.h"
#include "statssystem.h"
#include "zone.h"
#include "questwindow.h"
#include "npc.h"
#include "player.h"
#include "configuration.h"
#include "globals.h"
#include "random.h"
#include <map>
#include <string>
#include <limits>
#include <iostream>
#include <memory>
#include <iostream>
std::map< std::string, CCharacter* > allMobTypes;
extern std::auto_ptr<QuestWindow> questWindow;
// Dawn LUA Interface
namespace DawnInterface
{
CCharacter* createNewMobType( std::string typeID )
{
CCharacter* newMobType = new CNPC(0, 0, 0, 0, 0);
allMobTypes[ typeID ] = newMobType;
return newMobType;
}
void addTextToLogWindow( GLfloat color[], const char* text, ... );
}
bool CCharacter::hasTarget( CCharacter* target )
{
if( this->target == target )
{
return true;
}
return false;
}
void CCharacter::baseOnType( std::string otherName )
{
CCharacter* other;
if( allMobTypes.count( otherName ) != 1 )
{
std::cerr << "mob type \"" << otherName << "\" found " << allMobTypes.count( otherName ) << " times!!! aborting." << std::endl;
abort();
}
other = allMobTypes[ otherName ];
// classID is only set if this was created as a new mob type with createNewMobType
if( this->classID == "" )
{
this->classID = otherName;
}
setStrength( other->getStrength() );
setDexterity( other->getDexterity() );
setVitality( other->getVitality() );
setIntellect( other->getIntellect() );
setWisdom( other->getWisdom() );
setMaxHealth( other->getMaxHealth() );
setMaxMana( other->getMaxMana() );
setMaxFatigue( other->getMaxFatigue() );
setMinDamage( other->getMinDamage() );
setMaxDamage( other->getMaxDamage() );
size_t numActivities=static_cast<size_t>(ActivityType::Count);
for ( size_t curActivity=0; curActivity<numActivities; ++curActivity ) {
ActivityType::ActivityType curActivityType = static_cast<ActivityType::ActivityType>( curActivity );
setNumMoveTexturesPerDirection( curActivityType, other->numMoveTexturesPerDirection[ curActivity ] );
setTexture( curActivityType, other->getTexture(curActivityType) );
}
setArmor( other->getArmor() );
setHealthRegen( other->getHealthRegen() );
setManaRegen( other->getManaRegen() );
setFatigueRegen( other->getFatigueRegen() );
setDamageModifierPoints( other->getDamageModifierPoints() );
setHitModifierPoints( other->getHitModifierPoints() );
setEvadeModifierPoints( other->getEvadeModifierPoints() );
setParryModifierPoints( other->getParryModifierPoints() );
setBlockModifierPoints( other->getBlockModifierPoints() );
setMeleeCriticalModifierPoints( other->getMeleeCriticalModifierPoints() );
setResistAllModifierPoints( other->getResistAllModifierPoints() );
setSpellEffectAllModifierPoints( other->getSpellEffectAllModifierPoints() );
for ( size_t curElement=0; curElement<static_cast<size_t>(ElementType::Count); ++curElement ) {
ElementType::ElementType curElementType = static_cast<ElementType::ElementType>(curElement);
setResistElementModifierPoints( curElementType, other->getResistElementModifierPoints( curElementType ) );
setSpellEffectElementModifierPoints( curElementType, other->getSpellEffectElementModifierPoints( curElementType ) );
}
setSpellCriticalModifierPoints( other->getSpellCriticalModifierPoints() );
setClass( other->getClass() );
setWanderRadius ( other->getWanderRadius() );
setName( other->getName() );
setLevel( other->getLevel() );
setLootTable( other->getLootTable() );
setBoundingBox( other->getBoundingBoxX(), other->getBoundingBoxY(), other->getBoundingBoxW(), other->getBoundingBoxH() );
setUseBoundingBox( other->getUseBoundingBox() );
setCoinDrop( other->minCoinDrop, other->maxCoinDrop, other->coinDropChance );
setSpellbook( other->getSpellbook() );
setExperienceValue( other->getExperienceValue() );
}
std::string CCharacter::getClassID() const
{
return classID;
}
const uint16_t NULLABLE_ATTRIBUTE_MIN = 0;
const uint16_t NON_NULLABLE_ATTRIBUTE_MIN = 1;
template <class AttributeType, class ModifierType>
AttributeType getModifiedAttributeValue( AttributeType attributeValue, ModifierType modifier,
AttributeType minValue = std::numeric_limits<AttributeType>::min(),
AttributeType maxValue = std::numeric_limits<AttributeType>::max() )
{
assert( attributeValue >= minValue && attributeValue <= maxValue );
// is modified value < minValue? => set to minValue
if ( modifier < 0 && static_cast<AttributeType>(-modifier) > attributeValue - minValue )
return minValue;
// is modified value > maxValue? => set to maxValue
else if ( modifier > 0 && (maxValue - attributeValue) < modifier )
return maxValue;
else
return (attributeValue + modifier);
}
CTexture* CCharacter::getPortraitTexture() const
{
return portrait;
}
CCharacter* CCharacter::getTarget() const
{
return target;
}
Attitude::Attitude CCharacter::getTargetAttitude()
{
return targetAttitude;
}
void CCharacter::setTarget( CCharacter *target )
{
this->target = target;
}
void CCharacter::setTarget( CCharacter *target, Attitude::Attitude attitude )
{
this->target = target;
targetAttitude = attitude;
}
std::string CCharacter::getName() const
{
return name;
}
void CCharacter::setName( std::string newName )
{
name = newName;
}
void CCharacter::setArmor( uint16_t newArmor )
{
armor = newArmor;
}
uint16_t CCharacter::getArmor() const
{
return armor;
}
uint16_t CCharacter::getModifiedArmor() const
{
return getArmor() + StatsSystem::getStatsSystem()->calculateDamageReductionPoints( this );
}
void CCharacter::modifyArmor( int16_t armorModifier )
{
setArmor( getModifiedAttributeValue( armor, armorModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setDamageModifierPoints( uint16_t newDamageModifierPoints )
{
damageModifierPoints = newDamageModifierPoints;
}
uint16_t CCharacter::getModifiedDamageModifierPoints() const
{
return getDamageModifierPoints() + StatsSystem::getStatsSystem()->calculateDamageModifierPoints( this );
}
uint16_t CCharacter::getDamageModifierPoints() const
{
return damageModifierPoints;
}
void CCharacter::modifyDamageModifierPoints( int16_t damageModifierPointsModifier )
{
setDamageModifierPoints( getModifiedAttributeValue( damageModifierPoints, damageModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setHitModifierPoints( uint16_t newHitModifierPoints )
{
hitModifierPoints = newHitModifierPoints;
}
uint16_t CCharacter::getModifiedHitModifierPoints() const
{
return getHitModifierPoints() + StatsSystem::getStatsSystem()->calculateHitModifierPoints( this );
}
uint16_t CCharacter::getHitModifierPoints() const
{
return hitModifierPoints;
}
void CCharacter::modifyHitModifierPoints( int16_t hitModifierPointsModifier )
{
setHitModifierPoints( getModifiedAttributeValue( hitModifierPoints, hitModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setEvadeModifierPoints( uint16_t newEvadeModifierPoints )
{
evadeModifierPoints = newEvadeModifierPoints;
}
uint16_t CCharacter::getModifiedEvadeModifierPoints() const
{
return getEvadeModifierPoints() + StatsSystem::getStatsSystem()->calculateEvadeModifierPoints( this );
}
uint16_t CCharacter::getEvadeModifierPoints() const
{
return evadeModifierPoints;
}
void CCharacter::modifyEvadeModifierPoints( int16_t evadeModifierPointsModifier )
{
setEvadeModifierPoints( getModifiedAttributeValue( evadeModifierPoints, evadeModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setParryModifierPoints( uint16_t newParryModifierPoints )
{
parryModifierPoints = newParryModifierPoints;
}
uint16_t CCharacter::getModifiedParryModifierPoints() const
{
return getParryModifierPoints() + StatsSystem::getStatsSystem()->calculateParryModifierPoints( this );
}
uint16_t CCharacter::getParryModifierPoints() const
{
return parryModifierPoints;
}
void CCharacter::modifyParryModifierPoints( int16_t parryModifierPointsModifier )
{
setParryModifierPoints( getModifiedAttributeValue( parryModifierPoints, parryModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setBlockModifierPoints( uint16_t newBlockModifierPoints )
{
blockModifierPoints = newBlockModifierPoints;
}
uint16_t CCharacter::getModifiedBlockModifierPoints() const
{
return getBlockModifierPoints() + StatsSystem::getStatsSystem()->calculateBlockModifierPoints( this );
}
uint16_t CCharacter::getBlockModifierPoints() const
{
return blockModifierPoints;
}
void CCharacter::modifyBlockModifierPoints( int16_t blockModifierPointsModifier )
{
setBlockModifierPoints( getModifiedAttributeValue( blockModifierPoints, blockModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setMeleeCriticalModifierPoints( uint16_t newMeleeCriticalModifierPoints )
{
meleeCriticalModifierPoints = newMeleeCriticalModifierPoints;
}
uint16_t CCharacter::getModifiedMeleeCriticalModifierPoints() const
{
return getMeleeCriticalModifierPoints() + StatsSystem::getStatsSystem()->calculateMeleeCriticalModifierPoints( this );
}
uint16_t CCharacter::getMeleeCriticalModifierPoints() const
{
return meleeCriticalModifierPoints;
}
void CCharacter::modifyMeleeCriticalModifierPoints( int16_t meleeCriticalModifierPointsModifier )
{
setMeleeCriticalModifierPoints( getModifiedAttributeValue( meleeCriticalModifierPoints, meleeCriticalModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setResistElementModifierPoints( ElementType::ElementType elementType, uint16_t newResistElementModifierPoints )
{
resistElementModifierPoints[ static_cast<size_t>(elementType) ] = newResistElementModifierPoints;
}
uint16_t CCharacter::getModifiedResistElementModifierPoints( ElementType::ElementType elementType ) const
{
return getResistElementModifierPoints( elementType ) + getResistAllModifierPoints() + StatsSystem::getStatsSystem()->calculateResistElementModifierPoints( elementType, this );
}
uint16_t CCharacter::getResistElementModifierPoints( ElementType::ElementType elementType ) const
{
return resistElementModifierPoints[ static_cast<size_t>(elementType) ];
}
void CCharacter::modifyResistElementModifierPoints( ElementType::ElementType elementType, int16_t resistElementModifierPointsModifier )
{
setResistElementModifierPoints( elementType, getModifiedAttributeValue( resistElementModifierPoints[ static_cast<size_t>(elementType) ], resistElementModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setResistAllModifierPoints( uint16_t newResistAllModifierPoints )
{
resistAllModifierPoints = newResistAllModifierPoints;
}
uint16_t CCharacter::getResistAllModifierPoints() const
{
return resistAllModifierPoints;
}
void CCharacter::modifyResistAllModifierPoints( int16_t resistAllModifierPointsModifier )
{
setResistAllModifierPoints( getModifiedAttributeValue( resistAllModifierPoints, resistAllModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setSpellEffectElementModifierPoints( ElementType::ElementType elementType, uint16_t newSpellEffectElementModifierPoints )
{
spellEffectElementModifierPoints[ static_cast<size_t>(elementType) ] = newSpellEffectElementModifierPoints;
}
uint16_t CCharacter::getModifiedSpellEffectElementModifierPoints( ElementType::ElementType elementType ) const
{
return getSpellEffectElementModifierPoints( elementType ) + getSpellEffectAllModifierPoints() + StatsSystem::getStatsSystem()->calculateSpellEffectElementModifierPoints( elementType, this );
}
uint16_t CCharacter::getSpellEffectElementModifierPoints( ElementType::ElementType elementType ) const
{
return spellEffectElementModifierPoints[ static_cast<size_t>(elementType) ];
}
void CCharacter::modifySpellEffectElementModifierPoints( ElementType::ElementType elementType, int16_t spellEffectElementModifierPointsModifier )
{
setSpellEffectElementModifierPoints( elementType, getModifiedAttributeValue( spellEffectElementModifierPoints[ static_cast<size_t>(elementType) ], spellEffectElementModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setSpellEffectAllModifierPoints( uint16_t newSpellEffectAllModifierPoints )
{
spellEffectAllModifierPoints = newSpellEffectAllModifierPoints;
}
uint16_t CCharacter::getSpellEffectAllModifierPoints() const
{
return spellEffectAllModifierPoints;
}
void CCharacter::modifySpellEffectAllModifierPoints( int16_t spellEffectAllModifierPointsModifier )
{
setSpellEffectAllModifierPoints( getModifiedAttributeValue( spellEffectAllModifierPoints, spellEffectAllModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setSpellCriticalModifierPoints( uint16_t newSpellCriticalModifierPoints )
{
spellCriticalModifierPoints = newSpellCriticalModifierPoints;
}
uint16_t CCharacter::getModifiedSpellCriticalModifierPoints() const
{
return getSpellCriticalModifierPoints() + StatsSystem::getStatsSystem()->calculateSpellCriticalModifierPoints( this );
}
uint16_t CCharacter::getSpellCriticalModifierPoints() const
{
return spellCriticalModifierPoints;
}
void CCharacter::modifySpellCriticalModifierPoints( int16_t spellCriticalModifierPointsModifier )
{
setSpellCriticalModifierPoints( getModifiedAttributeValue( spellCriticalModifierPoints, spellCriticalModifierPointsModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getStrength() const
{
return strength;
}
uint16_t CCharacter::getModifiedStrength() const
{
return getStrength();
}
void CCharacter::setStrength( uint16_t newStrength )
{
assert( newStrength >= NON_NULLABLE_ATTRIBUTE_MIN );
strength = newStrength;
}
void CCharacter::modifyStrength( int16_t strengthModifier )
{
setStrength( getModifiedAttributeValue( strength, strengthModifier, NON_NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getDexterity() const
{
return dexterity;
}
uint16_t CCharacter::getModifiedDexterity() const
{
return getDexterity();
}
void CCharacter::setDexterity( uint16_t newDexterity )
{
assert( newDexterity >= NON_NULLABLE_ATTRIBUTE_MIN );
dexterity = newDexterity;
}
void CCharacter::modifyDexterity( int16_t dexterityModifier )
{
setDexterity( getModifiedAttributeValue( dexterity, dexterityModifier, NON_NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getVitality() const
{
return vitality;
}
uint16_t CCharacter::getModifiedVitality() const
{
return getVitality();
}
void CCharacter::setVitality( uint16_t newVitality )
{
assert( newVitality >= NON_NULLABLE_ATTRIBUTE_MIN );
vitality = newVitality;
}
void CCharacter::modifyVitality( int16_t vitalityModifier )
{
setVitality( getModifiedAttributeValue( vitality, vitalityModifier, NON_NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getIntellect() const
{
return intellect;
}
uint16_t CCharacter::getModifiedIntellect() const
{
return getIntellect();
}
void CCharacter::setIntellect( uint16_t newIntellect )
{
assert( newIntellect >= NON_NULLABLE_ATTRIBUTE_MIN );
intellect = newIntellect;
}
void CCharacter::modifyIntellect( int16_t intellectModifier )
{
setIntellect( getModifiedAttributeValue( intellect, intellectModifier, NON_NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getWisdom() const
{
return wisdom;
}
uint16_t CCharacter::getModifiedWisdom() const
{
return getWisdom();
}
void CCharacter::setWisdom( uint16_t newWisdom )
{
assert( newWisdom >= NON_NULLABLE_ATTRIBUTE_MIN );
wisdom = newWisdom;
}
void CCharacter::modifyWisdom( int16_t wisdomModifier )
{
setWisdom( getModifiedAttributeValue( wisdom, wisdomModifier, NON_NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getMaxHealth() const
{
return max_health;
}
uint16_t CCharacter::getModifiedMaxHealth() const
{
return getMaxHealth();
}
void CCharacter::setMaxHealth( uint16_t newMaxHealth )
{
assert( newMaxHealth >= NON_NULLABLE_ATTRIBUTE_MIN );
max_health = newMaxHealth;
// if ( current_health > getModifiedMaxHealth() )
// {
current_health = getModifiedMaxHealth();
// }
}
void CCharacter::modifyMaxHealth( int16_t maxHealthModifier )
{
setMaxHealth( getModifiedAttributeValue( max_health, maxHealthModifier, NON_NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getCurrentHealth() const
{
if ( current_health > getModifiedMaxHealth() )
return getModifiedMaxHealth();
return current_health;
}
void CCharacter::setCurrentHealth( uint16_t newCurrentHealth )
{
assert( newCurrentHealth <= getModifiedMaxHealth() );
current_health = newCurrentHealth;
}
void CCharacter::modifyCurrentHealth( int16_t currentHealthModifier )
{
setCurrentHealth( getModifiedAttributeValue( getCurrentHealth(), currentHealthModifier, NULLABLE_ATTRIBUTE_MIN, getModifiedMaxHealth() ) );
}
uint16_t CCharacter::getMaxMana() const
{
return max_mana;
}
uint16_t CCharacter::getModifiedMaxMana() const
{
return getMaxMana();
}
void CCharacter::setMaxMana( uint16_t newMaxMana )
{
max_mana = newMaxMana;
// if ( current_mana > getModifiedMaxMana() )
// {
current_mana = getModifiedMaxMana();
// }
}
void CCharacter::modifyMaxMana( int16_t maxManaModifier )
{
setMaxMana( getModifiedAttributeValue( max_mana, maxManaModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getCurrentMana() const
{
if ( current_mana > getModifiedMaxMana() )
return getModifiedMaxMana();
return current_mana;
}
void CCharacter::setCurrentMana( uint16_t newCurrentMana )
{
assert( newCurrentMana <= getModifiedMaxMana() );
current_mana = newCurrentMana;
}
void CCharacter::modifyCurrentMana( int16_t currentManaModifier )
{
setCurrentMana( getModifiedAttributeValue( getCurrentMana(), currentManaModifier, NULLABLE_ATTRIBUTE_MIN, getModifiedMaxMana() ) );
}
uint16_t CCharacter::getMaxFatigue() const
{
return max_fatigue;
}
uint16_t CCharacter::getModifiedMaxFatigue() const
{
return getMaxFatigue();
}
void CCharacter::setMaxFatigue( uint16_t newMaxFatigue )
{
max_fatigue = newMaxFatigue;
// if ( current_fatigue > getModifiedMaxFatigue() )
// {
current_fatigue = getModifiedMaxFatigue();
// }
}
void CCharacter::modifyMaxFatigue( int16_t maxFatigueModifier )
{
setMaxFatigue( getModifiedAttributeValue( max_fatigue, maxFatigueModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
uint16_t CCharacter::getCurrentFatigue() const
{
if ( current_fatigue > getModifiedMaxFatigue() )
return getModifiedMaxFatigue();
return current_fatigue;
}
void CCharacter::setCurrentFatigue( uint16_t newCurrentFatigue )
{
assert( newCurrentFatigue <= getModifiedMaxFatigue() );
current_fatigue = newCurrentFatigue;
}
void CCharacter::modifyCurrentFatigue( int16_t currentFatigueModifier )
{
setCurrentFatigue( getModifiedAttributeValue( getCurrentFatigue(), currentFatigueModifier, NULLABLE_ATTRIBUTE_MIN, getModifiedMaxFatigue() ) );
}
void CCharacter::setManaRegen( uint16_t newManaRegen )
{
assert( newManaRegen >= NULLABLE_ATTRIBUTE_MIN );
manaRegen = newManaRegen;
}
uint16_t CCharacter::getModifiedManaRegen() const
{
return getManaRegen();
}
uint16_t CCharacter::getManaRegen() const
{
return manaRegen;
}
void CCharacter::modifyManaRegen( int16_t manaRegenModifier )
{
setManaRegen( getModifiedAttributeValue( manaRegen, manaRegenModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setFatigueRegen( uint16_t newFatigueRegen )
{
assert( newFatigueRegen >= NULLABLE_ATTRIBUTE_MIN );
fatigueRegen = newFatigueRegen;
}
uint16_t CCharacter::getModifiedFatigueRegen() const
{
return getFatigueRegen();
}
uint16_t CCharacter::getFatigueRegen() const
{
return fatigueRegen;
}
void CCharacter::modifyFatigueRegen( int16_t fatigueRegenModifier )
{
setFatigueRegen( getModifiedAttributeValue( fatigueRegen, fatigueRegenModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setHealthRegen( uint16_t newHealthRegen )
{
assert( newHealthRegen >= NULLABLE_ATTRIBUTE_MIN );
healthRegen = newHealthRegen;
}
uint16_t CCharacter::getModifiedHealthRegen() const
{
return getHealthRegen();
}
uint16_t CCharacter::getHealthRegen() const
{
return healthRegen;
}
void CCharacter::modifyHealthRegen( int16_t healthRegenModifier )
{
setHealthRegen( getModifiedAttributeValue( healthRegen, healthRegenModifier, NULLABLE_ATTRIBUTE_MIN ) );
}
void CCharacter::setMinDamage( uint16_t newMinDamage )
{
min_damage = newMinDamage;
}
uint16_t CCharacter::getMinDamage() const
{
return min_damage;
}
uint16_t CCharacter::getModifiedMinDamage() const
{
return getMinDamage();
}
void CCharacter::setMaxDamage( uint16_t newMaxDamage )
{
max_damage = newMaxDamage;
}
uint16_t CCharacter::getMaxDamage() const
{
return max_damage;
}
uint16_t CCharacter::getModifiedMaxDamage() const
{
return getMaxDamage();
}
void CCharacter::setExperienceValue( uint8_t experienceValue )
{
this->experienceValue = experienceValue;
}
uint8_t CCharacter::getExperienceValue() const
{
return experienceValue;
}
void CCharacter::addItemToLootTable(Item *item, double dropChance )
{
if ( item == NULL ) {
dawn_debug_fatal("CCharacter::addItemToLootTable() was called without a valid Item. Exiting!");
}
lootTable.push_back( sLootTable( item, dropChance ) );
}
void CCharacter::setExperience( uint64_t experience )
{
this->experience = experience;
}
uint64_t CCharacter::getExperience() const
{
return experience;
}
void CCharacter::gainExperience( uint64_t addExp )
{
if ( isPlayer() ) {
if ( std::numeric_limits<uint64_t>::max() - addExp < experience ) {
experience = std::numeric_limits<uint64_t>::max();
dawn_debug_warn( "max experience reached" );
} else {
experience += addExp;
GLfloat yellow[] = { 1.0f, 1.0f, 0.0f };
DawnInterface::addTextToLogWindow( yellow, "You gain %d experience.", addExp );
}
while ( canRaiseLevel() ) {
raiseLevel();
}
}
}
uint64_t CCharacter::getExpNeededForLevel( uint8_t level ) const
{
assert( level > 0 );
uint64_t result = (level*(level-1)* 50);
return result;
}
bool CCharacter::canRaiseLevel() const
{
return ( experience >= getExpNeededForLevel( getLevel() + 1 ) && ( getExpNeededForLevel( getLevel() + 1 ) != getExpNeededForLevel( getLevel() ) ) );
}
void CCharacter::raiseLevel()
{
if ( canRaiseLevel() ) {
setMaxHealth( getMaxHealth() * 1.1 );
setStrength( getStrength() * 1.1 );
setLevel( getLevel() + 1 );
GLfloat yellow[] = { 1.0f, 1.0f, 0.0f };
if ( isPlayer() == true )
{
dynamic_cast<Player*>(this)->setTicketForItemTooltip();
dynamic_cast<Player*>(this)->setTicketForSpellTooltip();
}
DawnInterface::addTextToLogWindow( yellow, "You are now a level %d %s.", getLevel(), getClassName().c_str() );
}
}
void CCharacter::setClass( CharacterClass::CharacterClass characterClass )
{
this->characterClass = characterClass;
switch ( characterClass )
{
/// all caster classes here...
case CharacterClass::Liche:
characterArchType = CharacterArchType::Caster;
break;
/// and all other fighter classes here...
case CharacterClass::Ranger:
case CharacterClass::Warrior:
characterArchType = CharacterArchType::Fighter;
break;
}
/// loading our portrait for the class
if ( portrait != NULL )
{
delete portrait;
}
portrait = new CTexture;
portrait->LoadIMG( CharacterClass::getCharacterClassPortrait( getClass() ), 0 );
}
CharacterClass::CharacterClass CCharacter::getClass() const
{
return characterClass;
}
CharacterArchType::CharacterArchType CCharacter::getArchType() const
{
return characterArchType;
}
std::string CCharacter::getClassName() const
{
return CharacterClass::getCharacterClassName( getClass() );
}
void CCharacter::setWanderRadius( uint16_t newWanderRadius )
{
wander_radius = newWanderRadius;
}
uint16_t CCharacter::getWanderRadius() const
{
return wander_radius;
}
void CCharacter::setLevel ( uint8_t newLevel )
{
assert( newLevel > 0 );
level = newLevel;
}
uint8_t CCharacter::getLevel() const
{
assert( level > 0 );
return level;
}
void CCharacter::setLootTable( std::vector<sLootTable> newLootTable )
{
lootTable = newLootTable;
}
std::vector<sLootTable> CCharacter::getLootTable() const
{
return lootTable;
}
void CCharacter::setTexture( ActivityType::ActivityType activity, CTexture *newTexture )
{
size_t activityNr = static_cast<size_t>( activity );
this->texture[ activityNr ] = newTexture;
}
CTexture* CCharacter::getTexture( ActivityType::ActivityType activity ) const
{
size_t activityNr = static_cast<size_t>( activity );
return this->texture[ activityNr ];
}
void CCharacter::setNumMoveTexturesPerDirection( ActivityType::ActivityType activity, int numTextures )
{
size_t activityNr = static_cast<size_t>(activity);
numMoveTexturesPerDirection[ activityNr ] = numTextures;
assert( texture[ activityNr ] == NULL );
texture[ activityNr ] = new CTexture();
}
void CCharacter::setMoveTexture( ActivityType::ActivityType activity, int direction, int index, std::string filename, int textureOffsetX, int textureOffsetY )
{
size_t activityNr = static_cast<size_t>(activity);
assert( texture[activityNr] != NULL );
assert( index < numMoveTexturesPerDirection[activityNr] );
texture[ activityNr ]->LoadIMG( filename, direction + 8*index, false, textureOffsetX, textureOffsetY );
}
// end of Dawn LUA Interface
CCharacter::CCharacter()
: strength( 1 ),
dexterity( 1 ),
vitality( 1 ),
intellect( 1 ),
wisdom( 1 ),
max_health( 1 ),
current_health( 1 ),
max_mana( 0 ),
current_mana( 0 ),
healthRegen( 0 ),
manaRegen( 0 ),
armor( 0 ),
damageModifierPoints( 0 ),
hitModifierPoints( 0 ),
evadeModifierPoints( 0 ),
blockModifierPoints( 0 ),
meleeCriticalModifierPoints( 0 ),
resistElementModifierPoints( NULL ),
resistAllModifierPoints( 0 ),
spellEffectElementModifierPoints( NULL ),
spellEffectAllModifierPoints( 0 ),
spellCriticalModifierPoints( 0 ),
experienceValue( 0 ),
level( 1 ),
boundingBoxX( 0 ),
boundingBoxY( 0 ),
boundingBoxW( 0 ),
boundingBoxH( 0 ),
useBoundingBox( false ),
minCoinDrop( 0 ),
maxCoinDrop( 0 ),
coinDropChance( 0.0 ),
portrait( NULL )
{
resistElementModifierPoints = new uint16_t[ static_cast<size_t>( ElementType::Count ) ];
spellEffectElementModifierPoints = new uint16_t[ static_cast<size_t>( ElementType::Count ) ];
for ( size_t curElement=0; curElement<static_cast<size_t>( ElementType::Count ); ++curElement ) {
resistElementModifierPoints[ curElement ] = 0;
spellEffectElementModifierPoints[ curElement ] = 0;
}
size_t numActivities = static_cast<size_t>( ActivityType::Count );
numMoveTexturesPerDirection = new int[ numActivities ];
texture = new CTexture* [ numActivities ];
for ( size_t curActivity=0; curActivity<numActivities; ++curActivity ) {
numMoveTexturesPerDirection[ curActivity ] = 0;
texture[ curActivity ] = NULL;
}
activeDirection = S;
}
CCharacter::~CCharacter()
{
if ( isPreparing ) {
// note: if the current spell / action is not null this means
// it is still bound to the player. He alone is responsible
// for it.
delete curSpellAction;
}
size_t numActivities = static_cast<size_t>( ActivityType::Count );
for ( size_t curActivity=0; curActivity<numActivities; ++curActivity ) {
if ( texture[ curActivity ] != NULL ) {
delete texture[ curActivity ];
}
}
delete[] numMoveTexturesPerDirection;
delete[] texture;
}
int CCharacter::getXPos() const
{
You can’t perform that action at this time.
