// MV_RANDOM_SHOP.js
// 商店展示的最大商品项目数,有机会少于该数目,暂定为 6个
Game_Interpreter.prototype._maxCommodityItems = 6;
// 开关编号,拟定该编号的开关状态为:是否启用随机商店。暂定为 1号开关
SwitchNumber = 1;
/*
======================================================================
◆ 商店处理
======================================================================
*/
// Shop Processing
Game_Interpreter.prototype.command302 = function() {
if (!$gameParty.inBattle()) {
var goods = [this._params];
while (this.nextEventCode() === 605) {
this._index++;
goods.push(this.currentCommand().parameters);
}
if($gameSwitches.value(SwitchNumber)){ // <<< 插入代码
goods = this.classificationProcessing(this._params[4]); // <<< 插入代码
} // <<< 插入代码
SceneManager.push(Scene_Shop);
SceneManager.prepareNextScene(goods, this._params[4]);
}
return true;
};
/*
======================================================================
◆ 分类处理
======================================================================
*/
Game_Interpreter.prototype.classificationProcessing = function(param){
var s = [0, 0, 0, 0];
var R = Math.randomInt;
s[0] = this._maxCommodityItems;
s[4] = $dataItems.length + $dataWeapons.length + $dataArmors.length - 3;
s[0] = s[0] > s[4]? s[4] : s[0];
s[1] = R(s[0]);
s[4] = $dataItems.length - 1;
s[1] = s[1] > s[4]? s[4] : s[1];
s[2] = s[1] > 0? R(s[0] - s[1]) : R(s[0]);
s[4] = $dataWeapons.length -1;
s[2] = s[2] > s[4]? s[4] : s[2];
s[4] = s[1] + s[2];
s[3] = s[4] > 0? s[0] - s[4] : s[0];
s[4] = $dataArmors.length -1;
s[3] = s[3] > s[4]? s[4] : s[3];
/*------------------------------------------------------------------------*/
var y = [null, [], [], []];
var goods = [];
var temp = [null, $dataItems, $dataWeapons, $dataArmors];
for(var i = 1; i < 4; i++){
temp[i].forEach(function(t, index){y[i].push(index)});
var x = 0;
while(x < s[i]){
x++;
var n = y[i].length - 1;
var v = Math.randomInt(n) + 1;
var tempGoods = [ i - 1, 0, 0, 0];
tempGoods[1] = y[i][v];
goods.push(tempGoods);
y[i].splice(v, 1);
}
}
if(!goods.length) goods = [0, 0, 0, 0, param];
goods[0][4] = param;
/*------------------------------------------------------------------------*/
return goods;
};