-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskill.cpp
23381 lines (20964 loc) · 788 KB
/
skill.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
// Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
#include "skill.hpp"
#include <array>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "../common/cbasetypes.hpp"
#include "../common/ers.hpp"
#include "../common/malloc.hpp"
#include "../common/nullpo.hpp"
#include "../common/random.hpp"
#include "../common/showmsg.hpp"
#include "../common/strlib.hpp"
#include "../common/timer.hpp"
#include "../common/utilities.hpp"
#include "../common/utils.hpp"
#include "achievement.hpp"
#include "battle.hpp"
#include "battleground.hpp"
#include "chrif.hpp"
#include "clif.hpp"
#include "date.hpp"
#include "elemental.hpp"
#include "guild.hpp"
#include "homunculus.hpp"
#include "intif.hpp"
#include "itemdb.hpp"
#include "log.hpp"
#include "map.hpp"
#include "mercenary.hpp"
#include "mob.hpp"
#include "npc.hpp"
#include "party.hpp"
#include "path.hpp"
#include "pc.hpp"
#include "pc_groups.hpp"
#include "pet.hpp"
#include "script.hpp"
#include "status.hpp"
#include "unit.hpp"
using namespace rathena;
#define SKILLUNITTIMER_INTERVAL 100
#define TIMERSKILL_INTERVAL 150
// ranges reserved for mapping skill ids to skilldb offsets
#define HM_SKILLRANGEMIN 700
#define HM_SKILLRANGEMAX HM_SKILLRANGEMIN + MAX_HOMUNSKILL
#define MC_SKILLRANGEMIN HM_SKILLRANGEMAX + 1
#define MC_SKILLRANGEMAX MC_SKILLRANGEMIN + MAX_MERCSKILL
#define EL_SKILLRANGEMIN MC_SKILLRANGEMAX + 1
#define EL_SKILLRANGEMAX EL_SKILLRANGEMIN + MAX_ELEMENTALSKILL
#define GD_SKILLRANGEMIN EL_SKILLRANGEMAX + 1
#define GD_SKILLRANGEMAX GD_SKILLRANGEMIN + MAX_GUILDSKILL
#if GD_SKILLRANGEMAX > 999
#error GD_SKILLRANGEMAX is greater than 999
#endif
static uint16 skilldb_id2idx[(UINT16_MAX + 1)]; /// Skill ID to Index lookup: skill_index = skill_get_index(skill_id) - [FWI] 20160423 the whole index thing should be removed.
static uint16 skill_num = 1; /// Skill count, also as last index
static struct eri *skill_unit_ers = NULL; //For handling skill_unit's [Skotlex]
static struct eri *skill_timer_ers = NULL; //For handling skill_timerskills [Skotlex]
static DBMap* bowling_db = NULL; // int mob_id -> struct mob_data*
DBMap* skillunit_db = NULL; // int id -> struct skill_unit*
/**
* Skill Unit Persistency during endack routes (mostly for songs see bugreport:4574)
*/
DBMap* skillusave_db = NULL; // char_id -> struct skill_usave
struct skill_usave {
uint16 skill_id, skill_lv;
};
struct s_skill_produce_db skill_produce_db[MAX_SKILL_PRODUCE_DB];
static unsigned short skill_produce_count;
struct s_skill_arrow_db skill_arrow_db[MAX_SKILL_ARROW_DB];
static unsigned short skill_arrow_count;
AbraDatabase abra_db;
ImprovisedSongDatabase improvised_song_db;
ReadingSpellbookDatabase reading_spellbook_db;
#define MAX_SKILL_CHANGEMATERIAL_DB 75
#define MAX_SKILL_CHANGEMATERIAL_SET 3
struct s_skill_changematerial_db {
unsigned short nameid;
unsigned short rate;
unsigned short qty[MAX_SKILL_CHANGEMATERIAL_SET];
unsigned short qty_rate[MAX_SKILL_CHANGEMATERIAL_SET];
};
struct s_skill_changematerial_db skill_changematerial_db[MAX_SKILL_CHANGEMATERIAL_DB];
static unsigned short skill_changematerial_count;
MagicMushroomDatabase magic_mushroom_db;
struct s_skill_unit_layout skill_unit_layout[MAX_SKILL_UNIT_LAYOUT];
int firewall_unit_pos;
int icewall_unit_pos;
int earthstrain_unit_pos;
int firerain_unit_pos;
int wallofthorn_unit_pos;
struct s_skill_nounit_layout skill_nounit_layout[MAX_SKILL_UNIT_LAYOUT2];
int overbrand_nounit_pos;
int overbrand_brandish_nounit_pos;
static char dir_ka = -1; // Holds temporary direction to the target for SR_KNUCKLEARROW
//Early declaration
bool skill_strip_equip(struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv);
static int skill_check_unit_range (struct block_list *bl, int x, int y, uint16 skill_id, uint16 skill_lv);
static int skill_check_unit_range2 (struct block_list *bl, int x, int y, uint16 skill_id, uint16 skill_lv, bool isNearNPC);
static int skill_destroy_trap( struct block_list *bl, va_list ap );
static int skill_check_condition_mob_master_sub (struct block_list *bl, va_list ap);
static bool skill_check_condition_sc_required(struct map_session_data *sd, unsigned short skill_id, struct s_skill_condition *require);
static bool skill_check_unit_movepos(uint8 check_flag, struct block_list *bl, short dst_x, short dst_y, int easy, bool checkpath);
// Use this function for splash skills that can't hit icewall when cast by players
static inline int splash_target(struct block_list* bl) {
return ( bl->type == BL_MOB ) ? BL_SKILL|BL_CHAR : BL_CHAR;
}
uint16 SKILL_MAX_DB(void) {
return skill_num;
}
/**
* Get skill id from name
* @param name
* @return Skill ID of the skill, or 0 if not found.
**/
uint16 skill_name2id(const char* name) {
if (name == nullptr)
return 0;
for (const auto &it : skill_db) {
if (strcmpi(it.second->name, name) == 0)
return it.first;
}
return 0;
}
/**
* Get skill index from skill_db array. The index is also being used for skill lookup in mmo_charstatus::skill[]
* @param skill_id
* @param silent If Skill is undefined, show error message!
* @return Skill Index or 0 if not found/unset
**/
uint16 skill_get_index_(uint16 skill_id, bool silent, const char *func, const char *file, int line) {
uint16 idx = skilldb_id2idx[skill_id];
if (!idx && skill_id != 0 && !silent)
ShowError("Skill '%d' is undefined! %s:%d::%s\n", skill_id, file, line, func);
return idx;
}
/**
* Get Skill name
* @param skill_id
* @return AEGIS Skill name
**/
const char* skill_get_name( uint16 skill_id ) {
return skill_db.find(skill_id)->name;
}
/**
* Get Skill name
* @param skill_id
* @return English Skill name
**/
const char* skill_get_desc( uint16 skill_id ) {
return skill_db.find(skill_id)->desc;
}
static bool skill_check(uint16 id) {
if (id == 0 || skill_get_index(id) == 0)
return false;
return true;
}
#define skill_get(id, var) do {\
if (!skill_check(id))\
return 0;\
return var;\
} while(0)
#define skill_get_lv(id, lv, arrvar) do {\
if (!skill_check(id))\
return 0;\
int lv_idx = min(lv, MAX_SKILL_LEVEL) - 1;\
if (lv > MAX_SKILL_LEVEL && arrvar[lv_idx] > 1 && lv_idx > 1) {\
int a__ = arrvar[lv_idx - 2];\
int b__ = arrvar[lv_idx - 1];\
int c__ = arrvar[lv_idx];\
return (c__ + ((lv - MAX_SKILL_LEVEL + 1) * (b__ - a__) / 2) + ((lv - MAX_SKILL_LEVEL) * (c__ - b__) / 2));\
}\
return arrvar[lv_idx];\
} while(0)
// Skill DB
e_damage_type skill_get_hit( uint16 skill_id ) { if (!skill_check(skill_id)) return DMG_NORMAL; return skill_db.find(skill_id)->hit; }
int skill_get_inf( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->inf); }
int skill_get_ele( uint16 skill_id , uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->element); }
int skill_get_max( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->max); }
int skill_get_range( uint16 skill_id , uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->range); }
int skill_get_splash_( uint16 skill_id , uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->splash); }
int skill_get_num( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->num); }
int skill_get_cast( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->cast); }
int skill_get_delay( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->delay); }
int skill_get_walkdelay( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->walkdelay); }
int skill_get_time( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->upkeep_time); }
int skill_get_time2( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->upkeep_time2); }
int skill_get_castdef( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->cast_def_rate); }
int skill_get_castcancel( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->castcancel); }
int skill_get_maxcount( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->maxcount); }
int skill_get_blewcount( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->blewcount); }
int skill_get_castnodex( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->castnodex); }
int skill_get_delaynodex( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->delaynodex); }
int skill_get_nocast ( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->nocast); }
int skill_get_type( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->skill_type); }
int skill_get_unit_id ( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->unit_id); }
int skill_get_unit_id2 ( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->unit_id2); }
int skill_get_unit_interval( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->unit_interval); }
int skill_get_unit_range( uint16 skill_id, uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->unit_range); }
int skill_get_unit_target( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->unit_target&BCT_ALL); }
int skill_get_unit_bl_target( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->unit_target&BL_ALL); }
int skill_get_unit_layout_type( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->unit_layout_type); }
int skill_get_cooldown( uint16 skill_id, uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->cooldown); }
#ifdef RENEWAL_CAST
int skill_get_fixed_cast( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->fixed_cast); }
#endif
// Skill requirements
int skill_get_hp( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->require.hp); }
int skill_get_mhp( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->require.mhp); }
int skill_get_sp( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->require.sp); }
int skill_get_hp_rate( uint16 skill_id, uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->require.hp_rate); }
int skill_get_sp_rate( uint16 skill_id, uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->require.sp_rate); }
int skill_get_zeny( uint16 skill_id ,uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->require.zeny); }
int skill_get_weapontype( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->require.weapon); }
int skill_get_ammotype( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->require.ammo); }
int skill_get_ammo_qty( uint16 skill_id, uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->require.ammo_qty); }
int skill_get_state( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->require.state); }
int skill_get_status_count( uint16 skill_id ) { skill_get(skill_id, skill_db.find(skill_id)->require.status.size()); }
int skill_get_spiritball( uint16 skill_id, uint16 skill_lv ) { skill_get_lv(skill_id, skill_lv, skill_db.find(skill_id)->require.spiritball); }
int skill_get_splash( uint16 skill_id , uint16 skill_lv ) {
int splash = skill_get_splash_(skill_id, skill_lv);
if (splash < 0)
return AREA_SIZE;
return splash;
}
bool skill_get_nk_(uint16 skill_id, std::vector<e_skill_nk> nk) {
if( skill_id == 0 ){
return false;
}
std::shared_ptr<s_skill_db> skill = skill_db.find(skill_id);
if (!skill)
return false;
for (const auto &nkit : nk) {
if (skill->nk[nkit])
return true;
}
return false;
}
bool skill_get_inf2_(uint16 skill_id, std::vector<e_skill_inf2> inf2) {
if( skill_id == 0 ){
return false;
}
std::shared_ptr<s_skill_db> skill = skill_db.find(skill_id);
if (!skill)
return false;
for (const auto &inf2it : inf2) {
if (skill->inf2[inf2it])
return true;
}
return false;
}
bool skill_get_unit_flag_(uint16 skill_id, std::vector<e_skill_unit_flag> unit) {
if( skill_id == 0 ){
return false;
}
std::shared_ptr<s_skill_db> skill = skill_db.find(skill_id);
if (!skill)
return false;
for (const auto &unitit : unit) {
if (skill->unit_flag[unitit])
return true;
}
return false;
}
int skill_tree_get_max(uint16 skill_id, int b_class)
{
int i;
b_class = pc_class2idx(b_class);
ARR_FIND( 0, MAX_SKILL_TREE, i, skill_tree[b_class][i].skill_id == 0 || skill_tree[b_class][i].skill_id == skill_id );
if( i < MAX_SKILL_TREE && skill_tree[b_class][i].skill_id == skill_id )
return skill_tree[b_class][i].skill_lv;
else
return skill_get_max(skill_id);
}
int skill_frostjoke_scream(struct block_list *bl,va_list ap);
int skill_attack_area(struct block_list *bl,va_list ap);
struct skill_unit_group *skill_locate_element_field(struct block_list *bl); // [Skotlex]
int skill_graffitiremover(struct block_list *bl, va_list ap); // [Valaris]
int skill_greed(struct block_list *bl, va_list ap);
static int skill_cell_overlap(struct block_list *bl, va_list ap);
static int skill_trap_splash(struct block_list *bl, va_list ap);
struct skill_unit_group_tickset *skill_unitgrouptickset_search(struct block_list *bl,struct skill_unit_group *sg,t_tick tick);
static int skill_unit_onplace(struct skill_unit *src,struct block_list *bl,t_tick tick);
int skill_unit_onleft(uint16 skill_id, struct block_list *bl,t_tick tick);
static int skill_unit_effect(struct block_list *bl,va_list ap);
static int skill_bind_trap(struct block_list *bl, va_list ap);
e_cast_type skill_get_casttype (uint16 skill_id) {
std::shared_ptr<s_skill_db> skill = skill_db.find(skill_id);
if( skill == nullptr ){
return CAST_DAMAGE;
}
if (skill->inf&(INF_GROUND_SKILL))
return CAST_GROUND;
if (skill->inf&INF_SUPPORT_SKILL)
return CAST_NODAMAGE;
if (skill->inf&INF_SELF_SKILL) {
if(skill->inf2[INF2_NOTARGETSELF])
return CAST_DAMAGE; //Combo skill.
return CAST_NODAMAGE;
}
if (skill->nk[NK_NODAMAGE])
return CAST_NODAMAGE;
return CAST_DAMAGE;
}
//Returns actual skill range taking into account attack range and AC_OWL [Skotlex]
int skill_get_range2(struct block_list *bl, uint16 skill_id, uint16 skill_lv, bool isServer) {
if( bl->type == BL_MOB && battle_config.mob_ai&0x400 )
return 9; //Mobs have a range of 9 regardless of skill used.
int32 range = skill_get_range(skill_id, skill_lv);
if( range < 0 ) {
if( battle_config.use_weapon_skill_range&bl->type )
return status_get_range(bl);
range *=-1;
}
if (isServer && range > 14) {
range = 14; // Server-sided base range can't be above 14
}
std::bitset<INF2_MAX> inf2 = skill_db.find(skill_id)->inf2;
if(inf2[INF2_ALTERRANGEVULTURE] || inf2[INF2_ALTERRANGESNAKEEYE] ){
if( bl->type == BL_PC ) {
if(inf2[INF2_ALTERRANGEVULTURE]) range += pc_checkskill((TBL_PC*)bl, AC_VULTURE);
// added to allow GS skills to be effected by the range of Snake Eyes [Reddozen]
if(inf2[INF2_ALTERRANGESNAKEEYE]) range += pc_checkskill((TBL_PC*)bl, GS_SNAKEEYE);
} else
range += battle_config.mob_eye_range_bonus;
}
if(inf2[INF2_ALTERRANGESHADOWJUMP] || inf2[INF2_ALTERRANGERADIUS] || inf2[INF2_ALTERRANGERESEARCHTRAP] ){
if( bl->type == BL_PC ) {
if(inf2[INF2_ALTERRANGESHADOWJUMP]) range = skill_get_range(NJ_SHADOWJUMP,pc_checkskill((TBL_PC*)bl,NJ_SHADOWJUMP));
if(inf2[INF2_ALTERRANGERADIUS]) range += pc_checkskill((TBL_PC*)bl, WL_RADIUS);
if(inf2[INF2_ALTERRANGERESEARCHTRAP]) {
int rt_range[11] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
range += rt_range[pc_checkskill((TBL_PC*)bl, RA_RESEARCHTRAP)];
}
}
}
if( !range && bl->type != BL_PC )
return 9; // Enable non players to use self skills on others. [Skotlex]
return range;
}
/** Copy Referral: dummy skills should point to their source.
* @param skill_id Dummy skill ID
* @return Real skill id if found
**/
unsigned short skill_dummy2skill_id(unsigned short skill_id) {
switch (skill_id) {
case AB_DUPLELIGHT_MELEE:
case AB_DUPLELIGHT_MAGIC:
return AB_DUPLELIGHT;
case WL_CHAINLIGHTNING_ATK:
return WL_CHAINLIGHTNING;
case WL_TETRAVORTEX_FIRE:
case WL_TETRAVORTEX_WATER:
case WL_TETRAVORTEX_WIND:
case WL_TETRAVORTEX_GROUND:
return WL_TETRAVORTEX;
case WL_SUMMON_ATK_FIRE:
return WL_SUMMONFB;
case WL_SUMMON_ATK_WIND:
return WL_SUMMONBL;
case WL_SUMMON_ATK_WATER:
return WL_SUMMONWB;
case WL_SUMMON_ATK_GROUND:
return WL_SUMMONSTONE;
case LG_OVERBRAND_BRANDISH:
case LG_OVERBRAND_PLUSATK:
return LG_OVERBRAND;
case WM_REVERBERATION_MELEE:
case WM_REVERBERATION_MAGIC:
return WM_REVERBERATION;
case WM_SEVERE_RAINSTORM_MELEE:
return WM_SEVERE_RAINSTORM;
case GN_CRAZYWEED_ATK:
return GN_CRAZYWEED;
case GN_HELLS_PLANT_ATK:
return GN_HELLS_PLANT;
case GN_SLINGITEM_RANGEMELEEATK:
return GN_SLINGITEM;
case RL_R_TRIP_PLUSATK:
return RL_R_TRIP;
case NPC_MAXPAIN_ATK:
return NPC_MAXPAIN;
case SU_CN_METEOR2:
return SU_CN_METEOR;
case SU_SV_ROOTTWIST_ATK:
return SU_SV_ROOTTWIST;
case SU_LUNATICCARROTBEAT2:
return SU_LUNATICCARROTBEAT;
case NPC_REVERBERATION_ATK:
return NPC_REVERBERATION;
}
return skill_id;
}
/**
* Check skill unit maxcount
* @param src: Caster to check against
* @param x: X location of skill
* @param y: Y location of skill
* @param skill_id: Skill used
* @param skill_lv: Skill level used
* @param type: Type of unit to check against for battle_config checks
* @param display_failure: Display skill failure message
* @return True on skill cast success or false on failure
*/
bool skill_pos_maxcount_check(struct block_list *src, int16 x, int16 y, uint16 skill_id, uint16 skill_lv, enum bl_type type, bool display_failure) {
if (!src)
return false;
struct unit_data *ud = unit_bl2ud(src);
struct map_session_data *sd = map_id2sd(src->id);
int maxcount = 0;
std::shared_ptr<s_skill_db> skill = skill_db.find(skill_id);
if (!(type&battle_config.skill_reiteration) && skill->unit_flag[UF_NOREITERATION] && skill_check_unit_range(src, x, y, skill_id, skill_lv)) {
if (sd && display_failure)
clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
return false;
}
if (type&battle_config.skill_nofootset && skill->unit_flag[UF_NOFOOTSET] && skill_check_unit_range2(src, x, y, skill_id, skill_lv, false)) {
if (sd && display_failure)
clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
return false;
}
if (type&battle_config.land_skill_limit && (maxcount = skill_get_maxcount(skill_id, skill_lv)) > 0) {
for (int i = 0; i < MAX_SKILLUNITGROUP && ud->skillunit[i] && maxcount; i++) {
if (ud->skillunit[i]->skill_id == skill_id)
maxcount--;
}
if (maxcount == 0) {
if (sd && display_failure)
clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
return false;
}
}
return true;
}
/**
* Calculates heal value of skill's effect
* @param src: Unit casting heal
* @param target: Target of src
* @param skill_id: Skill ID used
* @param skill_lv: Skill Level used
* @param heal: True if it's the heal part or false if it's the damage part of the skill
* @return modified heal value
*/
int skill_calc_heal(struct block_list *src, struct block_list *target, uint16 skill_id, uint16 skill_lv, bool heal) {
int skill, hp = 0;
#ifdef RENEWAL
int hp_bonus = 0;
double global_bonus = 1;
#endif
struct map_session_data *sd = BL_CAST(BL_PC, src);
struct map_session_data *tsd = BL_CAST(BL_PC, target);
struct status_change *sc, *tsc;
sc = status_get_sc(src);
tsc = status_get_sc(target);
switch( skill_id ) {
#ifndef RENEWAL
case BA_APPLEIDUN:
hp = 30 + 5 * skill_lv + (status_get_vit(src) / 2); // HP recovery
if (sd)
hp += 5 * pc_checkskill(sd, BA_MUSICALLESSON);
break;
#endif
case PR_SANCTUARY:
hp = (skill_lv > 6) ? 777 : skill_lv * 100;
break;
case NPC_EVILLAND:
hp = (skill_lv > 6) ? 666 : skill_lv * 100;
break;
case AB_HIGHNESSHEAL:
#ifdef RENEWAL
hp = ((status_get_int(src) + status_get_lv(src)) / 5) * 30;
if (sd && ((skill = pc_checkskill(sd, HP_MEDITATIO)) > 0))
hp_bonus += skill * 2;
#else
hp = ((status_get_lv(src) + status_get_int(src)) / 8) * (4 + ((sd ? pc_checkskill(sd, AL_HEAL) : 1) * 8));
hp = (hp * (17 + 3 * skill_lv)) / 10;
#endif
break;
case SU_FRESHSHRIMP:
hp = (status_get_lv(src) + status_get_int(src)) / 5 * 6;
break;
case SU_BUNCHOFSHRIMP:
hp = (status_get_lv(src) + status_get_int(src)) / 5 * 15;
break;
default:
if (skill_lv >= battle_config.max_heal_lv)
return battle_config.max_heal;
#ifdef RENEWAL
/**
* Renewal Heal Formula
* Formula: ( [(Base Level + INT) / 5] x 30 ) x (Heal Level / 10) x (Modifiers) + MATK
*/
hp = (status_get_lv(src) + status_get_int(src)) / 5 * 30 * skill_lv / 10;
#else
hp = (status_get_lv(src) + status_get_int(src)) / 8 * (4 + (skill_lv * 8));
#endif
if (sd && ((skill = pc_checkskill(sd, HP_MEDITATIO)) > 0))
#ifdef RENEWAL
hp_bonus += skill * 2;
#else
hp += hp * skill * 2 / 100;
#endif
else if (src->type == BL_HOM && (skill = hom_checkskill(((TBL_HOM*)src), HLIF_BRAIN)) > 0)
#ifdef RENEWAL
hp_bonus += skill * 2;
#else
hp += hp * skill * 2 / 100;
#endif
if (sd && tsd && sd->status.partner_id == tsd->status.char_id && (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.sex == 0)
hp *= 2;
break;
}
if( (!heal || (target && target->type == BL_MER)) && skill_id != NPC_EVILLAND )
hp >>= 1;
if (sd) {
if (pc_checkskill(sd, SU_POWEROFSEA) > 0) {
#ifdef RENEWAL
hp_bonus += 10;
#else
hp += hp * 10 / 100;
#endif
if (pc_checkskill(sd, SU_TUNABELLY) == 5 && pc_checkskill(sd, SU_TUNAPARTY) == 5 && pc_checkskill(sd, SU_BUNCHOFSHRIMP) == 5 && pc_checkskill(sd, SU_FRESHSHRIMP) == 5)
#ifdef RENEWAL
hp_bonus += 20;
#else
hp += hp * 20 / 100;
#endif
}
if ((skill = pc_checkskill(sd, NV_BREAKTHROUGH)) > 0)
#ifdef RENEWAL
hp_bonus += 2;
#else
hp += hp * skill * 2 / 100;
#endif
if ((skill = pc_checkskill(sd, NV_TRANSCENDENCE)) > 0)
#ifdef RENEWAL
hp_bonus += 3;
#else
hp += hp * skill * 3 / 100;
#endif
if (skill = pc_skillheal_bonus(sd, skill_id))
#ifdef RENEWAL
hp_bonus += skill;
#else
hp += hp * skill / 100;
#endif
}
if (tsd && (skill = pc_skillheal2_bonus(tsd, skill_id)))
#ifdef RENEWAL
hp_bonus += skill;
#else
hp += hp * skill / 100;
#endif
if (sc && sc->count) {
if (sc->data[SC_OFFERTORIUM] && (skill_id == AB_HIGHNESSHEAL || skill_id == AB_CHEAL || skill_id == PR_SANCTUARY || skill_id == AL_HEAL))
#ifdef RENEWAL
hp_bonus += sc->data[SC_OFFERTORIUM]->val2;
#else
hp += hp * sc->data[SC_OFFERTORIUM]->val2 / 100;
#endif
if (sc->data[SC_GLASTHEIM_HEAL] && skill_id != NPC_EVILLAND && skill_id != BA_APPLEIDUN)
#ifdef RENEWAL
hp_bonus += sc->data[SC_GLASTHEIM_HEAL]->val1;
#else
hp += hp * sc->data[SC_GLASTHEIM_HEAL]->val1 / 100;
#endif
#ifdef RENEWAL
if (sc->data[SC_ASSUMPTIO])
hp_bonus += sc->data[SC_ASSUMPTIO]->val1 * 2;
#endif
}
if (tsc && tsc->count) {
if (skill_id != NPC_EVILLAND && skill_id != BA_APPLEIDUN) {
if (tsc->data[SC_INCHEALRATE])
#ifdef RENEWAL
hp_bonus += tsc->data[SC_INCHEALRATE]->val1; //Only affects Heal, Sanctuary and PotionPitcher.(like bHealPower) [Inkfish]
#else
hp += hp * tsc->data[SC_INCHEALRATE]->val1 / 100;
#endif
if (tsc->data[SC_GLASTHEIM_HEAL])
#ifdef RENEWAL
hp_bonus += tsc->data[SC_GLASTHEIM_HEAL]->val2;
#else
hp += hp * tsc->data[SC_GLASTHEIM_HEAL]->val2 / 100;
#endif
if (tsc->data[SC_ANCILLA])
#ifdef RENEWAL
hp_bonus += tsc->data[SC_ANCILLA]->val1;
#else
hp += hp * tsc->data[SC_ANCILLA]->val1 / 100;
if (tsc->data[SC_WATER_INSIGNIA] && tsc->data[SC_WATER_INSIGNIA]->val1 == 2)
hp += hp / 10;
#endif
}
}
#ifdef RENEWAL
if (hp_bonus)
hp += hp * hp_bonus / 100;
// MATK part of the RE heal formula [malufett]
// Note: in this part matk bonuses from items or skills are not applied
switch( skill_id ) {
case BA_APPLEIDUN:
case PR_SANCTUARY:
case NPC_EVILLAND:
break;
default:
{
struct status_data *status = status_get_status_data(src);
int min, max;
min = status_base_matk_min(src, status, status_get_lv(src));
max = status_base_matk_max(src, status, status_get_lv(src));
if( status->rhw.matk > 0 ){
int wMatk, variance;
wMatk = status->rhw.matk;
variance = wMatk * status->rhw.wlv / 10;
min += wMatk - variance;
max += wMatk + variance;
}
if( sc && sc->data[SC_RECOGNIZEDSPELL] )
min = max;
if( sd && sd->right_weapon.overrefine > 0 ){
min++;
max += sd->right_weapon.overrefine - 1;
}
if(max > min)
hp += min+rnd()%(max-min);
else
hp += min;
}
}
// Global multipliers are applied after the MATK is applied
if (tsc && tsc->count) {
if (skill_id != NPC_EVILLAND && skill_id != BA_APPLEIDUN) {
if (tsc->data[SC_WATER_INSIGNIA] && tsc->data[SC_WATER_INSIGNIA]->val1 == 2)
global_bonus *= 1.1f;
}
}
if (skill_id == AB_HIGHNESSHEAL)
global_bonus *= 2 + 0.3f * (skill_lv - 1);
#endif
if (heal && tsc && tsc->count) {
uint8 penalty = 0;
if (tsc->data[SC_CRITICALWOUND])
penalty += tsc->data[SC_CRITICALWOUND]->val2;
if (tsc->data[SC_DEATHHURT])
penalty += 20;
if (tsc->data[SC_NORECOVER_STATE])
penalty = 100;
if (penalty > 0) {
#ifdef RENEWAL
penalty = cap_value(penalty, 1, 100);
global_bonus *= (100 - penalty) / 100.f;
#else
hp -= hp * penalty / 100;
#endif
}
}
#ifdef RENEWAL
hp = (int)(hp * global_bonus);
return (heal) ? max(1, hp) : hp;
#else
return hp;
#endif
}
/**
* Making Plagiarism and Reproduce check their own function
* Previous prevention for NPC skills, Wedding skills, and INF3_DIS_PLAGIA are removed since we use skill_copyable_db.txt [Cydh]
* @param sd: Player who will copy the skill
* @param skill_id: Target skill
* @return 0 - Cannot be copied; 1 - Can be copied by Plagiarism 2 - Can be copied by Reproduce
* @author Aru - for previous check; Jobbie for class restriction idea; Cydh expands the copyable skill
*/
static int8 skill_isCopyable(struct map_session_data *sd, uint16 skill_id) {
uint16 skill_idx = skill_get_index(skill_id);
if (!skill_idx)
return 0;
// Only copy skill that player doesn't have or the skill is old clone
if (sd->status.skill[skill_idx].id != 0 && sd->status.skill[skill_idx].flag != SKILL_FLAG_PLAGIARIZED)
return 0;
s_skill_copyable copyable = skill_db.find(skill_id)->copyable;
//Plagiarism only able to copy skill while SC_PRESERVE is not active and skill is copyable by Plagiarism
if (copyable.option & SKILL_COPY_PLAGIARISM && pc_checkskill(sd,RG_PLAGIARISM) && !sd->sc.data[SC_PRESERVE])
return 1;
//Reproduce can copy skill if SC__REPRODUCE is active and the skill is copyable by Reproduce
if (copyable.option & SKILL_COPY_REPRODUCE && pc_checkskill(sd,SC_REPRODUCE) && sd->sc.data[SC__REPRODUCE] && sd->sc.data[SC__REPRODUCE]->val1)
return 2;
return 0;
}
/**
* Check if the skill is ok to cast and when.
* Done before skill_check_condition_castbegin, requirement
* @param skill_id: Skill ID that casted
* @param sd: Player who casted
* @return true: Skill cannot be used, false: otherwise
* @author [MouseJstr]
*/
bool skill_isNotOk(uint16 skill_id, struct map_session_data *sd)
{
nullpo_retr(1,sd);
if (pc_has_permission(sd,PC_PERM_SKILL_UNCONDITIONAL))
return false; // can do any damn thing they want
if (skill_id == AL_TELEPORT && sd->skillitem == skill_id && sd->skillitemlv > 2)
return false; // Teleport lv 3 bypasses this check.[Inkfish]
struct map_data *mapdata = map_getmapdata(sd->bl.m);
if (mapdata->flag[MF_NOSKILL] && skill_id != ALL_EQSWITCH && !sd->skillitem) //Item skills bypass noskill
return true;
// Epoque:
// This code will compare the player's attack motion value which is influenced by ASPD before
// allowing a skill to be cast. This is to prevent no-delay ACT files from spamming skills such as
// AC_DOUBLE which do not have a skill delay and are not regarded in terms of attack motion.
if (!sd->state.autocast && sd->skillitem != skill_id && sd->canskill_tick &&
DIFF_TICK(gettick(),sd->canskill_tick) < (sd->battle_status.amotion * (battle_config.skill_amotion_leniency) / 100))
{// attempted to cast a skill before the attack motion has finished
return true;
}
if (skill_blockpc_get(sd, skill_id) != -1){
clif_skill_fail(sd,skill_id,USESKILL_FAIL_SKILLINTERVAL,0);
return true;
}
/**
* It has been confirmed on a official server (thanks to Yommy) that item-cast skills bypass all mapflag restrictions
* Also, without this check, an exploit where an item casting + healing (or any other kind buff) isn't deleted after used on a restricted map
*/
if( sd->skillitem == skill_id && !sd->skillitem_keep_requirement && !sd->state.abra_flag)
return false;
uint32 skill_nocast = skill_get_nocast(skill_id);
// Check skill restrictions [Celest]
if( (skill_nocast&1 && !mapdata_flag_vs2(mapdata)) ||
(skill_nocast&2 && mapdata->flag[MF_PVP]) ||
(skill_nocast&4 && mapdata_flag_gvg2_no_te(mapdata)) ||
(skill_nocast&8 && mapdata->flag[MF_BATTLEGROUND]) ||
(skill_nocast&16 && mapdata_flag_gvg2_te(mapdata)) || // WOE:TE
(mapdata->zone && skill_nocast&(mapdata->zone) && mapdata->flag[MF_RESTRICTED]) ){
clif_msg(sd, SKILL_CANT_USE_AREA); // This skill cannot be used within this area
return true;
}
if( sd->sc.data[SC_ALL_RIDING] )
return true; //You can't use skills while in the new mounts (The client doesn't let you, this is to make cheat-safe)
switch (skill_id) {
case AL_WARP:
case RETURN_TO_ELDICASTES:
case ALL_GUARDIAN_RECALL:
case ECLAGE_RECALL:
if(mapdata->flag[MF_NOWARP]) {
clif_skill_teleportmessage(sd,0);
return true;
}
return false;
case AL_TELEPORT:
case SC_DIMENSIONDOOR:
case ALL_ODINS_RECALL:
case WE_CALLALLFAMILY:
if(mapdata->flag[MF_NOTELEPORT]) {
clif_skill_teleportmessage(sd,0);
return true;
}
return false; // gonna be checked in 'skill_castend_nodamage_id'
case WE_CALLPARTNER:
case WE_CALLPARENT:
case WE_CALLBABY:
if (mapdata->flag[MF_NOMEMO]) {
clif_skill_teleportmessage(sd,1);
return true;
}
break;
case MC_VENDING:
case ALL_BUYING_STORE:
if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return true;
}
if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return true;
}
if( npc_isnear(&sd->bl) ) {
// uncomment to send msg_txt.
//char output[150];
//sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
//clif_displaymessage(sd->fd, output);
clif_skill_fail(sd,skill_id,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
return true;
}
if (skill_id == MC_VENDING && pc_check_security(sd,SECU_VENDING_OPEN))
return true;
else if (skill_id == ALL_BUYING_STORE && pc_check_security(sd,SECU_BUYINGSTORE_OPEN))
return true;
// Market Clone [AnnieRuru/Dastgir]
if ( sd->market_clone_id ) {
clif_messagecolor(&sd->bl,color_table[COLOR_RED], "You can't use vending while you already have a market clone.", false, SELF);
return true;
}
case MC_IDENTIFY:
return false; // always allowed
case WZ_ICEWALL:
// noicewall flag [Valaris]
if (mapdata->flag[MF_NOICEWALL]) {
clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return true;
}
break;
case GC_DARKILLUSION:
if( mapdata_flag_gvg2(mapdata) ) {
clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return true;
}
break;
case GD_EMERGENCYCALL:
case GD_ITEMEMERGENCYCALL:
if (
!(battle_config.emergency_call&((is_agit_start())?2:1)) ||
!(battle_config.emergency_call&(mapdata_flag_gvg2(mapdata)?8:4)) ||
(battle_config.emergency_call&16 && mapdata->flag[MF_NOWARPTO] && !(mapdata->flag[MF_GVG_CASTLE] || mapdata->flag[MF_GVG_TE_CASTLE]))
) {
clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0);
return true;
}
break;
case WM_SIRCLEOFNATURE:
case WM_SOUND_OF_DESTRUCTION:
case WM_LULLABY_DEEPSLEEP:
case WM_SATURDAY_NIGHT_FEVER:
if( !mapdata_flag_vs(mapdata) ) {
clif_skill_teleportmessage(sd,2); // This skill uses this msg instead of skill fails.
return true;
}
break;
//case TF_BACKSLIDING: //Gidz Mod For Ankle Snare & Spider Web (NOT WORKING ANYMORE REF to STATUS.C)
//case TK_HIGHJUMP: //Gidz Mod For Ankle Snare & Spider Web (NOT WORKING ANYMORE REF to STATUS.C)
case MO_BODYRELOCATION: //Gidz Mod For Ankle Snare & Spider Web
case NJ_SHADOWJUMP: //Gidz Mod For Ankle Snare & Spider Web
case KN_CHARGEATK: //Gidz Mod For Ankle Snare & Spider Web
//case TK_JUMPKICK: //Gidz Mod For Ankle Snare & Spider Web
if( sd && ( sd->sc.data[RG_CLOSECONFINE] || sd->sc.data[SC_ANKLE] || sd->sc.data[SC_SPIDERWEB] || sd->sc.data[SC_THORNSTRAP] || sd->sc.data[SC_VACUUM_EXTREME] ) ) { //Gidz Mod No Escape
clif_skill_fail(sd,skill_id,USESKILL_FAIL_LEVEL,0); //Gidz Mod No Escape
return true; //Gidz Mod No Escape
} //Gidz Mod No Escape
break; //Gidz Mod No Escape
}
return false;
}
/**
* Check if the homunculus skill is ok to be processed
* After checking from Homunculus side, also check the master condition
* @param hd: Homunculus who casted
* @param skill_id: Skill ID casted
* @param skill_lv: Skill level casted
* @return true: Skill cannot be used, false: otherwise
*/
bool skill_isNotOk_hom(struct homun_data *hd, uint16 skill_id, uint16 skill_lv)
{
struct map_session_data *sd = NULL;
struct status_change *sc;
int8 spiritball = 0;
nullpo_retr(true, hd);
spiritball = skill_get_spiritball(skill_id, skill_lv);
sd = hd->master;
sc = status_get_sc(&hd->bl);
if (!sd)
return true;
if (sc && !sc->count)
sc = NULL;
if (util::vector_exists(hd->blockskill, skill_id))
return true;
switch(skill_id) {
case HFLI_SBR44:
if (hom_get_intimacy_grade(hd) <= HOMGRADE_HATE_WITH_PASSION) {
clif_skill_fail(sd, skill_id, USESKILL_FAIL_RELATIONGRADE, 0);
return true;
}