查看: 5021|回复: 3

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

[复制链接]
梦石
0
星屑
1748
在线时间
485 小时
注册时间
2006-1-7
回帖
996
发表于 2015-6-2 11:09:01 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 白鬼 于 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 手动认可奖励+设置为推荐问答

查看全部评分

初从文,三年不中;后习武,校场发一矢,中鼓吏,逐之出;遂学医,有所成。自撰一良方,服之,卒。
梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2015-6-2 18:04:03 | 显示全部楼层
建议把原脚本中 所有含
@equip
的检查一遍.
没有给
@equip_actor  设置值
@equip_window_left 没有设置

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

使用道具 举报

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

开拓者贵宾剧作品鉴家

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

参考的Scene_Equip如下(只修改了):
[pre lang="Ruby"]#==============================================================================
# ■ Scene_Equip
#------------------------------------------------------------------------------
#  处理装备画面的类。
#==============================================================================

class Scene_Equip
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #     actor_index : 角色索引
  #     equip_index : 装备索引
  #--------------------------------------------------------------------------
  def initialize(actor_index = 0, equip_index = 0)
    @actor_index = actor_index
    @equip_index = equip_index
  end
  #--------------------------------------------------------------------------
  # ● 主处理
  #--------------------------------------------------------------------------
  def main
    # 获取角色
    @actor = $game_party.actors[@actor_index]
    @equip_actor = @actor
    # 生成窗口
    @help_window = Window_Help.new
    @left_window = Window_EquipLeft.new(@actor)
    @right_window = Window_EquipRight.new(@actor)
    @item_window1 = Window_EquipItem.new(@actor, 0)
    @item_window2 = Window_EquipItem.new(@actor, 1)
    @item_window3 = Window_EquipItem.new(@actor, 2)
    @item_window4 = Window_EquipItem.new(@actor, 3)
    @item_window5 = Window_EquipItem.new(@actor, 4)
    # 关联帮助窗口
    @right_window.help_window = @help_window
    @item_window1.help_window = @help_window
    @item_window2.help_window = @help_window
    @item_window3.help_window = @help_window
    @item_window4.help_window = @help_window
    @item_window5.help_window = @help_window
    # 设置光标位置
    @right_window.index = @equip_index
    refresh
    # 执行过渡
    Graphics.transition
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果画面切换的话的就中断循环
      if $scene != self
        break
      end
    end
    # 准备过渡
    Graphics.freeze
    # 释放窗口
    @help_window.dispose
    @left_window.dispose
    @right_window.dispose
    @item_window1.dispose
    @item_window2.dispose
    @item_window3.dispose
    @item_window4.dispose
    @item_window5.dispose
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    # 设置物品窗口的可视状态
    @item_window1.visible = (@right_window.index == 0)
    @item_window2.visible = (@right_window.index == 1)
    @item_window3.visible = (@right_window.index == 2)
    @item_window4.visible = (@right_window.index == 3)
    @item_window5.visible = (@right_window.index == 4)
    # 获取当前装备中的物品
    item1 = @right_window.item
    # 设置当前的物品窗口到 @item_window
    case @right_window.index
    when 0
      @item_window = @item_window1
    when 1
      @item_window = @item_window2
    when 2
      @item_window = @item_window3
    when 3
      @item_window = @item_window4
    when 4
      @item_window = @item_window5
    end
    # 右窗口被激活的情况下
    if @right_window.active
      # 删除变更装备后的能力
      @left_window.set_new_parameters(nil, nil, nil)
    end
    # 物品窗口被激活的情况下
    if @item_window.active
      # 获取现在选中的物品
      item2 = @item_window.item
      # 变更装备
      last_hp = @actor.hp
      last_sp = @actor.sp
      @actor.equip(@right_window.index, item2 == nil ? 0 : item2.id)
      # 获取变更装备后的能力值
      new_atk = @actor.atk
      new_pdef = @actor.pdef
      new_mdef = @actor.mdef
      # 返回到装备
      @actor.equip(@right_window.index, item1 == nil ? 0 : item1.id)
      @actor.hp = last_hp
      @actor.sp = last_sp
      # 描画左窗口
      @left_window.set_new_parameters(new_atk, new_pdef, new_mdef)
    end
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面
  #--------------------------------------------------------------------------
  def update
    # 刷新窗口
    @left_window.update
    @right_window.update
    @item_window.update
    refresh
    # 右侧窗口被激活的情况下: 调用 update_right
    if @right_window.active
      update_right
      return
    end
    # 物品窗口被激活的情况下: 调用 update_item
    if @item_window.active
      update_item
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面 (右侧窗口被激活的情况下)
  #--------------------------------------------------------------------------
  def update_right
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 切换到菜单画面
      $scene = Scene_Menu.new(2)
      return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 固定装备的情况下
      if @actor.equip_fix?(@right_window.index)
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 演奏确定 SE
      $game_system.se_play($data_system.decision_se)
      # 激活物品窗口
      @right_window.active = false
      @item_window.active = true
      @item_window.index = 0
      return
    end
    # 按下 R 键的情况下
    if Input.trigger?(Input::R)
      # 演奏光标 SE
      $game_system.se_play($data_system.cursor_se)
      # 移至下一位角色
      @actor_index += 1
      @actor_index %= $game_party.actors.size
      # 切换到别的装备画面
      $scene = Scene_Equip.new(@actor_index, @right_window.index)
      return
    end
    # 按下 L 键的情况下
    if Input.trigger?(Input::L)
      # 演奏光标 SE
      $game_system.se_play($data_system.cursor_se)
      # 移至上一位角色
      @actor_index += $game_party.actors.size - 1
      @actor_index %= $game_party.actors.size
      # 切换到别的装备画面
      $scene = Scene_Equip.new(@actor_index, @right_window.index)
      return
    end
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面 (物品窗口被激活的情况下)
  #--------------------------------------------------------------------------
  def update_item
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 激活右侧窗口
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      return
    end
    #byakki#↓上面注释掉的全替换
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 获取物品窗口现在选择的装备数据
      item = @item_window.item
      if item != nil
        unless $game_party.item_can_equip?(@actor, item)
          # 演奏冻结 SE
          $game_system.se_play($data_system.buzzer_se)
        else
          # 演奏装备 SE
          $game_system.se_play($data_system.equip_se)
          # 变更装备
          @actor.equip(@right_window.index, item == nil ? 0 : item.id)
          # 激活右侧窗口
          @right_window.active = true
          @item_window.active = false
          @item_window.index = -1
          # 再生成右侧窗口、物品窗口的内容
          @right_window.refresh
          @item_window.refresh
          return
        end
      else
        # 演奏装备 SE
        $game_system.se_play($data_system.equip_se)
        # 变更装备
        @actor.equip(@right_window.index, item == nil ? 0 : item.id)
        # 激活右侧窗口
        @right_window.active = true
        @item_window.active = false
        @item_window.index = -1
        # 再生成右侧窗口、物品窗口的内容
        @right_window.refresh
        @item_window.refresh
        return   
      end
    end
    #byakki#↑上面注释掉的全替换
  end
end[/pre]

点评

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

使用道具 举报

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

开拓者

发表于 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:
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部