-
Notifications
You must be signed in to change notification settings - Fork 0
/
NRP_EnemyCollapse.js
643 lines (600 loc) · 22.3 KB
/
NRP_EnemyCollapse.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
//=============================================================================
// NRP_EnemyCollapse.js
//=============================================================================
/*:
* @target MV MZ
* @plugindesc v1.001 Change the effect when an enemy collapses.
* @author Takeshi Sunagawa (https://newrpg.seesaa.net/)
* @orderAfter NRP_DamageTiming
* @url https://newrpg.seesaa.net/article/501277851.html
*
* @help Change the effect when an enemy collapses.
*
* BlendMode and BlendColor can be changed.
* Other animations can be played back
* by calling DynamicAnimation&Motion.
*
* -------------------------------------------------------------------
* [Usage]
* -------------------------------------------------------------------
* Register your settings in CollapseList.
* The ID registered here will be used to link the settings.
*
* The collapse effect can be applied to the entire area
* by means of a plugin parameter.
* In addition, it can be specified individually for each enemy.
*
* -------------------------------------------------------------------
* [Note of Enemies]
* -------------------------------------------------------------------
* ◆Specify method of collapse
* <CollapseId:[ID]>
*
* Link the registered collapse effects to the enemy by ID.
* Do not include [].
*
* -------------------------------------------------------------------
* [Sample]
* -------------------------------------------------------------------
* The following samples are available in CollapseList.
*
* ◆normal
* This is exactly the same as the normal enemy collapse direction.
* Please use for reference only.
*
* ◆boss
* It is exactly the same as the normal boss collapse direction.
*
* ◆sink
* It collapses as the enemy sinks.
*
* ◆boss_shake
* This is a boss collapse direction with screen shaking.
*
* -------------------------------------------------------------------
* [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.
*
* @-----------------------------------------------------
* @ [Plugin Parameters]
* @-----------------------------------------------------
*
* @param CollapseList
* @type struct<CollapseData>[]
* @default ["{\"Id\":\"normal\",\"CollapseType\":\"Normal\",\"Duration\":\"32\",\"BlendMode\":\"1\",\"BlendColor\":\"[255, 128, 128, 128]\",\"ShakeStrength\":\"0\",\"Sound1\":\"Collapse1\",\"Sound2\":\"\",\"Sound2Interval\":\"\",\"DynamicId\":\"\",\"Wait\":\"\",\"Script\":\"\"}","{\"Id\":\"boss\",\"CollapseType\":\"Sink\",\"Duration\":\"this.bitmap.height\",\"BlendMode\":\"1\",\"BlendColor\":\"[255, 255, 255, 255 - this.opacity]\",\"ShakeStrength\":\"2\",\"Sound1\":\"Collapse2\",\"Sound2\":\"Collapse3\",\"Sound2Interval\":\"20\",\"DynamicId\":\"\",\"Wait\":\"\",\"Script\":\"\"}","{\"Id\":\"sink\",\"CollapseType\":\"Sink\",\"Duration\":\"32\",\"BlendMode\":\"1\",\"BlendColor\":\"[255, 128, 128, 128]\",\"ShakeStrength\":\"0\",\"Sound1\":\"Collapse1\",\"Sound2\":\"\",\"Sound2Interval\":\"\",\"DynamicId\":\"\",\"Wait\":\"\",\"Script\":\"\"}","{\"Id\":\"boss_shake\",\"CollapseType\":\"Sink\",\"Duration\":\"this.bitmap.height\",\"BlendMode\":\"1\",\"BlendColor\":\"[255, 255, 255, 255 - this.opacity]\",\"ShakeStrength\":\"2\",\"Sound1\":\"Collapse2\",\"Sound2\":\"Collapse3\",\"Sound2Interval\":\"20\",\"DynamicId\":\"\",\"Wait\":\"\",\"Script\":\"$gameScreen.startShake(1, 20, this.bitmap.height);\"}"]
* @desc This list defines the collapse effects.
*
* @param DefaultCollapseId
* @type string
* @desc Standard collapse effects.
* CollapseList ID.
*
* @param DefaultBossCollapseId
* @type string
* @desc Standard boss collapse effects.
* CollapseList ID.
*/
/*~struct~CollapseData:
* @param Id
* @type string
* @desc Management ID.
*
* @param CollapseType
* @type select
* @option Normal
* @option Sink
* @option None
* @default Normal
* @desc Type of collapse.
* In the case of "Sink", the collapse is downward.
*
* @param Duration
* @type combo
* @option 32
* @option this.bitmap.height
* @default 32
* @desc The time to collapse.
* this.bitmap.height refers to the height of the image.
*
* @param BlendMode
* @type select
* @option 0:Normal @value 0
* @option 1:Add @value 1
* @option 2:Multiply @value 2
* @option 3:Screen @value 3
* @default 1
* @desc This is how the image is blended during the collapse.
*
* @param BlendColor
* @type string
* @default [255, 128, 128, 128]
* @desc The color to be applied to the image.
* e.g.:[255,255,255,255] (Red, Green, Blue, Strength)
*
* @param ShakeStrength
* @type number
* @default 0
* @desc The strength of the shaking.
*
* @param Sound1
* @text Sound1 (start)
* @type file
* @dir audio/se
* @desc This is the sound effect at the start of the collapse.
*
* @param Sound2
* @text Sound2 (loop)
* @type file
* @dir audio/se
* @desc This is a sound effect that continues to sound during the collapse.
*
* @param Sound2Interval
* @type number
* @desc This is the interval at which Sound2 is played repeatedly.
*
* @param DynamicId
* @text DynamicID
* @type skill
* @desc Specify the collapse direction by DynamicAnimation&Motion.
* Specify the ID of the skill.
*
* @param Wait
* @type boolean
* @desc Whether to wait for the collapse effect.
* If blank (DEL), the original settings will be taken over.
*
* @param Script
* @type string
* @desc Script to be executed at the time of collapse.
* e.g.:$gameScreen.startShake(1, 20, this.bitmap.height);
*/
/*:ja
* @target MV MZ
* @plugindesc v1.001 敵消滅時の演出を変更する。
* @author 砂川赳(https://newrpg.seesaa.net/)
* @orderAfter NRP_DamageTiming
* @url https://newrpg.seesaa.net/article/501277851.html
*
* @help 敵が消滅する際のエフェクトを変更します。
*
* 合成方法や色調の変更の他にも、
* DynamicAnimation&Motionの呼び出しによって、
* アニメーションを再生することもできます。
*
* -------------------------------------------------------------------
* ■使用方法
* -------------------------------------------------------------------
* 消滅エフェクト一覧に設定を登録してください。
* ここで登録したIDによって紐づけを行います。
*
* 消滅エフェクトはプラグインパラメータによって、
* 全体に適用することができる他、敵毎に個別に指定することもできます。
*
* -------------------------------------------------------------------
* ■敵キャラのメモ欄
* -------------------------------------------------------------------
* ◆消滅方法の指定
* <CollapseId:[ID]>
*
* 登録した消滅エフェクトを、IDによって敵と紐づけします。
* ※[]は含まないでください。
*
* -------------------------------------------------------------------
* ■サンプル
* -------------------------------------------------------------------
* 消滅エフェクト一覧に以下のサンプルを用意しています。
*
* ◆normal
* 通常の敵消滅演出と全く同じものです。
* 参考用にご利用ください。
*
* ◆boss
* 通常のボス消滅演出と全く同じものです。
*
* ◆sink
* 敵が沈むように消滅します。
*
* ◆boss_shake
* ボス消滅演出に画面振動を加えたものです。
*
* -------------------------------------------------------------------
* ■利用規約
* -------------------------------------------------------------------
* 特に制約はありません。
* 改変、再配布自由、商用可、権利表示も任意です。
* 作者は責任を負いませんが、不具合については可能な範囲で対応します。
*
* @-----------------------------------------------------
* @ プラグインパラメータ
* @-----------------------------------------------------
*
* @param CollapseList
* @text 消滅エフェクト一覧
* @type struct<CollapseData>[]
* @default ["{\"Id\":\"normal\",\"CollapseType\":\"Normal\",\"Duration\":\"32\",\"BlendMode\":\"1\",\"BlendColor\":\"[255, 128, 128, 128]\",\"ShakeStrength\":\"0\",\"Sound1\":\"Collapse1\",\"Sound2\":\"\",\"Sound2Interval\":\"\",\"DynamicId\":\"\",\"Wait\":\"\",\"Script\":\"\"}","{\"Id\":\"boss\",\"CollapseType\":\"Sink\",\"Duration\":\"this.bitmap.height\",\"BlendMode\":\"1\",\"BlendColor\":\"[255, 255, 255, 255 - this.opacity]\",\"ShakeStrength\":\"2\",\"Sound1\":\"Collapse2\",\"Sound2\":\"Collapse3\",\"Sound2Interval\":\"20\",\"DynamicId\":\"\",\"Wait\":\"\",\"Script\":\"\"}","{\"Id\":\"sink\",\"CollapseType\":\"Sink\",\"Duration\":\"32\",\"BlendMode\":\"1\",\"BlendColor\":\"[255, 128, 128, 128]\",\"ShakeStrength\":\"0\",\"Sound1\":\"Collapse1\",\"Sound2\":\"\",\"Sound2Interval\":\"\",\"DynamicId\":\"\",\"Wait\":\"\",\"Script\":\"\"}","{\"Id\":\"boss_shake\",\"CollapseType\":\"Sink\",\"Duration\":\"this.bitmap.height\",\"BlendMode\":\"1\",\"BlendColor\":\"[255, 255, 255, 255 - this.opacity]\",\"ShakeStrength\":\"2\",\"Sound1\":\"Collapse2\",\"Sound2\":\"Collapse3\",\"Sound2Interval\":\"20\",\"DynamicId\":\"\",\"Wait\":\"\",\"Script\":\"$gameScreen.startShake(1, 20, this.bitmap.height);\"}"]
* @desc 消滅エフェクトを定義する一覧です。
*
* @param DefaultCollapseId
* @text 標準の消滅ID
* @type string
* @desc 標準の消滅エフェクトです。
* 消滅エフェクト一覧のIDを指定してください。
*
* @param DefaultBossCollapseId
* @text 標準の消滅ID(ボス)
* @type string
* @desc 標準のボスの消滅エフェクトです。
* 消滅エフェクト一覧のIDを指定してください。
*/
/*~struct~CollapseData:ja
* @param Id
* @text ID
* @type string
* @desc 管理用のIDです。
*
* @param CollapseType
* @text 消滅タイプ
* @type select
* @option 通常 @value Normal
* @option 沈む @value Sink
* @option 消えない @value None
* @default Normal
* @desc 消滅のタイプです。
* 『沈む』の場合は下に向かって消滅します。
*
* @param Duration
* @text 消滅時間
* @type combo
* @option 32
* @option this.bitmap.height
* @default 32
* @desc 消滅にかける時間です。
* this.bitmap.heightで画像の高さを参照します。
*
* @param BlendMode
* @text 合成方法
* @type select
* @option 0:通常 @value 0
* @option 1:加算 @value 1
* @option 2:乗算 @value 2
* @option 3:スクリーン @value 3
* @default 1
* @desc 消滅時の画像の合成方法です。
*
* @param BlendColor
* @text 色
* @type string
* @default [255, 128, 128, 128]
* @desc 消滅時の画像に適用する色です。
* 例:[255,255,255,255](赤、緑、青、強さ)
*
* @param ShakeStrength
* @text 揺れの強さ
* @type number
* @default 0
* @desc 揺れの強さです。
*
* @param Sound1
* @text 効果音1(開始)
* @type file
* @dir audio/se
* @desc 消滅開始時の効果音です。
*
* @param Sound2
* @text 効果音2(繰返)
* @type file
* @dir audio/se
* @desc 消滅中に鳴らし続ける効果音です。
*
* @param Sound2Interval
* @text 効果音2の間隔
* @type number
* @desc 効果音2を繰り返し演奏する間隔です。
*
* @param DynamicId
* @text DynamicID
* @type skill
* @desc DynamicAnimation&Motionによる消滅演出を指定します。
* スキルのIDを指定してください。
*
* @param Wait
* @text ウェイト
* @type boolean
* @desc 消滅エフェクトを待つかどうかです。
* 空欄(DEL)なら元の設定を引き継ぎます。
*
* @param Script
* @text スクリプト
* @type string
* @desc 消滅時に実行するスクリプトです。
* 例:$gameScreen.startShake(1, 20, this.bitmap.height);
*/
(function() {
"use strict";
/**
* ●構造体(二重配列)をJSで扱えるように変換
*/
function parseStruct2(arg) {
const ret = [];
if (arg) {
for (const str of JSON.parse(arg)) {
ret.push(JSON.parse(str));
}
}
return ret;
}
function toNumber(str, def) {
if (str == undefined || str == "") {
return def;
}
return isNaN(str) ? def : +(str || def);
}
function toBoolean(str, def) {
if (str === true || str === "true") {
return true;
} else if (str === false || str === "false") {
return false;
}
return def;
}
function setDefault(str, def) {
if (str == undefined || str == "") {
return def;
}
return str;
}
const PLUGIN_NAME = "NRP_EnemyCollapse";
const parameters = PluginManager.parameters(PLUGIN_NAME);
const pCollapseList = parseStruct2(parameters["CollapseList"]);
const pDefaultCollapseId = setDefault(parameters["DefaultCollapseId"]);
const pDefaultBossCollapseId = setDefault(parameters["DefaultBossCollapseId"]);
// ----------------------------------------------------------------------------
// Game_BattlerBase
// ----------------------------------------------------------------------------
/**
* 【独自】独自の消滅タイプ
*/
Game_BattlerBase.prototype.originalCollapseId = function() {
return null;
};
/**
* 【独自】独自の消滅データ
*/
Game_BattlerBase.prototype.originalCollapseData = function() {
return null;
};
// ----------------------------------------------------------------------------
// Game_Enemy
// ----------------------------------------------------------------------------
/**
* 【独自】独自の消滅タイプ
*/
Game_Enemy.prototype.originalCollapseId = function() {
const collapseId = this.enemy().meta.CollapseId;
// 消滅IDの指定がない場合は既定値
if (collapseId == null) {
// 通常
if (this.collapseType() == 0 && pDefaultCollapseId) {
return pDefaultCollapseId;
// ボス
} else if (this.collapseType() == 1 && pDefaultBossCollapseId) {
return pDefaultBossCollapseId;
}
return null;
}
// 消滅IDの指定がある場合
try {
const a = this;
return eval(collapseId);
} catch(e) {}
// evalでエラーになった場合はそのまま返す
return collapseId;
};
/**
* 【独自】独自の消滅データ
*/
Game_Enemy.prototype.originalCollapseData = function() {
// 演出の指定があった場合
const originalCollapseId = this.originalCollapseId();
if (originalCollapseId != null) {
Game_Battler.prototype.performCollapse.call(this);
// 条件を満たす消滅データを取得
return pCollapseList.find(collapseData => collapseData.Id == originalCollapseId);
}
return null;
};
/**
* ●消滅演出開始
*/
const _Game_Enemy_performCollapse = Game_Enemy.prototype.performCollapse;
Game_Enemy.prototype.performCollapse = function() {
// 独自の消滅演出があった場合
const collapseData = this.originalCollapseData();
if (collapseData) {
// 通常は空だが元の処理にあったので呼び出し
Game_Battler.prototype.performCollapse.call(this);
// 独自の消滅演出を呼び出し
this.requestEffect("originalCollapse");
// 効果音を演奏
if (collapseData.Sound1) {
AudioManager.playSe({"name":collapseData.Sound1, "volume":90, "pitch":100, "pan":0})
}
return;
}
_Game_Enemy_performCollapse.apply(this, arguments);
};
// ----------------------------------------------------------------------------
// Sprite_Enemy
// ----------------------------------------------------------------------------
/**
* ●エフェクト開始
*/
const _Sprite_Enemy_startEffect = Sprite_Enemy.prototype.startEffect;
Sprite_Enemy.prototype.startEffect = function(effectType) {
// 独自の消滅演出の場合
if (effectType == "originalCollapse") {
this._effectType = effectType;
this.startOriginalCollapse();
this.revertToNormal();
return;
}
_Sprite_Enemy_startEffect.apply(this, arguments);
};
/**
* ●エフェクト更新
*/
const _Sprite_Enemy_updateEffect = Sprite_Enemy.prototype.updateEffect;
Sprite_Enemy.prototype.updateEffect = function() {
// 独自の消滅演出の場合
if (this._effectType == "originalCollapse") {
this.setupEffect();
if (this._effectDuration > 0) {
this._effectDuration--;
this.updateOriginalCollapse();
// キリのよい計算でないとフリーズするので『<=』にしておく。
if (this._effectDuration <= 0) {
this._effectType = null;
}
}
return;
}
_Sprite_Enemy_updateEffect.apply(this, arguments);
};
/**
* 【独自】独自の消滅演出を開始
*/
Sprite_Enemy.prototype.startOriginalCollapse = function() {
// eval参照用
const a = this._battler;
const collapseData = this._battler.originalCollapseData();
const duration = eval(collapseData.Duration);
this._effectDuration = setDefault(duration, 32);
this._appeared = false;
// DynamicAnimation&Motion実行
if (collapseData.DynamicId) {
const dynamicId = eval(collapseData.DynamicId);
if (dynamicId) {
callDynamic(this, dynamicId);
}
}
// スクリプトの実行
if (collapseData.Script != null) {
eval(collapseData.Script);
}
};
/**
* 【独自】独自の消滅演出の更新
*/
Sprite_Enemy.prototype.updateOriginalCollapse = function() {
const collapseData = this._battler.originalCollapseData();
// 消さない場合
if (collapseData.CollapseType == "None") {
return;
}
// 消滅時間が小数だと余剰計算ができないので切り捨てする。
const effectDuration = Math.floor(this._effectDuration);
// 振動
const shakeStrength = setDefault(eval(collapseData.ShakeStrength), 0);
this._shake = (effectDuration % 2) == 0 ? -shakeStrength : shakeStrength;
// 合成方法
const blendMode = setDefault(eval(collapseData.BlendMode), 1);
this.blendMode = blendMode;
// 色調
const blendColor = setDefault(eval(collapseData.BlendColor), [255, 128, 128, 128]);
this.setBlendColor(blendColor);
// 効果音2
if (collapseData.Sound2 && collapseData.Sound2Interval) {
const sound2Interval = eval(collapseData.Sound2Interval);
if (effectDuration % sound2Interval === sound2Interval - 1) {
AudioManager.playSe({"name":collapseData.Sound2, "volume":90, "pitch":100, "pan":0})
}
}
this.opacity *= this._effectDuration / (this._effectDuration + 1);
};
/**
* ●フレーム更新
*/
const _Sprite_Enemy_updateFrame = Sprite_Enemy.prototype.updateFrame;
Sprite_Enemy.prototype.updateFrame = function() {
const collapseData = this._battler.originalCollapseData();
// 独自消滅エフェクトでない場合
// または、消滅データがない場合は通常通り
if (this._effectType != "originalCollapse" || !collapseData) {
_Sprite_Enemy_updateFrame.apply(this, arguments);
return;
}
Sprite_Battler.prototype.updateFrame.call(this);
// 沈む場合(ボス)
if (collapseData.CollapseType == "Sink") {
const duration = eval(collapseData.Duration);
this.setFrame(0, 0, this.bitmap.width, (this._effectDuration / duration) * this.bitmap.height);
// 通常の場合
} else {
this.setFrame(0, 0, this.bitmap.width, this.bitmap.height);
}
};
/**
* ●撃破演出時のウェイト
*/
const _Sprite_Enemy_isEffecting = Sprite_Enemy.prototype.isEffecting;
Sprite_Enemy.prototype.isEffecting = function() {
const collapseData = this._battler.originalCollapseData();
// 独自消滅エフェクトかつ消滅データが存在する場合
if (this._effectType == "originalCollapse" && collapseData) {
// ウェイトの指定がある場合
const wait = toBoolean(collapseData.Wait);
if (wait === true) {
return true;
} else if (wait === false) {
return false;
}
}
return _Sprite_Enemy_isEffecting.apply(this, arguments);
};
//-----------------------------------------------------------------------------
// 共通関数
//-----------------------------------------------------------------------------
/**
* ●DynamicAnimation&Motionを呼び出し
*/
function callDynamic(sprite, dynamicId) {
const battler = sprite._battler;
// 実行するDynamicAnimation情報を持ったアクション
const dynamicAction = makeAction(dynamicId, battler);
// バトラーを対象にする。
const targets = [battler];
// 引き継ぎたい情報をセット
const mapAnimation = [];
// バトラーを行動主体にする。
mapAnimation.subject = battler;
// ウェイトしないように並列実行
mapAnimation.isParallel = true;
// 空のWindow_BattleLogを作成し、DynamicAnimationを起動
const win = new Window_BattleLog(new Rectangle());
win.showDynamicAnimation(targets, dynamicAction, false, mapAnimation);
}
/**
* ●アクション情報の作成
*/
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;
}
})();