forked from cIII1993/LineBotTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
2830 lines (2741 loc) · 100 KB
/
bot.js
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
/* jshint esversion: 9 */
class Bot {
constructor() {
////
this.parseInput = (inputStr) => {
let res;
for (let p in this.parser) {
res = this.parser[p](inputStr);
if (res != undefined && res != "") break;
}
return res;
};
this.parserExtant = (parserName, parserFn) => {
this.parser[parserName] = parserFn;
return this;
};
this.helpList = [];
this.helpExtant = (parserName, helpFn) => {
this.helpList = this.helpList.concat(...helpFn);
return this;
};
////
this.version = '2.11 dndbo';
//表格放置區
////sw2.0
this.powerSheet = [
[0, 0, 0, 1, 2, 2, 3, 3, 4, 4],
[0, 0, 0, 1, 2, 3, 3, 3, 4, 4],
[0, 0, 0, 1, 2, 3, 4, 4, 4, 4],
[0, 0, 1, 1, 2, 3, 4, 4, 4, 5],
[0, 0, 1, 2, 2, 3, 4, 4, 5, 5],
[0, 1, 1, 2, 2, 3, 4, 5, 5, 5],
[0, 1, 1, 2, 3, 3, 4, 5, 5, 5],
[0, 1, 1, 2, 3, 4, 4, 5, 5, 6],
[0, 1, 2, 2, 3, 4, 4, 5, 6, 6],
[0, 1, 2, 3, 3, 4, 4, 5, 6, 7],
[1, 1, 2, 3, 3, 4, 5, 5, 6, 7],
[1, 2, 2, 3, 3, 4, 5, 6, 6, 7],
[1, 2, 2, 3, 4, 4, 5, 6, 6, 7],
[1, 2, 3, 3, 4, 4, 5, 6, 7, 7],
[1, 2, 3, 4, 4, 4, 5, 6, 7, 8],
[1, 2, 3, 4, 4, 5, 5, 6, 7, 8],
[1, 2, 3, 4, 4, 5, 6, 7, 7, 8],
[1, 2, 3, 4, 5, 5, 6, 7, 7, 8],
[1, 2, 3, 4, 5, 6, 6, 7, 7, 8],
[1, 2, 3, 4, 5, 6, 7, 7, 8, 9],
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
[2, 2, 3, 4, 6, 6, 7, 8, 9, 10],
[2, 2, 3, 5, 6, 6, 7, 8, 9, 10],
[2, 2, 3, 5, 6, 7, 7, 8, 9, 10],
[2, 3, 4, 5, 6, 7, 7, 8, 9, 10],
[2, 3, 4, 5, 6, 7, 8, 8, 9, 10],
[2, 3, 4, 5, 6, 8, 8, 9, 9, 10],
[2, 3, 4, 6, 6, 8, 8, 9, 9, 10],
[2, 3, 4, 6, 6, 8, 9, 9, 10, 10],
[2, 3, 4, 6, 7, 8, 9, 9, 10, 10],
[2, 4, 4, 6, 7, 8, 9, 10, 10, 10],
[2, 4, 5, 6, 7, 8, 9, 10, 10, 11],
[3, 4, 5, 6, 7, 8, 10, 10, 10, 11],
[3, 4, 5, 6, 8, 8, 10, 10, 10, 11],
[3, 4, 5, 6, 8, 9, 10, 10, 11, 11],
[3, 4, 5, 7, 8, 9, 10, 10, 11, 12],
[3, 5, 5, 7, 8, 9, 10, 11, 11, 12],
[3, 5, 6, 7, 8, 9, 10, 11, 12, 12],
[3, 5, 6, 7, 8, 10, 10, 11, 12, 13],
[4, 5, 6, 7, 8, 10, 11, 11, 12, 13],
[4, 5, 6, 7, 9, 10, 11, 11, 12, 13],
[4, 6, 6, 7, 9, 10, 11, 12, 12, 13],
[4, 6, 7, 7, 9, 10, 11, 12, 13, 13],
[4, 6, 7, 8, 9, 10, 11, 12, 13, 14],
[4, 6, 7, 8, 10, 10, 11, 12, 13, 14],
[4, 6, 7, 9, 10, 10, 11, 12, 13, 14],
[4, 6, 7, 9, 10, 10, 12, 13, 13, 14],
[4, 6, 7, 9, 10, 11, 12, 13, 13, 15],
[4, 6, 7, 9, 10, 12, 12, 13, 13, 15],
[4, 6, 7, 10, 10, 12, 12, 13, 14, 15],
[4, 6, 8, 10, 10, 12, 12, 13, 15, 15],
[5, 7, 8, 10, 10, 12, 12, 13, 15, 15],
[5, 7, 8, 10, 11, 12, 12, 13, 15, 15],
[5, 7, 9, 10, 11, 12, 12, 14, 15, 15],
[5, 7, 9, 10, 11, 12, 13, 14, 15, 16],
[5, 7, 10, 10, 11, 12, 13, 14, 16, 16],
[5, 8, 10, 10, 11, 12, 13, 15, 16, 16],
[5, 8, 10, 11, 11, 12, 13, 15, 16, 17],
[5, 8, 10, 11, 12, 12, 13, 15, 16, 17],
[5, 9, 10, 11, 12, 12, 14, 15, 16, 17],
[5, 9, 10, 11, 12, 13, 14, 15, 16, 18],
[5, 9, 10, 11, 12, 13, 14, 16, 17, 18],
[5, 9, 10, 11, 13, 13, 14, 16, 17, 18],
[5, 9, 10, 11, 13, 13, 15, 17, 17, 18],
[5, 9, 10, 11, 13, 14, 15, 17, 17, 18],
[5, 9, 10, 12, 13, 14, 15, 17, 18, 18],
[5, 9, 10, 12, 13, 15, 15, 17, 18, 19],
[5, 9, 10, 12, 13, 15, 16, 17, 19, 19],
[5, 9, 10, 12, 14, 15, 16, 17, 19, 19],
[5, 9, 10, 12, 14, 16, 16, 17, 19, 19],
[5, 9, 10, 12, 14, 16, 17, 18, 19, 19],
[5, 9, 10, 13, 14, 16, 17, 18, 19, 20],
[5, 9, 10, 13, 15, 16, 17, 18, 19, 20],
[5, 9, 10, 13, 15, 16, 17, 19, 20, 21],
[6, 9, 10, 13, 15, 16, 18, 19, 20, 21],
[6, 9, 10, 13, 16, 16, 18, 19, 20, 21],
[6, 9, 10, 13, 16, 17, 18, 19, 20, 21],
[6, 9, 10, 13, 16, 17, 18, 20, 21, 22],
[6, 9, 10, 13, 16, 17, 19, 20, 22, 23],
[6, 9, 10, 13, 16, 18, 19, 20, 22, 23],
[6, 9, 10, 13, 16, 18, 20, 21, 22, 23],
[6, 9, 10, 13, 17, 18, 20, 21, 22, 23],
[6, 9, 10, 14, 17, 18, 20, 21, 22, 24],
[6, 9, 11, 14, 17, 18, 20, 21, 23, 24],
[6, 9, 11, 14, 17, 19, 20, 21, 23, 24],
[6, 9, 11, 14, 17, 19, 21, 22, 23, 24],
[7, 10, 11, 14, 17, 19, 21, 22, 23, 25],
[7, 10, 12, 14, 17, 19, 21, 22, 24, 25],
[7, 10, 12, 14, 18, 19, 21, 22, 24, 25],
[7, 10, 12, 15, 18, 19, 21, 22, 24, 26],
[7, 10, 12, 15, 18, 19, 21, 23, 25, 26],
[7, 11, 13, 15, 18, 19, 21, 23, 25, 26],
[7, 11, 13, 15, 18, 20, 21, 23, 25, 27],
[8, 11, 13, 15, 18, 20, 22, 23, 25, 27],
[8, 11, 13, 16, 18, 20, 22, 23, 25, 28],
[8, 11, 14, 16, 18, 20, 22, 23, 26, 28],
[8, 11, 14, 16, 19, 20, 22, 23, 26, 28],
[8, 12, 14, 16, 19, 20, 22, 24, 26, 28],
[8, 12, 15, 16, 19, 20, 22, 24, 27, 28],
[8, 12, 15, 17, 19, 20, 22, 24, 27, 29],
[8, 12, 15, 18, 19, 20, 22, 24, 27, 30]
];
this.swRmSheet1 = ['有個領主', '一把守護之劍', '一批走私貨品', '一個德雷克', '一隊暗影傭兵團', '一隊貿易商旅', '一個神官', '一堆狗頭人', '三隻伯格妖', '一個精靈', '一群精靈', '一個矮人', '一群矮人', '一個人類', '一群人類', '一個草原妖精', '一群草原妖精', '一個塔比特', '一群長頸巨龍', '一群哥布林', '一個符民', '一個未啟動的符民', '兩隻巴西利斯克', '一大群人馬', '一支蠻族軍隊', '一個龍人', '一個慧人', '一個女武神', '一個古貓人', '一隻兔子', '一個吟遊詩人', '三萬伯格妖', '三億個龍人', '一個公會長', '一批輕騎兵', '一個傭兵團', '一批重步兵', '一個國王', '兩個公爵', '三個伯爵', '四個男爵', '五個子爵', '六個侯爵', '七個小矮人', '八個老太婆', '九個太陽傳教士', '一個手持雙刀的輕戰士', '一個手無縛雞之力的拳鬥士', '一個身穿重裝鎧甲的法師', '某個工具人'];
this.swRmSheet2 = ['在宴會上', '在冒險者店裡', '在森林裡', '在河邊', '在娼館裡', '在路邊', '在睡覺時', '在領主宅底', '在魔動文明遺跡中', '在一座小島上', '在隔壁城鎮', '在附近的村莊', '在平原上', '在迷宮裡', '在城牆上', '在船上', '在發呆時', '在蒐集戰利品時', '在貧民窟裡', '在攻擊的時候', '在洗澡之前,脫光了以後', '在櫃台前', '在異空間', '在戰場中央', '在山頂上', '在沙漠', '在沼澤', '在極寒之地', '在餐廳', '在沙灘上', '在湖裡', '在洞窟', '在王宮', '在莊園裡', '在旅館', '在冒險者公會', '在酒館', '在教堂', '在賭場', '在競技場', '在火山', '在冰河', '在哨所中', '在堡壘裡', '在軍營', '在一座高塔上面', '在內衣堆上'];
this.swRmSheet3 = ['被吃掉了', '爆炸了', '被藏起來了', '失蹤了', '喝醉了', '打起來了', '自殺了', '佔領該處了', '到處施放魔法', '準備睡覺了', '販賣戰利品', '脫手裝備中', '開始遊行了', '展開攻擊了', '被襲擊了', '被偷走了', '當上領主了', '當上神官了', '四處搜索著', '騎著魔動機車', '找到了迷宮入口', '看到了貴族的醜聞', '孵了一顆蛋', '被拿去料理了', '下海了', '發起革命', '膝蓋上中了一箭', '組成了聯邦', '協議停戰了', '叛亂了', '得了重病', '被埋伏了', '開始無差別殺人', '解放了奴隸', '脫褲子放屁', '得了不治之症', '暴斃了', '腿斷了', '瞎了', '唱起歌來', '無法生育了', '受到了詛咒', '失智了', '精神失常了', '撿到了古文明的神奇物品', '謀殺行動暴露了', '偷情被發現了', '去朝聖了', '蓋了一座實驗室', '重要的東西被偷走了', '使用左右開弓打出了1000點傷害', '用守護吃下了全部的傷害還沒有死', '用石頭打死一個伯格妖', '用內褲悶死一隻哥布林'];
//表格結束
this.parser = {
oriParser: (inputStr) => {
let countStr = '';
let msgSplitor = (/\S+/ig);
let mainMsg = inputStr.match(msgSplitor);
let trigger = mainMsg[0].toString().toLowerCase();
//let trigger2 = mainMsg[1].toString().toLowerCase();
//help
if (trigger.match(new RegExp(`^(sw|sg|dryh|toy|wq|qy|ddr|${this.helpList.map(h => h.reg.toLowerCase()).join("|")})?(help|幫助)$`, "g")) != null) {
return this.help(trigger);
}
if (trigger.match(/^ver$/) != null) {
return this.version;
}
//SW2.0 威力骰
if (trigger.match(/^(k)(\d+)(((\+|-)\d+)|(@\d+)|(#\d+)|(\$(\+|-)?\d+)|(gf))*$/) != null) {
return this.Kx(trigger);
}
//SW2.0 超越判定
if (trigger.match(/^swfc((\+|-)\d+)?$/) != null) {
return this.swFc(trigger);
}
//SW2.0 成長骰
if (trigger.match(/^gr\d*$/) != null) {
return this.swGr(trigger);
}
//SW2.0 大失敗表
if (trigger.match(/^swft$/) != null) {
return this.swFt();
}
//SW2.0 纏繞表
if (trigger.match(/^swtt$/) != null) {
return this.swTt();
}
//SW2.0 流言表
if (trigger.match(/^swrm$/) != null) {
return this.swRm();
}
//SW2.0 寶物表
if (trigger.match(/^swdi$/) != null) {
return this.swDi();
}
//SW2.0 城鎮生成
if (trigger.match(/^swtw/) != null) {
return this.swTw(trigger);
}
//忍神判定
if (trigger.match(/^sg(\+\d+|-\d+)?>=\d+(#\d+)?(@\d+)?$/) != null) {
return this.sg(trigger);
}
if (trigger.match(/^sg$/) != null) {
return this.sg('sg>=5');
}
//忍神情感表
if (trigger.match(/^sget$/) != null) {
return this.sgEt();
}
//忍神大失敗表
if (trigger.match(/^sgft$/) != null) {
return this.sgFt();
}
//忍神變調表
if (trigger.match(/^sgwt$/) != null) {
return this.sgWt();
}
//忍神戰國變調表
if (trigger.match(/^sggwt$/) != null) {
return this.sgGWt();
}
//忍神場景表
if (trigger.match(/^sgst$/) != null) {
return this.sgSt();
}
//忍神分野表
if (trigger.match(/^sgrtt$/) != null) {
return this.sgRtt();
}
//忍神戰場表
if (trigger.match(/^sgbt$/) != null) {
return this.sgBt();
}
//CoC7基本骰組
if (trigger.match(/^cc<=\d+(\(-?\d+\))?$/) != null) {
return this.cc(trigger);
}
//死亡flag flag表
if (trigger.match(/^df$/) != null) {
return this.df();
}
//死亡flag 場景表
if (trigger.match(/^dfs$/) != null) {
return this.dfs();
}
//死亡flag 關係表
if (trigger.match(/^dfr$/) != null) {
return this.dfr();
}
//請勿入睡 PC骰
if (trigger.match(/^dryh((\d+d)|(\d+e)|(\d+m))+$/) != null) {
return this.dontRestYourHeadPC(trigger);
}
//請勿入睡 GM骰
if (trigger.match(/^dryh(\d+p)$/) != null) {
return this.dontRestYourHeadGM(trigger);
}
//fudge骰
if (trigger.match(/^fg(\+\d+|-\d+)*$/) != null) {
return this.fudge(trigger);
}
//wq骰
if (trigger.match(/^wq(\d|\+|-)+/) != null) {
return this.wq(trigger);
}
//wqm骰
if (trigger.match(/^wqm(\d|\+|-)+/) != null) {
return this.wqm(trigger);
}
//wqt骰
if (trigger.match(/^wqt/) != null) {
return this.wqt(trigger);
}
//qy骰
if (trigger.match(/^qy(sp|sm|at|wt)?\d*$/) != null) {
return this.qy(trigger);
}
//dnd骰
if (trigger.match(/^dndbuild$/) != null) {
return this.dndBuild();
}
//dndbo骰
if (trigger.match(/^dndbo$/) != null) {
return this.dndBo();
}
//duderun骰
if (trigger.match(/^ddr\d+/) != null) {
return this.ddr(trigger);
}
if (trigger.match(/^ddra\d+/) != null) {
return this.ddrAdd(trigger);
}
//em骰
if (trigger.match(/^\d*em\d+$/) != null) {
return this.em(trigger);
}
//cookJudge骰
if (inputStr.match(/^ck (\S+ )+/i) != null) {
return this.cookJudge(inputStr);
}
//cook骰
if (trigger.match(/^ck\d+/) != null) {
return this.cook(trigger);
}
//基本骰組 this.xDx+a>b
if (trigger.match(/^(\d+d\d+|\d+d)((\+|-)\d+)?((>=|<=|=|>|<)\d+)?$/) != null) {
return this.xDx(trigger);
}
//基本骰組 this.xBx+a>b
if (trigger.match(/^(\d+b\d+|\d+b|b\d+)((\+|-)\d+)?((>=|<=|=|>|<)\d+)?$/) != null) {
return this.xBx(trigger);
}
//基本骰組 this.d66
if (trigger.match(/^d66$/) != null) {
return this.d66();
}
//基本骰組 choice
if (trigger.match(/^choice$/) != null) {
return this.choice(inputStr);
}
//基本骰組 choiceN
if (trigger.match(/^choice\d+$/) != null) {
return this.choiceN(inputStr);
}
//基本骰組 week
if (trigger.match(/^\d+\.\d\d?\.\d\d?$/) != null) {
return this.week(trigger);
}
///基本運算
if (trigger.match(/[^\d\+\-\*\/%\(\)\.d><=]/) == null &&
trigger.match(/[\+\-\*\/%><=]/) != null &&
trigger.match(/^[\d\+\-\*\/%\(\)\.d]+((>=|<=|=|>|<)\d+(\.\d+)?)?/) != null) {
return this.claculate(trigger);
}
//*/
//雜項
if (trigger.match(/^(紅炎的|紅蓮的)/) != null) {
return '\\蓮帝/';
}
if (trigger.match(/投人機$/) != null) {
return this.terbuchet(trigger);
}
if (trigger.match(/^霍普rm$/) != null) {
return this.GinWayRm();
}
if (trigger.match(/^hpm\d*$/) != null) {
return this.GinWayMonster();
}
if (trigger.match(/^生成霍普角色$/) != null) {
return this.GinWayCharacter();
}
if (trigger.match(/^\\泡泡\/$/) != null) {
return '泡泡!泡泡!更多泡泡!';
}
if (inputStr.match(/複雜度/) != null ||
inputStr.match(/O\(\)/) != null) {
return '☆逼歐恩平方☆';
}
if (trigger.match(/^(鑑定|aps|鑑定武器|apsw|鑑定防具|apsa|鑑定道具|apsi)/) != null) {
return this.appraisal(inputStr);
}
/*/
if (inputStr.match(/(峻巍|霍普|哼|機掰|G8|閉嘴|口亨)/)!= null ){
return this.GinWay();
}
//*/
//
if (inputStr.match(/霍普黑雷達/) != null) {
return this.GinWay();
}
//*/
return countStr;
}
};
}
//骰組function
////seed random
srand(seed) {
seed = '0.' + Math.sin(seed).toString().substr(6);
return Number(seed);
}
////this.strToSeed
strToSeed(inputStr) {
let seed = 7;
for (let i = 0; i < inputStr.length; i++) {
seed = (seed / 7 * inputStr.charCodeAt(i)) % 65535;
}
return Number(seed);
}
////this.extract
extract(rate, num) {
let sum = 0;
num = num * rate.reduce(function(a, b) {
return a + b;
}, 0);
for (let i = 0; i < rate.length; i++) {
sum += rate[i];
if (sum > num) return i;
}
return undefined;
}
////this.extractStr
extractStr(rate, num) {
let sum = 0;
num = num * rate.reduce(function(a, b) {
return a + b[0];
}, 0);
for (let i = 0; i < rate.length; i++) {
sum += rate[i][0];
if (sum > num) return rate[i][1];
}
return undefined;
}
////基本運算
claculate(inputStr) {
let returnStr = '基礎運算:';
let claculate = inputStr.match(/^[\d\+\-\*\/%\(\)\.d]+/)[0].toString();
let compare = null;
if (inputStr.match(/(>=|<=|=|>|<)\d+/) != null) {
compare = inputStr.match(/(>=|<=|=|>|<)\d+/)[0].toString();
}
while (claculate.match(/\d+d\d+/) != null) {
let input = claculate.match(/\d+d\d+/)[0].toString();
let output = 0;
let num = input.match(/\d+/g);
for (let i = 0; i < num[0]; i++) {
let dice = Math.ceil(Math.random() * num[1]);
output += dice;
}
claculate = claculate.replace(input, output);
}
returnStr += claculate + ' = ';
let sum = eval(claculate);
if (Math.abs(sum - Math.round(sum)) > 0.01)
returnStr += sum.toFixed(2);
else
returnStr += sum.toFixed(0);
if (compare != null) {
returnStr += ' ' + compare;
if (eval(sum + compare)) returnStr += ' → 成功';
else returnStr += ' → 失敗';
}
return returnStr;
}
////基本骰組
xDx(inputStr) {
let returnStr = '基本擲骰:[';
let answer = 0;
let bool = false;
//this.xDx
if (inputStr.match(/\d+d\d+/) != null) {
let tempMatch = inputStr.match(/\d+d\d+/).toString();
let a = tempMatch.match(/\d+/g);
for (let i = 0; i < a[0]; i++) {
let dice = Math.ceil(Math.random() * a[1]);
answer += dice;
if (i > 0) returnStr += ',';
returnStr += dice.toString();
}
returnStr += ']';
}
//xD
else if (inputStr.match(/\d+d/) != null) {
let tempMatch = inputStr.match(/\d+d/).toString();
let a = tempMatch.match(/\d+/g);
for (let i = 0; i < a[0]; i++) {
let dice = Math.ceil(Math.random() * 6);
answer += dice;
if (i > 0) returnStr += ',';
returnStr += dice.toString();
}
returnStr += ']';
}
//Dx
else if (inputStr.match(/d\d+/) != null) {
return undefined;
}
if (inputStr.match(/\+\d+/) != null) {
let tempMatch = inputStr.match(/\+\d+/).toString();
let a = tempMatch.match(/\d+/g);
answer += Number(a[0]);
returnStr += '+' + a[0].toString();
}
if (inputStr.match(/-\d+/) != null) {
let tempMatch = inputStr.match(/-\d+/).toString();
let a = tempMatch.match(/\d+/g);
answer -= Number(a[0]);
returnStr += '-' + a[0].toString();
}
returnStr += ' = ' + answer.toString();
if (inputStr.match(/(>=|<=|=|>|<)\d+/)) {
let tempMatch = inputStr.match(/(>=|<=|=|>|<)\d+/).toString();
let a = tempMatch.match(/\d+/g);
if (tempMatch.match(/>/) && Number(answer) > Number(a[0]))
returnStr += '→成功';
else if (tempMatch.match(/</) && Number(answer) < Number(a[0]))
returnStr += '→成功';
else if (tempMatch.match(/=/) && Number(answer) == Number(a[0]))
returnStr += '→成功';
else returnStr += '→失敗';
}
return returnStr;
}
xBx(inputStr) {
let returnStr = '基本擲骰:[';
let clacu = inputStr.match(/\d*b\d*/)[0].toString();
let adding = null;
if (inputStr.match(/(\+|-)\d+/) != null) {
adding = inputStr.match(/(\+|-)\d+/)[0].toString();
}
let compare = null;
if (inputStr.match(/(>=|<=|=|>|<)\d+/) != null) {
compare = inputStr.match(/(>=|<=|=|>|<)\d+/)[0].toString();
}
let answer = 0;
let successCount = 0;
let bool = false;
//xB
if (clacu.match(/^\d+b$/) != null) {
clacu = clacu + '6';
}
//Bx
if (clacu.match(/^b\d+$/) != null) {
clacu = '1' + clacu;
}
//this.xBx
if (clacu.match(/\d+b\d+/) != null) {
let num = clacu.match(/\d+/g);
for (let i = 0; i < num[0]; i++) {
let dice = Math.ceil(Math.random() * num[1]);
if (i > 0) returnStr += ', ';
if (adding != null) dice = eval(dice + adding);
returnStr += dice.toString();
if (compare != null) {
successCount += eval(dice + compare);
}
}
returnStr += ']';
}
if (compare != null) {
returnStr += compare;
returnStr += ' → ';
returnStr += successCount;
returnStr += '成功';
}
return returnStr;
}
////this.d66骰
d66() {
let returnStr = '基本擲骰:' + Math.ceil(Math.random() * 6) + Math.ceil(Math.random() * 6);
return returnStr;
}
////choiceN
choiceN(inputStr) {
let c = 1;
let returnStr = '隨機選取:';
c = inputStr.toLowerCase().match(/^choice\d+/).toString();
c = c.match(/\d+/).toString();
if (c < 1) {
returnStr += '不能選取少於一個選項喔';
return returnStr;
}
inputStr = inputStr.toLowerCase().replace(/choice\d+ /, '');
let option = inputStr.split(' ');
if (c > option.length) {
c = option.length + 1;
}
for (; c > 0; c--) {
returnStr += option.splice(Math.floor(Math.random() * option.length), 1) + ' ';
}
return returnStr;
}
////choice
choice(inputStr) {
inputStr = inputStr.toLowerCase().replace('choice ', '');
let option = inputStr.split(' ');
let returnStr = '隨機選取:' + option[Math.floor(Math.random() * option.length)];
return returnStr;
}
////week
week(inputStr) {
let returnStr = '日期運算:';
let num = inputStr.split('.');
let d = new Date(num[0], num[1]-1, num[2]);
let day = ['日', '一', '二', '三', '四', '五', '六'];
returnStr += d.getFullYear() + '年' + (d.getMonth()+1) + '月' + d.getDate() + '日' + '(' + day[d.getDay()] + ')';
return returnStr;
}
////SW2.0 function 開始
//////sw威力表
Kx(inputStr) {
let returnStr = 'SW2.5威力表擲骰:';
let tempMatch = inputStr;
//return tempMatch.match(/k\d+/).toString();
let k = 0;
let b = 0;
let c = 10;
let ca = 0;
let s = 0;
let sFlag = false;
let count = 0;
let damage = 0;
let dice = 0;
let dice1 = 0;
let dice2 = 0;
let damageOverflow = false;
if (tempMatch.match(/k\d+/) != null) {
k = tempMatch.match(/k\d+/).toString();
k = k.match(/\d+/).toString();
}
if (tempMatch.match(/(\+|-)\d+/) != null) {
b = tempMatch.match(/(\+|-)\d+/)[0].toString();
b = b.match(/-?\d+/).toString();
}
if (tempMatch.match(/@\d+/) != null) {
c = tempMatch.match(/@\d+/).toString();
c = c.match(/\d+/).toString();
}
if (tempMatch.match(/#\d+/) != null) {
ca = tempMatch.match(/#\d+/).toString();
ca = ca.match(/\d+/).toString();
}
if (tempMatch.match(/\$(\+|-)?\d+/) != null) {
s = tempMatch.match(/\$(\+|-)?\d+/)[0].toString();
if (s.match(/(\+|-)/) == null)
sFlag = true;
s = s.match(/-?\d+/).toString();
}
if (c < 3) {
//returnStr+='c值不能小於2喔';
//return returnStr;
c = 3;
}
if (k < 0 || k > 100) {
returnStr += 'k值只支援0~100喔';
return returnStr;
}
dice1 = Math.ceil(Math.random() * 6);
if (tempMatch.match(/gf$/) != null) dice2 = dice1;
else dice2 = Math.ceil(Math.random() * 6);
if (sFlag) {
dice = Number(s);
returnStr += '[' + dice + ']';
} else {
dice = dice1 + dice2 + Number(s);
if (dice > 2) dice += Number(ca);
returnStr += '[' + dice1 + ',' + dice2 + ']';
if (s > 0) returnStr += '+' + s;
else if (s < 0) returnStr += s;
}
if (dice > 12) {
damage += this.powerSheet[k][9];
} else if (dice > 2) {
damage += this.powerSheet[k][dice - 3];
} else {
return returnStr + '→☆大失敗☆ 回家領50囉~';
}
while (dice >= c && c <= 12) {
count++;
dice1 = Math.ceil(Math.random() * 6);
if (tempMatch.match(/gf$/) != null) dice2 = dice1;
else dice2 = Math.ceil(Math.random() * 6);
dice = dice1 + dice2;
if (dice > 2) dice += Number(ca);
returnStr += ',[' + dice1 + ',' + dice2 + ']';
if (dice > 12) {
damage += this.powerSheet[k][9];
}
else if (dice > 2) {
damage += this.powerSheet[k][dice - 3];
}
if( damage >= 10000) {
damage = '傷害爆炸囉!有好好按照規則玩嗎?';
damageOverflow = true;
break;
}
}
if(!damageOverflow) {
damage = damage + Number(b);
if( damage >= 10000) {
damage = '傷害爆炸囉!有好好按照規則玩嗎?';
damageOverflow = true;
}
}
if (count) {
returnStr = returnStr + '→' + count + '迴轉→' + damage;
} else {
returnStr = returnStr + '→' + damage;
}
return returnStr;
}
//////超越判定
swFc(inputStr) {
let returnStr = 'SW2.0超越判定:';
let successFlag = false;
let successFlag2 = false;
let b = 0;
let count = 0;
let dice = 0;
let dice1 = Math.ceil(Math.random() * 6);
let dice2 = Math.ceil(Math.random() * 6);
returnStr += '[' + dice1 + ',' + dice2 + ']';
if (dice1 + dice2 == 2) {
return returnStr + '→☆大失敗☆ 回家領50囉~';
} else if (dice1 + dice2 == 12) {
successFlag = true;
}
if (inputStr.match(/(\+|-)\d+/) != null) {
b = inputStr.match(/(\+|-)\d+/)[0].toString();
b = b.match(/-?\d+/).toString();
}
while (dice1 + dice2 >= 10) {
dice += dice1 + dice2;
dice1 = Math.ceil(Math.random() * 6);
dice2 = Math.ceil(Math.random() * 6);
returnStr += '[' + dice1 + ',' + dice2 + ']';
count++;
}
dice += dice1 + dice2;
if (dice >= 40) {
successFlag2 = true;
}
dice += Number(b);
if (count) {
returnStr = returnStr + '→' + count + '迴轉';
}
returnStr += '→' + dice;
if (successFlag) {
returnStr += '→★大成功★';
}
if (successFlag2) {
returnStr += '→★超成功★';
}
return returnStr;
}
//////成長骰
swGr(inputStr) {
let returnStr = 'SW2.0成長擲骰:';
let sheet = ['靈巧', '敏捷', '力量', '生命', '智力', '精神'];
let count = 0;
if (inputStr.match(/\d+/) == null) {
count = 1;
} else {
count = Number(inputStr.match(/\d+/)[0].toString());
}
for (let i = 0; i < count; i++) {
returnStr += '[' + sheet[Math.floor(Math.random() * 6)] + ', ' + sheet[Math.floor(Math.random() * 6)] + ']';
}
return returnStr;
}
//////大失敗表
swFt() {
let returnStr = 'SW2.0大失敗表:';
let sheet = ['[1]額外擲兩次大失敗表,兩方效果皆適用(不會累加),另外本次大失敗額外增加50點經驗', '[2]傷害增加攻擊者的「劍之碎片」點', '[3]傷害增加攻擊者的「等級」點', '[4]骰兩次傷害骰,選擇較高者', '[5]傷害增加為原本的兩倍', '[6]防護點無效化'];
returnStr += sheet[Math.floor(Math.random() * 6)];
return returnStr;
}
//////纏繞表
swTt() {
let returnStr = 'SW2.0纏繞表:';
let sheet = ['[1]頭或臉:使用牙齒的命中判定-2,魔法行使判定-2', '[2]武器:武器無法使用,盾牌加值無效化', '[3]手腕:命中判定-2,盾牌加值無效化', '[4]腳:迴避判定-2', '[5]身體:所有行為判定-1', '[6]特殊:使用該部位的行為判定-1,失去該部位加值'];
returnStr += sheet[Math.floor(Math.random() * 6)];
return returnStr;
}
//////流言表
swRm() {
let returnStr = 'SW2.0流言:';
returnStr += this.swRmSheet1[Math.floor(Math.random() * this.swRmSheet1.length)];
returnStr += this.swRmSheet2[Math.floor(Math.random() * this.swRmSheet2.length)];
returnStr += this.swRmSheet3[Math.floor(Math.random() * this.swRmSheet3.length)];
return returnStr;
}
//////掉落表
swDi() {
let returnStr = 'SW2.0寶物表:';
let dropSheet = [
[1, '劍'],
[1, '斧'],
[1, '槍'],
[1, '釘頭錘'],
[1, '杖'],
[1, '連枷'],
[1, '戰錘'],
[1, '纏繞'],
[1, '格鬥'],
[1, '投擲'],
[1, '弓'],
[1, '十字弓'],
[1, '銃'],
[1, '箭、子彈'],
[7, '非金屬甲'],
[7, '金屬甲'],
[1, '盾'],
[1, '職業專用道具'],
[14, '裝飾品'],
[7, '消耗品'],
[7, '其他道具']
];
let rankSheet = [
[27, 'B'],
[9, 'A'],
[3, 'S'],
[1, 'SS']
];
let magicSheet = [
[27, ''],
[9, '+'],
[3, '++'],
[1, '+++']
];
returnStr += this.extractStr(dropSheet, Math.random());
returnStr += this.extractStr(rankSheet, Math.random());
returnStr += this.extractStr(magicSheet, Math.random());
return returnStr;
}
//////城鎮生成
swTw(inputStr) {
if (inputStr.match(/^swtw$/) != null) return undefined;
inputStr = inputStr.replace(/^swtw/, '');
let seedO = this.strToSeed(inputStr);
let seed = seedO;
let townLvSheet = ['小型村', '中型村', '小型鎮', '中型鎮', '大型鎮', '小型城市', '中型城市', '大型城市(經濟樞紐級)', '巨型城都(王城級)', '超巨型城都(世界都市級)'];
let popuSheet = [25, 80, 200, 500, 1000, 2000, 5000, 10000, 20000, 60000];
//信仰組成機率:村莊多為單一、城鎮較為多樣
let comRate = [
[9, 4, 1],
[3, 2, 1],
[1, 1, 1]
];
//信仰組成:單一、雙重、多重
let populationComSheet = [
[90],
[50, 40],
[30, 20, 20, 10]
];
let riligionComSheet = [
[90],
[50, 40],
[30, 20, 20, 10]
];
let populationSheet = [
[200, '人類'],
[160, '精靈'],
[160, '矮人'],
[100, '塔比特'],
[20, '符民'],
[5, '夢魘'],
[80, '暗影'],
[100, '龍人'],
[20, '草原妖精'],
[20, '慧人'],
[5, '瓦爾基里'],
[0.1, '仙靈'],
[0.1, '螢石人'],
[5, '古貓人'],
[20, '旭日'],
[20, '狗頭人'],
[1, '人族側蠻族']
]
let riligionSheet = [
[25, '始祖神'],
[20, '太陽神'],
[15, '賢神'],
[10, '妖精神'],
[15, '炎武帝'],
[11, '騎士神'],
[8, '月神'],
[8, '酒幸神'],
[6, '慈雨神'],
[8, '隱密神'],
[5, '水神'],
[1, '融合神'],
[1, '纏衣神'],
[1, '劍神'],
[1, '韋馱天'],
[1, '器械神'],
[1, '刃神'],
[1, '鐵鎚神'],
[1, '龍帝神'],
[1, '無特定信仰']
];
let industrySheet = ['農業', '畜牧業', '漁業', '礦業', '林業', '貿易', '皮革加工', '金屬加工', '煉金', '宗教', '紡織業',
'魔法道具加工', '學院'
];
//人口
let level = 0;
if (inputStr.match(/村$/) != null) level = Math.floor(this.srand(seed) * 2);
else if (inputStr.match(/鎮$/) != null) level = 2 + Math.floor(this.srand(seed) * 3);
else if (inputStr.match(/城$/) != null) level = 5 + Math.floor(this.srand(seed) * 4.2);
else level = Math.floor(this.srand(seed) * 9.2);
let population = Math.floor(popuSheet[level] * (2 + this.srand(++seed) + this.srand((seed++) + 1)) / 3);
let type = 0;
if (level < 2) type = 0;
else if (level < 5) type = 1;
else if (level < 10) type = 2;
//種族
//populationComType處理
let pCType = this.extract(comRate[type], this.srand(++seed));
pCType = populationComSheet[pCType];
for (let i = 0; i < pCType.length; i++) {
pCType[i] = pCType[i] + Math.floor(this.srand(++seed) * 6) - Math.floor(this.srand((seed++) + 1) * 6);
}
pCType = pCType.sort(function(a, b) {
return b - a
}); //排序種族
pCType.push(100 - pCType.reduce(function(a, b) {
return a + b;
}, 0)); //加入其他種族
//populationCom處理
let populationCom = [];
for (let i = 0; i < pCType.length - 1; i++) {
let r = this.extractStr(populationSheet, this.srand(++seed));
while (populationCom.some(function(a) {
return a == r;
})) {
r = this.extractStr(populationSheet, this.srand(++seed));
}
populationCom.push(r);
}
populationCom.push('其他');
//信仰
//信仰調整
if (type == 0) { //提高慈雨神、妖精神於村出現率
riligionSheet[8][0] += 12;
riligionSheet[3][0] += 10;
}
if (type == 1) riligionSheet[8][0] += 4; //提高慈雨神於鎮出現率
if (populationCom[0] == '矮人') riligionSheet[4][0] += 15; //提高矮人對於炎武帝出現率
if (populationCom[0] == '精靈') riligionSheet[3][0] += 10; //提高精靈對於妖精神出現率
if (populationCom[0] == '塔比特') riligionSheet[2][0] += 14; //提高塔比特對於賢神出現率
if (populationCom[0] == '旭日') riligionSheet[1][0] += 14; //提高旭日對於太陽神出現率
//riligionComType處理
let rCType = this.extract(comRate[type], this.srand(++seed));
rCType = riligionComSheet[rCType];
for (let i = 0; i < rCType.length; i++) {
rCType[i] = rCType[i] + Math.floor(this.srand(++seed) * 6) - Math.floor(this.srand((seed++) + 1) * 6);
}
rCType = rCType.sort(function(a, b) {
return b - a
}); //排序信仰
rCType.push(100 - rCType.reduce(function(a, b) {
return a + b;
}, 0)); //加入其他信仰
//riligionCom處理
let riligionCom = [];
for (let i = 0; i < rCType.length - 1; i++) {
let r = this.extractStr(riligionSheet, this.srand(++seed));
while (riligionCom.some(function(a) {
return a == r;
})) {
r = this.extractStr(riligionSheet, this.srand(++seed));
}
riligionCom.push(r);
}
riligionCom.push('其他');
//輸出
let returnStr = 'SW2.0城鎮:' + inputStr + '\n';
returnStr += '規模:' + townLvSheet[level] + ' 約' + population + '人\n';
returnStr += '人口組成:';
for (let i = 0; i < pCType.length; i++) {
returnStr += populationCom[i] + pCType[i] + '% ';
}
returnStr += '\n信仰組成:';
for (let i = 0; i < rCType.length; i++) {
returnStr += riligionCom[i] + rCType[i] + '% ';
}
returnStr += '\n興盛產業:';
for (let i = 0; i < industrySheet.length; i++) {
if (this.srand(++seed) * 10 < level) returnStr += industrySheet[i] + ' ';
}
return returnStr;
}
////SW2.0 function 結束
////忍神 function 開始
//////sg基本判定
sg(inputStr) {
let returnStr = '忍神骰組:[';
let tempMatch = inputStr.match(/^sg(\+\d+|-\d+)?>=\d+(#\d+)?(@\d+)?$/)[0].toString();
let dice = 0;
let ans = 0;
let ans2 = 0;
let t = 0;
let b = 0;
let f = 2;
let s = 12;
if (tempMatch.match(/>=\d+/) != null) {
t = tempMatch.match(/>=\d+/).toString();
t = t.match(/\d+/).toString();
}
if (tempMatch.match(/(\+|-)\d+/) != null) {
b = tempMatch.match(/(\+|-)\d+/)[0].toString();
}
if (tempMatch.match(/#\d+/) != null) {
f = tempMatch.match(/#\d+/).toString();
f = f.match(/\d+/).toString();
}
if (tempMatch.match(/@\d+/) != null) {
s = tempMatch.match(/@\d+/).toString();
s = s.match(/\d+/).toString();
}
if (Number(s) <= Number(f)) {
s = Number(f) + 1;