-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathAkeaBattleCry.js
279 lines (258 loc) · 8.53 KB
/
AkeaBattleCry.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
//==========================================================================
// Akea - Battle Cry
//----------------------------------------------------------------------------
// 19/09/20 | Version: 1.0.0
// This software is released under the zlib License.
//============================================================================
/*:
* @target MZ
* @plugindesc Add voices to actors on battle.
* @author Gabe (Gabriel Nascimento)
* @url http://patreon.com/gabriel_nfd
* @base AkeaAnimatedBattleSystem
* @orderAfter AkeaAnimatedBattleSystem
*
* @help Akea - Battle Cry
* - This plugin is released under the zlib License.
*
* This plugin add voices to actors on battle.
*
* How to setup a Battle Cry:
*
* The first step are set the Actor Settings (and Enemy Settings for the
* enemies) 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:
* | Actor Name + _ + Base Name + Random value
* Examples:
* | Battle Cry Setting:
* | Actor: Reid (01)
* | Base Name: Start
* | Variance: 4
* | This setting may randomly call the following files:
* | Reid_Start1
* | Reid_Start2
* | Reid_Start3
* | Reid_Start4
*
* By default, each actor has four settings:
* | Start:
* | Played at the beginning of the battle.
*
* | Turn:
* | Played at the beginning of the actor turn.
*
* | Death:
* | Played when the actor dies.
*
* | Win:
* | Played when the battle is won.
*
* And it is possible to add as many more settings as desired using the
* Custom parameter. All of these settings can be called up in the skills
* through your grade, acting in conjunction with the Akea Animated Battle
* System.
*
* Skill Notes Tag:
* <akeaBattleCry>
* action: battleCryName
* </akeaBattleCry>
* | Plays the battle cry of the specified name
* | action: the battle cry name.
*
* Usage Examples:
* <akeaBattleCry>
* action: CastFire
* </akeaBattleCry>
* | Plays a random file within the battle cry settings
* | named CastFire.
*
* For support and new plugins join our Discord server:
* https://discord.gg/GG85QRz
*
* @param actorSettings
* @text Actor Settings
* @desc Actors voice files settings.
* @type struct<defaultSettingsActor>[]
*
* @param enemySettings
* @text Enemy Settings
* @desc Enemies voice files settings.
* @type struct<defaultSettingsEnemy>[]
*
*/
/*~struct~defaultSettingsActor:
* @param info
* @text Info
* @desc A info to distinct this field.
* @type text
*
* @param actor
* @text Actor
* @desc The actor ID.
* @type actor
* @default 1
*
* @param start
* @text Start
* @desc Played at the beginning of the battle.
* @type number
* @default 1
*
* @param turn
* @text Turn
* @desc Played at the beginning of the actor turn.
* @type number
* @default 1
*
* @param death
* @text Death
* @desc Played when the actor dies.
* @type number
* @default 1
*
* @param win
* @text Win
* @desc Played when the battle is won.
* @type number
* @default 1
*
* @param custom
* @text Custom
* @type struct<customSettingsActor>[]
*
*/
/*~struct~defaultSettingsEnemy:
* @param info
* @text Info
* @desc A info to distinct this field.
* @type text
*
* @param enemy
* @text Enemy
* @desc The enemy ID.
* @type enemy
* @default 1
*
* @param custom
* @text Custom
* @desc Custom configuration that can be called up through the skill note.
* @type struct<customSettingsActor>[]
*
*/
/*~struct~customSettingsActor:
* @param name
* @text Name
* @desc The custom battle cry name.
* @type text
*
* @param variation
* @text Variation
* @desc The custom battle cry variations.
* @type number
* @default 1
* @min 1
*/
var Akea = Akea || {};
Akea.BattleCry = Akea.BattleCry || {};
Akea.BattleCry.VERSION = [1, 0, 0];
if (!Akea.BattleSystem) throw new Error("Akea Battle Cry plugin needs the Akea Animated Battle System base.");
if (Akea.BattleSystem.VERSION < [1, 1, 0]) throw new Error("Akea Battle Cry plugin only works with versions 1.1.0 or higher of the Akea Animated Battle System.");
(() => {
const pluginName = "AkeaBattleCry";
Akea.params = PluginManager.parameters(pluginName);
Akea.BattleCry.actorSettings = JSON.parse(Akea.params.actorSettings);
Akea.BattleCry.enemySettings = JSON.parse(Akea.params.enemySettings);
//-----------------------------------------------------------------------------
// BattleManager
//
// The static class that manages battle progress.
const _BattleManager_startBattle = BattleManager.startBattle;
BattleManager.startBattle = function() {
_BattleManager_startBattle.call(this);
this.playBattleCry(this.randomAliveMember(), "Start");
};
const _BattleManager_startActorInput = BattleManager.startActorInput;
BattleManager.startActorInput = function() {
_BattleManager_startActorInput.call(this);
this.playBattleCry(this._currentActor, "Turn");
};
const _BattleManager_processVictory = BattleManager.processVictory;
BattleManager.processVictory = function() {
this.playBattleCry(this.randomAliveMember(), "Start");
_BattleManager_processVictory.call(this);
};
BattleManager.playBattleCry = function(actor, actionName) {
let variation = 0;
let settings = 0;
if (actor instanceof Game_Actor) {
settings = Akea.BattleCry.actorSettings.find(settings => JSON.parse(settings).actor == actor.actorId());
if (settings) settings = JSON.parse(settings);
} else if (actor instanceof Game_Enemy) {
settings = Akea.BattleCry.enemySettings.find(settings => JSON.parse(settings).enemy == actor.enemyId());
if (settings) settings = JSON.parse(settings);
}
if (!settings) return;
if (settings.custom) {
const custom = JSON.parse(settings.custom).find(action => JSON.parse(action).name == actionName);
if (custom) variation = parseInt(JSON.parse(custom).variation);
}
if (!variation) variation = parseInt(settings[actionName.toLowerCase()]);
if (!variation) return;
const v = Math.floor(Math.random() * variation) + 1;
const name = `${actor.name()}_${actionName}${v}`;
const se = {
name: name,
volume: 100,
pitch: 100,
pan: 0
}
AudioManager.playSe(se);
}
BattleManager.randomAliveMember = function() {
const id = Math.floor(Math.random() * $gameParty.aliveMembers().length);
const actor = $gameParty.aliveMembers()[id];
return actor;
}
//-----------------------------------------------------------------------------
// Game_Battler
//
// The superclass of Game_Actor and Game_Enemy. It contains methods for sprites
// and actions.
const _Game_Battler_addState = Game_Battler.prototype.addState;
Game_Battler.prototype.addState = function(stateId) {
_Game_Battler_addState.call(this, stateId);
if (stateId == this.deathStateId()) BattleManager.playBattleCry(this, "Death");
};
const _Game_Battler_callAkeaActions = Game_Battler.prototype.callAkeaActions;
Game_Battler.prototype.callAkeaActions = function (actionName, parameters, action, targets) {
_Game_Battler_callAkeaActions.call(this, actionName, parameters, action, targets)
let regex = /(\w+):\s*([^\s]*)/gm;
let id = {};
do {
param = regex.exec(parameters);
if (param) {
id[RegExp.$1] = RegExp.$2;
}
} while (param);
switch (actionName) {
case "BattleCry":
this._akeaAnimatedBSActions.addCustomAddon(id, targets, actionName, this, action);
break;
}
}
//-----------------------------------------------------------------------------
// Sprite_Battler
//
// The superclass of Sprite_Actor and Sprite_Enemy.
const _Sprite_Battler_manageAkeaActions = Sprite_Battler.prototype.manageAkeaActions;
Sprite_Battler.prototype.manageAkeaActions = function (action) {
_Sprite_Battler_manageAkeaActions.call(this, action);
switch (action.getActionType()) {
case "BattleCry":
BattleManager.playBattleCry(action.getSubject(), action.getId().action);
break;
}
}
})();