forked from Trivel/RMMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrTS_SimpleSkillLeveling.js
144 lines (136 loc) · 4.92 KB
/
MrTS_SimpleSkillLeveling.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
//=============================================================================
// MrTS_SimpleSkillLeveling.js
//=============================================================================
/*:
* @plugindesc Skills change to stronger version of themselves after X uses.
* @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
* --------------------------------------------------------------------------------
**
* --------------------------------------------------------------------------------
* Skill Tags
* --------------------------------------------------------------------------------
* To make skill change after some uses, use the following tag:
* <LevelUpTo: [ID], [USES], [REMOVE]>
*
* Will make skill require a specific other existing skill that was used.
* <LevelUpRequire: [ID], [USES], [REMOVE]>
*
* [ID] - Skill ID to change to
* [USES] - After how many uses change into that skill
* [REMOVE] - 0 - keep skill after leveling up, 1 - remove skill after leveling up
* (Remove is optional, by default it'll remove)
*
* Examples:
* <LevelUpTo: 5, 25, 0>
* <LevelUpTo: 8, 10>
*
* <LevelUpTo: 5, 20, 0>
* <LevelUpRequire: 7, 5>
* <LevelUpRequire: 8, 9>
*
* <LevelUpTo: 7, 20>
* <LevelUpRequire: 8, 10, 0>
*
* <LevelUpTo: 8, 10>
* <LevelUpRequire: 7, 20>
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.1 - Added multiple skill requirement for level up.
* - Added ability to keep skills after they leveled up.
* - Fixed a bug where it'd count as multiple uses for multiple target skill.
* 1.0 - Release
*/
(function() {
var _GameActor_initMembers = Game_Actor.prototype.initMembers;
Game_Actor.prototype.initMembers = function() {
_GameActor_initMembers.call(this);
Game_Battler.prototype.initMembers.call(this);
this._skillUsedTimes = {};
this._levelingSkillNeeds = [];
};
var _GameActor_learnSkill = Game_Actor.prototype.learnSkill;
Game_Actor.prototype.learnSkill = function(skillId) {
if (!this.isLearnedSkill(skillId) && $dataSkills[skillId].meta.LevelUpTo)
{
this.grabSkillLevelingData(skillId);
this._skillUsedTimes[skillId] = 0;
}
_GameActor_learnSkill.call(this, skillId);
};
Game_Actor.prototype.grabSkillLevelingData = function(skillId) {
var lines = $dataSkills[skillId].note.split(/[\r\n]/);
var skillLearnObj = {result: 0, required: [], completed: false};
var regex1 = /<LevelUpTo:[ ]*(\d+),[ ]*(\d+),?[ ]?(\d+)?>/i;
var regex2 = /<LevelUpRequire:[ ]*(\d+),[ ]*(\d+),?[ ]?(\d+)?>/i;
for (var i = 0; i < lines.length; i++) {
var regex1Match = regex1.exec(lines[i]);
if (regex1Match)
{
var goal = Number(regex1Match[1]);
var reqId = skillId;
var uses = Number(regex1Match[2]);
var remove = regex1Match[3] ? regex1Match[3] === "1" : true;
skillLearnObj.result = goal;
skillLearnObj.required.push({id: reqId, uses: uses, remove: remove});
continue;
}
var regex2Match = regex2.exec(lines[i]);
if (regex2Match)
{
var reqId = Number(regex2Match[1]);
var uses = Number(regex2Match[2]);
var remove = regex2Match[3] ? regex2Match[3] === "1" : true;
skillLearnObj.required.push({id: reqId, uses: uses, remove: remove});
continue;
}
}
this._levelingSkillNeeds.push(skillLearnObj);
};
Game_Actor.prototype.checkSkillLevelUps = function() {
for (var i = 0; i < this._levelingSkillNeeds.length; i++) {
var skill = this._levelingSkillNeeds[i];
if (skill.completed) continue;
var allDone = true;
for (var j = 0; j < skill.required.length; j++) {
var req = skill.required[j];
if (!this._skillUsedTimes[req.id]) allDone = false;
if (this._skillUsedTimes[req.id] < req.uses) allDone = false;
if (!allDone) break;
}
if (allDone)
{
this.learnSkill(skill.result);
this._levelingSkillNeeds[i].completed = true;
for (var j = 0; j < skill.required.length; j++) {
if(skill.required[j].remove) this.forgetSkill(skill.required[j].id);
}
}
}
};
Game_Actor.prototype.increaseSkillUsage = function(skill) {
if (!this._skillUsedTimes[skill.id]) this._skillUsedTimes[skill.id] = 0;
this._skillUsedTimes[skill.id]++;
this.checkSkillLevelUps();
};
var _Game_Actor_useItem = Game_Actor.prototype.useItem;
Game_Actor.prototype.useItem = function(item) {
_Game_Actor_useItem.call(this, item);
if (DataManager.isSkill(item))
{
this.increaseSkillUsage(item);
}
};
})();