/
Mano_CoinShop.js
228 lines (199 loc) · 5.79 KB
/
Mano_CoinShop.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
//=============================================================================
// Mano_CoinShop.js
// ----------------------------------------------------------------------------
// Copyright (c) 2019-2019 Sigureya
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
// ----------------------------------------------------------------------------
// Version
// 0.9.0 2019/05/26 初版
// ----------------------------------------------------------------------------
// [Twitter]: https://twitter.com/Sigureya/
//=============================================================================
/*:
* @plugindesc 変数やアイテムを消費して購入できるショップが作れます。
* 競合率・中ぐらい
* @author しぐれん(https://github.com/Sigureya/RPGmakerMV)
*
* @help
* お金の代わりに変数やアイテムを消費して購入できるショップを作成できます。
*
* 内部的には専用の財布を作って、そこに処理を流します。
* 既存処理を再定義しているため、競合の可能性があります。
* (ポイントカードのようなプラグインを使っている場合、これより後ろにおいてください)
*
* プラグインコマンドで以下の内容を入力してください。
* 設定変更は1回のみ有効です。
*
* ShopMode モード 識別番号 単位
* パラメータは上記の通りです。
* この機能を使った場合、売却機能は強制的にロックされます。
*
* ShopMode Variable 8 枚
* お金の代わりに変数8番の数値を見ます。
* 単位として「枚」を使うようになります。
*
* ShopMode item 3 個
* お金の代わりにitemID[3]のアイテムの所持数を見ます
* 単位として「個」を使うようになります。
*
* 2019/05/26 公開
*
*/
(function(){
'use strict';
class WalletBase{
/**
* @param {String} unit
*/
constructor(unit){
this.setUnit(unit ||TextManager.currencyUnit);
}
/**
* @param {String} unit
*/
setUnit(unit){
this._unit = unit;
}
value(){
return 0;
}
pay(value){
}
loseValue(value){
this.pay(value);
}
gainValue(value){
this.pay(-value);
}
unit(){
return this._unit;
}
canSeil(){
return false;
}
isGold(){
return false;
}
}
class WalletGold extends WalletBase{
constructor(){
super(TextManager.currencyUnit);
}
value(){
return $gameParty.gold();
}
pay(value){
$gameParty.loseGold(value);
}
canSeil(){
return true;
}
isGold(){
return true;
}
}
class WalletItem extends WalletBase{
/**
* @param {Number} itemId
*/
constructor(itemId){
super();
this._itemId=itemId;
}
item(){
return $dataItems[this._itemId];
}
value(){
return $gameParty.numItems(this.item());
}
pay(value){
$gameParty.loseItem( this.item(), value);
}
}
window[WalletItem.name] =WalletItem;
class WalletVariable extends WalletBase{
/**
* @param {Number} id
*/
constructor(id){
super();
this._variableId=id;
}
value(){
return $gameVariables.value(this._variableId);
}
pay(value){
const lastValue = this.value();
$gameVariables.setValue(this._variableId, lastValue-value );
}
}
/**
* @returns {WalletBase}
* @param {String} mode
* @param {Number} id
*/
function makeWallet(mode,id){
if(mode ==="item"){
const wi = new WalletItem(id);
return wi;
}
if(mode ==="variable"){
const wv = new WalletVariable(id);
return wv;
}
return new WalletGold();
}
let g_wallet =null;
const Game_Interpreter_pluginCommand=Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand =function(cmd,args){
if(cmd ==="ShopMode"){
const mode = args[0];
const id = Number( args[1]);
const unit =args[2];
const wallet = makeWallet(mode,id);
wallet.setUnit(unit);
g_wallet =wallet;
return;
}
Game_Interpreter_pluginCommand.call(this,cmd,args);
};
const Scene_Load_onLoadSuccess=Scene_Load.prototype.onLoadSuccess
Scene_Load.prototype.onLoadSuccess =function(){
g_wallet=null;
Scene_Load_onLoadSuccess.call(this);
};
Window_Gold.prototype.setupWallet =function(){
const w = g_wallet || new WalletGold();
this._wallet =w;
g_wallet =null;
};
Window_Gold.prototype.value = function() {
return this._wallet.value();
};
Window_Gold.prototype.currencyUnit = function() {
return this._wallet.unit();
};
Window_Gold.prototype.wallet =function(){
return this._wallet;
};
const Window_Gold_initialize =Window_Gold.prototype.initialize;
Window_Gold.prototype.initialize =function(x,y){
this.setupWallet();
Window_Gold_initialize.call(this,x,y);
};
const Scene_Shop_createGoldWindow =Scene_Shop.prototype.createGoldWindow;
Scene_Shop.prototype.createGoldWindow =function(){
Scene_Shop_createGoldWindow.call(this);
this._purchaseOnly =this._purchaseOnly || !this._goldWindow.wallet().canSeil();
};
Scene_Shop.prototype.doBuy = function(number) {
this._goldWindow.wallet().loseValue(number * this.buyingPrice());
$gameParty.gainItem(this._item, number);
};
Scene_Shop.prototype.doSell = function(number) {
const p =number * this.sellingPrice();
this._goldWindow.wallet().gainValue(p);
$gameParty.loseItem(this._item, number);
};
})();