设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 121|回复: 0
打印 上一主题 下一主题

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

[复制链接]

Lv2.观梦者

梦石
0
星屑
657
在线时间
508 小时
注册时间
2011-4-25
帖子
167
跳转到指定楼层
1
发表于 2025-8-27 18:49:40 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 刘飞洋 于 2025-8-27 19:08 编辑

通过十号变量来切换商店显示的货币,本脚本还解决了其他第二货币脚本的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. #==============================================================================
  13. # ■ Game_Party
  14. #  新增银币和铜币的属性及相关方法
  15. #==============================================================================
  16. class Game_Party
  17.   # 新增银币和铜币的读取器
  18.   attr_reader   :sliver                  # 银币
  19.   attr_reader   :copper                  # 铜币
  20.  
  21.   #--------------------------------------------------------------------------
  22.   # ● 初始化对象(重写)
  23.   #--------------------------------------------------------------------------
  24.   alias original_initialize initialize
  25.   def initialize
  26.     original_initialize
  27.     @sliver = 0        # 新增:银币
  28.     @copper = 0        # 新增:铜币
  29.   end
  30.  
  31.   #--------------------------------------------------------------------------
  32.   # ● 增加银币
  33.   #     n : 数量(正数增加,负数减少)
  34.   #--------------------------------------------------------------------------
  35.   def gain_sliver(n)
  36.     @sliver = [[@sliver + n, 0].max, 9999999].min
  37.   end
  38.  
  39.   #--------------------------------------------------------------------------
  40.   # ● 减少银币
  41.   #     n : 数量
  42.   #--------------------------------------------------------------------------
  43.   def lose_sliver(n)
  44.     gain_sliver(-n)
  45.   end
  46.  
  47.   #--------------------------------------------------------------------------
  48.   # ● 增加铜币
  49.   #     n : 数量(正数增加,负数减少)
  50.   #--------------------------------------------------------------------------
  51.   def gain_copper(n)
  52.     @copper = [[@copper + n, 0].max, 9999999].min
  53.   end
  54.  
  55.   #--------------------------------------------------------------------------
  56.   # ● 减少铜币
  57.   #     n : 数量
  58.   #--------------------------------------------------------------------------
  59.   def lose_copper(n)
  60.     gain_copper(-n)
  61.   end
  62.  
  63.   #--------------------------------------------------------------------------
  64.   # ● 获取当前活跃货币数量
  65.   #--------------------------------------------------------------------------
  66.   def current_currency
  67.     case $game_variables[10]  # 变量10控制货币类型
  68.     when 1 then @sliver
  69.     when 2 then @copper
  70.     else @gold  # 默认金币
  71.     end
  72.   end
  73.  
  74.   #--------------------------------------------------------------------------
  75.   # ● 获取当前活跃货币名称
  76.   #--------------------------------------------------------------------------
  77.   def current_currency_name
  78.     case $game_variables[10]
  79.     when 1 then "银币"  # 银币名称
  80.     when 2 then "铜币"  # 铜币名称
  81.     else $data_system.words.gold  # 原版金币名称
  82.     end
  83.   end
  84.  
  85.   #--------------------------------------------------------------------------
  86.   # ● 减少当前活跃货币
  87.   #     n : 数量
  88.   #--------------------------------------------------------------------------
  89.   def lose_current_currency(n)
  90.     case $game_variables[10]
  91.     when 1 then lose_sliver(n)
  92.     when 2 then lose_copper(n)
  93.     else lose_gold(n)
  94.     end
  95.   end
  96.  
  97.   #--------------------------------------------------------------------------
  98.   # ● 增加当前活跃货币
  99.   #     n : 数量
  100.   #--------------------------------------------------------------------------
  101.   def gain_current_currency(n)
  102.     case $game_variables[10]
  103.     when 1 then gain_sliver(n)
  104.     when 2 then gain_copper(n)
  105.     else gain_gold(n)
  106.     end
  107.   end
  108. end
  109.  
  110. #==============================================================================
  111. # ■ Window_Gold
  112. #  修改金钱窗口以显示当前活跃货币
  113. #==============================================================================
  114. class Window_Gold < Window_Base
  115.   #--------------------------------------------------------------------------
  116.   # ● 刷新(重写)
  117.   #--------------------------------------------------------------------------
  118.   def refresh
  119.     self.contents.clear
  120.     # 获取当前货币名称和数量
  121.     currency_name = $game_party.current_currency_name
  122.     amount = $game_party.current_currency
  123.  
  124.     cx = contents.text_size(currency_name).width
  125.     self.contents.font.color = normal_color
  126.     self.contents.draw_text(4, 0, 120 - cx - 2, 32, amount.to_s, 2)
  127.     self.contents.font.color = system_color
  128.     self.contents.draw_text(124 - cx, 0, cx, 32, currency_name, 2)
  129.   end
  130. end
  131.  
  132. #==============================================================================
  133. # ■ Window_ShopBuy
  134. #  修改商店购买窗口显示当前货币
  135. #==============================================================================
  136. class Window_ShopBuy < Window_Selectable
  137.   #--------------------------------------------------------------------------
  138.   # ● 绘制项目(重写)
  139.   #--------------------------------------------------------------------------
  140.   def draw_item(index)
  141.     item = @data[index]
  142.     case item
  143.     when RPG::Item
  144.       number = $game_party.item_number(item.id)
  145.     when RPG::Weapon
  146.       number = $game_party.weapon_number(item.id)
  147.     when RPG::Armor
  148.       number = $game_party.armor_number(item.id)
  149.     end
  150.     if item.price <= 0 or number == 99
  151.       self.contents.font.color = disabled_color
  152.     else
  153.       self.contents.font.color = normal_color
  154.     end
  155.     x = 4
  156.     y = index * 32
  157.     rect = Rect.new(x, y, self.width - 32, 32)
  158.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  159.     bitmap = RPG::Cache.icon(item.icon_name)
  160.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  161.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  162.     # 显示价格和当前货币
  163.     currency_name = $game_party.current_currency_name
  164.     self.contents.draw_text(x + 240, y, 88, 32, item.price.to_s + " " + currency_name, 2)
  165.   end
  166. end
  167.  
  168. #==============================================================================
  169. # ■ Window_ShopNumber
  170. #  修改数量选择窗口显示当前货币
  171. #==============================================================================
  172. class Window_ShopNumber < Window_Base
  173.   #--------------------------------------------------------------------------
  174.   # ● 设置(重写)
  175.   #     item      : 物品
  176.   #     max       : 最大数量
  177.   #     price     : 单价
  178.   #--------------------------------------------------------------------------
  179.   def set(item, max, price)
  180.     @item = item
  181.     @max = max
  182.     @price = price
  183.     @number = 1
  184.     currency_name = $game_party.current_currency_name
  185.     refresh
  186.   end
  187.  
  188.   #--------------------------------------------------------------------------
  189.   # ● 刷新(重写)
  190.   #--------------------------------------------------------------------------
  191.   def refresh
  192.     self.contents.clear
  193.     # 绘制物品名称
  194.     draw_item_name(@item, 4, 0)
  195.     # 绘制数量输入
  196.     self.contents.font.color = normal_color
  197.     self.contents.draw_text(272, 0, 32, 32, "×", 1)
  198.     self.contents.draw_text(304, 0, 24, 32, @number.to_s, 2)
  199.     # 绘制总价和当前货币
  200.     currency_name = $game_party.current_currency_name
  201.     total = @price * @number
  202.     self.contents.font.color = system_color
  203.     self.contents.draw_text(4, 32, 120, 32, "总计", 0)
  204.     self.contents.font.color = normal_color
  205.     self.contents.draw_text(124, 32, 160, 32, total.to_s + " " + currency_name, 2)
  206.   end
  207. end
  208.  
  209. #==============================================================================
  210. # ■ Scene_Shop
  211. #  修改商店场景以支持多货币交易
  212. #==============================================================================
  213. class Scene_Shop
  214.   #--------------------------------------------------------------------------
  215.   # ● 刷新画面 (购买窗口激活的情况下)(修改)
  216.   #--------------------------------------------------------------------------
  217.   def update_buy
  218.     @status_window.item = @buy_window.item
  219.     if Input.trigger?(Input::B)
  220.       $game_system.se_play($data_system.cancel_se)
  221.       @command_window.active = true
  222.       @dummy_window.visible = true
  223.       @buy_window.active = false
  224.       @buy_window.visible = false
  225.       @status_window.visible = false
  226.       @status_window.item = nil
  227.       @help_window.set_text("")
  228.       return
  229.     end
  230.     if Input.trigger?(Input::C)
  231.       @item = @buy_window.item
  232.       # 检查物品有效性和当前货币是否足够
  233.       if @item == nil or @item.price > $game_party.current_currency
  234.         $game_system.se_play($data_system.buzzer_se)
  235.         return
  236.       end
  237.       # 获取物品持有数量
  238.       case @item
  239.       when RPG::Item; number = $game_party.item_number(@item.id)
  240.       when RPG::Weapon; number = $game_party.weapon_number(@item.id)
  241.       when RPG::Armor; number = $game_party.armor_number(@item.id)
  242.       end
  243.       if number == 99
  244.         $game_system.se_play($data_system.buzzer_se)
  245.         return
  246.       end
  247.       $game_system.se_play($data_system.decision_se)
  248.       # 计算最大购买数量(基于当前货币)
  249.       max = @item.price == 0 ? 99 : $game_party.current_currency / @item.price
  250.       max = [max, 99 - number].min
  251.       @buy_window.active = false
  252.       @buy_window.visible = false
  253.       @number_window.set(@item, max, @item.price)
  254.       @number_window.active = true
  255.       @number_window.visible = true
  256.     end
  257.   end
  258.  
  259.   #--------------------------------------------------------------------------
  260.   # ● 刷新画面 (个数输入窗口激活的情况下)(修改)
  261.   #--------------------------------------------------------------------------
  262.   def update_number
  263.     if Input.trigger?(Input::B)
  264.       $game_system.se_play($data_system.cancel_se)
  265.       @number_window.active = false
  266.       @number_window.visible = false
  267.       case @command_window.index
  268.       when 0
  269.         @buy_window.active = true
  270.         @buy_window.visible = true
  271.       when 1
  272.         @sell_window.active = true
  273.         @sell_window.visible = true
  274.         @status_window.visible = false
  275.       end
  276.       return
  277.     end
  278.     if Input.trigger?(Input::C)
  279.       $game_system.se_play($data_system.shop_se)
  280.       @number_window.active = false
  281.       @number_window.visible = false
  282.       case @command_window.index
  283.       when 0  # 购买处理(使用当前货币)
  284.         total_price = @number_window.number * @item.price
  285.         $game_party.lose_current_currency(total_price)
  286.         case @item
  287.         when RPG::Item; $game_party.gain_item(@item.id, @number_window.number)
  288.         when RPG::Weapon; $game_party.gain_weapon(@item.id, @number_window.number)
  289.         when RPG::Armor; $game_party.gain_armor(@item.id, @number_window.number)
  290.         end
  291.         @gold_window.refresh
  292.         @buy_window.refresh
  293.         @status_window.refresh
  294.         @buy_window.active = true
  295.         @buy_window.visible = true
  296.       when 1  # 卖出处理(获得当前货币)
  297.         total_price = @number_window.number * (@item.price / 2)
  298.         $game_party.gain_current_currency(total_price)
  299.         case @item
  300.         when RPG::Item; $game_party.lose_item(@item.id, @number_window.number)
  301.         when RPG::Weapon; $game_party.lose_weapon(@item.id, @number_window.number)
  302.         when RPG::Armor; $game_party.lose_armor(@item.id, @number_window.number)
  303.         end
  304.         @gold_window.refresh
  305.         @sell_window.refresh
  306.         @status_window.refresh
  307.         @sell_window.active = true
  308.         @sell_window.visible = true
  309.         @status_window.visible = false
  310.       end
  311.       return
  312.     end
  313.   end
  314. end


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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-9-6 06:15

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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