查看: 1995|回复: 3

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

[复制链接]
梦石
0
星屑
75
在线时间
27 小时
注册时间
2014-7-19
回帖
87
发表于 2015-2-7 16:42:47 | 显示全部楼层 |阅读模式

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

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

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

[pre lang="Ruby"]class Window_ItemCommand < Window_Command
  attr_accessor :calling_window
  def initialize(width, commands)
    super(width, commands)
    @item = nil
    @calling_window = nil
    self.z = 120
    self.active = false
    self.visible = false
  end
  def item=(item)
    @item = item
    refresh
  end
  def refresh
    self.contents.clear
    (0...@item_max).each do |i|
      draw_item(i, normal_color)
    end
    unless @item.is_a?(RPG::Item) && $game_party.item_can_use?(@item.id)
      disable_item(0)
    end
  end
  def adjust_position
    if @calling_window.nil?
      return
    end
    if @calling_window.cursor_y + 32 + self.height < 480
      self.y = @calling_window.cursor_y + 32
    else
      self.y = @calling_window.cursor_y - self.height
    end
    self.x = @calling_window.cursor_x
  end
end

class Window_Selectable
  def cursor_x
    cursor_width = self.width / @column_max - 32
    x = @index % @column_max * (cursor_width + 32) + self.x + 16
    return x
  end
  def cursor_y
    y = @index / @column_max * 32 - self.oy + self.y + 16
    return y
  end
end


class Window_Dump < Window_Base
  def initialize
    super(0, 0, 176, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.x = 320 - width / 2
    self.y = 240 - height / 2
    self.z = 200
    self.active = false
    self.visible = false
    @Max = 1
    @number = 1
  end
  def set(max)
    @max = max
    @number = 1
    refresh
  end
  def number
    return @number
  end
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(0, 0, 144, 32, "输入丢弃个数")
    self.contents.font.color = normal_color
    self.contents.draw_text(72, 32, 32, 32, "×")
    self.contents.draw_text(104, 32, 24, 32, @number.to_s, 2)
    self.cursor_rect.set(100, 32, 32, 32)
  end
  def update
    super
    if self.active
      # 光标右 (+1)
      if Input.repeat?(Input::RIGHT) and @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number += 1
        refresh
      end
      # 光标左 (-1)
      if Input.repeat?(Input::LEFT) and @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number -= 1
        refresh
      end
      # 光标上 (+10)
      if Input.repeat?(Input::UP) and @number < @max
        $game_system.se_play($data_system.cursor_se)
        @number = [@number + 10, @max].min
        refresh
      end
      # 光标下 (-10)
      if Input.repeat?(Input::DOWN) and @number > 1
        $game_system.se_play($data_system.cursor_se)
        @number = [@number - 10, 1].max
        refresh
      end
    end
  end
end


class Scene_Item
  alias rb_main main
  def main
    @dump_window = Window_Dump.new
    @command_window = Window_ItemCommand.new(108, ["使用", "丢弃"])
    rb_main
    @dump_window.dispose
    @command_window.dispose
  end
  def update
    @command_window.calling_window = @item_window
    @dump_window.update
    @command_window.update
    @help_window.update
    @item_window.update
    @target_window.update
    if @item_window.active
      update_item
      return
    end
    if @target_window.active
      update_target
      return
    end
    if @command_window.active
      update_command
      return
    end
    if @dump_window.active
      update_dump
      return
    end
  end
  def update_item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Menu.new(0)
      return
    end
    if Input.trigger?(Input::C)
      @item = @item_window.item
      if @item.nil?
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      $game_system.se_play($data_system.decision_se)
      @command_window.item = @item
      @command_window.adjust_position
      @command_window.index = 0
      @command_window.active = true
      @command_window.visible = true
      @item_window.active = false
      return
    end
  end
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @command_window.visible = false
      @command_window.active = false
      @item_window.active = true
      return
    end
    if Input.trigger?(Input::C)
      case @command_window.index
      when 0
        unless @item.is_a?(RPG::Item) && $game_party.item_can_use?(@item.id)
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        $game_system.se_play($data_system.decision_se)
        if @item.scope >= 3
          @command_window.active = false
          @command_window.visible = false
          @target_window.x = (@item_window.index + 1) % 2 * 304
          @target_window.visible = true
          @target_window.active = true
          if @item.scope == 4 || @item.scope == 6
            @target_window.index = -1
          else
            @target_window.index = 0
          end
        else
          if @item.common_event_id > 0
            $game_temp.common_event_id = @item.common_event_id
            $game_system.se_play(@item.menu_se)
            if @item.consumable
              $game_party.lose_item(@item.id, 1)
              @item_window.draw_item(@item_window.index)
            end
            $scene = Scene_Map.new
            return
          end
        end
      when 1
        case @item
        when RPG::Item
          number = $game_party.item_number(@item.id)
        when RPG::Weapon
          number = $game_party.weapon_number(@item.id)
        when RPG::Armor
          number = $game_party.weapon_number(@item.id)
        end
        $game_system.se_play($data_system.decision_se)
        @dump_window.set(number)
        @dump_window.visible = true
        @dump_window.active = true
        @command_window.visible = false
        @command_window.active = false
      end
    end
    return
  end
  def update_dump
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @dump_window.visible = false
      @dump_window.active = false
      @command_window.active = true
      @command_window.visible = true
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.shop_se)
      number = @dump_window.number
      case @item
      when RPG::Item
        $game_party.lose_item(@item.id, number)
      when RPG::Weapon
        $game_party.lose_weapon(@item.id, number)
      when RPG::Armor
        $game_party.lose_armor(@item.id, number)
      end
      @dump_window.visible = false
      @dump_window.active = false
      @item_window.active = true
      @item_window.refresh
      return
    end
  end
end
[/pre]
这段代码是版主以前给我的丢弃物品的代码。我想把它改一下,让使用物品时也可以选择数量。我尝试自己估摸着改,但最后总是不成功。请问哪位大神能帮我这样修改一下?  
梦石
0
星屑
75
在线时间
27 小时
注册时间
2014-7-19
回帖
87
 楼主| 发表于 2015-2-7 22:02:25 | 显示全部楼层
自顶……
回复

使用道具 举报

梦石
0
星屑
9557
在线时间
5074 小时
注册时间
2013-6-21
回帖
3459

开拓者贵宾剧作品鉴家

发表于 2015-2-8 19:31:34 | 显示全部楼层
还是我自己写的东西
这个代码最近好像被发出来很多遍。

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

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

点评

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

使用道具 举报

梦石
0
星屑
175
在线时间
332 小时
注册时间
2013-7-6
回帖
316
发表于 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 认可答案

查看全部评分

偶是熬夜学编程的傻子
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部