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

Project1

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

[已经解决] 关于商店价格变动的一个小问题

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
244 小时
注册时间
2010-6-19
帖子
95
跳转到指定楼层
1
发表于 2011-8-19 11:13:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 mmmkly 于 2011-8-19 11:14 编辑

还是商店买卖价、最大值变动脚本的问题
怪我上回没一次问完

脚本
  1. #------------------------------------------------------------------------------
  2. # 商店买卖价、最大值变动脚本 VER 1.3
  3. #
  4. # 更新了脚本关闭的情况下,低于价格的物品仍然可以买的BUG(紧急更新)
  5. # 更新了商店可以买的数目的BUG(紧急更新)
  6. # 可以使商店变动的脚本。
  7. # 更新几个可以关闭功能的方法。
  8. # 制作 by 精灵使者
  9. #------------------------------------------------------------------------------
  10.   #--------------------------------------------------------------------------
  11.   # ● 设定部分
  12.   #--------------------------------------------------------------------------
  13.    BUY_SELL_SWITCH = 1   #默认此脚本的开启开关号,为0则不使用开关,默认开启
  14.    BUY_VARIABLE = 2      #买价浮动变量ID号,如果ID号或者其值为0的话则默认卖价
  15.                          #100的时候也是原卖价,如果是其他数值按照100的比例浮动。
  16.                          #例如200的时候就是原价的2倍,50的时候是原价的一半。
  17.    SELL_VARIABLE = 1     #卖价浮动变量ID号,如果ID号或者值为0的的话则是默认卖价
  18.                          #设置的原理同买价变量(100的时候是原卖价)
  19.    BUY_MAX_VARIABLE = 3  #购买最高个数变量ID号,如果手持物品超过此数则无法购买,
  20.                          #购买变量ID号或者值为0的时候是99个,否则则是可以买物品的
  21.                          #个数。
  22.   
  23. #==============================================================================
  24. # ■ Scene_Shop
  25. #------------------------------------------------------------------------------
  26. #  处理商店画面的类。
  27. #==============================================================================

  28. class Scene_Shop
  29.   #--------------------------------------------------------------------------
  30.   # ● 刷新画面 (购买窗口激活的情况下)
  31.   #--------------------------------------------------------------------------
  32.   def update_buy
  33.     # 设置状态窗口的物品
  34.     @status_window.item = @buy_window.item
  35.     # 按下 B 键的情况下
  36.     if Input.trigger?(Input::B)
  37.       # 演奏取消 SE
  38.       $game_system.se_play($data_system.cancel_se)
  39.       # 窗口状态转向初期模式
  40.       @command_window.active = true
  41.       @dummy_window.visible = true
  42.       @buy_window.active = false
  43.       @buy_window.visible = false
  44.       @status_window.visible = false
  45.       @status_window.item = nil
  46.       # 删除帮助文本
  47.       @help_window.set_text("")
  48.       return
  49.     end
  50.     # 按下 C 键的情况下
  51.     if Input.trigger?(Input::C)
  52.       # 获取物品
  53.       @item = @buy_window.item
  54.       ####################################################################
  55.       # 物品无效的情况下、或者价格在所持金以上的情况下
  56.       if BUY_SELL_SWITCH == 0
  57.       if @item == nil or @item.price * $game_variables[BUY_VARIABLE] / 100 > $game_party.gold
  58.         # 演奏冻结 SE
  59.         $game_system.se_play($data_system.buzzer_se)
  60.         return
  61.       end
  62.       elsif !$game_switches[BUY_SELL_SWITCH] or $game_variables[BUY_VARIABLE] == 0
  63.       if @item == nil or @item.price > $game_party.gold
  64.         # 演奏冻结 SE
  65.         $game_system.se_play($data_system.buzzer_se)
  66.         return
  67.       end
  68.       else
  69.       if @item == nil or @item.price * $game_variables[BUY_VARIABLE] / 100 > $game_party.gold
  70.         # 演奏冻结 SE
  71.         $game_system.se_play($data_system.buzzer_se)
  72.         return
  73.       end
  74.     end
  75.     ###################################################
  76.       # 获取物品所持数
  77.       case @item
  78.       when RPG::Item
  79.         number = $game_party.item_number(@item.id)
  80.       when RPG::Weapon
  81.         number = $game_party.weapon_number(@item.id)
  82.       when RPG::Armor
  83.         number = $game_party.armor_number(@item.id)
  84.       end
  85.       # 如果已经拥有了 99 个情况下
  86.       #####################################################
  87.       if BUY_SELL_SWITCH == 0
  88.         @buy_max = $game_variables[BUY_MAX_VARIABLE]
  89.       elsif !$game_switches[BUY_SELL_SWITCH] or $game_variables[BUY_MAX_VARIABLE] == 0
  90.         @buy_max = 99
  91.       else
  92.         @buy_max = $game_variables[BUY_MAX_VARIABLE]
  93.       end
  94.       if number >= @buy_max
  95.         # 演奏冻结 SE
  96.         $game_system.se_play($data_system.buzzer_se)
  97.         return
  98.       end
  99.       ######################################################
  100.       # 演奏确定 SE
  101.       $game_system.se_play($data_system.decision_se)
  102.       # 计算可以最多购买的数量
  103.       max = @item.price == 0 ? @buy_max : $game_party.gold / @item.price
  104.       max = [max, (@buy_max - number)].min
  105.       # 窗口状态转向数值输入模式
  106.       @buy_window.active = false
  107.       @buy_window.visible = false
  108.       ######################################################
  109.       if BUY_SELL_SWITCH == 0
  110.       @number_window.set(@item, max, @item.price *
  111.       $game_variables[BUY_VARIABLE] / 100)
  112.     elsif !$game_switches[BUY_SELL_SWITCH] or BUY_VARIABLE == 0 or
  113.       $game_variables[BUY_VARIABLE] == 0
  114.       @number_window.set(@item, max, @item.price)
  115.     else
  116.       @number_window.set(@item, max, @item.price *
  117.       $game_variables[BUY_VARIABLE] / 100)
  118.     end
  119.       #####################################################
  120.       @number_window.active = true
  121.       @number_window.visible = true
  122.     end
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # ● 画面更新 (卖出窗口激活的情况下)
  126.   #--------------------------------------------------------------------------
  127.   def update_sell
  128.     # 按下 B 键的情况下
  129.     if Input.trigger?(Input::B)
  130.       # 演奏取消 SE
  131.       $game_system.se_play($data_system.cancel_se)
  132.       # 窗口状态转向初期模式
  133.       @command_window.active = true
  134.       @dummy_window.visible = true
  135.       @sell_window.active = false
  136.       @sell_window.visible = false
  137.       @status_window.item = nil
  138.       # 删除帮助文本
  139.       @help_window.set_text("")
  140.       return
  141.     end
  142.     # 按下 C 键的情况下
  143.     if Input.trigger?(Input::C)
  144.       # 获取物品
  145.       @item = @sell_window.item
  146.       # 设置状态窗口的物品
  147.       @status_window.item = @item
  148.       # 物品无效的情况下、或者价格为 0 (不能卖出) 的情况下
  149.       if @item == nil or @item.price == 0
  150.         # 演奏冻结 SE
  151.         $game_system.se_play($data_system.buzzer_se)
  152.         return
  153.       end
  154.       # 演奏确定 SE
  155.       $game_system.se_play($data_system.decision_se)
  156.       # 获取物品的所持数
  157.       case @item
  158.       when RPG::Item
  159.         number = $game_party.item_number(@item.id)
  160.       when RPG::Weapon
  161.         number = $game_party.weapon_number(@item.id)
  162.       when RPG::Armor
  163.         number = $game_party.armor_number(@item.id)
  164.       end
  165.       # 最大卖出个数 = 物品的所持数
  166.       max = number
  167.       # 窗口状态转向个数输入模式
  168.       @sell_window.active = false
  169.       @sell_window.visible = false
  170.       ###############################################################
  171.       if BUY_SELL_SWITCH == 0
  172.         @number_window.set(@item, max, @item.price *
  173.         $game_variables[SELL_VARIABLE] / 100)
  174.       elsif !$game_switches[BUY_SELL_SWITCH] or SELL_VARIABLE == 0 or
  175.         $game_variables[SELL_VARIABLE] == 0
  176.         @number_window.set(@item, max, @item.price / 2)
  177.       else
  178.         @number_window.set(@item, max, @item.price *
  179.         $game_variables[SELL_VARIABLE] / 100)
  180.       end
  181.       ###############################################################
  182.       @number_window.active = true
  183.       @number_window.visible = true
  184.       @status_window.visible = true
  185.     end
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ● 刷新画面 (个数输入窗口激活的情况下)
  189.   #--------------------------------------------------------------------------
  190.   def update_number
  191.     # 按下 B 键的情况下
  192.     if Input.trigger?(Input::B)
  193.       # 演奏取消 SE
  194.       $game_system.se_play($data_system.cancel_se)
  195.       # 设置个数输入窗口为不活动·非可视状态
  196.       @number_window.active = false
  197.       @number_window.visible = false
  198.       # 命令窗口光标位置分支
  199.       case @command_window.index
  200.       when 0  # 购买
  201.         # 窗口状态转向购买模式
  202.         @buy_window.active = true
  203.         @buy_window.visible = true
  204.       when 1  # 卖出
  205.         # 窗口状态转向卖出模式
  206.         @sell_window.active = true
  207.         @sell_window.visible = true
  208.         @status_window.visible = false
  209.       end
  210.       return
  211.     end
  212.     # 按下 C 键的情况下
  213.     if Input.trigger?(Input::C)
  214.       # 演奏商店 SE
  215.       $game_system.se_play($data_system.shop_se)
  216.       # 设置个数输入窗口为不活动·非可视状态
  217.       @number_window.active = false
  218.       @number_window.visible = false
  219.       # 命令窗口光标位置分支
  220.       case @command_window.index
  221.       when 0  # 购买
  222.         # 购买处理
  223.         ###############################################
  224.       if BUY_SELL_SWITCH == 0
  225.         $game_party.lose_gold(@number_window.number * (@item.price *
  226.         $game_variables[BUY_VARIABLE] / 100))
  227.       elsif !$game_switches[BUY_SELL_SWITCH] or BUY_VARIABLE == 0 or
  228.         $game_variables[BUY_VARIABLE] == 0
  229.         $game_party.lose_gold(@number_window.number * @item.price)
  230.       else
  231.         $game_party.lose_gold(@number_window.number * (@item.price *
  232.         $game_variables[BUY_VARIABLE] / 100))
  233.       end
  234.       ###################################################
  235.         case @item
  236.         when RPG::Item
  237.           $game_party.gain_item(@item.id, @number_window.number)
  238.         when RPG::Weapon
  239.           $game_party.gain_weapon(@item.id, @number_window.number)
  240.         when RPG::Armor
  241.           $game_party.gain_armor(@item.id, @number_window.number)
  242.         end
  243.         # 刷新各窗口
  244.         @gold_window.refresh
  245.         @buy_window.refresh
  246.         @status_window.refresh
  247.         # 窗口状态转向购买模式
  248.         @buy_window.active = true
  249.         @buy_window.visible = true
  250.       when 1  # 卖出
  251.         # 卖出处理
  252.         ###############################################################
  253.       if BUY_SELL_SWITCH == 0
  254.         $game_party.gain_gold(@number_window.number * (@item.price *
  255.         $game_variables[SELL_VARIABLE] / 100))
  256.       elsif !$game_switches[BUY_SELL_SWITCH] or SELL_VARIABLE == 0 or
  257.         $game_variables[SELL_VARIABLE] == 0
  258.         $game_party.gain_gold(@number_window.number * (@item.price / 2))
  259.       else
  260.         $game_party.gain_gold(@number_window.number * (@item.price *
  261.         $game_variables[SELL_VARIABLE] / 100))
  262.       end
  263.         ##############################################################
  264.         case @item
  265.         when RPG::Item
  266.           $game_party.lose_item(@item.id, @number_window.number)
  267.         when RPG::Weapon
  268.           $game_party.lose_weapon(@item.id, @number_window.number)
  269.         when RPG::Armor
  270.           $game_party.lose_armor(@item.id, @number_window.number)
  271.         end
  272.         # 刷新各窗口
  273.         @gold_window.refresh
  274.         @sell_window.refresh
  275.         @status_window.refresh
  276.         # 窗口状态转向卖出模式
  277.         @sell_window.active = true
  278.         @sell_window.visible = true
  279.         @status_window.visible = false
  280.       end
  281.       return
  282.     end
  283.   end
  284. end
  285. #==============================================================================
  286. # ■ Window_ShopBuy
  287. #------------------------------------------------------------------------------
  288. #  商店画面、浏览显示可以购买的商品的窗口。
  289. #==============================================================================

  290. class Window_ShopBuy < Window_Selectable
  291.   #--------------------------------------------------------------------------
  292.   # ● 描绘项目
  293.   #     index : 项目编号
  294.   #--------------------------------------------------------------------------
  295.   def draw_item(index)
  296.     item = @data[index]
  297.     # 获取物品所持数
  298.     case item
  299.     when RPG::Item
  300.       number = $game_party.item_number(item.id)
  301.     when RPG::Weapon
  302.       number = $game_party.weapon_number(item.id)
  303.     when RPG::Armor
  304.       number = $game_party.armor_number(item.id)
  305.     end
  306.     # 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
  307.     # 除此之外的情况设置为无效文字色
  308.     ###############################################################
  309.       if BUY_SELL_SWITCH == 0
  310.         @buy_max = $game_variables[BUY_MAX_VARIABLE]
  311.         if item.price * $game_variables[BUY_VARIABLE] / 100 <= $game_party.gold and number < @buy_max
  312.          self.contents.font.color = normal_color
  313.         else
  314.          self.contents.font.color = disabled_color
  315.         end
  316.       elsif !$game_switches[BUY_SELL_SWITCH] or BUY_MAX_VARIABLE == 0 or
  317.         $game_variables[BUY_VARIABLE] == 0
  318.         @buy_max = 99
  319.         if item.price <= $game_party.gold and number < @buy_max
  320.          self.contents.font.color = normal_color
  321.         else
  322.          self.contents.font.color = disabled_color
  323.         end
  324.       else
  325.         @buy_max = $game_variables[BUY_MAX_VARIABLE]
  326.         if item.price * $game_variables[BUY_VARIABLE] / 100 <= $game_party.gold and number < @buy_max
  327.          self.contents.font.color = normal_color
  328.         else
  329.          self.contents.font.color = disabled_color
  330.         end
  331.       end
  332.     ###############################################################
  333.     x = 4
  334.     y = index * 32
  335.     rect = Rect.new(x, y, self.width - 32, 32)
  336.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  337.     bitmap = RPG::Cache.icon(item.icon_name)
  338.     opacity = self.contents.font.color == normal_color ? 255 : 128
  339.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  340.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  341.     ####################################################
  342.     if BUY_SELL_SWITCH == 0
  343.       self.contents.draw_text(x + 240, y, 88, 32, (item.price *
  344.       $game_variables[BUY_VARIABLE] / 100).to_s, 2)
  345.     elsif !$game_switches[BUY_SELL_SWITCH] or BUY_VARIABLE == 0 or
  346.        $game_variables[BUY_VARIABLE] == 0
  347.       self.contents.draw_text(x + 240, y, 88, 32, item.price.to_s, 2)
  348.     else
  349.       self.contents.draw_text(x + 240, y, 88, 32, (item.price *
  350.       $game_variables[BUY_VARIABLE] / 100).to_s, 2)
  351.     end
  352.     #####################################################
  353.   end
  354. end
复制代码
问题在于
如果是降价处理的话
钱不够原价格的话就只能一个一个买

举个例子
一瓶药水10000元
身上有10000元
降价为1%
药水变为100元
可以买100瓶
但是只能1瓶1瓶的购买

问下怎么解决
谢谢了
没事做个游戏
暗黑-外传
剧情:■■■■■□□□□□
脚本:■■■■■■■■■□
素材:■■■■■■■■■■
地图:■■■■■■■■■□
系统:■■■■■■■■□□
整体完成度:■■■■■■■□□□
发布日期:未知

Lv6.析梦学徒

Fuzzy Ginkgo
Taciturn Knight

梦石
0
星屑
60575
在线时间
1933 小时
注册时间
2010-6-26
帖子
1605

烫烫烫开拓者

2
发表于 2011-8-19 13:18:46 | 只看该作者
184 行附近
  1. # 计算可以最多购买的数量
  2.       max = @item.price == 0 ? @buy_max : $game_party.gold / @item.price
复制代码
改成
  1. # 计算可以最多购买的数量
  2.       max = @item.price == 0 ? @buy_max : $game_party.gold / (@item.price * $game_variables[BUY_VARIABLE] / 100)
复制代码
我的言论只代表我个人的观点,不代表雇主及/或任何第三方的立场。
Opinions expressed are solely my own and do not express the views or opinions of my employer and/or any third parties.
捐赠 | GitHub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

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

GMT+8, 2024-4-29 03:50

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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