查看: 2297|回复: 1

[已经解决] 武器仓库修改为装备仓库的问题

[复制链接]
梦石
0
星屑
50
在线时间
200 小时
注册时间
2008-3-1
回帖
258
发表于 2014-9-22 11:26:43 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 木许许 于 2014-9-22 11:27 编辑

前几天版主帮忙把人物仓库修改成武器仓库的脚本希望可以再次修改成可以同时存取武器和防具的仓库,改了一半,发现的当存进一件武器,连相同编号的防具也一起存进去了,求解决区分武器和防具的方法

这里是工程:
存取.rar (189.09 KB, 下载次数: 40)


22.JPG

评分

参与人数 1星屑 +35 收起 理由
︶ㄣ牛排ぶ + 35 手动认可奖励

查看全部评分

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

开拓者贵宾剧作品鉴家

发表于 2014-9-22 16:48:34 | 显示全部楼层
试试这个(URL自行去掉):
[pre lang="Ruby"]class Game_Party
  alias rb_initialize initialize
  def initialize
    @weapon_storage = {}
    @armor_storage = {}
    rb_initialize
  end
  def storage_import(item_id, number, type)
    case type
    when 1
      @weapon_storage[item_id] = 0 if @weapon_storage[item_id].nil?
      current = @weapon_storage[item_id]
      @weapon_storage[item_id] = [number + current, 99].min
    when 2
      @armor_storage[item_id] = 0 if @armor_storage[item_id].nil?
      current = @armor_storage[item_id]
      @armor_storage[item_id] = [number + current, 99].min
    end
  end
  def storage_export(item_id, number, type)
    case type
    when 1
      @weapon_storage[item_id] = 0 if @weapon_storage[item_id].nil?
      current = @weapon_storage[item_id]
      @weapon_storage[item_id] = [current - number, 0].max
    when 2
      @armor_storage[item_id] = 0 if @armor_storage[item_id].nil?
      current = @armor_storage[item_id]
      @armor_storage[item_id] = [current - number, 0].max
    end
  end
  def storage_number(item_id, type)
    case type
    when 1
      @weapon_storage[item_id].nil? ? 0 : @weapon_storage[item_id]
    when 2
      @armor_storage[item_id].nil? ? 0 : @armor_storage[item_id]
    end
  end
  def storage_full?(item_id, type)
    case type
    when 1
      @weapon_storage[item_id] == 99
    when 2
      @armor_storage[item_id] == 99
    end
  end
end

class Commitem_Window_PartyLeft < Window_Selectable
  def initialize
    super(0, 64, 320, 324)
    self.index = 0
    refresh
  end
  def item
    return @data[self.index]
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 1..$data_weapons.size  #武器
      if $game_party.weapon_number(i) > 0
        @data.push($data_weapons)
      end
    end
    for i in 1..$data_armors.size # 防具
      if $game_party.armor_number(i) > 0
        @data.push($data_armors)
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, @item_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    self.contents.font.color = normal_color
    x = 4
    y = index * 32
    rect = Rect.new(x,y,self.width - 32,32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end
  def item_type
    case self.item
    when RPG::Weapon
      return 1
    when RPG::Armor
      return 2
    end
  end
end

class Commitem_Window_PartyRight < Window_Selectable
  def initialize
    super(320, 64, 320, 324)
    self.index = -1
    refresh
  end
  def item
    return @data[self.index]
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    $data_weapons.each do |weapon|
      next if weapon.nil?
      @data.push(weapon) if $game_party.storage_number(weapon.id, 1) > 0
    end
    $data_armors.each do |armor|
      next if armor.nil?
      @data.push(armor) if $game_party.storage_number(armor.id, 2) > 0
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, @item_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Weapon
      number = $game_party.storage_number(item.id, 1)
    when RPG::Armor
      number = $game_party.storage_number(item.id, 2)
    end
    self.contents.font.color = normal_color
    x = 4
    y = index * 32
    rect = Rect.new(x,y,self.width - 32,32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end
  def item_type
    case self.item
    when RPG::Weapon
      return 1
    when RPG::Armor
      return 2
    end
  end
end

class Commitem_Scene_Party
  def main
    @left_temp_command = 0
    @right_temp_command = 0
    @temp = 0
    @left_window = Commitem_Window_PartyLeft.new
    @left_window.active = true
    @right_window = Commitem_Window_PartyRight.new
    @right_window.active = false
    @base = Window_Base.new(0, 0, 640, 64)
    @base.contents = Bitmap.new(@base.width - 32, @base.height - 32)
    @base.contents.draw_text(4, 0, @base.width - 40, 32, "装备仓库", 1)
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @left_window.dispose
    @right_window.dispose
    @base.dispose
  end
  def update
    @left_window.update
    @right_window.update
    update_command
  end
  def update_command
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    if @left_window.active
      update_left
      return
    end
    if @right_window.active
      update_right
      return
    end
  end
  
  def update_left
    if Input.trigger?(Input::RIGHT)
      @left_temp_command = @left_window.index
      @left_window.index = -1
      $game_system.se_play($data_system.cursor_se)
      @left_window.active = false
      @right_window.active = true
      @right_window.index = @right_temp_command
      return
    end
    if Input.trigger?(Input::C)
      if @left_window.item == nil
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      id = @left_window.item.id
      case @left_window.item_type
      when 1
        if $game_party.weapon_number(id) > 0 && !$game_party.storage_full?(id, 1)
          $game_system.se_play($data_system.decision_se)
          $game_party.lose_weapon(id, 1)
          $game_party.storage_import(id, 1, 1)
          @left_window.refresh
          @right_window.refresh
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      when 2
        if $game_party.armor_number(id) > 0 && !$game_party.storage_full?(id, 2)
          $game_system.se_play($data_system.decision_se)
          $game_party.lose_armor(id, 1)
          $game_party.storage_import(id, 1, 2)
          @left_window.refresh
          @right_window.refresh
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      end
      return
    end
  end
  def update_right
    if Input.trigger?(Input::LEFT)
      @right_temp_command = @right_window.index
      @right_window.index = -1
      $game_system.se_play($data_system.cursor_se)
      @left_window.active = true
      @right_window.active = false
      @left_window.index = @left_temp_command
      return
    end
    if Input.trigger?(Input::C)
      if @right_window.item == nil
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      id = @right_window.item.id
      case @right_window.item_type
      when 1
        if $game_party.weapon_number(id) < 99 && $game_party.storage_number(id, 1) > 0
          $game_system.se_play($data_system.decision_se)
          $game_party.gain_weapon(id, 1)
          $game_party.storage_export(id, 1, 1)
          @left_window.refresh
          @right_window.refresh
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      when 2
        if $game_party.armor_number(id) < 99 && $game_party.storage_number(id, 2) > 0
          $game_system.se_play($data_system.decision_se)
          $game_party.gain_armor(id, 1)
          $game_party.storage_export(id, 1, 2)
          @left_window.refresh
          @right_window.refresh
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      end
      return
    end
  end
end[/pre]

点评

多谢!能否限制只能放三种装备(武器+防具)?  发表于 2014-9-22 21:31

评分

参与人数 1梦石 +1 收起 理由
︶ㄣ牛排ぶ + 1 认可答案

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部