-
Notifications
You must be signed in to change notification settings - Fork 21
/
condition.cpp
1950 lines (1607 loc) · 41.9 KB
/
condition.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
//////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// 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 2
// 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, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#include "otpch.h"
#include "condition.h"
#include "game.h"
#include "creature.h"
#include "tools.h"
#include "combat.h"
#include <utility>
extern Game g_game;
Condition::Condition(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff, uint32_t _subId) :
id(_id),
subId(_subId),
ticks(_ticks),
endTime(0),
conditionType(_type),
isBuff(_buff)
{
//
}
bool Condition::setParam(ConditionParam_t param, int32_t value)
{
switch(param)
{
case CONDITIONPARAM_TICKS:
{
ticks = value;
return true;
}
case CONDITIONPARAM_BUFF_SPELL:
{
isBuff = (value != 0);
return true;
}
case CONDITIONPARAM_SUBID:
{
subId = value;
return true;
}
default:
{
return false;
}
}
return false;
}
bool Condition::unserialize(PropStream& propStream)
{
uint8_t attr_type;
while(propStream.GET_UCHAR(attr_type) && attr_type != CONDITIONATTR_END)
{
if(!unserializeProp((ConditionAttr_t)attr_type, propStream))
return false;
}
return true;
}
bool Condition::unserializeProp(ConditionAttr_t attr, PropStream& propStream)
{
switch(attr)
{
case CONDITIONATTR_TYPE:
{
int32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
conditionType = (ConditionType_t)value;
return true;
}
case CONDITIONATTR_ID:
{
int32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
id = (ConditionId_t)value;
return true;
}
case CONDITIONATTR_TICKS:
{
int32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
ticks = value;
return true;
}
case CONDITIONATTR_ISBUFF:
{
int8_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
isBuff = value != 0;
return true;
}
case CONDITIONATTR_SUBID:
{
int32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
subId = value;
return true;
}
case CONDITIONATTR_END:
return true;
default:
return false;
}
}
bool Condition::serialize(PropWriteStream& propWriteStream)
{
propWriteStream.ADD_UCHAR(CONDITIONATTR_TYPE);
propWriteStream.ADD_VALUE((int32_t)conditionType);
propWriteStream.ADD_UCHAR(CONDITIONATTR_ID);
propWriteStream.ADD_VALUE((int32_t)id);
propWriteStream.ADD_UCHAR(CONDITIONATTR_TICKS);
propWriteStream.ADD_VALUE((int32_t)ticks);
propWriteStream.ADD_UCHAR(CONDITIONATTR_ISBUFF);
propWriteStream.ADD_VALUE((int8_t)isBuff);
propWriteStream.ADD_UCHAR(CONDITIONATTR_SUBID);
propWriteStream.ADD_VALUE((int32_t)subId);
return true;
}
void Condition::setTicks(int32_t newTicks)
{
ticks = newTicks;
endTime = ticks + OTSYS_TIME();
}
bool Condition::executeCondition(Creature* creature, int32_t interval)
{
if(ticks == -1)
return true;
int32_t newTicks = std::max<int32_t>(0, getTicks() - interval);
//Not using set ticks here since it would reset endTime
ticks = newTicks;
return getEndTime() >= OTSYS_TIME();
}
Condition* Condition::createCondition(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, int32_t param/* = 0*/, bool _buff/* = false*/, uint32_t _subId/* = 0*/)
{
switch((int32_t)_type)
{
case CONDITION_POISON:
case CONDITION_FIRE:
case CONDITION_ENERGY:
case CONDITION_DROWN:
case CONDITION_FREEZING:
case CONDITION_DAZZLED:
case CONDITION_CURSED:
case CONDITION_BLEEDING:
return new ConditionDamage(_id, _type, _buff, _subId);
case CONDITION_HASTE:
case CONDITION_PARALYZE:
return new ConditionSpeed(_id, _type, _ticks, _buff, _subId, param);
case CONDITION_INVISIBLE:
return new ConditionInvisible(_id, _type, _ticks, _buff, _subId);
case CONDITION_OUTFIT:
return new ConditionOutfit(_id, _type, _ticks, _buff, _subId);
case CONDITION_LIGHT:
return new ConditionLight(_id, _type, _ticks, _buff, _subId, param & 0xFF, (param & 0xFF00) >> 8);
case CONDITION_REGENERATION:
return new ConditionRegeneration(_id, _type, _ticks, _buff, _subId);
case CONDITION_SOUL:
return new ConditionSoul(_id, _type, _ticks, _buff, _subId);
case CONDITION_MANASHIELD:
return new ConditionManaShield(_id, _type, _ticks, _buff, _subId);
case CONDITION_ATTRIBUTES:
return new ConditionAttributes(_id, _type, _ticks, _buff, _subId);
case CONDITION_SPELLCOOLDOWN:
return new ConditionSpellCooldown(_id, _type, _ticks, _buff, _subId);
case CONDITION_SPELLGROUPCOOLDOWN:
return new ConditionSpellGroupCooldown(_id, _type, _ticks, _buff, _subId);
case CONDITION_INFIGHT:
case CONDITION_DRUNK:
case CONDITION_EXHAUST_WEAPON:
case CONDITION_EXHAUST_COMBAT:
case CONDITION_EXHAUST_HEAL:
case CONDITION_MUTED:
case CONDITION_ADVERTISINGTICKS:
case CONDITION_YELLTICKS:
case CONDITION_PACIFIED:
return new ConditionGeneric(_id, _type, _ticks, _buff, _subId);
default:
return NULL;
}
}
Condition* Condition::createCondition(PropStream& propStream)
{
uint8_t attr;
if(!propStream.GET_UCHAR(attr) || attr != CONDITIONATTR_TYPE)
return NULL;
uint32_t _type = 0;
if(!propStream.GET_ULONG(_type))
return NULL;
if(!propStream.GET_UCHAR(attr) || attr != CONDITIONATTR_ID)
return NULL;
uint32_t _id = 0;
if(!propStream.GET_ULONG(_id))
return NULL;
if(!propStream.GET_UCHAR(attr) || attr != CONDITIONATTR_TICKS)
return NULL;
uint32_t _ticks = 0;
if(!propStream.GET_ULONG(_ticks))
return NULL;
if(!propStream.GET_UCHAR(attr) || attr != CONDITIONATTR_ISBUFF)
return NULL;
uint8_t _buff = 0;
if(!propStream.GET_UCHAR(_buff))
return NULL;
if(!propStream.GET_UCHAR(attr) || attr != CONDITIONATTR_SUBID)
return NULL;
uint32_t _subId = 0;
if(!propStream.GET_ULONG(_subId))
return NULL;
return createCondition((ConditionId_t)_id, (ConditionType_t)_type, _ticks, 0, _buff != 0, _subId);
}
bool Condition::startCondition(Creature* creature)
{
if(getTicks() > 0)
endTime = getTicks() + OTSYS_TIME();
return true;
}
bool Condition::isPersistent() const
{
if(ticks == -1)
return false;
if(!(id == CONDITIONID_DEFAULT || id == CONDITIONID_COMBAT))
return false;
return true;
}
uint32_t Condition::getIcons() const
{
return isBuff ? ICON_PARTY_BUFF : 0;
}
bool Condition::updateCondition(const Condition* addCondition)
{
if(conditionType != addCondition->getType())
return false;
if(getTicks() == -1 && addCondition->getTicks() > 0)
return false;
if(addCondition->getTicks() >= 0 && getEndTime() > (OTSYS_TIME() + addCondition->getTicks()))
return false;
return true;
}
ConditionGeneric::ConditionGeneric(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff, uint32_t _subId) :
Condition(_id, _type, _ticks, _buff, _subId)
{
//
}
bool ConditionGeneric::startCondition(Creature* creature)
{
return Condition::startCondition(creature);
}
bool ConditionGeneric::executeCondition(Creature* creature, int32_t interval)
{
return Condition::executeCondition(creature, interval);
}
void ConditionGeneric::endCondition(Creature* creature, ConditionEnd_t reason)
{
//
}
void ConditionGeneric::addCondition(Creature* creature, const Condition* addCondition)
{
if(updateCondition(addCondition))
setTicks(addCondition->getTicks());
}
uint32_t ConditionGeneric::getIcons() const
{
uint32_t icons = Condition::getIcons();
switch(conditionType)
{
case CONDITION_MANASHIELD:
icons |= ICON_MANASHIELD;
break;
case CONDITION_INFIGHT:
icons |= ICON_SWORDS;
break;
case CONDITION_DRUNK:
icons |= ICON_DRUNK;
break;
default:
break;
}
return icons;
}
ConditionAttributes::ConditionAttributes(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff, uint32_t _subId) :
ConditionGeneric(_id, _type, _ticks, _buff, _subId)
{
currentSkill = 0;
currentStat = 0;
memset(skills, 0, sizeof(skills));
memset(skillsPercent, 0, sizeof(skillsPercent));
memset(stats, 0, sizeof(stats));
memset(statsPercent, 0, sizeof(statsPercent));
}
void ConditionAttributes::addCondition(Creature* creature, const Condition* addCondition)
{
if(updateCondition(addCondition))
{
setTicks(addCondition->getTicks());
const ConditionAttributes& conditionAttrs = static_cast<const ConditionAttributes&>(*addCondition);
//Remove the old condition
endCondition(creature, CONDITIONEND_ABORT);
//Apply the new one
memcpy(skills, conditionAttrs.skills, sizeof(skills));
memcpy(skillsPercent, conditionAttrs.skillsPercent, sizeof(skillsPercent));
memcpy(stats, conditionAttrs.stats, sizeof(stats));
memcpy(statsPercent, conditionAttrs.statsPercent, sizeof(statsPercent));
if(Player* player = creature->getPlayer())
{
updatePercentSkills(player);
updateSkills(player);
updatePercentStats(player);
updateStats(player);
}
}
}
bool ConditionAttributes::unserializeProp(ConditionAttr_t attr, PropStream& propStream)
{
if(attr == CONDITIONATTR_SKILLS)
{
int32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
skills[currentSkill] = value;
++currentSkill;
return true;
}
else if(attr == CONDITIONATTR_STATS)
{
int32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
stats[currentStat] = value;
++currentStat;
return true;
}
return Condition::unserializeProp(attr, propStream);
}
bool ConditionAttributes::serialize(PropWriteStream& propWriteStream)
{
if(!Condition::serialize(propWriteStream))
return false;
for(int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i)
{
propWriteStream.ADD_UCHAR(CONDITIONATTR_SKILLS);
propWriteStream.ADD_VALUE(skills[i]);
}
for(int32_t i = STAT_FIRST; i <= STAT_LAST; ++i)
{
propWriteStream.ADD_UCHAR(CONDITIONATTR_STATS);
propWriteStream.ADD_VALUE(stats[i]);
}
return true;
}
bool ConditionAttributes::startCondition(Creature* creature)
{
if(!Condition::startCondition(creature))
return false;
if(Player* player = creature->getPlayer())
{
updatePercentSkills(player);
updateSkills(player);
updatePercentStats(player);
updateStats(player);
}
return true;
}
void ConditionAttributes::updatePercentStats(Player* player)
{
for(int32_t i = STAT_FIRST; i <= STAT_LAST; ++i)
{
if(statsPercent[i] == 0)
continue;
switch(i)
{
case STAT_MAXHITPOINTS:
stats[i] = (int32_t)(player->getMaxHealth() * ((statsPercent[i] - 100) / 100.f));
break;
case STAT_MAXMANAPOINTS:
stats[i] = (int32_t)(player->getMaxMana() * ((statsPercent[i] - 100) / 100.f));
break;
case STAT_SOULPOINTS:
stats[i] = (int32_t)(player->getPlayerInfo(PLAYERINFO_SOUL) * ((statsPercent[i] - 100) / 100.f));
break;
case STAT_MAGICPOINTS:
stats[i] = (int32_t)(player->getMagicLevel() * ((statsPercent[i] - 100) / 100.f));
break;
}
}
}
void ConditionAttributes::updateStats(Player* player)
{
bool needUpdateStats = false;
for(int32_t i = STAT_FIRST; i <= STAT_LAST; ++i)
{
if(stats[i])
{
needUpdateStats = true;
player->setVarStats((stats_t)i, stats[i]);
}
}
if(needUpdateStats)
player->sendStats();
}
void ConditionAttributes::updatePercentSkills(Player* player)
{
for(int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i)
{
if(skillsPercent[i] == 0)
continue;
int32_t currSkill = player->getSkill((skills_t)i, SKILL_LEVEL);
skills[i] = (int32_t)(currSkill * ((skillsPercent[i] - 100) / 100.f));
}
}
void ConditionAttributes::updateSkills(Player* player)
{
bool needUpdateSkills = false;
for(int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i)
{
if(skills[i])
{
needUpdateSkills = true;
player->setVarSkill((skills_t)i, skills[i]);
}
}
if(needUpdateSkills)
player->sendSkills();
}
bool ConditionAttributes::executeCondition(Creature* creature, int32_t interval)
{
return ConditionGeneric::executeCondition(creature, interval);
}
void ConditionAttributes::endCondition(Creature* creature, ConditionEnd_t reason)
{
Player* player = creature->getPlayer();
if(player)
{
bool needUpdateSkills = false;
for(int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i)
{
if(skills[i] || skillsPercent[i])
{
needUpdateSkills = true;
const int new_skill = skills[i];
player->setVarSkill((skills_t)i, -new_skill);
}
}
if(needUpdateSkills)
player->sendSkills();
bool needUpdateStats = false;
for(int32_t i = STAT_FIRST; i <= STAT_LAST; ++i)
{
if(stats[i])
{
needUpdateStats = true;
player->setVarStats((stats_t)i, -stats[i]);
}
}
if(needUpdateStats)
player->sendStats();
}
}
bool ConditionAttributes::setParam(ConditionParam_t param, int32_t value)
{
bool ret = ConditionGeneric::setParam(param, value);
switch(param)
{
case CONDITIONPARAM_SKILL_MELEE:
{
skills[SKILL_CLUB] = value;
skills[SKILL_AXE] = value;
skills[SKILL_SWORD] = value;
return true;
}
case CONDITIONPARAM_SKILL_MELEEPERCENT:
{
skillsPercent[SKILL_CLUB] = value;
skillsPercent[SKILL_AXE] = value;
skillsPercent[SKILL_SWORD] = value;
return true;
}
case CONDITIONPARAM_SKILL_FIST:
{
skills[SKILL_FIST] = value;
return true;
}
case CONDITIONPARAM_SKILL_FISTPERCENT:
{
skillsPercent[SKILL_FIST] = value;
return true;
}
case CONDITIONPARAM_SKILL_CLUB:
{
skills[SKILL_CLUB] = value;
return true;
}
case CONDITIONPARAM_SKILL_CLUBPERCENT:
{
skillsPercent[SKILL_CLUB] = value;
return true;
}
case CONDITIONPARAM_SKILL_SWORD:
{
skills[SKILL_SWORD] = value;
return true;
}
case CONDITIONPARAM_SKILL_SWORDPERCENT:
{
skillsPercent[SKILL_SWORD] = value;
return true;
}
case CONDITIONPARAM_SKILL_AXE:
{
skills[SKILL_AXE] = value;
return true;
}
case CONDITIONPARAM_SKILL_AXEPERCENT:
{
skillsPercent[SKILL_AXE] = value;
return true;
}
case CONDITIONPARAM_SKILL_DISTANCE:
{
skills[SKILL_DIST] = value;
return true;
}
case CONDITIONPARAM_SKILL_DISTANCEPERCENT:
{
skillsPercent[SKILL_DIST] = value;
return true;
}
case CONDITIONPARAM_SKILL_SHIELD:
{
skills[SKILL_SHIELD] = value;
return true;
}
case CONDITIONPARAM_SKILL_SHIELDPERCENT:
{
skillsPercent[SKILL_SHIELD] = value;
return true;
}
case CONDITIONPARAM_SKILL_FISHING:
{
skills[SKILL_FISH] = value;
return true;
}
case CONDITIONPARAM_SKILL_FISHINGPERCENT:
{
skillsPercent[SKILL_FISH] = value;
return true;
}
case CONDITIONPARAM_STAT_MAXHITPOINTS:
{
stats[STAT_MAXHITPOINTS] = value;
return true;
}
case CONDITIONPARAM_STAT_MAXMANAPOINTS:
{
stats[STAT_MAXMANAPOINTS] = value;
return true;
}
case CONDITIONPARAM_STAT_SOULPOINTS:
{
stats[STAT_SOULPOINTS] = value;
return true;
}
case CONDITIONPARAM_STAT_MAGICPOINTS:
{
stats[STAT_MAGICPOINTS] = value;
return true;
}
case CONDITIONPARAM_STAT_MAXHITPOINTSPERCENT:
{
if(value < 0)
value = 0;
statsPercent[STAT_MAXHITPOINTS] = value;
return true;
}
case CONDITIONPARAM_STAT_MAXMANAPOINTSPERCENT:
{
if(value < 0)
value = 0;
statsPercent[STAT_MAXMANAPOINTS] = value;
return true;
}
case CONDITIONPARAM_STAT_SOULPOINTSPERCENT:
{
if(value < 0)
value = 0;
statsPercent[STAT_SOULPOINTS] = value;
return true;
}
case CONDITIONPARAM_STAT_MAGICPOINTSPERCENT:
{
if(value < 0)
value = 0;
statsPercent[STAT_MAGICPOINTS] = value;
return true;
}
default:
return false;
}
return ret;
}
ConditionRegeneration::ConditionRegeneration(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff, uint32_t _subId) :
ConditionGeneric(_id, _type, _ticks, _buff, _subId)
{
internalHealthTicks = 0;
internalManaTicks = 0;
healthTicks = 1000;
manaTicks = 1000;
healthGain = 0;
manaGain = 0;
}
void ConditionRegeneration::addCondition(Creature* creature, const Condition* addCondition)
{
if(updateCondition(addCondition))
{
setTicks(addCondition->getTicks());
const ConditionRegeneration& conditionRegen = static_cast<const ConditionRegeneration&>(*addCondition);
healthTicks = conditionRegen.healthTicks;
manaTicks = conditionRegen.manaTicks;
healthGain = conditionRegen.healthGain;
manaGain = conditionRegen.manaGain;
}
}
bool ConditionRegeneration::unserializeProp(ConditionAttr_t attr, PropStream& propStream)
{
if(attr == CONDITIONATTR_HEALTHTICKS)
{
uint32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
healthTicks = value;
return true;
}
else if(attr == CONDITIONATTR_HEALTHGAIN)
{
uint32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
healthGain = value;
return true;
}
else if(attr == CONDITIONATTR_MANATICKS)
{
uint32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
manaTicks = value;
return true;
}
else if(attr == CONDITIONATTR_MANAGAIN)
{
uint32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
manaGain = value;
return true;
}
return Condition::unserializeProp(attr, propStream);
}
bool ConditionRegeneration::serialize(PropWriteStream& propWriteStream)
{
if(!Condition::serialize(propWriteStream))
return false;
propWriteStream.ADD_UCHAR(CONDITIONATTR_HEALTHTICKS);
propWriteStream.ADD_VALUE(healthTicks);
propWriteStream.ADD_UCHAR(CONDITIONATTR_HEALTHGAIN);
propWriteStream.ADD_VALUE(healthGain);
propWriteStream.ADD_UCHAR(CONDITIONATTR_MANATICKS);
propWriteStream.ADD_VALUE(manaTicks);
propWriteStream.ADD_UCHAR(CONDITIONATTR_MANAGAIN);
propWriteStream.ADD_VALUE(manaGain);
return true;
}
bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interval)
{
internalHealthTicks += interval;
internalManaTicks += interval;
if(creature->getZone() != ZONE_PROTECTION)
{
if(internalHealthTicks >= healthTicks)
{
internalHealthTicks = 0;
int32_t realHealthGain = creature->getHealth();
creature->changeHealth(healthGain);
realHealthGain = creature->getHealth() - realHealthGain;
if(isBuff && realHealthGain > 0)
{
Player* player = creature->getPlayer();
if(player)
{
std::ostringstream ss;
ss << ucfirst(player->getNameDescription()) << " was healed for " << realHealthGain << " hitpoint" << (realHealthGain != 1 ? "s." : ".");
std::string message = ss.str();
std::ostringstream tmpSs;
tmpSs << "You were healed for " << realHealthGain << " hitpoint" << (realHealthGain != 1 ? "s." : ".");
player->sendHealMessage(MSG_HEALED, tmpSs.str(), player->getPosition(), realHealthGain, TEXTCOLOR_MAYABLUE);
SpectatorVec list;
g_game.getSpectators(list, player->getPosition(), false, true);
for(SpectatorVec::const_iterator it = list.begin(), end = list.end(); it != end; ++it)
{
Player* tmpPlayer = (*it)->getPlayer();
if(tmpPlayer != player)
tmpPlayer->sendHealMessage(MSG_HEALED_OTHERS, message, player->getPosition(), realHealthGain, TEXTCOLOR_MAYABLUE);
}
}
}
}
if(internalManaTicks >= manaTicks)
{
internalManaTicks = 0;
creature->changeMana(manaGain);
}
}
return ConditionGeneric::executeCondition(creature, interval);
}
bool ConditionRegeneration::setParam(ConditionParam_t param, int32_t value)
{
bool ret = ConditionGeneric::setParam(param, value);
switch(param)
{
case CONDITIONPARAM_HEALTHGAIN:
healthGain = value;
return true;
case CONDITIONPARAM_HEALTHTICKS:
healthTicks = value;
return true;
case CONDITIONPARAM_MANAGAIN:
manaGain = value;
return true;
case CONDITIONPARAM_MANATICKS:
manaTicks = value;
return true;
default:
return false;
}
return ret;
}
ConditionSoul::ConditionSoul(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, bool _buff, uint32_t _subId) :
ConditionGeneric(_id, _type, _ticks, _buff, _subId)
{
internalSoulTicks = 0;
soulTicks = 0;
soulGain = 0;
}
void ConditionSoul::addCondition(Creature* creature, const Condition* addCondition)
{
if(updateCondition(addCondition))
{
setTicks(addCondition->getTicks());
const ConditionSoul& conditionSoul = static_cast<const ConditionSoul&>(*addCondition);
soulTicks = conditionSoul.soulTicks;
soulGain = conditionSoul.soulGain;
}
}
bool ConditionSoul::unserializeProp(ConditionAttr_t attr, PropStream& propStream)
{
if(attr == CONDITIONATTR_SOULGAIN)
{
uint32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
soulGain = value;
return true;
}
else if(attr == CONDITIONATTR_SOULTICKS)
{
uint32_t value = 0;
if(!propStream.GET_VALUE(value))
return false;
soulTicks = value;
return true;
}
return Condition::unserializeProp(attr, propStream);
}
bool ConditionSoul::serialize(PropWriteStream& propWriteStream)
{
if(!Condition::serialize(propWriteStream))
return false;
propWriteStream.ADD_UCHAR(CONDITIONATTR_SOULGAIN);
propWriteStream.ADD_VALUE(soulGain);
propWriteStream.ADD_UCHAR(CONDITIONATTR_SOULTICKS);
propWriteStream.ADD_VALUE(soulTicks);
return true;
}
bool ConditionSoul::executeCondition(Creature* creature, int32_t interval)
{
internalSoulTicks += interval;
if(Player* player = creature->getPlayer())
{
if(player->getZone() != ZONE_PROTECTION)
{
if(internalSoulTicks >= soulTicks)
{
internalSoulTicks = 0;
player->changeSoul(soulGain);
}
}
}
return ConditionGeneric::executeCondition(creature, interval);
}
bool ConditionSoul::setParam(ConditionParam_t param, int32_t value)
{
bool ret = ConditionGeneric::setParam(param, value);