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
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
|
// $Id: mob.c,v 1.7 2004/09/25 05:32:18 MouseJstr Exp $
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "timer.h"
#include "socket.h"
#include "db.h"
#include "nullpo.h"
#include "malloc.h"
#include "map.h"
#include "clif.h"
#include "intif.h"
#include "pc.h"
#include "status.h"
#include "mob.h"
#include "guild.h"
#include "itemdb.h"
#include "skill.h"
#include "battle.h"
#include "party.h"
#include "npc.h"
#include "log.h"
#include "showmsg.h"
#ifdef MEMWATCH
#include "memwatch.h"
#endif
#define MIN_MOBTHINKTIME 100
#define MOB_LAZYMOVEPERC 50 // Move probability in the negligent mode MOB (rate of 1000 minute)
#define MOB_LAZYWARPPERC 20 // Warp probability in the negligent mode MOB (rate of 1000 minute)
#define MAX_MOB_DB 2000 /* Change this to increase the table size in your mob_db to accomodate
numbers more than 2000 for mobs if you want to (and know what you're doing).
Be sure to note that 4001 to 4047 are for advanced classes. */
struct mob_db mob_db[2001];
#define CLASSCHANGE_BOSS_NUM 21
/*==========================================
* Local prototype declaration (only required thing)
*------------------------------------------
*/
static int distance(int,int,int,int);
static int mob_makedummymobdb(int);
static int mob_timer(int,unsigned int,int,int);
int mobskill_use(struct mob_data *md,unsigned int tick,int event);
int mobskill_deltimer(struct mob_data *md );
int mob_skillid2skillidx(int class_,int skillid);
int mobskill_use_id(struct mob_data *md,struct block_list *target,int skill_idx);
static int mob_unlocktarget(struct mob_data *md,int tick);
/*==========================================
* Mob is searched with a name.
*------------------------------------------
*/
int mobdb_searchname(const char *str)
{
int i;
for(i=0;i<sizeof(mob_db)/sizeof(mob_db[0]);i++){
if( strcmpi(mob_db[i].name,str)==0 || strcmp(mob_db[i].jname,str)==0 ||
memcmp(mob_db[i].name,str,24)==0 || memcmp(mob_db[i].jname,str,24)==0)
return i;
}
return 0;
}
/*==========================================
* Id Mob is checked.
*------------------------------------------
*/
int mobdb_checkid(const int id)
{
if (id <= 0 || id >= (sizeof(mob_db) / sizeof(mob_db[0])) || mob_db[id].name[0] == '\0')
return 0;
return id;
}
/*==========================================
* The minimum data set for MOB spawning
*------------------------------------------
*/
int mob_spawn_dataset(struct mob_data *md,const char *mobname,int class_)
{
nullpo_retr(0, md);
md->bl.prev=NULL;
md->bl.next=NULL;
if(strcmp(mobname,"--en--")==0)
memcpy(md->name,mob_db[class_].name,24);
else if(strcmp(mobname,"--ja--")==0)
memcpy(md->name,mob_db[class_].jname,24);
else
memcpy(md->name,mobname,24);
md->n = 0;
md->base_class = md->class_ = class_;
md->bl.id= npc_get_new_npc_id();
memset(&md->state,0,sizeof(md->state));
md->timer = -1;
md->target_id=0;
md->attacked_id=0;
md->speed=mob_db[class_].speed;
return 0;
}
/*==========================================
* The MOB appearance for one time (for scripts)
*------------------------------------------
*/
int mob_once_spawn(struct map_session_data *sd,char *mapname,
int x,int y,const char *mobname,int class_,int amount,const char *event)
{
struct mob_data *md=NULL;
int m,count,lv=255,r=class_;
int c,j=0;
if( sd )
lv=sd->status.base_level;
if( sd && strcmp(mapname,"this")==0)
m=sd->bl.m;
else
m=map_mapname2mapid(mapname);
if(m<0 || amount<=0 || (class_>=0 && class_<=1000) || class_>MAX_MOB_DB) // �l���ُ�Ȃ珢�����~�߂�
return 0;
if(class_<0){ // �����_���ɏ���
int i=0;
int j=-class_-1;
int k;
if(j>=0 && j<MAX_RANDOMMONSTER){
do{
class_=rand()%1000+1001;
k=rand()%1000000;
}while((mob_db[class_].max_hp <= 0 || mob_db[class_].summonper[j] <= k ||
(lv<mob_db[class_].lv && battle_config.random_monster_checklv)) && (i++) < 2000);
if(i>=2000){
class_=mob_db[0].summonper[j];
}
}else{
return 0;
}
// if(battle_config.etc_log)
// printf("mobclass=%d try=%d\n",class_,i);
}
if (sd) { //even if the coords were wrong, spawn mob anyways (but look for most suitable coords first) Got from Freya [Lupus]
if (x <= 0 || y <= 0) {
if (x <= 0) x = sd->bl.x + rand() % 3 - 1;
if (y <= 0) y = sd->bl.y + rand() % 3 - 1;
if ((c = map_getcell(m, x, y)) == 1 || c == 5) {
x = sd->bl.x;
y = sd->bl.y;
}
}
} else if (x <= 0 || y <= 0) {
printf("mob_once_spawn: %i at %s x:%i y:%i\n ??\n",class_,map[m].name,x,y); //got idea from Freya [Lupus]
do {
x = rand() % (map[m].xs - 2) + 1;
y = rand() % (map[m].ys - 2) + 1;
} while (((c = map_getcell(m, x, y)) == 1 || c == 5) && j++ < 64);
if (c == 1 || c == 5) { // not solved?
x = 0;
y = 0;
}
}
for(count=0;count<amount;count++){
md=(struct mob_data *)aCalloc(1,sizeof(struct mob_data));
memset(md, '\0', sizeof *md);
if(class_>4000) { // large/tiny mobs [Valaris]
md->size=2;
class_-=4000;
}
else if(class_>MAX_MOB_DB) {
md->size=1;
class_-=MAX_MOB_DB;
}
if(mob_db[class_].mode&0x02)
md->lootitem=(struct item *)aCalloc(LOOTITEM_SIZE,sizeof(struct item));
else
md->lootitem=NULL;
mob_spawn_dataset(md,mobname,class_);
md->bl.m=m;
md->bl.x=x;
md->bl.y=y;
if(r<0&&battle_config.dead_branch_active) md->mode=0x1+0x4+0x80; //�ړ����ăA�N�e�B�u�Ŕ�������
md->m =m;
md->x0=x;
md->y0=y;
md->xs=0;
md->ys=0;
md->spawndelay1=-1; // ��x�̂݃t���O
md->spawndelay2=-1; // ��x�̂݃t���O
memcpy(md->npc_event,event,strlen(event));
md->bl.type=BL_MOB;
map_addiddb(&md->bl);
mob_spawn(md->bl.id);
if(class_==1288) { // emperium hp based on defense level [Valaris]
struct guild_castle *gc=guild_mapname2gc(map[md->bl.m].name);
if(gc) {
mob_db[class_].max_hp+=2000*gc->defense;
md->hp=mob_db[class_].max_hp;
}
} // end addition [Valaris]
}
return (amount>0)?md->bl.id:0;
}
/*==========================================
* The MOB appearance for one time (& area specification for scripts)
*------------------------------------------
*/
int mob_once_spawn_area(struct map_session_data *sd,char *mapname,
int x0,int y0,int x1,int y1,
const char *mobname,int class_,int amount,const char *event)
{
int x,y,i,max,lx=-1,ly=-1,id=0;
int m;
if(strcmp(mapname,"this")==0)
m=sd->bl.m;
else
m=map_mapname2mapid(mapname);
max=(y1-y0+1)*(x1-x0+1)*3;
if(max>1000)max=1000;
if(m<0 || amount<=0 || (class_>=0 && class_<=1000) || class_>MAX_MOB_DB) // A summon is stopped if a value is unusual
return 0;
for(i=0;i<amount;i++){
int j=0;
do{
x=rand()%(x1-x0+1)+x0;
y=rand()%(y1-y0+1)+y0;
} while (map_getcell(m,x,y,CELL_CHKNOPASS) && (++j)<max);
// freya }while( ( (c=map_getcell(m,x,y))==1 || c==5)&& (++j)<max );
if(j>=max){
if(lx>=0){ // Since reference went wrong, the place which boiled before is used.
x=lx;
y=ly;
}else
return 0; // Since reference of the place which boils first went wrong, it stops.
}
if(x==0||y==0) printf("xory=0, x=%d,y=%d,x0=%d,y0=%d\n",x,y,x0,y0);
id=mob_once_spawn(sd,mapname,x,y,mobname,class_,1,event);
lx=x;
ly=y;
}
return id;
}
/*==========================================
* Summoning Guardians [Valaris]
*------------------------------------------
*/
int mob_spawn_guardian(struct map_session_data *sd,char *mapname,
int x,int y,const char *mobname,int class_,int amount,const char *event,int guardian)
{
struct mob_data *md=NULL;
int m,count=1,lv=255;
if( sd )
lv=sd->status.base_level;
if( sd && strcmp(mapname,"this")==0)
m=sd->bl.m;
else
m=map_mapname2mapid(mapname);
if(m<0 || amount<=0 || (class_>=0 && class_<=1000) || class_>MAX_MOB_DB) // Invalid monster classes
return 0;
if(class_<0)
return 0;
if(sd){
if(x<=0) x=sd->bl.x;
if(y<=0) y=sd->bl.y;
}
else if(x<=0 || y<=0)
printf("mob_spawn_guardian: ??\n");
for(count=0;count<amount;count++){
struct guild_castle *gc;
md=(struct mob_data *) aCalloc(sizeof(struct mob_data), 1);
if(md==NULL){
printf("mob_spawn_guardian: out of memory !\n");
exit(1);
}
memset(md, '\0', sizeof *md);
mob_spawn_dataset(md,mobname,class_);
md->bl.m=m;
md->bl.x=x;
md->bl.y=y;
md->m =m;
md->x0=x;
md->y0=y;
md->xs=0;
md->ys=0;
md->spawndelay1=-1; // Only once is a flag.
md->spawndelay2=-1; // Only once is a flag.
memcpy(md->npc_event,event,sizeof(md->npc_event));
md->bl.type=BL_MOB;
map_addiddb(&md->bl);
mob_spawn(md->bl.id);
gc=guild_mapname2gc(map[md->bl.m].name);
if(gc) {
mob_db[class_].max_hp+=2000*gc->defense;
if(guardian==0) { md->hp=gc->Ghp0; gc->GID0=md->bl.id; }
if(guardian==1) { md->hp=gc->Ghp1; gc->GID1=md->bl.id; }
if(guardian==2) { md->hp=gc->Ghp2; gc->GID2=md->bl.id; }
if(guardian==3) { md->hp=gc->Ghp3; gc->GID3=md->bl.id; }
if(guardian==4) { md->hp=gc->Ghp4; gc->GID4=md->bl.id; }
if(guardian==5) { md->hp=gc->Ghp5; gc->GID5=md->bl.id; }
if(guardian==6) { md->hp=gc->Ghp6; gc->GID6=md->bl.id; }
if(guardian==7) { md->hp=gc->Ghp7; gc->GID7=md->bl.id; }
}
}
return (amount>0)?md->bl.id:0;
}
/*==========================================
* The disregard ID is added to mob.
*------------------------------------------
*/
int mob_exclusion_add(struct mob_data *md,int type,int id)
{
nullpo_retr(0, md);
if(type==1)
md->exclusion_src=id;
if(type==2)
md->exclusion_party=id;
if(type==3)
md->exclusion_guild=id;
return 0;
}
/*==========================================
* The disregard ID of mob is checked. (TAGE?)
*------------------------------------------
*/
int mob_exclusion_check(struct mob_data *md,struct map_session_data *sd)
{
nullpo_retr(0, sd);
nullpo_retr(0, md);
if(sd->bl.type==BL_PC){
if(md->exclusion_src && md->exclusion_src==sd->bl.id)
return 1;
if(md->exclusion_party && md->exclusion_party==sd->status.party_id)
return 2;
if(md->exclusion_guild && md->exclusion_guild==sd->status.guild_id)
return 3;
}
return 0;
}
/*==========================================
* Appearance income of mob
*------------------------------------------
*/
int mob_get_viewclass(int class_)
{
return mob_db[class_].view_class;
}
int mob_get_sex(int class_)
{
return mob_db[class_].sex;
}
short mob_get_hair(int class_)
{
return mob_db[class_].hair;
}
short mob_get_hair_color(int class_)
{
return mob_db[class_].hair_color;
}
short mob_get_weapon(int class_)
{
return mob_db[class_].weapon;
}
short mob_get_shield(int class_)
{
return mob_db[class_].shield;
}
short mob_get_head_top(int class_)
{
return mob_db[class_].head_top;
}
short mob_get_head_mid(int class_)
{
return mob_db[class_].head_mid;
}
short mob_get_head_buttom(int class_)
{
return mob_db[class_].head_buttom;
}
short mob_get_clothes_color(int class_) // Add for player monster dye - Valaris
{
return mob_db[class_].clothes_color; // End
}
int mob_get_equip(int class_) // mob equip [Valaris]
{
return mob_db[class_].equip;
}
/*==========================================
* Is MOB in the state in which the present movement is possible or not?
*------------------------------------------
*/
int mob_can_move(struct mob_data *md)
{
nullpo_retr(0, md);
if(md->canmove_tick > gettick() || (md->opt1 > 0 && md->opt1 != 6) || md->option&2)
return 0;
// �A���N�����œ����Ȃ��Ƃ�
if( md->sc_data[SC_ANKLE].timer != -1 || //�A���N���X�l�A
md->sc_data[SC_AUTOCOUNTER].timer != -1 || //�I�[�g�J�E���^�[
md->sc_data[SC_BLADESTOP].timer != -1 || //���n���
md->sc_data[SC_SPIDERWEB].timer != -1 //�X�p�C�_�[�E�F�b�u
)
return 0;
return 1;
}
/*==========================================
* Time calculation concerning one step next to mob
*------------------------------------------
*/
static int calc_next_walk_step(struct mob_data *md)
{
nullpo_retr(0, md);
if(md->walkpath.path_pos>=md->walkpath.path_len)
return -1;
if(md->walkpath.path[md->walkpath.path_pos]&1)
return status_get_speed(&md->bl)*14/10;
return status_get_speed(&md->bl);
}
static int mob_walktoxy_sub(struct mob_data *md);
/*==========================================
* Mob Walk processing
*------------------------------------------
*/
static int mob_walk(struct mob_data *md,unsigned int tick,int data)
{
int moveblock;
int i;
static int dirx[8]={0,-1,-1,-1,0,1,1,1};
static int diry[8]={1,1,0,-1,-1,-1,0,1};
int x,y,dx,dy;
nullpo_retr(0, md);
md->state.state=MS_IDLE;
if(md->walkpath.path_pos>=md->walkpath.path_len || md->walkpath.path_pos!=data)
return 0;
md->walkpath.path_half ^= 1;
if(md->walkpath.path_half==0){
md->walkpath.path_pos++;
if(md->state.change_walk_target){
mob_walktoxy_sub(md);
return 0;
}
}
else {
if(md->walkpath.path[md->walkpath.path_pos]>=8)
return 1;
x = md->bl.x;
y = md->bl.y;
if(map_getcell(md->bl.m,x,y,CELL_CHKNOPASS)) {
mob_stop_walking(md,1);
return 0;
}
md->dir=md->walkpath.path[md->walkpath.path_pos];
dx = dirx[md->dir];
dy = diry[md->dir];
if (map_getcell(md->bl.m,x+dx,y+dy,CELL_CHKBASILICA) && !(status_get_mode(&md->bl)&0x20)) {
mob_stop_walking(md,1);
return 0;
}
if (map_getcell(md->bl.m,x+dx,y+dy,CELL_CHKNOPASS)) {
mob_walktoxy_sub(md);
return 0;
}
if (skill_check_moonlit (&md->bl,x+dx,y+dy)) {
mob_walktoxy_sub(md);
return 0;
}
moveblock = ( x/BLOCK_SIZE != (x+dx)/BLOCK_SIZE || y/BLOCK_SIZE != (y+dy)/BLOCK_SIZE);
md->state.state=MS_WALK;
map_foreachinmovearea(clif_moboutsight,md->bl.m,x-AREA_SIZE,y-AREA_SIZE,x+AREA_SIZE,y+AREA_SIZE,dx,dy,BL_PC,md);
x += dx;
y += dy;
if(md->min_chase>13)
md->min_chase--;
skill_unit_move(&md->bl,tick,0);
if(moveblock) map_delblock(&md->bl);
md->bl.x = x;
md->bl.y = y;
if(moveblock) map_addblock(&md->bl);
skill_unit_move(&md->bl,tick,1);
map_foreachinmovearea(clif_mobinsight,md->bl.m,x-AREA_SIZE,y-AREA_SIZE,x+AREA_SIZE,y+AREA_SIZE,-dx,-dy,BL_PC,md);
md->state.state=MS_IDLE;
if(md->option&4)
skill_check_cloaking(&md->bl);
}
if((i=calc_next_walk_step(md))>0){
i = i>>1;
if(i < 1 && md->walkpath.path_half == 0)
i = 1;
md->timer=add_timer(tick+i,mob_timer,md->bl.id,md->walkpath.path_pos);
md->state.state=MS_WALK;
if(md->walkpath.path_pos>=md->walkpath.path_len)
clif_fixmobpos(md); // �Ƃ܂����Ƃ��Ɉʒu�̍đ��M
}
return 0;
}
/*==========================================
* Attack processing of mob
*------------------------------------------
*/
static int mob_attack(struct mob_data *md,unsigned int tick,int data)
{
struct block_list *tbl=NULL;
struct map_session_data *tsd=NULL;
struct mob_data *tmd=NULL;
int mode,race,range;
nullpo_retr(0, md);
md->min_chase=13;
md->state.state=MS_IDLE;
md->state.skillstate=MSS_IDLE;
if( md->skilltimer!=-1 ) // �X�L���g�p��
return 0;
if(md->opt1>0 || md->option&2)
return 0;
if(md->sc_data[SC_AUTOCOUNTER].timer != -1)
return 0;
if(md->sc_data[SC_BLADESTOP].timer != -1)
return 0;
if((tbl=map_id2bl(md->target_id))==NULL){
md->target_id=0;
md->state.targettype = NONE_ATTACKABLE;
return 0;
}
if(tbl->type==BL_PC)
tsd=(struct map_session_data *)tbl;
else if(tbl->type==BL_MOB)
tmd=(struct mob_data *)tbl;
else
return 0;
if(tsd){
if( pc_isdead(tsd) || tsd->invincible_timer != -1 || pc_isinvisible(tsd) || md->bl.m != tbl->m || tbl->prev == NULL || distance(md->bl.x,md->bl.y,tbl->x,tbl->y)>=13 ){
md->target_id=0;
md->state.targettype = NONE_ATTACKABLE;
return 0;
}
}
if(tmd){
if(md->bl.m != tbl->m || tbl->prev == NULL || distance(md->bl.x,md->bl.y,tbl->x,tbl->y)>=13){
md->target_id=0;
md->state.targettype = NONE_ATTACKABLE;
return 0;
}
}
if(!md->mode)
mode=mob_db[md->class_].mode;
else
mode=md->mode;
race=mob_db[md->class_].race;
if(!(mode&0x80)){
md->target_id=0;
md->state.targettype = NONE_ATTACKABLE;
return 0;
}
if(tsd && !(mode&0x20) && (tsd->sc_data[SC_TRICKDEAD].timer != -1 || tsd->sc_data[SC_BASILICA].timer != -1 ||
((pc_ishiding(tsd) || tsd->state.gangsterparadise) && !((race == 4 || race == 6) && !tsd->perfect_hiding) ) ) ) {
md->target_id=0;
md->state.targettype = NONE_ATTACKABLE;
return 0;
}
range = mob_db[md->class_].range;
if(mode&1)
range++;
if(distance(md->bl.x,md->bl.y,tbl->x,tbl->y) > range)
return 0;
if(battle_config.monster_attack_direction_change)
md->dir=map_calc_dir(&md->bl, tbl->x,tbl->y ); // �����ݒ�
//clif_fixmobpos(md);
md->state.skillstate=MSS_ATTACK;
if( mobskill_use(md,tick,-2) ) // �X�L���g�p
return 0;
md->target_lv = battle_weapon_attack(&md->bl,tbl,tick,0);
if(!(battle_config.monster_cloak_check_type&2) && md->sc_data[SC_CLOAKING].timer != -1)
status_change_end(&md->bl,SC_CLOAKING,-1);
md->attackabletime = tick + status_get_adelay(&md->bl);
md->timer=add_timer(md->attackabletime,mob_timer,md->bl.id,0);
md->state.state=MS_ATTACK;
return 0;
}
/*==========================================
* The attack of PC which is attacking id is stopped.
* The callback function of clif_foreachclient
*------------------------------------------
*/
int mob_stopattacked(struct map_session_data *sd,va_list ap)
{
int id;
nullpo_retr(0, sd);
nullpo_retr(0, ap);
id=va_arg(ap,int);
if(sd->attacktarget==id)
pc_stopattack(sd);
return 0;
}
/*==========================================
* The timer in which the mob's states changes
*------------------------------------------
*/
int mob_changestate(struct mob_data *md,int state,int type)
{
unsigned int tick;
int i;
nullpo_retr(0, md);
if(md->timer != -1)
delete_timer(md->timer,mob_timer);
md->timer=-1;
md->state.state=state;
switch(state){
case MS_WALK:
if((i=calc_next_walk_step(md))>0){
i = i>>2;
md->timer=add_timer(gettick()+i,mob_timer,md->bl.id,0);
}
else
md->state.state=MS_IDLE;
break;
case MS_ATTACK:
tick = gettick();
i=DIFF_TICK(md->attackabletime,tick);
if(i>0 && i<2000)
md->timer=add_timer(md->attackabletime,mob_timer,md->bl.id,0);
else if(type) {
md->attackabletime = tick + status_get_amotion(&md->bl);
md->timer=add_timer(md->attackabletime,mob_timer,md->bl.id,0);
}
else {
md->attackabletime = tick + 1;
md->timer=add_timer(md->attackabletime,mob_timer,md->bl.id,0);
}
break;
case MS_DELAY:
md->timer=add_timer(gettick()+type,mob_timer,md->bl.id,0);
break;
case MS_DEAD:
skill_castcancel(&md->bl,0);
// mobskill_deltimer(md);
md->state.skillstate=MSS_DEAD;
md->last_deadtime=gettick();
// Since it died, all aggressors' attack to this mob is stopped.
clif_foreachclient(mob_stopattacked,md->bl.id);
skill_unit_move(&md->bl,gettick(),0);
status_change_clear(&md->bl,2); // �X�e�[�^�X�ُ����������
skill_clear_unitgroup(&md->bl); // �S�ẴX�L�����j�b�g�O���[�v���폜����
skill_cleartimerskill(&md->bl);
if(md->deletetimer!=-1)
delete_timer(md->deletetimer,mob_timer_delete);
md->deletetimer=-1;
md->hp=md->target_id=md->attacked_id=0;
md->state.targettype = NONE_ATTACKABLE;
break;
}
return 0;
}
/*==========================================
* timer processing of mob (timer function)
* It branches to a walk and an attack.
*------------------------------------------
*/
static int mob_timer(int tid,unsigned int tick,int id,int data)
{
struct mob_data *md;
struct block_list *bl;
if( (bl=map_id2bl(id)) == NULL ){ //�U�����Ă����G���������Ȃ��̂͐���̂悤��
return 1;
}
if(!bl || !bl->type || bl->type!=BL_MOB)
return 1;
nullpo_retr(1, md=(struct mob_data*)bl);
if(!md->bl.type || md->bl.type!=BL_MOB)
return 1;
if(md->timer != tid){
if(battle_config.error_log)
printf("mob_timer %d != %d\n",md->timer,tid);
return 0;
}
md->timer=-1;
if(md->bl.prev == NULL || md->state.state == MS_DEAD)
return 1;
map_freeblock_lock();
switch(md->state.state){
case MS_WALK:
mob_walk(md,tick,data);
break;
case MS_ATTACK:
mob_attack(md,tick,data);
break;
case MS_DELAY:
mob_changestate(md,MS_IDLE,0);
break;
default:
if(battle_config.error_log)
printf("mob_timer : %d ?\n",md->state.state);
break;
}
if (md->timer == -1)
mob_changestate(md,MS_WALK,0);
map_freeblock_unlock();
return 0;
}
/*==========================================
*
*------------------------------------------
*/
static int mob_walktoxy_sub(struct mob_data *md)
{
struct walkpath_data wpd;
int x,y;
static int dirx[8]={0,-1,-1,-1,0,1,1,1};
static int diry[8]={1,1,0,-1,-1,-1,0,1};
nullpo_retr(0, md);
if(path_search(&wpd,md->bl.m,md->bl.x,md->bl.y,md->to_x,md->to_y,md->state.walk_easy))
return 1;
x = md->bl.x+dirx[wpd.path[0]];
y = md->bl.y+diry[wpd.path[0]];
if (map_getcell(md->bl.m,x,y,CELL_CHKBASILICA) && !(status_get_mode(&md->bl)&0x20)) {
md->state.change_walk_target=0;
return 1;
}
memcpy(&md->walkpath,&wpd,sizeof(wpd));
md->state.change_walk_target=0;
mob_changestate(md,MS_WALK,0);
clif_movemob(md);
return 0;
}
/*==========================================
* mob move start
*------------------------------------------
*/
int mob_walktoxy(struct mob_data *md,int x,int y,int easy)
{
struct walkpath_data wpd;
nullpo_retr(0, md);
if(md->state.state == MS_WALK && path_search(&wpd,md->bl.m,md->bl.x,md->bl.y,x,y,easy) )
return 1;
md->state.walk_easy = easy;
md->to_x=x;
md->to_y=y;
if(md->state.state == MS_WALK)
md->state.change_walk_target=1;
else
return mob_walktoxy_sub(md);
return 0;
}
/*==========================================
* mob spawn with delay (timer function)
*------------------------------------------
*/
static int mob_delayspawn(int tid,unsigned int tick,int m,int n)
{
mob_spawn(m);
return 0;
}
/*==========================================
* spawn timing calculation
*------------------------------------------
*/
int mob_setdelayspawn(int id)
{
unsigned int spawntime,spawntime1,spawntime2,spawntime3;
struct mob_data *md;
struct block_list *bl;
if((bl=map_id2bl(id)) == NULL)
return -1;
if(!bl || !bl->type || bl->type!=BL_MOB)
return -1;
nullpo_retr(-1, md=(struct mob_data*)bl);
if(!md || md->bl.type!=BL_MOB)
return -1;
// Processing of MOB which is not revitalized
if(md->spawndelay1==-1 && md->spawndelay2==-1 && md->n==0){
map_deliddb(&md->bl);
if(md->lootitem) {
map_freeblock(md->lootitem);
md->lootitem=NULL;
}
map_freeblock(md); // Instead of [ of free ]
return 0;
}
spawntime1=md->last_spawntime+md->spawndelay1;
spawntime2=md->last_deadtime+md->spawndelay2;
spawntime3=gettick()+5000;
// spawntime = max(spawntime1,spawntime2,spawntime3);
if(DIFF_TICK(spawntime1,spawntime2)>0)
spawntime=spawntime1;
else
spawntime=spawntime2;
if(DIFF_TICK(spawntime3,spawntime)>0)
spawntime=spawntime3;
add_timer(spawntime,mob_delayspawn,id,0);
return 0;
}
/*==========================================
* Mob spawning. Initialization is also variously here.
*------------------------------------------
*/
int mob_spawn(int id)
{
int x=0,y=0,i=0,c;
unsigned int tick = gettick();
struct mob_data *md;
struct block_list *bl;
nullpo_retr(-1, bl=map_id2bl(id));
if(!bl || !bl->type || bl->type!=BL_MOB)
return -1;
nullpo_retr(-1, md=(struct mob_data*)bl);
if(!md || !md->bl.type || md->bl.type!=BL_MOB)
return -1;
md->last_spawntime=tick;
if( md->bl.prev!=NULL ){
// clif_clearchar_area(&md->bl,3);
// skill_unit_move(&md->bl,tick,0);
map_delblock(&md->bl);
}
else
md->class_ = md->base_class;
md->bl.m =md->m;
do {
if(md->x0==0 && md->y0==0){
x=rand()%(map[md->bl.m].xs-2)+1;
y=rand()%(map[md->bl.m].ys-2)+1;
} else {
x=md->x0+rand()%(md->xs+1)-md->xs/2;
y=md->y0+rand()%(md->ys+1)-md->ys/2;
}
i++;
} while(map_getcell(md->bl.m,x,y,CELL_CHKNOPASS) && i<50);
if(i>=50){
// if(battle_config.error_log==1)
// printf("MOB spawn error %d @ %s\n",id,map[md->bl.m].name);
add_timer(tick+5000,mob_delayspawn,id,0);
return 1;
}
md->to_x=md->bl.x=x;
md->to_y=md->bl.y=y;
md->dir=0;
md->target_dir=0;
memset(&md->state,0,sizeof(md->state));
md->attacked_id = 0;
md->target_id = 0;
md->move_fail_count = 0;
if(!md->speed)
md->speed = mob_db[md->class_].speed;
md->def_ele = mob_db[md->class_].element;
if(!md->level) // [Valaris]
md->level=mob_db[md->class_].lv;
md->master_id=0;
md->master_dist=0;
md->state.state = MS_IDLE;
md->state.skillstate = MSS_IDLE;
md->timer = -1;
md->last_thinktime = tick;
md->next_walktime = tick+rand()%50+5000;
md->attackabletime = tick;
md->canmove_tick = tick;
md->guild_id = 0;
if (md->class_ >= 1285 && md->class_ <= 1288) {
struct guild_castle *gc=guild_mapname2gc(map[md->bl.m].name);
if(gc)
md->guild_id = gc->guild_id;
}
md->deletetimer=-1;
md->skilltimer=-1;
for(i=0,c=tick-1000*3600*10;i<MAX_MOBSKILL;i++)
md->skilldelay[i] = c;
md->skillid=0;
md->skilllv=0;
memset(md->dmglog,0,sizeof(md->dmglog));
if(md->lootitem)
memset(md->lootitem,0,sizeof(md->lootitem));
md->lootitem_count = 0;
for(i=0;i<MAX_MOBSKILLTIMERSKILL;i++)
md->skilltimerskill[i].timer = -1;
for(i=0;i<MAX_STATUSCHANGE;i++) {
md->sc_data[i].timer=-1;
md->sc_data[i].val1 = md->sc_data[i].val2 = md->sc_data[i].val3 = md->sc_data[i].val4 =0;
}
md->sc_count=0;
md->opt1=md->opt2=md->opt3=md->option=0;
memset(md->skillunit,0,sizeof(md->skillunit));
memset(md->skillunittick,0,sizeof(md->skillunittick));
md->hp = status_get_max_hp(&md->bl);
if(md->hp<=0){
mob_makedummymobdb(md->class_);
md->hp = status_get_max_hp(&md->bl);
}
map_addblock(&md->bl);
skill_unit_move(&md->bl,tick,1);
clif_spawnmob(md);
return 0;
}
/*==========================================
* Distance calculation between two points
*------------------------------------------
*/
static int distance(int x0,int y0,int x1,int y1)
{
int dx,dy;
dx=abs(x0-x1);
dy=abs(y0-y1);
return dx>dy ? dx : dy;
}
/*==========================================
* The stop of MOB's attack
*------------------------------------------
*/
int mob_stopattack(struct mob_data *md)
{
md->target_id=0;
md->state.targettype = NONE_ATTACKABLE;
md->attacked_id=0;
return 0;
}
/*==========================================
* The stop of MOB's walking
*------------------------------------------
*/
int mob_stop_walking(struct mob_data *md,int type)
{
nullpo_retr(0, md);
if(md->state.state == MS_WALK || md->state.state == MS_IDLE) {
int dx=0,dy=0;
md->walkpath.path_len=0;
if(type&4){
dx=md->to_x-md->bl.x;
if(dx<0)
dx=-1;
else if(dx>0)
dx=1;
dy=md->to_y-md->bl.y;
if(dy<0)
dy=-1;
else if(dy>0)
dy=1;
}
md->to_x=md->bl.x+dx;
md->to_y=md->bl.y+dy;
if(dx!=0 || dy!=0){
mob_walktoxy_sub(md);
return 0;
}
mob_changestate(md,MS_IDLE,0);
}
if(type&0x01)
clif_fixmobpos(md);
if(type&0x02) {
int delay=status_get_dmotion(&md->bl);
unsigned int tick = gettick();
if(md->canmove_tick < tick)
md->canmove_tick = tick + delay;
}
return 0;
}
/*==========================================
* Reachability to a Specification ID existence place
*------------------------------------------
*/
int mob_can_reach(struct mob_data *md,struct block_list *bl,int range)
{
int dx,dy;
struct walkpath_data wpd;
int i;
nullpo_retr(0, md);
nullpo_retr(0, bl);
dx=abs(bl->x - md->bl.x);
dy=abs(bl->y - md->bl.y);
//=========== guildcastle guardian no search start===========
//when players are the guild castle member not attack them !
if(md->class_ >= 1285 && md->class_ <= 1287){
struct map_session_data *sd;
struct guild *g=NULL;
struct guild_castle *gc=guild_mapname2gc(map[bl->m].name);
if(gc && agit_flag==0) // Guardians will not attack during non-woe time [Valaris]
return 0; // end addition [Valaris]
if(bl && bl->type == BL_PC){
nullpo_retr(0, sd=(struct map_session_data *)bl);
if(!gc)
return 0;
if(gc && sd && sd->status.guild_id) {
g=guild_search(sd->status.guild_id); // don't attack guild members [Valaris]
if(g && g->guild_id == gc->guild_id)
return 0;
if(g && gc && guild_isallied(g,gc))
return 0;
}
}
}
//========== guildcastle guardian no search eof==============
if(bl && bl->type == BL_PC && battle_config.monsters_ignore_gm) { // option to have monsters ignore GMs [Valaris]
struct map_session_data *sd;
if((sd=(struct map_session_data *)bl) != NULL && pc_isGM(sd) >= battle_config.monsters_ignore_gm)
return 0;
}
if( md->bl.m != bl->m) // �Ⴄ��b�v
return 0;
if( range>0 && range < ((dx>dy)?dx:dy) ) // ��������
return 0;
if( md->bl.x==bl->x && md->bl.y==bl->y ) // �����}�X
return 1;
// Obstacle judging
wpd.path_len=0;
wpd.path_pos=0;
wpd.path_half=0;
if(path_search(&wpd,md->bl.m,md->bl.x,md->bl.y,bl->x,bl->y,0)!=-1)
return 1;
if(bl->type!=BL_PC && bl->type!=BL_MOB)
return 0;
// It judges whether it can adjoin or not.
dx=(dx>0)?1:((dx<0)?-1:0);
dy=(dy>0)?1:((dy<0)?-1:0);
if(path_search(&wpd,md->bl.m,md->bl.x,md->bl.y,bl->x-dx,bl->y-dy,0)!=-1)
return 1;
for(i=0;i<9;i++){
if(path_search(&wpd,md->bl.m,md->bl.x,md->bl.y,bl->x-1+i/3,bl->y-1+i%3,0)!=-1)
return 1;
}
return 0;
}
/*==========================================
* Determination for an attack of a monster
*------------------------------------------
*/
int mob_target(struct mob_data *md,struct block_list *bl,int dist)
{
struct map_session_data *sd;
struct status_change *sc_data;
short *option;
int mode,race;
nullpo_retr(0, md);
nullpo_retr(0, bl);
sc_data = status_get_sc_data(bl);
option = status_get_option(bl);
race=mob_db[md->class_].race;
if(!md->mode)
mode=mob_db[md->class_].mode;
else
mode=md->mode;
if(!(mode&0x80)) {
md->target_id = 0;
return 0;
}
// Nothing will be carried out if there is no mind of changing TAGE by TAGE ending.
if( (md->target_id > 0 && md->state.targettype == ATTACKABLE) && (!(mode&0x04) || rand()%100>25) &&
// if the monster was provoked ignore the above rule [celest]
!(md->state.provoke_flag && md->state.provoke_flag == bl->id))
return 0;
if(mode&0x20 || // Coercion is exerted if it is MVPMOB.
(sc_data && sc_data[SC_TRICKDEAD].timer == -1 && sc_data[SC_BASILICA].timer == -1 &&
( (option && !(*option&0x06) ) || race==4 || race==6) ) ) {
if(bl->type == BL_PC) {
nullpo_retr(0, sd = (struct map_session_data *)bl);
if(sd->invincible_timer != -1 || pc_isinvisible(sd))
return 0;
if(!(mode&0x20) && race!=4 && race!=6 && sd->state.gangsterparadise)
return 0;
}
md->target_id = bl->id; // Since there was no disturbance, it locks on to target.
if(bl->type == BL_PC || bl->type == BL_MOB)
md->state.targettype = ATTACKABLE;
else
md->state.targettype = NONE_ATTACKABLE;
if (md->state.provoke_flag)
md->state.provoke_flag = 0;
md->min_chase=dist+13;
if(md->min_chase>26)
md->min_chase=26;
}
return 0;
}
/*==========================================
* The ?? routine of an active monster
*------------------------------------------
*/
static int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap)
{
struct map_session_data *tsd=NULL;
struct mob_data *smd,*tmd=NULL;
int mode,race,dist,*pcc;
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, smd=va_arg(ap,struct mob_data *));
nullpo_retr(0, pcc=va_arg(ap,int *));
if(bl->type==BL_PC)
tsd=(struct map_session_data *)bl;
else if(bl->type==BL_MOB)
tmd=(struct mob_data *)bl;
else
return 0;
//�G��������
if(battle_check_target(&smd->bl,bl,BCT_ENEMY)==0)
return 0;
if(!smd->mode)
mode=mob_db[smd->class_].mode;
else
mode=smd->mode;
// �A�N�e�B�u�Ń^�[�Q�b�g�˒����ɂ���Ȃ�A���b�N����
if( mode&0x04 ){
race=mob_db[smd->class_].race;
//�Ώۂ�PC�̏ꍇ
if(tsd &&
!pc_isdead(tsd) &&
tsd->bl.m == smd->bl.m &&
tsd->invincible_timer == -1 &&
!pc_isinvisible(tsd) &&
(dist=distance(smd->bl.x,smd->bl.y,tsd->bl.x,tsd->bl.y))<9
)
{
if(mode&0x20 ||
(tsd->sc_data[SC_TRICKDEAD].timer == -1 && tsd->sc_data[SC_BASILICA].timer == -1 &&
((!pc_ishiding(tsd) && !tsd->state.gangsterparadise) || ((race == 4 || race == 6) && !tsd->perfect_hiding) ))){ // �W�Q���Ȃ�������
if( mob_can_reach(smd,bl,12) && // ���B�\������
rand()%1000<1000/(++(*pcc)) ){ // �͈͓�PC�œ��m���ɂ���
smd->target_id=tsd->bl.id;
smd->state.targettype = ATTACKABLE;
smd->min_chase=13;
}
}
}
//�Ώۂ�Mob�̏ꍇ
else if(tmd &&
tmd->bl.m == smd->bl.m &&
(dist=distance(smd->bl.x,smd->bl.y,tmd->bl.x,tmd->bl.y))<9
)
{
if( mob_can_reach(smd,bl,12) && // ���B�\������
rand()%1000<1000/(++(*pcc)) ){ // �͈͓��œ��m���ɂ���
smd->target_id=bl->id;
smd->state.targettype = ATTACKABLE;
smd->min_chase=13;
}
}
}
return 0;
}
/*==========================================
* loot monster item search
*------------------------------------------
*/
static int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
{
struct mob_data* md;
int mode,dist,*itc;
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, md=va_arg(ap,struct mob_data *));
nullpo_retr(0, itc=va_arg(ap,int *));
if(!md->mode)
mode=mob_db[md->class_].mode;
else
mode=md->mode;
if( !md->target_id && mode&0x02){
if(!md->lootitem || (battle_config.monster_loot_type == 1 && md->lootitem_count >= LOOTITEM_SIZE) )
return 0;
if(bl->m == md->bl.m && (dist=distance(md->bl.x,md->bl.y,bl->x,bl->y))<9){
if( mob_can_reach(md,bl,12) && // Reachability judging
rand()%1000<1000/(++(*itc)) ){ // It is made a probability, such as within the limits PC.
md->target_id=bl->id;
md->state.targettype = NONE_ATTACKABLE;
md->min_chase=13;
}
}
}
return 0;
}
/*==========================================
* The ?? routine of a link monster
*------------------------------------------
*/
static int mob_ai_sub_hard_linksearch(struct block_list *bl,va_list ap)
{
struct mob_data *tmd;
struct mob_data* md;
struct block_list *target;
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, tmd=(struct mob_data *)bl);
nullpo_retr(0, md=va_arg(ap,struct mob_data *));
nullpo_retr(0, target=va_arg(ap,struct block_list *));
// same family free in a range at a link monster -- it will be made to lock if MOB is
/* if( (md->target_id > 0 && md->state.targettype == ATTACKABLE) && mob_db[md->class_].mode&0x08){
if( tmd->class_==md->class_ && (!tmd->target_id || md->state.targettype == NONE_ATTACKABLE) && tmd->bl.m == md->bl.m){
if( mob_can_reach(tmd,target,12) ){ // Reachability judging
tmd->target_id=md->target_id;
tmd->state.targettype = ATTACKABLE;
tmd->min_chase=13;
}
}
}*/
if( md->attacked_id > 0 && mob_db[md->class_].mode&0x08){
if( tmd->class_==md->class_ && tmd->bl.m == md->bl.m && (!tmd->target_id || md->state.targettype == NONE_ATTACKABLE)){
if( mob_can_reach(tmd,target,12) ){ // Reachability judging
tmd->target_id=md->attacked_id;
tmd->state.targettype = ATTACKABLE;
tmd->min_chase=13;
}
}
}
return 0;
}
/*==========================================
* Processing of slave monsters
*------------------------------------------
*/
static int mob_ai_sub_hard_slavemob(struct mob_data *md,unsigned int tick)
{
struct mob_data *mmd=NULL;
struct block_list *bl;
int mode,race,old_dist;
nullpo_retr(0, md);
if((bl=map_id2bl(md->master_id)) != NULL )
mmd=(struct mob_data *)bl;
mode=mob_db[md->class_].mode;
// It is not main monster/leader.
if(!mmd || mmd->bl.type!=BL_MOB || mmd->bl.id!=md->master_id)
return 0;
// Since it is in the map on which the master is not, teleport is carried out and it pursues.
if( mmd->bl.m != md->bl.m ){
mob_warp(md,mmd->bl.m,mmd->bl.x,mmd->bl.y,3);
md->state.master_check = 1;
return 0;
}
// Distance with between slave and master is measured.
old_dist=md->master_dist;
md->master_dist=distance(md->bl.x,md->bl.y,mmd->bl.x,mmd->bl.y);
// Since the master was in near immediately before, teleport is carried out and it pursues.
if( old_dist<10 && md->master_dist>18){
mob_warp(md,-1,mmd->bl.x,mmd->bl.y,3);
md->state.master_check = 1;
return 0;
}
// Although there is the master, since it is somewhat far, it approaches.
if((!md->target_id || md->state.targettype == NONE_ATTACKABLE) && mob_can_move(md) &&
(md->walkpath.path_pos>=md->walkpath.path_len || md->walkpath.path_len==0) && md->master_dist<15){
int i=0,dx,dy,ret;
if(md->master_dist>4) {
do {
if(i<=5){
dx=mmd->bl.x - md->bl.x;
dy=mmd->bl.y - md->bl.y;
if(dx<0) dx+=(rand()%( (dx<-3)?3:-dx )+1);
else if(dx>0) dx-=(rand()%( (dx>3)?3:dx )+1);
if(dy<0) dy+=(rand()%( (dy<-3)?3:-dy )+1);
else if(dy>0) dy-=(rand()%( (dy>3)?3:dy )+1);
}else{
dx=mmd->bl.x - md->bl.x + rand()%7 - 3;
dy=mmd->bl.y - md->bl.y + rand()%7 - 3;
}
ret=mob_walktoxy(md,md->bl.x+dx,md->bl.y+dy,0);
i++;
} while(ret && i<10);
}
else {
do {
dx = rand()%9 - 5;
dy = rand()%9 - 5;
if( dx == 0 && dy == 0) {
dx = (rand()%1)? 1:-1;
dy = (rand()%1)? 1:-1;
}
dx += mmd->bl.x;
dy += mmd->bl.y;
ret=mob_walktoxy(md,mmd->bl.x+dx,mmd->bl.y+dy,0);
i++;
} while(ret && i<10);
}
md->next_walktime=tick+500;
md->state.master_check = 1;
}
// There is the master, the master locks a target and he does not lock.
if( (mmd->target_id>0 && mmd->state.targettype == ATTACKABLE) && (!md->target_id || md->state.targettype == NONE_ATTACKABLE) ){
struct map_session_data *sd=map_id2sd(mmd->target_id);
if(sd!=NULL && !pc_isdead(sd) && sd->invincible_timer == -1 && !pc_isinvisible(sd)){
race=mob_db[md->class_].race;
if(mode&0x20 ||
(sd->sc_data[SC_TRICKDEAD].timer == -1 && sd->sc_data[SC_BASILICA].timer == -1 &&
( (!pc_ishiding(sd) && !sd->state.gangsterparadise) || ((race == 4 || race == 6) && !sd->perfect_hiding) ) ) ){ // �W�Q���Ȃ�������
md->target_id=sd->bl.id;
md->state.targettype = ATTACKABLE;
md->min_chase=5+distance(md->bl.x,md->bl.y,sd->bl.x,sd->bl.y);
md->state.master_check = 1;
}
}
}
// There is the master, the master locks a target and he does not lock.
/* if( (md->target_id>0 && mmd->state.targettype == ATTACKABLE) && (!mmd->target_id || mmd->state.targettype == NONE_ATTACKABLE) ){
struct map_session_data *sd=map_id2sd(md->target_id);
if(sd!=NULL && !pc_isdead(sd) && sd->invincible_timer == -1 && !pc_isinvisible(sd)){
race=mob_db[mmd->class_].race;
if(mode&0x20 ||
(sd->sc_data[SC_TRICKDEAD].timer == -1 &&
(!(sd->status.option&0x06) || race==4 || race==6)
) ){ // It judges whether there is any disturbance.
mmd->target_id=sd->bl.id;
mmd->state.targettype = ATTACKABLE;
mmd->min_chase=5+distance(mmd->bl.x,mmd->bl.y,sd->bl.x,sd->bl.y);
}
}
}*/
return 0;
}
/*==========================================
* A lock of target is stopped and mob moves to a standby state.
*------------------------------------------
*/
static int mob_unlocktarget(struct mob_data *md,int tick)
{
nullpo_retr(0, md);
md->target_id=0;
md->state.targettype = NONE_ATTACKABLE;
md->state.skillstate=MSS_IDLE;
md->next_walktime=tick+rand()%3000+3000;
return 0;
}
/*==========================================
* Random walk
*------------------------------------------
*/
static int mob_randomwalk(struct mob_data *md,int tick)
{
const int retrycount=20;
int speed;
nullpo_retr(0, md);
speed=status_get_speed(&md->bl);
if(DIFF_TICK(md->next_walktime,tick)<0){
int i,x,y,c,d=12-md->move_fail_count;
int mask[8][2] = {{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1}};
if(d<5) d=5;
for(i=0;i<retrycount;i++){ // Search of a movable place
int r=rand();
x=r%(d*2+1)-d;
y=r/(d*2+1)%(d*2+1)-d;
if (md->target_dir){
if (x<0) x=0-x;
if (y<0) y=0-y;
x *= mask[md->target_dir-1][0];
y *= mask[md->target_dir-1][1];
}
x+=md->bl.x;
y+=md->bl.y;
if((map_getcell(md->bl.m,x,y,CELL_CHKPASS)) && mob_walktoxy(md,x,y,1)==0){
md->move_fail_count=0;
break;
}
if(i+1>=retrycount){
md->move_fail_count++;
md->target_dir = 0;
if(md->move_fail_count>1000){
if(battle_config.error_log)
printf("MOB cant move. random spawn %d, class = %d\n",md->bl.id,md->class_);
md->move_fail_count=0;
mob_spawn(md->bl.id);
}
}
}
for(i=c=0;i<md->walkpath.path_len;i++){ // The next walk start time is calculated.
if(md->walkpath.path[i]&1)
c+=speed*14/10;
else
c+=speed;
}
md->next_walktime = tick+rand()%3000+3000+c;
md->state.skillstate=MSS_WALK;
return 1;
}
return 0;
}
/*==========================================
* AI of MOB whose is near a Player
*------------------------------------------
*/
static int mob_ai_sub_hard(struct block_list *bl,va_list ap)
{
struct mob_data *md,*tmd=NULL;
struct map_session_data *tsd=NULL;
struct block_list *tbl=NULL;
struct flooritem_data *fitem;
unsigned int tick;
int i,dx,dy,ret,dist;
int attack_type=0;
int mode,race;
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, md=(struct mob_data*)bl);
tick=va_arg(ap,unsigned int);
if(DIFF_TICK(tick,md->last_thinktime)<MIN_MOBTHINKTIME)
return 0;
md->last_thinktime=tick;
if( md->skilltimer!=-1 || md->bl.prev==NULL ){ // Under a skill aria and death
if(DIFF_TICK(tick,md->next_walktime)>MIN_MOBTHINKTIME)
md->next_walktime=tick;
return 0;
}
if(!md->mode)
mode=mob_db[md->class_].mode;
else
mode=md->mode;
race=mob_db[md->class_].race;
// Abnormalities
if((md->opt1 > 0 && md->opt1 != 6) || md->state.state==MS_DELAY || md->sc_data[SC_BLADESTOP].timer != -1)
return 0;
if(!(mode&0x80) && md->target_id > 0)
md->target_id = 0;
if(md->attacked_id > 0 && mode&0x08){ // Link monster
struct map_session_data *asd=map_id2sd(md->attacked_id);
if(asd){
if(asd->invincible_timer == -1 && !pc_isinvisible(asd)){
map_foreachinarea(mob_ai_sub_hard_linksearch,md->bl.m,
md->bl.x-13,md->bl.y-13,
md->bl.x+13,md->bl.y+13,
BL_MOB,md,&asd->bl);
}
}
}
// It checks to see it was attacked first (if active, it is target change at 25% of probability).
if( mode>0 && md->attacked_id>0 && (!md->target_id || md->state.targettype == NONE_ATTACKABLE
|| (mode&0x04 && rand()%100<25 ) ) ){
struct block_list *abl=map_id2bl(md->attacked_id);
struct map_session_data *asd=NULL;
if(abl){
if(abl->type==BL_PC)
asd=(struct map_session_data *)abl;
if(asd==NULL || md->bl.m != abl->m || abl->prev == NULL || asd->invincible_timer != -1 || pc_isinvisible(asd) ||
(dist=distance(md->bl.x,md->bl.y,abl->x,abl->y))>=32 || battle_check_target(bl,abl,BCT_ENEMY)==0)
md->attacked_id=0;
else {
//�����������ꍇ�̓^�Q��ύX���Ȃ�
if (!md->target_id || (distance(md->bl.x,md->bl.y,abl->x,abl->y)<3)) {
md->target_id=md->attacked_id; // set target
md->state.targettype = ATTACKABLE;
attack_type = 1;
md->attacked_id=0;
md->min_chase=dist+13;
if(md->min_chase>26)
md->min_chase=26;
}
}
}
}
md->state.master_check = 0;
// Processing of slave monster
if( md->master_id > 0 && md->state.special_mob_ai==0)
mob_ai_sub_hard_slavemob(md,tick);
// �A�N�e�B�������X�^�[�̍��G (?? of a bitter taste TIVU monster)
if( (!md->target_id || md->state.targettype == NONE_ATTACKABLE) && mode&0x04 && !md->state.master_check &&
battle_config.monster_active_enable){
i=0;
if(md->state.special_mob_ai){
map_foreachinarea(mob_ai_sub_hard_activesearch,md->bl.m,
md->bl.x-AREA_SIZE*2,md->bl.y-AREA_SIZE*2,
md->bl.x+AREA_SIZE*2,md->bl.y+AREA_SIZE*2,
0,md,&i);
}else{
map_foreachinarea(mob_ai_sub_hard_activesearch,md->bl.m,
md->bl.x-AREA_SIZE*2,md->bl.y-AREA_SIZE*2,
md->bl.x+AREA_SIZE*2,md->bl.y+AREA_SIZE*2,
BL_PC,md,&i);
}
}
// The item search of a route monster
if( !md->target_id && mode&0x02 && !md->state.master_check){
i=0;
map_foreachinarea(mob_ai_sub_hard_lootsearch,md->bl.m,
md->bl.x-AREA_SIZE*2,md->bl.y-AREA_SIZE*2,
md->bl.x+AREA_SIZE*2,md->bl.y+AREA_SIZE*2,
BL_ITEM,md,&i);
}
// It will attack, if the candidate for an attack is.
if(md->target_id > 0){
if((tbl=map_id2bl(md->target_id))){
if(tbl->type==BL_PC)
tsd=(struct map_session_data *)tbl;
else if(tbl->type==BL_MOB)
tmd=(struct mob_data *)tbl;
if(tsd || tmd) {
if(tbl->m != md->bl.m || tbl->prev == NULL || (dist=distance(md->bl.x,md->bl.y,tbl->x,tbl->y))>=md->min_chase)
mob_unlocktarget(md,tick); // �ʃ}�b�v���A���E�O
else if( tsd && !(mode&0x20) && (tsd->sc_data[SC_TRICKDEAD].timer != -1 || tsd->sc_data[SC_BASILICA].timer != -1 ||
((pc_ishiding(tsd) || tsd->state.gangsterparadise) &&
!((race == 4 || race == 6) && !tsd->perfect_hiding) )) )
mob_unlocktarget(md,tick); // �X�L���Ȃǂɂ����G�W�Q
else if(!battle_check_range(&md->bl,tbl,mob_db[md->class_].range)){
// �U���͈͊O�Ȃ̂ňړ�
if(!(mode&1)){ // �ړ����Ȃ����[�h
mob_unlocktarget(md,tick);
return 0;
}
if( !mob_can_move(md) ) // �����Ȃ���Ԃɂ���
return 0;
md->state.skillstate=MSS_CHASE; // �ˌ����X�L��
mobskill_use(md,tick,-1);
// if(md->timer != -1 && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tsd->bl.x,tsd->bl.y)<2) )
if(md->timer != -1 && md->state.state!=MS_ATTACK && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tbl->x,tbl->y)<2) )
return 0; // ���Ɉړ���
if( !mob_can_reach(md,tbl,(md->min_chase>13)?md->min_chase:13) )
mob_unlocktarget(md,tick); // �ړ��ł��Ȃ��̂Ń^�Q�����iIW�Ƃ��H�j
else{
// �ǐ�
md->next_walktime=tick+500;
i=0;
do {
if(i==0){ // �ŏ���AEGIS�Ɠ������@�Ō���
dx=tbl->x - md->bl.x;
dy=tbl->y - md->bl.y;
if(dx<0) dx++;
else if(dx>0) dx--;
if(dy<0) dy++;
else if(dy>0) dy--;
}else{ // ���߂Ȃ�Athena��(�����_��)
dx=tbl->x - md->bl.x + rand()%3 - 1;
dy=tbl->y - md->bl.y + rand()%3 - 1;
}
/* if(path_search(&md->walkpath,md->bl.m,md->bl.x,md->bl.y,md->bl.x+dx,md->bl.y+dy,0)){
dx=tsd->bl.x - md->bl.x;
dy=tsd->bl.y - md->bl.y;
if(dx<0) dx--;
else if(dx>0) dx++;
if(dy<0) dy--;
else if(dy>0) dy++;
}*/
ret=mob_walktoxy(md,md->bl.x+dx,md->bl.y+dy,0);
i++;
} while(ret && i<5);
if(ret){ // �ړ��s�\�ȏ�����̍U���Ȃ�2������
if(dx<0) dx=2;
else if(dx>0) dx=-2;
if(dy<0) dy=2;
else if(dy>0) dy=-2;
mob_walktoxy(md,md->bl.x+dx,md->bl.y+dy,0);
}
}
} else { // �U���˒��͈͓�
md->state.skillstate=MSS_ATTACK;
if(md->state.state==MS_WALK)
mob_stop_walking(md,1); // ���s���Ȃ��~
if(md->state.state==MS_ATTACK)
return 0; // ���ɍU����
mob_changestate(md,MS_ATTACK,attack_type);
/* if(mode&0x08){ // �����N�����X�^�[
map_foreachinarea(mob_ai_sub_hard_linksearch,md->bl.m,
md->bl.x-13,md->bl.y-13,
md->bl.x+13,md->bl.y+13,
BL_MOB,md,&tsd->bl);
}*/
}
return 0;
}else{ // ���[�g�����X�^�[����
if(tbl == NULL || tbl->type != BL_ITEM ||tbl->m != md->bl.m ||
(dist=distance(md->bl.x,md->bl.y,tbl->x,tbl->y))>=md->min_chase || !md->lootitem){
// �������邩�A�C�e�����Ȃ��Ȃ���
mob_unlocktarget(md,tick);
if(md->state.state==MS_WALK)
mob_stop_walking(md,1); // ���s���Ȃ��~
}else if(dist){
if(!(mode&1)){ // �ړ����Ȃ����[�h
mob_unlocktarget(md,tick);
return 0;
}
if( !mob_can_move(md) ) // �����Ȃ���Ԃɂ���
return 0;
md->state.skillstate=MSS_LOOT; // ���[�g���X�L���g�p
mobskill_use(md,tick,-1);
// if(md->timer != -1 && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tbl->x,tbl->y)<2) )
if(md->timer != -1 && md->state.state!=MS_ATTACK && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tbl->x,tbl->y) <= 0))
return 0; // ���Ɉړ���
md->next_walktime=tick+500;
dx=tbl->x - md->bl.x;
dy=tbl->y - md->bl.y;
/* if(path_search(&md->walkpath,md->bl.m,md->bl.x,md->bl.y,md->bl.x+dx,md->bl.y+dy,0)){
dx=tbl->x - md->bl.x;
dy=tbl->y - md->bl.y;
}*/
ret=mob_walktoxy(md,md->bl.x+dx,md->bl.y+dy,0);
if(ret)
mob_unlocktarget(md,tick);// �ړ��ł��Ȃ��̂Ń^�Q�����iIW�Ƃ��H�j
}else{ // �A�C�e���܂ł��ǂ蒅����
if(md->state.state==MS_ATTACK)
return 0; // �U����
if(md->state.state==MS_WALK)
mob_stop_walking(md,1); // ���s���Ȃ��~
fitem = (struct flooritem_data *)tbl;
if(md->lootitem_count < LOOTITEM_SIZE)
memcpy(&md->lootitem[md->lootitem_count++],&fitem->item_data,sizeof(md->lootitem[0]));
else if(battle_config.monster_loot_type == 1 && md->lootitem_count >= LOOTITEM_SIZE) {
mob_unlocktarget(md,tick);
return 0;
}
else {
if(md->lootitem[0].card[0] == (short)0xff00)
intif_delete_petdata(*((long *)(&md->lootitem[0].card[1])));
for(i=0;i<LOOTITEM_SIZE-1;i++)
memcpy(&md->lootitem[i],&md->lootitem[i+1],sizeof(md->lootitem[0]));
memcpy(&md->lootitem[LOOTITEM_SIZE-1],&fitem->item_data,sizeof(md->lootitem[0]));
}
map_clearflooritem(tbl->id);
mob_unlocktarget(md,tick);
}
return 0;
}
}else{
mob_unlocktarget(md,tick);
if(md->state.state==MS_WALK)
mob_stop_walking(md,4); // ���s���Ȃ��~
return 0;
}
}
// It is skill use at the time of /standby at the time of a walk.
if( mobskill_use(md,tick,-1) )
return 0;
// ���s����
if( mode&1 && mob_can_move(md) && // �ړ��\MOB&�������Ԃɂ���
(md->master_id==0 || md->state.special_mob_ai || md->master_dist>10) ){ //��芪��MOB����Ȃ�
if( DIFF_TICK(md->next_walktime,tick) > + 7000 &&
(md->walkpath.path_len==0 || md->walkpath.path_pos>=md->walkpath.path_len) ){
md->next_walktime = tick + 3000*rand()%2000;
}
// Random movement
if( mob_randomwalk(md,tick) )
return 0;
}
// Since he has finished walking, it stands by.
if( md->walkpath.path_len==0 || md->walkpath.path_pos>=md->walkpath.path_len )
md->state.skillstate=MSS_IDLE;
return 0;
}
/*==========================================
* Serious processing for mob in PC field of view (foreachclient)
*------------------------------------------
*/
static int mob_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
{
unsigned int tick;
nullpo_retr(0, sd);
nullpo_retr(0, ap);
tick=va_arg(ap,unsigned int);
map_foreachinarea(mob_ai_sub_hard,sd->bl.m,
sd->bl.x-AREA_SIZE*2,sd->bl.y-AREA_SIZE*2,
sd->bl.x+AREA_SIZE*2,sd->bl.y+AREA_SIZE*2,
BL_MOB,tick);
return 0;
}
/*==========================================
* Serious processing for mob in PC field of view (interval timer function)
*------------------------------------------
*/
static int mob_ai_hard(int tid,unsigned int tick,int id,int data)
{
clif_foreachclient(mob_ai_sub_foreachclient,tick);
return 0;
}
/*==========================================
* Negligent mode MOB AI (PC is not in near)
*------------------------------------------
*/
static int mob_ai_sub_lazy(void * key,void * data,va_list app)
{
struct mob_data *md=(struct mob_data *)data;
unsigned int tick;
va_list ap;
nullpo_retr(0, md);
nullpo_retr(0, app);
ap=va_arg(app,va_list);
if(md->bl.type!=BL_MOB)
return 0;
if(!md->bl.type || md->bl.type!=BL_MOB)
return 0;
tick=va_arg(ap,unsigned int);
if(DIFF_TICK(tick,md->last_thinktime)<MIN_MOBTHINKTIME*10)
return 0;
md->last_thinktime=tick;
if(md->bl.prev==NULL || md->skilltimer!=-1){
if(DIFF_TICK(tick,md->next_walktime)>MIN_MOBTHINKTIME*10)
md->next_walktime=tick;
return 0;
}
if(DIFF_TICK(md->next_walktime,tick)<0 &&
(mob_db[md->class_].mode&1) && mob_can_move(md) ){
if( map[md->bl.m].users>0 ){
// Since PC is in the same map, somewhat better negligent processing is carried out.
// It sometimes moves.
if(rand()%1000<MOB_LAZYMOVEPERC)
mob_randomwalk(md,tick);
// MOB which is not not the summons MOB but BOSS, either sometimes reboils.
else if( rand()%1000<MOB_LAZYWARPPERC && md->x0<=0 && md->master_id!=0 &&
mob_db[md->class_].mexp <= 0 && !(mob_db[md->class_].mode & 0x20))
mob_spawn(md->bl.id);
}else{
// Since PC is not even in the same map, suitable processing is carried out even if it takes.
// MOB which is not BOSS which is not Summons MOB, either -- a case -- sometimes -- leaping
if( rand()%1000<MOB_LAZYWARPPERC && md->x0<=0 && md->master_id!=0 &&
mob_db[md->class_].mexp <= 0 && !(mob_db[md->class_].mode & 0x20))
mob_warp(md,-1,-1,-1,-1);
}
md->next_walktime = tick+rand()%10000+5000;
}
return 0;
}
/*==========================================
* Negligent processing for mob outside PC field of view (interval timer function)
*------------------------------------------
*/
static int mob_ai_lazy(int tid,unsigned int tick,int id,int data)
{
map_foreachiddb(mob_ai_sub_lazy,tick);
return 0;
}
/*==========================================
* The structure object for item drop with delay
* Since it is only two being able to pass [ int ] a timer function
* Data is put in and passed to this structure object.
*------------------------------------------
*/
struct delay_item_drop {
int m,x,y;
int nameid,amount;
struct map_session_data *first_sd,*second_sd,*third_sd;
};
struct delay_item_drop2 {
int m,x,y;
struct item item_data;
struct map_session_data *first_sd,*second_sd,*third_sd;
};
/*==========================================
* item drop with delay (timer function)
*------------------------------------------
*/
static int mob_delay_item_drop(int tid,unsigned int tick,int id,int data)
{
struct delay_item_drop *ditem;
struct item temp_item;
int flag, drop_flag = 1;
nullpo_retr(0, ditem=(struct delay_item_drop *)id);
memset(&temp_item,0,sizeof(temp_item));
temp_item.nameid = ditem->nameid;
temp_item.amount = ditem->amount;
temp_item.identify = !itemdb_isequip3(temp_item.nameid);
if (ditem->first_sd){
#if 0
if (ditem->first_sd->status.party_id > 0){
struct party *p;
if((p=party_search(ditem->first_sd->status.party_id)) && p->item){
struct map_session_data *sd = NULL;
int i;
for (i = p->itemc + 1; i!=p->itemc; i++) { // initialise counter and loop through the party
if (i >= MAX_PARTY)
i = 0; // reset counter to 1st person in party so it'll stop when it reaches "itemc"
if ((sd=p->member[i].sd)!=NULL && sd->bl.m == ditem->first_sd->bl.m)
break;
}
if (sd){ // if an appropiate party member was found
drop_flag = 0;
if ((p->itemc++) >= MAX_PARTY)
p->itemc = 0;
if ((flag = pc_additem(ditem->first_sd,&temp_item,ditem->amount))) {
clif_additem(ditem->first_sd,0,0,flag);
drop_flag = 1;
}
}
}
} else
#endif
if(battle_config.item_auto_get || ditem->first_sd->autoloot){//Autoloot added by Upa-Kun
drop_flag = 0;
if((flag = pc_additem(ditem->first_sd,&temp_item,ditem->amount))){
clif_additem(ditem->first_sd,0,0,flag);
drop_flag = 1;
}
}
}
if (drop_flag) {
map_addflooritem(&temp_item,1,ditem->m,ditem->x,ditem->y,ditem->first_sd,ditem->second_sd,ditem->third_sd,0);
}
aFree(ditem);
return 0;
}
/*==========================================
* item drop (timer function)-lootitem with delay
*------------------------------------------
*/
static int mob_delay_item_drop2(int tid,unsigned int tick,int id,int data)
{
struct delay_item_drop2 *ditem;
int flag, drop_flag = 1;
nullpo_retr(0, ditem=(struct delay_item_drop2 *)id);
if (ditem->first_sd){
#if 0
if (ditem->first_sd->status.party_id > 0){
struct party *p;
if((p=party_search(ditem->first_sd->status.party_id)) && p->item){
struct map_session_data *sd = NULL;
int i;
for (i = p->itemc + 1; i!=p->itemc; i++) { // initialise counter and loop through the party
if (i >= MAX_PARTY)
i = 0; // reset counter to 1st person in party so it'll stop when it reaches "itemc"
if ((sd=p->member[i].sd)!=NULL && sd->bl.m == ditem->first_sd->bl.m)
break;
}
if (sd){ // if an appropiate party member was found
drop_flag = 0;
if ((p->itemc++) >= MAX_PARTY)
p->itemc = 0;
if((flag = pc_additem(ditem->first_sd,&ditem->item_data,ditem->item_data.amount))){
clif_additem(ditem->first_sd,0,0,flag);
drop_flag = 1;
}
}
}
} else
#endif
if(battle_config.item_auto_get || ditem->first_sd->autoloot){//Autoloot added by Upa-Kun
drop_flag = 0;
if((flag = pc_additem(ditem->first_sd,&ditem->item_data,ditem->item_data.amount))){
clif_additem(ditem->first_sd,0,0,flag);
drop_flag = 1;
}
}
}
if (drop_flag) {
map_addflooritem(&ditem->item_data,ditem->item_data.amount,ditem->m,ditem->x,ditem->y,ditem->first_sd,ditem->second_sd,ditem->third_sd,0);
}
aFree(ditem);
return 0;
}
/*==========================================
* mob data is erased.
*------------------------------------------
*/
int mob_delete(struct mob_data *md)
{
nullpo_retr(1, md);
if(md->bl.prev == NULL)
return 1;
mob_changestate(md,MS_DEAD,0);
clif_clearchar_area(&md->bl,1);
map_delblock(&md->bl);
if(mob_get_viewclass(md->class_) <= 1000)
clif_clearchar_delay(gettick()+3000,&md->bl,0);
mob_deleteslave(md);
mob_setdelayspawn(md->bl.id);
return 0;
}
int mob_catch_delete(struct mob_data *md,int type)
{
nullpo_retr(1, md);
if(md->bl.prev == NULL)
return 1;
mob_changestate(md,MS_DEAD,0);
clif_clearchar_area(&md->bl,type);
map_delblock(&md->bl);
mob_setdelayspawn(md->bl.id);
return 0;
}
int mob_timer_delete(int tid, unsigned int tick, int id, int data)
{
struct block_list *bl=map_id2bl(id);
struct mob_data *md;
nullpo_retr(0, bl);
md = (struct mob_data *)bl;
mob_catch_delete(md,3);
return 0;
}
/*==========================================
*
*------------------------------------------
*/
int mob_deleteslave_sub(struct block_list *bl,va_list ap)
{
struct mob_data *md;
int id;
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, md = (struct mob_data *)bl);
id=va_arg(ap,int);
if(md->master_id > 0 && md->master_id == id )
mob_damage(NULL,md,md->hp,1);
return 0;
}
/*==========================================
*
*------------------------------------------
*/
int mob_deleteslave(struct mob_data *md)
{
nullpo_retr(0, md);
map_foreachinarea(mob_deleteslave_sub, md->bl.m,
0,0,map[md->bl.m].xs,map[md->bl.m].ys,
BL_MOB,md->bl.id);
return 0;
}
/*==========================================
* It is the damage of sd to damage to md.
*------------------------------------------
*/
int mob_damage(struct block_list *src,struct mob_data *md,int damage,int type)
{
int i,count,minpos,mindmg;
struct map_session_data *sd = NULL,*tmpsd[DAMAGELOG_SIZE];
struct {
struct party *p;
int id,base_exp,job_exp,zeny;
} pt[DAMAGELOG_SIZE];
int pnum=0;
int mvp_damage,max_hp;
unsigned int tick = gettick();
struct map_session_data *mvp_sd = NULL, *second_sd = NULL,*third_sd = NULL;
struct block_list *master = NULL;
double tdmg,temp;
struct item item;
int ret;
int drop_rate;
nullpo_retr(0, md); //src��NULL�ŌĂ��ꍇ������̂ŁA���Ń`�F�b�N
max_hp = status_get_max_hp(&md->bl);
if(src && src->type == BL_PC) {
sd = (struct map_session_data *)src;
mvp_sd = sd;
}
// if(battle_config.battle_log)
// printf("mob_damage %d %d %d\n",md->hp,max_hp,damage);
if(md->bl.prev==NULL){
if(battle_config.error_log==1)
printf("mob_damage : BlockError!!\n");
return 0;
}
if(md->state.state==MS_DEAD || md->hp<=0) {
if(md->bl.prev != NULL) {
mob_changestate(md,MS_DEAD,0);
mobskill_use(md,tick,-1); // It is skill at the time of death.
clif_clearchar_area(&md->bl,1);
map_delblock(&md->bl);
mob_setdelayspawn(md->bl.id);
}
return 0;
}
if(md->sc_data[SC_ENDURE].timer == -1)
mob_stop_walking(md,3);
if(damage > max_hp>>2)
skill_stop_dancing(&md->bl,0);
if(md->hp > max_hp)
md->hp = max_hp;
// The amount of overkill rounds to hp.
if(damage>md->hp)
damage=md->hp;
if(!(type&2)) {
if(sd!=NULL){
for(i=0,minpos=0,mindmg=0x7fffffff;i<DAMAGELOG_SIZE;i++){
if(md->dmglog[i].id==sd->bl.id)
break;
if(md->dmglog[i].id==0){
minpos=i;
mindmg=0;
}
else if(md->dmglog[i].dmg<mindmg){
minpos=i;
mindmg=md->dmglog[i].dmg;
}
}
if(i<DAMAGELOG_SIZE)
md->dmglog[i].dmg+=damage;
else {
md->dmglog[minpos].id=sd->bl.id;
md->dmglog[minpos].dmg=damage;
}
if(md->attacked_id <= 0 && md->state.special_mob_ai==0)
md->attacked_id = sd->bl.id;
}
if(src && src->type == BL_PET && battle_config.pet_attack_exp_to_master==1) {
struct pet_data *pd = (struct pet_data *)src;
nullpo_retr(0, pd);
for(i=0,minpos=0,mindmg=0x7fffffff;i<DAMAGELOG_SIZE;i++){
if(md->dmglog[i].id==pd->msd->bl.id)
break;
if(md->dmglog[i].id==0){
minpos=i;
mindmg=0;
}
else if(md->dmglog[i].dmg<mindmg){
minpos=i;
mindmg=md->dmglog[i].dmg;
}
}
if(i<DAMAGELOG_SIZE)
md->dmglog[i].dmg+=(damage*battle_config.pet_attack_exp_rate)/100;
else {
md->dmglog[minpos].id=pd->msd->bl.id;
md->dmglog[minpos].dmg=(damage*battle_config.pet_attack_exp_rate)/100;
}
}
if(src && src->type == BL_MOB && ((struct mob_data*)src)->state.special_mob_ai){
struct mob_data *md2 = (struct mob_data *)src;
nullpo_retr(0, md2);
for(i=0,minpos=0,mindmg=0x7fffffff;i<DAMAGELOG_SIZE;i++){
if(md->dmglog[i].id==md2->master_id)
break;
if(md->dmglog[i].id==0){
minpos=i;
mindmg=0;
}
else if(md->dmglog[i].dmg<mindmg){
minpos=i;
mindmg=md->dmglog[i].dmg;
}
}
if(i<DAMAGELOG_SIZE)
md->dmglog[i].dmg+=damage;
else {
md->dmglog[minpos].id=md2->master_id;
md->dmglog[minpos].dmg=damage;
if(md->attacked_id <= 0 && md->state.special_mob_ai==0)
md->attacked_id = md2->master_id;
}
}
}
md->hp-=damage;
if(md->class_ >= 1285 && md->class_ <=1287) { // guardian hp update [Valaris]
struct guild_castle *gc=guild_mapname2gc(map[md->bl.m].name);
if(gc) {
if(md->bl.id==gc->GID0) {
gc->Ghp0=md->hp;
if(gc->Ghp0<=0) {
guild_castledatasave(gc->castle_id,10,0);
guild_castledatasave(gc->castle_id,18,0);
}
}
if(md->bl.id==gc->GID1) {
gc->Ghp1=md->hp;
if(gc->Ghp1<=0) {
guild_castledatasave(gc->castle_id,11,0);
guild_castledatasave(gc->castle_id,19,0);
}
}
if(md->bl.id==gc->GID2) {
gc->Ghp2=md->hp;
if(gc->Ghp2<=0) {
guild_castledatasave(gc->castle_id,12,0);
guild_castledatasave(gc->castle_id,20,0);
}
}
if(md->bl.id==gc->GID3) {
gc->Ghp3=md->hp;
if(gc->Ghp3<=0) {
guild_castledatasave(gc->castle_id,13,0);
guild_castledatasave(gc->castle_id,21,0);
}
}
if(md->bl.id==gc->GID4) {
gc->Ghp4=md->hp;
if(gc->Ghp4<=0) {
guild_castledatasave(gc->castle_id,14,0);
guild_castledatasave(gc->castle_id,22,0);
}
}
if(md->bl.id==gc->GID5) {
gc->Ghp5=md->hp;
if(gc->Ghp5<=0) {
guild_castledatasave(gc->castle_id,15,0);
guild_castledatasave(gc->castle_id,23,0);
}
}
if(md->bl.id==gc->GID6) {
gc->Ghp6=md->hp;
if(gc->Ghp6<=0) {
guild_castledatasave(gc->castle_id,16,0);
guild_castledatasave(gc->castle_id,24,0);
}
}
if(md->bl.id==gc->GID7) {
gc->Ghp7=md->hp;
if(gc->Ghp7<=0) {
guild_castledatasave(gc->castle_id,17,0);
guild_castledatasave(gc->castle_id,25,0);
}
}
}
} // end addition [Valaris]
if(md->option&2 )
status_change_end(&md->bl, SC_HIDING, -1);
if(md->option&4 )
status_change_end(&md->bl, SC_CLOAKING, -1);
if(md->state.special_mob_ai == 2){//�X�t�B�A�[�}�C��
int skillidx=0;
if((skillidx=mob_skillid2skillidx(md->class_,NPC_SELFDESTRUCTION2))>=0){
md->mode |= 0x1;
md->next_walktime=tick;
mobskill_use_id(md,&md->bl,skillidx);//�����r���J�n
md->state.special_mob_ai++;
}
if (src && md->master_id==src->id)
md->target_dir=map_calc_dir(src,md->bl.x,md->bl.y)+1;
}
if(md->hp>0){
if (battle_config.show_mob_hp)
clif_update_mobhp (md);
return 0;
}
// ----- �������玀�S���� -----
map_freeblock_lock();
mob_changestate(md,MS_DEAD,0);
mobskill_use(md,tick,-1); // ���S���X�L��
memset(tmpsd,0,sizeof(tmpsd));
memset(pt,0,sizeof(pt));
max_hp = status_get_max_hp(&md->bl);
if(src && src->type == BL_MOB)
mob_unlocktarget((struct mob_data *)src,tick);
if(sd) {
int sp = 0, hp = 0;
if (sd->state.attack_type == BF_MAGIC && (i=pc_checkskill(sd,HW_SOULDRAIN))>0){ /* �\�E���h���C�� */
clif_skill_nodamage(src,&md->bl,HW_SOULDRAIN,i,1);
sp += (status_get_lv(&md->bl))*(65+15*i)/100;
}
sp += sd->sp_gain_value;
hp += sd->hp_gain_value;
if (sp > 0) {
if(sd->status.sp + sp > sd->status.max_sp)
sp = sd->status.max_sp - sd->status.sp;
sd->status.sp += sp;
clif_heal(sd->fd,SP_SP,sp);
}
if (hp > 0) {
if(sd->status.hp + hp > sd->status.max_hp)
hp = sd->status.max_hp - sd->status.hp;
sd->status.hp += hp;
clif_heal(sd->fd,SP_HP,hp);
}
}
// map�O�ɏ������l�͌v�Z���珜���̂�
// overkill���͖�������sum��max_hp�Ƃ͈Ⴄ
tdmg = 0;
for(i=0,count=0,mvp_damage=0;i<DAMAGELOG_SIZE;i++){
if(md->dmglog[i].id==0)
continue;
tmpsd[i] = map_id2sd(md->dmglog[i].id);
if(tmpsd[i] == NULL)
continue;
count++;
if(tmpsd[i]->bl.m != md->bl.m || pc_isdead(tmpsd[i]))
continue;
tdmg += (double)md->dmglog[i].dmg;
if(mvp_damage<md->dmglog[i].dmg){
third_sd = second_sd;
second_sd = mvp_sd;
mvp_sd=tmpsd[i];
mvp_damage=md->dmglog[i].dmg;
}
}
// [MouseJstr]
if((map[md->bl.m].flag.pvp == 0) || (battle_config.pvp_exp == 1)) {
/* if((double)max_hp < tdmg)
dmg_rate = ((double)max_hp) / tdmg;
else dmg_rate = 1;*/
// �o���l�̕��z
for(i=0;i<DAMAGELOG_SIZE;i++){
int pid,base_exp,job_exp,flag=1,zeny=0;
double per;
struct party *p;
if(tmpsd[i]==NULL || tmpsd[i]->bl.m != md->bl.m || pc_isdead(tmpsd[i]))
continue;
if (battle_config.exp_calc_type == 0) {
// jAthena's exp formula
// per = ((double)md->dmglog[i].dmg)*(9.+(double)((count > 6)? 6:count))/10./((double)max_hp) * dmg_rate;
per = ((double)md->dmglog[i].dmg)*(9.+(double)((count > 6)? 6:count))/10./tdmg;
temp = (double)mob_db[md->class_].base_exp * per;
base_exp = (temp > 2147483647.)? 0x7fffffff:(int)temp;
if(mob_db[md->class_].base_exp > 0 && base_exp < 1) base_exp = 1;
if(base_exp < 0) base_exp = 0;
temp = (double)mob_db[md->class_].job_exp * per;
job_exp = (temp > 2147483647.)? 0x7fffffff:(int)temp;
if(mob_db[md->class_].job_exp > 0 && job_exp < 1) job_exp = 1;
if(job_exp < 0) job_exp = 0;
}
else if (battle_config.exp_calc_type == 1) {
//eAthena's exp formula rather than jAthena's
per=(double)md->dmglog[i].dmg*256*(9+(double)((count > 6)? 6:count))/10/(double)max_hp;
if(per>512) per=512;
if(per<1) per=1;
base_exp=mob_db[md->class_].base_exp*per/256;
if(base_exp < 1) base_exp = 1;
job_exp=mob_db[md->class_].job_exp*per/256;
if(job_exp < 1) job_exp = 1;
}
else {
//eAthena's exp formula rather than jAthena's, but based on total damage dealt
per=(double)md->dmglog[i].dmg*256*(9+(double)((count > 6)? 6:count))/10/tdmg;
if(per>512) per=512;
if(per<1) per=1;
base_exp=mob_db[md->class_].base_exp*per/256;
if(base_exp < 1) base_exp = 1;
job_exp=mob_db[md->class_].job_exp*per/256;
if(job_exp < 1) job_exp = 1;
}
if(sd && battle_config.pk_mode && (mob_db[md->class_].lv - sd->status.base_level >= 20)) {
base_exp*=1.15; // pk_mode additional exp if monster >20 levels [Valaris]
}
if(sd && battle_config.pk_mode && (mob_db[md->class_].lv - sd->status.base_level >= 20)) {
job_exp*=1.15; // pk_mode additional exp if monster >20 levels [Valaris]
}
if(md->master_id) {
master = map_id2bl(md->master_id);
}
if((master && status_get_mode(master)&0x20) || // check if its master is a boss (MVP's and minibosses)
(md->state.special_mob_ai >= 1 && battle_config.alchemist_summon_reward != 1)) { // for summoned creatures [Valaris]
base_exp = 0;
job_exp = 0;
}
else {
if(battle_config.zeny_from_mobs) {
if(md->level > 0) zeny=(md->level+rand()%md->level)*per/256; // zeny calculation moblv + random moblv [Valaris]
if(mob_db[md->class_].mexp > 0)
zeny*=rand()%250;
}
if(battle_config.mobs_level_up && md->level > mob_db[md->class_].lv) { // [Valaris]
job_exp+=((md->level-mob_db[md->class_].lv)*mob_db[md->class_].job_exp*.03)*per/256;
base_exp+=((md->level-mob_db[md->class_].lv)*mob_db[md->class_].base_exp*.03)*per/256;
}
}
if((pid=tmpsd[i]->status.party_id)>0){ // �p�[�e�B�ɓ����Ă���
int j=0;
for(j=0;j<pnum;j++) // �����p�[�e�B���X�g�ɂ��邩�ǂ���
if(pt[j].id==pid)
break;
if(j==pnum){ // ���Ȃ��Ƃ��͌������ǂ����m�F
if((p=party_search(pid))!=NULL && p->exp!=0){
pt[pnum].id=pid;
pt[pnum].p=p;
pt[pnum].base_exp=base_exp;
pt[pnum].job_exp=job_exp;
if(battle_config.zeny_from_mobs)
pt[pnum].zeny=zeny; // zeny share [Valaris]
pnum++;
flag=0;
}
}else{ // ����Ƃ��͌���
pt[j].base_exp+=base_exp;
pt[j].job_exp+=job_exp;
if(battle_config.zeny_from_mobs)
pt[j].zeny+=zeny; // zeny share [Valaris]
flag=0;
}
}
if(flag) { // added zeny from mobs [Valaris]
if(base_exp > 0 || job_exp > 0)
pc_gainexp(tmpsd[i],base_exp,job_exp);
if (battle_config.zeny_from_mobs && zeny > 0) {
pc_getzeny(tmpsd[i],zeny); // zeny from mobs [Valaris]
}
}
}
// �������z
for(i=0;i<pnum;i++)
party_exp_share(pt[i].p,md->bl.m,pt[i].base_exp,pt[i].job_exp,pt[i].zeny);
// item drop
if(!(type&1)) {
int log_item[10] = {0}; //8 -> 10 Lupus
int drop_ore = -1,drop_items=0; //slot N for DROP LOG, number of dropped items
for(i=0;i<10;i++){ // 8 -> 10 Lupus
struct delay_item_drop *ditem;
int drop_rate;
if((master && status_get_mode(master)&0x20) || // check if its master is a boss (MVP's and minibosses)
(md->state.special_mob_ai >= 1 && battle_config.alchemist_summon_reward != 1)) // Added [Valaris]
break; // End
if(mob_db[md->class_].dropitem[i].nameid <= 0)
continue;
drop_rate = mob_db[md->class_].dropitem[i].p;
if(drop_rate <= 0 && battle_config.drop_rate0item)
drop_rate = 1;
if(battle_config.drops_by_luk>0 && sd && md) drop_rate+=(sd->status.luk*battle_config.drops_by_luk)/100; // drops affected by luk [Valaris]
if(sd && md && battle_config.pk_mode==1 && (mob_db[md->class_].lv - sd->status.base_level >= 20)) drop_rate*=1.25; // pk_mode increase drops if 20 level difference [Valaris]
if(drop_rate <= rand()%10000) {
drop_ore = i; //we rmember an empty slot to put there ORE DISCOVERY drop later.
continue;
}
drop_items++; //we cound if there were any drops
ditem=(struct delay_item_drop *)aCalloc(1,sizeof(struct delay_item_drop));
ditem->nameid = mob_db[md->class_].dropitem[i].nameid;
log_item[i] = ditem->nameid;
ditem->amount = 1;
ditem->m = md->bl.m;
ditem->x = md->bl.x;
ditem->y = md->bl.y;
ditem->first_sd = mvp_sd;
ditem->second_sd = second_sd;
ditem->third_sd = third_sd;
add_timer(tick+500+i,mob_delay_item_drop,(int)ditem,0);
}
// Ore Discovery [Celest]
if (pc_checkskill(sd,BS_FINDINGORE)>0 && battle_config.finding_ore_rate/100 >= rand()%1000) {
struct delay_item_drop *ditem;
int itemid[17] = { 714, 756, 757, 969, 984, 985, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1002 };
ditem=(struct delay_item_drop *)aCalloc(1,sizeof(struct delay_item_drop));
ditem->nameid = itemid[rand()%17]; //should return from 0 to 16
if (drop_ore<0) i=8; //we have only 10 slots in LOG, there's a check to not overflow (9th item usually a card, so we use 8th slot)
log_item[i] = ditem->nameid; //it's for logging only
drop_items++; //we cound if there were any drops
ditem->amount = 1;
ditem->m = md->bl.m;
ditem->x = md->bl.x;
ditem->y = md->bl.y;
ditem->first_sd = mvp_sd;
ditem->second_sd = second_sd;
ditem->third_sd = third_sd;
add_timer(tick+500+i,mob_delay_item_drop,(int)ditem,0);
}
//this drop log contains ALL dropped items + ORE (if there was ORE Recovery) [Lupus]
if(log_config.drop > 0 && drop_items) //we check were there any drops.. and if not - don't write the log
log_drop(sd, md->class_, log_item); //mvp_sd
if(sd && sd->state.attack_type == BF_WEAPON) {
for(i=0;i<sd->monster_drop_item_count;i++) {
struct delay_item_drop *ditem;
int race = status_get_race(&md->bl);
if(sd->monster_drop_itemid[i] <= 0)
continue;
if(sd->monster_drop_race[i] & (1<<race) ||
(mob_db[md->class_].mode & 0x20 && sd->monster_drop_race[i] & 1<<10) ||
(!(mob_db[md->class_].mode & 0x20) && sd->monster_drop_race[i] & 1<<11) ) {
if(sd->monster_drop_itemrate[i] <= rand()%10000)
continue;
ditem=(struct delay_item_drop *)aCalloc(1,sizeof(struct delay_item_drop));
ditem->nameid = sd->monster_drop_itemid[i];
ditem->amount = 1;
ditem->m = md->bl.m;
ditem->x = md->bl.x;
ditem->y = md->bl.y;
ditem->first_sd = mvp_sd;
ditem->second_sd = second_sd;
ditem->third_sd = third_sd;
add_timer(tick+520+i,mob_delay_item_drop,(int)ditem,0);
}
}
if(sd->get_zeny_num > 0)
pc_getzeny(sd,mob_db[md->class_].lv*10 + rand()%(sd->get_zeny_num+1));
}
if(md->lootitem) {
for(i=0;i<md->lootitem_count;i++) {
struct delay_item_drop2 *ditem;
ditem=(struct delay_item_drop2 *)aCalloc(1,sizeof(struct delay_item_drop2));
memcpy(&ditem->item_data,&md->lootitem[i],sizeof(md->lootitem[0]));
ditem->m = md->bl.m;
ditem->x = md->bl.x;
ditem->y = md->bl.y;
ditem->first_sd = mvp_sd;
ditem->second_sd = second_sd;
ditem->third_sd = third_sd;
add_timer(tick+540+i,mob_delay_item_drop2,(int)ditem,0);
}
}
}
// mvp����
if(mvp_sd && mob_db[md->class_].mexp > 0 ){
int log_mvp[2] = {0};
int j;
int mexp;
temp = ((double)mob_db[md->class_].mexp * (9.+(double)count)/10.); //[Gengar]
mexp = (temp > 2147483647.)? 0x7fffffff:(int)temp;
if(mexp < 1) mexp = 1;
clif_mvp_effect(mvp_sd); // �G�t�F�N�g
clif_mvp_exp(mvp_sd,mexp);
pc_gainexp(mvp_sd,mexp,0);
log_mvp[1] = mexp;
for(j=0;j<3;j++){
i = rand() % 3;
if(mob_db[md->class_].mvpitem[i].nameid <= 0)
continue;
drop_rate = mob_db[md->class_].mvpitem[i].p;
if(drop_rate <= 0 && battle_config.drop_rate0item)
drop_rate = 1;
if(drop_rate < battle_config.item_drop_mvp_min)
drop_rate = battle_config.item_drop_mvp_min;
else if(drop_rate > battle_config.item_drop_mvp_max) //fixed
drop_rate = battle_config.item_drop_mvp_max;
if(drop_rate <= rand()%10000)
continue;
memset(&item,0,sizeof(item));
item.nameid=mob_db[md->class_].mvpitem[i].nameid;
item.identify=!itemdb_isequip3(item.nameid);
clif_mvp_item(mvp_sd,item.nameid);
log_mvp[0] = item.nameid;
if(mvp_sd->weight*2 > mvp_sd->max_weight)
map_addflooritem(&item,1,mvp_sd->bl.m,mvp_sd->bl.x,mvp_sd->bl.y,mvp_sd,second_sd,third_sd,1);
else if((ret = pc_additem(mvp_sd,&item,1))) {
clif_additem(sd,0,0,ret);
map_addflooritem(&item,1,mvp_sd->bl.m,mvp_sd->bl.x,mvp_sd->bl.y,mvp_sd,second_sd,third_sd,1);
}
break;
}
if(log_config.mvpdrop > 0)
log_mvpdrop(mvp_sd, md->class_, log_mvp);
}
} // [MouseJstr]
// <Agit> NPC Event [OnAgitBreak]
if(md->npc_event[0] && strcmp(((md->npc_event)+strlen(md->npc_event)-13),"::OnAgitBreak") == 0) {
printf("MOB.C: Run NPC_Event[OnAgitBreak].\n");
if (agit_flag == 1) //Call to Run NPC_Event[OnAgitBreak]
guild_agit_break(md);
}
// SCRIPT���s
if(md->npc_event[0]){
// if(battle_config.battle_log)
// printf("mob_damage : run event : %s\n",md->npc_event);
if(src && src->type == BL_PET)
sd = ((struct pet_data *)src)->msd;
if(sd == NULL) {
if(mvp_sd != NULL)
sd = mvp_sd;
else {
struct map_session_data *tmpsd;
int i;
for(i=0;i<fd_max;i++){
if(session[i] && (tmpsd= (struct map_session_data *) session[i]->session_data) && tmpsd->state.auth) {
if(md->bl.m == tmpsd->bl.m) {
sd = tmpsd;
break;
}
}
}
}
}
if(sd)
npc_event(sd,md->npc_event,0);
}
clif_clearchar_area(&md->bl,1);
if(md->level) md->level=0;
map_delblock(&md->bl);
if(mob_get_viewclass(md->class_) <= 1000)
clif_clearchar_delay(tick+3000,&md->bl,0);
mob_deleteslave(md);
mob_setdelayspawn(md->bl.id);
map_freeblock_unlock();
return 0;
}
/*==========================================
*
*------------------------------------------
*/
int mob_class_change(struct mob_data *md,int *value)
{
unsigned int tick = gettick();
int i,c,hp_rate,max_hp,class_,count = 0;
nullpo_retr(0, md);
nullpo_retr(0, value);
if(value[0]<=1000 || value[0]>MAX_MOB_DB)
return 0;
if(md->bl.prev == NULL) return 0;
while(count < 5 && value[count] > 1000 && value[count] <= MAX_MOB_DB) count++;
if(count < 1) return 0;
class_ = value[rand()%count];
if(class_<=1000 || class_>MAX_MOB_DB) return 0;
max_hp = status_get_max_hp(&md->bl);
hp_rate = md->hp*100/max_hp;
clif_mob_class_change(md,class_);
md->class_ = class_;
max_hp = status_get_max_hp(&md->bl);
if(battle_config.monster_class_change_full_recover==1) {
md->hp = max_hp;
memset(md->dmglog,0,sizeof(md->dmglog));
}
else
md->hp = max_hp*hp_rate/100;
if(md->hp > max_hp) md->hp = max_hp;
else if(md->hp < 1) md->hp = 1;
memcpy(md->name,mob_db[class_].jname,24);
memset(&md->state,0,sizeof(md->state));
md->attacked_id = 0;
md->target_id = 0;
md->move_fail_count = 0;
md->speed = mob_db[md->class_].speed;
md->def_ele = mob_db[md->class_].element;
mob_changestate(md,MS_IDLE,0);
skill_castcancel(&md->bl,0);
md->state.skillstate = MSS_IDLE;
md->last_thinktime = tick;
md->next_walktime = tick+rand()%50+5000;
md->attackabletime = tick;
md->canmove_tick = tick;
for(i=0,c=tick-1000*3600*10;i<MAX_MOBSKILL;i++)
md->skilldelay[i] = c;
md->skillid=0;
md->skilllv=0;
if(md->lootitem == NULL && mob_db[class_].mode&0x02)
md->lootitem=(struct item *)aCalloc(LOOTITEM_SIZE,sizeof(struct item));
skill_clear_unitgroup(&md->bl);
skill_cleartimerskill(&md->bl);
clif_clearchar_area(&md->bl,0);
clif_spawnmob(md);
return 0;
}
/*==========================================
* mob��
*------------------------------------------
*/
int mob_heal(struct mob_data *md,int heal)
{
int max_hp;
nullpo_retr(0, md);
max_hp = status_get_max_hp(&md->bl);
md->hp += heal;
if( max_hp < md->hp )
md->hp = max_hp;
if(md->class_ >= 1285 && md->class_ <=1287) { // guardian hp update [Valaris]
struct guild_castle *gc=guild_mapname2gc(map[md->bl.m].name);
if(gc) {
if(md->bl.id==gc->GID0) gc->Ghp0=md->hp;
if(md->bl.id==gc->GID1) gc->Ghp1=md->hp;
if(md->bl.id==gc->GID2) gc->Ghp2=md->hp;
if(md->bl.id==gc->GID3) gc->Ghp3=md->hp;
if(md->bl.id==gc->GID4) gc->Ghp4=md->hp;
if(md->bl.id==gc->GID5) gc->Ghp5=md->hp;
if(md->bl.id==gc->GID6) gc->Ghp6=md->hp;
if(md->bl.id==gc->GID7) gc->Ghp7=md->hp;
}
} // end addition [Valaris]
return 0;
}
/*==========================================
* Added by RoVeRT
*------------------------------------------
*/
int mob_warpslave_sub(struct block_list *bl,va_list ap)
{
struct mob_data *md=(struct mob_data *)bl;
int id,x,y;
id=va_arg(ap,int);
x=va_arg(ap,int);
y=va_arg(ap,int);
if( md->master_id==id ) {
mob_warp(md,-1,x,y,2);
}
return 0;
}
/*==========================================
* Added by RoVeRT
*------------------------------------------
*/
int mob_warpslave(struct mob_data *md,int x, int y)
{
//printf("warp slave\n");
map_foreachinarea(mob_warpslave_sub, md->bl.m,
x-AREA_SIZE,y-AREA_SIZE,
x+AREA_SIZE,y+AREA_SIZE,BL_MOB,
md->bl.id, md->bl.x, md->bl.y );
return 0;
}
/*==========================================
* mob���[�v
*------------------------------------------
*/
int mob_warp(struct mob_data *md,int m,int x,int y,int type)
{
int i=0,xs=0,ys=0,bx=x,by=y;
int tick = gettick();
nullpo_retr(0, md);
if( md->bl.prev==NULL )
return 0;
if( m<0 ) m=md->bl.m;
if(type >= 0) {
if(map[md->bl.m].flag.monster_noteleport)
return 0;
clif_clearchar_area(&md->bl,type);
}
skill_unit_move(&md->bl,tick,0);
map_delblock(&md->bl);
if(bx>0 && by>0){ // �ʒu�w��̏ꍇ���͂X�Z����T��
xs=ys=9;
}
while( ( x<0 || y<0 || map_getcell(m,x,y,CELL_CHKNOPASS)) && (i++)<1000 ){
if( xs>0 && ys>0 && i<250 ){ // �w��ʒu�t�߂̒T��
x=bx+rand()%xs-xs/2;
y=by+rand()%ys-ys/2;
}else{ // ���S�����_���T��
x=rand()%(map[m].xs-2)+1;
y=rand()%(map[m].ys-2)+1;
}
}
md->dir=0;
if(i<1000){
md->bl.x=md->to_x=x;
md->bl.y=md->to_y=y;
md->bl.m=m;
}else {
m=md->bl.m;
if(battle_config.error_log==1)
printf("MOB %d warp failed, class = %d\n",md->bl.id,md->class_);
}
md->target_id=0; // �^�Q����������
md->state.targettype=NONE_ATTACKABLE;
md->attacked_id=0;
md->state.skillstate=MSS_IDLE;
mob_changestate(md,MS_IDLE,0);
if(type>0 && i==1000) {
if(battle_config.battle_log)
printf("MOB %d warp to (%d,%d), class = %d\n",md->bl.id,x,y,md->class_);
}
map_addblock(&md->bl);
skill_unit_move(&md->bl,tick,1);
if(type>0)
{
clif_spawnmob(md);
mob_warpslave(md,md->bl.x,md->bl.y);
}
return 0;
}
/*==========================================
* ��ʓ��̎�芪���̐��v�Z�p(foreachinarea)
*------------------------------------------
*/
int mob_countslave_sub(struct block_list *bl,va_list ap)
{
int id,*c;
struct mob_data *md;
id=va_arg(ap,int);
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, c=va_arg(ap,int *));
nullpo_retr(0, md = (struct mob_data *)bl);
if( md->master_id==id )
(*c)++;
return 0;
}
/*==========================================
* ��ʓ��̎�芪���̐��v�Z
*------------------------------------------
*/
int mob_countslave(struct mob_data *md)
{
int c=0;
nullpo_retr(0, md);
map_foreachinarea(mob_countslave_sub, md->bl.m,
0,0,map[md->bl.m].xs-1,map[md->bl.m].ys-1,
BL_MOB,md->bl.id,&c);
return c;
}
/*==========================================
* �艺MOB����
*------------------------------------------
*/
int mob_summonslave(struct mob_data *md2,int *value,int amount,int flag)
{
struct mob_data *md;
int bx,by,m,count = 0,class_,k,a = amount;
nullpo_retr(0, md2);
nullpo_retr(0, value);
bx=md2->bl.x;
by=md2->bl.y;
m=md2->bl.m;
if(value[0]<=1000 || value[0]>MAX_MOB_DB) // �l���ُ�Ȃ珢�����~�߂�
return 0;
while(count < 21 && value[count] > 1000 && value[count] <= 2000) count++;
if(count < 1) return 0;
for(k=0;k<count;k++) {
amount = a;
class_ = value[k];
if(class_<=1000 || class_>MAX_MOB_DB) continue;
for(;amount>0;amount--){
int x=0,y=0,i=0;
md=(struct mob_data *)aCalloc(1,sizeof(struct mob_data));
if(mob_db[class_].mode&0x02)
md->lootitem=(struct item *)aCalloc(LOOTITEM_SIZE,sizeof(struct item));
else
md->lootitem=NULL;
while((x<=0 || y<=0 || map_getcell(m,x,y,CELL_CHKNOPASS)) && (i++)<100){
x=rand()%9-4+bx;
y=rand()%9-4+by;
}
if(i>=100){
x=bx;
y=by;
}
mob_spawn_dataset(md,"--ja--",class_);
md->bl.m=m;
md->bl.x=x;
md->bl.y=y;
md->m =m;
md->x0=x;
md->y0=y;
md->xs=0;
md->ys=0;
md->speed=md2->speed;
md->spawndelay1=-1; // ��x�̂݃t���O
md->spawndelay2=-1; // ��x�̂݃t���O
memset(md->npc_event,0,sizeof(md->npc_event));
md->bl.type=BL_MOB;
map_addiddb(&md->bl);
mob_spawn(md->bl.id);
clif_skill_nodamage(&md->bl,&md->bl,(flag)? NPC_SUMMONSLAVE:NPC_SUMMONMONSTER,a,1);
if(flag)
md->master_id=md2->bl.id;
}
}
return 0;
}
/*==========================================
* ���������b�N���Ă���PC�̐��𐔂���(foreachclient)
*------------------------------------------
*/
static int mob_counttargeted_sub(struct block_list *bl,va_list ap)
{
int id,*c,target_lv;
struct block_list *src;
id=va_arg(ap,int);
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, c=va_arg(ap,int *));
src=va_arg(ap,struct block_list *);
target_lv=va_arg(ap,int);
if(id == bl->id || (src && id == src->id)) return 0;
if(bl->type == BL_PC) {
struct map_session_data *sd = (struct map_session_data *)bl;
if(sd && sd->attacktarget == id && sd->attacktimer != -1 && sd->attacktarget_lv >= target_lv)
(*c)++;
}
else if(bl->type == BL_MOB) {
struct mob_data *md = (struct mob_data *)bl;
if(md && md->target_id == id && md->timer != -1 && md->state.state == MS_ATTACK && md->target_lv >= target_lv)
(*c)++;
}
else if(bl->type == BL_PET) {
struct pet_data *pd = (struct pet_data *)bl;
if(pd->target_id == id && pd->timer != -1 && pd->state.state == MS_ATTACK && pd->target_lv >= target_lv)
(*c)++;
}
return 0;
}
/*==========================================
* ���������b�N���Ă���PC�̐��𐔂���
*------------------------------------------
*/
int mob_counttargeted(struct mob_data *md,struct block_list *src,int target_lv)
{
int c=0;
nullpo_retr(0, md);
map_foreachinarea(mob_counttargeted_sub, md->bl.m,
md->bl.x-AREA_SIZE,md->bl.y-AREA_SIZE,
md->bl.x+AREA_SIZE,md->bl.y+AREA_SIZE,0,md->bl.id,&c,src,target_lv);
return c;
}
/*==========================================
*MOBskill����Y��skillid��skillidx��Ԃ�
*------------------------------------------
*/
int mob_skillid2skillidx(int class_,int skillid)
{
int i;
struct mob_skill *ms=mob_db[class_].skill;
if(ms==NULL)
return -1;
for(i=0;i<mob_db[class_].maxskill;i++){
if(ms[i].skill_id == skillid)
return i;
}
return -1;
}
//
// MOB�X�L��
//
/*==========================================
* �X�L���g�p�i�r�������AID�w��j
*------------------------------------------
*/
int mobskill_castend_id( int tid, unsigned int tick, int id,int data )
{
struct mob_data* md=NULL;
struct block_list *bl;
struct block_list *mbl;
int range;
if((mbl = map_id2bl(id)) == NULL ) //�r������Mob���������Ȃ��Ƃ����̂͗ǂ����鐳�폈��
return 0;
if((md=(struct mob_data *)mbl) == NULL ){
printf("mobskill_castend_id nullpo mbl->id:%d\n",mbl->id);
return 0;
}
if( md->bl.type!=BL_MOB || md->bl.prev==NULL )
return 0;
if( md->skilltimer != tid ) // �^�C�}ID�̊m�F
return 0;
md->skilltimer=-1;
//���ق��Ԉُ�Ȃ�
if(md->sc_data){
if(md->opt1>0 || md->sc_data[SC_DIVINA].timer != -1 || md->sc_data[SC_ROKISWEIL].timer != -1 || md->sc_data[SC_STEELBODY].timer != -1)
return 0;
if(md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //�I�[�g�J�E���^�[
return 0;
if(md->sc_data[SC_BLADESTOP].timer != -1) //���n���
return 0;
if(md->sc_data[SC_BERSERK].timer != -1) //�o�[�T�[�N
return 0;
}
if(md->skillid != NPC_EMOTION)
md->last_thinktime=tick + status_get_adelay(&md->bl);
if((bl = map_id2bl(md->skilltarget)) == NULL || bl->prev==NULL){ //�X�L���^�[�Q�b�g�����݂��Ȃ�
//printf("mobskill_castend_id nullpo\n");//�^�[�Q�b�g�����Ȃ��Ƃ���nullpo����Ȃ��ĕ��ʂɏI��
return 0;
}
if(md->bl.m != bl->m)
return 0;
if(md->skillid == PR_LEXAETERNA) {
struct status_change *sc_data = status_get_sc_data(bl);
if(sc_data && (sc_data[SC_FREEZE].timer != -1 || (sc_data[SC_STONE].timer != -1 && sc_data[SC_STONE].val2 == 0)))
return 0;
}
else if(md->skillid == RG_BACKSTAP) {
int dir = map_calc_dir(&md->bl,bl->x,bl->y),t_dir = status_get_dir(bl);
int dist = distance(md->bl.x,md->bl.y,bl->x,bl->y);
if(bl->type != BL_SKILL && (dist == 0 || map_check_dir(dir,t_dir)))
return 0;
}
if( ( (skill_get_inf(md->skillid)&1) || (skill_get_inf2(md->skillid)&4) ) && // �މ�G�ΊW�`�F�b�N
battle_check_target(&md->bl,bl, BCT_ENEMY)<=0 )
return 0;
range = skill_get_range(md->skillid,md->skilllv);
if(range < 0)
range = status_get_range(&md->bl) - (range + 1);
if(range + battle_config.mob_skill_add_range < distance(md->bl.x,md->bl.y,bl->x,bl->y))
return 0;
md->skilldelay[md->skillidx]=tick;
if(battle_config.mob_skill_log)
printf("MOB skill castend skill=%d, class = %d\n",md->skillid,md->class_);
// mob_stop_walking(md,0);
switch( skill_get_nk(md->skillid) )
{
// �U���n/��������n
case 0: case 2:
skill_castend_damage_id(&md->bl,bl,md->skillid,md->skilllv,tick,0);
break;
case 1:// �x���n
if(!mob_db[md->class_].skill[md->skillidx].val[0] &&
(md->skillid==AL_HEAL || (md->skillid==ALL_RESURRECTION && bl->type != BL_PC)) && battle_check_undead(status_get_race(bl),status_get_elem_type(bl)) )
skill_castend_damage_id(&md->bl,bl,md->skillid,md->skilllv,tick,0);
else
skill_castend_nodamage_id(&md->bl,bl,md->skillid,md->skilllv,tick,0);
break;
}
return 0;
}
/*==========================================
* �X�L���g�p�i�r�������A�ꏊ�w��j
*------------------------------------------
*/
int mobskill_castend_pos( int tid, unsigned int tick, int id,int data )
{
struct mob_data* md=NULL;
struct block_list *bl;
int range,maxcount;
//mobskill_castend_id���l�r������Mob���r���������ɂ������Ȃ��Ƃ����̂͂��肻���Ȃ̂�nullpo���珜�O
if((bl=map_id2bl(id))==NULL)
return 0;
nullpo_retr(0, md=(struct mob_data *)bl);
if( md->bl.type!=BL_MOB || md->bl.prev==NULL )
return 0;
if( md->skilltimer != tid ) // �^�C�}ID�̊m�F
return 0;
md->skilltimer=-1;
if(md->sc_data){
if(md->opt1>0 || md->sc_data[SC_DIVINA].timer != -1 || md->sc_data[SC_ROKISWEIL].timer != -1 || md->sc_data[SC_STEELBODY].timer != -1)
return 0;
if(md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //�I�[�g�J�E���^�[
return 0;
if(md->sc_data[SC_BLADESTOP].timer != -1) //���n���
return 0;
if(md->sc_data[SC_BERSERK].timer != -1) //�o�[�T�[�N
return 0;
}
if (!battle_config.monster_skill_reiteration &&
skill_get_unit_flag(md->skillid)&UF_NOREITERATION &&
skill_check_unit_range(md->bl.m,md->skillx,md->skilly,md->skillid,md->skilllv))
return 0;
if(battle_config.monster_skill_nofootset &&
skill_get_unit_flag(md->skillid)&UF_NOFOOTSET &&
skill_check_unit_range2(md->bl.m,md->skillx,md->skilly,md->skillid,md->skilllv))
return 0;
if(battle_config.monster_land_skill_limit) {
maxcount = skill_get_maxcount(md->skillid);
if(maxcount > 0) {
int i,c;
for(i=c=0;i<MAX_MOBSKILLUNITGROUP;i++) {
if(md->skillunit[i].alive_count > 0 && md->skillunit[i].skill_id == md->skillid)
c++;
}
if(c >= maxcount)
return 0;
}
}
range = skill_get_range(md->skillid,md->skilllv);
if(range < 0)
range = status_get_range(&md->bl) - (range + 1);
if(range + battle_config.mob_skill_add_range < distance(md->bl.x,md->bl.y,md->skillx,md->skilly))
return 0;
md->skilldelay[md->skillidx]=tick;
if(battle_config.mob_skill_log)
printf("MOB skill castend skill=%d, class = %d\n",md->skillid,md->class_);
// mob_stop_walking(md,0);
skill_castend_pos2(&md->bl,md->skillx,md->skilly,md->skillid,md->skilllv,tick,0);
return 0;
}
/*==========================================
* Skill use (an aria start, ID specification)
*------------------------------------------
*/
int mobskill_use_id(struct mob_data *md,struct block_list *target,int skill_idx)
{
int casttime,range;
struct mob_skill *ms;
int skill_id, skill_lv, forcecast = 0;
nullpo_retr(0, md);
nullpo_retr(0, ms=&mob_db[md->class_].skill[skill_idx]);
if( target==NULL && (target=map_id2bl(md->target_id))==NULL )
return 0;
if( target->prev==NULL || md->bl.prev==NULL )
return 0;
skill_id=ms->skill_id;
skill_lv=ms->skill_lv;
// ���ق�ُ�
if(md->sc_data){
if(md->opt1>0 || md->sc_data[SC_DIVINA].timer != -1 || md->sc_data[SC_ROKISWEIL].timer != -1 || md->sc_data[SC_STEELBODY].timer != -1)
return 0;
if(md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //�I�[�g�J�E���^�[
return 0;
if(md->sc_data[SC_BLADESTOP].timer != -1) //���n���
return 0;
if(md->sc_data[SC_BERSERK].timer != -1) //�o�[�T�[�N
return 0;
}
if(md->option&4 && skill_id==TF_HIDING)
return 0;
if(md->option&2 && skill_id!=TF_HIDING && skill_id!=AS_GRIMTOOTH && skill_id!=RG_BACKSTAP && skill_id!=RG_RAID)
return 0;
if(map[md->bl.m].flag.gvg && (skill_id == SM_ENDURE || skill_id == AL_TELEPORT || skill_id == AL_WARP ||
skill_id == WZ_ICEWALL || skill_id == TF_BACKSLIDING))
return 0;
if(skill_get_inf2(skill_id)&0x200 && md->bl.id == target->id)
return 0;
// �˒��Ə�Q���`�F�b�N
range = skill_get_range(skill_id,skill_lv);
if(range < 0)
range = status_get_range(&md->bl) - (range + 1);
if(!battle_check_range(&md->bl,target,range))
return 0;
// delay=skill_delayfix(&md->bl, skill_get_delay( skill_id,skill_lv) );
casttime=skill_castfix(&md->bl,ms->casttime);
md->state.skillcastcancel=ms->cancel;
md->skilldelay[skill_idx]=gettick();
switch(skill_id){ /* ��������ȏ������K�v */
case ALL_RESURRECTION: /* ���U���N�V���� */
if(target->type != BL_PC && battle_check_undead(status_get_race(target),status_get_elem_type(target))){ /* �G���A���f�b�h�Ȃ� */
forcecast=1; /* �^�[���A���f�b�g�Ɠ����r������ */
casttime=skill_castfix(&md->bl, skill_get_cast(PR_TURNUNDEAD,skill_lv) );
}
break;
case MO_EXTREMITYFIST: /*���C���e�P��*/
case SA_MAGICROD:
case SA_SPELLBREAKER:
forcecast=1;
break;
case NPC_SUMMONSLAVE:
case NPC_SUMMONMONSTER:
if(md->master_id!=0)
return 0;
break;
}
if(battle_config.mob_skill_log)
printf("MOB skill use target_id=%d skill=%d lv=%d cast=%d, class = %d\n",target->id,skill_id,skill_lv,casttime,md->class_);
if(casttime>0 || forcecast){ // �r�����K�v
// struct mob_data *md2;
mob_stop_walking(md,0); // ���s��~
clif_skillcasting( &md->bl,
md->bl.id, target->id, 0,0, skill_id,casttime);
// �r�����������X�^�[
/* if( target->type==BL_MOB && mob_db[(md2=(struct mob_data *)target)->class_].mode&0x10 &&
md2->state.state!=MS_ATTACK){
md2->target_id=md->bl.id;
md->state.targettype = ATTACKABLE;
md2->min_chase=13;
}*/
}
if( casttime<=0 ) // �r���̖������̂̓L�����Z������Ȃ�
md->state.skillcastcancel=0;
md->skilltarget = target->id;
md->skillx = 0;
md->skilly = 0;
md->skillid = skill_id;
md->skilllv = skill_lv;
md->skillidx = skill_idx;
if(!(battle_config.monster_cloak_check_type&2) && md->sc_data[SC_CLOAKING].timer != -1 && md->skillid != AS_CLOAKING)
status_change_end(&md->bl,SC_CLOAKING,-1);
if( casttime>0 ){
md->skilltimer =
add_timer( gettick()+casttime, mobskill_castend_id, md->bl.id, 0 );
}else{
md->skilltimer = -1;
mobskill_castend_id(md->skilltimer,gettick(),md->bl.id, 0);
}
return 1;
}
/*==========================================
* �X�L���g�p�i�ꏊ�w��j
*------------------------------------------
*/
int mobskill_use_pos( struct mob_data *md,
int skill_x, int skill_y, int skill_idx)
{
int casttime=0,range;
struct mob_skill *ms;
struct block_list bl;
int skill_id, skill_lv;
nullpo_retr(0, md);
nullpo_retr(0, ms=&mob_db[md->class_].skill[skill_idx]);
if( md->bl.prev==NULL )
return 0;
skill_id=ms->skill_id;
skill_lv=ms->skill_lv;
//���ق��Ԉُ�Ȃ�
if(md->sc_data){
if(md->opt1>0 || md->sc_data[SC_DIVINA].timer != -1 || md->sc_data[SC_ROKISWEIL].timer != -1 || md->sc_data[SC_STEELBODY].timer != -1)
return 0;
if(md->sc_data[SC_AUTOCOUNTER].timer != -1 && md->skillid != KN_AUTOCOUNTER) //�I�[�g�J�E���^�[
return 0;
if(md->sc_data[SC_BLADESTOP].timer != -1) //���n���
return 0;
if(md->sc_data[SC_BERSERK].timer != -1) //�o�[�T�[�N
return 0;
}
if(md->option&2)
return 0;
if(map[md->bl.m].flag.gvg && (skill_id == SM_ENDURE || skill_id == AL_TELEPORT || skill_id == AL_WARP ||
skill_id == WZ_ICEWALL || skill_id == TF_BACKSLIDING))
return 0;
// �˒��Ə�Q���`�F�b�N
bl.type = BL_NUL;
bl.m = md->bl.m;
bl.x = skill_x;
bl.y = skill_y;
range = skill_get_range(skill_id,skill_lv);
if(range < 0)
range = status_get_range(&md->bl) - (range + 1);
if(!battle_check_range(&md->bl,&bl,range))
return 0;
// delay=skill_delayfix(&sd->bl, skill_get_delay( skill_id,skill_lv) );
casttime=skill_castfix(&md->bl,ms->casttime);
md->skilldelay[skill_idx]=gettick();
md->state.skillcastcancel=ms->cancel;
if(battle_config.mob_skill_log)
printf("MOB skill use target_pos=(%d,%d) skill=%d lv=%d cast=%d, class = %d\n",
skill_x,skill_y,skill_id,skill_lv,casttime,md->class_);
if( casttime>0 ) { // A cast time is required.
mob_stop_walking(md,0); // ���s��~
clif_skillcasting( &md->bl,
md->bl.id, 0, skill_x,skill_y, skill_id,casttime);
}
if( casttime<=0 ) // A skill without a cast time wont be cancelled.
md->state.skillcastcancel=0;
md->skillx = skill_x;
md->skilly = skill_y;
md->skilltarget = 0;
md->skillid = skill_id;
md->skilllv = skill_lv;
md->skillidx = skill_idx;
if(!(battle_config.monster_cloak_check_type&2) && md->sc_data[SC_CLOAKING].timer != -1)
status_change_end(&md->bl,SC_CLOAKING,-1);
if( casttime>0 ){
md->skilltimer =
add_timer( gettick()+casttime, mobskill_castend_pos, md->bl.id, 0 );
}else{
md->skilltimer = -1;
mobskill_castend_pos(md->skilltimer,gettick(),md->bl.id, 0);
}
return 1;
}
/*==========================================
* Friendly Mob whose HP is decreasing by a nearby MOB is looked for.
*------------------------------------------
*/
int mob_getfriendhpltmaxrate_sub(struct block_list *bl,va_list ap)
{
int rate;
struct mob_data **fr, *md, *mmd;
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, mmd=va_arg(ap,struct mob_data *));
md=(struct mob_data *)bl;
if( mmd->bl.id == bl->id )
return 0;
rate=va_arg(ap,int);
fr=va_arg(ap,struct mob_data **);
if( md->hp < mob_db[md->class_].max_hp*rate/100 )
(*fr)=md;
return 0;
}
struct mob_data *mob_getfriendhpltmaxrate(struct mob_data *md,int rate)
{
struct mob_data *fr=NULL;
const int r=8;
nullpo_retr(NULL, md);
map_foreachinarea(mob_getfriendhpltmaxrate_sub, md->bl.m,
md->bl.x-r ,md->bl.y-r, md->bl.x+r, md->bl.y+r,
BL_MOB,md,rate,&fr);
return fr;
}
/*==========================================
* What a status state suits by nearby MOB is looked for.
*------------------------------------------
*/
int mob_getfriendstatus_sub(struct block_list *bl,va_list ap)
{
int cond1,cond2;
struct mob_data **fr, *md, *mmd;
int flag=0;
nullpo_retr(0, bl);
nullpo_retr(0, ap);
nullpo_retr(0, md=(struct mob_data *)bl);
nullpo_retr(0, mmd=va_arg(ap,struct mob_data *));
if( mmd->bl.id == bl->id )
return 0;
cond1=va_arg(ap,int);
cond2=va_arg(ap,int);
fr=va_arg(ap,struct mob_data **);
if( cond2==-1 ){
int j;
for(j=SC_STONE;j<=SC_BLIND && !flag;j++){
flag=(md->sc_data[j].timer!=-1 );
}
}else
flag=( md->sc_data[cond2].timer!=-1 );
if( flag^( cond1==MSC_FRIENDSTATUSOFF ) )
(*fr)=md;
return 0;
}
struct mob_data *mob_getfriendstatus(struct mob_data *md,int cond1,int cond2)
{
struct mob_data *fr=NULL;
const int r=8;
nullpo_retr(0, md);
map_foreachinarea(mob_getfriendstatus_sub, md->bl.m,
md->bl.x-r ,md->bl.y-r, md->bl.x+r, md->bl.y+r,
BL_MOB,md,cond1,cond2,&fr);
return fr;
}
/*==========================================
* Skill use judging
*------------------------------------------
*/
int mobskill_use(struct mob_data *md,unsigned int tick,int event)
{
struct mob_skill *ms;
// struct block_list *target=NULL;
int i,max_hp;
nullpo_retr(0, md);
nullpo_retr(0, ms = mob_db[md->class_].skill);
max_hp = status_get_max_hp(&md->bl);
if(battle_config.mob_skill_use == 0 || md->skilltimer != -1)
return 0;
if(md->state.special_mob_ai)
return 0;
if(md->sc_data[SC_SELFDESTRUCTION].timer!=-1) //�������̓X�L�����g��Ȃ�
return 0;
for(i=0;i<mob_db[md->class_].maxskill;i++){
int c2=ms[i].cond2,flag=0;
struct mob_data *fmd=NULL;
// �f�B���C��
if( DIFF_TICK(tick,md->skilldelay[i])<ms[i].delay )
continue;
// ��Ԕ���
if( ms[i].state>=0 && ms[i].state!=md->state.skillstate )
continue;
// ��������
flag=(event==ms[i].cond1);
if(!flag){
switch( ms[i].cond1 ){
case MSC_ALWAYS:
flag=1; break;
case MSC_MYHPLTMAXRATE: // HP< maxhp%
flag=( md->hp < max_hp*c2/100 ); break;
case MSC_MYSTATUSON: // status[num] on
case MSC_MYSTATUSOFF: // status[num] off
if( ms[i].cond2==-1 ){
int j;
for(j=SC_STONE;j<=SC_BLIND && !flag;j++){
flag=(md->sc_data[j].timer!=-1 );
}
}else
flag=( md->sc_data[ms[i].cond2].timer!=-1 );
flag^=( ms[i].cond1==MSC_MYSTATUSOFF ); break;
case MSC_FRIENDHPLTMAXRATE: // friend HP < maxhp%
flag=(( fmd=mob_getfriendhpltmaxrate(md,ms[i].cond2) )!=NULL ); break;
case MSC_FRIENDSTATUSON: // friend status[num] on
case MSC_FRIENDSTATUSOFF: // friend status[num] off
flag=(( fmd=mob_getfriendstatus(md,ms[i].cond1,ms[i].cond2) )!=NULL ); break;
case MSC_SLAVELT: // slave < num
flag=( mob_countslave(md) < c2 ); break;
case MSC_ATTACKPCGT: // attack pc > num
flag=( mob_counttargeted(md,NULL,0) > c2 ); break;
case MSC_SLAVELE: // slave <= num
flag=( mob_countslave(md) <= c2 ); break;
case MSC_ATTACKPCGE: // attack pc >= num
flag=( mob_counttargeted(md,NULL,0) >= c2 ); break;
case MSC_SKILLUSED: // specificated skill used
flag=( (event&0xffff)==MSC_SKILLUSED && ((event>>16)==c2 || c2==0)); break;
}
}
// �m������
if( flag && rand()%10000 < ms[i].permillage ){
if( skill_get_inf(ms[i].skill_id)&2 ){
// �ꏊ�w��
struct block_list *bl = NULL;
int x=0,y=0;
if( ms[i].target<=MST_AROUND ){
bl= ((ms[i].target==MST_TARGET || ms[i].target==MST_AROUND5)? map_id2bl(md->target_id):
(ms[i].target==MST_FRIEND)? &fmd->bl : &md->bl);
if(bl!=NULL){
x=bl->x; y=bl->y;
}
}
if( x<=0 || y<=0 )
continue;
// �����̎���
if( ms[i].target>=MST_AROUND1 ){
int bx=x, by=y, i=0, m=bl->m, r=ms[i].target-MST_AROUND1;
do{
bx=x + rand()%(r*2+3) - r;
by=y + rand()%(r*2+3) - r;
}while( ( bx<=0 || by<=0 || bx>=map[m].xs || by>=map[m].ys ||
map_getcell(m,bx,by,CELL_CHKNOPASS)) && (i++)<1000);
if(i<1000){
x=bx; y=by;
}
}
// ����̎���
if( ms[i].target>=MST_AROUND5 ){
int bx=x, by=y, i=0,m=bl->m, r=(ms[i].target-MST_AROUND5)+1;
do{
bx=x + rand()%(r*2+1) - r;
by=y + rand()%(r*2+1) - r;
}while( ( bx<=0 || by<=0 || bx>=map[m].xs || by>=map[m].ys ||
map_getcell(m,bx,by,CELL_CHKNOPASS)) && (i++)<1000);
if(i<1000){
x=bx; y=by;
}
}
if(!mobskill_use_pos(md,x,y,i))
return 0;
}else{
// ID�w��
if( ms[i].target<=MST_FRIEND ){
struct block_list *bl = NULL;
bl= ((ms[i].target==MST_TARGET)? map_id2bl(md->target_id):
(ms[i].target==MST_FRIEND)? &fmd->bl : &md->bl);
if(bl && !mobskill_use_id(md,bl,i))
return 0;
}
}
if(ms[i].emotion >= 0)
clif_emotion(&md->bl,ms[i].emotion);
return 1;
}
}
return 0;
}
/*==========================================
* Skill use event processing
*------------------------------------------
*/
int mobskill_event(struct mob_data *md,int flag)
{
nullpo_retr(0, md);
if(flag==-1 && mobskill_use(md,gettick(),MSC_CASTTARGETED))
return 1;
if( (flag&BF_SHORT) && mobskill_use(md,gettick(),MSC_CLOSEDATTACKED))
return 1;
if( (flag&BF_LONG) && mobskill_use(md,gettick(),MSC_LONGRANGEATTACKED))
return 1;
return 0;
}
/*==========================================
* Mob���G���y���E���Ȃǂ̏ꍇ�̔���
*------------------------------------------
*/
int mob_gvmobcheck(struct map_session_data *sd, struct block_list *bl)
{
struct mob_data *md=NULL;
nullpo_retr(0,sd);
nullpo_retr(0,bl);
if(bl->type==BL_MOB && (md=(struct mob_data *)bl) &&
(md->class_ == 1288 || md->class_ == 1287 || md->class_ == 1286 || md->class_ == 1285))
{
struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
struct guild *g=guild_search(sd->status.guild_id);
if(g == NULL && md->class_ == 1288)
return 0;//�M���h�������Ȃ�_���[�W����
else if(gc != NULL && !map[sd->bl.m].flag.gvg)
return 0;//�ԓ���Gv����Ȃ��Ƃ��̓_���[�W�Ȃ�
else if(g && gc != NULL && g->guild_id == gc->guild_id)
return 0;//����̃M���h�̃G���y�Ȃ�_���[�W����
else if(g && guild_checkskill(g,GD_APPROVAL) <= 0 && md->class_ == 1288)
return 0;//���K�M���h���F���Ȃ��ƃ_���[�W����
}
return 1;
}
/*==========================================
* �X�L���p�^�C�}�[�폜
*------------------------------------------
*/
int mobskill_deltimer(struct mob_data *md )
{
nullpo_retr(0, md);
if( md->skilltimer!=-1 ){
if( skill_get_inf( md->skillid )&2 )
delete_timer( md->skilltimer, mobskill_castend_pos );
else
delete_timer( md->skilltimer, mobskill_castend_id );
md->skilltimer=-1;
}
return 0;
}
//
// ������
//
/*==========================================
* Since un-setting [ mob ] up was used, it is an initial provisional value setup.
*------------------------------------------
*/
static int mob_makedummymobdb(int class_)
{
int i;
sprintf(mob_db[class_].name,"mob%d",class_);
sprintf(mob_db[class_].jname,"mob%d",class_);
mob_db[class_].lv=1;
mob_db[class_].max_hp=1000;
mob_db[class_].max_sp=1;
mob_db[class_].base_exp=2;
mob_db[class_].job_exp=1;
mob_db[class_].range=1;
mob_db[class_].atk1=7;
mob_db[class_].atk2=10;
mob_db[class_].def=0;
mob_db[class_].mdef=0;
mob_db[class_].str=1;
mob_db[class_].agi=1;
mob_db[class_].vit=1;
mob_db[class_].int_=1;
mob_db[class_].dex=6;
mob_db[class_].luk=2;
mob_db[class_].range2=10;
mob_db[class_].range3=10;
mob_db[class_].size=0;
mob_db[class_].race=0;
mob_db[class_].element=0;
mob_db[class_].mode=0;
mob_db[class_].speed=300;
mob_db[class_].adelay=1000;
mob_db[class_].amotion=500;
mob_db[class_].dmotion=500;
//mob_db[class_].dropitem[0].nameid=909; // Jellopy
//mob_db[class_].dropitem[0].p=1000;
for(i=1;i<10;i++){ // 8-> 10 Lupus
mob_db[class_].dropitem[i].nameid=0;
mob_db[class_].dropitem[i].p=0;
}
// Item1,Item2
mob_db[class_].mexp=0;
mob_db[class_].mexpper=0;
for(i=0;i<3;i++){
mob_db[class_].mvpitem[i].nameid=0;
mob_db[class_].mvpitem[i].p=0;
}
for(i=0;i<MAX_RANDOMMONSTER;i++)
mob_db[class_].summonper[i]=0;
return 0;
}
/*==========================================
* db/mob_db.txt reading
*------------------------------------------
*/
static int mob_readdb(void)
{
FILE *fp;
char line[1024];
char *filename[]={ "db/mob_db.txt","db/mob_db2.txt" };
int i;
memset(mob_db,0,sizeof(mob_db));
for(i=0;i<2;i++){
fp=fopen(filename[i],"r");
if(fp==NULL){
if(i>0)
continue;
return -1;
}
while(fgets(line,1020,fp)){
int class_,i;
char *str[60],*p,*np; // 55->60 Lupus
if(line[0] == '/' && line[1] == '/')
continue;
for(i=0,p=line;i<60;i++){
if((np=strchr(p,','))!=NULL){
str[i]=p;
*np=0;
p=np+1;
} else
str[i]=p;
}
class_=atoi(str[0]);
if(class_<=1000 || class_>MAX_MOB_DB)
continue;
mob_db[class_].view_class=class_;
memcpy(mob_db[class_].name,str[1],24);
memcpy(mob_db[class_].jname,str[2],24);
mob_db[class_].lv=atoi(str[3]);
mob_db[class_].max_hp=atoi(str[4]);
mob_db[class_].max_sp=atoi(str[5]);
mob_db[class_].base_exp = atoi(str[6]);
if (mob_db[class_].base_exp <= 0)
mob_db[class_].base_exp = 0;
else if (mob_db[class_].base_exp * battle_config.base_exp_rate / 100 > 1000000000 ||
mob_db[class_].base_exp * battle_config.base_exp_rate / 100 < 0)
mob_db[class_].base_exp = 1000000000;
else {
mob_db[class_].base_exp = mob_db[class_].base_exp * battle_config.base_exp_rate / 100;
if (mob_db[class_].base_exp < 1)
mob_db[class_].base_exp = 1;
}
mob_db[class_].job_exp = atoi(str[7]);
if (mob_db[class_].job_exp <= 0)
mob_db[class_].job_exp = 0;
else if (mob_db[class_].job_exp * battle_config.job_exp_rate / 100 > 1000000000 ||
mob_db[class_].job_exp * battle_config.job_exp_rate / 100 < 0)
mob_db[class_].job_exp = 1000000000;
else {
mob_db[class_].job_exp = mob_db[class_].job_exp * battle_config.job_exp_rate / 100;
if (mob_db[class_].job_exp < 1)
mob_db[class_].job_exp = 1;
}
mob_db[class_].range=atoi(str[8]);
mob_db[class_].atk1=atoi(str[9]);
mob_db[class_].atk2=atoi(str[10]);
mob_db[class_].def=atoi(str[11]);
mob_db[class_].mdef=atoi(str[12]);
mob_db[class_].str=atoi(str[13]);
mob_db[class_].agi=atoi(str[14]);
mob_db[class_].vit=atoi(str[15]);
mob_db[class_].int_=atoi(str[16]);
mob_db[class_].dex=atoi(str[17]);
mob_db[class_].luk=atoi(str[18]);
mob_db[class_].range2=atoi(str[19]);
mob_db[class_].range3=atoi(str[20]);
mob_db[class_].size=atoi(str[21]);
mob_db[class_].race=atoi(str[22]);
mob_db[class_].element=atoi(str[23]);
mob_db[class_].mode=atoi(str[24]);
mob_db[class_].speed=atoi(str[25]);
mob_db[class_].adelay=atoi(str[26]);
mob_db[class_].amotion=atoi(str[27]);
mob_db[class_].dmotion=atoi(str[28]);
for(i=0;i<10;i++){ // 8 -> 10 Lupus
int rate = 0,type,ratemin,ratemax;
mob_db[class_].dropitem[i].nameid=atoi(str[29+i*2]);
type = itemdb_type(mob_db[class_].dropitem[i].nameid);
if (type == 0) {
rate = battle_config.item_rate_heal * atoi(str[30+i*2]) / 100; //fix by Yor
ratemin = battle_config.item_drop_heal_min;
ratemax = battle_config.item_drop_heal_max;
}
else if (type == 2) {
rate = battle_config.item_rate_use * atoi(str[30+i*2]) / 100; //fix by Yor
ratemin = battle_config.item_drop_use_min;
ratemax = battle_config.item_drop_use_max; // End
}
else if (type == 4 || type == 5 || type == 8) { // Changed to include Pet Equip
rate = battle_config.item_rate_equip * atoi(str[30+i*2]) / 100;
ratemin = battle_config.item_drop_equip_min;
ratemax = battle_config.item_drop_equip_max;
}
else if (type == 6) {
rate = battle_config.item_rate_card * atoi(str[30+i*2]) / 100;
ratemin = battle_config.item_drop_card_min;
ratemax = battle_config.item_drop_card_max;
}
else {
rate = battle_config.item_rate_common * atoi(str[30+i*2]) / 100;
ratemin = battle_config.item_drop_common_min;
ratemax = battle_config.item_drop_common_max;
}
mob_db[class_].dropitem[i].p = (rate < ratemin) ? ratemin : (rate > ratemax) ? ratemax: rate;
}
// MVP EXP Bonus, Chance: MEXP,ExpPer
mob_db[class_].mexp=atoi(str[49])*battle_config.mvp_exp_rate/100;
mob_db[class_].mexpper=atoi(str[50]);
// MVP Drops: MVP1id,MVP1per,MVP2id,MVP2per,MVP3id,MVP3per
for(i=0;i<3;i++){
mob_db[class_].mvpitem[i].nameid=atoi(str[51+i*2]);
mob_db[class_].mvpitem[i].p=atoi(str[52+i*2])*battle_config.mvp_item_rate/100;
}
for(i=0;i<MAX_RANDOMMONSTER;i++)
mob_db[class_].summonper[i]=0;
mob_db[class_].maxskill=0;
mob_db[class_].sex=0;
mob_db[class_].hair=0;
mob_db[class_].hair_color=0;
mob_db[class_].weapon=0;
mob_db[class_].shield=0;
mob_db[class_].head_top=0;
mob_db[class_].head_mid=0;
mob_db[class_].head_buttom=0;
mob_db[class_].clothes_color=0; //Add for player monster dye - Valaris
}
fclose(fp);
sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n",filename[i]);
ShowStatus(tmp_output);
}
return 0;
}
/*==========================================
* MOB display graphic change data reading
*------------------------------------------
*/
static int mob_readdb_mobavail(void)
{
FILE *fp;
char line[1024];
int ln=0;
int class_,j,k;
char *str[20],*p,*np;
if( (fp=fopen("db/mob_avail.txt","r"))==NULL ){
printf("can't read db/mob_avail.txt\n");
return -1;
}
while(fgets(line,1020,fp)){
if(line[0]=='/' && line[1]=='/')
continue;
memset(str,0,sizeof(str));
for(j=0,p=line;j<12;j++){
if((np=strchr(p,','))!=NULL){
str[j]=p;
*np=0;
p=np+1;
} else
str[j]=p;
}
if(str[0]==NULL)
continue;
class_=atoi(str[0]);
if(class_<=1000 || class_>MAX_MOB_DB) // �l���ُ�Ȃ珈�����Ȃ��B
continue;
k=atoi(str[1]);
if(k >= 0)
mob_db[class_].view_class=k;
if((mob_db[class_].view_class < 24) || (mob_db[class_].view_class > 4000)) {
mob_db[class_].sex=atoi(str[2]);
mob_db[class_].hair=atoi(str[3]);
mob_db[class_].hair_color=atoi(str[4]);
mob_db[class_].weapon=atoi(str[5]);
mob_db[class_].shield=atoi(str[6]);
mob_db[class_].head_top=atoi(str[7]);
mob_db[class_].head_mid=atoi(str[8]);
mob_db[class_].head_buttom=atoi(str[9]);
mob_db[class_].option=atoi(str[10])&~0x46;
mob_db[class_].clothes_color=atoi(str[11]); // Monster player dye option - Valaris
}
else if(atoi(str[2]) > 0) mob_db[class_].equip=atoi(str[2]); // mob equipment [Valaris]
ln++;
}
fclose(fp);
sprintf(tmp_output,"Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,"db/mob_avail.txt");
ShowStatus(tmp_output);
return 0;
}
/*==========================================
* Reading of random monster data
*------------------------------------------
*/
static int mob_read_randommonster(void)
{
FILE *fp;
char line[1024];
char *str[10],*p;
int i,j;
const char* mobfile[] = {
"db/mob_branch.txt",
"db/mob_poring.txt",
"db/mob_boss.txt" };
for(i=0;i<MAX_RANDOMMONSTER;i++){
mob_db[0].summonper[i] = 1002; // �ݒ肵�Y�ꂽ�ꍇ�̓|�������o��悤�ɂ��Ă���
fp=fopen(mobfile[i],"r");
if(fp==NULL){
printf("can't read %s\n",mobfile[i]);
return -1;
}
while(fgets(line,1020,fp)){
int class_,per;
if(line[0] == '/' && line[1] == '/')
continue;
memset(str,0,sizeof(str));
for(j=0,p=line;j<3 && p;j++){
str[j]=p;
p=strchr(p,',');
if(p) *p++=0;
}
if(str[0]==NULL || str[2]==NULL)
continue;
class_ = atoi(str[0]);
per=atoi(str[2]);
if((class_>1000 && class_<=MAX_MOB_DB) || class_==0)
mob_db[class_].summonper[i]=per;
}
fclose(fp);
sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n",mobfile[i]);
ShowStatus(tmp_output);
}
return 0;
}
/*==========================================
* db/mob_skill_db.txt reading
*------------------------------------------
*/
static int mob_readskilldb(void)
{
FILE *fp;
char line[1024];
int i;
const struct {
char str[32];
int id;
} cond1[] = {
{ "always", MSC_ALWAYS },
{ "myhpltmaxrate", MSC_MYHPLTMAXRATE },
{ "friendhpltmaxrate",MSC_FRIENDHPLTMAXRATE },
{ "mystatuson", MSC_MYSTATUSON },
{ "mystatusoff", MSC_MYSTATUSOFF },
{ "friendstatuson", MSC_FRIENDSTATUSON },
{ "friendstatusoff", MSC_FRIENDSTATUSOFF },
{ "attackpcgt", MSC_ATTACKPCGT },
{ "attackpcge", MSC_ATTACKPCGE },
{ "slavelt", MSC_SLAVELT },
{ "slavele", MSC_SLAVELE },
{ "closedattacked", MSC_CLOSEDATTACKED },
{ "longrangeattacked",MSC_LONGRANGEATTACKED },
{ "skillused", MSC_SKILLUSED },
{ "casttargeted", MSC_CASTTARGETED },
}, cond2[] ={
{ "anybad", -1 },
{ "stone", SC_STONE },
{ "freeze", SC_FREEZE },
{ "stan", SC_STAN },
{ "sleep", SC_SLEEP },
{ "poison", SC_POISON },
{ "curse", SC_CURSE },
{ "silence", SC_SILENCE },
{ "confusion", SC_CONFUSION },
{ "blind", SC_BLIND },
{ "hiding", SC_HIDING },
{ "sight", SC_SIGHT },
}, state[] = {
{ "any", -1 },
{ "idle", MSS_IDLE },
{ "walk", MSS_WALK },
{ "attack", MSS_ATTACK },
{ "dead", MSS_DEAD },
{ "loot", MSS_LOOT },
{ "chase", MSS_CHASE },
}, target[] = {
{ "target", MST_TARGET },
{ "self", MST_SELF },
{ "friend", MST_FRIEND },
{ "around5", MST_AROUND5 },
{ "around6", MST_AROUND6 },
{ "around7", MST_AROUND7 },
{ "around8", MST_AROUND8 },
{ "around1", MST_AROUND1 },
{ "around2", MST_AROUND2 },
{ "around3", MST_AROUND3 },
{ "around4", MST_AROUND4 },
{ "around", MST_AROUND },
};
int x;
char *filename[]={ "db/mob_skill_db.txt","db/mob_skill_db2.txt" };
for(x=0;x<2;x++){
fp=fopen(filename[x],"r");
if(fp==NULL){
if(x==0)
printf("can't read %s\n",filename[x]);
continue;
}
while(fgets(line,1020,fp)){
char *sp[20],*p;
int mob_id;
struct mob_skill *ms;
int j=0;
if(line[0] == '/' && line[1] == '/')
continue;
memset(sp,0,sizeof(sp));
for(i=0,p=line;i<18 && p;i++){
sp[i]=p;
if((p=strchr(p,','))!=NULL)
*p++=0;
}
if( (mob_id=atoi(sp[0]))<=0 )
continue;
if( strcmp(sp[1],"clear")==0 ){
memset(mob_db[mob_id].skill,0,sizeof(mob_db[mob_id].skill));
mob_db[mob_id].maxskill=0;
continue;
}
for(i=0;i<MAX_MOBSKILL;i++)
if( (ms=&mob_db[mob_id].skill[i])->skill_id == 0)
break;
if(i==MAX_MOBSKILL){
printf("mob_skill: readdb: too many skill ! [%s] in %d[%s]\n",
sp[1],mob_id,mob_db[mob_id].jname);
continue;
}
ms->state=atoi(sp[2]);
for(j=0;j<sizeof(state)/sizeof(state[0]);j++){
if( strcmp(sp[2],state[j].str)==0)
ms->state=state[j].id;
}
ms->skill_id=atoi(sp[3]);
j=atoi(sp[4]);
if (j<=0 || j>MAX_SKILL_DB)
continue;
ms->skill_lv=j;
ms->permillage=atoi(sp[5]);
ms->casttime=atoi(sp[6]);
ms->delay=atoi(sp[7]);
ms->cancel=atoi(sp[8]);
if( strcmp(sp[8],"yes")==0 ) ms->cancel=1;
ms->target=atoi(sp[9]);
for(j=0;j<sizeof(target)/sizeof(target[0]);j++){
if( strcmp(sp[9],target[j].str)==0)
ms->target=target[j].id;
}
ms->cond1=-1;
for(j=0;j<sizeof(cond1)/sizeof(cond1[0]);j++){
if( strcmp(sp[10],cond1[j].str)==0)
ms->cond1=cond1[j].id;
}
ms->cond2=atoi(sp[11]);
for(j=0;j<sizeof(cond2)/sizeof(cond2[0]);j++){
if( strcmp(sp[11],cond2[j].str)==0)
ms->cond2=cond2[j].id;
}
ms->val[0]=atoi(sp[12]);
ms->val[1]=atoi(sp[13]);
ms->val[2]=atoi(sp[14]);
ms->val[3]=atoi(sp[15]);
ms->val[4]=atoi(sp[16]);
if(sp[17] != NULL && strlen(sp[17])>2)
ms->emotion=atoi(sp[17]);
else
ms->emotion=-1;
mob_db[mob_id].maxskill=i+1;
}
fclose(fp);
sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n",filename[x]);
ShowStatus(tmp_output);
}
return 0;
}
/*==========================================
* db/mob_race_db.txt reading
*------------------------------------------
*/
static int mob_readdb_race(void)
{
FILE *fp;
char line[1024];
int race,j,k;
char *str[20],*p,*np;
if( (fp=fopen("db/mob_race2_db.txt","r"))==NULL ){
printf("can't read db/mob_race2_db.txt\n");
return -1;
}
while(fgets(line,1020,fp)){
if(line[0]=='/' && line[1]=='/')
continue;
memset(str,0,sizeof(str));
for(j=0,p=line;j<12;j++){
if((np=strchr(p,','))!=NULL){
str[j]=p;
*np=0;
p=np+1;
} else
str[j]=p;
}
if(str[0]==NULL)
continue;
race=atoi(str[0]);
if (race < 0 || race >= MAX_MOB_RACE_DB)
continue;
for (j=1; j<20; j++) {
if (!str[j])
break;
k=atoi(str[j]);
if (k < 1000 || k > MAX_MOB_DB)
continue;
mob_db[k].race2 = race;
//mob_race_db[race][j] = k;
}
}
fclose(fp);
sprintf(tmp_output,"Done reading '"CL_WHITE"%s"CL_RESET"'.\n","db/mob_race2_db.txt");
ShowStatus(tmp_output);
return 0;
}
void mob_reload(void)
{
/*
<empty monster database>
mob_read();
*/
do_init_mob();
}
#ifndef TXT_ONLY
/*==========================================
* SQL reading
*------------------------------------------
*/
static int mob_read_sqldb(void)
{
char line[1024];
int i,class_;
long unsigned int ln=0;
char *str[60],*p,*np; // 55->60 Lupus
memset(mob_db,0,sizeof(mob_db));
sprintf (tmp_sql, "SELECT * FROM `%s`",mob_db_db);
if(mysql_query(&mmysql_handle, tmp_sql) ) {
printf("DB server Error (select %s to Memory)- %s\n",mob_db_db,mysql_error(&mmysql_handle) );
}
sql_res = mysql_store_result(&mmysql_handle);
if (sql_res) {
while((sql_row = mysql_fetch_row(sql_res))){
sprintf(line,"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
sql_row[0],sql_row[1],sql_row[2],sql_row[3],sql_row[4],
sql_row[5],sql_row[6],sql_row[7],sql_row[8],sql_row[9],
sql_row[10],sql_row[11],sql_row[12],sql_row[13],sql_row[14],
sql_row[15],sql_row[16],sql_row[17],sql_row[18],sql_row[19],
sql_row[20],sql_row[21],sql_row[22],sql_row[23],sql_row[24],
sql_row[25],sql_row[26],sql_row[27],sql_row[28],sql_row[29],
sql_row[30],sql_row[31],sql_row[32],sql_row[33],sql_row[34],
sql_row[35],sql_row[36],sql_row[37],sql_row[38],sql_row[39],
sql_row[40],sql_row[41],sql_row[42],sql_row[43],sql_row[44],
sql_row[45],sql_row[46],sql_row[47],sql_row[48],sql_row[49],
sql_row[50],sql_row[51],sql_row[52],sql_row[53],sql_row[54],
sql_row[55],sql_row[56]);
for(i=0,p=line;i<57;i++){
if((np=strchr(p,','))!=NULL){
str[i]=p;
*np=0;
p=np+1;
} else
str[i]=p;
}
class_=atoi(str[0]);
if(class_<=1000 || class_>MAX_MOB_DB)
continue;
ln++;
mob_db[class_].view_class=class_;
memcpy(mob_db[class_].name,str[1],24);
memcpy(mob_db[class_].jname,str[2],24);
mob_db[class_].lv=atoi(str[3]);
mob_db[class_].max_hp=atoi(str[4]);
mob_db[class_].max_sp=atoi(str[5]);
mob_db[class_].base_exp = atoi(str[6]);
if (mob_db[class_].base_exp <= 0)
mob_db[class_].base_exp = 0;
else if (mob_db[class_].base_exp * battle_config.base_exp_rate / 100 > 1000000000 ||
mob_db[class_].base_exp * battle_config.base_exp_rate / 100 < 0)
mob_db[class_].base_exp = 1000000000;
else {
mob_db[class_].base_exp = mob_db[class_].base_exp * battle_config.base_exp_rate / 100;
if (mob_db[class_].base_exp < 1)
mob_db[class_].base_exp = 1;
}
mob_db[class_].job_exp = atoi(str[7]);
if (mob_db[class_].job_exp <= 0)
mob_db[class_].job_exp = 0;
else if (mob_db[class_].job_exp * battle_config.job_exp_rate / 100 > 1000000000 ||
mob_db[class_].job_exp * battle_config.job_exp_rate / 100 < 0)
mob_db[class_].job_exp = 1000000000;
else {
mob_db[class_].job_exp = mob_db[class_].job_exp * battle_config.job_exp_rate / 100;
if (mob_db[class_].job_exp < 1)
mob_db[class_].job_exp = 1;
}
mob_db[class_].range=atoi(str[8]);
mob_db[class_].atk1=atoi(str[9]);
mob_db[class_].atk2=atoi(str[10]);
mob_db[class_].def=atoi(str[11]);
mob_db[class_].mdef=atoi(str[12]);
mob_db[class_].str=atoi(str[13]);
mob_db[class_].agi=atoi(str[14]);
mob_db[class_].vit=atoi(str[15]);
mob_db[class_].int_=atoi(str[16]);
mob_db[class_].dex=atoi(str[17]);
mob_db[class_].luk=atoi(str[18]);
mob_db[class_].range2=atoi(str[19]);
mob_db[class_].range3=atoi(str[20]);
mob_db[class_].size=atoi(str[21]);
mob_db[class_].race=atoi(str[22]);
mob_db[class_].element=atoi(str[23]);
mob_db[class_].mode=atoi(str[24]);
mob_db[class_].speed=atoi(str[25]);
mob_db[class_].adelay=atoi(str[26]);
mob_db[class_].amotion=atoi(str[27]);
mob_db[class_].dmotion=atoi(str[28]);
for(i=0;i<10;i++){ // 8 -> 10 Lupus
int rate = 0,type,ratemin,ratemax;
mob_db[class_].dropitem[i].nameid=atoi(str[29+i*2]);
type = itemdb_type(mob_db[class_].dropitem[i].nameid);
if (type == 0) { // Added by Valaris
rate = battle_config.item_rate_heal * atoi(str[30+i*2]) / 100;
ratemin = battle_config.item_drop_heal_min;
ratemax = battle_config.item_drop_heal_max;
}
else if (type == 2) {
rate = battle_config.item_rate_use * atoi(str[30+i*2]) / 100;
ratemin = battle_config.item_drop_use_min;
ratemax = battle_config.item_drop_use_max; // End
}
else if (type == 4 || type == 5 || type == 8) { // Changed to include Pet Equip
rate = battle_config.item_rate_equip * atoi(str[30+i*2]) / 100;
ratemin = battle_config.item_drop_equip_min;
ratemax = battle_config.item_drop_equip_max;
}
else if (type == 6) {
rate = battle_config.item_rate_card * atoi(str[30+i*2]) / 100;
ratemin = battle_config.item_drop_card_min;
ratemax = battle_config.item_drop_card_max;
}
else {
rate = battle_config.item_rate_common * atoi(str[30+i*2]) / 100;
ratemin = battle_config.item_drop_common_min;
ratemax = battle_config.item_drop_common_max;
}
mob_db[class_].dropitem[i].p = (rate < ratemin) ? ratemin : (rate > ratemax) ? ratemax: rate;
}
// MVP EXP Bonus, Chance: MEXP,ExpPer
mob_db[class_].mexp=atoi(str[49])*battle_config.mvp_exp_rate/100;
mob_db[class_].mexpper=atoi(str[50]);
// MVP Drops: MVP1id,MVP1per,MVP2id,MVP2per,MVP3id,MVP3per
for(i=0;i<3;i++){
mob_db[class_].mvpitem[i].nameid=atoi(str[51+i*2]);
mob_db[class_].mvpitem[i].p=atoi(str[52+i*2])*battle_config.mvp_item_rate/100;
}
for(i=0;i<MAX_RANDOMMONSTER;i++)
mob_db[class_].summonper[i]=0;
mob_db[class_].maxskill=0;
mob_db[class_].sex=0;
mob_db[class_].hair=0;
mob_db[class_].hair_color=0;
mob_db[class_].weapon=0;
mob_db[class_].shield=0;
mob_db[class_].head_top=0;
mob_db[class_].head_mid=0;
mob_db[class_].head_buttom=0;
}
mysql_free_result(sql_res);
sprintf(tmp_output,"Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n",ln,mob_db_db);
ShowStatus(tmp_output);
}
return 0;
}
#endif /* not TXT_ONLY */
/*==========================================
* Circumference initialization of mob
*------------------------------------------
*/
int do_init_mob(void)
{
#ifndef TXT_ONLY
if(db_use_sqldbs)
mob_read_sqldb();
else
#endif /* TXT_ONLY */
mob_readdb();
mob_readdb_mobavail();
mob_read_randommonster();
mob_readskilldb();
mob_readdb_race();
add_timer_func_list(mob_timer,"mob_timer");
add_timer_func_list(mob_delayspawn,"mob_delayspawn");
add_timer_func_list(mob_delay_item_drop,"mob_delay_item_drop");
add_timer_func_list(mob_delay_item_drop2,"mob_delay_item_drop2");
add_timer_func_list(mob_ai_hard,"mob_ai_hard");
add_timer_func_list(mob_ai_lazy,"mob_ai_lazy");
add_timer_func_list(mobskill_castend_id,"mobskill_castend_id");
add_timer_func_list(mobskill_castend_pos,"mobskill_castend_pos");
add_timer_func_list(mob_timer_delete,"mob_timer_delete");
add_timer_interval(gettick()+MIN_MOBTHINKTIME,mob_ai_hard,0,0,MIN_MOBTHINKTIME);
add_timer_interval(gettick()+MIN_MOBTHINKTIME*10,mob_ai_lazy,0,0,MIN_MOBTHINKTIME*10);
return 0;
}
|