forked from Trivel/RMMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrTS_SkillTimeReaction.js
258 lines (245 loc) · 9.24 KB
/
MrTS_SkillTimeReaction.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
//=============================================================================
// MrTS_SkillTimeReaction.js
//=============================================================================
/*:
* @plugindesc After using certain skills, there's a small window where
* you can react to it. Doing so, improves skill in some way.
* @author Mr. Trivel
*
*
* @param Default Reaction Appearance
* @desc How long it takes for reaction window to appear? From To in frames.
* Default: 20 60
* @default 20 60
*
* @param Default Reaction Time
* @desc How long the reaction window lasts? From To in frames.
* Default: 60 150
* @default 60 150
*
* @param Default State
* @desc If reaction succeeds which state to apply for the duration of attack?
* Default: 11
* @default 11
*
* @param Success SFX
* @desc Which SFX to play on success?
* Default: Skill2
* @default Skill2
*
* @param Fail SFX
* @desc Which SFX to play on failure?
* Default: Splash
* @default Splash
*
* @help
* --------------------------------------------------------------------------------
* Terms of Use
* --------------------------------------------------------------------------------
* Don't remove the header or claim that you wrote this plugin.
* Credit Mr. Trivel if using this plugin in your project.
* Free for commercial and non-commercial projects.
* --------------------------------------------------------------------------------
* Commissioned by Fisherolol
* --------------------------------------------------------------------------------
* Version 1.2
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* --------------------------------------------------------------------------------
* REQUIRES:
* Yanfly's Battle Engine Core
* --------------------------------------------------------------------------------
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Skill Tags
* --------------------------------------------------------------------------------
* Skill tags are placed in Skill Note fields.
*
* When a skill has <Reaction> tag in it, it will display an image for a random
* amount of time in which player can
* <Reaction>
* <ReactionAppear: [FROM] [TO]>
* <ReactionWindow: [FROM] [TO]>
* <ReactionState: [STATE ID]>
* [FROM] [TO] - How long the window lasts or appears. It'll pick a random number
* of frames between [FROM] and [TO] ([FROM] <= time < [TO]).
* [STATE ID] - Which state to apply when hitting the button in react window.
*
* Only <Reaction> tag is a must to have the reaction window. Other tags like
* <ReactionAppear: [FROM] [TO]>, <ReactionWindow: [FROM] [TO]> or \
* <ReactionState: [STATE ID]> can be omitted to use default values from parameters.
*
* Examples:
* <Reaction>
* <ReactionWindow: 50 100>
* <ReactionState: 15>
*
* <Reaction>
* <ReactionState: 50>
* <ReactionAppear: 40 100>
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Image Files
* --------------------------------------------------------------------------------
* This plugin displays an image to click.
* Images go to img\system.
*
* Image list:
* img\system\reactionWait.png
* img\system\reactionHit.png
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.2 - Fixed success and failure sound play overlap.
* 1.1 - SFX on success/failure. Fixed hit image not appearing when using default
* values.
* 1.0 - Release
*/
(function() {
var parameters = PluginManager.parameters('MrTS_SkillTimeReaction');
var paramDefaultReactAppear = String(parameters['Default Reaction Appearance'] || "20 60");
var paramDefaultReactWindow = String(parameters['Default Reaction Time'] || "60 150");
var paramDefaultStateId = Number(parameters['Default State'] || 11);
var paramSuccessSfx = String(parameters['Success SFX'] || "Skill2");
var paramFailSfx = String(parameters['Fail SFX'] || "Splash");
var _SceneBattle_createDisplayObjects = Scene_Battle.prototype.createDisplayObjects;
Scene_Battle.prototype.createDisplayObjects = function() {
_SceneBattle_createDisplayObjects.call(this);
this.createReactionVariables();
};
Scene_Battle.prototype.createReactionVariables = function() {
this._successSfx = AudioManager.makeEmptyAudioObject();
this._failSfx = AudioManager.makeEmptyAudioObject();
this._successSfx.name = paramSuccessSfx;
this._failSfx.name = paramFailSfx;
this._successSfx.volume = 90;
this._successSfx.pitch = 100;
this._failSfx.volume = 90;
this._failSfx.pitch = 100;
AudioManager.loadStaticSe(this._successSfx);
AudioManager.loadStaticSe(this._failSfx);
this._reactionAppearTimer = 0;
this._reactionWindowTimer = 0;
this._reactionState = 0;
this._reactionStatus = 'appear';
this._reactionSpriteSet = false;
this._reactWaitSpriteBitmap = ImageManager.loadSystem("reactionWait");
this._reactHitSpriteBitmap = ImageManager.loadSystem("reactionHit");
this._reactSprite = new Sprite(this._reactWaitSpriteBitmap);
this._reactSprite.visible = false;
this._spriteset.addChild(this._reactSprite);
};
Scene_Battle.prototype.appearReaction = function(item) {
var appearTimer = paramDefaultReactAppear;
if (appearTimer[0] === ' ') appearTimer = appearTimer.substr(1);
appearTimer = appearTimer.split(' ');
appearTimer = Math.randomInt(Number(appearTimer[1]) - Number(appearTimer[0])) + Number(appearTimer[0]);
var windowTimer = paramDefaultReactWindow;
if (windowTimer[0] === ' ') windowTimer = windowTimer.substr(1);
windowTimer = windowTimer.split(' ');
windowTimer = Math.randomInt(Number(windowTimer[1]) - Number(windowTimer[0])) + Number(windowTimer[0]);
var state = paramDefaultStateId;
if (item.meta.ReactionWindow)
{
var timer = item.meta.ReactionWindow;
if (timer[0] === ' ') timer = timer.substr(1);
timer = timer.split(' ');
windowTimer = Math.randomInt(Number(timer[1]) - Number(timer[0])) + Number(timer[0]);
}
if (item.meta.ReactionAppear)
{
var timer = item.meta.ReactionAppear;
if (timer[0] === ' ') timer = timer.substr(1);
timer = timer.split(' ');
appearTimer = Math.randomInt(Number(timer[1]) - Number(timer[0])) + Number(timer[0]);
}
if (item.meta.ReactionState)
{
state = Number(item.meta.ReactionState);
}
this._reactionAppearTimer = appearTimer;
this._reactionWindowTimer = windowTimer;
this._reactionState = state;
this._reactionStatus = 'appear';
};
var _SceneBattle_update = Scene_Battle.prototype.update;
Scene_Battle.prototype.update = function() {
_SceneBattle_update.call(this);
if (this._reactSprite.visible)
{
if (!this._reactSpriteSet && this._reactSprite.bitmap.isReady()) {
this._reactSprite.x = Graphics.boxWidth/2 - this._reactSprite.width/2;
this._reactSprite.y = Graphics.boxHeight/2 - this._reactSprite.height/2;
this._reactSpriteSet = true;
}
if (this._reactionStatus === 'appear')
{
if (Input.isTriggered('ok') || TouchInput.isTriggered())
{
this._reactionAppearTimer = 999;
this._reactionWindowTimer = 0;
this._reactionStatus = 'off';
this._reactSprite.visible = false;
this._reactSprite.bitmap = this._reactWaitSpriteBitmap;
AudioManager.playStaticSe(this._failSfx);
}
this._reactionAppearTimer -= 1;
if (this._reactionAppearTimer <= 0) {
this._reactionStatus = 'window';
this._reactSprite.bitmap = this._reactHitSpriteBitmap;
}
}
if (this._reactionStatus === 'window')
{
var played = false;
if (Input.isTriggered('ok') || TouchInput.isTriggered())
{
this._reactionWindowTimer = 0;
var actor = BattleManager._subject;
actor.addState(this._reactionState);
actor._reactionStateId = this._reactionState;
AudioManager.playStaticSe(this._successSfx);
played = true;
}
this._reactionWindowTimer -= 1;
if (this._reactionWindowTimer <= 0) {
this._reactionStatus = 'off';
this._reactSprite.visible = false;
this._reactSprite.bitmap = this._reactWaitSpriteBitmap;
if (!played) AudioManager.playStaticSe(this._failSfx);
}
}
}
};
var _SceneBattle_isAnyInputWindowActive = Scene_Battle.prototype.isAnyInputWindowActive;
Scene_Battle.prototype.isAnyInputWindowActive = function() {
var active = _SceneBattle_isAnyInputWindowActive.call(this);
return active || this._reactSprite.visible;
};
var _GameActor_useItem = Game_Actor.prototype.useItem;
Game_Actor.prototype.useItem = function(item) {
if (item.meta.Reaction)
{
if (SceneManager._scene.constructor === Scene_Battle)
{
SceneManager._scene.appearReaction(item);
SceneManager._scene._reactSprite.visible = true;
}
}
_GameActor_useItem.call(this, item);
};
var _Battlemanager_endAction = BattleManager.endAction;
BattleManager.endAction = function() {
if (this._subject._reactionStateId > 0)
{
this._subject.removeState(this._subject._reactionStateId);
this._subject.reactionStateId = 0;
}
_Battlemanager_endAction.call(this);
};
})();