设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 85|回复: 0

[转载发布] Item Price Control

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    8305

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    30617
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    39816

    灌水之王

    发表于 6 天前 | 显示全部楼层 |阅读模式
    Item Price Control v1.4.2
    Feldherren


    Introduction
    RPG Maker MV's control over shops and item prices is a step up from previous entries, as we can now determine item buying price in the shop processing command, but is otherwise missing a few obvious or useful features; notably, item sell price is in a default project always half of the database item value, not the shop value (which prompted me to start writing this thing). This plugin allows you to change various values relating to item buy and sell prices in shops via plugin command.

    Features
    - Change whether sell price is based on database value or shop value for an item
    - Change buy and sell price multipliers
    - Explicitly define buy and sell prices for specific items (and undo this, when you want the database or shop price again)
    - Set arbitrary categories for items, and apply multipliers to buying or selling price for all items in category

    How to Use
    No special steps for setting up the plugin; drop it into the plugin folder and select it in RPG Maker MV's plugin manager, same as you would for most other plugins.
    Initial settings can be set up as plugin parameters in the plugin manager, but otherwise a number of plugin commands can be used to control the plugin's behaviour during play.

    Plugin commands:
    SETSELLPRICEDEPENDENCY [shop|database]
    Changes whether the sell price is dependent on the shop value, or the
    database value, of an item.
    SELLINGMULTIPLIER [float]
    Changes the sell-price multiplier to the specified float.
    CATEGORYSELLINGMULTIPLIER [category] [float]
    Changes the sell-price multiplier for the specified category to the
    SELLINGMULTIPLIERAFFECTSSETPRICES [true|false]
    Sets whether the selling multiplier is applied to explicitly-set prices.
    BUYINGMULTIPLIER [float]
    Changes the buy-price multiplier to the specified float.
    CATEGORYBUYINGMULTIPLIER [category] [float]
    Changes the sell-price multiplier for the specified category to the
    specified float.
    BUYINGMULTIPLIERAFFECTSSETPRICES [true|false]
    Sets whether the buying multiplier is applied to explicitly-set prices.
    SETSELLPRICE [item|weapon|armor] [id] [price]
    Sets the selling price for the item/weapon/armor with the specified ID
    to the given price.
    UNSETSELLPRICE [item|weapon|armor] [id]
    Unsets a defined selling price for the item/weapon/armor with the
    specified ID.
    SETBUYPRICE [item|weapon|armor] [id] [price]
    Sets the buying price for the item/weapon/armor with the specified ID
    to the given price.
    UNSETBUYPRICE [item|weapon|armor] [id]
    Unsets a defined buying price for the item/weapon/armor with the
    specified ID.

    Script
    Spoiler                Code:       
    1. /*:
    2. * @plugindesc Allows changing item prices mid-game via plugin command.
    3. * @author Feldherren
    4. *
    5. * @param Item Sell Price Dependent on Shop Price
    6. * @desc Sets whether the item sell price in shops is dependent on the shop value, or the database value
    7. * @default shop
    8. *
    9. * @param Item Sell Price Multiplier
    10. * @desc Default multiplier to use when calculating sell price.
    11. * @default 0.5
    12. *
    13. * @param Sell Price Multiplier Affects Explicitly Set Prices
    14. * @desc Whether the sell price multiplier affects explicitly set buy prices; true/false
    15. * @default false
    16. *
    17. * @param Item Buy Price Multiplier
    18. * @desc Default multiplier to use when calculating buy price.
    19. * @default 1.0
    20. *
    21. * @param Buy Price Multiplier Affects Explicitly Set Prices
    22. * @desc Whether the buy price multiplier affects explicitly set sell prices; true/false
    23. * @default false
    24. *
    25. * @help Item Price Control v1.4.2, by Feldherren (rpaliwoda AT googlemail.com)
    26. Changelog:
    27. 1.4.2:   fixed bug where category sell multipliers weren't being applied; instead
    28.        category buy multipliers were applied when trying to sell items.
    29. 1.4.1:   fixed bug where attempting to sell items would cause an error, and another
    30.        issue where attempting to sell items with item price determined by shop
    31.        price, when the item was not in the shop, would result in a price of 0
    32.        being offered, and a related issue where selling price wasn't properly
    33.        calculated for weapons and armour. Also fixed a bug where database buying
    34.        price wasn't getting the buying multiplier applied.
    35. 1.4.0:   can now set categories for items, weapons and armor via notebox tags,
    36.        and apply a modifier for entire categories of items
    37. 1.3.2:   fixed issue where buying price was not changed for an item after
    38.        attempting to explicitly change buying price for it
    39. 1.3.1:   fixed issue where plugin commands referred to an entirely different
    40.        script
    41. 1.3.0:   changed how buying price was being determined, is now displayed properly
    42.        in shop item list
    43. 1.2.0:   can now set item buy price multipler via plugin parameter and command
    44. 1.1.0:   can now explicitly set item buy and sell prices
    45. 1.0.0:   initial commit
    46. Allows you to set whether item selling price is calculated based on the
    47. database price, or the shop price; by default RPG Maker MV only has the
    48. selling price dependent on the database price, even if the shop has a
    49. custom price for the item in question.
    50. Allows you to change the sell-price and buy-price multiplier
    51. from game start (as a plugin parameter), and mid-game (via plugin command).
    52. Note:if you change the buying price multiplier, and have selling price
    53. determined by shop price (and not explicitly set for an item), this will
    54. affect selling price. For example, if you have a buying price multiplier
    55. of 1.1, a selling price multiplier of 1.0, and the item price is set to
    56. 20, the item will both buy and sell for 22.
    57. Allows you to outright set buy and sell prices (which overrides
    58. the above settings), and unset the same.
    59. Allows you to set categories for items, weapons and armor, and set multipliers
    60. to be applied to all bought or sold items with that category.
    61. Note that all applicable multipliers are applied, not just one. For example,
    62. a general multiplier of 1.1 and a category multiplier of 1.1 effectively
    63. become a total multiplier of 1.21.
    64. Notebox tags:
    65. Items, Weapons and Armor:
    66. <category:name>
    67. <category:name,name>
    68. Assigns a category to the item, weapon or armour. Multiple categories
    69. can be separated via commas.
    70. Plugin commands:
    71. SETSELLPRICEDEPENDENCY [shop|database]
    72. Changes whether the sell price is dependent on the shop value, or the
    73. database value, of an item.
    74. SELLINGMULTIPLIER [float]
    75. Changes the sell-price multiplier to the specified float.
    76. CATEGORYSELLINGMULTIPLIER [category] [float]
    77. Changes the sell-price multiplier for the specified category to the
    78. specified float.
    79. SELLINGMULTIPLIERAFFECTSSETPRICES [true|false]
    80. Sets whether the selling multiplier is applied to explicitly-set prices.
    81. BUYINGMULTIPLIER [float]
    82. Changes the buy-price multiplier to the specified float.
    83. CATEGORYBUYINGMULTIPLIER [category] [float]
    84. Changes the sell-price multiplier for the specified category to the
    85. specified float.
    86. BUYINGMULTIPLIERAFFECTSSETPRICES [true|false]
    87. Sets whether the buying multiplier is applied to explicitly-set prices.
    88. SETSELLPRICE [item|weapon|armor] [id] [price]
    89. Sets the selling price for the item/weapon/armor with the specified ID
    90. to the given price.
    91. UNSETSELLPRICE [item|weapon|armor] [id]
    92. Unsets a defined selling price for the item/weapon/armor with the
    93. specified ID.
    94. SETBUYPRICE [item|weapon|armor] [id] [price]
    95. Sets the buying price for the item/weapon/armor with the specified ID
    96. to the given price.
    97. UNSETBUYPRICE [item|weapon|armor] [id]
    98. Unsets a defined buying price for the item/weapon/armor with the
    99. specified ID.
    100. Free for use with commercial projects, though I'd appreciate being
    101. contacted if you do use it in any games, just to know.
    102. */
    103. (function(){
    104.    var parameters = PluginManager.parameters('FELD_ItemPriceControl');
    105.    
    106.    var shopSellPriceDependentOnShopBuyPrice = (parameters["Item Sell Price Dependent on Shop Price"] == 'shop');
    107.    var generalSellMultiplier = parseFloat(parameters["Item Sell Price Multiplier"]);
    108.    var generalBuyMultiplier = parseFloat(parameters["Item Buy Price Multiplier"]);
    109.    var explicitSellPriceAffectedByMultiplier = (parameters["Sell Price Multiplier Affects Explicitly Set Prices"] == 'true');
    110.    var explicitBuyPriceAffectedByMultiplier = (parameters["Buy Price Multiplier Affects Explicitly Set Prices"] == 'true');
    111.    
    112.    var categoryBuyMultipliers = new Object();
    113.    var categorySellMultipliers = new Object();
    114.    
    115.    var itemBuyPrices = new Object();
    116.    var weaponBuyPrices = new Object();
    117.    var armorBuyPrices = new Object();
    118.    
    119.    var itemSellPrices = new Object();
    120.    var weaponSellPrices = new Object();
    121.    var armorSellPrices = new Object();
    122.    
    123.    var oldPrice = Window_ShopBuy.prototype.price;
    124.    Window_ShopBuy.prototype.price = function(item) {
    125.        var buyingPrice = oldPrice.call(this, item);
    126.        // calculating buyMultiplier
    127.        var buyMultiplier = generalBuyMultiplier;
    128.        var categories = [];
    129.        if (item.meta.category)
    130.        {
    131.            categories = item.meta.category.split(',');
    132.        }
    133.        for (i in categories)
    134.        {
    135.            if (categories[i] in categoryBuyMultipliers)
    136.            {
    137.                buyMultiplier = buyMultiplier * categoryBuyMultipliers[categories[i]];
    138.            }
    139.        }
    140.        buyingPrice = buyingPrice * buyMultiplier;
    141.        if (DataManager.isItem(item)/* && this._item.itypeId === 1*/) // item
    142.        {
    143.            if (item.id in itemBuyPrices)
    144.            {
    145.                buyingPrice = itemBuyPrices[item.id];
    146.                if (explicitBuyPriceAffectedByMultiplier)
    147.                {
    148.                    buyingPrice = buyingPrice * buyMultiplier;
    149.                }
    150.            }
    151.        }
    152.        else if (DataManager.isWeapon(item)) // weapon
    153.        {
    154.            if (item.id in weaponBuyPrices)
    155.            {
    156.                buyingPrice = weaponBuyPrices[this._item.id];
    157.                if (explicitBuyPriceAffectedByMultiplier)
    158.                {
    159.                    buyingPrice = buyingPrice * buyMultiplier;
    160.                }
    161.            }
    162.        }
    163.        else if (DataManager.isArmor(item)) // armor
    164.        {
    165.            if (item.id in armorBuyPrices)
    166.            {
    167.                buyingPrice = armorBuyPrices[item.id];
    168.                if (explicitBuyPriceAffectedByMultiplier)
    169.                {
    170.                    buyingPrice = buyingPrice * buyMultiplier;
    171.                }
    172.            }
    173.        }
    174.        return Math.floor(buyingPrice);
    175.    };
    176.    // new sellingPrice function
    177.    var oldSellingPrice = Scene_Shop.prototype.sellingPrice;
    178.    Scene_Shop.prototype.sellingPrice = function() {
    179.        // calls the old method.
    180.        var sellingPrice = oldSellingPrice.call(this);
    181.        // calculating sellMultiplier
    182.        var sellMultiplier = generalSellMultiplier;
    183.        var categories = [];
    184.        console.log(this._item); // good
    185.        console.log(this._item.meta.category); // good
    186.        if (this._item.meta.category)
    187.        {
    188.            categories = this._item.meta.category.split(',');
    189.        }
    190.        console.log(categories);
    191.        for (i in categories)
    192.        {
    193.            console.log(i);
    194.            if (categories[i] in categorySellMultipliers)
    195.            {
    196.                console.log(categorySellMultipliers[categories[i]]);
    197.                sellMultiplier = sellMultiplier * categorySellMultipliers[categories[i]];
    198.            }
    199.        }
    200.        console.log(categorySellMultipliers);      
    201.        console.log(sellMultiplier);
    202.       
    203.        // this._buyWindow._shopGoods is an array of arrays
    204.        // each array in the array is an item/weapon/armour in the shop
    205.        // index 0 is item type: 0 for item, 1 for weapon, 2 for armour
    206.        // index 1 is item ID within the category
    207.       
    208.        var itemType = null;
    209.        if (DataManager.isItem(this._item)/* && this._item.itypeId === 1*/) // item
    210.        {
    211.            itemType = 0;
    212.        }
    213.        else if (DataManager.isWeapon(this._item)) // weapon
    214.        {
    215.            itemType = 1;
    216.        }
    217.        else if (DataManager.isArmor(this._item)) // armor
    218.        {
    219.            itemType = 2;
    220.        }
    221.       
    222.        var itemInShop = false
    223.        for (var i in this._buyWindow._shopGoods)
    224.        {
    225.            if (this._buyWindow._shopGoods[i][0] === itemType)
    226.            {
    227.                if (this._buyWindow._shopGoods[i][1] === this._item.id)
    228.                {
    229.                    itemInShop = true;
    230.                    break;
    231.                }
    232.            }
    233.        }
    234.       
    235.        // check that shopSellPriceDependentOnShopBuyPrice is true
    236.        if (shopSellPriceDependentOnShopBuyPrice) // dependent on shop value
    237.        {
    238.            if (itemInShop)
    239.            {
    240.                // item is in shop, use shop price for calculating sell value
    241.                sellingPrice = this._buyWindow.price(this._item) * sellMultiplier;
    242.            }
    243.            else
    244.            {
    245.                // item is not in shop, use database price for calculating sell value
    246.                sellingPrice = this._item.price * sellMultiplier;
    247.            }
    248.        }
    249.        else // dependent on database value
    250.        {
    251.            // selling prices are dependent on database value
    252.            sellingPrice = this._item.price * sellMultiplier;
    253.        }
    254.       
    255.        if (DataManager.isItem(this._item)/* && this._item.itypeId === 1*/) // item
    256.        {
    257.            if (this._item.id in itemSellPrices)
    258.            {
    259.                sellingPrice = itemSellPrices[this._item.id];
    260.                if (explicitSellPriceAffectedByMultiplier)
    261.                {
    262.                    sellingPrice = sellingPrice * sellMultiplier;
    263.                }
    264.            }
    265.        }
    266.        else if (DataManager.isWeapon(this._item)) // weapon
    267.        {
    268.            if (this._item.id in weaponSellPrices)
    269.            {
    270.                sellingPrice = weaponSellPrices[this._item.id];
    271.                if (explicitSellPriceAffectedByMultiplier)
    272.                {
    273.                    sellingPrice = sellingPrice * sellMultiplier;
    274.                }
    275.            }
    276.        }
    277.        else if (DataManager.isArmor(this._item)) // armor
    278.        {
    279.            if (this._item.id in armorSellPrices)
    280.            {
    281.                sellingPrice = armorSellPrices[this._item.id];
    282.                if (explicitSellPriceAffectedByMultiplier)
    283.                {
    284.                    sellingPrice = sellingPrice * sellMultiplier;
    285.                }
    286.            }
    287.        }
    288.       
    289.        return Math.floor(sellingPrice);
    290.    };
    291.    var FELD_ItemPriceControl_aliasPluginCommand = Game_Interpreter.prototype.pluginCommand;
    292.    Game_Interpreter.prototype.pluginCommand = function(command, args)
    293.    {
    294.        FELD_ItemPriceControl_aliasPluginCommand.call(this,command,args);
    295.        if(command == "SETSELLPRICEDEPENDENCY" && args[0] != null)
    296.        {
    297.            if (args[0] == 'shop')
    298.            {
    299.                shopSellPriceDependentOnShopBuyPrice = true;
    300.            }
    301.            else
    302.            {
    303.                shopSellPriceDependentOnShopBuyPrice = false;
    304.            }
    305.        }
    306.        else if(command == "SELLINGMULTIPLIER" && args[0] != null)
    307.        {
    308.            generalSellMultiplier = parseFloat(args[0]);
    309.        }
    310.        else if(command == "CATEGORYSELLINGMULTIPLIER" && args[0] != null && args[1] != null)
    311.        {
    312.            categorySellMultipliers[args[0]] = parseFloat(args[1]);
    313.            // console.log("selling: ", args[0], args[1]);
    314.            // console.log("selling: ", categorySellMultipliers);
    315.        }
    316.        else if(command == "SELLINGMULTIPLIERAFFECTSSETPRICES" && args[0] != null)
    317.        {
    318.            if (args[0] == 'true')
    319.            {
    320.                explicitSellPriceAffectedByMultiplier = true;
    321.            }
    322.            else
    323.            {
    324.                explicitSellPriceAffectedByMultiplier = false;
    325.            }
    326.        }
    327.        else if(command == "BUYINGMULTIPLIER" && args[0] != null)
    328.        {
    329.            generalBuyMultiplier = parseFloat(args[0]);
    330.        }
    331.        else if(command == "CATEGORYBUYINGMULTIPLIER" && args[0] != null && args[1] != null)
    332.        {
    333.            categoryBuyMultipliers[args[0]] = parseFloat(args[1]);
    334.            // console.log("buying: ", args[0], args[1]);
    335.            // console.log("buying: ", categoryBuyMultipliers);
    336.        }
    337.        else if(command == "BUYINGMULTIPLIERAFFECTSSETPRICES" && args[0] != null)
    338.        {
    339.            if (args[0] == 'true')
    340.            {
    341.                explicitBuyPriceAffectedByMultiplier = true;
    342.            }
    343.            else
    344.            {
    345.                explicitBuyPriceAffectedByMultiplier = false;
    346.            }
    347.        }
    348.        else if(command == "SETSELLPRICE" && args[0] != null && args[1] != null && args[2] != null)
    349.        {
    350.            if (args[0] == 'item')
    351.            {
    352.                itemSellPrices[parseInt(args[1])] = parseInt(args[2]);
    353.            }
    354.            else if (args[0] == 'weapon')
    355.            {
    356.                weaponSellPrices[parseInt(args[1])] = parseInt(args[2]);
    357.            }
    358.            else if (args[0] == 'armor')
    359.            {
    360.                armorSellPrices[parseInt(args[1])] = parseInt(args[2]);
    361.            }
    362.        }
    363.        else if(command == "SETBUYPRICE" && args[0] != null && args[1] != null && args[2] != null)
    364.        {
    365.            if (args[0] == 'item')
    366.            {
    367.                itemBuyPrices[parseInt(args[1])] = parseInt(args[2]);
    368.            }
    369.            else if (args[0] == 'weapon')
    370.            {
    371.                weaponBuyPrices[parseInt(args[1])] = parseInt(args[2]);
    372.            }
    373.            else if (args[0] == 'armor')
    374.            {
    375.                armorBuyPrices[parseInt(args[1])] = parseInt(args[2]);
    376.            }
    377.        }
    378.        else if(command == "UNSETSELLPRICE" && args[0] != null && args[1] != null)
    379.        {
    380.            if (args[0] == 'item')
    381.            {
    382.                delete itemSellPrices[parseInt(args[1])];
    383.            }
    384.            else if (args[0] == 'weapon')
    385.            {
    386.                delete weaponSellPrices[parseInt(args[1])];
    387.            }
    388.            else if (args[0] == 'armor')
    389.            {
    390.                delete armorSellPrices[parseInt(args[1])];
    391.            }
    392.        }
    393.        else if(command == "UNSETBUYPRICE" && args[0] != null && args[1] != null)
    394.        {
    395.            if (args[0] == 'item')
    396.            {
    397.                delete itemBuyPrices[parseInt(args[1])];
    398.            }
    399.            else if (args[0] == 'weapon')
    400.            {
    401.                delete weaponBuyPrices[parseInt(args[1])];
    402.            }
    403.            else if (args[0] == 'armor')
    404.            {
    405.                delete armorBuyPrices[parseInt(args[1])];
    406.            }
    407.        }
    408.    }
    409. })();
    复制代码






    FAQ

    Q: Are there bugs?
    A: Lots! Probably. I am using this for one of my own projects, so I assure you I am working on it, but the rapid rise in version numbers might tell you how thorough I am in testing stuff before marking things as a release. Please let me know if you have any issues.

    Q: I have this great idea for a new feature; what should I do?
    A: Suggest it. Worst case scenario is I won't implement it. Likely outcome is I'll implement it even if I'm not currently using the thing.

    Q: Where can I always get the most up-to-date version of this plugin?
    A: Barring Github dying a cold and lonely death, here: https://github.com/Feldherren/mv-item-prices

    Credit and Thanks
    - Feldherren
    - Kinio's EISShopSystem.js helped me locate a few things

    Notes
    Let me know (either by posting here, or emailing me, anything short of throwing bricks at my windows) if you have any issues with my plugin, if anything doesn't appear to be acting as expected, or if it's outright broken.


    本贴来自国际rpgmaker官方论坛作者:Feldherren处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/item-price-control.85096/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 20:44 , Processed in 0.143020 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表