//==================================================================================================================
;var XdRsData = XdRsData || {};
XdRsData.floatingPrices = {};
//==================================================================================================================
XdRsData.floatingPrices.DMonLoad = DataManager.onLoad;
DataManager.onLoad = function(object) {
XdRsData.floatingPrices.DMonLoad.call(this, object);
XdRsData.floatingPrices.setup(object);
};
XdRsData.floatingPrices.DMloadGame = DataManager.loadGame;
DataManager.loadGame = function(savefileId) {
var loaded = XdRsData.floatingPrices.DMloadGame.call(this, savefileId);
loaded && XdRsData.floatingPrices.setupPrice();
return loaded;
};
//==================================================================================================================
XdRsData.floatingPrices.isItemData = function(object) {
return object === $dataItems || object === $dataWeapons || object === $dataArmors;
};
XdRsData.floatingPrices.syms = function() {
return ['I','W','A'];
};
XdRsData.floatingPrices.setup = function(object) {
if (!this.isItemData(object)) return;
object.forEach(function(item){if (item) item.basePrice = item.price;});
};
XdRsData.floatingPrices.setupPrice = function() {
this.syms().forEach(function(sym){this.change(sym, $gameSystem.itemPriceData()[sym]);}, this);
};
XdRsData.floatingPrices.getObj = function(sym) {
switch (sym) {
case 'I' :return $dataItems;
case 'W' :return $dataWeapons;
case 'A' :return $dataArmors;
}
return [];
};
XdRsData.floatingPrices.change = function(sym, rate) {
this.getObj(sym).forEach(function(item){this.changeItemPrice(item, rate);}, this);
$gameSystem.saveItemPrices(sym, rate);
};
XdRsData.floatingPrices.changeItemPrice = function(item, rate) {
if (!item || !item.basePrice) return;
item.price = Math.max(Math.round(item.basePrice * rate / 100), 1);
};
XdRsData.floatingPrices.restore = function(sym) {
this.change(sym, 100);
};
XdRsData.floatingPrices.restoreAll = function() {
this.syms().forEach(function(sym){this.restore(sym);}, this);
};
//==================================================================================================================
XdRsData.floatingPrices.GSinitialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
XdRsData.floatingPrices.GSinitialize.call(this);
this.restoreItemPrices();
};
Game_System.prototype.itemPriceData = function() {
return this._itemPrices;
};
Game_System.prototype.saveItemPrices = function(sym, rate) {
this._itemPrices[sym] = rate;
};
Game_System.prototype.restoreItemPrices = function() {
this._itemPrices = {'I':100,'W':100,'A':100};
};
//==================================================================================================================
XdRsData.floatingPrices.GIpluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
XdRsData.floatingPrices.GIpluginCommand.call(this, command, args);
command === 'ChangeItemPrice' && XdRsData.floatingPrices.change(''+args[0], +args[1]);
command === 'RestoreItemPrice' && XdRsData.floatingPrices.restore(''+args[0]);
command === 'RestoreAllPrice' && XdRsData.floatingPrices.restoreAll();
};
//==================================================================================================================
// end
//==================================================================================================================