-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathGabeMZ_StepSound.js
402 lines (368 loc) · 12.8 KB
/
GabeMZ_StepSound.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
//============================================================================
// Gabe MZ - Step Sound
//----------------------------------------------------------------------------
// 23/10/20 | Version: 1.1.1 | Followers step sound bug fix
// 07/09/20 | Version: 1.1.0 | Included new sound control parameters
// 28/08/20 | Version: 1.0.0 | Released
//----------------------------------------------------------------------------
// This plugin is released under the zlib License.
//============================================================================
/*:
* @target MZ
* @plugindesc [v1.1.1] Allows characters to emit step sounds when walking.
* @author Gabe (Gabriel Nascimento)
* @url https://github.com/comuns-rpgmaker/GabeMZ
*
* @help Gabe MZ - Step Sound
* - This plugin is released under the zlib License.
*
* This plugin allows characters to emit step sounds when walking.
*
* How to Setup a Step Sound:
*
* The first step are set the Step Sound Settings in this plugin
* parameters. The definitions are simple, but pay attention to the
* base name of the SE file and it's variations number. The plugin
* runs the SEs randomly within the maximum number of variations.
* Works as follows:
* | Base Name + Random value within the amount of variations
* Examples:
* | Step Sound Setting:
* | Base Name: Step_Dirt
* | Variance: 4
* | This setting may randomly call the following files:
* | Step_Dirt1
* | Step_Dirt2
* | Step_Dirt3
* | Step_Dirt4
*
* After that, you can add a step sound setting in the tileset
* terrains or in the map regions.
*
* In both cases the definition is made through the same note.
*
* Tileset Note Tag:
* <stepSound terrainId: stepSoundId>
* | This note tag add the specific step sound to the
* | specific terrain.
* Usage Example:
* <stepSound 5: 1>
* | This tag adds the step sound of ID 1 at the tileset
* | terrain 5.
*
* Map Note Tag:
* <stepSound regionId: stepSoundId>
* | This note tag add the specific step sound to the
* | specific map region.
* Usage Example:
* <stepSound 3: 4>
* | This tag adds the step sound of ID 4 at the map
* | region 3.
*
* It is also possible to add step sounds to the events movement. To do
* this add the following note to them:
*
* Event Note Tag:
* <stepSound>
* | Just by inserting this note in an event it will emit step sounds
* | when moving.
*
* Plugin Commands:
* Player Step Sound
* | This command allows to set if the player will emit step sounds
* | or not.
*
* Followers Step Sound
* | This command allows to set if the followers will emit step sounds
* | or not.
*
* Event Step Sound
* | This command allows to set if the event will emit step sounds
* | or not. When the id is 0 it will be applied to the current event.
* | Else, the event of the defined ID.
*
* For support and new plugins join our Discord server:
* https://discord.gg/GG85QRz
*
* @param stepSoundSettings
* @text Step Sound Settings
* @desc Set the Step Sound Setings to use in the game.
* @type struct<stepSoundsStruct>[]
*
* @param playerStepSound
* @text Player Step Sound
* @desc Set if the player will emit steps sounds by default.
* @type boolean
* @default true
*
* @param followersStepSound
* @text Followers Step Sound
* @desc Set if the followers will emit steps sounds by default.
* @type boolean
* @default true
*
* @param walkingFrequency
* @text Walking Frequency
* @desc Set the steps sound frequency when walking.
* @type number
* @default 100
* @min 0
* @max 100
*
* @param dashingFrequency
* @text Dashing Frequency
* @desc Set the steps sound frequency when dashing.
* @type number
* @default 90
* @min 0
* @max 100
*
* @command playerStepSound
* @text Player Step Sound
* @desc Set if the player emit the step sound.
*
* @arg playerStepSound
* @text Player Step Sound
* @desc Set if the player emit the step sound.
* @type boolean
* @default true
*
* @command followersStepSound
* @text Followers Step Sound
* @desc Set if the followers emit the step sound.
*
* @arg followersStepSound
* @text Followers Step Sound
* @desc Set if the followers emit the step sound.
* @type boolean
* @default true
*
* @command eventStepSound
* @text Event Step Sound
* @desc Set if the event emit the step sound.
*
* @arg eventId
* @text Event ID
* @desc Set the event ID. When 0 will be the current event.
* @type number
* @default 0
* @min 0
*
* @arg eventStepSound
* @text Event Step Sound
* @desc Set if the event emit the step sound.
* @type boolean
* @default true
*/
/*~struct~stepSoundsStruct:
* @param baseName
* @text Base Name
* @desc Set the SE base filename
* @type text
*
* @param variance
* @text Files Variance
* @desc Set the SE files variance
* @type number
* @min 1
* @max 100
* @default 1
*
* @param volume
* @text Volume
* @desc Set the SE volume
* @type number
* @min 0
* @max 100
* @default 75
*
* @param volumeVariance
* @text Volume Variance
* @desc Set the SE volume variance
* @type number
* @default 0
* @min -100
* @max 100
*
* @param pitch
* @text Pitch
* @desc Set the SE pitch
* @type number
* @min 50
* @max 150
* @default 100
*
* @param pitchVariance
* @text Pitch Variance
* @desc Set the SE pitch variance
* @type number
* @default 0
* @min -150
* @max 150
*
* @param pan
* @text Pan
* @desc Set the SE pan
* @type number
* @min -100
* @max 100
* @default 0
*
* @param panVariance
* @text Pan Variance
* @desc Set the SE pan variance
* @type number
* @default 0
* @min -100
* @max 100
*/
var Imported = Imported || {};
Imported.GMZ_StepSound = true;
var GabeMZ = GabeMZ || {};
GabeMZ.StepSound = GabeMZ.StepSound || {};
GabeMZ.StepSound.VERSION = [1, 1, 1];
(() => {
const pluginName = "GabeMZ_StepSound";
const params = PluginManager.parameters(pluginName);
GabeMZ.StepSound.stepSoundSettings = JSON.parse(params.stepSoundSettings)
GabeMZ.StepSound.playerStepSound = JSON.parse(params.playerStepSound);
GabeMZ.StepSound.followersStepSound = JSON.parse(params.followersStepSound);
GabeMZ.StepSound.walkingFrequency = JSON.parse(params.walkingFrequency);
GabeMZ.StepSound.dashingFrequency = JSON.parse(params.dashingFrequency);
//-----------------------------------------------------------------------------
// PluginManager
//
// The static class that manages the plugins.
PluginManager.registerCommand(pluginName, "playerStepSound", args => {
$gamePlayer.setStepSoundEmittance(JSON.parse(args.playerStepSound));
});
PluginManager.registerCommand(pluginName, "followersStepSound", args => {
$gamePlayer.followers().setAllStepSoundEmittance(JSON.parse(args.followersStepSound));
});
PluginManager.registerCommand(pluginName, "eventStepSound", args => {
let id = parseInt(args.eventId);
let event = id == 0 ? $gameMap.currentEvent() : $gameMap.event(id)
event.setStepSoundEmittance(JSON.parse(args.eventStepSound));
});
//-----------------------------------------------------------------------------
// Game_CharacterBase
//
// The superclass of Game_Character. It handles basic information, such as
// coordinates and images, shared by all characters.
const _Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.prototype.initMembers = function() {
_Game_CharacterBase_initMembers.call(this);
this._stepSoundEmittance = false;
};
const _Game_CharacterBase_increaseSteps = Game_CharacterBase.prototype.increaseSteps;
Game_CharacterBase.prototype.increaseSteps = function() {
_Game_CharacterBase_increaseSteps.call(this)
const frequency = this.isDashing() ? GabeMZ.StepSound.dashingFrequency : GabeMZ.StepSound.walkingFrequency;
if ((Math.floor(Math.random() * 100)) > frequency) return;
const settings = this.stepSound();
if (this.stepSoundEmittance() && settings && this.isNearTheScreen()) {
let variance = Math.floor(Math.random() * parseInt(settings.variance)) + 1;
let name = parseInt(settings.variance) == 1 ? `${settings.baseName}` : `${settings.baseName + variance}`;
let volume = parseInt(settings.volume) + (Math.floor(Math.random() * parseInt(settings.volumeVariance)));
let pitch = parseInt(settings.pitch) + (Math.floor(Math.random() * parseInt(settings.pitchVariance)));
let pan = parseInt(settings.pan) + (Math.floor(Math.random() * parseInt(settings.panVariance)));
let se = {
name: name,
volume: volume,
pitch: pitch,
pan: pan
}
AudioManager.playSe(se);
}
};
Game_CharacterBase.prototype.stepSound = function() {
return $gameMap.stepSoundRegion(this.regionId()) || $gameMap.stepSoundTerrain(this.terrainTag());
}
Game_CharacterBase.prototype.setStepSoundEmittance = function(stepSoundEmittance) {
this._stepSoundEmittance = stepSoundEmittance;
}
Game_CharacterBase.prototype.stepSoundEmittance = function() {
return this._stepSoundEmittance;
}
//-----------------------------------------------------------------------------
// Game_Player
//
// The game object class for the player. It contains event starting
// determinants and map scrolling functions.
const _Game_Player_initMembers = Game_Player.prototype.initMembers;
Game_Player.prototype.initMembers = function() {
_Game_Player_initMembers.call(this);
this._stepSoundEmittance = GabeMZ.StepSound.playerStepSound;
};
//-----------------------------------------------------------------------------
// Game_Follower
//
// The game object class for a follower. A follower is an allied character,
// other than the front character, displayed in the party.
const _Game_Follower_initMembers = Game_Follower.prototype.initMembers;
Game_Follower.prototype.initMembers = function() {
_Game_Follower_initMembers.call(this);
this._stepSoundEmittance = GabeMZ.StepSound.followersStepSound;
};
const _Game_Follower_refresh = Game_Follower.prototype.refresh;
Game_Follower.prototype.refresh = function() {
_Game_Follower_refresh.call(this);
this._stepSoundEmittance = this.isVisible() && GabeMZ.StepSound.followersStepSound;
};
//-----------------------------------------------------------------------------
// Game_Followers
//
// The wrapper class for a follower array.
Game_Followers.prototype.setAllStepSoundEmittance = function(stepSoundEmittance) {
for (const follower of this._data) {
follower.setStepSoundEmittance(stepSoundEmittance);
}
}
//-----------------------------------------------------------------------------
// Game_Event
//
// The game object class for an event. It contains functionality for event page
// switching and running parallel process events.
const _Game_Event_initialize = Game_Event.prototype.initialize;
Game_Event.prototype.initialize = function(mapId, eventId) {
_Game_Event_initialize.call(this, mapId, eventId);
//
this._stepSoundEmittance = /<stepSound>/.test(this.event().note);
};
//-----------------------------------------------------------------------------
// Game_Map
//
// The game object class for a map. It contains scrolling and passage
// determination functions.
const _Game_Map_initialize = Game_Map.prototype.initialize;
Game_Map.prototype.initialize = function() {
_Game_Map_initialize.call(this);
this._stepSoundTerrains = {};
this._stepSoundRegions = {};
};
const _Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
_Game_Map_setup.call(this, mapId);
this._stepSoundRegions = this.setMapStepSoundSettings($dataMap.note)
this._stepSoundTerrains = this.setMapStepSoundSettings($dataTilesets[this._tilesetId].note)
};
Game_Map.prototype.setMapStepSoundSettings = function(note) {
let result = {}
let reg = /<stepSound\s*(\d+):\s*(\d+)>/g;
let match;
while (match = reg.exec(note)) {
let setting = JSON.parse(GabeMZ.StepSound.stepSoundSettings[parseInt(match[2] - 1)]);
result[match[1]] = setting;
}
return result;
}
Game_Map.prototype.stepSoundRegion = function(id) {
return this._stepSoundRegions[id];
}
Game_Map.prototype.stepSoundTerrain = function(id) {
return this._stepSoundTerrains[id];
}
Game_Map.prototype.currentEvent = function() {
return this.event(this._interpreter.eventId());
};
})();