-
Notifications
You must be signed in to change notification settings - Fork 0
/
NRP_DynamicAnimationMap.js
2524 lines (2231 loc) · 88.3 KB
/
NRP_DynamicAnimationMap.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
//=============================================================================
// NRP_DynamicAnimationMap.js
//=============================================================================
/*:
* @target MV
* @plugindesc v1.16 Call DynamicAnimation on the map.
* @author Takeshi Sunagawa (http://newrpg.seesaa.net/)
* @base NRP_DynamicAnimation
* @url http://newrpg.seesaa.net/article/477639171.html
*
* @help Call DynamicAnimation on the map.
*
* Although it says on the map, it can actually be executed during a battle.
* In this case, I recommend working with the following plugins
* that perform parallel processing during battle.
* http://newrpg.seesaa.net/article/477740800.html
*
* For more information on this plugin, please see below.
* http://newrpg.seesaa.net/article/477639171.html
*
* Here's a sample.
* http://newrpg.seesaa.net/article/477704129.html
*
* [Plugin Command]
* > nrp.animation.skill 100
* DynamicAnimation is executed based on the skill with ID=100.
* It can be done on a map or in battle.
* Before specifying this command, you can specify the options (see below).
*
* [Example: Map]
* nrp.animation.subject 1
* nrp.animation.target 2
* nrp.animation.wait
* nrp.animation.skill 100
*
* In the example above, we will release an animation
* with skill ID=100 from event ID=1 to ID=2.
* In doing so, it waits for the animation to end.
*
* [Example: Battle]
* nrp.animation.subjectCondition a._actorId == 1
* nrp.animation.targetCondition a._enemyId == 2
* nrp.animation.wait
* nrp.animation.skill 100
*
* In the above example, the actor ID = 1 to the enemy ID = 2,
* releasing an animation with skill ID = 100.
* In doing so, it waits for the animation to end.
*
* It can also be specified in the item as follows.
* The usage is exactly the same as in the case of skills, so I'll skip it.
* > nrp.animation.item 100
*
* See below for more information on options.
*
* [Common Option (Plugin Command)]
* > nrp.animation.wait
* Wait for the animation to finish.
* If you use parallel processing,
* it waits for the animation to end and then loops.
* In this case, the player's operation is not stopped.
*
* [For Map Option (Plugin Command)]
* > nrp.animation.target 1
* Event ID = 1 is the target of the animation.
* If you specify 0, this event is targeted,
* if you specify -1, the player is targeted.
* if you specify -2 or less, the follower is targeted. (-2, -3, -4)
* And you can also specify multiple targets.
* "1,2,3" to specify one by one." 1 to 5" to specify them all at once.
*
* Formulas can also be specified. For example, ......
* this._eventId + 1
* The above is the ID+1 event for this event.
*
* > nrp.animation.subject 1
* Event ID = 1 is the subject (starting point) of the animation.
* This is the same as nrp.animation.target,
* including the ability to specify multiple targets.
*
* > nrp.animation.noscroll
* The animation is no longer affected by screen scrolling.
*
* > nrp.animation.range 10
* Animations are only executed
* if the distance to parallel processing events is within 10 grids.
*
* [For Battle Option (Plugin Command)]
* > nrp.animation.targetCondition
* Specify the conditions under which the animation will be performed.
* (Multiple targets are allowed.)
*
* > nrp.animation.subjectCondition
* Specify the conditions that determine who will use the animation.
* The point is the same as nrp.animation.targetCondition.
*
* However, I'm assuming an animation
* that basically doesn't require a target.
* For example, it is used for background effects.
* In this case, these specifications are not necessary.
*
* [Call from note]
* <D-Skill:1>
* As mentioned above,
* if you specify a skill ID for a map event
* or actor or enemy or state note,
* its animation will be executed automatically.
*
* Also fill in the tag in the note at the top of the event page.
* You can switch the status of this one for each of the current pages.
*
* [Play from the middle] (ver1.09~)
* <D-StartTiming:?>
* You can play the animation from an advanced state
* by adding the above to the note field of the skill.
* If ? =30 will start the animation with 30 frames advanced.
* ※The standard value is 1 frame = 1/15 second.
*
* This is useful when you want the animation
* to start immediately after switching maps.
*
* [Terms]
* There are no restrictions.
* Modification, redistribution freedom, commercial availability,
* and rights indication are also optional.
* The author is not responsible,
* but will deal with defects to the extent possible.
*
* @param keepAnimation
* @type boolean
* @desc Keep the animation when changing scenes such as menu, battle.
* As for the animation in MZ format, it is incomplete.
* @default true
*
* @param eventResetOnLoad
* @type boolean
* @desc Resets the processing status of any events that are running DynamicAnimation at load time.
* @default true
*
* @param targetRangeGrid
* @type number
* @desc If the distance to the parallel event falls within this range, the animation is displayed.
*
* @param noteTargetRangeGrid
* @type number
* @desc When executed from note, If the distance to the event falls within this range, the animation is displayed.
*
* @param closeAnimationGap
* @type boolean
* @default false
* @desc Slightly speeds up the end of the animation to eliminate gaps in the cyclical animation.
*
* @param actingNoStateAnimation
* @type boolean
* @default false
* @desc The animation specified in the state's note will not be displayed during the action.
*/
/*:ja
* @target MV
* @plugindesc v1.16 DynamicAnimationをマップ上から起動します。
* @author 砂川赳(http://newrpg.seesaa.net/)
* @base NRP_DynamicAnimation
* @url http://newrpg.seesaa.net/article/477639171.html
*
* @help DynamicAnimationをマップ上から起動します。
*
* マップ上とありますが、実際には戦闘中の実行も可能です。
* その際、以下の戦闘中に並列処理を実行するプラグインとの連携をオススメします。
* http://newrpg.seesaa.net/article/477740800.html
*
* 当プラグインの詳細は以下をご覧ください。
* http://newrpg.seesaa.net/article/477639171.html
*
* 以下はサンプルです。
* http://newrpg.seesaa.net/article/477704129.html
*
* 【プラグインコマンド】
* > nrp.animation.skill 100
* ID=100のスキルのDynamicAnimationを実行します。
* マップ上でも戦闘中でも実行可能です。
* このコマンドを指定する前に、オプション(下記参照)を指定可能です。
*
* [マップ上の使用例]
* nrp.animation.subject 1
* nrp.animation.target 2
* nrp.animation.wait
* nrp.animation.skill 100
*
* 上記の例ではイベントID=1からID=2に向けて、
* スキルID=100のアニメーションをウェイト指定で放ちます。
*
* [戦闘中の使用例]
* nrp.animation.subjectCondition a._actorId == 1
* nrp.animation.targetCondition a._enemyId == 2
* nrp.animation.wait
* nrp.animation.skill 100
*
* 上記の例ではアクターID=1から敵キャラID=2に向けて、
* スキルID=100のアニメーションをウェイト指定で放ちます。
*
* また、以下のようにアイテムでも指定可能です。
* 使い方はスキルの場合と全く同じなので割愛します。
* > nrp.animation.item 100
*
* オプションの詳細は以下をご覧ください。
*
* 【プラグインコマンドの共通オプション】
* > nrp.animation.wait
* アニメーションの終了を待ちます。
* 並列処理で指定するとアニメーションの終了を待ってからループするようになります。
* その際、プレイヤーの操作を停止しません。
*
* 【プラグインコマンドのマップ用オプション】
* > nrp.animation.target 1
* イベントID=1をアニメーションの対象とします。
* 0ならばこのイベント、-1ならばプレイヤーです。
* -2以下(-2, -3, -4)で隊列歩行の仲間も対象にできます。
* さらに複数指定も可能です。
* "1,2,3"で一つずつ指定。"1~5"で一括指定となります。
*
* また、数式も指定可能です。例えば……
* this._eventId + 1
* はこのイベントのID+1のイベントとなります。
*
* > nrp.animation.subject 1
* イベントID=1をアニメーションの行動主体(始点)とします。
* 複数指定ができることも含め、nrp.animation.targetと要領は同じです。
*
* > nrp.animation.noscroll
* アニメーションが画面スクロールの影響を受けなくなります。
*
* > nrp.animation.range 10
* 並列処理イベントとの距離が10マス以内に収まる場合のみ、
* アニメーションを実行します。
*
* 【プラグインコマンドの戦闘用オプション】
* > nrp.animation.targetCondition
* アニメーションの対象を決める条件を指定します。(対象複数可)
*
* > nrp.animation.subjectCondition
* アニメーションの使用者を決める条件を指定します。
* 要領はnrp.animation.targetConditionと同じです。
*
* もっとも基本的には背景など対象を取らないアニメーションを想定しています。
* その場合はこれらの指定も不要です。
*
* 【メモ欄&注釈からの起動】
* <D-Skill:1>
* というように、マップイベント、アクター、敵キャラ、
* およびステートのメモ欄にスキルIDを指定すると、
* そのアニメーションが自動実行されます。
*
* また、イベントページ先頭の注釈に記入しても有効です。
* こちらは現在のページ毎に状態を切り替えることも可能です。
*
* 【途中から再生】(ver1.09~)
* <D-StartTiming:?>
* スキルのメモ欄に上記を追加すれば、アニメーションを進めた状態から再生できます。
* ?=30ならば、アニメーションを30フレーム進めた状態から開始します。
* ※標準では1フレーム=1/15秒です。
* マップを切り替えた直後から表示したい演出などに有用です。
*
* 【利用規約】
* 特に制約はありません。
* 改変、再配布自由、商用可、権利表示も任意です。
* 作者は責任を負いませんが、不具合については可能な範囲で対応します。
*
* @param keepAnimation
* @text シーン変更時もアニメを維持
* @type boolean
* @desc メニューや戦闘などシーン変更時もアニメの表示を維持します。
* @default true
*
* @param eventResetOnLoad
* @text ロード時にイベントリセット
* @type boolean
* @desc ロード時にDynamicAnimationを実行中のイベントの処理状況をリセットします。
* @default true
*
* @param targetRangeGrid
* @text 並列実行時の有効範囲マス数
* @type number
* @desc 並列処理イベントとの距離がこのマス数に収まる場合のみ、アニメーションを実行します。
*
* @param noteTargetRangeGrid
* @text 注釈実行時の有効範囲マス数
* @type number
* @desc 注釈実行時、イベントとの距離がこのマス数に収まる場合のみ、アニメーションを実行します。
*
* @param closeAnimationGap
* @text アニメの切目をなくす
* @type boolean
* @default false
* @desc アニメーションの終了をわずかに早めることで、
* 並列処理などで循環するアニメーションの切れ目をなくします。
*
* @param actingNoStateAnimation
* @text 行動中のステートアニメを禁止
* @type boolean
* @default false
* @desc アクション中はステートのメモ欄に指定したアニメーションを非表示にします。
*/
// 連携用に値を保持
var Nrp = Nrp || {};
(function() {
"use strict";
/**
* バージョン互換対応
*/
if (!Array.prototype.find) {
Array.prototype.find = function (predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
function toBoolean(val, def) {
// 空白なら初期値を返す
if (val === "" || val === undefined) {
return def;
// 既にboolean型なら、そのまま返す
} else if (typeof val === "boolean") {
return val;
}
// 文字列ならboolean型に変換して返す
return val.toLowerCase() == "true";
}
function toNumber(str, def) {
return isNaN(str) ? def : +(str || def);
}
function setDefault(str, def) {
return str ? str : def;
}
const PLUGIN_NAME = "NRP_DynamicAnimationMap";
const BASE_PLUGIN_NAME = "NRP_DynamicAnimation";
//-----------------------------------------------------------
// ここより下、NRP_DynamicAnimationMapMZと
// NRP_DynamicAnimationMapは全く同じソースとなります。
//-----------------------------------------------------------
const parameters = PluginManager.parameters(PLUGIN_NAME);
const pKeepAnimation = toBoolean(parameters["keepAnimation"], true);
const pEventResetOnLoad = toBoolean(parameters["eventResetOnLoad"], true);
const pTargetRangeGrid = toNumber(parameters["targetRangeGrid"]);
const pNoteTargetRangeGrid = toNumber(parameters["noteTargetRangeGrid"]);
const pCloseAnimationGap = toBoolean(parameters["closeAnimationGap"], false);
const pActingNoStateAnimation = toBoolean(parameters["actingNoStateAnimation"], false);
// DynamicAnimation本体側のパラメータ
const baseParameters = PluginManager.parameters(BASE_PLUGIN_NAME);
// 計算レート(MVの場合は存在しないので既定値=4になる)
const pCalculationRate = toNumber(baseParameters["calculationRate"], 4);
const STARTTIMING_TAG_NAME = "D-StartTiming";
// DynamicMotionMapへ連携
Nrp.pKeepAnimation = pKeepAnimation;
//----------------------------------------
// MZ用プラグインコマンド
//----------------------------------------
// MVには存在しないため、空で定義しておかないとエラーになる。
if (!PluginManager.registerCommand) {
PluginManager.registerCommand = function() {}
}
/**
* ●アニメーションの表示
*/
PluginManager.registerCommand(PLUGIN_NAME, "showAnimation", function(args) {
// 戦闘中は無効
if ($gameParty.inBattle()) {
return;
}
const skillId = eval(getCommandValue(args.skillId));
const targetId = setDefault(getCommandValue(args.target), "0");
const startPointId = setDefault(getCommandValue(args.startPoint), "-1");
let wait = false; // デフォルトはウェイトなし
let noScroll = false; // デフォルトは画面に連動
let targetRangeGrid = pTargetRangeGrid;
// オプション情報
if (args.option) {
const option = JSON.parse(args.option);
wait = toBoolean(option.wait);
noScroll = toBoolean(option.noScroll);
// 指定がある場合は共通設定より優先
if (option.targetRangeGrid != undefined) {
targetRangeGrid = toNumber(option.targetRangeGrid);
}
}
const mapAnimationParams = [];
mapAnimationParams.skillId = skillId;
mapAnimationParams.targetId = targetId;
mapAnimationParams.startPointId = startPointId;
mapAnimationParams.wait = wait;
mapAnimationParams.noScroll = noScroll;
mapAnimationParams.targetRangeGrid = targetRangeGrid;
// マップ上でのアニメーション表示
showMapAnimation.bind(this)(mapAnimationParams);
});
/**
* ●マップ上でのアニメーション表示
* ※bindによってinterpreterをthisに渡して用いる。
*/
function showMapAnimation(mapAnimationParams) {
const skillId = mapAnimationParams.skillId;
const targetId = mapAnimationParams.targetId;
const startPointId = mapAnimationParams.startPointId;
const wait = mapAnimationParams.wait;
const noScroll = mapAnimationParams.noScroll;
const targetRangeGrid = mapAnimationParams.targetRangeGrid;
const battleSubject = mapAnimationParams.battleSubject;
const isItem = mapAnimationParams.isItem;
// 対象を生成
// ※bindによってthisをメソッドに渡す。
const targets = makeTargetsAndSubjects.bind(this)(targetId);
// 対象が取得できなければ処理しない。
if (targets.length == 0) {
return;
}
// イベントが範囲対象外ならば処理終了
const event = $gameMap.event(this.eventId());
// trigger:4(並列処理の場合)
if (event && event._trigger == 4
&& isOutOfRange(event, targetRangeGrid)) {
return;
}
// 行動主体を生成(複数を考慮)
// ※bindによってthisをメソッドに渡す。
const subjects = makeTargetsAndSubjects.bind(this)(startPointId);
for (const subject of subjects) {
// アクション情報を作成
const action = makeAction(skillId, battleSubject, isItem);
const mapAnimation = makeMapAnimation(this, subject, wait, noScroll, action);
// 最後の対象のイベントIDを取得
this._characterId = targets[targets.length - 1]._eventId;
// 取得できない場合は-1:プレイヤー
if (!this._characterId) {
this._characterId = -1;
}
// 設定があればウェイト
if (!mapAnimation.noWait) {
this.setWaitMode("animation");
this._onDynamicAnimation = true; // 実行中判定
// タイミングを測るためアニメーションの最終対象を保持しておく
this._lastDynamicTargetId = this.getDynamicTargetId(targets[targets.length - 1]);
// モーション判定用の行動主体
this._dynamicSubjectId = this.getDynamicTargetId(subject);
// MVの場合
// ※MZでは循環参照になるので厳禁!
if (Utils.RPGMAKER_NAME == "MV") {
this._character = targets[targets.length - 1];
}
}
// DynamicAnimation開始
this.startDynamicAnimation(targets, action, mapAnimation);
}
}
/**
* ●アニメーションの削除
*/
PluginManager.registerCommand(PLUGIN_NAME, "removeAnimation", function(args) {
// 戦闘中は無効
if ($gameParty.inBattle()) {
return;
}
const skillId = getCommandValue(args.skillId);
const targetId = getCommandValue(args.target);
const startPointId = getCommandValue(args.startPoint);
const targets = makeTargetsAndSubjects.bind(this)(targetId);
const startPoints = makeTargetsAndSubjects.bind(this)(startPointId);
const spriteset = getSpriteset();
// 再生中の全アニメーションでループ
for (const animationSprite of spriteset._animationSprites.clone()) {
const dynamicAnimation = animationSprite.dynamicAnimation;
// DynamicAnimationでないなら処理しない。
if (!dynamicAnimation) {
continue;
}
const baseAnimation = dynamicAnimation.baseAnimation;
// スキルIDが条件に設定されている。
if (skillId) {
const id = baseAnimation.action.item().id;
// スキルIDが一致していないなら処理しない
if (skillId != id) {
continue;
}
}
// 行動主体が条件に設定されている。
if (startPoints.length > 0) {
// 行動主体が一致していないなら処理しない
if (!startPoints.includes(baseAnimation.getSubject())) {
continue;
}
}
let removeFlg = false;
// アニメーションの対象毎にループ
for (const targetSprite of animationSprite._targets) {
// 対象が不一致ならば削除しない。
if (targets.length > 0
&& !targets.includes(targetSprite._character)) {
continue;
}
//------------------------------------------------
// ここまで来たならば、条件に一致しているということ。
//------------------------------------------------
// 予約されているアニメーションを削除
targetSprite._animations = [];
removeFlg = true;
}
if (removeFlg) {
// 再生中のアニメーションを削除
spriteset.removeAnimation(animationSprite);
}
}
});
/**
* ●アニメーションの削除(戦闘)
*/
PluginManager.registerCommand(PLUGIN_NAME, "removeAnimationBattle", function(args) {
// 戦闘中以外は無効
if (!$gameParty.inBattle()) {
return;
}
const skillId = eval(getCommandValue(args.skillId));
const targetCondition = getCommandValue(args.targetCondition);
const subjectCondition = getCommandValue(args.subjectCondition);
// 行動主体を取得
let subject = undefined;
if (subjectCondition) {
subject = BattleManager.allBattleMembers().find(a => eval(subjectCondition));
}
// 対象を取得
let targets = undefined;
if (targetCondition) {
targets = BattleManager.allBattleMembers().filter(a => eval(targetCondition));
}
const spriteset = getSpriteset();
// 再生中の全アニメーションでループ
for (const animationSprite of spriteset._animationSprites.clone()) {
const dynamicAnimation = animationSprite.dynamicAnimation;
// DynamicAnimationでないなら処理しない。
if (!dynamicAnimation) {
continue;
}
const baseAnimation = dynamicAnimation.baseAnimation;
// スキルIDが条件に設定されている。
if (skillId) {
const id = baseAnimation.action.item().id;
// スキルIDが一致していないなら処理しない
if (skillId != id) {
continue;
}
}
// 行動主体が条件に設定されている。
if (subject) {
// 行動主体が一致していないなら処理しない
if (subject != baseAnimation.getSubject()) {
continue;
}
}
let removeFlg = false;
// アニメーションの対象毎にループ
for (const targetSprite of animationSprite._targets) {
// 対象が不一致ならば削除しない。
if (targets && targets.length > 0
&& !targets.includes(targetSprite._battler)) {
continue;
}
//------------------------------------------------
// ここまで来たならば、条件に一致しているということ。
//------------------------------------------------
// 予約されているアニメーションを削除
targetSprite._battler._animations = [];
removeFlg = true;
}
if (removeFlg) {
// 再生中のアニメーションを削除
spriteset.removeAnimation(animationSprite);
}
}
});
/**
* ●lastDynamicTargetIdを元に最終ターゲットを取得する。
*/
Game_Interpreter.prototype.getLastDynamicTarget = function() {
return this.getDynamicTarget(this._lastDynamicTargetId);
}
/**
* ●dynamicSubjectIdを元に行動主体を取得する。
*/
Game_Interpreter.prototype.getDynamicSubject = function() {
return this.getDynamicTarget(this._dynamicSubjectId);
}
/**
* 【独自】マップ版DynamicAnimationを開始する。
* ※NRP_DynamicReadTxtとの連携用にメソッド分割
*/
Game_Interpreter.prototype.startDynamicAnimation = function(targets, action, mapAnimation) {
// 空のWindow_BattleLogを作成し、DynamicAnimationを起動
const win = new Window_BattleLog(new Rectangle());
win.showDynamicAnimation(targets, action, false, mapAnimation);
}
/**
* ●アニメーションの表示(戦闘用)
*/
PluginManager.registerCommand(PLUGIN_NAME, "showAnimationBattle", function(args) {
// 戦闘中以外は無効
if (!$gameParty.inBattle()) {
return;
}
const skillId = eval(getCommandValue(args.skillId));
const targetCondition = getCommandValue(args.targetCondition);
const subjectCondition = getCommandValue(args.subjectCondition);
let wait = false; // デフォルトはウェイトなし
// オプション情報
if (args.option) {
const option = JSON.parse(args.option);
wait = toBoolean(option.wait);
}
// 戦闘中のアニメーション表示
showBattleAnimation.bind(this)(skillId, targetCondition, subjectCondition, wait);
});
/**
* ●アニメーションの表示(戦闘用)
* ※bindによってinterpreterをthisに渡して用いる。
*/
function showBattleAnimation(skillId, targetCondition, subjectCondition, wait) {
// 行動主体を取得(指定がなければ適当に先頭)
let subject = $gameParty.members()[0];
if (subjectCondition) {
subject = BattleManager.allBattleMembers().find(a => eval(subjectCondition));
// 取得できなければ不発
if (!subject) {
return;
}
}
// 対象を取得(指定がなければ適当に先頭)
let targets = [$gameParty.members()[0]];
if (targetCondition) {
targets = BattleManager.allBattleMembers().filter(a => eval(targetCondition));
// 取得できなければ不発
if (targets.length == 0) {
return;
}
}
// アクション情報を作成
const action = makeAction(skillId)
const mapAnimation = makeMapAnimationBattle(this, subject, wait, action, targets)
// DynamicAnimation開始
this.startDynamicAnimation(targets, action, mapAnimation);
}
/**
* ●呼出元が並列処理かどうか?
* ※通常戦闘中に並列コモンイベントが呼び出されることはないので、
* 他プラグインとの連携を想定
*/
function isParallel(interpreter) {
let commonEvents;
// $gameTroopにコモンイベントを登録するタイプのプラグインにも対応
if ($gameTroop._commonEvents) {
commonEvents = $gameTroop._commonEvents;
// 通常は$gameMapを想定
} else {
commonEvents = $gameMap._commonEvents;
}
// interpreterが一致かつ有効な並列イベントである。
return commonEvents.some(common => common._interpreter == interpreter && common.isActive());
}
/**
* ●プラグインコマンドの値を取得する。
*/
function getCommandValue(value) {
if (value === undefined) {
return value;
}
// #以降は注釈扱いなので除去
// さらに前後の空白を除去する。
return value.split("#")[0].trim();
}
/**
* ●引数を元に対象(行動主体)の配列を取得する。
* ※bindによってinterpreterをthisに渡して用いる。
*/
function makeTargetsAndSubjects(targetId) {
const targets = [];
// 無効なら処理しない。
if (targetId === undefined || targetId === null || targetId === "") {
return targets;
}
// カンマ区切りでループ
for (let id of targetId.split(",")) {
// 空白除去
id = id.trim();
// 1~5というように範囲指定の場合
// ※~が存在する。
if (id.indexOf("~") >= 0) {
const idRange = id.split("~");
const idRangeStart = eval(idRange[0]);
const idRangeEnd = eval(idRange[1]);
// IDの指定範囲で実行
// 開始のほうが終了より大きい場合は反対に実行
if (idRangeEnd < idRangeStart) {
for (let i = idRangeStart; i >= idRangeEnd; i--) {
const evalId = eval(i);
if (this.characterAndFollower(evalId)) {
targets.push(this.characterAndFollower(evalId));
}
}
} else {
for (let i = idRangeStart; i <= idRangeEnd; i++) {
const evalId = eval(i);
if (this.characterAndFollower(evalId)) {
targets.push(this.characterAndFollower(evalId));
}
}
}
// 通常時
} else {
const evalId = eval(id);
if (this.characterAndFollower(evalId)) {
targets.push(this.characterAndFollower(evalId));
}
}
}
return targets;
}
/**
* ●アクション情報の作成
*/
function makeAction(itemId, battleSubject, isItem) {
// 適当に先頭のキャラを行動主体にしてアクションを作成
// ※行動主体の情報は基本的に使わないので実際はほぼダミー
let subject = $gameParty.members()[0];
if (battleSubject) {
subject = battleSubject;
}
const action = new Game_Action(subject);
// アイテムかスキルかで分岐
if (isItem) {
action.setItem(itemId);
} else {
action.setSkill(itemId);
}
return action;
}
/**
* ●マップアニメーション用情報を作成
*/
function makeMapAnimation(interpreter, subject, wait, noScroll, action) {
// 始点の初期値はプレイヤー
if (subject === undefined) {
subject = $gamePlayer;
}
// 引き継ぎたい情報をセット
const mapAnimation = [];
mapAnimation.subject = subject;
mapAnimation.interpreter = interpreter;
mapAnimation.noWait = !toBoolean(wait); // 反転させておく
mapAnimation.onScroll = !toBoolean(noScroll); // 反転させておく
// 呼出元が並列処理(trigger:4)かどうか?
const event = $gameMap.event(interpreter.eventId());
if (event && event._trigger == 4) {
mapAnimation.isParallel = true;
}
// 開始時間の設定
const startTimingTarget = getStartTimingTarget(interpreter);
setStartTiming(mapAnimation, action, startTimingTarget);
return mapAnimation;
}
/**
* ●マップアニメーション用情報を作成(戦闘時)
*/
function makeMapAnimationBattle(interpreter, subject, wait, action, targets) {
const mapAnimation = [];
mapAnimation.subject = subject;
mapAnimation.interpreter = interpreter;
mapAnimation.noWait = !toBoolean(wait); // 反転させておく
// 設定があればウェイト
if (!mapAnimation.noWait) {
interpreter.setWaitMode("animation");
interpreter._onDynamicAnimation = true; // 実行中判定
// タイミングを測るためアニメーションの最終対象を保持しておく
interpreter._lastDynamicTargetId = interpreter.getDynamicTargetId(targets[targets.length - 1]);
// モーション判定用の行動主体
interpreter._dynamicSubjectId = interpreter.getDynamicTargetId(subject);
// MVの場合
// ※MZでは循環参照になるので厳禁!
if (Utils.RPGMAKER_NAME == "MV") {
interpreter._character = targets[targets.length - 1];
}
}
// 呼出元が並列処理かどうか?
mapAnimation.isParallel = isParallel(interpreter);
// 開始時間の設定
const startTimingTarget = getStartTimingTarget(interpreter);
setStartTiming(mapAnimation, action, startTimingTarget);
return mapAnimation;
}
/**
* ●開始時間の設定
*/
function setStartTiming(mapAnimation, action, startTimingTarget) {
// メモ欄から開始タイミングを取得
const startTiming = getStartTiming(action);
// 設定があるなら制御
if (startTiming) {
const itemId = action.item().id;
// 未登録の場合のみ処理
// ※二回目以降は処理しない
if (!startTimingTarget.includesDynamicStartSkill(itemId)) {
// 開始時間を設定
mapAnimation.startTiming = startTiming
// スキルIDをイベントに設定
// これにより、一度だけ開始時間処理を行うようにする。
startTimingTarget.setDynamicStartSkill(itemId);
}
}
}
/**
* ●開始時間の管理対象を取得
*/
function getStartTimingTarget(interpreter) {
// コモンイベントが存在すればコモンイベントを取得
for (const commonEvent of $gameMap._commonEvents) {
if (commonEvent._interpreter == interpreter) {
return commonEvent;
}
}
// 実行元のイベントを取得
const event = $gameMap.event(interpreter._eventId);
if (event) {
return event;
}
// 取得できなければプレイヤーを設定
return $gamePlayer;
}
/**
* ●開始時間を取得
*/
function getStartTiming(action) {
// <D-StartTiming:*>を取得
const setting = action.getDynamicNote().match("<" + STARTTIMING_TAG_NAME + "\\s*:(.*)>");
if (setting) {
return setting[1];
}
return 0;
};
/**
* ●戦闘終了時
* ※アニメーション終了後に実行する必要があるため、
* BattleManager.endBattleではなくここでやる。
*/
const _Scene_Battle_terminate = Scene_Battle.prototype.terminate;
Scene_Battle.prototype.terminate = function() {
_Scene_Battle_terminate.apply(this, arguments);
// 戦闘用コモンイベントのDynamicAnimationのフラグをクリア
// ※NRP_BattleParallelCommon.jsとの連携
if ($gameMap._battleCommonEvents) {
for (const commonEvent of $gameMap._battleCommonEvents) {
clearRunningEvent(commonEvent);
}
}
};
/**
* 【独自】DynamicAnimationの途中実行制御フラグ
*/
Game_Character.prototype.includesDynamicStartSkill = function(skillId) {
// 初期化されていない
if (this._dynamicStartSkills === undefined) {
return false;
}
// 既に登録済ならば
if (this._dynamicStartSkills.includes(skillId)) {
return true;
}
return false;
};
Game_Battler.prototype.includesDynamicStartSkill = function(skillId) {
// 初期化されていない
if (this._dynamicStartSkills === undefined) {
return false;
}
// 既に登録済ならば
if (this._dynamicStartSkills.includes(skillId)) {
return true;
}
return false;
};
Game_CommonEvent.prototype.includesDynamicStartSkill = function(skillId) {
// 初期化されていない
if (this._dynamicStartSkills === undefined) {
return false;
}
// 既に登録済ならば
if (this._dynamicStartSkills.includes(skillId)) {