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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
|
#include "battle.hpp"
#include <cstring>
#include <fstream>
#include "../common/cxxstdio.hpp"
#include "../common/random.hpp"
#include "../common/nullpo.hpp"
#include "clif.hpp"
#include "itemdb.hpp"
#include "map.hpp"
#include "mob.hpp"
#include "pc.hpp"
#include "skill.hpp"
#include "../poison.hpp"
struct Battle_Config battle_config;
/*==========================================
* 自分をロックしている対象の数を返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
static
int battle_counttargeted(struct block_list *bl, struct block_list *src,
ATK target_lv)
{
nullpo_ret(bl);
if (bl->type == BL::PC)
return pc_counttargeted((struct map_session_data *) bl, src,
target_lv);
else if (bl->type == BL::MOB)
return mob_counttargeted((struct mob_data *) bl, src, target_lv);
return 0;
}
/*==========================================
* 対象のClassを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_class(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->mob_class;
else if (bl->type == BL::PC)
return 0;
else
return 0;
}
/*==========================================
* 対象の方向を返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
DIR battle_get_dir(struct block_list *bl)
{
nullpo_retr(DIR::S, bl);
if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->dir;
else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->dir;
else
return DIR::S;
}
/*==========================================
* 対象のレベルを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_lv(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->stats[mob_stat::LV];
else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.base_level;
else
return 0;
}
/*==========================================
* 対象の射程を返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_range(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].range;
else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->attackrange;
else
return 0;
}
/*==========================================
* 対象のHPを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_hp(struct block_list *bl)
{
nullpo_retr(1, bl);
if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->hp;
else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.hp;
else
return 1;
}
/*==========================================
* 対象のMHPを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_max_hp(struct block_list *bl)
{
nullpo_retr(1, bl);
if (bl->type == BL::PC && ((struct map_session_data *) bl))
return ((struct map_session_data *) bl)->status.max_hp;
else
{
int max_hp = 1;
if (bl->type == BL::MOB && ((struct mob_data *) bl))
{
max_hp = ((struct mob_data *) bl)->stats[mob_stat::MAX_HP];
{
if (battle_config.monster_hp_rate != 100)
max_hp = (max_hp * battle_config.monster_hp_rate) / 100;
}
}
if (max_hp < 1)
max_hp = 1;
return max_hp;
}
}
/*==========================================
* 対象のStrを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_str(struct block_list *bl)
{
int str = 0;
eptr<struct status_change, StatusChange> sc_data;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::MOB && ((struct mob_data *) bl))
str = ((struct mob_data *) bl)->stats[mob_stat::STR];
else if (bl->type == BL::PC && ((struct map_session_data *) bl))
return ((struct map_session_data *) bl)->paramc[ATTR::STR];
if (str < 0)
str = 0;
return str;
}
/*==========================================
* 対象のAgiを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_agi(struct block_list *bl)
{
int agi = 0;
eptr<struct status_change, StatusChange> sc_data;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::MOB)
agi = ((struct mob_data *) bl)->stats[mob_stat::AGI];
else if (bl->type == BL::PC)
agi = ((struct map_session_data *) bl)->paramc[ATTR::AGI];
if (agi < 0)
agi = 0;
return agi;
}
/*==========================================
* 対象のVitを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_vit(struct block_list *bl)
{
int vit = 0;
eptr<struct status_change, StatusChange> sc_data;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::MOB)
vit = ((struct mob_data *) bl)->stats[mob_stat::VIT];
else if (bl->type == BL::PC)
vit = ((struct map_session_data *) bl)->paramc[ATTR::VIT];
if (vit < 0)
vit = 0;
return vit;
}
/*==========================================
* 対象のIntを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_int(struct block_list *bl)
{
int int_ = 0;
eptr<struct status_change, StatusChange> sc_data;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::MOB)
int_ = ((struct mob_data *) bl)->stats[mob_stat::INT];
else if (bl->type == BL::PC)
int_ = ((struct map_session_data *) bl)->paramc[ATTR::INT];
if (int_ < 0)
int_ = 0;
return int_;
}
/*==========================================
* 対象のDexを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_dex(struct block_list *bl)
{
int dex = 0;
eptr<struct status_change, StatusChange> sc_data;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::MOB)
dex = ((struct mob_data *) bl)->stats[mob_stat::DEX];
else if (bl->type == BL::PC)
dex = ((struct map_session_data *) bl)->paramc[ATTR::DEX];
if (dex < 0)
dex = 0;
return dex;
}
/*==========================================
* 対象のLukを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_luk(struct block_list *bl)
{
int luk = 0;
eptr<struct status_change, StatusChange> sc_data;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::MOB)
luk = ((struct mob_data *) bl)->stats[mob_stat::LUK];
else if (bl->type == BL::PC)
luk = ((struct map_session_data *) bl)->paramc[ATTR::LUK];
if (luk < 0)
luk = 0;
return luk;
}
/*==========================================
* 対象のFleeを返す(汎用)
* 戻りは整数で1以上
*------------------------------------------
*/
static
int battle_get_flee(struct block_list *bl)
{
int flee = 1;
eptr<struct status_change, StatusChange> sc_data;
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
flee = ((struct map_session_data *) bl)->flee;
else
flee = battle_get_agi(bl) + battle_get_lv(bl);
if (sc_data)
{
if (battle_is_unarmed(bl))
flee += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 3); // +25 for 200
flee += skill_power_bl(bl, SkillID::TMW_SPEED) >> 3;
}
if (flee < 1)
flee = 1;
return flee;
}
/*==========================================
* 対象のHitを返す(汎用)
* 戻りは整数で1以上
*------------------------------------------
*/
static
int battle_get_hit(struct block_list *bl)
{
int hit = 1;
eptr<struct status_change, StatusChange> sc_data;
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
hit = ((struct map_session_data *) bl)->hit;
else
hit = battle_get_dex(bl) + battle_get_lv(bl);
if (sc_data)
{
if (battle_is_unarmed(bl))
hit += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 4); // +12 for 200
}
if (hit < 1)
hit = 1;
return hit;
}
/*==========================================
* 対象の完全回避を返す(汎用)
* 戻りは整数で1以上
*------------------------------------------
*/
static
int battle_get_flee2(struct block_list *bl)
{
int flee2 = 1;
eptr<struct status_change, StatusChange> sc_data;
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
{
flee2 = battle_get_luk(bl) + 10;
flee2 +=
((struct map_session_data *) bl)->flee2 -
(((struct map_session_data *) bl)->paramc[ATTR::LUK] + 10);
}
else
flee2 = battle_get_luk(bl) + 1;
{
if (battle_is_unarmed(bl))
flee2 += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 3); // +25 for 200
flee2 += skill_power_bl(bl, SkillID::TMW_SPEED) >> 3;
}
if (flee2 < 1)
flee2 = 1;
return flee2;
}
/*==========================================
* 対象のクリティカルを返す(汎用)
* 戻りは整数で1以上
*------------------------------------------
*/
static
int battle_get_critical(struct block_list *bl)
{
int critical = 1;
eptr<struct status_change, StatusChange> sc_data;
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
{
critical = battle_get_luk(bl) * 2 + 10;
critical +=
((struct map_session_data *) bl)->critical -
((((struct map_session_data *) bl)->paramc[ATTR::LUK] * 3) + 10);
}
else
critical = battle_get_luk(bl) * 3 + 1;
if (critical < 1)
critical = 1;
return critical;
}
/*==========================================
* base_atkの取得
* 戻りは整数で1以上
*------------------------------------------
*/
static
int battle_get_baseatk(struct block_list *bl)
{
eptr<struct status_change, StatusChange> sc_data;
int batk = 1;
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
batk = ((struct map_session_data *) bl)->base_atk; //設定されているbase_atk
else
{ //それ以外なら
int str, dstr;
str = battle_get_str(bl); //STR
dstr = str / 10;
batk = dstr * dstr + str; //base_atkを計算する
}
if (batk < 1)
batk = 1; //base_atkは最低でも1
return batk;
}
/*==========================================
* 対象のAtkを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
static
int battle_get_atk(struct block_list *bl)
{
eptr<struct status_change, StatusChange> sc_data;
int atk = 0;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
atk = ((struct map_session_data *) bl)->watk;
else if (bl->type == BL::MOB)
atk = ((struct mob_data *) bl)->stats[mob_stat::ATK1];
if (atk < 0)
atk = 0;
return atk;
}
/*==========================================
* 対象の左手Atkを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
static
int battle_get_atk_(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->watk_;
else
return 0;
}
/*==========================================
* 対象のAtk2を返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
static
int battle_get_atk2(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->watk2;
else
{
int atk2 = 0;
if (bl->type == BL::MOB)
atk2 = ((struct mob_data *) bl)->stats[mob_stat::ATK2];
if (atk2 < 0)
atk2 = 0;
return atk2;
}
}
/*==========================================
* 対象の左手Atk2を返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
static
int battle_get_atk_2(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->watk_2;
else
return 0;
}
/*==========================================
* 対象のMAtk1を返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
static
int battle_get_matk1(struct block_list *bl)
{
eptr<struct status_change, StatusChange> sc_data;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::MOB)
{
int matk, int_ = battle_get_int(bl);
matk = int_ + (int_ / 5) * (int_ / 5);
return matk;
}
else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->matk1;
else
return 0;
}
/*==========================================
* 対象のMAtk2を返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
static
int battle_get_matk2(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
{
int matk, int_ = battle_get_int(bl);
matk = int_ + (int_ / 7) * (int_ / 7);
return matk;
}
else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->matk2;
else
return 0;
}
/*==========================================
* 対象のDefを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_def(struct block_list *bl)
{
eptr<struct status_change, StatusChange> sc_data;
int def = 0;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
{
def = ((struct map_session_data *) bl)->def;
}
else if (bl->type == BL::MOB)
{
def = ((struct mob_data *) bl)->stats[mob_stat::DEF];
}
if (def < 1000000)
{
if (sc_data)
{
//毒にかかっている時は減算
if (sc_data[StatusChange::SC_POISON].timer
&& bl->type != BL::PC)
def = def * 75 / 100;
}
}
if (def < 0)
def = 0;
return def;
}
/*==========================================
* 対象のMDefを返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_mdef(struct block_list *bl)
{
eptr<struct status_change, StatusChange> sc_data;
int mdef = 0;
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
mdef = ((struct map_session_data *) bl)->mdef;
else if (bl->type == BL::MOB)
mdef = ((struct mob_data *) bl)->stats[mob_stat::MDEF];
if (mdef < 1000000)
{
if (sc_data)
{
//バリアー状態時はMDEF100
if (mdef < 90 && sc_data[StatusChange::SC_MBARRIER].timer)
{
mdef += sc_data[StatusChange::SC_MBARRIER].val1;
if (mdef > 90)
mdef = 90;
}
}
}
if (mdef < 0)
mdef = 0;
return mdef;
}
/*==========================================
* 対象のDef2を返す(汎用)
* 戻りは整数で1以上
*------------------------------------------
*/
int battle_get_def2(struct block_list *bl)
{
eptr<struct status_change, StatusChange> sc_data;
int def2 = 1;
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
if (bl->type == BL::PC)
def2 = ((struct map_session_data *) bl)->def2;
else if (bl->type == BL::MOB)
def2 = ((struct mob_data *) bl)->stats[mob_stat::VIT];
if (sc_data)
{
if (sc_data[StatusChange::SC_POISON].timer
&& bl->type != BL::PC)
def2 = def2 * 75 / 100;
}
if (def2 < 1)
def2 = 1;
return def2;
}
/*==========================================
* 対象のMDef2を返す(汎用)
* 戻りは整数で0以上
*------------------------------------------
*/
int battle_get_mdef2(struct block_list *bl)
{
int mdef2 = 0;
nullpo_ret(bl);
if (bl->type == BL::MOB)
mdef2 =
((struct mob_data *) bl)->stats[mob_stat::INT] +
(((struct mob_data *) bl)->stats[mob_stat::VIT] >> 1);
else if (bl->type == BL::PC)
mdef2 =
((struct map_session_data *) bl)->mdef2 +
(((struct map_session_data *) bl)->paramc[ATTR::VIT] >> 1);
if (mdef2 < 0)
mdef2 = 0;
return mdef2;
}
/*==========================================
* 対象のSpeed(移動速度)を返す(汎用)
* 戻りは整数で1以上
* Speedは小さいほうが移動速度が速い
*------------------------------------------
*/
interval_t battle_get_speed(struct block_list *bl)
{
nullpo_retr(std::chrono::seconds(1), bl);
if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->speed;
else
{
interval_t speed = std::chrono::seconds(1);
if (bl->type == BL::MOB)
speed = static_cast<interval_t>(((struct mob_data *) bl)->stats[mob_stat::SPEED]);
return std::max(speed, std::chrono::milliseconds(1));
}
}
/*==========================================
* 対象のaDelay(攻撃時ディレイ)を返す(汎用)
* aDelayは小さいほうが攻撃速度が速い
*------------------------------------------
*/
// TODO figure out what all the doubling is about
interval_t battle_get_adelay(struct block_list *bl)
{
nullpo_retr(std::chrono::seconds(4), bl);
if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->aspd * 2;
else
{
eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
interval_t adelay = std::chrono::seconds(4);
int aspd_rate = 100;
if (bl->type == BL::MOB)
adelay = static_cast<interval_t>(((struct mob_data *) bl)->stats[mob_stat::ADELAY]);
if (sc_data)
{
if (sc_data[StatusChange::SC_SPEEDPOTION0].timer)
aspd_rate -= sc_data[StatusChange::SC_SPEEDPOTION0].val1;
// Fate's `haste' spell works the same as the above
if (sc_data[StatusChange::SC_HASTE].timer)
aspd_rate -= sc_data[StatusChange::SC_HASTE].val1;
}
if (aspd_rate != 100)
adelay = adelay * aspd_rate / 100;
return std::max(adelay, static_cast<interval_t>(battle_config.monster_max_aspd) * 2);
}
}
interval_t battle_get_amotion(struct block_list *bl)
{
nullpo_retr(std::chrono::seconds(2), bl);
if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->amotion;
else
{
eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
interval_t amotion = std::chrono::seconds(2);
int aspd_rate = 100;
if (bl->type == BL::MOB)
amotion = static_cast<interval_t>(mob_db[((struct mob_data *) bl)->mob_class].amotion);
if (sc_data)
{
if (sc_data[StatusChange::SC_SPEEDPOTION0].timer)
aspd_rate -= sc_data[StatusChange::SC_SPEEDPOTION0].val1;
if (sc_data[StatusChange::SC_HASTE].timer)
aspd_rate -= sc_data[StatusChange::SC_HASTE].val1;
}
if (aspd_rate != 100)
amotion = amotion * aspd_rate / 100;
return std::max(amotion, static_cast<interval_t>(battle_config.monster_max_aspd));
}
}
interval_t battle_get_dmotion(struct block_list *bl)
{
nullpo_retr(interval_t::zero(), bl);
if (bl->type == BL::MOB)
{
return static_cast<interval_t>(mob_db[((struct mob_data *) bl)->mob_class].dmotion);
}
else if (bl->type == BL::PC)
{
return ((struct map_session_data *) bl)->dmotion;
}
else
return std::chrono::seconds(2);
}
LevelElement battle_get_element(struct block_list *bl)
{
LevelElement ret = {2, Element::neutral};
nullpo_retr(ret, bl);
if (bl->type == BL::MOB) // 10の位=Lv*2、1の位=属性
ret = ((struct mob_data *) bl)->def_ele;
return ret;
}
int battle_get_party_id(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.party_id;
else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
if (md->master_id > 0)
return -md->master_id;
return -md->bl.id;
}
return 0;
}
Race battle_get_race(struct block_list *bl)
{
nullpo_retr(Race::formless, bl);
if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].race;
else if (bl->type == BL::PC)
return Race::demihuman;
else
return Race::formless;
}
MobMode battle_get_mode(struct block_list *bl)
{
nullpo_retr(MobMode::CAN_MOVE, bl);
if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].mode;
// とりあえず動くということで1
return MobMode::CAN_MOVE;
}
int battle_get_stat(SP stat_id, struct block_list *bl)
{
switch (stat_id)
{
case SP::STR:
return battle_get_str(bl);
case SP::AGI:
return battle_get_agi(bl);
case SP::DEX:
return battle_get_dex(bl);
case SP::VIT:
return battle_get_vit(bl);
case SP::INT:
return battle_get_int(bl);
case SP::LUK:
return battle_get_luk(bl);
default:
return 0;
}
}
// StatusChange系の所得
eptr<struct status_change, StatusChange> battle_get_sc_data(struct block_list *bl)
{
nullpo_retr(nullptr, bl);
switch (bl->type)
{
case BL::MOB:
return ((struct mob_data *)(bl))->sc_data;
case BL::PC:
return ((struct map_session_data *)(bl))->sc_data;
}
return nullptr;
}
short *battle_get_sc_count(struct block_list *bl)
{
nullpo_retr(NULL, bl);
if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->sc_count;
else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->sc_count;
return NULL;
}
Opt1 *battle_get_opt1(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt1;
else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt1;
else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt1;
return 0;
}
Opt2 *battle_get_opt2(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt2;
else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt2;
else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt2;
return 0;
}
Opt3 *battle_get_opt3(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt3;
else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt3;
else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt3;
return 0;
}
Option *battle_get_option(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->option;
else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->status.option;
else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->option;
return 0;
}
//-------------------------------------------------------------------
// ダメージの遅延
struct battle_delay_damage_
{
struct block_list *src, *target;
int damage;
int flag;
};
// 実際にHPを操作
int battle_damage(struct block_list *bl, struct block_list *target,
int damage, int flag)
{
nullpo_ret(target); //blはNULLで呼ばれることがあるので他でチェック
if (damage == 0)
return 0;
if (target->prev == NULL)
return 0;
if (bl)
{
if (bl->prev == NULL)
return 0;
}
if (damage < 0)
return battle_heal(bl, target, -damage, 0, flag);
if (target->type == BL::MOB)
{ // MOB
struct mob_data *md = (struct mob_data *) target;
if (md && md->skilltimer && md->state.skillcastcancel) // 詠唱妨害
skill_castcancel(target, 0);
return mob_damage(bl, md, damage, 0);
}
else if (target->type == BL::PC)
{ // PC
struct map_session_data *tsd = (struct map_session_data *) target;
return pc_damage(bl, tsd, damage);
}
return 0;
}
int battle_heal(struct block_list *bl, struct block_list *target, int hp,
int sp, int flag)
{
nullpo_ret(target); //blはNULLで呼ばれることがあるので他でチェック
if (target->type == BL::PC
&& pc_isdead((struct map_session_data *) target))
return 0;
if (hp == 0 && sp == 0)
return 0;
if (hp < 0)
return battle_damage(bl, target, -hp, flag);
if (target->type == BL::MOB)
return mob_heal((struct mob_data *) target, hp);
else if (target->type == BL::PC)
return pc_heal((struct map_session_data *) target, hp, sp);
return 0;
}
// 攻撃停止
int battle_stopattack(struct block_list *bl)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return mob_stopattack((struct mob_data *) bl);
else if (bl->type == BL::PC)
return pc_stopattack((struct map_session_data *) bl);
return 0;
}
// 移動停止
int battle_stopwalking(struct block_list *bl, int type)
{
nullpo_ret(bl);
if (bl->type == BL::MOB)
return mob_stop_walking((struct mob_data *) bl, type);
else if (bl->type == BL::PC)
return pc_stop_walking((struct map_session_data *) bl, type);
return 0;
}
/*==========================================
* ダメージ最終計算
*------------------------------------------
*/
static
int battle_calc_damage(struct block_list *, struct block_list *bl,
int damage, int div_,
SkillID, int, BF flag)
{
struct mob_data *md = NULL;
nullpo_ret(bl);
if (bl->type == BL::MOB)
md = (struct mob_data *) bl;
if (battle_config.skill_min_damage
|| bool(flag & BF::MISC))
{
if (div_ < 255)
{
if (damage > 0 && damage < div_)
damage = div_;
}
else if (damage > 0 && damage < 3)
damage = 3;
}
if (md != NULL && md->hp > 0 && damage > 0) // 反撃などのMOBスキル判定
mobskill_event(md, flag);
return damage;
}
static
struct Damage battle_calc_mob_weapon_attack(struct block_list *src,
struct block_list *target,
SkillID skill_num,
int skill_lv, int)
{
struct map_session_data *tsd = NULL;
struct mob_data *md = (struct mob_data *) src, *tmd = NULL;
int hitrate, flee, cri = 0, atkmin, atkmax;
int target_count = 1;
int def1 = battle_get_def(target);
int def2 = battle_get_def2(target);
int t_vit = battle_get_vit(target);
struct Damage wd {};
int damage, damage2 = 0;
DamageType type;
int div_;
BF flag;
int ac_flag = 0;
ATK dmg_lv = ATK::ZERO;
eptr<struct status_change, StatusChange> sc_data, t_sc_data;
nullpo_retr(wd, src);
nullpo_retr(wd, target);
nullpo_retr(wd, md);
sc_data = battle_get_sc_data(src);
// ターゲット
if (target->type == BL::PC)
tsd = (struct map_session_data *) target;
else if (target->type == BL::MOB)
tmd = (struct mob_data *) target;
MobMode t_mode = battle_get_mode(target);
t_sc_data = battle_get_sc_data(target);
flag = BF::SHORT | BF::WEAPON | BF::NORMAL; // 攻撃の種類の設定
// 回避率計算、回避判定は後で
flee = battle_get_flee(target);
if (battle_config.agi_penaly_type > 0
|| battle_config.vit_penaly_type > 0)
target_count +=
battle_counttargeted(target, src,
ATK(battle_config.agi_penaly_count_lv)); // FIXME
if (battle_config.agi_penaly_type > 0)
{
if (target_count >= battle_config.agi_penaly_count)
{
if (battle_config.agi_penaly_type == 1)
flee =
(flee *
(100 -
(target_count -
(battle_config.agi_penaly_count -
1)) * battle_config.agi_penaly_num)) / 100;
else if (battle_config.agi_penaly_type == 2)
flee -=
(target_count -
(battle_config.agi_penaly_count -
1)) * battle_config.agi_penaly_num;
if (flee < 1)
flee = 1;
}
}
hitrate = battle_get_hit(src) - flee + 80;
type = DamageType::NORMAL;
div_ = 1; // single attack
if (battle_config.enemy_str)
damage = battle_get_baseatk(src);
else
damage = 0;
{
atkmin = battle_get_atk(src);
atkmax = battle_get_atk2(src);
}
if (mob_db[md->mob_class].range > 3)
flag = (flag & ~BF::RANGEMASK) | BF::LONG;
if (atkmin > atkmax)
atkmin = atkmax;
cri = battle_get_critical(src);
cri -= battle_get_luk(target) * 3;
if (battle_config.enemy_critical_rate != 100)
{
cri = cri * battle_config.enemy_critical_rate / 100;
if (cri < 1)
cri = 1;
}
if (ac_flag)
cri = 1000;
if (tsd && tsd->critical_def)
cri = cri * (100 - tsd->critical_def) / 100;
if ((skill_num == SkillID::ZERO)
&& skill_lv >= 0 && battle_config.enemy_critical
&& random_::chance({cri, 1000}))
// 判定(スキルの場合は無視)
// 敵の判定
{
damage += atkmax;
type = DamageType::CRITICAL;
}
else
{
int vitbonusmax;
if (atkmax > atkmin)
damage += random_::in(atkmin, atkmax);
else
damage += atkmin;
if (skill_num != SkillID::ZERO && skill_num != SkillID::NEGATIVE)
{
flag = (flag & ~BF::SKILLMASK) | BF::SKILL;
}
{
// 対 象の防御力によるダメージの減少
// ディバインプロテクション(ここでいいのかな?)
if (def1 < 1000000)
{ //DEF, VIT無視
int t_def;
target_count =
1 + battle_counttargeted(target, src,
ATK(battle_config.vit_penaly_count_lv)); // FIXME
if (battle_config.vit_penaly_type > 0)
{
if (target_count >= battle_config.vit_penaly_count)
{
if (battle_config.vit_penaly_type == 1)
{
def1 =
(def1 *
(100 -
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num)) /
100;
def2 =
(def2 *
(100 -
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num)) /
100;
t_vit =
(t_vit *
(100 -
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num)) /
100;
}
else if (battle_config.vit_penaly_type == 2)
{
def1 -=
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num;
def2 -=
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num;
t_vit -=
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num;
}
if (def1 < 0)
def1 = 0;
if (def2 < 1)
def2 = 1;
if (t_vit < 1)
t_vit = 1;
}
}
t_def = def2 * 8 / 10;
vitbonusmax = (t_vit / 20) * (t_vit / 20) - 1;
{
damage = damage * (100 - def1) / 100;
damage -= t_def;
if (vitbonusmax > 0)
damage -= random_::in(0, vitbonusmax);
}
}
}
}
// 0未満だった場合1に補正
if (damage < 1)
damage = 1;
// 回避修正
if (hitrate < 1000000)
hitrate = ((hitrate > 95) ? 95 : ((hitrate < 5) ? 5 : hitrate));
if (type == DamageType::NORMAL && !random_::chance({hitrate, 100}))
{
damage = damage2 = 0;
dmg_lv = ATK::FLEE;
}
else
{
dmg_lv = ATK::DEF;
}
if (damage < 0)
damage = 0;
// 完全回避の判定
if (skill_num == SkillID::ZERO && skill_lv >= 0 && tsd != NULL
&& random_::chance({battle_get_flee2(target), 1000}))
{
damage = 0;
type = DamageType::FLEE2;
dmg_lv = ATK::LUCKY;
}
if (battle_config.enemy_perfect_flee)
{
if (skill_num == SkillID::ZERO && skill_lv >= 0 && tmd != NULL
&& random_::chance({battle_get_flee2(target), 1000}))
{
damage = 0;
type = DamageType::FLEE2;
dmg_lv = ATK::LUCKY;
}
}
// if(def1 >= 1000000 && damage > 0)
if (bool(t_mode & MobMode::PLANT) && damage > 0)
damage = 1;
damage = battle_calc_damage(src, target, damage, div_,
skill_num, skill_lv, flag);
wd.damage = damage;
wd.damage2 = 0;
wd.type = type;
wd.div_ = div_;
wd.amotion = battle_get_amotion(src);
wd.dmotion = battle_get_dmotion(target);
wd.flag = flag;
wd.dmg_lv = dmg_lv;
return wd;
}
int battle_is_unarmed(struct block_list *bl)
{
if (!bl)
return 0;
if (bl->type == BL::PC)
{
struct map_session_data *sd = (struct map_session_data *) bl;
return (sd->equip_index[EQUIP::SHIELD] == -1
&& sd->equip_index[EQUIP::WEAPON] == -1);
}
else
return 0;
}
/*
* =========================================================================
* PCの武器による攻撃
*-------------------------------------------------------------------------
*/
static
struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
struct block_list *target,
SkillID skill_num,
int skill_lv, int)
{
struct map_session_data *sd = (struct map_session_data *) src, *tsd =
NULL;
struct mob_data *tmd = NULL;
int hitrate, flee, cri = 0, atkmin, atkmax;
int dex, target_count = 1;
int def1 = battle_get_def(target);
int def2 = battle_get_def2(target);
int t_vit = battle_get_vit(target);
struct Damage wd {};
int damage, damage2;
DamageType type;
int div_;
BF flag;
ATK dmg_lv = ATK::ZERO;
eptr<struct status_change, StatusChange> sc_data, t_sc_data;
int atkmax_ = 0, atkmin_ = 0; //二刀流用
int watk, watk_;
bool da = false;
int ac_flag = 0;
int target_distance;
nullpo_retr(wd, src);
nullpo_retr(wd, target);
nullpo_retr(wd, sd);
// アタッカー
sc_data = battle_get_sc_data(src); //ステータス異常
sd->state.attack_type = BF::WEAPON; //攻撃タイプは武器攻撃
// ターゲット
if (target->type == BL::PC) //対象がPCなら
tsd = (struct map_session_data *) target; //tsdに代入(tmdはNULL)
else if (target->type == BL::MOB) //対象がMobなら
tmd = (struct mob_data *) target; //tmdに代入(tsdはNULL)
MobMode t_mode = battle_get_mode(target); //対象のMode
t_sc_data = battle_get_sc_data(target); //対象のステータス異常
flag = BF::SHORT | BF::WEAPON | BF::NORMAL; // 攻撃の種類の設定
// 回避率計算、回避判定は後で
flee = battle_get_flee(target);
if (battle_config.agi_penaly_type > 0 || battle_config.vit_penaly_type > 0) //AGI、VITペナルティ設定が有効
target_count += battle_counttargeted(target, src,
ATK(battle_config.agi_penaly_count_lv)); //対象の数を算出
if (battle_config.agi_penaly_type > 0)
{
if (target_count >= battle_config.agi_penaly_count)
{ //ペナルティ設定より対象が多い
if (battle_config.agi_penaly_type == 1) //回避率がagi_penaly_num%ずつ減少
flee =
(flee *
(100 -
(target_count -
(battle_config.agi_penaly_count -
1)) * battle_config.agi_penaly_num)) / 100;
else if (battle_config.agi_penaly_type == 2) //回避率がagi_penaly_num分減少
flee -=
(target_count -
(battle_config.agi_penaly_count -
1)) * battle_config.agi_penaly_num;
if (flee < 1)
flee = 1; //回避率は最低でも1
}
}
hitrate = battle_get_hit(src) - flee + 80; //命中率計算
{ // [fate] Reduce hit chance by distance
int dx = abs(src->x - target->x);
int dy = abs(src->y - target->y);
int malus_dist;
target_distance = max(dx, dy);
malus_dist =
max(0, target_distance - (skill_power(sd, SkillID::AC_OWL) / 75));
hitrate -= (malus_dist * (malus_dist + 1));
}
dex = battle_get_dex(src); //DEX
watk = battle_get_atk(src); //ATK
watk_ = battle_get_atk_(src); //ATK左手
type = DamageType::NORMAL;
div_ = 1; // single attack
{
damage = damage2 = battle_get_baseatk(&sd->bl); //damega,damega2初登場、base_atkの取得
}
if (sd->attackrange > 2)
{ // [fate] ranged weapon?
const int range_damage_bonus = 80; // up to 31.25% bonus for long-range hit
damage =
damage * (256 +
((range_damage_bonus * target_distance) /
sd->attackrange)) >> 8;
damage2 =
damage2 * (256 +
((range_damage_bonus * target_distance) /
sd->attackrange)) >> 8;
}
atkmin = atkmin_ = dex; //最低ATKはDEXで初期化?
sd->state.arrow_atk = 0; //arrow_atk初期化
if (sd->equip_index[EQUIP::WEAPON] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::WEAPON]])
atkmin =
atkmin * (80 +
sd->inventory_data[sd->equip_index[EQUIP::WEAPON]]->wlv * 20) / 100;
if (sd->equip_index[EQUIP::SHIELD] >= 0 && sd->inventory_data[sd->equip_index[EQUIP::SHIELD]])
atkmin_ =
atkmin_ * (80 +
sd->inventory_data[sd->equip_index[EQUIP::SHIELD]]->wlv * 20) /
100;
if (sd->status.weapon == ItemLook::BOW)
{ //武器が弓矢の場合
atkmin = watk * ((atkmin < watk) ? atkmin : watk) / 100; //弓用最低ATK計算
flag = (flag & ~BF::RANGEMASK) | BF::LONG; //遠距離攻撃フラグを有効
sd->state.arrow_atk = 1; //arrow_atk有効化
}
{
atkmax = watk;
atkmax_ = watk_;
}
if (atkmin > atkmax && !(sd->state.arrow_atk))
atkmin = atkmax; //弓は最低が上回る場合あり
if (atkmin_ > atkmax_)
atkmin_ = atkmax_;
if (sd->double_rate > 0 && skill_num == SkillID::ZERO && skill_lv >= 0)
da = random_::chance({sd->double_rate, 100});
// 過剰精錬ボーナス
if (sd->overrefine > 0)
damage += random_::in(1, sd->overrefine);
if (sd->overrefine_ > 0)
damage2 += random_::in(1, sd->overrefine_);
if (!da)
{ //ダブルアタックが発動していない
// クリティカル計算
cri = battle_get_critical(src);
if (sd->state.arrow_atk)
cri += sd->arrow_cri;
if (sd->status.weapon == ItemLook::_16)
// カタールの場合、クリティカルを倍に
cri <<= 1;
cri -= battle_get_luk(target) * 3;
if (ac_flag)
cri = 1000;
}
if (tsd && tsd->critical_def)
cri = cri * (100 - tsd->critical_def) / 100;
//ダブルアタックが発動していない
// 判定(スキルの場合は無視)
if (!da && skill_num == SkillID::ZERO && skill_lv >= 0
&& random_::chance({cri, 1000}))
{
damage += atkmax;
damage2 += atkmax_;
if (sd->atk_rate != 100)
{
damage = (damage * sd->atk_rate) / 100;
damage2 = (damage2 * sd->atk_rate) / 100;
}
if (sd->state.arrow_atk)
damage += sd->arrow_atk;
type = DamageType::CRITICAL;
}
else
{
int vitbonusmax;
if (atkmax > atkmin)
damage += random_::in(atkmin, atkmax);
else
damage += atkmin;
if (atkmax_ > atkmin_)
damage2 += random_::in(atkmin_, atkmax_);
else
damage2 += atkmin_;
if (sd->atk_rate != 100)
{
damage = (damage * sd->atk_rate) / 100;
damage2 = (damage2 * sd->atk_rate) / 100;
}
if (sd->state.arrow_atk)
{
if (sd->arrow_atk > 0)
damage += random_::in(0, sd->arrow_atk);
hitrate += sd->arrow_hit;
}
if (skill_num != SkillID::ZERO && skill_num != SkillID::NEGATIVE)
{
flag = (flag & ~BF::SKILLMASK) | BF::SKILL;
}
{
// 対 象の防御力によるダメージの減少
// ディバインプロテクション(ここでいいのかな?)
if (def1 < 1000000)
{ //DEF, VIT無視
int t_def;
target_count =
1 + battle_counttargeted(target, src,
ATK(battle_config.vit_penaly_count_lv)); // FIXME
if (battle_config.vit_penaly_type > 0)
{
if (target_count >= battle_config.vit_penaly_count)
{
if (battle_config.vit_penaly_type == 1)
{
def1 =
(def1 *
(100 -
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num)) /
100;
def2 =
(def2 *
(100 -
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num)) /
100;
t_vit =
(t_vit *
(100 -
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num)) /
100;
}
else if (battle_config.vit_penaly_type == 2)
{
def1 -=
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num;
def2 -=
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num;
t_vit -=
(target_count -
(battle_config.vit_penaly_count -
1)) * battle_config.vit_penaly_num;
}
if (def1 < 0)
def1 = 0;
if (def2 < 1)
def2 = 1;
if (t_vit < 1)
t_vit = 1;
}
}
t_def = def2 * 8 / 10;
vitbonusmax = (t_vit / 20) * (t_vit / 20) - 1;
{
{
damage = damage * (100 - def1) / 100;
damage -= t_def;
if (vitbonusmax > 0)
damage -= random_::in(0, vitbonusmax);
}
}
{
{
damage2 = damage2 * (100 - def1) / 100;
damage2 -= t_def;
if (vitbonusmax > 0)
damage2 -= random_::in(0, vitbonusmax);
}
}
}
}
}
// 精錬ダメージの追加
{ //DEF, VIT無視
damage += battle_get_atk2(src);
damage2 += battle_get_atk_2(src);
}
// 0未満だった場合1に補正
if (damage < 1)
damage = 1;
if (damage2 < 1)
damage2 = 1;
// スキル修正2(修練系)
// 修練ダメージ(右手のみ) ソニックブロー時は別処理(1撃に付き1/8適応)
{ //修練ダメージ無視
}
if (sd->perfect_hit > 0)
{
if (random_::chance({sd->perfect_hit, 100}))
hitrate = 1000000;
}
// 回避修正
hitrate = (hitrate < 5) ? 5 : hitrate;
if (type == DamageType::NORMAL && !random_::chance({hitrate, 100}))
{
damage = damage2 = 0;
dmg_lv = ATK::FLEE;
}
else
{
dmg_lv = ATK::DEF;
}
if (damage < 0)
damage = 0;
if (damage2 < 0)
damage2 = 0;
// 星のかけら、気球の適用
damage += sd->star;
damage2 += sd->star_;
// >二刀流の左右ダメージ計算誰かやってくれぇぇぇぇえええ!
// >map_session_data に左手ダメージ(atk,atk2)追加して
// >pc_calcstatus()でやるべきかな?
// map_session_data に左手武器(atk,atk2,ele,star,atkmods)追加して
// pc_calcstatus()でデータを入力しています
//左手のみ武器装備
if (sd->weapontype1 == ItemLook::NONE
&& sd->weapontype2 != ItemLook::NONE)
{
damage = damage2;
damage2 = 0;
}
// 右手、左手修練の適用
if (sd->status.weapon >= ItemLook::SINGLE_HANDED_COUNT)
{ // 二刀流か?
int dmg = damage, dmg2 = damage2;
// 右手修練(60% 〜 100%) 右手全般
damage = damage * 50 / 100;
if (dmg > 0 && damage < 1)
damage = 1;
// 左手修練(40% 〜 80%) 左手全般
damage2 = damage2 * 30 / 100;
if (dmg2 > 0 && damage2 < 1)
damage2 = 1;
}
else //二刀流でなければ左手ダメージは0
damage2 = 0;
// 右手,短剣のみ
if (da)
{ //ダブルアタックが発動しているか
div_ = 2;
damage += damage;
type = DamageType::DOUBLED;
}
if (sd->status.weapon == ItemLook::_16)
{
// カタール追撃ダメージ
damage2 = damage * 1 / 100;
if (damage > 0 && damage2 < 1)
damage2 = 1;
}
// 完全回避の判定
if (skill_num == SkillID::ZERO && skill_lv >= 0 && tsd != NULL && div_ < 255
&& random_::chance({battle_get_flee2(target), 1000}))
{
damage = damage2 = 0;
type = DamageType::FLEE2;
dmg_lv = ATK::LUCKY;
}
// 対象が完全回避をする設定がONなら
if (battle_config.enemy_perfect_flee)
{
if (skill_num == SkillID::ZERO && skill_lv >= 0 && tmd != NULL && div_ < 255
&& random_::chance({battle_get_flee2(target), 1000}))
{
damage = damage2 = 0;
type = DamageType::FLEE2;
dmg_lv = ATK::LUCKY;
}
}
//MobのModeに頑強フラグが立っているときの処理
if (bool(t_mode & MobMode::PLANT))
{
if (damage > 0)
damage = 1;
if (damage2 > 0)
damage2 = 1;
}
if (damage > 0 || damage2 > 0)
{
if (damage2 < 1) // ダメージ最終修正
damage =
battle_calc_damage(src, target, damage, div_, skill_num,
skill_lv, flag);
else if (damage < 1) // 右手がミス?
damage2 =
battle_calc_damage(src, target, damage2, div_, skill_num,
skill_lv, flag);
else
{ // 両 手/カタールの場合はちょっと計算ややこしい
int d1 = damage + damage2, d2 = damage2;
damage =
battle_calc_damage(src, target, damage + damage2, div_,
skill_num, skill_lv, flag);
damage2 = (d2 * 100 / d1) * damage / 100;
if (damage > 1 && damage2 < 1)
damage2 = 1;
damage -= damage2;
}
}
wd.damage = damage;
wd.damage2 = damage2;
wd.type = type;
wd.div_ = div_;
wd.amotion = battle_get_amotion(src);
wd.dmotion = battle_get_dmotion(target);
wd.flag = flag;
wd.dmg_lv = dmg_lv;
return wd;
}
/*==========================================
* 武器ダメージ計算
*------------------------------------------
*/
static
struct Damage battle_calc_weapon_attack(struct block_list *src,
struct block_list *target,
SkillID skill_num, int skill_lv,
int wflag)
{
struct Damage wd {};
nullpo_retr(wd, src);
nullpo_retr(wd, target);
if (src->type == BL::PC)
wd = battle_calc_pc_weapon_attack(src, target, skill_num, skill_lv, wflag); // weapon breaking [Valaris]
else if (src->type == BL::MOB)
wd = battle_calc_mob_weapon_attack(src, target, skill_num, skill_lv, wflag);
return wd;
}
/*==========================================
* 魔法ダメージ計算
*------------------------------------------
*/
static
struct Damage battle_calc_magic_attack(struct block_list *bl,
struct block_list *target,
SkillID skill_num, int skill_lv, int)
{
int mdef1 = battle_get_mdef(target);
int mdef2 = battle_get_mdef2(target);
int matk1, matk2, damage = 0, div_ = 1;
struct Damage md {};
int normalmagic_flag = 1;
struct map_session_data *sd = NULL;
nullpo_retr(md, bl);
nullpo_retr(md, target);
matk1 = battle_get_matk1(bl);
matk2 = battle_get_matk2(bl);
MobMode t_mode = battle_get_mode(target);
if (bl->type == BL::PC && (sd = (struct map_session_data *) bl))
{
sd->state.attack_type = BF::MAGIC;
if (sd->matk_rate != 100)
{
matk1 = matk1 * sd->matk_rate / 100;
matk2 = matk2 * sd->matk_rate / 100;
}
sd->state.arrow_atk = 0;
}
BF aflag = BF::MAGIC | BF::LONG | BF::SKILL;
if (normalmagic_flag)
{
// 一般魔法ダメージ計算
if (matk1 > matk2)
damage = random_::in(matk2, matk1);
else
damage = matk2;
{
{
damage = (damage * (100 - mdef1)) / 100;
damage -= mdef2;
}
}
if (damage < 1)
damage = 1;
}
if (damage < 0)
damage = 0;
div_ = skill_get_num(skill_num, skill_lv);
if (div_ > 1)
damage *= div_;
// if(mdef1 >= 1000000 && damage > 0)
if (bool(t_mode & MobMode::PLANT) && damage > 0)
damage = 1;
damage = battle_calc_damage(bl, target, damage, div_, skill_num, skill_lv, aflag); // 最終修正
md.damage = damage;
md.div_ = div_;
md.amotion = battle_get_amotion(bl);
md.dmotion = battle_get_dmotion(target);
md.damage2 = 0;
md.type = DamageType::NORMAL;
md.flag = aflag;
return md;
}
/*==========================================
* その他ダメージ計算
*------------------------------------------
*/
static
struct Damage battle_calc_misc_attack(struct block_list *bl,
struct block_list *target,
SkillID skill_num, int skill_lv, int)
{
struct map_session_data *sd = NULL;
int damage = 0, div_ = 1;
struct Damage md {};
int damagefix = 1;
BF aflag = BF::MISC | BF::LONG | BF::SKILL;
nullpo_retr(md, bl);
nullpo_retr(md, target);
if (bl->type == BL::PC && (sd = (struct map_session_data *) bl))
{
sd->state.attack_type = BF::MISC;
sd->state.arrow_atk = 0;
}
switch (skill_num)
{
case SkillID::NPC_SELFDESTRUCTION: // 自爆
damage = battle_get_hp(bl) - (bl == target ? 1 : 0);
damagefix = 0;
break;
}
if (damagefix)
{
if (damage < 1)
damage = 1;
}
div_ = skill_get_num(skill_num, skill_lv);
if (div_ > 1)
damage *= div_;
if (damage > 0
&& (damage < div_
|| (battle_get_def(target) >= 1000000
&& battle_get_mdef(target) >= 1000000)))
{
damage = div_;
}
damage = battle_calc_damage(bl, target, damage, div_, skill_num, skill_lv, aflag); // 最終修正
md.damage = damage;
md.div_ = div_;
md.amotion = battle_get_amotion(bl);
md.dmotion = battle_get_dmotion(target);
md.damage2 = 0;
md.type = DamageType::NORMAL;
md.flag = aflag;
return md;
}
/*==========================================
* ダメージ計算一括処理用
*------------------------------------------
*/
struct Damage battle_calc_attack(BF attack_type,
struct block_list *bl,
struct block_list *target, SkillID skill_num,
int skill_lv, int flag)
{
struct Damage d;
memset(&d, 0, sizeof(d));
switch (attack_type)
{
case BF::WEAPON:
return battle_calc_weapon_attack(bl, target, skill_num, skill_lv,
flag);
case BF::MAGIC:
return battle_calc_magic_attack(bl, target, skill_num, skill_lv,
flag);
case BF::MISC:
return battle_calc_misc_attack(bl, target, skill_num, skill_lv,
flag);
default:
if (battle_config.error_log)
PRINTF("battle_calc_attack: unknwon attack type ! %d\n",
attack_type);
break;
}
return d;
}
/*==========================================
* 通常攻撃処理まとめ
*------------------------------------------
*/
ATK battle_weapon_attack(struct block_list *src, struct block_list *target,
tick_t tick)
{
struct map_session_data *sd = NULL;
eptr<struct status_change, StatusChange> t_sc_data = battle_get_sc_data(target);
struct Damage wd;
nullpo_retr(ATK::ZERO, src);
nullpo_retr(ATK::ZERO, target);
if (src->type == BL::PC)
sd = (struct map_session_data *) src;
if (src->prev == NULL || target->prev == NULL)
return ATK::ZERO;
if (src->type == BL::PC && pc_isdead(sd))
return ATK::ZERO;
if (target->type == BL::PC
&& pc_isdead((struct map_session_data *) target))
return ATK::ZERO;
Opt1 *opt1 = battle_get_opt1(src);
if (opt1 != NULL && bool(*opt1))
{
battle_stopattack(src);
return ATK::ZERO;
}
if (battle_check_target(src, target, BCT_ENEMY) > 0 &&
battle_check_range(src, target, 0))
{
// 攻撃対象となりうるので攻撃
if (sd && sd->status.weapon == ItemLook::BOW)
{
if (sd->equip_index[EQUIP::ARROW] >= 0)
{
if (battle_config.arrow_decrement)
pc_delitem(sd, sd->equip_index[EQUIP::ARROW], 1, 0);
}
else
{
clif_arrow_fail(sd, 0);
return ATK::ZERO;
}
}
wd = battle_calc_weapon_attack(src, target, SkillID::ZERO, 0, 0);
// significantly increase injuries for hasted characters
if (wd.damage > 0 && t_sc_data[StatusChange::SC_HASTE].timer)
{
wd.damage = (wd.damage * (16 + t_sc_data[StatusChange::SC_HASTE].val1)) >> 4;
}
if (wd.damage > 0
&& t_sc_data[StatusChange::SC_PHYS_SHIELD].timer
&& target->type == BL::PC)
{
int reduction = t_sc_data[StatusChange::SC_PHYS_SHIELD].val1;
if (reduction > wd.damage)
reduction = wd.damage;
wd.damage -= reduction;
MAP_LOG_PC(((struct map_session_data *) target),
"MAGIC-ABSORB-DMG %d", reduction);
}
{
clif_damage(src, target, tick, wd.amotion, wd.dmotion,
wd.damage, wd.div_, wd.type, wd.damage2);
if (sd
&& (sd->status.weapon == ItemLook::_16
|| sd->status.weapon >= ItemLook::SINGLE_HANDED_COUNT)
&& wd.damage2 == 0)
clif_damage(src, target, tick + std::chrono::milliseconds(10),
wd.amotion, wd.dmotion, 0, 1, DamageType::NORMAL, 0);
}
MapBlockLock lock;
if (src->type == BL::PC)
{
int weapon_index = sd->equip_index[EQUIP::WEAPON];
int weapon = 0;
if (sd->inventory_data[weapon_index]
&& bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON))
weapon = sd->inventory_data[weapon_index]->nameid;
MAP_LOG("PC%d %d:%d,%d WPNDMG %s%d %d FOR %d WPN %d",
sd->status.char_id, src->m, src->x, src->y,
(target->type == BL::PC) ? "PC" : "MOB",
(target->type ==
BL::PC) ? ((struct map_session_data *) target)->
status.char_id : target->id,
battle_get_class(target),
wd.damage + wd.damage2, weapon);
}
if (target->type == BL::PC)
{
struct map_session_data *sd2 = (struct map_session_data *) target;
MAP_LOG("PC%d %d:%d,%d WPNINJURY %s%d %d FOR %d",
sd2->status.char_id, target->m, target->x, target->y,
(src->type == BL::PC) ? "PC" : "MOB",
(src->type == BL::PC)
? ((struct map_session_data *) src)->status.char_id
: src->id,
battle_get_class(src),
wd.damage + wd.damage2);
}
battle_damage(src, target, (wd.damage + wd.damage2), 0);
if (target->prev != NULL &&
(target->type != BL::PC
|| (target->type == BL::PC
&& !pc_isdead((struct map_session_data *) target))))
{
if (wd.damage > 0 || wd.damage2 > 0)
{
skill_additional_effect(src, target, SkillID::ZERO, 0);
}
}
if (sd)
{
if (bool(wd.flag & BF::WEAPON)
&& src != target
&& (wd.damage > 0 || wd.damage2 > 0))
{
int hp = 0, sp = 0;
if (sd->hp_drain_rate && wd.damage > 0
&& random_::chance({sd->hp_drain_rate, 100}))
{
hp += (wd.damage * sd->hp_drain_per) / 100;
}
if (sd->hp_drain_rate_ && wd.damage2 > 0
&& random_::chance({sd->hp_drain_rate_, 100}))
{
hp += (wd.damage2 * sd->hp_drain_per_) / 100;
}
if (sd->sp_drain_rate && wd.damage > 0
&& random_::chance({sd->sp_drain_rate, 100}))
{
sp += (wd.damage * sd->sp_drain_per) / 100;
}
if (sd->sp_drain_rate_ && wd.damage2 > 0
&& random_::chance({sd->sp_drain_rate_, 100}))
{
sp += (wd.damage2 * sd->sp_drain_per_) / 100;
}
if (hp || sp)
pc_heal(sd, hp, sp);
}
}
}
return wd.dmg_lv;
}
bool battle_check_undead(Race race, Element element)
{
if (battle_config.undead_detect_type == 0)
{
return element == Element::undead;
}
else if (battle_config.undead_detect_type == 1)
{
return race == Race::undead;
}
else
{
return element == Element::undead || race == Race::undead;
}
}
/*==========================================
* 敵味方判定(1=肯定,0=否定,-1=エラー)
* flag&0xf0000 = 0x00000:敵じゃないか判定(ret:1=敵ではない)
* = 0x10000:パーティー判定(ret:1=パーティーメンバ)
* = 0x20000:全て(ret:1=敵味方両方)
* = 0x40000:敵か判定(ret:1=敵)
* = 0x50000:パーティーじゃないか判定(ret:1=パーティでない)
*------------------------------------------
*/
int battle_check_target(struct block_list *src, struct block_list *target,
BCT flag)
{
int s_p, t_p;
struct block_list *ss = src;
nullpo_ret(src);
nullpo_ret(target);
if (flag & BCT_ENEMY)
{ // 反転フラグ
int ret = battle_check_target(src, target, flag & (BCT_PARTY | BCT_ALL));
if (ret != -1)
return !ret;
return -1;
}
if (flag & BCT_ALL)
{
if (target->type == BL::MOB || target->type == BL::PC)
return 1;
else
return -1;
}
if (target->type == BL::PC
&& ((struct map_session_data *) target)->invincible_timer)
return -1;
// Mobでmaster_idがあってspecial_mob_aiなら、召喚主を求める
if (src->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) src;
if (md && md->master_id > 0)
{
if (md->master_id == target->id) // 主なら肯定
return 1;
if (md->state.special_mob_ai)
{
if (target->type == BL::MOB)
{ //special_mob_aiで対象がMob
struct mob_data *tmd = (struct mob_data *) target;
if (tmd)
{
if (tmd->master_id != md->master_id) //召喚主が一緒でなければ否定
return 0;
else
{ //召喚主が一緒なので肯定したいけど自爆は否定
if (md->state.special_mob_ai > 2)
return 0;
else
return 1;
}
}
}
}
if ((ss = map_id2bl(md->master_id)) == NULL)
return -1;
}
}
if (src == target || ss == target) // 同じなら肯定
return 1;
if (target->type == BL::PC
&& pc_isinvisible((struct map_session_data *) target))
return -1;
if (src->prev == NULL || // 死んでるならエラー
(src->type == BL::PC && pc_isdead((struct map_session_data *) src)))
return -1;
if ((ss->type == BL::PC && target->type == BL::MOB) ||
(ss->type == BL::MOB && target->type == BL::PC))
return 0; // PCvsMOBなら否定
s_p = battle_get_party_id(ss);
t_p = battle_get_party_id(target);
if (flag & BCT_PARTY)
{
if (s_p && t_p && s_p == t_p) // 同じパーティなら肯定(味方)
return 1;
else // パーティ検索なら同じパーティじゃない時点で否定
return 0;
}
//PRINTF("ss:%d src:%d target:%d flag:0x%x %d %d ",ss->id,src->id,target->id,flag,src->type,target->type);
//PRINTF("p:%d %d g:%d %d\n",s_p,t_p,s_g,t_g);
if (ss->type == BL::PC && target->type == BL::PC)
{ // 両方PVPモードなら否定(敵)
if (map[ss->m].flag.pvp
|| pc_iskiller((struct map_session_data *) ss,
(struct map_session_data *) target))
{ // [MouseJstr]
if (battle_config.pk_mode)
return 1; // prevent novice engagement in pk_mode [Valaris]
else if (map[ss->m].flag.pvp_noparty && s_p > 0 && t_p > 0
&& s_p == t_p)
return 1;
return 0;
}
}
return 1; // 該当しないので無関係人物(まあ敵じゃないので味方)
}
/*==========================================
* 射程判定
*------------------------------------------
*/
int battle_check_range(struct block_list *src, struct block_list *bl,
int range)
{
int dx, dy;
struct walkpath_data wpd;
int arange;
nullpo_ret(src);
nullpo_ret(bl);
dx = abs(bl->x - src->x);
dy = abs(bl->y - src->y);
arange = ((dx > dy) ? dx : dy);
if (src->m != bl->m) // 違うマップ
return 0;
if (range > 0 && range < arange) // 遠すぎる
return 0;
if (arange < 2) // 同じマスか隣接
return 1;
// if(bl->type == BL_SKILL && ((struct skill_unit *)bl)->group->unit_id == 0x8d)
// return 1;
// 障害物判定
wpd.path_len = 0;
wpd.path_pos = 0;
wpd.path_half = 0;
if (path_search(&wpd, src->m, src->x, src->y, bl->x, bl->y, 0x10001) !=
-1)
return 1;
dx = (dx > 0) ? 1 : ((dx < 0) ? -1 : 0);
dy = (dy > 0) ? 1 : ((dy < 0) ? -1 : 0);
return (path_search(&wpd, src->m, src->x + dx, src->y + dy,
bl->x - dx, bl->y - dy, 0x10001) != -1) ? 1 : 0;
}
/*==========================================
* 設定ファイルを読み込む
*------------------------------------------
*/
int battle_config_read(const char *cfgName)
{
static int count = 0;
if ((count++) == 0)
{
battle_config.warp_point_debug = 0;
battle_config.enemy_critical = 0;
battle_config.enemy_critical_rate = 100;
battle_config.enemy_str = 1;
battle_config.enemy_perfect_flee = 0;
battle_config.cast_rate = 100;
battle_config.delay_rate = 100;
battle_config.delay_dependon_dex = 0;
battle_config.sdelay_attack_enable = 0;
battle_config.left_cardfix_to_right = 0;
battle_config.pc_skill_add_range = 0;
battle_config.skill_out_range_consume = 1;
battle_config.mob_skill_add_range = 0;
battle_config.pc_damage_delay = 1;
battle_config.defnotenemy = 1;
battle_config.random_monster_checklv = 1;
battle_config.attr_recover = 1;
battle_config.flooritem_lifetime = (int)std::chrono::duration_cast<std::chrono::milliseconds>(LIFETIME_FLOORITEM).count();
battle_config.item_auto_get = 0;
battle_config.drop_pickup_safety_zone = 20;
battle_config.item_first_get_time = 3000;
battle_config.item_second_get_time = 1000;
battle_config.item_third_get_time = 1000;
battle_config.base_exp_rate = 100;
battle_config.job_exp_rate = 100;
battle_config.pvp_exp = 1;
battle_config.gtb_pvp_only = 0;
battle_config.death_penalty_type = 0;
battle_config.death_penalty_base = 0;
battle_config.death_penalty_job = 0;
battle_config.zeny_penalty = 0;
battle_config.restart_hp_rate = 0;
battle_config.restart_sp_rate = 0;
battle_config.monster_hp_rate = 100;
battle_config.monster_max_aspd = 199;
battle_config.atc_gmonly = 0;
battle_config.gm_allskill = 0;
battle_config.gm_allequip = 0;
battle_config.gm_skilluncond = 0;
battle_config.skillfree = 0;
battle_config.skillup_limit = 0;
battle_config.wp_rate = 100;
battle_config.pp_rate = 100;
battle_config.monster_active_enable = 1;
battle_config.monster_loot_type = 0;
battle_config.mob_skill_use = 1;
battle_config.mob_count_rate = 100;
battle_config.quest_skill_learn = 0;
battle_config.quest_skill_reset = 1;
battle_config.basic_skill_check = 1;
battle_config.pc_invincible_time = 5000;
battle_config.skill_min_damage = 0;
battle_config.finger_offensive_type = 0;
battle_config.heal_exp = 0;
battle_config.resurrection_exp = 0;
battle_config.shop_exp = 0;
battle_config.combo_delay_rate = 100;
battle_config.item_check = 1;
battle_config.wedding_modifydisplay = 0;
battle_config.natural_healhp_interval = 6000;
battle_config.natural_healsp_interval = 8000;
battle_config.natural_heal_skill_interval = 10000;
battle_config.natural_heal_weight_rate = 50;
battle_config.itemheal_regeneration_factor = 1;
battle_config.item_name_override_grffile = 1;
battle_config.arrow_decrement = 1;
battle_config.max_aspd = 199;
battle_config.max_hp = 32500;
battle_config.max_sp = 32500;
battle_config.max_lv = 99; // [MouseJstr]
battle_config.max_parameter = 99;
battle_config.max_cart_weight = 8000;
battle_config.pc_skill_log = 0;
battle_config.mob_skill_log = 0;
battle_config.battle_log = 0;
battle_config.save_log = 0;
battle_config.error_log = 1;
battle_config.etc_log = 1;
battle_config.save_clothcolor = 0;
battle_config.undead_detect_type = 0;
battle_config.pc_auto_counter_type = 1;
battle_config.monster_auto_counter_type = 1;
battle_config.agi_penaly_type = 0;
battle_config.agi_penaly_count = 3;
battle_config.agi_penaly_num = 0;
battle_config.agi_penaly_count_lv = static_cast<int>(ATK::FLEE); // FIXME
battle_config.vit_penaly_type = 0;
battle_config.vit_penaly_count = 3;
battle_config.vit_penaly_num = 0;
battle_config.vit_penaly_count_lv = static_cast<int>(ATK::DEF); // FIXME
battle_config.pc_skill_reiteration = 0;
battle_config.monster_skill_reiteration = 0;
battle_config.pc_skill_nofootset = 0;
battle_config.monster_skill_nofootset = 0;
battle_config.pc_cloak_check_type = 0;
battle_config.monster_cloak_check_type = 0;
battle_config.mob_changetarget_byskill = 0;
battle_config.pc_attack_direction_change = 1;
battle_config.monster_attack_direction_change = 1;
battle_config.pc_undead_nofreeze = 0;
battle_config.pc_land_skill_limit = 1;
battle_config.monster_land_skill_limit = 1;
battle_config.party_skill_penaly = 1;
battle_config.monster_class_change_full_recover = 0;
battle_config.produce_item_name_input = 1;
battle_config.produce_potion_name_input = 1;
battle_config.making_arrow_name_input = 1;
battle_config.holywater_name_input = 1;
battle_config.display_delay_skill_fail = 1;
battle_config.chat_warpportal = 0;
battle_config.mob_warpportal = 0;
battle_config.dead_branch_active = 0;
battle_config.show_steal_in_same_party = 0;
battle_config.enable_upper_class = 0;
battle_config.pc_attack_attr_none = 0;
battle_config.mob_attack_attr_none = 1;
battle_config.mob_ghostring_fix = 0;
battle_config.gx_allhit = 0;
battle_config.gx_cardfix = 0;
battle_config.gx_dupele = 1;
battle_config.gx_disptype = 1;
battle_config.player_skill_partner_check = 1;
battle_config.hide_GM_session = 0;
battle_config.unit_movement_type = 0;
battle_config.invite_request_check = 1;
battle_config.skill_removetrap_type = 0;
battle_config.disp_experience = 0;
battle_config.prevent_logout = 1; // Added by RoVeRT
battle_config.maximum_level = 255; // Added by Valaris
battle_config.drops_by_luk = 0; // [Valaris]
battle_config.pk_mode = 0; // [Valaris]
battle_config.multi_level_up = 0; // [Valaris]
battle_config.backstab_bow_penalty = 0; // Akaru
battle_config.show_mob_hp = 0; // [Valaris]
battle_config.hack_info_GM_level = 60; // added by [Yor] (default: 60, GM level)
battle_config.any_warp_GM_min_level = 20; // added by [Yor]
battle_config.packet_ver_flag = 63; // added by [Yor]
battle_config.min_hair_style = 0;
battle_config.max_hair_style = 20;
battle_config.min_hair_color = 0;
battle_config.max_hair_color = 9;
battle_config.min_cloth_color = 0;
battle_config.max_cloth_color = 4;
battle_config.castrate_dex_scale = 150;
battle_config.area_size = 14;
battle_config.chat_lame_penalty = 2;
battle_config.chat_spam_threshold = 10;
battle_config.chat_spam_flood = 10;
battle_config.chat_spam_ban = 1;
battle_config.chat_spam_warn = 8;
battle_config.chat_maxline = 255;
battle_config.packet_spam_threshold = 2;
battle_config.packet_spam_flood = 30;
battle_config.packet_spam_kick = 1;
battle_config.mask_ip_gms = 1;
battle_config.mob_splash_radius = -1;
}
std::ifstream in(cfgName);
if (!in.is_open())
{
PRINTF("file not found: %s\n", cfgName);
return 1;
}
std::string line;
while (std::getline(in, line))
{
// s/{"\([a-zA-Z_0-9]*\)", &battle_config.\1}/BATTLE_CONFIG_VAR(\1)/
const struct
{
const char *str;
int *val;
} data[] =
{
{"warp_point_debug", &battle_config.warp_point_debug},
{"enemy_critical", &battle_config.enemy_critical},
{"enemy_critical_rate", &battle_config.enemy_critical_rate},
{"enemy_str", &battle_config.enemy_str},
{"enemy_perfect_flee", &battle_config.enemy_perfect_flee},
{"casting_rate", &battle_config.cast_rate},
{"delay_rate", &battle_config.delay_rate},
{"delay_dependon_dex", &battle_config.delay_dependon_dex},
{"skill_delay_attack_enable", &battle_config.sdelay_attack_enable},
{"left_cardfix_to_right", &battle_config.left_cardfix_to_right},
{"player_skill_add_range", &battle_config.pc_skill_add_range},
{"skill_out_range_consume", &battle_config.skill_out_range_consume},
{"monster_skill_add_range", &battle_config.mob_skill_add_range},
{"player_damage_delay", &battle_config.pc_damage_delay},
{"defunit_not_enemy", &battle_config.defnotenemy},
{"random_monster_checklv", &battle_config.random_monster_checklv},
{"attribute_recover", &battle_config.attr_recover},
{"flooritem_lifetime", &battle_config.flooritem_lifetime},
{"item_auto_get", &battle_config.item_auto_get},
{"drop_pickup_safety_zone", &battle_config.drop_pickup_safety_zone},
{"item_first_get_time", &battle_config.item_first_get_time},
{"item_second_get_time", &battle_config.item_second_get_time},
{"item_third_get_time", &battle_config.item_third_get_time},
{"base_exp_rate", &battle_config.base_exp_rate},
{"job_exp_rate", &battle_config.job_exp_rate},
{"pvp_exp", &battle_config.pvp_exp},
{"gtb_pvp_only", &battle_config.gtb_pvp_only},
{"death_penalty_type", &battle_config.death_penalty_type},
{"death_penalty_base", &battle_config.death_penalty_base},
{"death_penalty_job", &battle_config.death_penalty_job},
{"zeny_penalty", &battle_config.zeny_penalty},
{"restart_hp_rate", &battle_config.restart_hp_rate},
{"restart_sp_rate", &battle_config.restart_sp_rate},
{"monster_hp_rate", &battle_config.monster_hp_rate},
{"monster_max_aspd", &battle_config.monster_max_aspd},
{"atcommand_gm_only", &battle_config.atc_gmonly},
{"atcommand_spawn_quantity_limit", &battle_config.atc_spawn_quantity_limit},
{"gm_all_skill", &battle_config.gm_allskill},
{"gm_all_skill_add_abra", &battle_config.gm_allskill_addabra},
{"gm_all_equipment", &battle_config.gm_allequip},
{"gm_skill_unconditional", &battle_config.gm_skilluncond},
{"player_skillfree", &battle_config.skillfree},
{"player_skillup_limit", &battle_config.skillup_limit},
{"weapon_produce_rate", &battle_config.wp_rate},
{"potion_produce_rate", &battle_config.pp_rate},
{"monster_active_enable", &battle_config.monster_active_enable},
{"monster_loot_type", &battle_config.monster_loot_type},
{"mob_skill_use", &battle_config.mob_skill_use},
{"mob_count_rate", &battle_config.mob_count_rate},
{"quest_skill_learn", &battle_config.quest_skill_learn},
{"quest_skill_reset", &battle_config.quest_skill_reset},
{"basic_skill_check", &battle_config.basic_skill_check},
{"player_invincible_time", &battle_config.pc_invincible_time},
{"skill_min_damage", &battle_config.skill_min_damage},
{"finger_offensive_type", &battle_config.finger_offensive_type},
{"heal_exp", &battle_config.heal_exp},
{"resurrection_exp", &battle_config.resurrection_exp},
{"shop_exp", &battle_config.shop_exp},
{"combo_delay_rate", &battle_config.combo_delay_rate},
{"item_check", &battle_config.item_check},
{"wedding_modifydisplay", &battle_config.wedding_modifydisplay},
{"natural_healhp_interval", &battle_config.natural_healhp_interval},
{"natural_healsp_interval", &battle_config.natural_healsp_interval},
{"natural_heal_skill_interval", &battle_config.natural_heal_skill_interval},
{"natural_heal_weight_rate", &battle_config.natural_heal_weight_rate},
{"itemheal_regeneration_factor", &battle_config.itemheal_regeneration_factor},
{"item_name_override_grffile", &battle_config.item_name_override_grffile},
{"arrow_decrement", &battle_config.arrow_decrement},
{"max_aspd", &battle_config.max_aspd},
{"max_hp", &battle_config.max_hp},
{"max_sp", &battle_config.max_sp},
{"max_lv", &battle_config.max_lv},
{"max_parameter", &battle_config.max_parameter},
{"max_cart_weight", &battle_config.max_cart_weight},
{"player_skill_log", &battle_config.pc_skill_log},
{"monster_skill_log", &battle_config.mob_skill_log},
{"battle_log", &battle_config.battle_log},
{"save_log", &battle_config.save_log},
{"error_log", &battle_config.error_log},
{"etc_log", &battle_config.etc_log},
{"save_clothcolor", &battle_config.save_clothcolor},
{"undead_detect_type", &battle_config.undead_detect_type},
{"player_auto_counter_type", &battle_config.pc_auto_counter_type},
{"monster_auto_counter_type", &battle_config.monster_auto_counter_type},
{"agi_penaly_type", &battle_config.agi_penaly_type},
{"agi_penaly_count", &battle_config.agi_penaly_count},
{"agi_penaly_num", &battle_config.agi_penaly_num},
{"agi_penaly_count_lv", &battle_config.agi_penaly_count_lv},
{"vit_penaly_type", &battle_config.vit_penaly_type},
{"vit_penaly_count", &battle_config.vit_penaly_count},
{"vit_penaly_num", &battle_config.vit_penaly_num},
{"vit_penaly_count_lv", &battle_config.vit_penaly_count_lv},
{"player_skill_reiteration", &battle_config.pc_skill_reiteration},
{"monster_skill_reiteration", &battle_config.monster_skill_reiteration},
{"player_skill_nofootset", &battle_config.pc_skill_nofootset},
{"monster_skill_nofootset", &battle_config.monster_skill_nofootset},
{"player_cloak_check_type", &battle_config.pc_cloak_check_type},
{"monster_cloak_check_type", &battle_config.monster_cloak_check_type},
{"mob_changetarget_byskill", &battle_config.mob_changetarget_byskill},
{"player_attack_direction_change", &battle_config.pc_attack_direction_change},
{"monster_attack_direction_change", &battle_config.monster_attack_direction_change},
{"player_land_skill_limit", &battle_config.pc_land_skill_limit},
{"monster_land_skill_limit", &battle_config.monster_land_skill_limit},
{"party_skill_penaly", &battle_config.party_skill_penaly},
{"monster_class_change_full_recover", &battle_config.monster_class_change_full_recover},
{"produce_item_name_input", &battle_config.produce_item_name_input},
{"produce_potion_name_input", &battle_config.produce_potion_name_input},
{"making_arrow_name_input", &battle_config.making_arrow_name_input},
{"holywater_name_input", &battle_config.holywater_name_input},
{"display_delay_skill_fail", &battle_config.display_delay_skill_fail},
{"chat_warpportal", &battle_config.chat_warpportal},
{"mob_warpportal", &battle_config.mob_warpportal},
{"dead_branch_active", &battle_config.dead_branch_active},
{"show_steal_in_same_party", &battle_config.show_steal_in_same_party},
{"enable_upper_class", &battle_config.enable_upper_class},
{"mob_attack_attr_none", &battle_config.mob_attack_attr_none},
{"mob_ghostring_fix", &battle_config.mob_ghostring_fix},
{"pc_attack_attr_none", &battle_config.pc_attack_attr_none},
{"gx_allhit", &battle_config.gx_allhit},
{"gx_cardfix", &battle_config.gx_cardfix},
{"gx_dupele", &battle_config.gx_dupele},
{"gx_disptype", &battle_config.gx_disptype},
{"player_skill_partner_check", &battle_config.player_skill_partner_check},
{"hide_GM_session", &battle_config.hide_GM_session},
{"unit_movement_type", &battle_config.unit_movement_type},
{"invite_request_check", &battle_config.invite_request_check},
{"skill_removetrap_type", &battle_config.skill_removetrap_type},
{"disp_experience", &battle_config.disp_experience},
{"riding_weight", &battle_config.riding_weight},
{"prevent_logout", &battle_config.prevent_logout}, // Added by RoVeRT
{"alchemist_summon_reward", &battle_config.alchemist_summon_reward}, // [Valaris]
{"maximum_level", &battle_config.maximum_level}, // [Valaris]
{"drops_by_luk", &battle_config.drops_by_luk}, // [Valaris]
{"monsters_ignore_gm", &battle_config.monsters_ignore_gm}, // [Valaris]
{"pk_mode", &battle_config.pk_mode}, // [Valaris]
{"multi_level_up", &battle_config.multi_level_up}, // [Valaris]
{"backstab_bow_penalty", &battle_config.backstab_bow_penalty},
{"show_mob_hp", &battle_config.show_mob_hp}, // [Valaris]
{"hack_info_GM_level", &battle_config.hack_info_GM_level}, // added by [Yor]
{"any_warp_GM_min_level", &battle_config.any_warp_GM_min_level}, // added by [Yor]
{"packet_ver_flag", &battle_config.packet_ver_flag}, // added by [Yor]
{"min_hair_style", &battle_config.min_hair_style}, // added by [MouseJstr]
{"max_hair_style", &battle_config.max_hair_style}, // added by [MouseJstr]
{"min_hair_color", &battle_config.min_hair_color}, // added by [MouseJstr]
{"max_hair_color", &battle_config.max_hair_color}, // added by [MouseJstr]
{"min_cloth_color", &battle_config.min_cloth_color}, // added by [MouseJstr]
{"max_cloth_color", &battle_config.max_cloth_color}, // added by [MouseJstr]
{"castrate_dex_scale", &battle_config.castrate_dex_scale}, // added by [MouseJstr]
{"area_size", &battle_config.area_size}, // added by [MouseJstr]
{"chat_lame_penalty", &battle_config.chat_lame_penalty},
{"chat_spam_threshold", &battle_config.chat_spam_threshold},
{"chat_spam_flood", &battle_config.chat_spam_flood},
{"chat_spam_ban", &battle_config.chat_spam_ban},
{"chat_spam_warn", &battle_config.chat_spam_warn},
{"chat_maxline", &battle_config.chat_maxline},
{"packet_spam_threshold", &battle_config.packet_spam_threshold},
{"packet_spam_flood", &battle_config.packet_spam_flood},
{"packet_spam_kick", &battle_config.packet_spam_kick},
{"mask_ip_gms", &battle_config.mask_ip_gms},
{"mob_splash_radius", &battle_config.mob_splash_radius},
};
std::string w1, w2;
if (!split_key_value(line, &w1, &w2))
continue;
if (w1 == "import")
{
battle_config_read(w2.c_str());
continue;
}
for (auto datum : data)
if (w1 == datum.str)
{
*datum.val = config_switch(w2.c_str());
goto continue_outer;
}
PRINTF("WARNING: unknown battle conf key: %s\n", w1);
continue_outer:
;
}
if (--count == 0)
{
if (static_cast<interval_t>(battle_config.flooritem_lifetime) < std::chrono::seconds(1))
battle_config.flooritem_lifetime = (int)std::chrono::duration_cast<std::chrono::milliseconds>(LIFETIME_FLOORITEM).count();
if (battle_config.restart_hp_rate < 0)
battle_config.restart_hp_rate = 0;
else if (battle_config.restart_hp_rate > 100)
battle_config.restart_hp_rate = 100;
if (battle_config.restart_sp_rate < 0)
battle_config.restart_sp_rate = 0;
else if (battle_config.restart_sp_rate > 100)
battle_config.restart_sp_rate = 100;
if (battle_config.natural_healhp_interval < NATURAL_HEAL_INTERVAL.count())
battle_config.natural_healhp_interval = NATURAL_HEAL_INTERVAL.count();
if (battle_config.natural_healsp_interval < NATURAL_HEAL_INTERVAL.count())
battle_config.natural_healsp_interval = NATURAL_HEAL_INTERVAL.count();
if (battle_config.natural_heal_skill_interval < NATURAL_HEAL_INTERVAL.count())
battle_config.natural_heal_skill_interval = NATURAL_HEAL_INTERVAL.count();
if (battle_config.natural_heal_weight_rate < 50)
battle_config.natural_heal_weight_rate = 50;
if (battle_config.natural_heal_weight_rate > 101)
battle_config.natural_heal_weight_rate = 101;
battle_config.monster_max_aspd =
2000 - battle_config.monster_max_aspd * 10;
if (battle_config.monster_max_aspd < 10)
battle_config.monster_max_aspd = 10;
if (battle_config.monster_max_aspd > 1000)
battle_config.monster_max_aspd = 1000;
battle_config.max_aspd = 2000 - battle_config.max_aspd * 10;
if (battle_config.max_aspd < 10)
battle_config.max_aspd = 10;
if (battle_config.max_aspd > 1000)
battle_config.max_aspd = 1000;
if (battle_config.max_hp > 1000000)
battle_config.max_hp = 1000000;
if (battle_config.max_hp < 100)
battle_config.max_hp = 100;
if (battle_config.max_sp > 1000000)
battle_config.max_sp = 1000000;
if (battle_config.max_sp < 100)
battle_config.max_sp = 100;
if (battle_config.max_parameter < 10)
battle_config.max_parameter = 10;
if (battle_config.max_parameter > 10000)
battle_config.max_parameter = 10000;
if (battle_config.max_cart_weight > 1000000)
battle_config.max_cart_weight = 1000000;
if (battle_config.max_cart_weight < 100)
battle_config.max_cart_weight = 100;
battle_config.max_cart_weight *= 10;
if (battle_config.agi_penaly_count < 2)
battle_config.agi_penaly_count = 2;
if (battle_config.vit_penaly_count < 2)
battle_config.vit_penaly_count = 2;
if (battle_config.hack_info_GM_level < 0) // added by [Yor]
battle_config.hack_info_GM_level = 0;
else if (battle_config.hack_info_GM_level > 100)
battle_config.hack_info_GM_level = 100;
if (battle_config.any_warp_GM_min_level < 0) // added by [Yor]
battle_config.any_warp_GM_min_level = 0;
else if (battle_config.any_warp_GM_min_level > 100)
battle_config.any_warp_GM_min_level = 100;
if (battle_config.chat_spam_ban < 0)
battle_config.chat_spam_ban = 0;
else if (battle_config.chat_spam_ban > 32767)
battle_config.chat_spam_ban = 32767;
if (battle_config.chat_spam_flood < 0)
battle_config.chat_spam_flood = 0;
else if (battle_config.chat_spam_flood > 32767)
battle_config.chat_spam_flood = 32767;
if (battle_config.chat_spam_warn < 0)
battle_config.chat_spam_warn = 0;
else if (battle_config.chat_spam_warn > 32767)
battle_config.chat_spam_warn = 32767;
if (battle_config.chat_spam_threshold < 0)
battle_config.chat_spam_threshold = 0;
else if (battle_config.chat_spam_threshold > 32767)
battle_config.chat_spam_threshold = 32767;
if (battle_config.chat_maxline < 1)
battle_config.chat_maxline = 1;
else if (battle_config.chat_maxline > 512)
battle_config.chat_maxline = 512;
if (battle_config.packet_spam_threshold < 0)
battle_config.packet_spam_threshold = 0;
else if (battle_config.packet_spam_threshold > 32767)
battle_config.packet_spam_threshold = 32767;
if (battle_config.packet_spam_flood < 0)
battle_config.packet_spam_flood = 0;
else if (battle_config.packet_spam_flood > 32767)
battle_config.packet_spam_flood = 32767;
if (battle_config.packet_spam_kick < 0)
battle_config.packet_spam_kick = 0;
else if (battle_config.packet_spam_kick > 1)
battle_config.packet_spam_kick = 1;
if (battle_config.mask_ip_gms < 0)
battle_config.mask_ip_gms = 0;
else if (battle_config.mask_ip_gms > 1)
battle_config.mask_ip_gms = 1;
// at least 1 client must be accepted
if ((battle_config.packet_ver_flag & 63) == 0) // added by [Yor]
battle_config.packet_ver_flag = 63; // accept all clients
}
return 0;
}
|