扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 68|回复: 0

[转载发布] 新手写的一个多货币商店脚本

[复制链接]
累计送礼:
0 个
累计收礼:
0 个
  • TA的每日心情
    开心
    2025-8-20 22:20
  • 签到天数: 161 天

    连续签到: 1 天

    [LV.7]常住居民III

    2483

    主题

    527

    回帖

    1万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    6
    卡币
    13716
    OK点
    16
    推广点
    0
    同能卷
    0
    积分
    16754

    灌水之王

    发表于 昨天 18:58 | 显示全部楼层 |阅读模式
    通过十号变量来切换商店显示的货币,本脚本还解决了其他第二货币脚本的buG,就是商店购买商品时会显示系统货币的BUG。
    这是示意图片



    下面是脚本,新手写的,可能有点繁琐,大家可以提出自己的意见。
    RUBY 代码
    1. #==============================================================================
    2. # ■ 多货币系统·金银铜
    3. #  新增两种货币类型,通过变量控制商店使用的货币
    4. #  变量ID=10控制货币类型(0=金币,1=银币,2=铜币)
    5. #  灵狐阁主(刘飞洋)制作
    6. #  货币操作脚本命令:
    7. #  - 金币:$game_party.gain_gold(数量)   # 正数增加,负数减少
    8. #  - 银币:$game_party.gain_sliver(数量) # 正数增加,负数减少
    9. #  - 铜币:$game_party.gain_copper(数量) # 正数增加,负数减少
    10. #==============================================================================
    11. #==============================================================================
    12. # ■ Game_Party
    13. #  新增银币和铜币的属性及相关方法
    14. #==============================================================================
    15. class Game_Party
    16.   # 新增银币和铜币的读取器
    17.   attr_reader   :sliver                  # 银币
    18.   attr_reader   :copper                  # 铜币
    19.   #--------------------------------------------------------------------------
    20.   # ● 初始化对象(重写)
    21.   #--------------------------------------------------------------------------
    22.   alias original_initialize initialize
    23.   def initialize
    24.     original_initialize
    25.     @sliver = 0        # 新增:银币
    26.     @copper = 0        # 新增:铜币
    27.   end
    28.   #--------------------------------------------------------------------------
    29.   # ● 增加银币
    30.   #     n : 数量(正数增加,负数减少)
    31.   #--------------------------------------------------------------------------
    32.   def gain_sliver(n)
    33.     @sliver = [[@sliver + n, 0].max, 9999999].min
    34.   end
    35.   #--------------------------------------------------------------------------
    36.   # ● 减少银币
    37.   #     n : 数量
    38.   #--------------------------------------------------------------------------
    39.   def lose_sliver(n)
    40.     gain_sliver(-n)
    41.   end
    42.   #--------------------------------------------------------------------------
    43.   # ● 增加铜币
    44.   #     n : 数量(正数增加,负数减少)
    45.   #--------------------------------------------------------------------------
    46.   def gain_copper(n)
    47.     @copper = [[@copper + n, 0].max, 9999999].min
    48.   end
    49.   #--------------------------------------------------------------------------
    50.   # ● 减少铜币
    51.   #     n : 数量
    52.   #--------------------------------------------------------------------------
    53.   def lose_copper(n)
    54.     gain_copper(-n)
    55.   end
    56.   #--------------------------------------------------------------------------
    57.   # ● 获取当前活跃货币数量
    58.   #--------------------------------------------------------------------------
    59.   def current_currency
    60.     case$game_variables[10]  # 变量10控制货币类型
    61.     when1then@sliver
    62.     when2then@copper
    63.     else@gold  # 默认金币
    64.     end
    65.   end
    66.   #--------------------------------------------------------------------------
    67.   # ● 获取当前活跃货币名称
    68.   #--------------------------------------------------------------------------
    69.   def current_currency_name
    70.     case$game_variables[10]
    71.     when1then"银币"  # 银币名称
    72.     when2then"铜币"  # 铜币名称
    73.     else$data_system.words.gold  # 原版金币名称
    74.     end
    75.   end
    76.   #--------------------------------------------------------------------------
    77.   # ● 减少当前活跃货币
    78.   #     n : 数量
    79.   #--------------------------------------------------------------------------
    80.   def lose_current_currency(n)
    81.     case$game_variables[10]
    82.     when1then lose_sliver(n)
    83.     when2then lose_copper(n)
    84.     else lose_gold(n)
    85.     end
    86.   end
    87.   #--------------------------------------------------------------------------
    88.   # ● 增加当前活跃货币
    89.   #     n : 数量
    90.   #--------------------------------------------------------------------------
    91.   def gain_current_currency(n)
    92.     case$game_variables[10]
    93.     when1then gain_sliver(n)
    94.     when2then gain_copper(n)
    95.     else gain_gold(n)
    96.     end
    97.   end
    98. end
    99. #==============================================================================
    100. # ■ Window_Gold
    101. #  修改金钱窗口以显示当前活跃货币
    102. #==============================================================================
    103. class Window_Gold < Window_Base
    104.   #--------------------------------------------------------------------------
    105.   # ● 刷新(重写)
    106.   #--------------------------------------------------------------------------
    107.   def refresh
    108.     self.contents.clear
    109.     # 获取当前货币名称和数量
    110.     currency_name = $game_party.current_currency_name
    111.     amount = $game_party.current_currency
    112.     cx = contents.text_size(currency_name).width
    113.     self.contents.font.color = normal_color
    114.     self.contents.draw_text(4, 0, 120 - cx - 2, 32, amount.to_s, 2)
    115.     self.contents.font.color = system_color
    116.     self.contents.draw_text(124 - cx, 0, cx, 32, currency_name, 2)
    117.   end
    118. end
    119. #==============================================================================
    120. # ■ Window_ShopBuy
    121. #  修改商店购买窗口显示当前货币
    122. #==============================================================================
    123. class Window_ShopBuy < Window_Selectable
    124.   #--------------------------------------------------------------------------
    125.   # ● 绘制项目(重写)
    126.   #--------------------------------------------------------------------------
    127.   def draw_item(index)
    128.     item = @data[index]
    129.     case item
    130.     whenRPG::Item
    131.       number = $game_party.item_number(item.id)
    132.     whenRPG::Weapon
    133.       number = $game_party.weapon_number(item.id)
    134.     whenRPG::Armor
    135.       number = $game_party.armor_number(item.id)
    136.     end
    137.     if item.price  $game_party.current_currency
    138.         $game_system.se_play($data_system.buzzer_se)
    139.         return
    140.       end
    141.       # 获取物品持有数量
    142.       case@item
    143.       whenRPG::Item; number = $game_party.item_number(@item.id)
    144.       whenRPG::Weapon; number = $game_party.weapon_number(@item.id)
    145.       whenRPG::Armor; number = $game_party.armor_number(@item.id)
    146.       end
    147.       if number == 99
    148.         $game_system.se_play($data_system.buzzer_se)
    149.         return
    150.       end
    151.       $game_system.se_play($data_system.decision_se)
    152.       # 计算最大购买数量(基于当前货币)
    153.       max = @item.price == 0 ? 99 : $game_party.current_currency / @item.price
    154.       max = [max, 99 - number].min
    155.       @buy_window.active = false
    156.       @buy_window.visible = false
    157.       @number_window.set(@item, max, @item.price)
    158.       @number_window.active = true
    159.       @number_window.visible = true
    160.     end
    161.   end
    162.   #--------------------------------------------------------------------------
    163.   # ● 刷新画面 (个数输入窗口激活的情况下)(修改)
    164.   #--------------------------------------------------------------------------
    165.   def update_number
    166.     if Input.trigger?(Input::B)
    167.       $game_system.se_play($data_system.cancel_se)
    168.       @number_window.active = false
    169.       @number_window.visible = false
    170.       case@command_window.index
    171.       when0
    172.         @buy_window.active = true
    173.         @buy_window.visible = true
    174.       when1
    175.         @sell_window.active = true
    176.         @sell_window.visible = true
    177.         @status_window.visible = false
    178.       end
    179.       return
    180.     end
    181.     if Input.trigger?(Input::C)
    182.       $game_system.se_play($data_system.shop_se)
    183.       @number_window.active = false
    184.       @number_window.visible = false
    185.       case@command_window.index
    186.       when0  # 购买处理(使用当前货币)
    187.         total_price = @number_window.number * @item.price
    188.         $game_party.lose_current_currency(total_price)
    189.         case@item
    190.         whenRPG::Item; $game_party.gain_item(@item.id, @number_window.number)
    191.         whenRPG::Weapon; $game_party.gain_weapon(@item.id, @number_window.number)
    192.         whenRPG::Armor; $game_party.gain_armor(@item.id, @number_window.number)
    193.         end
    194.         @gold_window.refresh
    195.         @buy_window.refresh
    196.         @status_window.refresh
    197.         @buy_window.active = true
    198.         @buy_window.visible = true
    199.       when1  # 卖出处理(获得当前货币)
    200.         total_price = @number_window.number * (@item.price / 2)
    201.         $game_party.gain_current_currency(total_price)
    202.         case@item
    203.         whenRPG::Item; $game_party.lose_item(@item.id, @number_window.number)
    204.         whenRPG::Weapon; $game_party.lose_weapon(@item.id, @number_window.number)
    205.         whenRPG::Armor; $game_party.lose_armor(@item.id, @number_window.number)
    206.         end
    207.         @gold_window.refresh
    208.         @sell_window.refresh
    209.         @status_window.refresh
    210.         @sell_window.active = true
    211.         @sell_window.visible = true
    212.         @status_window.visible = false
    213.       end
    214.       return
    215.     end
    216.   end
    217. end
    复制代码


    后面我在研究怎么魔改菜单的货币窗口,目前的情况是,如果那个十号变量没有归零,菜单的货币窗口显示的是第三或第二货币。
    我下一步要考虑的是,要不把游戏时间和步数窗口废掉,直接竖排显示三种货币,实际上可以魔改扩充更多货币,这只是个思路。

                本帖来自P1论坛作者刘飞洋,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=498008  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。

    本帖子中包含更多资源

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

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

    使用道具 举报

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

    本版积分规则

    关闭

    幸运抽奖

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

    立即查看

    聊天机器人
    Loading...

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

    GMT+8, 2025-8-28 03:01 , Processed in 0.130885 second(s), 50 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

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