-
Notifications
You must be signed in to change notification settings - Fork 5
/
Kru_SkillToggle.js
323 lines (284 loc) · 10.2 KB
/
Kru_SkillToggle.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
//=============================================================================
// Skill Toggle
// Version: 1.0.0
//=============================================================================
/*:
* @plugindesc Creates passive skills that can be toggled on/off.
*
* @author Krusynth
*
* @help
* ============================================================================
* Information
* ============================================================================
*
* Creates passive skills that can be toggled on/off.
*
* Terms & Conditions
* This plugin is free for non-commercial and commercial use.
*/
/*
* TODO
* - Refresh reserve after adding points to skills.
*/
var Imported = Imported || {};
Imported.Kru_SkillToggle = "1.0.0";
var Kru = Kru || {};
Kru.STog = {};
if(!Imported.Kru_Core) {
alert("Kru_SkillToggle requires Kru_Core.");
throw new Error("Kru_SkillToggle requires Kru_Core.");
}
if(!Imported.Kru_SkillCore) {
alert("Kru_SkillToggle requires Kru_SkillCore.");
throw new Error("Kru_SkillToggle requires Kru_SkillCore.");
}
Kru.STog.Window_SkillList_drawItem = Window_SkillList.prototype.drawItem;
Window_SkillList.prototype.drawItem = function(index) {
var skill = this._data[index];
if (skill) {
var costWidth = this.costWidth();
var rect = this.itemRect(index);
rect.width -= this.textPadding();
this.changePaintOpacity(this.isEnabled(skill));
this.drawItemName(skill, rect.x, rect.y, rect.width - costWidth);
this.drawSkillCost(skill, rect.x, rect.y, rect.width);
this.changePaintOpacity(1);
}
};
Kru.STog.Window_SkillList___drawItemName = Window_SkillList.prototype.drawItemName;
Window_SkillList.prototype.drawItemName = function(item, x, y, width) {
width = width || 312;
if (item) {
var iconBoxWidth = Window_Base._iconWidth + 4;
this.resetTextColor();
if(item.meta && item.meta.type) {
if(item.meta.type == 'toggle') {
if(this._actor._stskills[item.id].toggleState == true) {
this.changeTextColor(this.textColor(23));
}
else {
this.changeTextColor(this.textColor(22));
}
}
}
this.drawIcon(item.iconIndex, x + 2, y + 2);
this.drawText(item.name, x + iconBoxWidth, y, width - iconBoxWidth);
}
};
Kru.STog.setHelpWindowItem = Window_SkillList.prototype.setHelpWindowItem;
Window_SkillList.prototype.setHelpWindowItem = function(item) {
this._helpWindow.contents.clear();
this._helpWindow.setText('');
Kru.STog.setHelpWindowItem.call(this, item);
// If this skill is toggleable we need to show the state in the help.
let msg;
if (this._helpWindow && item) {
if(item.meta && item.meta.type) {
if(item.meta.type == 'toggle') {
if(this._actor._stskills[item.id].toggleState == true) {
msg = '[ACTIVE]';
this._helpWindow.changeTextColor(this.textColor(23));
}
else {
msg = '[INACTIVE]';
this._helpWindow.changeTextColor(this.textColor(22));
}
}
}
if(msg) {
this._helpWindow.drawText(msg, 0, 32, Graphics.boxWidth - this.padding*2, 'right')
}
this.resetTextColor();
}
};
Kru.STog.Window_SkillList___isCurrentItemEnabled = Window_SkillList.prototype.isCurrentItemEnabled;
Window_SkillList.prototype.isCurrentItemEnabled = function() {
let result = Kru.STog.Window_SkillList___isCurrentItemEnabled.call(this);
let item = this.item();
if(!result && item && item.meta && item.meta.type) {
if(item.meta.type == 'toggle') {
result = true;
}
}
return result;
}
// Create method to calculate reserved points.
Kru.STog.Game_Battler___refresh = Game_Battler.prototype.refresh;
Kru.STog.Game_BattlerBase___initialize = Game_BattlerBase.prototype.initialize;
Game_BattlerBase.prototype.initialize = function() {
Kru.STog.Game_BattlerBase___initialize.call(this);
this.resetReserve();
this._stskills = this._stskills || [];
this._mtp = this._mtp || 100;
this._tp = this._tp || 0;
}
Game_BattlerBase.prototype.maxTp = function() {
return this._mtp;
}
Game_Battler.prototype.resetReserve = function() {
this._hpReserved = 0;
this._mpReserved = 0;
this._tpReserved = 0;
}
Game_Battler.prototype.updateReserve = function() {
this.resetReserve();
for(let i = 0; i < this._stskills.length; i++) {
if(this._stskills[i] && $dataSkills[i] && $dataSkills[i].meta &&
$dataSkills[i].meta.type == 'toggle') {
let skillInfo = $dataSkills[i];
let hp = this.skillHpCost($dataSkills[i]);
let mp = this.skillMpCost($dataSkills[i]);
let tp = this.skillTpCost($dataSkills[i]);
if(this._stskills[i].toggleState) {
// We alread paid once, so we don't have to pay again.
// this._hp -= hp;
// this._mp -= mp;
// this._tp -= tp;
this._hpReserved += hp;
this._mpReserved += mp;
this._tpReserved += tp;
}
else {
// We already paid for the skills in the default action, so we double
// the payback here.
this._hp += hp * 2;
this._mp += mp * 2;
this._tp += tp * 2;
}
}
}
}
// Game_Battler.prototype.refresh = function() {
// Kru.STog.Game_Battler___refresh.call(this);
// this.updateReserve();
// }
// Confirm action is handled by the Scene.
Kru.STog.Scene_Skill___useItem = Scene_Skill.prototype.useItem;
Scene_Skill.prototype.useItem = function() {
Kru.STog.Scene_Skill___useItem.call(this);
let item = this.item();
this._actor._stskills[item.id].toggleState = !this._actor._stskills[item.id].toggleState;
for(let i = 0; i < item.effects.length; i++) {
// Toggle state effects.
if(item.effects[i].code === Game_Action.EFFECT_ADD_STATE) {
if(this._actor._stskills[item.id].toggleState) {
this._actor.addState(item.effects[i].dataId);
}
else {
this._actor.removeState(item.effects[i].dataId);
}
}
}
this._actor.clearResult();
this._actor.updateReserve();
this._statusWindow.refresh();
}
// First, we need a *little* more room to draw.
Window_Base.prototype._sWindow = {
leftCol: {width: 120}
}
Kru.STog.Window_Base___drawActorSimpleStatus = Window_Base.prototype.drawActorSimpleStatus;
Window_Base.prototype.drawActorSimpleStatus = function(actor, x, y, width) {
let width1 = this._sWindow.leftCol.width;
let lineHeight = this.lineHeight();
let x2 = x + width1;
let width2 = width - width1 - this.textPadding();
this.drawActorName(actor, x, y);
this.drawActorLevel(actor, x, y + lineHeight * 1);
this.drawActorIcons(actor, x, y + lineHeight * 2);
this.drawActorClass(actor, x2, y, width2);
this.drawActorHp(actor, x2, y + lineHeight * 1, width2);
this.drawActorMp(actor, x2, y + lineHeight * 2, width2);
};
// Move the class all the way to the right.
Kru.STog.Window_Base___drawActorClass = Window_Base.prototype.drawActorClass;
Window_Base.prototype.drawActorClass = function(actor, x, y, width) {
width = width || 168;
this.resetTextColor();
this.drawText(actor.currentClass().name, x, y, width, 'right');
};
// Squeeze our level over to the left.
Kru.STog.Window_Base___drawActorLevel = Window_Base.prototype.drawActorLevel;
Window_Base.prototype.drawActorLevel = function(actor, x, y) {
let width1 = this._sWindow.leftCol.width;
this.changeTextColor(this.systemColor());
this.drawText(TextManager.levelA, x, y, 48);
this.resetTextColor();
this.drawText(actor.level, x + Math.ceil(width1 / 2), y, 36, 'right');
};
// Show our reserved values.
Kru.STog.Window_Base___drawActorHp = Window_Base.prototype.drawActorHp;
Window_Base.prototype.drawActorHp = function(actor, x, y, width) {
width = width || 186;
let color1 = this.hpGaugeColor1();
let color2 = this.hpGaugeColor2();
let gaugeW = width;
let textW = width;
let gaugeR = 0;
let textR = 70;
let mhp = actor.mhp;
if(actor._hpReserved) {
textW = textW - textR;
let percent = actor._hpReserved / actor.mhp;
gaugeR = Math.floor(percent * gaugeW);
gaugeW = gaugeW - gaugeR;
this.drawGauge(x+gaugeW+5, y, gaugeR-5, actor.hpRate(), this.textColor(22), this.textColor(23));
mhp -= actor._hpReserved;
}
this.drawGauge(x, y, gaugeW, actor.hpRate(), color1, color2);
this.changeTextColor(this.systemColor());
this.drawText(TextManager.hpA, x, y, 44);
this.drawCurrentAndMax(actor.hp, mhp, x, y, textW,
this.hpColor(actor), this.normalColor());
this.changeTextColor(this.textColor(23));
if(actor._hpReserved) {
this.drawText('('+actor._hpReserved+')', x+textW+5, y, textR, 'right');
}
this.resetTextColor();
};
Kru.STog.Window_Base___drawActorMp = Window_Base.prototype.drawActorMp;
Window_Base.prototype.drawActorMp = function(actor, x, y, width) {
width = width || 186;
var color1 = this.mpGaugeColor1();
var color2 = this.mpGaugeColor2();
let gaugeW = width;
let textW = width;
let gaugeR = 0;
let textR = 70;
let mmp = actor.mmp;
if(actor.mmp && actor._mpReserved) {
textW = textW - textR;
let percent = actor._mpReserved / actor.mmp;
gaugeR = Math.floor(percent * gaugeW);
gaugeW = gaugeW - gaugeR;
this.drawGauge(x+gaugeW+5, y, gaugeR-5, actor.hpRate(), this.textColor(22), this.textColor(23));
mmp -= actor._mpReserved;
}
this.drawGauge(x, y, gaugeW, actor.mpRate(), color1, color2);
this.changeTextColor(this.systemColor());
this.drawText(TextManager.mpA, x, y, 44);
this.drawCurrentAndMax(actor.mp, mmp, x, y, textW,
this.mpColor(actor), this.normalColor());
this.changeTextColor(this.textColor(23));
if(actor._mpReserved) {
this.drawText('('+actor._mpReserved+')', x+textW+5, y, textR, 'right');
}
this.resetTextColor();
};
Kru.STog.Game_BattlerBase___hpRate = Game_BattlerBase.prototype.hpRate;
Game_BattlerBase.prototype.hpRate = function() {
let reserve = this._hpReserved || 0;
return (this.hp - reserve) / (this.mhp - reserve);
};
Kru.STog.Game_BattlerBase___mpRate = Game_BattlerBase.prototype.mpRate;
Game_BattlerBase.prototype.mpRate = function() {
let reserve = this._mpReserved || 0;
return this.mmp > 0 ? (this.mp - reserve) / (this.mmp - reserve) : 0;
};
/* TODO
Game_BattlerBase.prototype.paySkillCost = function(skill) {
this._mp -= this.skillMpCost(skill);
this._tp -= this.skillTpCost(skill);
};
*/