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

Project1

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

[已经过期] 这个代码有没有办法改一下?

[复制链接]

Lv1.梦旅人

梦石
0
星屑
75
在线时间
27 小时
注册时间
2014-7-19
帖子
110
跳转到指定楼层
1
发表于 2015-2-7 16:42:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 RyanBern 于 2015-2-8 19:26 编辑

RUBY 代码复制
  1. class Window_ItemCommand < Window_Command
  2.   attr_accessor :calling_window
  3.   def initialize(width, commands)
  4.     super(width, commands)
  5.     @item = nil
  6.     @calling_window = nil
  7.     self.z = 120
  8.     self.active = false
  9.     self.visible = false
  10.   end
  11.   def item=(item)
  12.     @item = item
  13.     refresh
  14.   end
  15.   def refresh
  16.     self.contents.clear
  17.     (0...@item_max).each do |i|
  18.       draw_item(i, normal_color)
  19.     end
  20.     unless @item.is_a?(RPG::Item) && $game_party.item_can_use?(@item.id)
  21.       disable_item(0)
  22.     end
  23.   end
  24.   def adjust_position
  25.     if @calling_window.nil?
  26.       return
  27.     end
  28.     if @calling_window.cursor_y + 32 + self.height < 480
  29.       self.y = @calling_window.cursor_y + 32
  30.     else
  31.       self.y = @calling_window.cursor_y - self.height
  32.     end
  33.     self.x = @calling_window.cursor_x
  34.   end
  35. end
  36.  
  37. class Window_Selectable
  38.   def cursor_x
  39.     cursor_width = self.width / @column_max - 32
  40.     x = @index % @column_max * (cursor_width + 32) + self.x + 16
  41.     return x
  42.   end
  43.   def cursor_y
  44.     y = @index / @column_max * 32 - self.oy + self.y + 16
  45.     return y
  46.   end
  47. end
  48.  
  49.  
  50. class Window_Dump < Window_Base
  51.   def initialize
  52.     super(0, 0, 176, 96)
  53.     self.contents = Bitmap.new(width - 32, height - 32)
  54.     self.x = 320 - width / 2
  55.     self.y = 240 - height / 2
  56.     self.z = 200
  57.     self.active = false
  58.     self.visible = false
  59.     [url=home.php?mod=space&uid=25307]@Max[/url] = 1
  60.     @number = 1
  61.   end
  62.   def set(max)
  63.     @max = max
  64.     @number = 1
  65.     refresh
  66.   end
  67.   def number
  68.     return @number
  69.   end
  70.   def refresh
  71.     self.contents.clear
  72.     self.contents.font.color = system_color
  73.     self.contents.draw_text(0, 0, 144, 32, "输入丢弃个数")
  74.     self.contents.font.color = normal_color
  75.     self.contents.draw_text(72, 32, 32, 32, "×")
  76.     self.contents.draw_text(104, 32, 24, 32, @number.to_s, 2)
  77.     self.cursor_rect.set(100, 32, 32, 32)
  78.   end
  79.   def update
  80.     super
  81.     if self.active
  82.       # 光标右 (+1)
  83.       if Input.repeat?(Input::RIGHT) and @number < @max
  84.         $game_system.se_play($data_system.cursor_se)
  85.         @number += 1
  86.         refresh
  87.       end
  88.       # 光标左 (-1)
  89.       if Input.repeat?(Input::LEFT) and @number > 1
  90.         $game_system.se_play($data_system.cursor_se)
  91.         @number -= 1
  92.         refresh
  93.       end
  94.       # 光标上 (+10)
  95.       if Input.repeat?(Input::UP) and @number < @max
  96.         $game_system.se_play($data_system.cursor_se)
  97.         @number = [@number + 10, @max].min
  98.         refresh
  99.       end
  100.       # 光标下 (-10)
  101.       if Input.repeat?(Input::DOWN) and @number > 1
  102.         $game_system.se_play($data_system.cursor_se)
  103.         @number = [@number - 10, 1].max
  104.         refresh
  105.       end
  106.     end
  107.   end
  108. end
  109.  
  110.  
  111. class Scene_Item
  112.   alias rb_main main
  113.   def main
  114.     @dump_window = Window_Dump.new
  115.     @command_window = Window_ItemCommand.new(108, ["使用", "丢弃"])
  116.     rb_main
  117.     @dump_window.dispose
  118.     @command_window.dispose
  119.   end
  120.   def update
  121.     @command_window.calling_window = @item_window
  122.     @dump_window.update
  123.     @command_window.update
  124.     @help_window.update
  125.     @item_window.update
  126.     @target_window.update
  127.     if @item_window.active
  128.       update_item
  129.       return
  130.     end
  131.     if @target_window.active
  132.       update_target
  133.       return
  134.     end
  135.     if @command_window.active
  136.       update_command
  137.       return
  138.     end
  139.     if @dump_window.active
  140.       update_dump
  141.       return
  142.     end
  143.   end
  144.   def update_item
  145.     if Input.trigger?(Input::B)
  146.       $game_system.se_play($data_system.cancel_se)
  147.       $scene = Scene_Menu.new(0)
  148.       return
  149.     end
  150.     if Input.trigger?(Input::C)
  151.       @item = @item_window.item
  152.       if @item.nil?
  153.         $game_system.se_play($data_system.buzzer_se)
  154.         return
  155.       end
  156.       $game_system.se_play($data_system.decision_se)
  157.       @command_window.item = @item
  158.       @command_window.adjust_position
  159.       @command_window.index = 0
  160.       @command_window.active = true
  161.       @command_window.visible = true
  162.       @item_window.active = false
  163.       return
  164.     end
  165.   end
  166.   def update_command
  167.     if Input.trigger?(Input::B)
  168.       $game_system.se_play($data_system.cancel_se)
  169.       @command_window.visible = false
  170.       @command_window.active = false
  171.       @item_window.active = true
  172.       return
  173.     end
  174.     if Input.trigger?(Input::C)
  175.       case @command_window.index
  176.       when 0
  177.         unless @item.is_a?(RPG::Item) && $game_party.item_can_use?(@item.id)
  178.           $game_system.se_play($data_system.buzzer_se)
  179.           return
  180.         end
  181.         $game_system.se_play($data_system.decision_se)
  182.         if @item.scope >= 3
  183.           @command_window.active = false
  184.           @command_window.visible = false
  185.           @target_window.x = (@item_window.index + 1) % 2 * 304
  186.           @target_window.visible = true
  187.           @target_window.active = true
  188.           if @item.scope == 4 || @item.scope == 6
  189.             @target_window.index = -1
  190.           else
  191.             @target_window.index = 0
  192.           end
  193.         else
  194.           if @item.common_event_id > 0
  195.             $game_temp.common_event_id = @item.common_event_id
  196.             $game_system.se_play(@item.menu_se)
  197.             if @item.consumable
  198.               $game_party.lose_item(@item.id, 1)
  199.               @item_window.draw_item(@item_window.index)
  200.             end
  201.             $scene = Scene_Map.new
  202.             return
  203.           end
  204.         end
  205.       when 1
  206.         case @item
  207.         when RPG::Item
  208.           number = $game_party.item_number(@item.id)
  209.         when RPG::Weapon
  210.           number = $game_party.weapon_number(@item.id)
  211.         when RPG::Armor
  212.           number = $game_party.weapon_number(@item.id)
  213.         end
  214.         $game_system.se_play($data_system.decision_se)
  215.         @dump_window.set(number)
  216.         @dump_window.visible = true
  217.         @dump_window.active = true
  218.         @command_window.visible = false
  219.         @command_window.active = false
  220.       end
  221.     end
  222.     return
  223.   end
  224.   def update_dump
  225.     if Input.trigger?(Input::B)
  226.       $game_system.se_play($data_system.cancel_se)
  227.       @dump_window.visible = false
  228.       @dump_window.active = false
  229.       @command_window.active = true
  230.       @command_window.visible = true
  231.       return
  232.     end
  233.     if Input.trigger?(Input::C)
  234.       $game_system.se_play($data_system.shop_se)
  235.       number = @dump_window.number
  236.       case @item
  237.       when RPG::Item
  238.         $game_party.lose_item(@item.id, number)
  239.       when RPG::Weapon
  240.         $game_party.lose_weapon(@item.id, number)
  241.       when RPG::Armor
  242.         $game_party.lose_armor(@item.id, number)
  243.       end
  244.       @dump_window.visible = false
  245.       @dump_window.active = false
  246.       @item_window.active = true
  247.       @item_window.refresh
  248.       return
  249.     end
  250.   end
  251. end

这段代码是版主以前给我的丢弃物品的代码。我想把它改一下,让使用物品时也可以选择数量。我尝试自己估摸着改,但最后总是不成功。请问哪位大神能帮我这样修改一下?  

Lv1.梦旅人

梦石
0
星屑
75
在线时间
27 小时
注册时间
2014-7-19
帖子
110
2
 楼主| 发表于 2015-2-7 22:02:25 | 只看该作者
自顶……
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

梦石
0
星屑
9497
在线时间
5073 小时
注册时间
2013-6-21
帖子
3580

开拓者贵宾剧作品鉴家

3
发表于 2015-2-8 19:31:34 | 只看该作者
还是我自己写的东西
这个代码最近好像被发出来很多遍。

使用物品的话,使用的数量有点不好办。因为通常可以设置使用数量的物品要根据它的作用而言。比如说药水一类的物品,使用时要指定目标,如果这时也要同时指定数量,用起来就不太爽快。使用带有公共事件的物品时,设置使用数量就不太好。

所以可否说明一下,这种物品的功能是怎样的呢?

点评

目标就是唯一一个角色  发表于 2015-2-8 20:45
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
150
在线时间
332 小时
注册时间
2013-7-6
帖子
356
4
发表于 2015-2-11 22:09:34 | 只看该作者
  1. class Window_ItemCommand < Window_Command
  2.   attr_accessor :calling_window
  3.   def initialize(width, commands)
  4.     super(width, commands)
  5.     @item = nil
  6.     @calling_window = nil
  7.     self.z = 120
  8.     self.active = false
  9.     self.visible = false
  10.   end
  11.   def item=(item)
  12.     @item = item
  13.     refresh
  14.   end
  15.   def refresh
  16.     self.contents.clear
  17.     (0...@item_max).each do |i|
  18.       draw_item(i, normal_color)
  19.     end
  20.     unless @item.is_a?(RPG::Item) && $game_party.item_can_use?(@item.id)
  21.       disable_item(0)
  22.     end
  23.   end
  24.   def adjust_position
  25.     if @calling_window.nil?
  26.       return
  27.     end
  28.     if @calling_window.cursor_y + 32 + self.height < 480
  29.       self.y = @calling_window.cursor_y + 32
  30.     else
  31.       self.y = @calling_window.cursor_y - self.height
  32.     end
  33.     self.x = @calling_window.cursor_x
  34.   end
  35. end
  36. class Window_Selectable
  37.   def cursor_x
  38.     cursor_width = self.width / @column_max - 32
  39.     x = @index % @column_max * (cursor_width + 32) + self.x + 16
  40.     return x
  41.   end
  42.   def cursor_y
  43.     y = @index / @column_max * 32 - self.oy + self.y + 16
  44.     return y
  45.   end
  46. end
  47. class Window_Dump < Window_Base
  48.   def initialize
  49.     super(0, 0, 176, 96)
  50.     self.contents = Bitmap.new(width - 32, height - 32)
  51.     self.x = 320 - width / 2
  52.     self.y = 240 - height / 2
  53.     self.z = 200
  54.     self.active = false
  55.     self.visible = false
  56.     @Max = 1
  57.     @number = 1
  58.   end
  59.   def set(max)
  60.     @max = max
  61.     @number = 1
  62.     refresh
  63.   end
  64.   def number
  65.     return @number
  66.   end
  67.   def refresh
  68.     self.contents.clear
  69.     self.contents.font.color = system_color
  70.     self.contents.draw_text(0, 0, 144, 32, "输入个数")
  71.     self.contents.font.color = normal_color
  72.     self.contents.draw_text(72, 32, 32, 32, "×")
  73.     self.contents.draw_text(104, 32, 24, 32, @number.to_s, 2)
  74.     self.cursor_rect.set(100, 32, 32, 32)
  75.   end
  76.   def update
  77.     super
  78.     if self.active
  79.       # 光标右 (+1)
  80.       if Input.repeat?(Input::RIGHT) and @number < @max
  81.         $game_system.se_play($data_system.cursor_se)
  82.         @number += 1
  83.         refresh
  84.       end
  85.       # 光标左 (-1)
  86.       if Input.repeat?(Input::LEFT) and @number > 1
  87.         $game_system.se_play($data_system.cursor_se)
  88.         @number -= 1
  89.         refresh
  90.       end
  91.       # 光标上 (+10)
  92.       if Input.repeat?(Input::UP) and @number < @max
  93.         $game_system.se_play($data_system.cursor_se)
  94.         @number = [@number + 10, @max].min
  95.         refresh
  96.       end
  97.       # 光标下 (-10)
  98.       if Input.repeat?(Input::DOWN) and @number > 1
  99.         $game_system.se_play($data_system.cursor_se)
  100.         @number = [@number - 10, 1].max
  101.         refresh
  102.       end
  103.     end
  104.   end
  105. end
  106. class Scene_Item
  107.   alias rb_main main
  108.   def main
  109.     @dump_window = Window_Dump.new
  110.     @command_window = Window_ItemCommand.new(108, ["使用", "丢弃"])
  111.     rb_main
  112.     @dump_window.dispose
  113.     @command_window.dispose
  114.   end
  115.   def update
  116.     @command_window.calling_window = @item_window
  117.     @dump_window.update
  118.     @command_window.update
  119.     @help_window.update
  120.     @item_window.update
  121.     @target_window.update
  122.     if @item_window.active
  123.       update_item
  124.       return
  125.     end
  126.     if @target_window.active
  127.       update_target
  128.       return
  129.     end
  130.     if @command_window.active
  131.       update_command
  132.       return
  133.     end
  134.     if @dump_window.active
  135.       update_dump
  136.       return
  137.     end
  138.   end
  139.   def update_item
  140.     if Input.trigger?(Input::B)
  141.       $game_system.se_play($data_system.cancel_se)
  142.       $scene = Scene_Menu.new(0)
  143.       return
  144.     end
  145.     if Input.trigger?(Input::C)
  146.       @item = @item_window.item
  147.       if @item.nil?
  148.         $game_system.se_play($data_system.buzzer_se)
  149.         return
  150.       end
  151.       $game_system.se_play($data_system.decision_se)
  152.       @command_window.item = @item
  153.       @command_window.adjust_position
  154.       @command_window.index = 0
  155.       @command_window.active = true
  156.       @command_window.visible = true
  157.       @item_window.active = false
  158.       return
  159.     end
  160.   end
  161.   def update_command
  162.     if Input.trigger?(Input::B)
  163.       $game_system.se_play($data_system.cancel_se)
  164.       @command_window.visible = false
  165.       @command_window.active = false
  166.       @item_window.active = true
  167.       return
  168.     end
  169.     if Input.trigger?(Input::C)
  170.       case @command_window.index
  171.       when 0
  172.         unless @item.is_a?(RPG::Item) && $game_party.item_can_use?(@item.id)
  173.           $game_system.se_play($data_system.buzzer_se)
  174.           return
  175.         end
  176.         $game_system.se_play($data_system.decision_se)
  177.         if @item.scope >= 3
  178.           @use=true
  179.           @dump_window.set($game_party.item_number(@item.id))
  180.           @dump_window.visible = true
  181.           @dump_window.active = true
  182.           @command_window.visible = false
  183.           @command_window.active = false
  184.         else
  185.           if @item.common_event_id > 0
  186.             $game_temp.common_event_id = @item.common_event_id
  187.             $game_system.se_play(@item.menu_se)
  188.             if @item.consumable
  189.               $game_party.lose_item(@item.id, 1)
  190.               @item_window.draw_item(@item_window.index)
  191.             end
  192.             $scene = Scene_Map.new
  193.             return
  194.           end
  195.         end
  196.       when 1
  197.         case @item
  198.         when RPG::Item
  199.           number = $game_party.item_number(@item.id)
  200.         when RPG::Weapon
  201.           number = $game_party.weapon_number(@item.id)
  202.         when RPG::Armor
  203.           number = $game_party.weapon_number(@item.id)
  204.         end
  205.         $game_system.se_play($data_system.decision_se)
  206.         @use=false
  207.         @dump_window.set(number)
  208.         @dump_window.visible = true
  209.         @dump_window.active = true
  210.         @command_window.visible = false
  211.         @command_window.active = false
  212.       end
  213.     end
  214.     return
  215.   end
  216.   def update_target
  217.     # 按下 B 键的情况下
  218.     if Input.trigger?(Input::B)
  219.       # 演奏取消 SE
  220.       $game_system.se_play($data_system.cancel_se)
  221.       # 由于物品用完而不能使用的场合
  222.       unless $game_party.item_can_use?(@item.id)
  223.         # 再次生成物品窗口的内容
  224.         @item_window.refresh
  225.       end
  226.       # 删除目标窗口
  227.       @item_window.active = true
  228.       @target_window.visible = false
  229.       @target_window.active = false
  230.       return
  231.     end
  232.     # 按下 C 键的情况下
  233.     if Input.trigger?(Input::C)
  234.       # 如果物品用完的情况下
  235.       if $game_party.item_number(@item.id) < @numbersss
  236.         # 演奏冻结 SE
  237.         $game_system.se_play($data_system.buzzer_se)
  238.         return
  239.       end
  240.       # 目标是全体的情况下
  241.       if @target_window.index == -1
  242.         # 对同伴全体应用物品使用效果
  243.         @numbersss.times do
  244.           used = false
  245.           for i in $game_party.actors
  246.             used |= i.item_effect(@item)
  247.           end
  248.         end
  249.       end
  250.       # 目标是单体的情况下
  251.       if @target_window.index >= 0
  252.         # 对目标角色应用物品的使用效果
  253.         @numbersss.times do
  254.           target = $game_party.actors[@target_window.index]
  255.           target.item_effect(@item)
  256.         end
  257.       end
  258.       # 演奏物品使用时的 SE
  259.       $game_system.se_play(@item.menu_se)
  260.       # 消耗品的情况下
  261.       if @item.consumable
  262.         # 使用的物品数减 @numbersss
  263.         $game_party.lose_item(@item.id, @numbersss)
  264.         # 再描绘物品窗口的项目
  265.         @item_window.draw_item(@item_window.index)
  266.       end
  267.       # 再生成目标窗口的内容
  268.       @target_window.refresh
  269.       @target_window.active = false
  270.       @target_window.visible = false
  271.       @dump_window.visible = false
  272.       @item_window.active = true
  273.       @item_window.refresh
  274.       # 全灭的情况下
  275.       if $game_party.all_dead?
  276.         # 切换到游戏结束画面
  277.         $scene = Scene_Gameover.new
  278.         return
  279.       end
  280.       # 公共事件 ID 有效的情况下
  281.       if @item.common_event_id > 0
  282.         # 预约调用公共事件
  283.         $game_temp.common_event_id = @item.common_event_id
  284.         # 切换到地图画面
  285.         $scene = Scene_Map.new
  286.         return
  287.       end
  288.       return
  289.     end
  290.   end
  291.   def update_dump
  292.     if Input.trigger?(Input::B)
  293.       $game_system.se_play($data_system.cancel_se)
  294.       @dump_window.visible = false
  295.       @dump_window.active = false
  296.       @command_window.active = true
  297.       @command_window.visible = true
  298.       return
  299.     end
  300.     if Input.trigger?(Input::C)
  301.       number = @dump_window.number
  302.       if @use
  303.         @numbersss=number
  304.         @dump_window.active = false
  305.         @target_window.x = (@item_window.index + 1) % 2 * 304
  306.         @target_window.visible = true
  307.         @target_window.active = true
  308.         if @item.scope == 4 || @item.scope == 6
  309.           @target_window.index = -1
  310.         else
  311.           @target_window.index = 0
  312.         end
  313.       else
  314.         $game_system.se_play($data_system.shop_se)
  315.         case @item
  316.         when RPG::Item
  317.           $game_party.lose_item(@item.id, number)
  318.         when RPG::Weapon
  319.           $game_party.lose_weapon(@item.id, number)
  320.         when RPG::Armor
  321.           $game_party.lose_armor(@item.id, number)
  322.         end
  323.         @dump_window.visible = false
  324.         @dump_window.active = false
  325.         @item_window.active = true
  326.         @item_window.refresh
  327.         return
  328.       end
  329.     end
  330.   end
  331. end
复制代码
改好了,看看怎么样,使用数量只能对可使用物品有效。

点评

谢谢!原谅我现在才看到。  发表于 2015-6-22 02:04

评分

参与人数 1星屑 +100 梦石 +1 收起 理由
hys111111 + 100 + 1 认可答案

查看全部评分

偶是熬夜学编程的傻子
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-7 02:50

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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