File size: 14,701 Bytes
99b0de1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
//=============================================================================
// RPGツクールMZ - LL_MenuScreenBase.js v1.1.0
//-----------------------------------------------------------------------------
// ルルの教会 (Lulu's Church)
// https://nine-yusha.com/
//
// URL below for license details.
// https://nine-yusha.com/plugin/
//=============================================================================

/*:

 * @target MZ

 * @plugindesc メニュー画面立ち絵設定の共通ベースプラグインです。

 * @author ルルの教会

 * @url https://nine-yusha.com/plugin-menuscreen/

 *

 * @help LL_MenuScreenBase.js

 *

 * メニュー画面立ち絵設定の共通ベースプラグインです。

 * このプラグインでアクター毎の立ち絵リストを定義します。

 *

 * 下記のようにステート、スイッチ、変数条件で表示する立ち絵を複数定義できます。

 *   ・スイッチ1がONかつ毒状態の立ち絵

 *   ・変数1が10以上かつ毒状態の立ち絵

 *   ・スイッチ1がONの時の立ち絵

 *   ・毒状態の立ち絵

 *   ・スイッチ・ステート・変数条件なしの通常立ち絵 (最低限必要)

 *

 * 残りHP%で立ち絵を切り替える:

 *   まず「残りHP%」を「100」に設定した立ち絵リストを作成します。

 *   上記をコピーして「残りHP%」を「50」に変更し、立ち絵リストを複製します。

 *   これでHPが半分以下になった場合、「50」に設定した立ち絵が呼ばれます。

 *   残りHP%毎に、複数立ち絵を定義することも可能です。

 *

 * 画像ファイルの表示優先順:

 *   1. ステートID、スイッチID、変数条件全てに一致するもの

 *   2. ステートID、スイッチID両方に一致するもの

 *   3. ステートID、変数条件両方に一致するもの

 *   4. ステートIDのみ一致するもの

 *   5. スイッチID、変数条件両方に一致するもの

 *   6. スイッチIDのみ一致するもの

 *   7. 変数条件のみ一致するもの

 *   8. 条件なし (ステートID、スイッチID、変数条件全て設定なし)

 *   (上記の中で、残りHP%が最も低いものが優先して表示されます)

 *

 * 戦闘中立ち絵プラグイン連携:

 *   LL_StandingPictureBattle が導入されている場合は、

 *   戦闘中の立ち絵リストとそのまま連携させることも可能です。

 *

 * プラグインコマンドはありません。

 *

 * 利用規約:

 *   ・著作権表記は必要ございません。

 *   ・利用するにあたり報告の必要は特にございません。

 *   ・商用・非商用問いません。

 *   ・R18作品にも使用制限はありません。

 *   ・ゲームに合わせて自由に改変していただいて問題ございません。

 *   ・プラグイン素材としての再配布(改変後含む)は禁止させていただきます。

 *

 * 作者: ルルの教会

 * 作成日: 2022/3/7

 *

 * @param menuPictures

 * @text 立ち絵リスト

 * @desc メニュー画面に表示する立ち絵を定義します。

 * 特定ステート時、スイッチON時の立ち絵を複数定義できます。

 * @default []

 * @type struct<menuPictures>[]

 *

 * @param onSpbPlugin

 * @text 戦闘中立ち絵プラグイン連携

 * @desc ※この項目は使用しません

 *

 * @param onSpbPluginEnable

 * @text 立ち絵リストを連携

 * @desc LL_StandingPictureBattle の立ち絵リストと連携させます。

 * ONにするとこのプラグインの立ち絵リスト設定は無視されます。

 * @default false

 * @type boolean

 * @parent onSpbPlugin

 */

/*~struct~menuPictures:

 *

 * @param actorId

 * @text アクターID

 * @desc アクターIDです。立ち絵を定義するアクターを選択してください。

 * @type actor

 *

 * @param stateId

 * @text ステートID

 * @desc 特定ステートで立ち絵を変更したい場合に使用します。

 * 通常時の立ち絵は空白(なし)で設定ください。

 * @type state

 *

 * @param switchId

 * @text スイッチID

 * @desc スイッチONで立ち絵を変更したい場合に使用します。

 * 通常時の立ち絵は空白(なし)で設定ください。

 * @type switch

 *

 * @param variableCase

 * @text 変数条件

 * @desc 変数条件で立ち絵を変更したい場合に使用します。

 * @default

 * @type struct<variableCase>

 *

 * @param hpPercentage

 * @text 残りHP%

 * @desc 残りHP%で立ち絵を変更したい場合に使用します。

 * 通常時の立ち絵は100%で設定してください。

 * @default 100

 * @min 0

 * @max 100

 * @type number

 *

 * @param imageName

 * @text 画像ファイル名

 * @desc 立ち絵として表示する画像ファイルを選択してください。

 * @dir img/pictures

 * @type file

 * @require 1

 *

 * @param x

 * @text X座標

 * @desc 立ち絵の表示位置(X)の調整値です。

 * +で右へ、-で左へ調整します。 (初期値: 0)

 * @default 0

 * @min -9999

 * @max 9999

 * @type number

 *

 * @param y

 * @text Y座標

 * @desc 立ち絵の表示位置(Y)の調整値です。

 * +で下へ、-で上へ調整します。 (初期値: 0)

 * @default 0

 * @min -9999

 * @max 9999

 * @type number

 *

 * @param scaleX

 * @text X拡大率

 * @desc 立ち絵の拡大率(X)です。

 * @default 100

 * @min -2000

 * @max 2000

 * @type number

 *

 * @param scaleY

 * @text Y拡大率

 * @desc 立ち絵の拡大率(Y)です。

 * @default 100

 * @min -2000

 * @max 2000

 * @type number

 */

/*~struct~variableCase:

 *

 * @param id

 * @text 変数ID

 * @desc 条件に使用する変数IDです。

 * @type variable

 *

 * @param type

 * @text 変数条件

 * @desc 変数IDとの比較条件です。

 * @default equal

 * @type select

 * @option 一致する

 * @value equal

 * @option 以上

 * @value higher

 * @option 以下

 * @value lower

 *

 * @param value

 * @text 変数比較数値

 * @desc 変数IDと比較する数値です。

 * @default 0

 * @min -99999999

 * @max 99999999

 * @type number

 */

(() => {
	"use strict";
	const pluginName = "LL_MenuScreenBase";

	const parameters = PluginManager.parameters(pluginName);
	const paramJsonParse = function(key, value) {
		try {
			return JSON.parse(value);
		} catch(e) {
			return value;
		}
	};

	const menuPictures = String(parameters["menuPictures"] || "[]");
	const onSpbPluginEnable = eval(parameters["onSpbPluginEnable"] || "true");
	const menuPictureLists = JSON.parse(JSON.stringify(menuPictures, paramJsonParse));

	//-----------------------------------------------------------------------------
	// 戦闘中立ち絵プラグインの立ち絵リストを取得
	// On LL_StandingPictureBattle Plugin
	//-----------------------------------------------------------------------------
	const spbPluginName = "LL_StandingPictureBattle";
	const spbParameters = PluginManager.parameters(spbPluginName);
	const spbCommandPictures = String(spbParameters["sbCommandPictures"] || "[]");
	const spbCommandPictureLists = JSON.parse(JSON.stringify(spbCommandPictures, paramJsonParse));

	//-----------------------------------------------------------------------------
	// Ex Menu Screen Base Class
	//
	// メニュー画面立ち絵設定の独自クラスを追加定義します。

	class ExMenuScreenBase {

		//-----------------------------------------------------------------------------
		// 画像ファイル名を取得
		//-----------------------------------------------------------------------------
		static getImageName (actorId) {
			// 立ち絵リストを取得
			let pictureLists = this.getPictureLists();
			if (!pictureLists) return;

			// アクターのステート情報を取得
			let actorStates = [];
			if (actorId) actorStates = $gameActors.actor(actorId)._states;
			let specificPicture = null;

			// アクターIDが一致する立ち絵を検索
			pictureLists = pictureLists.filter(function(item) {
				if (Number(item.actorId) == actorId) {
					return true;
				}
			});

			// ステートにかかっているか?
			if (actorStates.length) {
				// ステートID・スイッチID・変数IDが有効な立ち絵リストを検索
				specificPicture = pictureLists.filter(function(item) {
					if (item.variableCase) {
						if (
							actorStates.indexOf(Number(item.stateId)) !== -1 &&
							$gameSwitches.value(Number(item.switchId)) &&
							(
								String(item.variableCase.type) == "equal" && $gameVariables.value(Number(item.variableCase.id)) == Number(item.variableCase.value) ||
								String(item.variableCase.type) == "higher" && $gameVariables.value(Number(item.variableCase.id)) >= Number(item.variableCase.value) ||
								String(item.variableCase.type) == "lower" && $gameVariables.value(Number(item.variableCase.id)) <= Number(item.variableCase.value)
							)
						) {
							return true;
						}
					}
				});
				if (specificPicture.length) return this.checkHpPercentage(actorId, specificPicture);
				// ステートID・スイッチIDが有効な立ち絵リストを検索
				specificPicture = pictureLists.filter(function(item) {
					if (actorStates.indexOf(Number(item.stateId)) !== -1 && $gameSwitches.value(Number(item.switchId)) && !item.variableCase) {
						return true;
					}
				});
				if (specificPicture.length) return this.checkHpPercentage(actorId, specificPicture);
				// ステートID・変数IDが有効な立ち絵リストを検索
				specificPicture = pictureLists.filter(function(item) {
					if (item.variableCase) {
						if (
							actorStates.indexOf(Number(item.stateId)) !== -1 &&
							(Number(item.switchId) === 0 || !item.switchId) &&
							(
								String(item.variableCase.type) == "equal" && $gameVariables.value(Number(item.variableCase.id)) == Number(item.variableCase.value) ||
								String(item.variableCase.type) == "higher" && $gameVariables.value(Number(item.variableCase.id)) >= Number(item.variableCase.value) ||
								String(item.variableCase.type) == "lower" && $gameVariables.value(Number(item.variableCase.id)) <= Number(item.variableCase.value)
							)
						) {
							return true;
						}
					}
				});
				if (specificPicture.length) return this.checkHpPercentage(actorId, specificPicture);
				// ステートIDが有効な立ち絵リストを検索
				specificPicture = pictureLists.filter(function(item) {
					if (actorStates.indexOf(Number(item.stateId)) !== -1 && (Number(item.switchId) === 0 || !item.switchId) && !item.variableCase) {
						return true;
					}
				});
				if (specificPicture.length) return this.checkHpPercentage(actorId, specificPicture);
			}

			// スイッチID・変数IDが有効な立ち絵リストを検索
			specificPicture = pictureLists.filter(function(item) {
				if (item.variableCase) {
					if (
						(Number(item.stateId) === 0 || !item.stateId) &&
						$gameSwitches.value(Number(item.switchId)) &&
						(
							String(item.variableCase.type) == "equal" && $gameVariables.value(Number(item.variableCase.id)) == Number(item.variableCase.value) ||
							String(item.variableCase.type) == "higher" && $gameVariables.value(Number(item.variableCase.id)) >= Number(item.variableCase.value) ||
							String(item.variableCase.type) == "lower" && $gameVariables.value(Number(item.variableCase.id)) <= Number(item.variableCase.value)
						)
					) {
						return true;
					}
				}
			});
			if (specificPicture.length) return this.checkHpPercentage(actorId, specificPicture);
			// スイッチIDが有効な立ち絵リストを検索
			specificPicture = pictureLists.filter(function(item) {
				if ((Number(item.stateId) === 0 || !item.stateId) && $gameSwitches.value(Number(item.switchId)) && !item.variableCase) {
					return true;
				}
			});
			if (specificPicture.length) return this.checkHpPercentage(actorId, specificPicture);
			// 変数IDが有効な立ち絵リストを検索
			specificPicture = pictureLists.filter(function(item) {
				if (item.variableCase) {
					if (
						(Number(item.stateId) === 0 || !item.stateId) &&
						(Number(item.switchId) === 0 || !item.switchId) &&
						(
							String(item.variableCase.type) == "equal" && $gameVariables.value(Number(item.variableCase.id)) == Number(item.variableCase.value) ||
							String(item.variableCase.type) == "higher" && $gameVariables.value(Number(item.variableCase.id)) >= Number(item.variableCase.value) ||
							String(item.variableCase.type) == "lower" && $gameVariables.value(Number(item.variableCase.id)) <= Number(item.variableCase.value)
						)
					) {
						return true;
					}
				}
			});
			if (specificPicture.length) return this.checkHpPercentage(actorId, specificPicture);

			// 上記で見つからなかった場合、通常の立ち絵を検索
			let normalPicture = pictureLists.filter(function(item) {
				if ((Number(item.stateId) === 0 || !item.stateId) && (Number(item.switchId) === 0 || !item.switchId) && !item.variableCase) return true;
			});
			if (normalPicture.length) return this.checkHpPercentage(actorId, normalPicture);
		}

		static checkHpPercentage (actorId, pictureLists) {
			// アクターの残HP%を取得
			let hpRate = this.getHpRate(actorId);
			// 最もHP%が低い立ち絵を適用する
			let minHpRate = 100;
			let result = null;
			pictureLists.forEach(function(item) {
				if (hpRate <= Number(item.hpPercentage) && minHpRate >= Number(item.hpPercentage)) {
					result = item;
					minHpRate = Number(item.hpPercentage);
				} else if (!item.hpPercentage && minHpRate >= 100) {
					// プラグインパラメータが更新されていない場合、便宜的に100として扱う
					result = item;
					minHpRate = Number(item.hpPercentage);
				}
			});
			return result;
		}

		static getPictureLists () {
			return onSpbPluginEnable ? spbCommandPictureLists : menuPictureLists;
		}

		static onSpbPluginEnable () {
			return onSpbPluginEnable;
		}

		// アクターのHPレートを取得
		static getHpRate (actorId) {
			if (!$gameActors.actor(actorId)) return 0;
			return $gameActors.actor(actorId).mhp > 0 ? $gameActors.actor(actorId).hp / $gameActors.actor(actorId).mhp * 100 : 0;
		}
	}

	window.ExMenuScreenBase = ExMenuScreenBase;
})();