forked from Trivel/RMMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrTS_StealSkill.js
207 lines (189 loc) · 6.26 KB
/
MrTS_StealSkill.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
//==============================================================================
// MrTS_StealSkill.js
//==============================================================================
/*:
* @plugindesc Allows to steal items and skills from enemies.
* @author Mr. Trivel
*
*
* @param Steal Mode
* @desc 1 - try to steal every item, 2 - try to steal 1 item. If
* mode is 2, % of all items has to add up to 1.0 or less.
* @default 1
*
* @param Steal Success Text
* @desc Text shown on successful steal.
* @default %1 stole %2 from %3!
*
* @param Steal Success Text
* @desc Text shown on successful skill steal.
* @default %1 stole skill %2 from %3!
*
* @param Steal Fail Text
* @desc Text shown on failed steal.
* @default %1 failed to steal from %2.
*
* @param Nothing Left Text
* @desc Text shown on when there's no more items to steal.
* @default %1 doesn't have anything left!
*
* @help Version 1.2
* Free for non-commercial use only.
*
* ## Modes
* Mode 1 - Attempts to steal every item at once,
* So if enemy has 3 available items to steal, player has a chance
* to steal them all.
*
* Mode 2 - Attemps to steal only 1 item.
* So if enemy has 3 available items to steal, player has a chance
* to steal only 1 of them.
* E.g. Potion 30%, Sword 20%, Doom Skill 1%.
* Player will have 30% chance to get potion, 20% to get sword
* and 1% to get Doom Skill.
*
* ## Note Fields
*
* Skill note fields:
* <steal> - Add this to a skill that allows to steal.
*
* Enemy note fields:
* <steal: X, Y, Z, K, L>
* X - item type: w - weapon, a - armour, i - item, s - skill
* Y - item/skill ID
* Z - steal chance. 0.00 - 0% , 0.33 - 33%, 1.00 - 100%
* K - item amount (Use 1 for skill)
* L - number of times steal can success on the enemy
*/
(function() {
var parameters = PluginManager.parameters('MrTS_StealSkill');
var stealMode = Number(parameters['Steal Mode'] || 1);
var stealSuccessText = String(parameters['Steal Success Text'] || "%1 stole %2 from %3!");
var stealSkillSuccessText = String(parameters['Skill Success Text'] || "%1 stole skill %2 from %3!");
var stealFailText = String(parameters['Steal Fail Text'] || "%1 failed to steal from %2.");
var nothingLeftText = String(parameters['Nothing Left Text'] || "%1 doesn't have anything left!");
var _Game_Enemy_setup = Game_Enemy.prototype.setup;
Game_Enemy.prototype.setup = function(enemyId, x, y) {
_Game_Enemy_setup.call(this, enemyId, x, y);
this.stealableItems = [];
if (this.enemy().meta.steal)
{
var note = this.enemy().note.split(/[\r\n]+/);
for (var i = 0; i < note.length; i++)
{
var regex = /<steal:[ ]*([wais])+,[ ]*(\d+),[ ]*(\d+[.]*\d*),[ ]*(\d+)[, ]*(\d+)>/i;
var match = regex.exec(note[i]);
if (!match) continue;
this.stealableItems.push(match);
}
}
};
_Game_ActionResult_clear = Game_ActionResult.prototype.clear;
Game_ActionResult.prototype.clear = function() {
_Game_ActionResult_clear.call(this);
this.stolenItems = [];
this.stolenSkills = [];
this.noItemsToSteal = true;
this.failedSteal = false;
this.stealAttempt = false;
};
_Game_Action_apply = Game_Action.prototype.apply;
Game_Action.prototype.apply = function(target) {
_Game_Action_apply.call(this, target);
var result = target.result();
if (result.isHit() && this.item().meta.steal) {
var stolenItems = this.stealSuccess(target, this.subject());
result.stealAttempt = true;
if ( stolenItems.length > 0)
{
result.stolenItems = stolenItems;
}
else
{
result.failedSteal = true;
}
this.makeSuccess(target);
}
};
Game_Action.prototype.stealSuccess = function(target, subject){
var success = [];
var modeRand = 0;
var modeRandSum = 0;
if (stealMode == 2) modeRand = Math.random();
if (target.stealableItems.length > 0)
{
for (var i = 0; i < target.stealableItems.length; i++)
{
if (stealMode == 2 && success.length > 0) break;
var stealData = target.stealableItems[i];
var stealSucceeded = false;
if (stealMode == 1)
{
if (Math.random() <= Number(stealData[3]) && Number(stealData[5]) > 0)
stealSucceeded = true;
}
else if (stealMode == 2)
{
modeRandSum += Number(stealData[3]);
if (modeRand <= modeRandSum)
if (Number(stealData[5]) > 0)
stealSucceeded = true;
else
break;
}
if (stealSucceeded)
{
target.stealableItems[i][5] = Number(target.stealableItems[i][5])-1;
switch(stealData[1].toLowerCase()){
case "a":
var item = $dataArmors[Number(stealData[2])];
$gameParty.gainItem(item, Number(stealData[4]));
success.push(item);
break;
case "w":
var item = $dataWeapons[Number(stealData[2])];
$gameParty.gainItem(item, Number(stealData[4]));
success.push(item);
break;
case "i":
var item = $dataItems[Number(stealData[2])];
$gameParty.gainItem(item, Number(stealData[4]));
success.push(item);
break;
case "s":
var skill = $dataSkills[Number(stealData[2])];
subject.learnSkill(skill.id);
success.push(skill);
break;
} // switch
} // if
} // for
for (var i = 0; i < target.stealableItems.length; i++)
{
if (Number(target.stealableItems[i][5]) > 0) target.result().noItemsToSteal = false;
}
} // if
return success;
};
_Window_BattleLog_displayActionResults = Window_BattleLog.prototype.displayActionResults;
Window_BattleLog.prototype.displayActionResults = function(subject, target) {
_Window_BattleLog_displayActionResults.call(this, subject, target);
if (target.result().used) {
if (target.result().stolenItems.length > 0)
{
var stolenItems = target.result().stolenItems;
for (var i = 0; i < stolenItems.length; i++)
{
if (!DataManager.isSkill(stolenItems[i]))
this.push('addText', stealSuccessText.format(subject.name(), stolenItems[i].name, target.name()));
else
this.push('addText', stealSkillSuccessText.format(subject.name(), stolenItems[i].name, target.name()));
}
}
if (target.result().noItemsToSteal && target.result().stealAttempt)
this.push('addText', nothingLeftText.format(target.name()));
else if (target.result().failedSteal)
this.push('addText', stealFailText.format(subject.name(), target.name()));
}
};
})();