forked from Trivel/RMMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMrTS_SaveItems.js
302 lines (288 loc) · 8.41 KB
/
MrTS_SaveItems.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
//=============================================================================
// MrTS_SaveItems.js
//=============================================================================
/*:
* @plugindesc Save party items and reclaim them later with plugin calls.
* @author Mr. Trivel
*
* @param Keep Items
* @desc Which items to keep. Write IDs separated by space.
* Default: 1 2
* @default 1 2
*
* @param Keep Weapons
* @desc Which weapons to keep. Write IDs separated by space.
* Default: 3
* @default 3
*
* @param Keep Armors
* @desc Which armors to keep. Write IDs separated by space.
* Default 1 4
* @default 1 4
*
* @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.0
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* About the Plugin
* --------------------------------------------------------------------------------
* Maybe you wanted to have different groups of actors going through story,
* or maybe the party split up for the next encounter and moving on their own.
* And that requires the party to remove currently held items, so another party
* moves on with their story. In that case, this plugin does just that.
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* Save items by using following plugin commands that suits items you have:
* SaveItems All
* SaveItems Items
* SaveItems Armors
* SaveItems Weapons
* SaveItems KeyItems
*
* Reclaim saved items by using the following plugin commands:
* ReclaimItems All
* ReclaimItems Items
* ReclaimItems Armors
* ReclaimItems Weapons
* ReclaimItems KeyItems
*
* Keep some items in your inventory before sending all of them away:
* KeepItems Items [IDs separated by space]
* KeepItems Armors [IDs separated by space]
* KeepItems Weapons [IDs spearated by space]
*
* Example:
* KeepItems Armor 1 2 3 6 7
*
* Clear item to be saved list with the following commands:
* KeepItems Clear All
* KeepItems Clear Items
* KeepItems Clear Armors
* KeepItems Clear Weapons
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.0 - Release
*/
(function() {
var parameters = PluginManager.parameters('MrTS_SaveItems');
var paramKeepItems = (parameters['Keep Items'] || "1 2");
var arrKeepItems = paramKeepItems.split(' ');
var paramKeepWeapons = (parameters['Keep Weapons'] || "3");
var arrKeepWeapons = paramKeepWeapons.split(' ');
var paramKeepArmors = (parameters['Keep Armors'] || "1 4");
var arrKeepArmors = paramKeepArmors.split(' ');
//--------------------------------------------------------------------------
// Game_Interpreter
//
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command.toLowerCase() === "saveitems") {
switch (args[0].toUpperCase())
{
case 'ALL':
{
$gameParty.saveItems('all');
} break;
case 'ITEMS':
{
$gameParty.saveItems('items');
} break;
case 'ARMORS':
{
$gameParty.saveItems('armors');
} break;
case 'WEAPONS':
{
$gameParty.saveItems('weapons');
} break;
case 'KEYITEMS':
{
$gameParty.saveItems('keyItems');
} break;
}
} else if (command.toLowerCase() === "reclaimitems") {
switch (args[0].toUpperCase())
{
case 'ALL':
{
$gameParty.reclaimItems('all');
} break;
case 'ITEMS':
{
$gameParty.reclaimItems('items');
} break;
case 'ARMORS':
{
$gameParty.reclaimItems('armors');
} break;
case 'WEAPONS':
{
$gameParty.reclaimItems('weapons');
} break;
case 'KEYITEMS':
{
$gameParty.reclaimItems('keyItems');
} break;
}
} else if (command.toLowerCase() === "keepitems") {
if (args[0].toLowerCase() === "clear")
{
switch (args[1].toUpperCase())
{
case 'ALL':
{
$gameParty.clearKeptItems('all');
} break;
case 'ITEMS':
{
$gameParty.clearKeptItems('items');
} break;
case 'ARMORS':
{
$gameParty.clearKeptItems('armors');
} break;
case 'WEAPONS':
{
$gameParty.clearKeptItems('weapons');
} break;
}
}
else
{
$gameParty.addKeptItems(args);
}
}
};
//--------------------------------------------------------------------------
// Game_Interpreter
//
var _Game_Party_initialize = Game_Party.prototype.initialize;
Game_Party.prototype.initialize = function() {
_Game_Party_initialize.call(this);
this._savedItems = [];
this._savedKeyItems = [];
this._savedArmor = [];
this._savedWeapons = [];
this._keptItems = [];
this._keptArmor = [];
this._keptWeapons = [];
};
Game_Party.prototype.addKeptItems = function(args) {
var type = args[0].toLowerCase();
switch (type)
{
case 'items':
{
for (var i = 1; i < args.length; i++) {
this._keptItems.push(Number(args[i]));
}
} break;
case 'armors':
{
for (var i = 1; i < args.length; i++) {
this._keptArmor.push(Number(args[i]));
}
} break;
case 'weapons':
{
for (var i = 1; i < args.length; i++) {
this._keptWeapons.push(Number(args[i]));
}
} break;
}
};
Game_Party.prototype.clearKeptItems = function(type) {
var all = (type === 'all');
if (all || type === 'items') {
this._keptItems = [];
}
if (all || type === 'armors') {
this._keptArmor = [];
}
if (all || type === 'weapons') {
this._keptWeapons = [];
}
};
Game_Party.prototype.saveItems = function(type) {
var all = (type === 'all');
if (all || type === 'items' || type === 'keyItems') {
for (var id in this._items) {
if (this._items.hasOwnProperty(id)) {
if (arrKeepItems.contains(id) || this._keptItems.contains(Number(id))) continue;
var item = $dataItems[id];
var amount = this._items[id];
if ((type === 'items' || all) && item.itypeId === 1) {
this._savedItems.push([id, amount]);
delete this._items[id];
}
if ((type === 'keyItems' || all) && item.itypeId === 2) {
this._savedKeyItems.push([id, amount]);
delete this._items[id];
}
}
}
}
if (all || type === 'armors') {
for (var id in this._armors) {
if (this._armors.hasOwnProperty(id)) {
if (arrKeepArmors.contains(id) || this._keptArmor.contains(Number(id))) continue;
var amount = this._armors[id];
this._savedArmor.push([id, amount]);
delete this._armors[id];
}
}
}
if (all || type === 'weapons') {
for (var id in this._weapons) {
if (this._weapons.hasOwnProperty(id)) {
if (arrKeepWeapons.contains(id) || this._keptWeapons.contains(Number(id))) continue;
var amount = this._weapons[id];
this._savedWeapons.push([id, amount]);
delete this._weapons[id];
}
}
}
};
Game_Party.prototype.reclaimItems = function(type) {
var all = (type === 'all');
if (all || type === 'items') {
for (var i = 0; i < this._savedItems.length; i++) {
this._items[this._savedItems[i][0]] = this._savedItems[i][1];
}
this._savedItems = [];
}
if (all || type === 'keyItems') {
for (var i = 0; i < this._savedKeyItems.length; i++) {
this._items[this._savedKeyItems[i][0]] = this._savedKeyItems[i][1];
}
this._savedKeyItems = [];
}
if (all || type === 'armors') {
for (var i = 0; i < this._savedArmor.length; i++) {
this._armors[this._savedArmor[i][0]] = this._savedArmor[i][1];
}
this._savedArmor = [];
}
if (all || type === 'weapons') {
for (var i = 0; i < this._savedWeapons.length; i++) {
this._weapons[this._savedWeapons[i][0]] = this._savedWeapons[i][1];
}
this._savedWeapons = [];
}
};
})();