forked from Trivel/RMMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrTS_GainStatsOnLevelUp.js
167 lines (153 loc) · 4.43 KB
/
MrTS_GainStatsOnLevelUp.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
//=============================================================================
// MrTS_GainStatsOnLevelUp.js
//=============================================================================
/*:
* @plugindesc Actors gain stats on level up.
* @author Mr. Trivel
*
* @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.
* --------------------------------------------------------------------------------
* Version 1.1
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Class Tags
* --------------------------------------------------------------------------------
* <STAT>
* formula
* </STAT>
*
* Stats:
* MHP, MMP, ATK, DEF, MAT, MDF, AGI, LUK
*
* v = variables
* a = actor
*
* Examples:
* <ATK>
* v[10];
* </ATK>
* <DEF>
* Math.randomInt(5);
* </DEF>
* <LUK>
* -1
* </LUK>
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.1 - Crash fix with multi line stat evaluations.
* 1.0 - Release
*/
(function() {
var _GameActor_setup = Game_Actor.prototype.setup;
Game_Actor.prototype.setup = function(actorId) {
_GameActor_setup.call(this, actorId);
this._classExtraParam = [];
this._classExtraParamLevels = [];
this._classExtraParamLevels[this._classId] = this._level;
};
var _GameActor_levelUp = Game_Actor.prototype.levelUp;
Game_Actor.prototype.levelUp = function() {
_GameActor_levelUp.call(this);
this.addClassExtraParams();
};
var _GameActor_paramPlus = Game_Actor.prototype.paramPlus;
Game_Actor.prototype.paramPlus = function(paramId) {
var value = _GameActor_paramPlus.call(this, paramId);
if (this._classExtraParam && this._classExtraParam[this._classId] && this._classExtraParam[this._classId][paramId])
value += this._classExtraParam[this._classId][paramId];
return value;
};
var _GameActor_changeClass = Game_Actor.prototype.changeClass;
Game_Actor.prototype.changeClass = function(classId, keepExp) {
_GameActor_changeClass.call(this, classId, keepExp);
this.addClassExtraParams();
};
Game_Actor.prototype.addClassExtraParams = function() {
if (!this._classExtraParamLevels[this._classId])
this._classExtraParamLevels[this._classId] = this.actor().initialLevel;
var difference = this._level - this._classExtraParamLevels[this._classId];
var note = this.currentClass().note.split(/[\r\n]/);
var statStarted = null
var code = "";
var regexStart = /<(MHP|MMP|ATK|DEF|MAT|MDF|AGI|LUK)>/i;
var regexEnd = /<(\/MHP|\/MMP|\/ATK|\/DEF|\/MAT|\/MDF|\/AGI|\/LUK)>/i;
var paramCode = [];
for (var i = 0; i < note.length; i++) {
var regexStartMatch = regexStart.exec(note[i]);
if (regexStartMatch)
{
statStarted = regexStartMatch[1].toLowerCase();
continue;
}
var regexEndMatch = regexEnd.exec(note[i]);
if (regexEndMatch)
{
switch(statStarted)
{
case 'mhp':
{
paramCode[0] = code;
} break;
case 'mmp':
{
paramCode[1] = code;
} break;
case 'atk':
{
paramCode[2] = code;
} break;
case 'def':
{
paramCode[3] = code;
} break;
case 'mat':
{
paramCode[4] = code;
} break;
case 'mdf':
{
paramCode[5] = code;
} break;
case 'agi':
{
paramCode[6] = code;
} break;
case 'luk':
{
paramCode[7] = code;
} break;
}
statStarted = null;
code = "";
continue;
}
if (statStarted)
{
code += " " + note[i];
continue;
}
} // for
for (var i = 0; i < difference; i++) {
for (var j = 0; j < 8; j++) {
if (!paramCode[j]) continue;
var v = $gameVariables._data;
var a = this;
var increase = eval(paramCode[j]);
if (!this._classExtraParam[this._classId])
this._classExtraParam[this._classId] = [0, 0, 0, 0, 0, 0, 0, 0];
this._classExtraParam[this._classId][j] += Number(increase);
}
}
this._classExtraParamLevels[this._classId] = this._level;
};
})();