-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRTK1_Shop.js
394 lines (373 loc) · 12.5 KB
/
RTK1_Shop.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
//=============================================================================
// RTK1_Shop.js ver1.15 2016/07/25
// The MIT License (MIT)
//=============================================================================
/*:
* @plugindesc Enhance normal shop function.
* @author Toshio Yamashita (yamachan)
*
* @param buy category
* @desc Use category for buy menu (0:OFF 1:ON)
* @default 0
*
* @param buy rate
* @desc Calculate buy price with this rate
* @default 1
*
* @param sell rate
* @desc Calculate sell price with this rate
* @default 0.5
*
* @param difficulty buy rate
* @desc Calculate buy price with RTK1_Difficulty plugin
* @default 0
*
* @param difficulty sell rate
* @desc Calculate sell price with RTK1_Difficulty plugin
* @default 0
*
* @help
* Plugin to enhance normal shop function.
* This plugin requires RTK1_Core plugin (1.14 or later) previously.
*
* Plugin Command:
* RTK1_Shop category on
* RTK1_Shop category off
*
* RTK1_Shop open i2-5,w1-2
* RTK1_Shop open i2-5,w1-2 true
* RTK1_Shop open i2-5,w1-2 true shop%20name
*
* RTK1_Shop clear
* RTK1_Shop add i1-8
* RTK1_Shop remove i2
* RTK1_Shop open
* RTK1_Shop open none false shop%20name
*
* RTK1_Shop buy 2
* RTK1_Shop buy switch 9
* RTK1_Shop sell 0.6
* RTK1_Shop sell switch 10
*
* Manual:
* https://github.com/yamachan/jgss-hack/blob/master/RTK1_Shop.md
*/
/*:ja
* @plugindesc 通常のショップ機能の拡張
* @author Toshio Yamashita (yamachan)
*
* @param buy category
* @desc 購入メニューもカテゴリー表示する (0:OFF 1:ON)
* @default 0
*
* @param buy rate
* @desc 商品の価格はこの数値を掛けたものに調整されます
* @default 1
*
* @param sell rate
* @desc 商品の売価はこの数値を掛けたものに調整されます
* @default 0.5
*
* @param difficulty buy rate
* @desc 商品の価格は難易度とこの数値を掛けたもので調整されます
* @default 0
*
* @param difficulty sell rate
* @desc 商品の売価は難易度とこの数値を掛けたもので調整されます
* @default 0
*
* @help
* RPGツクール MV 用に作成した、通常のショップ機能を拡張するプラグインです。
* このプラグインの前に RTK1_Core プラグイン(1.14以降)を読み込んでください。
*
* プラグインコマンド:
* RTK1_Shop category on
* RTK1_Shop category off
*
* RTK1_Shop open i2-5,w1-2
* RTK1_Shop open i2-5,w1-2 true
* RTK1_Shop open i2-5,w1-2 true shop%20name
*
* RTK1_Shop clear
* RTK1_Shop add i1-8
* RTK1_Shop remove i2
* RTK1_Shop open
* RTK1_Shop open none false shop%20name
*
* RTK1_Shop buy 2
* RTK1_Shop buy switch 9
* RTK1_Shop sell 0.6
* RTK1_Shop sell switch 10
*
* マニュアル:
* https://github.com/yamachan/jgss-hack/blob/master/RTK1_Shop.ja.md
*/
(function(_global) {
"use strict";
if (!_global["RTK"]) {
throw new Error('This plugin requires RTK1_Core plugin previously.');
}
if (RTK.VERSION_NO < 1.14) {
throw new Error('This plugin requires version 1.14 or later of RTK1_Core plugin. the current version looks ' + RTK.VERSION_NO + ".");
}
var N = "RTK1_Shop";
var NK = "RTK_SH";
var M = RTK["SH"] = RTK._modules[N] = {};
var param = PluginManager.parameters(N);
M._d_buy = Number(param['difficulty buy rate'] || "0");
M._d_sell = Number(param['difficulty sell rate'] || "0");
M._cat = Number(param['buy category'] || "0");
M._config = M._config || {
"buy": Number(param['buy rate'] || "1"),
"sell" : Number(param['sell rate'] || "0.5"),
"set" : {}
};
M.difficulty = function() {
if (RTK.DF) {
return RTK.DF.difficulty();
}
return 0;
};
RTK.onLoad(function(){
M._cat = RTK.load(NK + "_cat") || M._cat;
M._config = RTK.load(NK + "_config") || M._config;
RTK.log(N + " load (_config)", M._config);
});
RTK.onSave(function(){
RTK.save(NK + "_cat", M._cat);
RTK.save(NK + "_config", M._config);
RTK.log(N + " save (_config)", M._config);
});
M._list = [];
function filter_new(o) {
return o && !M._list.contains(o);
};
M.command = function(args) {
if (args[0] == "open") {
if (args.length > 1) {
if (args[1] == "none") {
} else {
M.command(["clear"]);
M.command(["add", args[1]]);
}
}
var purchaseOnly = args.length > 2 && args[2] == "true";
M._title = (args.length > 3 ? args[3] : "").replace(/%20/g, " ");
SceneManager.push(Scene_Shop);
SceneManager.prepareNextScene(M._list, purchaseOnly);
} else if (args[0] == "add" && args.length > 1) {
RTK.id4list(RTK.ADD, M._list, args[1], true, M._config.set);
} else if (args[0] == "remove" && args.length > 1) {
RTK.id4list(RTK.REMOVE, M._list, args[1], true, M._config.set);
} else if (args[0] == "clear") {
var t = args[1] == "all" || !args[1] ? "item,weapon,armor" : args[1];
M._list = M._list.filter(function(o){
return (!t.contains("item") && DataManager.isItem(o)) || (!t.contains("weapon") && DataManager.isWeapon(o)) || (!t.contains("armor") && DataManager.isArmor(o));
});
} else if (args[0] == "complete") {
var t = args[1] == "all" || !args[1] ? "item,weapon,armor" : args[1];
if (t.contains("item")) { M._list = M._list.concat($dataItems.filter(filter_new)); }
if (t.contains("weapon")) { M._list = M._list.concat($dataWeapons.filter(filter_new)); }
if (t.contains("armor")) { M._list = M._list.concat($dataArmors.filter(filter_new)); }
} else if (args[0] == "max_id" && args.length == 2) {
var v = Number(args[1]||"0");
if (v > 0) { M._list = M._list.filter(function(o){ return o && o.id && o.id <= v; }); }
} else if (args[0] == "min_id" && args.length == 2) {
var v = Number(args[1]||"0");
if (v > 0) { M._list = M._list.filter(function(o){ return o && o.id && o.id >= v; }); }
} else if (args[0] == "max_price" && args.length == 2) {
var v = Number(args[1]||"0");
if (v >= 0) { M._list = M._list.filter(function(o){ return o && (o.price||0) <= v; }); }
} else if (args[0] == "min_price" && args.length == 2) {
var v = Number(args[1]||"0");
if (v >= 0) { M._list = M._list.filter(function(o){ return o && (o.price||0) >= v; }); }
} else if (args[0] == "buy" || args[0] == "sell") {
var rate = -1;
if (args.length == 3 && (args[1] == "sw" || args[1] == "switch")) {
var v = Number(args[2]) || 0;
if (v == v && v > 0) {
rate = $gameVariables._data[v];
}
} else if (args.length == 2) {
rate = Number(args[1]);
}
if (rate !== undefined && rate == rate && rate >= 0) {
if (args[0] == "buy") { M._config.buy = rate; } else { M._config.sell = rate; }
}
} else if (args[0] == "set" && args.length == 2) {
var key = args[1].replace(/%20/g, " ");
if (M._config.set[key] && M._list.length == 0) {
delete M._config.set[key];
} else {
M._config.set[key] = RTK.objects2ids(M._list).join(",");
}
} else if (args[0] == "category" && args[1] == "on") {
M._cat = 1;
} else if (args[0] == "category" && args[1] == "off") {
M._cat = 0;
}
RTK.log(N + " command (" + args.join(" ") + ")");
};
RTK.onCall(N, M.command.bind(this));
var _Scene_Shop_sellingPrice = Scene_Shop.prototype.sellingPrice;
Scene_Shop.prototype.sellingPrice = function() {
var ret = _Scene_Shop_sellingPrice.call(this);
return Math.floor(ret * 2 * M._config.sell * (1 - M._d_sell * M.difficulty()));
};
var _Scene_Shop_createHelpWindow = Scene_Shop.prototype.createHelpWindow;
Scene_Shop.prototype.createHelpWindow = function() {
_Scene_Shop_createHelpWindow.call(this);
M._title_win = M._title||"";
M._title = "";
this._helpWindow.clear = function(){
this.setText(M._title_win);
};
};
var _Window_ShopBuy_makeItemList = Window_ShopBuy.prototype.makeItemList;
Window_ShopBuy.prototype.makeItemList = function() {
if (this._shopGoods == M._list) {
if (M._cat) {
this._data = M._list.filter(function(o){
if ((this._category == "item" && DataManager.isItem(o)) || (this._category == "weapon" && DataManager.isWeapon(o)) || (this._category == "armor" && DataManager.isArmor(o))) {
return o.price > 0;
}
}, this);
} else {
this._data = M._list.filter(function(o){ return o.price > 0; });
}
this._price = this._data.map(function(o){ return Math.floor(o.price * M._config.buy * (1 + M._d_buy * M.difficulty())); });
} else {
if (M._cat) {
this._data = [];
this._price = [];
this._shopGoods.forEach(function(goods) {
var item = null;
switch (goods[0]) {
case 0:
if (this._category == "item") {
item = $dataItems[goods[1]];
}
break;
case 1:
if (this._category == "weapon") {
item = $dataWeapons[goods[1]];
}
break;
case 2:
if (this._category == "armor") {
item = $dataArmors[goods[1]];
}
break;
}
if (item) {
this._data.push(item);
this._price.push(goods[2] === 0 ? item.price : goods[3]);
}
}, this);
} else {
_Window_ShopBuy_makeItemList.call(this);
}
this._price = this._price.map(function(p){
return Math.floor(p * M._config.buy * (1 + M._d_buy * M.difficulty()));
});
}
};
// ----- buy category -----
Scene_Shop.prototype.createBuyCategoryWindow = function() {
this._buyCategoryWindow = new RTK_Window_ItemCategory();
this._buyCategoryWindow.setHelpWindow(this._helpWindow);
this._buyCategoryWindow.y = this._dummyWindow.y;
this._buyCategoryWindow.hide();
this._buyCategoryWindow.deactivate();
this._buyCategoryWindow.setHandler('ok', this.onBuyCategoryOk.bind(this));
this._buyCategoryWindow.setHandler('cancel', this.onBuyCategoryCancel.bind(this));
this.addWindow(this._buyCategoryWindow);
};
Scene_Shop.prototype.onBuyCategoryOk = function() {
this.activateBuyWindow();
this._buyWindow.select(0);
};
Scene_Shop.prototype.onBuyCategoryCancel = function() {
this._commandWindow.activate();
this._dummyWindow.show();
this._statusWindow.hide();
this._buyCategoryWindow.hide();
this._buyWindow.hide();
};
var _Scene_Shop_createBuyWindow = Scene_Shop.prototype.createBuyWindow;
Scene_Shop.prototype.createBuyWindow = function() {
_Scene_Shop_createBuyWindow.call(this);
if (M._cat) {
this.createBuyCategoryWindow();
this._buyWindow.height -= this._buyCategoryWindow.height;
this._buyWindow.y += this._buyCategoryWindow.height;
this._buyWindow.setCategory = function(category) {
if (this._category !== category) {
this._category = category;
this.refresh();
this.resetScroll();
}
};
this._buyCategoryWindow.setItemWindow(this._buyWindow);
}
};
var _Scene_Shop_commandBuy = Scene_Shop.prototype.commandBuy;
Scene_Shop.prototype.commandBuy = function() {
if (M._cat) {
this._dummyWindow.hide();
this._buyCategoryWindow.show();
this._buyCategoryWindow.activate();
this._buyWindow.show();
this._buyWindow.deselect();
this._buyWindow.refresh();
this._statusWindow.show();
} else {
_Scene_Shop_commandBuy.call(this);
}
};
var _Scene_Shop_onBuyCancel = Scene_Shop.prototype.onBuyCancel;
Scene_Shop.prototype.onBuyCancel = function() {
if (M._cat) {
this._buyWindow.deselect();
this._buyCategoryWindow.activate();
this._statusWindow.setItem(null);
this._helpWindow.clear();
} else {
_Scene_Shop_onBuyCancel.call(this);
}
};
var _Scene_Shop_onBuyOk = Scene_Shop.prototype.onBuyOk;
Scene_Shop.prototype.onBuyOk = function() {
if (M._cat) {
this._numberWindow.height = this._dummyWindow.height - this._buyCategoryWindow.height;
this._numberWindow.y = this._dummyWindow.y + this._buyCategoryWindow.height;
}
_Scene_Shop_onBuyOk.call(this);
};
var _Scene_Shop_onSellOk = Scene_Shop.prototype.onSellOk;
Scene_Shop.prototype.onSellOk = function() {
if (M._cat) {
this._numberWindow.height = this._dummyWindow.height;
this._numberWindow.y = this._dummyWindow.y;
}
_Scene_Shop_onSellOk.call(this);
};
// ----- RTK_Window_ItemCategory -----
function RTK_Window_ItemCategory() {
this.initialize.apply(this, arguments);
}
RTK_Window_ItemCategory.prototype = Object.create(Window_ItemCategory.prototype);
RTK_Window_ItemCategory.prototype.constructor = RTK_Window_ItemCategory;
RTK_Window_ItemCategory.prototype.initialize = function() {
Window_HorzCommand.prototype.initialize.call(this, 0, 0);
};
RTK_Window_ItemCategory.prototype.windowWidth = Window_ShopBuy.prototype.windowWidth;
RTK_Window_ItemCategory.prototype.maxCols = function() {
return 3;
};
RTK_Window_ItemCategory.prototype.makeCommandList = function() {
this.addCommand(TextManager.item, 'item');
this.addCommand(TextManager.weapon, 'weapon');
this.addCommand(TextManager.armor, 'armor');
};
})(this);