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

Project1

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

[推荐问答] 分离 装备需要属性 时发生的意外。level没定义nil?

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1733
在线时间
484 小时
注册时间
2006-1-7
帖子
1073
跳转到指定楼层
1
发表于 2015-6-2 11:09:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 白鬼 于 2015-6-2 12:03 编辑

应求,分离
http://6rweb.sinaapp.com/articles/4472
这里面的 装备需要属性 时
发生了一点意外
总是说 level 没有定义 nil
而且是 actor.level
所以,请高手帮忙看一下,顺便指正一下是哪里出了问题。
Data.zip (170.41 KB, 下载次数: 96)

@RyanBern  

评分

参与人数 1星屑 +135 收起 理由
RyanBern + 135 手动认可奖励+设置为推荐问答

查看全部评分

初从文,三年不中;后习武,校场发一矢,中鼓吏,逐之出;遂学医,有所成。自撰一良方,服之,卒。

Lv3.寻梦者

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
帖子
1516
2
发表于 2015-6-2 18:04:03 | 只看该作者
建议把原脚本中 所有含
@equip
的检查一遍.
没有给
@equip_actor  设置值
@equip_window_left 没有设置

分离脚本需要确保功能的完整,赋值,设置,方法缺一不可
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

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

开拓者贵宾剧作品鉴家

3
发表于 2015-6-2 19:17:50 | 只看该作者
看来是要从原来的整合系统中分离出来装备需要属性的功能。
刚才看了一下脚本,发现做的分离没有彻底,原来的@equip_actor和@equip_window_left是原整合系统“超级菜单”的部分。对应部分应该去掉或者是重新命名。

修改建议:
1.将Scene_Equip里面所有的@equip_actor改为@actor,@equip_window_right改为@right_window,@equip_item_window改为@item_window
2.将Window_EquipItem里面,def draw_item方法体里,byakki追加的语句去掉,然后把它后面的一句话self.contents.font.color = normal_color改成:
RUBY 代码复制
  1. self.contents.font.color = $game_party.item_can_equip?(@actor, item) ? normal_color : disabled_color

3.还有一个残留问题,就是如果角色的初期装备不满足装备条件,那么按照这种设定依然可以装备上。所以这种特殊情况需要处理。还有,使用事件[变更装备]时,也会发生类似的问题。希望你自己能处理一下。提示:参考Game_Actor#setup和Interpreter#command_319
*4.(这条只作为建议,可以不进行改进)将item_can_equip?方法作为Game_Party的方法似乎不太妥当,应该把它改成Game_Actor的方法。

参考的Scene_Equip如下(只修改了):
RUBY 代码复制
  1. #==============================================================================
  2. # ■ Scene_Equip
  3. #------------------------------------------------------------------------------
  4. #  处理装备画面的类。
  5. #==============================================================================
  6.  
  7. class Scene_Equip
  8.   #--------------------------------------------------------------------------
  9.   # ● 初始化对像
  10.   #     actor_index : 角色索引
  11.   #     equip_index : 装备索引
  12.   #--------------------------------------------------------------------------
  13.   def initialize(actor_index = 0, equip_index = 0)
  14.     @actor_index = actor_index
  15.     @equip_index = equip_index
  16.   end
  17.   #--------------------------------------------------------------------------
  18.   # ● 主处理
  19.   #--------------------------------------------------------------------------
  20.   def main
  21.     # 获取角色
  22.     @actor = $game_party.actors[@actor_index]
  23.     @equip_actor = @actor
  24.     # 生成窗口
  25.     @help_window = Window_Help.new
  26.     @left_window = Window_EquipLeft.new(@actor)
  27.     @right_window = Window_EquipRight.new(@actor)
  28.     @item_window1 = Window_EquipItem.new(@actor, 0)
  29.     @item_window2 = Window_EquipItem.new(@actor, 1)
  30.     @item_window3 = Window_EquipItem.new(@actor, 2)
  31.     @item_window4 = Window_EquipItem.new(@actor, 3)
  32.     @item_window5 = Window_EquipItem.new(@actor, 4)
  33.     # 关联帮助窗口
  34.     @right_window.help_window = @help_window
  35.     @item_window1.help_window = @help_window
  36.     @item_window2.help_window = @help_window
  37.     @item_window3.help_window = @help_window
  38.     @item_window4.help_window = @help_window
  39.     @item_window5.help_window = @help_window
  40.     # 设置光标位置
  41.     @right_window.index = @equip_index
  42.     refresh
  43.     # 执行过渡
  44.     Graphics.transition
  45.     # 主循环
  46.     loop do
  47.       # 刷新游戏画面
  48.       Graphics.update
  49.       # 刷新输入信息
  50.       Input.update
  51.       # 刷新画面
  52.       update
  53.       # 如果画面切换的话的就中断循环
  54.       if $scene != self
  55.         break
  56.       end
  57.     end
  58.     # 准备过渡
  59.     Graphics.freeze
  60.     # 释放窗口
  61.     @help_window.dispose
  62.     @left_window.dispose
  63.     @right_window.dispose
  64.     @item_window1.dispose
  65.     @item_window2.dispose
  66.     @item_window3.dispose
  67.     @item_window4.dispose
  68.     @item_window5.dispose
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # ● 刷新
  72.   #--------------------------------------------------------------------------
  73.   def refresh
  74.     # 设置物品窗口的可视状态
  75.     @item_window1.visible = (@right_window.index == 0)
  76.     @item_window2.visible = (@right_window.index == 1)
  77.     @item_window3.visible = (@right_window.index == 2)
  78.     @item_window4.visible = (@right_window.index == 3)
  79.     @item_window5.visible = (@right_window.index == 4)
  80.     # 获取当前装备中的物品
  81.     item1 = @right_window.item
  82.     # 设置当前的物品窗口到 @item_window
  83.     case @right_window.index
  84.     when 0
  85.       @item_window = @item_window1
  86.     when 1
  87.       @item_window = @item_window2
  88.     when 2
  89.       @item_window = @item_window3
  90.     when 3
  91.       @item_window = @item_window4
  92.     when 4
  93.       @item_window = @item_window5
  94.     end
  95.     # 右窗口被激活的情况下
  96.     if @right_window.active
  97.       # 删除变更装备后的能力
  98.       @left_window.set_new_parameters(nil, nil, nil)
  99.     end
  100.     # 物品窗口被激活的情况下
  101.     if @item_window.active
  102.       # 获取现在选中的物品
  103.       item2 = @item_window.item
  104.       # 变更装备
  105.       last_hp = @actor.hp
  106.       last_sp = @actor.sp
  107.       @actor.equip(@right_window.index, item2 == nil ? 0 : item2.id)
  108.       # 获取变更装备后的能力值
  109.       new_atk = @actor.atk
  110.       new_pdef = @actor.pdef
  111.       new_mdef = @actor.mdef
  112.       # 返回到装备
  113.       @actor.equip(@right_window.index, item1 == nil ? 0 : item1.id)
  114.       @actor.hp = last_hp
  115.       @actor.sp = last_sp
  116.       # 描画左窗口
  117.       @left_window.set_new_parameters(new_atk, new_pdef, new_mdef)
  118.     end
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # ● 刷新画面
  122.   #--------------------------------------------------------------------------
  123.   def update
  124.     # 刷新窗口
  125.     @left_window.update
  126.     @right_window.update
  127.     @item_window.update
  128.     refresh
  129.     # 右侧窗口被激活的情况下: 调用 update_right
  130.     if @right_window.active
  131.       update_right
  132.       return
  133.     end
  134.     # 物品窗口被激活的情况下: 调用 update_item
  135.     if @item_window.active
  136.       update_item
  137.       return
  138.     end
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ● 刷新画面 (右侧窗口被激活的情况下)
  142.   #--------------------------------------------------------------------------
  143.   def update_right
  144.     # 按下 B 键的情况下
  145.     if Input.trigger?(Input::B)
  146.       # 演奏取消 SE
  147.       $game_system.se_play($data_system.cancel_se)
  148.       # 切换到菜单画面
  149.       $scene = Scene_Menu.new(2)
  150.       return
  151.     end
  152.     # 按下 C 键的情况下
  153.     if Input.trigger?(Input::C)
  154.       # 固定装备的情况下
  155.       if @actor.equip_fix?(@right_window.index)
  156.         # 演奏冻结 SE
  157.         $game_system.se_play($data_system.buzzer_se)
  158.         return
  159.       end
  160.       # 演奏确定 SE
  161.       $game_system.se_play($data_system.decision_se)
  162.       # 激活物品窗口
  163.       @right_window.active = false
  164.       @item_window.active = true
  165.       @item_window.index = 0
  166.       return
  167.     end
  168.     # 按下 R 键的情况下
  169.     if Input.trigger?(Input::R)
  170.       # 演奏光标 SE
  171.       $game_system.se_play($data_system.cursor_se)
  172.       # 移至下一位角色
  173.       @actor_index += 1
  174.       @actor_index %= $game_party.actors.size
  175.       # 切换到别的装备画面
  176.       $scene = Scene_Equip.new(@actor_index, @right_window.index)
  177.       return
  178.     end
  179.     # 按下 L 键的情况下
  180.     if Input.trigger?(Input::L)
  181.       # 演奏光标 SE
  182.       $game_system.se_play($data_system.cursor_se)
  183.       # 移至上一位角色
  184.       @actor_index += $game_party.actors.size - 1
  185.       @actor_index %= $game_party.actors.size
  186.       # 切换到别的装备画面
  187.       $scene = Scene_Equip.new(@actor_index, @right_window.index)
  188.       return
  189.     end
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # ● 刷新画面 (物品窗口被激活的情况下)
  193.   #--------------------------------------------------------------------------
  194.   def update_item
  195.     # 按下 B 键的情况下
  196.     if Input.trigger?(Input::B)
  197.       # 演奏取消 SE
  198.       $game_system.se_play($data_system.cancel_se)
  199.       # 激活右侧窗口
  200.       @right_window.active = true
  201.       @item_window.active = false
  202.       @item_window.index = -1
  203.       return
  204.     end
  205.     #byakki#↓上面注释掉的全替换
  206.     # 按下 C 键的情况下
  207.     if Input.trigger?(Input::C)
  208.       # 获取物品窗口现在选择的装备数据
  209.       item = @item_window.item
  210.       if item != nil
  211.         unless $game_party.item_can_equip?(@actor, item)
  212.           # 演奏冻结 SE
  213.           $game_system.se_play($data_system.buzzer_se)
  214.         else
  215.           # 演奏装备 SE
  216.           $game_system.se_play($data_system.equip_se)
  217.           # 变更装备
  218.           @actor.equip(@right_window.index, item == nil ? 0 : item.id)
  219.           # 激活右侧窗口
  220.           @right_window.active = true
  221.           @item_window.active = false
  222.           @item_window.index = -1
  223.           # 再生成右侧窗口、物品窗口的内容
  224.           @right_window.refresh
  225.           @item_window.refresh
  226.           return
  227.         end
  228.       else
  229.         # 演奏装备 SE
  230.         $game_system.se_play($data_system.equip_se)
  231.         # 变更装备
  232.         @actor.equip(@right_window.index, item == nil ? 0 : item.id)
  233.         # 激活右侧窗口
  234.         @right_window.active = true
  235.         @item_window.active = false
  236.         @item_window.index = -1
  237.         # 再生成右侧窗口、物品窗口的内容
  238.         @right_window.refresh
  239.         @item_window.refresh
  240.         return   
  241.       end
  242.     end
  243.     #byakki#↑上面注释掉的全替换
  244.   end
  245. end

点评

见建议的第2条,忘记写第2条是干什么的了  发表于 2015-6-2 20:52
多谢。另外,如果应用这个系统,那么将来更改菜单,也是需要修改好多地方了。总之这个东西就是麻烦。唉~  发表于 2015-6-2 19:50
这个OK了。但是,因为能力不足而不可装备的物品,名字颜色怎么设置成无效的颜色?  发表于 2015-6-2 19:43
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
76
在线时间
1379 小时
注册时间
2012-7-5
帖子
1698

开拓者

4
发表于 2015-6-2 19:20:41 | 只看该作者
本帖最后由 kuerlulu 于 2016-5-17 22:42 编辑

看起来不难所以顺手写个能用的(即插即用):
  1. # 装备需要属性 by hyrious
  2. # 设置姿势: [数据库] - [武器] 或 [防具] - 【说明】
  3. #           把需要的属性值按"@等级@力量@灵巧@速度@魔力"格式写到后面(@不可省)
  4. #    例: 004: 密斯利尔剑: 最高级的剑。战士可以装备。@10@@60@100@
  5. #       即为: 需要 10级 + 60灵巧 + 100速度 才能装备
  6. module RPG
  7.   # -------------------------------------------------------------------------
  8.   # ● 武器和防具需要的属性值
  9.   # -------------------------------------------------------------------------
  10.   class Weapon
  11.     def description
  12.       des = @description.split(/@/)[0]
  13.       return des != nil ? des : ""
  14.     end
  15.     def need_lv
  16.       need_lv  = @description.split(/@/)[1]
  17.       return need_lv != nil ? need_lv.to_i : 1
  18.     end
  19.     def need_str
  20.       need_str  = @description.split(/@/)[2]
  21.       return need_str != nil ? need_str.to_i : 0
  22.     end
  23.     def need_dex
  24.       need_dex  = @description.split(/@/)[3]
  25.       return need_dex != nil ? need_dex.to_i : 0
  26.     end
  27.     def need_agi
  28.       need_agi  = @description.split(/@/)[4]
  29.       return need_agi != nil ? need_agi.to_i : 0
  30.     end
  31.     def need_int
  32.       need_int  = @description.split(/@/)[5]
  33.       return need_int != nil ? need_int.to_i : 0
  34.     end
  35.   end
  36.   # -------------------------------------------------------------------------
  37.   class Armor
  38.     def description
  39.       des = @description.split(/@/)[0]
  40.       return des != nil ? des : ""
  41.     end
  42.     def need_lv
  43.       need_lv  = @description.split(/@/)[1]
  44.       return need_lv != nil ? need_lv.to_i : 1
  45.     end
  46.     def need_str
  47.       need_str  = @description.split(/@/)[2]
  48.       return need_str != nil ? need_str.to_i : 0
  49.     end
  50.     def need_dex
  51.       need_dex  = @description.split(/@/)[3]
  52.       return need_dex != nil ? need_dex.to_i : 0
  53.     end
  54.     def need_agi
  55.       need_agi  = @description.split(/@/)[4]
  56.       return need_agi != nil ? need_agi.to_i : 0
  57.     end
  58.     def need_int
  59.       need_int  = @description.split(/@/)[5]
  60.       return need_int != nil ? need_int.to_i : 0
  61.     end
  62.   end
  63. end
  64. # ---------------------------------------------------------------------------
  65. class Game_Party
  66.   # -------------------------------------------------------------------------
  67.   # ● 是否可以装备判定
  68.   # -------------------------------------------------------------------------
  69.   def item_can_equip?(actor,item)
  70.     return true if item.nil?
  71.     if actor.level<item.need_lv or
  72.       actor.str<item.need_str or
  73.       actor.dex<item.need_dex or
  74.       actor.agi<item.need_agi or
  75.       actor.int<item.need_int
  76.       return false
  77.     end
  78.     return true
  79.   end
  80. end
  81. # ---------------------------------------------------------------------------
  82. class Window_EquipItem < Window_Selectable
  83.   # -------------------------------------------------------------------------
  84.   # ● 描绘装备(+无效灰)
  85.   # -------------------------------------------------------------------------
  86.   def draw_item(index)
  87.     item = @data[index]
  88.     x = 4 + index % 2 * (288 + 32)
  89.     y = index / 2 * 32
  90.     item_can_equip = $game_party.item_can_equip?(@actor, item) # 喵
  91.     case item
  92.     when RPG::Weapon
  93.       number = $game_party.weapon_number(item.id)
  94.     when RPG::Armor
  95.       number = $game_party.armor_number(item.id)
  96.     end
  97.     bitmap = RPG::Cache.icon(item.icon_name)
  98.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  99.     self.contents.font.color = item_can_equip ? normal_color : disabled_color
  100.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  101.     self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  102.     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  103.   end
  104.   # -------------------------------------------------------------------------
  105.   # ● 帮助文本(+需要属性的说明)
  106.   # -------------------------------------------------------------------------
  107.   def update_help
  108.     des = (self.item == nil ? "" : self.item.description)
  109.     unless $game_party.item_can_equip?(@actor, item) || item == nil
  110.       other1 = item.need_lv  <= 1 ? "" : (" Lv:" + item.need_lv.to_s)
  111.       other2 = item.need_str == 0 ? "" : (" "+$data_system.words.str+":"+item.need_str.to_s)
  112.       other3 = item.need_dex == 0 ? "" : (" "+$data_system.words.dex+":"+item.need_dex.to_s)
  113.       other4 = item.need_agi == 0 ? "" : (" "+$data_system.words.agi+":"+item.need_agi.to_s)
  114.       other5 = item.need_int == 0 ? "" : (" "+$data_system.words.int+":"+item.need_int.to_s)
  115.       des += "需要"+other1+other2+other3+other4+other5
  116.     end
  117.     @help_window.set_text(des)
  118.   end
  119. end
  120. # ---------------------------------------------------------------------------
  121. class Scene_Equip
  122.   # -------------------------------------------------------------------------
  123.   # ● 装备无效化
  124.   # -------------------------------------------------------------------------
  125.   def update_item
  126.     if Input.trigger?(Input::B)
  127.       $game_system.se_play($data_system.cancel_se)
  128.       @right_window.active = true
  129.       @item_window.active = false
  130.       @item_window.index = -1
  131.       return
  132.     end
  133.     if Input.trigger?(Input::C)
  134.       item = @item_window.item
  135.       unless $game_party.item_can_equip?(@actor, item)  # 喵
  136.         $game_system.se_play($data_system.buzzer_se)
  137.         return
  138.       else
  139.         $game_system.se_play($data_system.equip_se)
  140.         @actor.equip(@right_window.index, item == nil ? 0 : item.id)
  141.         @right_window.active = true
  142.         @item_window.active = false
  143.         @item_window.index = -1
  144.         @right_window.refresh
  145.         @item_window.refresh
  146.         return
  147.       end
  148.     end
  149.   end
  150. end
复制代码
然后我暴力解决了一下顺便加个说明可以直接拿出来卖了

点评

灰常感谢。拿我直接把这个转给需要的小盆友了。  发表于 2015-6-2 19:46
已解决  发表于 2015-6-2 19:34
这个版本,没有未装备的装备时。会出错。还有,光标在无装备的格子时,会报错。  发表于 2015-6-2 19:28
不算撞车吗?  发表于 2015-6-2 19:22

评分

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

查看全部评分


  -fk: -azogi:
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-26 19:09

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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