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

[转载发布] PT_ShopPercentages

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

    连续签到: 2 天

    [LV.7]常住居民III

    9072

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

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

    灌水之王

    发表于 2026-7-26 19:00:13 | 显示全部楼层 |阅读模式
    I've made another plugin I find very useful.
    So I thought, I'd like to share it with you guys.
    Hope it helps


    What does it do?
    This plugin changes the way, user-specified prices in the shop windows work.
    They will now be treated as percentage values rather than absolute prices.

    Features

    • decide whether to use your input as total percentage or discount values.
    • you can also use variables for your special prices
    • also, special prices for ALL items can be set.
    How to use
    Copy the source code (from below) and save it as
    "YOUR_PROJECT_PATH/js/plugins/PT_ShopPercentages.js".

    The plugin is plug & play and will work just fine with default values.
    However, you can manipulate its behavior using the plugin parameters.
    See the documentation contained in the plugin itself for details.

    If you already work with special prices a lot already in your project,
    it is not recommended to install this plugin or you might have a lot of work before you.
    If you're starting a new project, however, this plugin will help make thinks
    a lot easier in terms of in-game financial balancing.

    Terms of use
    Spoiler: Terms of use
    You may freely use, copy and modify this script
    in any commercial or non-commercial game.

    Re-distribution of the source code as is, is prohibited.
    You may link to the source, you got it from, though.
    The distribution of your modified code is allowed,
    as long as the original author is kept visible.

    Crediting the author in the game, however,
    is not required, although much appreciated.

    Screenshots packed with this plugin are for
    demonstrational purpose only.

    Credits for the original software
    "RPG Maker MV" go to
    Copyright (c) 2015 KADOKAWA CORPORATION / YOJI OJIMA
    The plugin
    Spoiler: Source code
                    Code:       
    1. /*:
    2. * @plugindesc v1.1 Use percentages for special shop prices
    3. * @author Patrick Tietz <ptietz.official[at]gmail.com>
    4. *
    5. * @param rounding method
    6. * @desc how to round results
    7. * (round, floor, ceil)
    8. * @type select
    9. * @option round
    10. * @option floor
    11. * @option ceil
    12. * @default round
    13. *
    14. * @param treat as discount
    15. * @desc treat input percentages as discount
    16. * @type boolean
    17. * @default false
    18. *
    19. * @param use variables
    20. * @desc use price input as variable index
    21. * @type boolean
    22. * @default false
    23. *
    24. * @param overall variable
    25. * @desc apply to all prices
    26. * @type variable
    27. * @default 0
    28. *
    29. *
    30. * @help
    31. *
    32. * ######################################
    33. * # Welcome                            #
    34. * ######################################
    35. *
    36. * Thank you for using ShopPercentages.
    37. *
    38. * This Plugin treats special prices in the shop processing
    39. * as percentages rather than absolute prices.
    40. *
    41. * This way, you won't have to go over all the NPCs
    42. * that sell a particular item, whenever you change
    43. * and balance its price.
    44. *
    45. * Have fun making games! :)
    46. *
    47. *
    48. * ######################################
    49. * # General Instructions               #
    50. * ######################################
    51. *
    52. * This plugin is plug & play and will perfectly work
    53. * from the moment you install and enable it
    54. * from within the plugin manager.
    55. *
    56. * Please, keep in mind that this plugin
    57. * overrides the defaul shop behavior for special prices.
    58. * Installing this plugin midway through your project
    59. * will probably have a significant impact on
    60. * already set special prices in your game.
    61. * This might ruin your financial balance
    62. * and you will have to edit every shop again.
    63. *
    64. * The plugin does not add any plugin commands.
    65. *
    66. *
    67. * ######################################
    68. * # Parameters                         #
    69. * ######################################
    70. *
    71. * rounding method
    72. * ===============
    73. * You can define how you want float number results
    74. * to be rounded. Methods are "round", "ceil" and "floor".
    75. *
    76. *   Example:
    77. *   Let's assume we have an item for sale that costs 210 by default.
    78. *   We want to have it sold by 90% of its original value.
    79. *   That would give us a total of 189.81 which is not
    80. *   possible in RPG Maker MV. Therefore we must round.
    81. *
    82. *
    83. * treat as discount
    84. * =================
    85. * If enabled, you special price inputs will be treated
    86. * as discount rather than total percentage values.
    87. * This affects variables as well.
    88. *
    89. * This parameter's behavior adjusts to your
    90. * "treat as discount" setting.
    91. *
    92. *   Example:
    93. *   Usually, when you have an item of 200 value
    94. *   sold for 180, you would have to enter "90"
    95. *   as 180 is 90% of 200.
    96. *   With this parameter enabled, you would now
    97. *   have to enter "10" as 180 is a 10% discount
    98. *   of the original 200.
    99. *
    100. *
    101. * use variables
    102. * =============
    103. * If you enable "use variables", your special prices will no longer
    104. * be treated as direct percentage inputs but as variable indizes.
    105. *
    106. *   Example:
    107. *   Maybe, you want a 10% discount on all swords.
    108. *   To get there, you would have to set a value
    109. *   for a variable, depending on your "treat as discount" setting.
    110. *   Then you would write the index of that variable
    111. *   as a special price on each shop's swords.
    112. *   Of course, there are many other use cases thinkable.
    113. *
    114. *
    115. * overall variable
    116. * ================
    117. * Here, you can specify a variable whose value is applied to
    118. * all shop prices (even default ones).
    119. *
    120. * Be aware that this variable is applied AFTER
    121. * everything else. This means, that even an item
    122. * that already has a special price, will still
    123. * be affected by this setting.
    124. *
    125. * This parameter's behavior adjusts to your
    126. * "treat as discount" setting.
    127. *
    128. *   Example:
    129. *   Let's say your player has some sort of bargaining skill
    130. *   which affects all shop prices.
    131. *   This can be achieved by writing the current discount,
    132. *   calculated by the particular skill, into a variable
    133. *   and then specifying that variable in this plugin.
    134. *
    135. *
    136. * ######################################
    137. * # Terms of use                       #
    138. * ######################################
    139. *
    140. * You may freely use, copy and modify this script
    141. * in any commercial or non-commercial game.
    142. *
    143. * Re-distribution of the source code as is, is prohibited.
    144. * You may link to the source, you got it from, though.
    145. * The distribution of your modified code is allowed,
    146. * as long as the original author is kept visible.
    147. *
    148. * Crediting the author in the game, however,
    149. * is not required, although much appreciated.
    150. *
    151. * Screenshots packed with this plugin are for
    152. * demonstrational purpose only.
    153. *
    154. * Credits for the original software
    155. * "RPG Maker MV" go to
    156. * Copyright (c) 2015 KADOKAWA CORPORATION / YOJI OJIMA
    157. */
    158. // get parameters
    159. PT_ShopPercentages_ParamsRaw = {
    160.     roundingMethod: String( PluginManager.parameters( 'PT_ShopPercentages' )[ 'rounding method' ] ),
    161.     treatAsDiscount: String( PluginManager.parameters( 'PT_ShopPercentages' )[ 'treat as discount' ] ),
    162.     useVars: String( PluginManager.parameters( 'PT_ShopPercentages' )[ 'use variables' ] ),
    163.     overallVariable: parseInt( PluginManager.parameters( 'PT_ShopPercentages' )[ 'overall variable' ] ),
    164. };
    165. // validate parameters
    166. PT_ShopPercentages_Params = {
    167.     roundingMethod      : PT_ShopPercentages_ParamsRaw.roundingMethod === 'ceil'
    168.                             || PT_ShopPercentages_ParamsRaw.roundingMethod === 'floor'
    169.                             ? PT_ShopPercentages_ParamsRaw.roundingMethod
    170.                             : 'round',
    171.     treatAsDiscount     : PT_ShopPercentages_ParamsRaw.treatAsDiscount === 'true'
    172.                             || PT_ShopPercentages_ParamsRaw.treatAsDiscount === '1'
    173.                             || PT_ShopPercentages_ParamsRaw.treatAsDiscount === 'yes'
    174.                             ? true
    175.                             : false,
    176.     useVars: PT_ShopPercentages_ParamsRaw.useVars === 'true'
    177.                             || PT_ShopPercentages_ParamsRaw.useVars === '1'
    178.                             || PT_ShopPercentages_ParamsRaw.useVars === 'yes'
    179.                             ? true
    180.                             : false,
    181.     overallVariable: PT_ShopPercentages_ParamsRaw.overallVariable
    182. };
    183. /**
    184. * Calculate item price
    185. *
    186. * @param {number} origItemPrice original item price (from database)
    187. * @param {number} rawPriceInput raw price input from shop window, optional
    188. * @param {boolean} isOverall for internal use only
    189. * @returns {number}
    190. */
    191. Window_ShopBuy.prototype.calcItemPrice = function( origItemPrice, rawPriceInput, isOverall = false )
    192. {
    193.     var result = origItemPrice;
    194.    
    195.     if ( arguments.length > 1 && typeof rawPriceInput !== 'undefined' )
    196.     {
    197.         // get price modifier depending "use variables" setting
    198.         var input = !isOverall && PT_ShopPercentages_Params.useVars
    199.             ? parseInt( $gameVariables.value( rawPriceInput ) )
    200.             : rawPriceInput;
    201.            
    202.         // calculate price depending on "treatAsDiscount" setting
    203.         var percentage = PT_ShopPercentages_Params.treatAsDiscount
    204.             ? origItemPrice - origItemPrice * input / 100
    205.             : origItemPrice * ( input / 100 );
    206.            
    207.         // round price depending on "rounding message" setting
    208.         result = parseInt( Math[ PT_ShopPercentages_Params.roundingMethod ]( percentage ) );
    209.     }
    210.    
    211.     // if "overall variable" is set
    212.     if ( !isOverall && PT_ShopPercentages_Params.overallVariable > 0 )
    213.     {
    214.         // redo the whole thing
    215.         result = this.calcItemPrice(
    216.             result,
    217.             $gameVariables.value( PT_ShopPercentages_Params.overallVariable ),
    218.             true
    219.         );
    220.     }
    221.    
    222.     // return result
    223.     return result;
    224. };
    225. /**
    226. * Make item list for buying window
    227. *
    228. * @override
    229. * @returns {undefined}
    230. */
    231. Window_ShopBuy.prototype.makeItemList = function()
    232. {
    233.     this._data = [];
    234.     this._price = [];
    235.    
    236.     this._shopGoods.forEach( function( goods )
    237.     {
    238.         var item = null;
    239.       
    240.         switch ( goods[0] )
    241.         {
    242.             case 0:
    243.                 item = $dataItems[ goods[1] ];
    244.                 break;
    245.             case 1:
    246.                 item = $dataWeapons[ goods[1] ];
    247.                 break;
    248.             case 2:
    249.                 item = $dataArmors[ goods[1] ];
    250.                 break;
    251.         }
    252.       
    253.         if ( item )
    254.         {
    255.             this._data.push( item );
    256.             this._price.push(
    257.                 goods[2] === 0
    258.                 ? this.calcItemPrice( item.price )
    259.                 : this.calcItemPrice( item.price, goods[3] )
    260.             );
    261.         }
    262.       
    263.     }, this );
    264.    
    265. };
    复制代码


    Happy game making!



    本贴来自国际rpgmaker官方论坛作者:ptietz处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/pt_shoppercentages.98150/

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

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

    本版积分规则

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

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2026-8-22 08:36 , Processed in 0.087473 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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