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

Project1

 找回密码
 注册会员
搜索

武器仓库修改为装备仓库的问题

查看数: 1830 | 评论数: 1 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2014-9-22 11:26

正文摘要:

本帖最后由 木许许 于 2014-9-22 11:27 编辑 前几天版主帮忙把人物仓库修改成武器仓库的脚本希望可以再次修改成可以同时存取武器和防具的仓库,改了一半,发现的当存进一件武器,连相同编号的防具也一起存进去了 ...

回复

RyanBern 发表于 2014-9-22 16:48:34
试试这个(URL自行去掉):
RUBY 代码复制
  1. class Game_Party
  2.   alias rb_initialize initialize
  3.   def initialize
  4.     @weapon_storage = {}
  5.     @armor_storage = {}
  6.     rb_initialize
  7.   end
  8.   def storage_import(item_id, number, type)
  9.     case type
  10.     when 1
  11.       @weapon_storage[item_id] = 0 if @weapon_storage[item_id].nil?
  12.       current = @weapon_storage[item_id]
  13.       @weapon_storage[item_id] = [number + current, 99].min
  14.     when 2
  15.       @armor_storage[item_id] = 0 if @armor_storage[item_id].nil?
  16.       current = @armor_storage[item_id]
  17.       @armor_storage[item_id] = [number + current, 99].min
  18.     end
  19.   end
  20.   def storage_export(item_id, number, type)
  21.     case type
  22.     when 1
  23.       @weapon_storage[item_id] = 0 if @weapon_storage[item_id].nil?
  24.       current = @weapon_storage[item_id]
  25.       @weapon_storage[item_id] = [current - number, 0].max
  26.     when 2
  27.       @armor_storage[item_id] = 0 if @armor_storage[item_id].nil?
  28.       current = @armor_storage[item_id]
  29.       @armor_storage[item_id] = [current - number, 0].max
  30.     end
  31.   end
  32.   def storage_number(item_id, type)
  33.     case type
  34.     when 1
  35.       @weapon_storage[item_id].nil? ? 0 : @weapon_storage[item_id]
  36.     when 2
  37.       @armor_storage[item_id].nil? ? 0 : @armor_storage[item_id]
  38.     end
  39.   end
  40.   def storage_full?(item_id, type)
  41.     case type
  42.     when 1
  43.       @weapon_storage[item_id] == 99
  44.     when 2
  45.       @armor_storage[item_id] == 99
  46.     end
  47.   end
  48. end
  49.  
  50. class Commitem_Window_PartyLeft < Window_Selectable
  51.   def initialize
  52.     super(0, 64, 320, 324)
  53.     self.index = 0
  54.     refresh
  55.   end
  56.   def item
  57.     return @data[self.index]
  58.   end
  59.   def refresh
  60.     if self.contents != nil
  61.       self.contents.dispose
  62.       self.contents = nil
  63.     end
  64.     @data = []
  65.     for i in 1..$data_weapons.size  #武器
  66.       if $game_party.weapon_number(i) > 0
  67.         @data.push($data_weapons[i])
  68.       end
  69.     end
  70.     for i in 1..$data_armors.size # 防具
  71.       if $game_party.armor_number(i) > 0
  72.         @data.push($data_armors[i])
  73.       end
  74.     end
  75.     @item_max = @data.size
  76.     if @item_max > 0
  77.       self.contents = Bitmap.new(width - 32, @item_max * 32)
  78.       for i in 0...@item_max
  79.         draw_item(i)
  80.       end
  81.     end
  82.   end
  83.   def draw_item(index)
  84.     item = @data[index]
  85.     case item
  86.     when RPG::Weapon
  87.       number = $game_party.weapon_number(item.id)
  88.     when RPG::Armor
  89.       number = $game_party.armor_number(item.id)
  90.     end
  91.     self.contents.font.color = normal_color
  92.     x = 4
  93.     y = index * 32
  94.     rect = Rect.new(x,y,self.width - 32,32)
  95.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  96.     bitmap = RPG::Cache.icon(item.icon_name)
  97.     opacity = self.contents.font.color == normal_color ? 255 : 128
  98.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  99.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  100.     self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  101.     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  102.   end
  103.   def item_type
  104.     case self.item
  105.     when RPG::Weapon
  106.       return 1
  107.     when RPG::Armor
  108.       return 2
  109.     end
  110.   end
  111. end
  112.  
  113. class Commitem_Window_PartyRight < Window_Selectable
  114.   def initialize
  115.     super(320, 64, 320, 324)
  116.     self.index = -1
  117.     refresh
  118.   end
  119.   def item
  120.     return @data[self.index]
  121.   end
  122.   def refresh
  123.     if self.contents != nil
  124.       self.contents.dispose
  125.       self.contents = nil
  126.     end
  127.     @data = []
  128.     $data_weapons.each do |weapon|
  129.       next if weapon.nil?
  130.       @data.push(weapon) if $game_party.storage_number(weapon.id, 1) > 0
  131.     end
  132.     $data_armors.each do |armor|
  133.       next if armor.nil?
  134.       @data.push(armor) if $game_party.storage_number(armor.id, 2) > 0
  135.     end
  136.     @item_max = @data.size
  137.     if @item_max > 0
  138.       self.contents = Bitmap.new(width - 32, @item_max * 32)
  139.       for i in 0...@item_max
  140.         draw_item(i)
  141.       end
  142.     end
  143.   end
  144.   def draw_item(index)
  145.     item = @data[index]
  146.     case item
  147.     when RPG::Weapon
  148.       number = $game_party.storage_number(item.id, 1)
  149.     when RPG::Armor
  150.       number = $game_party.storage_number(item.id, 2)
  151.     end
  152.     self.contents.font.color = normal_color
  153.     x = 4
  154.     y = index * 32
  155.     rect = Rect.new(x,y,self.width - 32,32)
  156.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  157.     bitmap = RPG::Cache.icon(item.icon_name)
  158.     opacity = self.contents.font.color == normal_color ? 255 : 128
  159.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  160.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  161.     self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  162.     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  163.   end
  164.   def item_type
  165.     case self.item
  166.     when RPG::Weapon
  167.       return 1
  168.     when RPG::Armor
  169.       return 2
  170.     end
  171.   end
  172. end
  173.  
  174. class Commitem_Scene_Party
  175.   def main
  176.     @left_temp_command = 0
  177.     @right_temp_command = 0
  178.     [url=home.php?mod=space&uid=263426]@temp[/url] = 0
  179.     @left_window = Commitem_Window_PartyLeft.new
  180.     @left_window.active = true
  181.     @right_window = Commitem_Window_PartyRight.new
  182.     @right_window.active = false
  183.     @base = Window_Base.new(0, 0, 640, 64)
  184.     @base.contents = Bitmap.new(@base.width - 32, @base.height - 32)
  185.     @base.contents.draw_text(4, 0, @base.width - 40, 32, "装备仓库", 1)
  186.     Graphics.transition
  187.     loop do
  188.       Graphics.update
  189.       Input.update
  190.       update
  191.       if $scene != self
  192.         break
  193.       end
  194.     end
  195.     Graphics.freeze
  196.     @left_window.dispose
  197.     @right_window.dispose
  198.     @base.dispose
  199.   end
  200.   def update
  201.     @left_window.update
  202.     @right_window.update
  203.     update_command
  204.   end
  205.   def update_command
  206.     if Input.trigger?(Input::B)
  207.       $game_system.se_play($data_system.cancel_se)
  208.       $scene = Scene_Map.new
  209.       return
  210.     end
  211.     if @left_window.active
  212.       update_left
  213.       return
  214.     end
  215.     if @right_window.active
  216.       update_right
  217.       return
  218.     end
  219.   end
  220.  
  221.   def update_left
  222.     if Input.trigger?(Input::RIGHT)
  223.       @left_temp_command = @left_window.index
  224.       @left_window.index = -1
  225.       $game_system.se_play($data_system.cursor_se)
  226.       @left_window.active = false
  227.       @right_window.active = true
  228.       @right_window.index = @right_temp_command
  229.       return
  230.     end
  231.     if Input.trigger?(Input::C)
  232.       if @left_window.item == nil
  233.         $game_system.se_play($data_system.buzzer_se)
  234.         return
  235.       end
  236.       id = @left_window.item.id
  237.       case @left_window.item_type
  238.       when 1
  239.         if $game_party.weapon_number(id) > 0 && !$game_party.storage_full?(id, 1)
  240.           $game_system.se_play($data_system.decision_se)
  241.           $game_party.lose_weapon(id, 1)
  242.           $game_party.storage_import(id, 1, 1)
  243.           @left_window.refresh
  244.           @right_window.refresh
  245.         else
  246.           $game_system.se_play($data_system.buzzer_se)
  247.         end
  248.       when 2
  249.         if $game_party.armor_number(id) > 0 && !$game_party.storage_full?(id, 2)
  250.           $game_system.se_play($data_system.decision_se)
  251.           $game_party.lose_armor(id, 1)
  252.           $game_party.storage_import(id, 1, 2)
  253.           @left_window.refresh
  254.           @right_window.refresh
  255.         else
  256.           $game_system.se_play($data_system.buzzer_se)
  257.         end
  258.       end
  259.       return
  260.     end
  261.   end
  262.   def update_right
  263.     if Input.trigger?(Input::LEFT)
  264.       @right_temp_command = @right_window.index
  265.       @right_window.index = -1
  266.       $game_system.se_play($data_system.cursor_se)
  267.       @left_window.active = true
  268.       @right_window.active = false
  269.       @left_window.index = @left_temp_command
  270.       return
  271.     end
  272.     if Input.trigger?(Input::C)
  273.       if @right_window.item == nil
  274.         $game_system.se_play($data_system.buzzer_se)
  275.         return
  276.       end
  277.       id = @right_window.item.id
  278.       case @right_window.item_type
  279.       when 1
  280.         if $game_party.weapon_number(id) < 99 && $game_party.storage_number(id, 1) > 0
  281.           $game_system.se_play($data_system.decision_se)
  282.           $game_party.gain_weapon(id, 1)
  283.           $game_party.storage_export(id, 1, 1)
  284.           @left_window.refresh
  285.           @right_window.refresh
  286.         else
  287.           $game_system.se_play($data_system.buzzer_se)
  288.         end
  289.       when 2
  290.         if $game_party.armor_number(id) < 99 && $game_party.storage_number(id, 2) > 0
  291.           $game_system.se_play($data_system.decision_se)
  292.           $game_party.gain_armor(id, 1)
  293.           $game_party.storage_export(id, 1, 2)
  294.           @left_window.refresh
  295.           @right_window.refresh
  296.         else
  297.           $game_system.se_play($data_system.buzzer_se)
  298.         end
  299.       end
  300.       return
  301.     end
  302.   end
  303. end

点评

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

评分

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

查看全部评分

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

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

GMT+8, 2024-11-11 06:56

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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