| 赞 | 664 |
| VIP | |
| 好人卡 | |
| 积分 | 345 |
| 经验 | |
| 最后登录 | 2024-7-10 |
| 在线时间 | 5096 小时 |
- 梦石
- 0
- 星屑
- 34511
- 在线时间
- 5096 小时
- 注册时间
- 2012-11-19
- 回帖
- 4715

|
发表于 2020-7-31 18:59:19
|
显示全部楼层
以前 pia 过一个差不多的功能,构思很简单,以为没人会用这样的。
这个插件估计有 大改过商店界面 的不适用,可能无法记录到购买的个数或无法设置物品当前价格。
- //=================================================================================================
- // ItemPrice.js
- //=================================================================================================
- /*:
- * @plugindesc 物品价格自定义计算。
- * @author 芯☆淡茹水
- * @help
- *
- * 1, 插件命令: 清除所有记录的物品购买个数 => ClearPurchasedNum
- *
- * 2, 算式变量简写: item => 当前物品。
- * p => 该物品数据库设置的价格。
- * n => 该物品总计购买的个数。
- * v => 游戏变量。(写法为 v[n] 的方式)
- *
- * 3,可在物品备注里单独给这个物品写算式计算其价格,格式为:
- * <PriceFormula>
- * 算式 ...
- * .
- * .
- * .
- * </PriceFormula>
- *
- *
- * @param formula0
- * @text 道具价格算式。
- * @desc 道具价格算式。(p :数据库设置的初始价格; n :购买次数; v :游戏变量)
- * @default p + n * 50
- *
- * @param formula1
- * @text 武器价格算式。
- * @desc 武器价格算式。(p :数据库设置的初始价格; n :购买次数; v :游戏变量)
- * @default
- *
- * @param formula2
- * @text 防具价格算式。
- * @desc 防具价格算式。(p :数据库设置的初始价格; n :购买次数; v :游戏变量)
- * @default
- */
- //=================================================================================================
- ;var XdRsData = XdRsData || {};
- XdRsData.ip = XdRsData.ip || {};
- XdRsData.ip.param = PluginManager.parameters('XdRs_ItemPrice');
- //=================================================================================================
- XdRsData.ip.setupItemPrice = function(item) {
- if (!this.isGameItem(item)) return;
- var type = this.getItemType(item);
- var formula = this.getItemNoteFormula(item) || this.param['formula'+type];
- if (formula) {
- if (!item.basePrice) item.basePrice = item.price;
- var p = item.basePrice;
- var n = $gameSystem.purchasedNum(item);
- var v = $gameVariables._data;
- try {item.price = eval(formula);}
- catch(e) {
- item.price = p;
- var typeName = ['道具','武器','防具'][type];
- var msg = typeName+'价格算式书写错误! ' + typeName + 'id: '+item.id;
- console.error(msg);
- }
- }
- };
- XdRsData.ip.isGameItem = function(item) {
- return DataManager.isItem(item) ||
- DataManager.isWeapon(item) ||
- DataManager.isArmor(item);
- };
- XdRsData.ip.getItemType = function(item) {
- if (DataManager.isItem(item)) return 0;
- if (DataManager.isWeapon(item)) return 1;
- if (DataManager.isArmor(item)) return 2;
- return null;
- };
- XdRsData.ip.getItemNoteFormula = function(item) {
- if (!this.isGameItem(item) || !(/<PriceFormula>/.test(item.note))) return null;
- return item.note.match(/<PriceFormula>([\S\s]*)<\/PriceFormula>/) ? RegExp.$1 : null;
- };
- //=================================================================================================
- XdRsData.ip.Game_System_initialize = Game_System.prototype.initialize;
- Game_System.prototype.initialize = function() {
- XdRsData.ip.Game_System_initialize.call(this);
- this.clearPurchasedNum();
- };
- Game_System.prototype.clearPurchasedNum = function() {
- this._purchasedNumData = [[],[],[]];
- };
- Game_System.prototype.purchasedNum = function(item) {
- var type = XdRsData.ip.getItemType(item);
- return type !== null ? this._purchasedNumData[type][item.id] || 0 : 0;
- };
- Game_System.prototype.addPurchasedNum = function(item, num) {
- var type = XdRsData.ip.getItemType(item);
- if (type !== null) {
- this._purchasedNumData[type][item.id] = this.purchasedNum(item) + num;
- XdRsData.ip.setupItemPrice(item);
- }
- };
- //=================================================================================================
- XdRsData.ip.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
- Game_Interpreter.prototype.pluginCommand = function(command, args) {
- XdRsData.ip.Game_Interpreter_pluginCommand.call(this, command, args);
- command === 'ClearPurchasedNum' && $gameSystem.clearPurchasedNum();
- };
- //=================================================================================================
- XdRsData.ip.Scene_Shop_prepare = Scene_Shop.prototype.prepare;
- Scene_Shop.prototype.prepare = function(goods, purchaseOnly) {
- XdRsData.ip.Scene_Shop_prepare.call(this, goods, purchaseOnly);
- for (var i=0;i<goods.length;++i) {
- if (goods[i][0] === 0) XdRsData.ip.setupItemPrice($dataItems[goods[i][1]]);
- if (goods[i][0] === 1) XdRsData.ip.setupItemPrice($dataWeapons[goods[i][1]]);
- if (goods[i][0] === 2) XdRsData.ip.setupItemPrice($dataArmors[goods[i][1]]);
- }
- };
- XdRsData.ip.Scene_Shop_doBuy = Scene_Shop.prototype.doBuy;
- Scene_Shop.prototype.doBuy = function(number) {
- XdRsData.ip.Scene_Shop_doBuy.call(this, number);
- $gameSystem.addPurchasedNum(this._item, number);
- };
- //=================================================================================================
- // end
- //=================================================================================================
复制代码
物品价格自定义计算.rar
(1.52 KB, 下载次数: 41)
|
|