-
Notifications
You must be signed in to change notification settings - Fork 125
/
FootstepSound.js
353 lines (331 loc) · 14.7 KB
/
FootstepSound.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
//=============================================================================
// FootstepSound.js
// ----------------------------------------------------------------------------
// (C) 2016 Triacontane
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
// ----------------------------------------------------------------------------
// Version
// 2.0.0 2018/09/05 プレイヤーの足音を無効化するスイッチを指定できる機能を追加
// パラメータの型指定機能に対応
// 1.1.0 2017/06/23 立ち止まったときに足音演奏間隔をリセットする機能を追加
// 1.0.0 2016/02/18 初版
// ----------------------------------------------------------------------------
// [Blog] : https://triacontane.blogspot.jp/
// [Twitter]: https://twitter.com/triacontane/
// [GitHub] : https://github.com/triacontane/
//=============================================================================
/*:
* @plugindesc 足音プラグイン
* @author トリアコンタン
*
* @param EventRunningInvalid
* @text イベント実行中無効
* @desc イベント実行中は足音を無効にする。(ON/OFF)
* @default false
* @type boolean
*
* @param ResetIfStop
* @text 立ち止まるとリセット
* @desc 演奏間隔が設定されている場合、立ち止まることでリセットされます。(ON/OFF)
* @default false
* @type boolean
*
* @param InvalidSwitchId
* @text 無効スイッチID
* @desc 指定したスイッチがONのときプレイヤーの足音が無効になります。指定しない場合は常に有効になります。
* @default 0
* @type switch
*
* @help version 2.0.0以降に差し替えた場合はパラメータの再設定が必要です。
*
* 以下の状況下で指定した足音効果音を演奏します。
* 数字の小さい方が優先度が高いです。
* 1. 飛行船乗船時
* 2. 大型船乗船時
* 3. 小型船乗船時
* 4. 指定リージョン通過時
* 5. ダメージ床属性通過時
* 6. 茂み属性通過時
* 7. カウンター属性通過時
* 8. 梯子属性通過時
* 9. 指定地形タグ通過時
* 10. 常に
*
* 効果音を指定する場合、当ファイル「FootstepSound.js」を
* テキストエディタで開き「ユーザ書き換え領域」と書かれている
* 部分を注釈に従って修正してください。
*
* 要注意! 指定した効果音は、デプロイメント時に
* 未使用ファイルとして除外される可能性があります。
* その場合、削除されたファイルを入れ直す等の対応が必要です。
*
* 足音が演奏されるのはプレイヤーのみですが、
* 「移動ルートの指定」の「スクリプト」から以下を実行すると
* イベントにも足音が演奏されるようになります。
*
* 足音を演奏する :this.setStepSoundFlg(true);
* 足音を演奏しない:this.setStepSoundFlg(false);
*
* プラグインコマンド詳細
* イベントコマンド「プラグインコマンド」から実行。
* (引数の間は半角スペースで区切る)
*
* 足音無効化 or FS_INVALID_SOUND
* 一時的に全ての足音を無効にします。
* 例:足音無効化
*
* 足音有効化 or FS_VALID_SOUND
* 全ての足音を有効に戻します。
* 例:足音有効化
*
* 利用規約:
* 作者に無断で改変、再配布が可能で、利用形態(商用、18禁利用等)
* についても制限はありません。
* このプラグインはもうあなたのものです。
*/
(function() {
//=============================================================================
// ユーザ書き換え領域 - 開始 -
// name : 効果音名称(拡張子不要)
// volume : 音量(0...100)
// pitch : ピッチ(50...150)
// pan : 位相(-100...100)
// ※コピー&ペーストしやすくするために最後の項目にもカンマを付与しています。
//=============================================================================
var footStepJson = {
// walk1:歩行時の効果音1
// walk2:歩行時の効果音2
// dash1:ダッシュ時の効果音1
// dash2:ダッシュ時の効果音2
// interval:効果音を演奏する間隔(1の場合は1歩ごと)
// 常に演奏される足音
always : {
interval: 1,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
dash1 : {name: '', volume: 90, pitch: 100, pan: 0},
dash2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// 梯子属性通過時の足音
ladder : {
interval: 1,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
dash1 : {name: '', volume: 90, pitch: 100, pan: 0},
dash2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// カウンター属性通過時の足音
counter : {
interval: 1,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
dash1 : {name: '', volume: 90, pitch: 100, pan: 0},
dash2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// 茂み属性通過時の足音
bush : {
interval: 1,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
dash1 : {name: '', volume: 90, pitch: 100, pan: 0},
dash2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// ダメージ床属性通過時の足音
damageFloor: {
interval: 1,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
dash1 : {name: '', volume: 90, pitch: 100, pan: 0},
dash2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// 小型船乗船時の足音
boat : {
interval: 4,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// 大型船乗船時の足音
ship : {
interval: 4,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// 飛行船船乗船時の足音
airship : {
interval: 4,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// 地形タグ 1 通過時の足音(2以降はコピーするか以下の通り値を変更してください)
// terrainTag1 → terrainTag2
terrainTag1: {
interval: 1,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
dash1 : {name: '', volume: 90, pitch: 100, pan: 0},
dash2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
// リージョン 1 通過時の足音(2以降はコピーするか以下の通り値を変更してください)
// region1 → region2
region1 : {
interval: 1,
walk1 : {name: '', volume: 90, pitch: 100, pan: 0},
walk2 : {name: '', volume: 90, pitch: 100, pan: 0},
dash1 : {name: '', volume: 90, pitch: 100, pan: 0},
dash2 : {name: '', volume: 90, pitch: 100, pan: 0},
},
};
//=============================================================================
// ユーザ書き換え領域 - 終了 -
//=============================================================================
/**
* Create plugin parameter. param[paramName] ex. param.commandPrefix
* @param pluginName plugin name(EncounterSwitchConditions)
* @returns {Object} Created parameter
*/
var createPluginParameter = function(pluginName) {
var paramReplacer = function(key, value) {
if (value === 'null') {
return value;
}
if (value[0] === '"' && value[value.length - 1] === '"') {
return value;
}
try {
return JSON.parse(value);
} catch (e) {
return value;
}
};
var parameter = JSON.parse(JSON.stringify(PluginManager.parameters(pluginName), paramReplacer));
PluginManager.setParameters(pluginName, parameter);
return parameter;
};
var param = createPluginParameter('FootstepSound');
var getCommandName = function(command) {
return (command || '').toUpperCase();
};
//=============================================================================
// Game_Interpreter
// プラグインコマンドを追加定義します。
//=============================================================================
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.apply(this, arguments);
this.pluginCommandFootstep(command, args);
};
Game_Interpreter.prototype.pluginCommandFootstep = function(command, args) {
switch (getCommandName(command)) {
case 'FS_INVALID_SOUND' :
case '足音無効化':
$gameSystem.footstepDisable = true;
break;
case 'FS_VALID_SOUND':
case '足音有効化':
$gameSystem.footstepDisable = false;
break;
}
};
//=============================================================================
// Game_CharacterBase
// 足音効果音の演奏処理を追加します。
//=============================================================================
var _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.prototype.initMembers = function() {
_Game_CharacterBase_initMembers.apply(this, arguments);
this.setStepSoundFlg(false);
this._stepToggle = null;
this.resetStepCountForSound();
};
Game_CharacterBase.prototype.resetStepCountForSound = function() {
this._stepCountForSound = null;
};
var _Game_CharacterBase_increaseSteps = Game_CharacterBase.prototype.increaseSteps;
Game_CharacterBase.prototype.increaseSteps = function() {
_Game_CharacterBase_increaseSteps.apply(this, arguments);
if (!this.isPlayStepSound() || $gameSystem.footstepDisable ||
($gameMap.isEventRunning() && param.EventRunningInvalid)) return;
var soundsHash = [
{key: 'airship', condition: this.isInAirship.bind(this)},
{key: 'ship', condition: this.isInShip.bind(this)},
{key: 'boat', condition: this.isInBoat.bind(this)},
{key: 'region' + this.regionId(), condition: this.noCondition.bind(this)},
{key: 'damageFloor', condition: this.isOnDamageFloor.bind(this)},
{key: 'bush', condition: this.isOnBush.bind(this)},
{key: 'counter', condition: this.isOnCounter.bind(this)},
{key: 'ladder', condition: this.isOnLadder.bind(this)},
{key: 'terrainTag' + this.terrainTag(), condition: this.noCondition.bind(this)},
{key: 'always', condition: this.noCondition.bind(this)}
];
soundsHash.some(function(data) {
return this.playStepSound(data.key, data.condition);
}.bind(this));
};
Game_CharacterBase.prototype.playStepSound = function(typeKey, condition) {
if (condition() && footStepJson.hasOwnProperty(typeKey)) {
var soundHash = footStepJson[typeKey];
if (this._stepCountForSound++ % soundHash.interval === 0) {
var soundKey = this.isDashing() ? 'dash' : 'walk';
soundKey += this._stepToggle ? '2' : '1';
if (soundHash.hasOwnProperty(soundKey)) {
if (AudioManager.playAdjustSe) {
AudioManager.playAdjustSe(soundHash[soundKey], this);
} else {
AudioManager.playSe(soundHash[soundKey]);
}
}
this._stepToggle = !this._stepToggle;
}
return true;
}
return false;
};
Game_CharacterBase.prototype.noCondition = function() {
return true;
};
Game_CharacterBase.prototype.isOnDamageFloor = function() {
return $gameMap.isDamageFloor(this.x, this.y);
};
Game_CharacterBase.prototype.isOnCounter = function() {
return $gameMap.isCounter(this.x, this.y);
};
Game_CharacterBase.prototype.isInBoat = function() {
return false;
};
Game_CharacterBase.prototype.isInShip = function() {
return false;
};
Game_CharacterBase.prototype.isInAirship = function() {
return false;
};
Game_CharacterBase.prototype.isPlayStepSound = function() {
return this._stepSoundFlg;
};
Game_CharacterBase.prototype.setStepSoundFlg = function(value) {
this._stepSoundFlg = !!value;
};
//=============================================================================
// Game_Player
// キャラクターごとの足音演奏取得
//=============================================================================
Game_Player.prototype.isPlayStepSound = function() {
return !$gameSwitches.value(param.InvalidSwitchId);
};
var _Game_Player_updateNonmoving = Game_Player.prototype.updateNonmoving;
Game_Player.prototype.updateNonmoving = function(wasMoving) {
_Game_Player_updateNonmoving.apply(this, arguments);
if (!wasMoving && param.ResetIfStop) {
this.resetStepCountForSound();
}
};
//=============================================================================
// Game_System
// 足音効果音の有効無効設定を追加定義します。
//=============================================================================
var _Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_Game_System_initialize.apply(this, arguments);
this.footstepDisable = null;
};
})();