-
Notifications
You must be signed in to change notification settings - Fork 757
/
status.c
14615 lines (13341 loc) · 448 KB
/
status.c
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
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2012-2024 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules 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/>.
*/
#define HERCULES_CORE
#include "config/core.h" // ANTI_MAYAP_CHEAT, DBPATH, DEFTYPE_MAX, DEFTYPE_MIN, DEVOTION_REFLECT_DAMAGE, RENEWAL, RENEWAL_ASPD, RENEWAL_EDP
#include "status.h"
#include "map/battle.h"
#include "map/chrif.h"
#include "map/clan.h"
#include "map/clif.h"
#include "map/elemental.h"
#include "map/guild.h"
#include "map/homunculus.h"
#include "map/itemdb.h"
#include "map/map.h"
#include "map/mercenary.h"
#include "map/mob.h"
#include "map/npc.h"
#include "map/path.h"
#include "map/pc.h"
#include "map/pet.h"
#include "map/refine.h"
#include "map/script.h"
#include "map/skill.h"
#include "map/skill.h"
#include "map/unit.h"
#include "map/vending.h"
#include "common/cbasetypes.h"
#include "common/ers.h"
#include "common/memmgr.h"
#include "common/msgtable.h"
#include "common/nullpo.h"
#include "common/random.h"
#include "common/showmsg.h"
#include "common/strlib.h"
#include "common/timer.h"
#include "common/utils.h"
#include "common/conf.h"
#include <math.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
static struct status_interface status_s;
static struct s_status_dbs statusdbs;
struct status_interface *status;
/**
* Returns the FIRST skill (in order of definition in initChangeTables) to use a given status change.
* Utilized for various duration lookups. Use with caution!
* @param sc The status to look up
* @return A skill associated with the status
*/
static int status_sc2skill(sc_type sc)
{
if( sc < 0 || sc >= SC_MAX ) {
ShowError("status_sc2skill: Unsupported status change id %d\n", sc);
return 0;
}
return status->dbs->SkillChangeTable[sc];
}
/**
* Returns the status calculation flag associated with a given status change.
* @param sc The status to look up
* @return The scb_flag registered for this status (see enum scb_flag)
*/
static unsigned int status_sc2scb_flag(sc_type sc)
{
if( sc < 0 || sc >= SC_MAX ) {
ShowError("status_sc2scb_flag: Unsupported status change id %d\n", sc);
return SCB_NONE;
}
return status->dbs->ChangeFlagTable[sc];
}
/**
* Returns the bl types which require a status change packet to be sent for a given client status identifier.
* @param type status identifier to look up (see enum sc_type)
* @return The bl types relevant to the type (see enum bl_type)
*/
static int status_get_sc_relevant_bl_types(enum sc_type type)
{
if (type < 0 || type >= SC_MAX) {
ShowError("status_get_sc_relevant_bl_types: Unsupported type %d\n", type);
return BL_NUL;
}
return status->dbs->IconChangeTable[type].relevant_bl_types;
}
static int status_get_sc_icon(enum sc_type type)
{
Assert_retr(SI_BLANK, type >= SC_NONE && type < SC_MAX);
return status->dbs->IconChangeTable[type].id;
}
static void initChangeTables(void)
{
int i;
for (i = 0; i < SC_MAX; i++) {
status->dbs->IconChangeTable[i].id = SI_BLANK;
status->dbs->IconChangeTable[i].relevant_bl_types = BL_PC;
}
memset(status->dbs->SkillChangeTable, 0, sizeof(status->dbs->SkillChangeTable));
memset(status->dbs->ChangeFlagTable, 0, sizeof(status->dbs->ChangeFlagTable));
memset(status->dbs->DisplayType, 0, sizeof(status->dbs->DisplayType));
// Storing the target job rather than simply SC_SOULLINK simplifies code later on.
skill->dbs->db[skill->get_index(SL_ALCHEMIST)].status_type = (sc_type)MAPID_ALCHEMIST;
skill->dbs->db[skill->get_index(SL_MONK)].status_type = (sc_type)MAPID_MONK;
skill->dbs->db[skill->get_index(SL_STAR)].status_type = (sc_type)MAPID_STAR_GLADIATOR;
skill->dbs->db[skill->get_index(SL_SAGE)].status_type = (sc_type)MAPID_SAGE;
skill->dbs->db[skill->get_index(SL_CRUSADER)].status_type = (sc_type)MAPID_CRUSADER;
skill->dbs->db[skill->get_index(SL_SUPERNOVICE)].status_type = (sc_type)MAPID_SUPER_NOVICE;
skill->dbs->db[skill->get_index(SL_KNIGHT)].status_type = (sc_type)MAPID_KNIGHT;
skill->dbs->db[skill->get_index(SL_WIZARD)].status_type = (sc_type)MAPID_WIZARD;
skill->dbs->db[skill->get_index(SL_PRIEST)].status_type = (sc_type)MAPID_PRIEST;
skill->dbs->db[skill->get_index(SL_BARDDANCER)].status_type = (sc_type)MAPID_BARDDANCER;
skill->dbs->db[skill->get_index(SL_ROGUE)].status_type = (sc_type)MAPID_ROGUE;
skill->dbs->db[skill->get_index(SL_ASSASIN)].status_type = (sc_type)MAPID_ASSASSIN;
skill->dbs->db[skill->get_index(SL_BLACKSMITH)].status_type = (sc_type)MAPID_BLACKSMITH;
skill->dbs->db[skill->get_index(SL_HUNTER)].status_type = (sc_type)MAPID_HUNTER;
skill->dbs->db[skill->get_index(SL_SOULLINKER)].status_type = (sc_type)MAPID_SOUL_LINKER;
#undef set_sc_with_vfx
}
static void initDummyData(void)
{
memset(&status->dummy, 0, sizeof(status->dummy));
status->dummy.hp =
status->dummy.max_hp =
status->dummy.max_sp =
status->dummy.str =
status->dummy.agi =
status->dummy.vit =
status->dummy.int_ =
status->dummy.dex =
status->dummy.luk =
status->dummy.hit = 1;
status->dummy.speed = 2000;
status->dummy.adelay = 4000;
status->dummy.amotion = 2000;
status->dummy.dmotion = 2000;
status->dummy.ele_lv = 1; //Min elemental level.
status->dummy.mode = MD_CANMOVE;
memset(&status->dummy_unit_params, 0, sizeof(status->dummy_unit_params));
strcpy(status->dummy_unit_params.name, "");
status->dummy_unit_params.natural_heal_weight_rate = 50;
status->dummy_unit_params.max_aspd = battle_config.max_aspd;
CREATE(status->dummy_unit_params.maxhp, struct s_maxhp_entry, 1);
status->dummy_unit_params.maxhp[0].max_level = MAX_LEVEL;
status->dummy_unit_params.maxhp[0].value = 1;
status->dummy_unit_params.maxhp_size = 1;
status->dummy_unit_params.max_stats = 99;
}
//For copying a status_data structure from b to a, without overwriting current Hp and Sp
static void status_copy(struct status_data *a, const struct status_data *b)
{
nullpo_retv(a);
nullpo_retv(b);
memcpy((void*)&a->max_hp, (const void*)&b->max_hp, sizeof(struct status_data)-(sizeof(a->hp)+sizeof(a->sp)));
}
/**
* Sets HP to the given value.
*
* @param bl The target unit.
* @param hp The desired HP value.
* @param flag Additional options. @see enum status_heal_flag. STATUS_HEAL_FORCED is always implied.
* @return The amount of HP gained.
*/
static int status_set_hp(struct block_list *bl, unsigned int hp, enum status_heal_flag flag)
{
struct status_data *st;
if (hp < 1) return 0;
st = status->get_status_data(bl);
if (st == &status->dummy)
return 0;
if (hp > st->max_hp) hp = st->max_hp;
if (hp == st->hp) return 0;
if (hp > st->hp)
return status->heal(bl, hp - st->hp, 0, STATUS_HEAL_FORCED | flag);
return status_zap(bl, st->hp - hp, 0);
}
/**
* Sets SP to the given value.
*
* @param bl The target unit.
* @param hp The desired SP value.
* @param flag Additional options. @see enum status_heal_flag. STATUS_HEAL_FORCED is always implied.
* @return The amount of SP gained.
*/
static int status_set_sp(struct block_list *bl, unsigned int sp, enum status_heal_flag flag)
{
struct status_data *st;
st = status->get_status_data(bl);
if (st == &status->dummy)
return 0;
if (sp > st->max_sp) sp = st->max_sp;
if (sp == st->sp) return 0;
if (sp > st->sp)
return status->heal(bl, 0, sp - st->sp, STATUS_HEAL_FORCED | flag);
return status_zap(bl, 0, st->sp - sp);
}
static int status_charge(struct block_list *bl, int64 hp, int64 sp)
{
nullpo_retr((int)(hp + sp), bl);
if(!(bl->type&BL_CONSUME))
return (int)(hp+sp); //Assume all was charged so there are no 'not enough' fails.
return status->damage(NULL, bl, hp, sp, 0, 3);
}
//Inflicts damage on the target with the according walkdelay.
//If flag&1, damage is passive and does not triggers canceling status changes.
//If flag&2, fail if target does not has enough to subtract.
//If flag&4, if killed, mob must not give exp/loot.
//flag will be set to &8 when damaging sp of a dead character
static int status_damage(struct block_list *src, struct block_list *target, int64 in_hp, int64 in_sp, int walkdelay, int flag)
{
struct status_data *st;
struct status_change *sc;
int hp,sp;
nullpo_ret(target);
/* From here onwards, we consider it a 32-type as the client does not support higher and the value doesn't get through percentage modifiers */
hp = (int)cap_value(in_hp,INT_MIN,INT_MAX);
sp = (int)cap_value(in_sp,INT_MIN,INT_MAX);
if(sp && !(target->type&BL_CONSUME))
sp = 0; //Not a valid SP target.
if (hp < 0) { //Assume absorbed damage.
status->heal(target, -hp, 0, STATUS_HEAL_FORCED);
hp = 0;
}
if (sp < 0) {
status->heal(target, 0, -sp, STATUS_HEAL_FORCED);
sp = 0;
}
if (target->type == BL_SKILL)
return skill->unit_ondamaged(BL_UCAST(BL_SKILL, target), src, hp, timer->gettick());
st = status->get_status_data(target);
if( st == &status->dummy )
return 0;
if ((unsigned int)hp >= st->hp) {
if (flag&2) return 0;
hp = st->hp;
}
if ((unsigned int)sp > st->sp) {
if (flag&2) return 0;
sp = st->sp;
}
if (!hp && !sp)
return 0;
if( !st->hp )
flag |= 8;
#if 0
// Let through. battle.c/skill.c have the whole logic of when it's possible or
// not to hurt someone (and this check breaks pet catching) [Skotlex]
if (!target->prev && !(flag&2))
return 0; //Cannot damage a bl not on a map, except when "charging" hp/sp
#endif // 0
sc = status->get_sc(target);
if( hp && battle_config.invincible_nodamage && src && sc && sc->data[SC_INVINCIBLE] && !sc->data[SC_INVINCIBLEOFF] )
hp = 1;
if( hp && !(flag&1) ) {
if( sc ) {
struct status_change_entry *sce;
#ifdef DEVOTION_REFLECT_DAMAGE
if (src && (sce = sc->data[SC_DEVOTION]) != NULL) {
struct block_list *d_bl = map->id2bl(sce->val1);
struct mercenary_data *d_md = BL_CAST(BL_MER, d_bl);
struct map_session_data *d_sd = BL_CAST(BL_PC, d_bl);
if (d_bl != NULL
&& ((d_md != NULL && d_md->master != NULL && d_md->master->bl.id == target->id)
|| (d_sd != NULL && d_sd->devotion[sce->val2] == target->id))
&& check_distance_bl(target, d_bl, sce->val3)
) {
clif->damage(d_bl, d_bl, 0, 0, hp, 0, BDT_NORMAL, 0);
status_fix_damage(NULL, d_bl, hp, 0);
return 0;
}
status_change_end(target, SC_DEVOTION, INVALID_TIMER);
}
#endif
if (sc->data[SC_STONE] && sc->opt1 == OPT1_STONE)
status_change_end(target, SC_STONE, INVALID_TIMER);
status_change_end(target, SC_FREEZE, INVALID_TIMER);
status_change_end(target, SC_SLEEP, INVALID_TIMER);
status_change_end(target, SC_DC_WINKCHARM, INVALID_TIMER);
status_change_end(target, SC_CONFUSION, INVALID_TIMER);
status_change_end(target, SC_TRICKDEAD, INVALID_TIMER);
status_change_end(target, SC_HIDING, INVALID_TIMER);
status_change_end(target, SC_CLOAKING, INVALID_TIMER);
status_change_end(target, SC_CHASEWALK, INVALID_TIMER);
status_change_end(target, SC_CAMOUFLAGE, INVALID_TIMER);
status_change_end(target, SC_SUHIDE, INVALID_TIMER);
status_change_end(target, SC_NEWMOON, INVALID_TIMER);
if ((sce=sc->data[SC_ENDURE]) && !sce->val4 && !sc->data[SC_LKCONCENTRATION]) {
//Endure count is only reduced by non-players on non-gvg maps.
//val4 signals infinite endure. [Skotlex]
if (src && src->type != BL_PC && !map_flag_gvg2(target->m) && !map->list[target->m].flag.battleground && --(sce->val2) < 0)
status_change_end(target, SC_ENDURE, INVALID_TIMER);
}
if ((sce=sc->data[SC_GRAVITATION]) && sce->val3 == BCT_SELF) {
struct skill_unit_group* sg = skill->id2group(sce->val4);
if (sg) {
skill->del_unitgroup(sg);
sce->val4 = 0;
status_change_end(target, SC_GRAVITATION, INVALID_TIMER);
}
}
if(sc->data[SC_DANCING] && (unsigned int)hp > st->max_hp>>2)
status_change_end(target, SC_DANCING, INVALID_TIMER);
if(sc->data[SC_CLOAKINGEXCEED] && --(sc->data[SC_CLOAKINGEXCEED]->val2) <= 0)
status_change_end(target, SC_CLOAKINGEXCEED, INVALID_TIMER);
if(sc->data[SC_KAGEMUSYA] && --(sc->data[SC_KAGEMUSYA]->val3) <= 0)
status_change_end(target, SC_KAGEMUSYA, INVALID_TIMER);
}
unit->skillcastcancel(target, 2);
}
st->hp-= hp;
st->sp-= sp;
if (sc && hp && st->hp) {
if (sc->data[SC_AUTOBERSERK] &&
(!sc->data[SC_PROVOKE] || !sc->data[SC_PROVOKE]->val2) &&
st->hp < st->max_hp>>2)
sc_start4(src, target, SC_PROVOKE, 100, 10, 1, 0, 0, 0, SM_AUTOBERSERK);
if (sc->data[SC_BERSERK] && st->hp <= 100)
status_change_end(target, SC_BERSERK, INVALID_TIMER);
if( sc->data[SC_RAISINGDRAGON] && st->hp <= 1000 )
status_change_end(target, SC_RAISINGDRAGON, INVALID_TIMER);
if (sc->data[SC_SATURDAY_NIGHT_FEVER] && st->hp <= 100)
status_change_end(target, SC_SATURDAY_NIGHT_FEVER, INVALID_TIMER);
}
switch (target->type) {
case BL_PC: pc->damage(BL_UCAST(BL_PC, target), src, hp, sp); break;
case BL_MOB: mob->damage(BL_UCAST(BL_MOB, target), src, hp); break;
case BL_HOM: homun->damaged(BL_UCAST(BL_HOM, target)); break;
case BL_MER: mercenary->heal(BL_UCAST(BL_MER, target), hp, sp); break;
case BL_ELEM: elemental->heal(BL_UCAST(BL_ELEM, target), hp, sp); break;
case BL_NUL:
case BL_PET:
case BL_ITEM:
case BL_SKILL:
case BL_NPC:
case BL_CHAT:
case BL_ALL:
break;
}
if (src != NULL && target->type == BL_PC && BL_UCAST(BL_PC, target)->disguise > 0) {
// stop walking when attacked in disguise to prevent walk-delay bug
unit->stop_walking(target, STOPWALKING_FLAG_FIXPOS);
}
if (st->hp || (flag&8)) {
//Still lives or has been dead before this damage.
#ifndef WALKDELAY_SYNC
if (walkdelay)
unit->set_walkdelay(target, timer->gettick(), walkdelay, 0);
#endif
return (int)(hp+sp);
}
st->hp = 1; //To let the dead function cast skills and all that.
//NOTE: These dead functions should return: [Skotlex]
//0: Death canceled, auto-revived.
//Non-zero: Standard death. Clear status, cancel move/attack, etc
//&2: Also remove object from map.
//&4: Also delete object from memory.
switch (target->type) {
case BL_PC: flag = pc->dead(BL_UCAST(BL_PC, target), src); break;
case BL_MOB: flag = mob->dead(BL_UCAST(BL_MOB, target), src, (flag&4) ? 3 : 0); break;
case BL_HOM: flag = homun->dead(BL_UCAST(BL_HOM, target)); break;
case BL_MER: flag = mercenary->dead(BL_UCAST(BL_MER, target)); break;
case BL_ELEM: flag = elemental->dead(BL_UCAST(BL_ELEM, target)); break;
case BL_NUL:
case BL_PET:
case BL_ITEM:
case BL_SKILL:
case BL_NPC:
case BL_CHAT:
case BL_ALL:
default: //Unhandled case, do nothing to object.
flag = 0;
break;
}
if(!flag) //Death canceled.
return (int)(hp+sp);
//Normal death
st->hp = 0;
if (battle_config.clear_unit_ondeath &&
battle_config.clear_unit_ondeath&target->type)
skill->clear_unitgroup(target);
if(target->type&BL_REGEN) {
//Reset regen ticks.
struct regen_data *regen = status->get_regen_data(target);
if (regen != NULL) {
memset(®en->tick, 0, sizeof(regen->tick));
if (regen->skill != NULL)
memset(®en->skill->tick, 0, sizeof(regen->skill->tick));
if (regen->sitting != NULL)
memset(®en->sitting->tick, 0, sizeof(regen->sitting->tick));
}
}
if( sc && sc->data[SC_KAIZEL] && !map_flag_gvg2(target->m) ) {
//flag&8 = disable Kaizel
int time = skill->get_time2(SL_KAIZEL,sc->data[SC_KAIZEL]->val1);
//Look for Osiris Card's bonus effect on the character and revive 100% or revive normally
if ( target->type == BL_PC && BL_CAST(BL_PC,target)->special_state.restart_full_recover )
status->revive(target, 100, 100);
else
status->revive(target, sc->data[SC_KAIZEL]->val2, 0);
status->change_clear(target,0);
clif->skill_nodamage(target,target,ALL_RESURRECTION,1,1);
sc_start(target, target, skill->get_sc_type(PR_KYRIE), 100, 10, time, PR_KYRIE);
if( target->type == BL_MOB )
BL_UCAST(BL_MOB, target)->state.rebirth = 1;
return (int)(hp+sp);
}
if (target->type == BL_MOB && sc != NULL && sc->data[SC_REBIRTH] != NULL) {
struct mob_data *t_md = BL_UCAST(BL_MOB, target);
if (!t_md->state.rebirth) {
// Ensure the monster has not already reborn before doing so.
status->revive(target, sc->data[SC_REBIRTH]->val2, 0);
status->change_clear(target,0);
t_md->state.rebirth = 1;
return (int)(hp+sp);
}
}
status->change_clear(target,0);
if(flag&4) //Delete from memory. (also invokes map removal code)
unit->free(target,CLR_DEAD);
else if(flag&2) //remove from map
unit->remove_map(target,CLR_DEAD,ALC_MARK);
else { //Some death states that would normally be handled by unit_remove_map
unit->stop_attack(target);
unit->stop_walking(target, STOPWALKING_FLAG_FIXPOS);
unit->skillcastcancel(target,0);
clif->clearunit_area(target,CLR_DEAD);
skill->unit_move(target,timer->gettick(),4);
skill->cleartimerskill(target);
}
return (int)(hp+sp);
}
/**
* Heals a character.
*
* @param bl The target unit.
* @param in_hp Amount of HP to recover.
* @param in_sp Amount of SP to recover.
* @param flag Additional options, @see enum status_heal_flag.
* @return The amount of HP + SP healed.
*/
static int status_heal(struct block_list *bl, int64 in_hp, int64 in_sp, enum status_heal_flag flag)
{
struct status_data *st;
struct status_change *sc;
int hp,sp;
nullpo_ret(bl);
st = status->get_status_data(bl);
if (st == &status->dummy)
return 0;
if (st->hp == 0 && (flag & STATUS_HEAL_ALLOWREVIVE) == 0)
return 0;
/* From here onwards, we consider it a 32-type as the client does not support higher and the value doesn't get through percentage modifiers */
hp = (int)cap_value(in_hp,INT_MIN,INT_MAX);
sp = (int)cap_value(in_sp,INT_MIN,INT_MAX);
sc = status->get_sc(bl);
if (sc && !sc->count)
sc = NULL;
if (hp < 0) {
if (hp == INT_MIN) hp++; //-INT_MIN == INT_MIN in some architectures!
status->damage(NULL, bl, -hp, 0, 0, 1);
hp = 0;
}
if (hp != 0) {
if (sc && sc->data[SC_BERSERK] != NULL) {
if ((flag & STATUS_HEAL_FORCED) != 0)
flag &= ~STATUS_HEAL_SHOWEFFECT;
else
hp = 0;
}
if((unsigned int)hp > st->max_hp - st->hp)
hp = st->max_hp - st->hp;
}
if(sp < 0) {
if (sp==INT_MIN) sp++;
status->damage(NULL, bl, 0, -sp, 0, 1);
sp = 0;
}
if(sp) {
if((unsigned int)sp > st->max_sp - st->sp)
sp = st->max_sp - st->sp;
}
if(!sp && !hp) return 0;
st->hp+= hp;
st->sp+= sp;
if( hp && sc
&& sc->data[SC_AUTOBERSERK]
&& sc->data[SC_PROVOKE]
&& sc->data[SC_PROVOKE]->val2==1
&& st->hp>=st->max_hp>>2
) //End auto berserk.
status_change_end(bl, SC_PROVOKE, INVALID_TIMER);
// send hp update to client
switch(bl->type) {
case BL_PC: pc->heal(BL_UCAST(BL_PC, bl), hp, sp, (flag & STATUS_HEAL_SHOWEFFECT) != 0 ? 1 : 0); break;
case BL_MOB: mob->heal(BL_UCAST(BL_MOB, bl), hp); break;
case BL_HOM: homun->healed(BL_UCAST(BL_HOM, bl)); break;
case BL_MER: mercenary->heal(BL_UCAST(BL_MER, bl), hp, sp); break;
case BL_ELEM: elemental->heal(BL_UCAST(BL_ELEM, bl), hp, sp); break;
case BL_NUL:
case BL_PET:
case BL_ITEM:
case BL_SKILL:
case BL_NPC:
case BL_CHAT:
case BL_ALL:
break;
}
return (int)(hp+sp);
}
//Does percentual non-flinching damage/heal. If mob is killed this way,
//no exp/drops will be awarded if there is no src (or src is target)
//If rates are > 0, percent is of current HP/SP
//If rates are < 0, percent is of max HP/SP
//If !flag, this is heal, otherwise it is damage.
//Furthermore, if flag==2, then the target must not die from the subtraction.
static int status_percent_change(struct block_list *src, struct block_list *target, signed char hp_rate, signed char sp_rate, int flag)
{
struct status_data *st;
unsigned int hp = 0, sp = 0;
st = status->get_status_data(target);
if (hp_rate > 100)
hp_rate = 100;
else if (hp_rate < -100)
hp_rate = -100;
if (hp_rate > 0)
hp = APPLY_RATE(st->hp, hp_rate);
else
hp = APPLY_RATE(st->max_hp, -hp_rate);
if (hp_rate && !hp)
hp = 1;
if (flag == 2 && hp >= st->hp)
hp = st->hp-1; //Must not kill target.
if (sp_rate > 100)
sp_rate = 100;
else if (sp_rate < -100)
sp_rate = -100;
if (sp_rate > 0)
sp = APPLY_RATE(st->sp, sp_rate);
else
sp = APPLY_RATE(st->max_sp, -sp_rate);
if (sp_rate && !sp)
sp = 1;
//Ugly check in case damage dealt is too much for the received args of
//status->heal / status->damage. [Skotlex]
if (hp > INT_MAX) {
hp -= INT_MAX;
if (flag)
status->damage(src, target, INT_MAX, 0, 0, (!src||src==target?5:1));
else
status->heal(target, INT_MAX, 0, STATUS_HEAL_DEFAULT);
}
if (sp > INT_MAX) {
sp -= INT_MAX;
if (flag)
status->damage(src, target, 0, INT_MAX, 0, (!src||src==target?5:1));
else
status->heal(target, 0, INT_MAX, STATUS_HEAL_DEFAULT);
}
if (flag)
return status->damage(src, target, hp, sp, 0, (!src||src==target?5:1));
return status->heal(target, hp, sp, STATUS_HEAL_DEFAULT);
}
static int status_revive(struct block_list *bl, unsigned char per_hp, unsigned char per_sp)
{
struct status_data *st;
unsigned int hp, sp;
nullpo_ret(bl);
if (!status->isdead(bl)) return 0;
st = status->get_status_data(bl);
if (st == &status->dummy)
return 0; //Invalid target.
hp = APPLY_RATE(st->max_hp, per_hp);
sp = APPLY_RATE(st->max_sp, per_sp);
if(hp > st->max_hp - st->hp)
hp = st->max_hp - st->hp;
else if (per_hp && !hp)
hp = 1;
if(sp > st->max_sp - st->sp)
sp = st->max_sp - st->sp;
else if (per_sp && !sp)
sp = 1;
st->hp += hp;
st->sp += sp;
if (bl->prev) //Animation only if character is already on a map.
clif->resurrection(bl, 1);
switch (bl->type) {
case BL_PC: pc->revive(BL_UCAST(BL_PC, bl), hp, sp); break;
case BL_MOB: mob->revive(BL_UCAST(BL_MOB, bl), hp); break;
case BL_HOM: homun->revive(BL_UCAST(BL_HOM, bl), hp, sp); break;
case BL_NUL:
case BL_PET:
case BL_MER:
case BL_ELEM:
case BL_ITEM:
case BL_SKILL:
case BL_NPC:
case BL_CHAT:
case BL_ALL:
break;
}
return 1;
}
static int status_fixed_revive(struct block_list *bl, unsigned int per_hp, unsigned int per_sp)
{
struct status_data *st;
unsigned int hp, sp;
if (!status->isdead(bl)) return 0;
nullpo_ret(bl);
st = status->get_status_data(bl);
if (st == &status->dummy)
return 0; //Invalid target.
hp = per_hp;
sp = per_sp;
if(hp > st->max_hp - st->hp)
hp = st->max_hp - st->hp;
else if (!hp)
hp = 1;
if(sp > st->max_sp - st->sp)
sp = st->max_sp - st->sp;
else if (!sp)
sp = 1;
st->hp += hp;
st->sp += sp;
if (bl->prev) //Animation only if character is already on a map.
clif->resurrection(bl, 1);
switch (bl->type) {
case BL_PC: pc->revive(BL_UCAST(BL_PC, bl), hp, sp); break;
case BL_MOB: mob->revive(BL_UCAST(BL_MOB, bl), hp); break;
case BL_HOM: homun->revive(BL_UCAST(BL_HOM, bl), hp, sp); break;
case BL_NUL:
case BL_PET:
case BL_MER:
case BL_ELEM:
case BL_ITEM:
case BL_SKILL:
case BL_NPC:
case BL_CHAT:
case BL_ALL:
break;
}
return 1;
}
/**
* a sub-function from 'status_check_skilluse' function, which can be use for plugin manipulation
* check 'disabled_skills' flag settings from `db\(pre-)re\map_zone_db.conf`
*
* @param src The source object can be BL_PC, BL_MOB, BL_PET, BL_HOM, BL_MER, BL_ELEM type
* @param st The status_data of the source object, use to check MD_BOSS of BL_MOB type
* @param skill_id The skill ID use by src
*
* @return false if the skill ID use is denied, true otherwise
**/
static bool status_check_skilluse_mapzone(struct block_list *src, struct status_data *st, uint16 skill_id)
{
nullpo_retr(false, src);
nullpo_retr(false, st);
for (int i = 0; i < map->list[src->m].zone->disabled_skills_count; i++) {
int zone_nameid = map->list[src->m].zone->disabled_skills[i]->nameid;
enum bl_type zone_type = map->list[src->m].zone->disabled_skills[i]->type;
enum map_zone_skill_subtype zone_subtype = map->list[src->m].zone->disabled_skills[i]->subtype;
if (skill_id == zone_nameid && (zone_type & src->type) != 0) {
if (src->type == BL_PC) {
struct map_session_data *sd = BL_UCAST(BL_PC, src);
#if PACKETVER >= 20080311
clif->skill_mapinfomessage(sd, 2);
#else
clif->messagecolor_self(sd->fd, COLOR_CYAN, msg_sd(sd, MSGTBL_SKILL_DISABLED_IN_AREA));
#endif
} else if (src->type == BL_MOB && zone_subtype != MZS_NONE) {
if ((st->mode & MD_BOSS) != 0) { /* is boss */
if ((zone_subtype & MZS_BOSS) == 0)
break;
} else { /* is not boss */
if ((zone_subtype & MZS_BOSS) != 0)
break;
}
}
return false;
}
}
return true;
}
/*==========================================
* Checks whether the src can use the skill on the target,
* taking into account status/option of both source/target. [Skotlex]
* flag:
* 0 - Trying to use skill on target.
* 1 - Cast bar is done.
* 2 - Skill already pulled off, check is due to ground-based skills or splash-damage ones.
* src MAY be null to indicate we shouldn't check it, this is a ground-based skill attack.
* target MAY Be null, in which case the checks are only to see
* whether the source can cast or not the skill on the ground.
*------------------------------------------*/
static int status_check_skilluse(struct block_list *src, struct block_list *target, uint16 skill_id, int flag)
{
struct status_data *st;
struct status_change *sc=NULL, *tsc;
int hide_flag;
struct map_session_data *sd = BL_CAST(BL_PC, src);
st = src ? status->get_status_data(src) : &status->dummy;
if (src != NULL && src->type != BL_PC && status->isdead(src))
return 0;
if (sd != NULL && sd->block_action.skill && skill_id) // *pcblock script command
return 0;
if (!skill_id) { //Normal attack checks.
if (!(st->mode&MD_CANATTACK))
return 0; //This mode is only needed for melee attacking.
//Dead state is not checked for skills as some skills can be used
//on dead characters, said checks are left to skill.c [Skotlex]
if (target && status->isdead(target))
return 0;
if( src && (sc = status->get_sc(src)) != NULL && sc->data[SC_COLD] && src->type != BL_MOB)
return 0;
}
if( skill_id ) {
if (src != NULL && (sd == NULL || sd->auto_cast_current.type != AUTOCAST_ITEM)) {
// Items that cast skills using 'itemskill' will not be handled by map_zone_db.
if (!status->check_skilluse_mapzone(src, st, skill_id))
return 0;
}
switch( skill_id ) {
case PA_PRESSURE:
if( flag && target ) {
//Gloria Avoids pretty much everything....
tsc = status->get_sc(target);
if(tsc && tsc->option&OPTION_HIDE)
return 0;
}
break;
case GN_WALLOFTHORN:
if( target && status->isdead(target) )
return 0;
break;
case AL_TELEPORT:
//Should fail when used on top of Land Protector [Skotlex]
if (src != NULL
&& map->getcell(src->m, src, src->x, src->y, CELL_CHKLANDPROTECTOR)
&& !(st->mode&MD_BOSS)
&& (src->type != BL_PC || sd->auto_cast_current.type != AUTOCAST_ITEM))
return 0;
break;
default:
break;
}
}
if ( src ) sc = status->get_sc(src);
if( sc && sc->count ) {
if (skill_id != RK_REFRESH && sc->opt1 >0 && !(sc->opt1 == OPT1_CRYSTALIZE && src->type == BL_MOB) && sc->opt1 != OPT1_BURNING && skill_id != SR_GENTLETOUCH_CURE) { //Stunned/Frozen/etc
if (flag != 1) //Can't cast, casted stuff can't damage.
return 0;
if (!(skill->get_inf(skill_id)&INF_GROUND_SKILL))
return 0; //Targeted spells can't come off.
}
if (
(sc->data[SC_TRICKDEAD] && skill_id != NV_TRICKDEAD)
|| (sc->data[SC_AUTOCOUNTER] && !flag && skill_id)
|| (sc->data[SC_GOSPEL] && sc->data[SC_GOSPEL]->val4 == BCT_SELF && skill_id != PA_GOSPEL)
|| (sc->data[SC_SUHIDE] && skill_id != SU_HIDE)
)
return 0;
if (sc->data[SC_DC_WINKCHARM] && target && !flag) { //Prevents skill usage
struct block_list *winkcharm_target = map->id2bl(sc->data[SC_DC_WINKCHARM]->val2);
if (winkcharm_target != NULL) {
if (unit->bl2ud(src) && (unit->bl2ud(src))->walktimer == INVALID_TIMER)
unit->walk_tobl(src, winkcharm_target, 3, 1);
clif->emotion(src, E_LV);
return 0;
} else {
status_change_end(src, SC_DC_WINKCHARM, INVALID_TIMER);
}
}
if (sc->data[SC_BLADESTOP]) {
switch (sc->data[SC_BLADESTOP]->val1)
{
case 5: if (skill_id == MO_EXTREMITYFIST) break;
FALLTHROUGH
case 4: if (skill_id == MO_CHAINCOMBO) break;
FALLTHROUGH
case 3: if (skill_id == MO_INVESTIGATE) break;
FALLTHROUGH
case 2: if (skill_id == MO_FINGEROFFENSIVE) break;
FALLTHROUGH
default: return 0;
}
}
if (sc->data[SC_DANCING] && flag!=2) {
if (src->type == BL_PC && skill_id >= WA_SWING_DANCE && skill_id <= WM_UNLIMITED_HUMMING_VOICE) {
// Lvl 5 Lesson or higher allow you use 3rd job skills while dancing.v
if (pc->checkskill(sd, WM_LESSON) < 5)
return 0;
} else if(sc->data[SC_LONGING]) { //Allow everything except dancing/re-dancing. [Skotlex]
if (skill_id == BD_ENCORE ||
skill->get_inf2(skill_id)&(INF2_SONG_DANCE|INF2_ENSEMBLE_SKILL)
)
return 0;
} else {
switch (skill_id) {
case BD_ADAPTATION:
case CG_LONGINGFREEDOM:
case BA_MUSICALSTRIKE:
case DC_THROWARROW:
break;
default:
return 0;
}
}
if ((sc->data[SC_DANCING]->val1&0xFFFF) == CG_HERMODE && skill_id == BD_ADAPTATION)
return 0; //Can't amp out of Wand of Hermode :/ [Skotlex]
}
if (skill_id != 0 /* Do not block item-casted skills.*/ && (src->type != BL_PC || sd->auto_cast_current.type != AUTOCAST_ITEM)) {
//Skills blocked through status changes...
if (!flag && ( //Blocked only from using the skill (stuff like autospell may still go through
sc->data[SC_SILENCE] ||
sc->data[SC_STEELBODY] ||
sc->data[SC_BERSERK] ||
sc->data[SC_OBLIVIONCURSE] ||
sc->data[SC_WHITEIMPRISON] ||
sc->data[SC__INVISIBILITY] ||
(sc->data[SC_COLD] && src->type != BL_MOB) ||
sc->data[SC__IGNORANCE] ||
sc->data[SC_DEEP_SLEEP] ||
sc->data[SC_SATURDAY_NIGHT_FEVER] ||
sc->data[SC_CURSEDCIRCLE_TARGET] ||
(sc->data[SC_MARIONETTE_MASTER] && skill_id != CG_MARIONETTE) || //Only skill you can use is marionette again to cancel it
(sc->data[SC_MARIONETTE] && skill_id == CG_MARIONETTE) || //Cannot use marionette if you are being buffed by another
(sc->data[SC_STASIS] && skill->block_check(src, SC_STASIS, skill_id)) ||
(sc->data[SC_KG_KAGEHUMI] && skill->block_check(src, SC_KG_KAGEHUMI, skill_id)) ||
(sc->data[SC_NOVAEXPLOSING] && skill->block_check(src, SC_NOVAEXPLOSING, skill_id)) ||
(sc->data[SC_GRAVITYCONTROL] && skill->block_check(src, SC_GRAVITYCONTROL, skill_id)) ||
sc->data[SC_ALL_RIDING] != NULL // New mounts can't attack nor use skills in the client; this check makes it cheat-safe. [Ind]
))
return 0;
//Skill blocking.
if (
(sc->data[SC_VOLCANO] && skill_id == WZ_ICEWALL) ||
(sc->data[SC_ROKISWEIL] && skill_id != BD_ADAPTATION) ||
(sc->data[SC_HERMODE] && skill->get_inf(skill_id) & INF_SUPPORT_SKILL) ||
pc_ismuted(sc, MANNER_NOSKILL)
)
return 0;
if( sc->data[SC__MANHOLE] || ((tsc = status->get_sc(target)) && tsc->data[SC__MANHOLE]) ) {
switch(skill_id) {//##TODO## make this a flag in skill_db?
// Skills that can be used even under Man Hole effects.
case SC_SHADOWFORM:
break;
default:
return 0;
}
}
}
}
if (sc && sc->option) {
if (sc->option&OPTION_HIDE) {
switch (skill_id) { //Usable skills while hiding.
case TF_HIDING:
case AS_GRIMTOOTH:
case RG_BACKSTAP:
case RG_RAID:
case NJ_SHADOWJUMP:
case NJ_KIRIKAGE:
case KO_YAMIKUMO:
break;
default:
//Non players can use all skills while hidden.
if (!skill_id || src->type == BL_PC)