-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTF_Condition.js
1222 lines (1161 loc) · 45.5 KB
/
TF_Condition.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
//=================================================
// TF_Condition.js
// Version :1.9.0.0
// For : RPGツクールMZ (RPG Maker MZ)
// ----------------------------------------------
// Copyright : Tobishima-Factory 2020-2024
// Website : http://tonbi.jp
//
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//=================================================
/*:ja
* @target MZ
* @plugindesc 条件判定関連のスクリプト
* @author とんび﹫鳶嶋工房(tonbi.jp)
* @url https://github.com/tonbijp/RPGMakerMZ/blob/master/TF_Condition.js
* @base PluginCommonBase
* @orderAfter PluginCommonBase
*
* @================= parameter ====================
* @param temporarySwitch @text 一時スイッチのID
* @desc 各種値を返すスイッチのID(規定値:1)
* @type switch @default 1
*
* @================================================
* @param temporaryVariable @text 一時変数のID
* @desc 各種値を返す変数のID(規定値:1)
* @type variable @default 1
*
*
* @================== command =====================
* @command switch @text スイッチの操作
* @desc 指定スイッチへの代入。
*
* @arg name @text スイッチの名前
* @desc 指定スイッチ
* @type string @default it
*
* @arg operand @text オペランド(値)
* @desc スイッチの名前、true、false、not、\S[n]いずれか
* @type combo @default true
* @option true
* @option false
* @option not
* @option \S[n]
*
* @================================================
* @command variable @text 変数の操作
* @desc 数値は小数値も扱う
* 数値以外が入った変数の動作は保証しない
*
* @arg name @text 変数の名前
* @desc 指定変数
* @type string @default $it
*
* @arg operate @text 操作
* @desc 規定値: 指定変数に代入 =
* @type select @default =
* @option 指定変数に代入 = @value =
* @option 足し算 += @value +=
* @option 引き算 -= @value -=
* @option 掛け算 *= @value *=
* @option 割り算 /= @value /=
* @option 割り算の余り %= @value %=
* @option 割り算の商 //= @value //=
* @option 足し算して一時変数に + @value +
* @option 引き算して一時変数に - @value -
* @option 掛け算して一時変数に * @value *
* @option 割り算して一時変数に / @value /
* @option 割り算の余りを一時変数に % @value %
* @option 割り算の商を一時変数に // @value //
*
* @arg operand @text オペランド(値)
* @desc 変数の名前、数値、\V[n]いずれか
* @type string @default 100
*
* @================================================
* @command textVariable @text 文字変数の操作
* @desc 変数に対して文字を代入
* 数値が含まれていても文字として代入される
*
* @arg name @text 変数の名前
* @desc 指定変数
* @type string @default $it
*
* @arg operate @text 操作
* @desc 規定値: 指定変数に代入 =
* @type select @default =
* @option 指定変数に代入 = @value =
* @option 結合 += @value +=
* @option 結合して一時変数に代入 + @value +
*
* @arg operand @text オペランド(値)
* @desc 変数に代入する文字(\V[n]を使用できる)
* @type multiline_string @default \V[1]
*
* @================================================
* @command selfSwitch @text セルフスイッチの操作
* @desc 指定イベントのセルフスイッチを設定。
*
* @arg mapId @text マップID
* @desc マップをIDまたは名前で指定
* 規定値:this(現在のマップ)
* @type string @default this
*
* @arg eventId @text イベントID
* @desc イベントをIDで指定(規定値:this(このイベント))
* マップ指定が this だとイベント名で指定できる。
* @type string @default this
*
* @arg type @text タイプ
* @desc 任意の文字が指定できるが
* 通常のイベントコマンドでは使えない。
* @type combo @default A
* @option A @option B @option C @option D
*
* @arg operand @text オペランド(値)
* @desc スイッチの名前、true、false、not、\S[n]いずれか
* (セルフスイッチの指定はできません)
* @type combo @default true
* @option true
* @option false
* @option not
* @option \S[n]
*
* @=================== 【判定】 ===============================================================
* @command rem1 @text _____ 判定 _____
* @desc [条件分岐]を行うため下準備的なものです。
* (なお、これは区切り線なので選択しても何も起きません)
*
* @================================================
* @command checkSwitch @text 判定:スイッチ
* @desc
* 指定スイッチと一時スイッチを論理演算し、
* 結果を一時スイッチに代入。
*
* @arg name @text スイッチの名前
* @desc 指定スイッチ
* @type string @default it
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkSelfSwitch @text 判定:セルフスイッチ
* @desc
* 指定セルフスイッチと一時スイッチを論理演算し、
* 結果を一時スイッチに代入。
*
* @arg mapId @text マップID
* @desc マップをIDまたは名前で指定
* 規定値:this(現在のマップ)
* @type string @default this
*
* @arg eventId @text イベントID
* @desc イベントをIDで指定(規定値:this(このイベント))
* マップ指定が this だとイベント名で指定できる。
* @type string @default this
*
* @arg type @text タイプ
* @desc 任意の文字が指定できるが
* 通常のイベントコマンドでは使えない。
* @type combo @default A
* @option A @option B @option C @option D
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkMultiple @text 判定:複数スイッチ and結合
* @desc
* 複数のスイッチの論理積(and)の結果を、
* 一時スイッチに代入。
*
* @arg nameList @text スイッチ名リスト
* @desc スイッチを名前で指定
* @type string[] @default ["it", "done"]
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkCompare @text 判定:数値比較
* @desc
* 一時変数と比較した結果を一時スイッチに設定。
*
* @arg leftSide @text 左辺の数値
* @desc 変数の名前、数値、\V[n]いずれか
* @type string @default $it
*
* @arg compare @text 比較演算子
* @desc (規定値: ==)
* @type select @default ==
* @option 同じ == @value ==
* @option 以外 ≠ @value ≠
* @option 以上 ≦ @value ≦
* @option より上 < @value <
* @option 以下 ≧ @value ≧
* @option より下 > @value >
*
* @arg rightSide @text 右辺の数値
* @desc 変数の名前、数値、\V[n]いずれか
* @type string @default $it
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkCompareText @text 判定:文字比較
* @desc
* 一時変数と比較した結果を一時スイッチに設定。
*
* @arg leftSide @text 左辺の文字変数
* @desc 変数の名前、\V[n]いずれか
* @type string @default $it
*
* @arg compare @text 比較演算子
* @desc (規定値: ==)
* @type select @default ==
* @option 同じ == @value ==
* @option 以外 ≠ @value ≠
*
* @arg rightSide @text 右辺の文字
* @desc 文字(\V[n]を使える)
* @type multiline_string @default
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkRange @text 判定:数値範囲
* @desc
* 指定変数が範囲内にあるか判定して、
* 結果を一時スイッチに設定。
*
* @arg min @text 最小値
* @desc 変数の名前、数値、\V[n]いずれか
* @type number @default 0
*
* @arg center @text ≦中間値
* @desc 変数の名前、数値、\V[n]いずれか
* @type string @default $it
*
* @arg max @text ≦最大値
* @desc 変数の名前、数値、\V[n]いずれか
* @type number @default 100
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkItem @text 判定:アイテム
* @desc
* 指定アイテムを持っているか判定して、
* 結果を一時スイッチに設定。
*
* @arg itemId @text アイテムID
* @desc (規定値: 0)
* @type item @default 0
*
* @arg hasOrNot @text 持っているか
* @desc 指定アイテムの有無の指定
* @type boolean @default true
* @on 持っている(規定) @off 持たない
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
*
* @=================== 【特殊判定】 ===============================================================
* @command rem2 @text ____ 特殊判定 ____
* @desc 標準にはついてない判定方式で[出現条件]では使えません。
* (なお、これは区切り線なので選択しても何も起きません)
*
* @================================================
* @command checkLocation @text 判定:座標位置
* @desc
* イベントの座標位置と向きをチェックして、
* 全て合致していたか結果を一時スイッチに設定。
*
* @arg mapId @text マップID
* @desc マップをIDまたは名前で指定
* 規定値: this (現在のマップ)
* @type string @default this
*
* @arg eventId @text イベントID
* @desc
* イベントID(数値)かイベントの名前
* 規定値: player
* @type combo @default player
* @option this @option player @option follower0 @option follower1 @option follower2
*
* @arg position @text 位置(タイル数)
* @desc マップ上の位置
* x, y 座標2つの数値を区切って入力。
* @type string @default 0,0
*
* @arg d @text 向き(テンキー対応)
* @desc プレイヤーの向き
* 規定値: 0 (向きを問わない)
* @type select @default 0
* @option ・0 @value 0
* @option ↑ 8 @value 8
* @option → 6 @value 6
* @option ← 4 @value 4
* @option ↓ 2 @value 2
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkFrontEvent @text 判定:前方イベント
* @desc
* プレイヤーの前方に指定イベントがあるか、
* 判定した結果を一時スイッチに設定。
*
* @arg mapId @text マップID
* @desc マップをIDまたは名前で指定
* 規定値:this(現在のマップ)
* @type string @default this
*
* @arg eventId @text イベントID
* @desc イベントをIDで指定
* 規定値:this(このイベント)
* @type string @default this
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkHereEvent @text 判定:その場イベント
* @desc
* プレイヤーと同じ場所に指定イベントがあるか、
* 判定した結果を一時スイッチに設定。
*
* @arg mapId @text マップID
* @desc マップをIDまたは名前で指定
* 規定値:this(現在のマップ)
* @type string @default this
*
* @arg d @text 向き(テンキー対応)
* @desc プレイヤーの向き
* 規定値:0 (向きを問わない)
* @type select @default 0
* @option ・0 @value 0
* @option ↑ 8 @value 8
* @option → 6 @value 6
* @option ← 4 @value 4
* @option ↓ 2 @value 2
*
* @arg eventId @text イベントID
* @desc イベントをIDで指定
* 規定値:this(このイベント)
* @type string @default this
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @================================================
* @command checkJs @text 判定:JavaScript
* @desc
* このイベントを this とした JavaScriptを実行し、
* return で返った結果を一時スイッチに設定。
*
* @arg script @text JavaScript
* @desc 真偽値を返すJavaScriptを書く。
* @type note @default "// 実行結果を returnで返す\nreturn true;"
*
* @arg operate @text 論理演算
* @desc 一時変数への代入前の処理
* 規定値: そのまま代入 get
* @type select @default get
* @option そのまま代入 get @value get
* @option 反転して代入 not @value not
* @option 一時スイッチとの論理積を代入 and @value and
* @option 一時スイッチとの論理和を代入 or @value or
* @option 一時スイッチとの比較結果を代入 == @value ==
*
* @=================== 【出現条件】 ===============================================================
* @command rem3 @text ____ 出現条件 ____
* @desc 出現条件は[実行内容]の上の方に並べて使います。
* (なお、これは区切り線なので選択しても何も起きません)
*
* @================================================
* @command conditionSwitch @text 出現条件:スイッチ
* @desc 指定した値と同じならページ出現。
*
* @arg name @text スイッチの名前
* @desc 指定スイッチ
* @type string @default it
*
* @arg operand @text オペランド(値)
* @desc
* @type boolean @default true
*
* @================================================
* @command conditionSelfSwitch @text 出現条件:セルフスイッチ
* @desc セルフスイッチと値が同じならページ出現。
*
* @arg mapId @text マップID
* @desc マップをIDまたは名前で指定
* 規定値:this(現在のマップ)
* @type string @default this
*
* @arg eventId @text イベントID
* @desc イベントをIDで指定(規定値:this(このイベント))
* マップ指定が this だとイベント名で指定できる。
* @type string @default this
*
* @arg type @text タイプ
* @desc 任意の文字が指定できるが
* 通常のイベントコマンドでは使えない。
* @type combo @default A
* @option A @option B @option C @option D
*
* @arg operand @text オペランド(値)
* @desc
* @type boolean @default true
*
* @================================================
* @command conditionMultiple @text 出現条件:複数スイッチ and結合
* @desc 指定した値がすべてtrueならページ出現。
*
* @arg nameList @text スイッチ名リスト
* @desc スイッチを名前で指定
* @type string[] @default ["it", "done"]
*
* @================================================
* @command conditionCompare @text 出現条件:数値比較
* @desc 比較した結果がtrueならページ出現。
*
* @arg leftSide @text 左辺の数値
* @desc 変数の名前、数値いずれか
* @type string @default $it
*
* @arg compare @text 比較演算子
* @desc (規定値: ≦)
* @type select @default ≦
* @option 同じ == @value ==
* @option 以外 ≠ @value ≠
* @option 以上 ≦ @value ≦
* @option より上 < @value <
* @option 以下 ≧ @value ≧
* @option より下 > @value >
*
* @arg rightSide @text 右辺の数値
* @desc 変数の名前、数値いずれか
* @type string @default $it
*
* @================================================
* @command conditionCompareText @text 出現条件:文字比較
* @desc 比較した結果がtrueならページ出現。
*
* @arg leftSide @text 左辺の文字変数
* @desc 変数の名前
* @type string @default $it
*
* @arg compare @text 比較演算子
* @desc (規定値: ==)
* @type select @default ==
* @option 同じ == @value ==
* @option 以外 ≠ @value ≠
*
* @arg rightSide @text 右辺の文字
* @desc 文字(\V[n]を使える)
* @type multiline_string @default
*
* @================================================
* @command conditionRange @text 出現条件:数値範囲
* @desc 指定変数が範囲内にあればページ出現。
*
* @arg min @text 最小値
* @desc 変数の名前、数値いずれか
* @type number @default 0
*
* @arg center @text ≦中間値
* @desc 変数の名前、数値いずれか
* @type string @default $it
*
* @arg max @text ≦最大値
* @desc 変数の名前、数値いずれか
* @type number @default 100
*
* @================================================
* @command conditionItem @text 出現条件:アイテム
* @desc 指定アイテムの所持状態でページ出現。
*
* @arg itemId @text アイテムID
* @desc (規定値: 0)
* @type item @default 0
*
* @arg hasOrNot @text 持っているか
* @desc 指定アイテムの有無の指定
* @type boolean @default true
* @on 持っている(規定) @off 持たない
*
*
* @============ この長さに合わせるとヘルプではみ出ない =============
* @help
* 変数・スイッチ・セルフスイッチをIDだけでなく[名前]で設定できる。
* そのため、制作途中でIDを変えても[名前]が同じなら大丈夫。
*
* プレイヤー位置・前方のイベントなどの判定ができる。
*
* 数値・真偽値に指定できる値について
* ・基本は変数・スイッチの[名前]を指定します。
* ・PluginCommonBase 定義により \V[n] \S[n]が使えます。
* ・数字は名前でなく数値と判断します。
* ・true、false は名前ではなく値と判断します。
*
* 一時変数・一時スイッチについて
* ・名前に it をつけることを推奨します。
* プラグインコマンドの規定値が it だからです。
* 一時変数・一時スイッチ両方とも it が規定値です。
* ・IDはプラグインパラメータで変更できますが 1 を推奨します。
* イベントコマンドの規定値が 1 だから入れ替える必要がありません。
*
* ※ PluginCommonBase 定義によりパラメータや引数に \V[n] を使えます。
*
* ●イベントコマンド
* [スイッチの操作][変数の操作][セルフスイッチの操作]
* 判定
* [スイッチ判定][セルフスイッチ判定]
* [複数スイッチ and結合][JavaScript判定]
* 比較
* [数値比較][数値範囲]
* 位置
* [座標位置][前方イベント][その場イベント]
* 出現条件:判定
* [スイッチ判定][セルフスイッチ判定][複数スイッチ and結合]
* 出現条件:比較
* [数値比較][数値範囲]
* ------------------------------
* 引数の[論理演算]の選択肢のうち get そして and、or、== は、
* 判定を連続して行いたい場合に使います。
* 論理演算の結果は一時スイッチに代入されます。
*
* [一時スイッチに代入 get]
* 判定結果。
* [一時スイッチとの論理積 and]
* 一時スイッチと判定結果が両方ともONだとON。
* [一時スイッチとの論理和 or]
* 一時スイッチと判定結果のどちらかがONだとON。
* [一時スイッチと同じ ==]
* 一時スイッチと判定結果の値が同じだとON。
*
* ●スクリプト
* $gameVariables.setValueByName( 変数名, 変数への設定値 )
* $gameVariables.valueByName( 変数名 )
* $gameSwitches.setValueByName( スイッチ名, スイッチ状態(真偽値) )
* $gameSwitches.valueByName( スイッチ名 )
* this.TF_checkLocation( マップID, イベントID, x, y, 向き )
* this.TF_checkFrontEvent( マップID, イベントID )
* this.TF_checkHereEvent( マップID, 向き, イベントID )
*
* 利用規約 : MITライセンス
*
* TODO:
* セルフスイッチを変数として利用できる機能をつける
*/
( function() {
"use strict";
// エラー表示用にプラグイン名を取得
const PLUGIN_NAME = PluginManagerEx.findPluginName( document.currentScript );
// プラグインコマンド判定用パス
const PLUGIN_PATH = ( () => {
const url = document.currentScript._url;
const args = url.match( /^js\/plugins\/(.+)\.js$/ );
return args[ 1 ];
} )();
// 論理演算子
const OPE_GET = "get"; // この定数は使われていないが予約
const OPE_NOT = "not";
const OPE_AND = "and";
const OPE_OR = "or";
const OPE_EQUAL = "==";
const CHAR_SPACE = " ";
/*---- パラメータパース関数 ----*/
const PARAM_TRUE = "true";
const TYPE_BOOLEAN = "boolean";
const TYPE_NUMBER = "number";
const TYPE_STRING = "string";
/**
* ショートサーキットなら結果を一時スイッチに代入。
* @param {String} logope
* @returns {Boolean} ショートサーキットが成立したか
*/
function shortCircuit( logope ) {
if( logope === OPE_AND ) {
if( !$gameSwitches.value( switchItId ) ) return true;
} else if( logope === OPE_OR ) {
if( $gameSwitches.value( switchItId ) ) return true;
}
return false;
}
// ショートサーキット処理が済んでいる場合の代入処理
function setItTo( value, logope ) {
if( logope === OPE_EQUAL ) {
value = value === $gameSwitches.value( switchItId );
} else if( logope === OPE_NOT ) {
value = !value;
}
$gameSwitches.setValue( switchItId, value );
}
/**
* character を拡張して隊列メンバーも指定できるようにしたもの。
* @param {Game_Interpreter} interpreter インタプリタ
* @param {Number} id 拡張イベントID
* @returns {Game_CharacterBase}
*/
function getEventById( interpreter, id ) {
if( id < -1 ) {
return $gamePlayer.followers().follower( -2 - id ); // 隊列メンバー(0〜2)
} else {
return interpreter.character( id ); // プレイヤーキャラおよびイベント
}
}
const EVENT_THIS = "this";
const EVENT_PLAYER = "player";
const EVENT_FOLLOWER0 = "follower0";
const EVENT_FOLLOWER1 = "follower1";
const EVENT_FOLLOWER2 = "follower2";
/**
* 文字列をイベントIDへ変換。
* @param {String} value イベントIDの番号か識別子
* @returns {Number} 拡張イベントID(イベントが存在しない場合、undefinedを返す)
*/
function stringToEventId( value ) {
const result = parseInt( value, 10 );
if( !isNaN( result ) ) return result;
const lowValue = value.toLowerCase();
switch( lowValue ) {
case EVENT_THIS: return 0;
case EVENT_PLAYER: return -1;
case EVENT_FOLLOWER0: return -2;
case EVENT_FOLLOWER1: return -3;
case EVENT_FOLLOWER2: return -4;
}
const e = $dataMap.events.find( e => e && e.name === value );
if( e === undefined ) throw Error( `${PLUGIN_NAME}: I can't find the event '${value}'` );
return e.id;
}
/**
* 文字列をマップIDへ変換。
* @param {String} value マップIDの番号か識別子(this で現在のマップ)
* @returns {Number} マップID
*/
function stringToMapId( value ) {
if( typeof value === TYPE_NUMBER ) return value;
const label = value.toLowerCase();
if( label === EVENT_THIS ) return $gameMap.mapId();
const i = $dataMapInfos.findIndex( e => e ? e.name === value : false );
if( i !== -1 ) return i; // $dataMapInfos[ i ].id が正しい気がするが、実は使われていないようだ
const result = parseInt( value, 10 );
if( isNaN( result ) ) throw Error( `${PLUGIN_NAME}: I can't find the map '${value}'` );
return result;
}
/**
* 指定した方向をプレイヤーが向いているか。
* @param {Game_Character} targetEvent イベント・プレイヤー・隊列メンバーのいずれか
* @param {Number} d 判定する方向(テンキー対応)
* @returns {Boolean} 方向が同じか
*/
function isMatchDirection( targetEvent, d ) {
return ( d === 0 ) ? true : ( d === targetEvent.direction() );
}
/**
* "2, 43" 形式の文字列を配列 [2,43] に変換して返す。
* @param {String} positionString "x, y" 形式の文字列
* @returns {Array} [x,y]形式の配列
*/
function positionStringToArray( positionString ) {
const args = positionString.match( /([-.0-9]+)[^-.0-9]+([-.0-9]+)/ );
if( args === null ) throw `${PLUGIN_NAME}: wrong parameter "${fixedMapArgs}"`;
return [ parseFloat( args[ 1 ] ), parseFloat( args[ 2 ] ) ];
}
// イベントコマンドの番号
const PLUGIN_COMMAND = 357;
const PLUGIN_PARAM = 657;
const COMMENT_LINE = 108;
const COMMENT_END = 408;
// HalfMove.js の確認
const hasHalfMove = PluginManager._scripts.contains( "HalfMove" );
// プラグインパラメータを受け取る
const pluginParams = PluginManagerEx.createParameter( document.currentScript );
const variableItId = pluginParams.temporaryVariable;
const switchItId = pluginParams.temporarySwitch;
/*---- プラグインコマンド識別子 ----*/
const COM_SWITCH = "switch";
const COM_VARIABLE = "variable";
const COM_TEXT_VARIABLE = "textVariable";
const COM_SELFSWITCH = "selfSwitch";
const COM_CHECK_SWITCH = "checkSwitch";
const COM_CHECK_SELFSWITCH = "checkSelfSwitch";
const COM_CHECK_MULTIPLE = "checkMultiple";
const COM_CHECK_COMPARE = "checkCompare";
const COM_CHECK_COMPARE_TEXT = "checkCompareText";
const COM_CHECK_RANGE = "checkRange";
const COM_CHECK_ITEM = "checkItem";
const COM_CHECK_LOCATION = "checkLocation";
const COM_CHECK_FRONT_EVENT = "checkFrontEvent";
const COM_CHECK_HERE_EVENT = "checkHereEvent";
const COM_CHECK_JS = "checkJs";
// [スイッチの操作]
PluginManagerEx.registerCommand( document.currentScript, COM_SWITCH, function( args ) {
const operand = ( args.operand === OPE_NOT ) ?
!$gameSwitches.valueByName( args.name ) : args.operand;
$gameSwitches.setValueByName( args.name, stringToBoolean( operand ) );
} );
// [変数の操作]
PluginManagerEx.registerCommand( document.currentScript, COM_VARIABLE, function( args ) {
const operand = stringToNumber( args.operand );
if( args.operate === "=" ) {
$gameVariables.setValueByName( args.name, operand );
return;
}
const value = $gameVariables.valueByName( args.name );
switch( args.operate ) {
// 指定変数に代入
case "+=": $gameVariables.setValueByName( args.name, value + operand ); break;
case "-=": $gameVariables.setValueByName( args.name, value - operand ); break;
case "*=": $gameVariables.setValueByName( args.name, value * operand ); break;
case "/=": $gameVariables.setValueByName( args.name, value / operand ); break;
case "%=": $gameVariables.setValueByName( args.name, value % operand ); break;
case "//=": $gameVariables.setValueByName( args.name, Mathi.floor( value / operand ) ); break;
// 一時変数に代入
case "+": $gameVariables.setValueByName( variableItId, value + operand ); break;
case "-": $gameVariables.setValueByName( variableItId, value - operand ); break;
case "*": $gameVariables.setValueByName( variableItId, value * operand ); break;
case "/": $gameVariables.setValueByName( variableItId, value / operand ); break;
case "%": $gameVariables.setValueByName( variableItId, value % operand ); break;
case "//": $gameVariables.setValueByName( variableItId, Mathi.floor( value / operand ) ); break;
}
} );
// [文字変数の操作]
PluginManagerEx.registerCommand( document.currentScript, COM_TEXT_VARIABLE, function( args ) {
const operand = String( args.operand );
if( args.operate === "=" ) {
$gameVariables.setValueByName( args.name, operand );
return;
}
const value = String( $gameVariables.valueByName( args.name ) );
switch( args.operate ) {
// 指定変数に代入
case "+=": $gameVariables.setValueByName( args.name, value + operand ); break;
// 一時変数に代入
case "+": $gameVariables.setValueByName( variableItId, value + operand ); break;
}
} );
// [セルフスイッチの操作]
PluginManagerEx.registerCommand( document.currentScript, COM_SELFSWITCH, function( args ) {
if( args.eventId === EVENT_THIS ) args.eventId = this.character( 0 )._eventId;
const operand = ( args.operand === OPE_NOT ) ?
!getSelfSwitch( args.mapId, args.eventId, args.type ) : args.operand;
setSelfSwitch( args.mapId, args.eventId, args.type, stringToBoolean( operand ) );
} );
// [判定:スイッチ]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_SWITCH, function( args ) {
if( shortCircuit( args.operate ) ) return;
const value = $gameSwitches.valueByName( args.name );
setItTo( value, args.operate );
} );
// [判定:セルフスイッチ]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_SELFSWITCH, function( args ) {
if( shortCircuit( args.operate ) ) return;
if( args.eventId === EVENT_THIS ) args.eventId = this.character( 0 )._eventId;
const value = getSelfSwitch( args.mapId, args.eventId, args.type );
setItTo( value, args.operate );
} );
// [判定:複数スイッチ and結合]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_MULTIPLE, function( args ) {
if( shortCircuit( args.operate ) ) return;
const value = args.nameList.every( e => $gameSwitches.valueByName( e ) );
setItTo( value, args.operate );
} );
// [判定:座標位置]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_LOCATION, function( args ) {
if( shortCircuit( args.operate ) ) return;
const [ x, y ] = positionStringToArray( args.position );
const value = this.TF_checkLocation( args.mapId, args.eventId, x, y, args.d );
setItTo( value, args.operate );
} );
// [判定:前方イベント]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_FRONT_EVENT, function( args ) {
if( shortCircuit( args.operate ) ) return;
const value = this.TF_checkFrontEvent( args.mapId, args.eventId );
setItTo( value, args.operate );
} );
// [判定:その場イベント]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_HERE_EVENT, function( args ) {
if( shortCircuit( args.operate ) ) return;
const value = this.TF_checkHereEvent( args.mapId, args.d, args.eventId );
setItTo( value, args.operate );
} );
// [判定:JavaScript]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_JS, function( args ) {
if( shortCircuit( args.operate ) ) return;
const code = JSON.parse( args.script );
const value = ( new Function( code ) ).call( this.character( 0 ) );
setItTo( value, args.operate );
} );
// [判定:数値比較]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_COMPARE, function( args ) {
if( shortCircuit( args.operate ) ) return;
const value = checkCompare( args );
setItTo( value, args.operate );
} );
function checkCompare( args ) {
const leftSide = stringToNumber( args.leftSide );
const rightSide = stringToNumber( args.rightSide );
switch( args.compare ) {
case "==": return leftSide === rightSide;
case "≠": return leftSide !== rightSide;
case "≦": return leftSide <= rightSide;
case "<": return leftSide < rightSide;
case "≧": return leftSide >= rightSide;
case ">": return leftSide > rightSide;
}
}
// [判定:文字比較]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_COMPARE_TEXT, function( args ) {
if( shortCircuit( args.operate ) ) return;
const value = checkCompareText( args );
setItTo( value, args.operate );
} );
function checkCompareText( args ) {
const leftSide = String( $gameVariables.valueByName( args.leftSide ) );
const rightSide = String( args.rightSide );
switch( args.compare ) {
case "==": return leftSide === rightSide;
case "≠": return leftSide !== rightSide;
}
}
// [判定:数値範囲]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_RANGE, function( args ) {
if( shortCircuit( args.operate ) ) return;
const value = checkRange( args );
setItTo( value, args.operate );
} );
function checkRange( args ) {
const minValue = stringToNumber( args.min );
const centerValue = stringToNumber( args.center );
const maxValue = stringToNumber( args.max );
return minValue <= centerValue && centerValue <= maxValue;
}
// 文字列を数値に変換
// 数値が書かれた文字列なら、それを数値に変換して返す
// 文字列なら、それを変数の識別子と判断して、変数の中身をそのまま返す
function stringToNumber( value ) {
if( value === undefined || value === "" ) return 0;
const num = parseFloat( value );
if( isNaN( num ) ) {
return $gameVariables.valueByName( value );
} else {
return num;
}
}
function stringToBoolean( value ) {
if( value === undefined || value === "" ) return false;
if( typeof value === TYPE_BOOLEAN ) return value;
return $gameSwitches.valueByName( value );
}
// [判定:アイテム]
PluginManagerEx.registerCommand( document.currentScript, COM_CHECK_ITEM, function( args ) {
if( shortCircuit( args.operate ) ) return;
const value = checkItem( args );
setItTo( value, args.operate );
} );
function checkItem( args ) {
const id = stringToNumber( args.itemId );
const hasOrNot = args.hasOrNot;
const hasItem = $gameParty.hasItem( $dataItems[ id ], true );
return hasOrNot ? hasItem : !hasItem;
}
/*---- Game_Interpreter ----*/
/**
* プレイヤー前方に指定イベントの判定があるか。
* @param {String} mapId マップID | マップ名 | here | this
* @param {String} eventId 対象イベントID か 名前
* @returns {Boolean} 指定イベントがあるか
*/
Game_Interpreter.prototype.TF_checkFrontEvent = function( mapId, eventId ) {
const d = $gamePlayer.direction();
let x, y;
if( hasHalfMove ) {//HalfMove.js を使っている場合