-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathMrTS_DisableItemsToSell.js
293 lines (278 loc) · 8.05 KB
/
MrTS_DisableItemsToSell.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
//=============================================================================
// MrTS_DisableItemsToSell.js
//=============================================================================
/*:
* @plugindesc Disables specific items from being allowed to be sold in shops.
* @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.0
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Plugin Commands
* --------------------------------------------------------------------------------
* To disallow specific items from being sold use the following commands group:
* ItemLock Disable Item ID (ID)
* ItemLock Disable Weapon ID (ID)
* ItemLock Disable Armor ID (ID)
* For plugin commands above, if you specify 2nd ID, it'll disable all items in
* that range. 2nd ID is optional.
* E.g.: ItemLock Disable Item 10 13 will disable items with IDs 10, 11, 12, 13.
*
* To allow specifically disabled items to be sold again use this commands group:
* ItemLock Enable Item ID (ID)
* ItemLock Enable Weapon ID (ID)
* ItemLock Enable Armor ID (ID)
* For plugin commands above, if you specify 2nd ID, it'll enable all items in
* that range. 2nd ID is optional.
* E.g.: ItemLock Enable Armor 5 9 will disable armors with IDs 5, 6, 7, 8, 9.
*
* To quickly clear all specifically disabled items, use the following group:
* ItemLock Clear Items
* ItemLock Clear Weapons
* ItemLock Clear Armors
* ItemLock Clear All
*
* To disable/enable whole groups of items to be sold use the following groups:
* ItemLock Disable All Items
* ItemLock Disable All Weapons
* ItemLock Disable All Armors
*
* ItemLock Enable All Items
* ItemLock Enable All Weapons
* ItemLock Enable All Armors
* --------------------------------------------------------------------------------
*
* --------------------------------------------------------------------------------
* Version History
* --------------------------------------------------------------------------------
* 1.0 - Release
*/
(function() {
//--------------------------------------------------------------------------
// 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() === "itemlock") {
switch (args[0].toUpperCase())
{
case 'DISABLE':
{
switch (args[1].toUpperCase())
{
case 'ALL':
{
$gameSystem.itemLockSetAllTo("disable", args[2].toLowerCase());
} break;
default:
{
var id = Number(args[2]);
var id2 = args[3] ? Number(args[3]) : null;
$gameSystem.itemLockChangeSpecific("disable", args[1].toLowerCase(), id, id2);
} break;
}
} break;
case 'ENABLE':
{
switch (args[1].toUpperCase())
{
case 'ALL':
{
$gameSystem.itemLockSetAllTo("enable", args[2].toLowerCase());
} break;
default:
{
var id = Number(args[2]);
var id2 = args[3] ? Number(args[3]) : null;
$gameSystem.itemLockChangeSpecific("enable", args[1].toLowerCase(), id, id2);
} break;
}
} break;
case 'CLEAR':
{
$gameSystem.itemLockClearSpecific(args[1].toLowerCase());
} break;
default:
{
console.warn("ItemLock " + args[0] + " command does not exist!");
} break;
}
}
};
//--------------------------------------------------------------------------
// Game_System
//
var _Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
_Game_System_initialize.call(this);
this._itemLockItems = [];
this._itemLockWeapons = [];
this._itemLockArmors = [];
this._itemLockAllItems = false;
this._itemLockAllWeapons = false;
this._itemLockAllArmors = false;
};
Game_System.prototype.itemLockCanSell = function(item) {
var type = null;
if (DataManager.isItem(item))
type = "item";
else if (DataManager.isWeapon(item))
type = "weapon";
else if (DataManager.isArmor(item))
type = "armor";
else
return true;
switch (type)
{
case 'item':
{
if (this._itemLockAllItems || this._itemLockItems.contains(item.id))
return false;
} break;
case 'weapon':
{
if (this._itemLockAllWeapons || this._itemLockWeapons.contains(item.id))
return false;
} break;
case 'armor':
{
if (this._itemLockAllArmors || this._itemLockArmors.contains(item.id))
return false;
} break;
}
return true;
};
Game_System.prototype.itemLockChangeSpecific = function(to, type, id, id2) {
var range = id2 ? id2 - id + 1 : 1;
for (var i = id; i < id+range; i++) {
switch (type)
{
case 'item':
{
if (to === "disable") {
if (!this._itemLockItems.contains(i)) this._itemLockItems.push(i);
}
else if (to === "enable") {
this._itemLockItems.splice(this._itemLockItems.indexOf(i), 1);
}
else {
console.warn("ItemLock " + to + " " + type + " command does not exist!");
}
} break;
case 'weapon':
{
if (to === "disable") {
if (!this._itemLockWeapons.contains(i)) this._itemLockWeapons.push(i);
}
else if (to === "enable") {
this._itemLockWeapons.splice(this._itemLockWeapons.indexOf(i), 1);
}
else {
console.warn("ItemLock " + to + " " + type + " command does not exist!");
}
} break;
case 'armor':
{
if (to === "disable") {
if (!this._itemLockArmors.contains(i)) this._itemLockArmors.push(i);
}
else if (to === "enable"){
this._itemLockArmors.splice(this._itemLockArmors.indexOf(i), 1);
}
else {
console.warn("ItemLock " + to + " " + type + " command does not exist!");
}
} break;
}
}
};
Game_System.prototype.itemLockClearSpecific = function(type) {
switch (type)
{
case 'items':
{
this._itemLockItems = [];
} break;
case 'weapons':
{
this._itemLockWeapons = [];
} break;
case 'armors':
{
this._itemLockArmors = [];
} break;
case 'all':
{
this._itemLockItems = [];
this._itemLockWeapons = [];
this._itemLockArmors = [];
} break;
default:
{
console.warn("ItemLock Clear " + type + " command does not exist!");
} break;
}
};
Game_System.prototype.itemLockSetAllTo = function(to, type) {
switch (type)
{
case 'items':
{
if (to === "disable") {
this._itemLockAllItems = true;
}
else if (to === "enable"){
this._itemLockAllItems = false;
}
else {
console.warn("ItemLock " + to + " All " + type + " command does not exist!");
}
} break;
case 'weapons':
{
if (to === "disable") {
this._itemLockAllWeapons = true;
}
else if (to === "enable"){
this._itemLockAllWeapons = false;
}
else {
console.warn("ItemLock " + to + " All " + type + " command does not exist!");
}
} break;
case 'armors':
{
if (to === "disable") {
this._itemLockAllArmors = true;
}
else if (to === "enable"){
this._itemLockAllArmors = false;
}
else {
console.warn("ItemLock " + to + " All " + type + " command does not exist!");
}
} break;
default:
{
console.warn("ItemLock " + to + " " + " All " + type + " command does not exist!");
}
}
};
//--------------------------------------------------------------------------
// Window_ShopSell
//
var _Window_ShopSell_isEnabled = Window_ShopSell.prototype.isEnabled;
Window_ShopSell.prototype.isEnabled = function(item) {
return _Window_ShopSell_isEnabled.call(this, item) && $gameSystem.itemLockCanSell(item);
};
})();