Project1

标题: Scene_Battle 4 的一行代码卡住,急求解救 [打印本页]

作者: gkl0510    时间: 2016-2-13 20:42
标题: Scene_Battle 4 的一行代码卡住,急求解救
各路大仙新年快乐,Scene_Battle 4 脚本的一行代码总是报错急求解救,
还望能人不吝赐教。

由于添加了几个脚本所以原脚本做过细微的修改,但是之前没有报错过,
但是这两天运行战斗中,几项技能叠加(或技能和物品使用叠加)就会
突然报错(如图然后跳出游戏界面)。但第二次使用同样的技能或物品
又会正常,并不是每次都报错,百思不得其解。



求大虾们相助,感激不尽!


RUBY 代码复制
  1. #==============================================================================
  2. # ■ Scene_Battle (分割定义 4)
  3. #------------------------------------------------------------------------------
  4. #  处理战斗画面的类。
  5. #==============================================================================
  6.  
  7. class Scene_Battle
  8.   #--------------------------------------------------------------------------
  9.   # ● 开始主回合
  10.   #--------------------------------------------------------------------------
  11.   def start_phase4
  12.     # 转移到回合 4
  13.     @phase = 4
  14.     # 回合数计数
  15.     $game_temp.battle_turn += 1
  16.     # 搜索全页的战斗事件
  17.     for index in 0...$data_troops[@troop_id].pages.size
  18.       # 获取事件页
  19.       page = $data_troops[@troop_id].pages[index]
  20.       # 本页的范围是 [回合] 的情况下
  21.       if page.span == 1
  22.         # 设置已经执行标志
  23.         $game_temp.battle_event_flags[index] = false
  24.       end
  25.     end
  26.     # 设置角色为非选择状态
  27.     @actor_index = -1
  28.     @active_battler = nil
  29.     # 有效化同伴指令窗口
  30.     @party_command_window.active = false
  31.     @party_command_window.visible = false
  32.     # 无效化角色指令窗口
  33.     @actor_command_window.active = false
  34.     @actor_command_window.visible = false
  35.     # 设置主回合标志
  36.     $game_temp.battle_main_phase = true
  37.     # 生成敌人行动
  38.     for enemy in $game_troop.enemies
  39.       enemy.make_action
  40.     end
  41.     # 生成行动顺序
  42.     make_action_orders
  43.     # 移动到步骤 1
  44.     @phase4_step = 1
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # ● 生成行动循序
  48.   #--------------------------------------------------------------------------
  49.   def make_action_orders
  50.     # 初始化序列 @action_battlers
  51.     @action_battlers = []
  52.     # 添加敌人到 @action_battlers 序列
  53.     for enemy in $game_troop.enemies
  54.       @action_battlers.push(enemy)
  55.     end
  56.     # 添加角色到 @action_battlers 序列
  57.     for actor in $game_party.actors
  58.       @action_battlers.push(actor)
  59.     end
  60.     # 确定全体的行动速度
  61.     for battler in @action_battlers
  62.       battler.make_action_speed
  63.     end
  64.     # 按照行动速度从大到小排列
  65.     @action_battlers.sort! {|a,b|
  66.       b.current_action.speed - a.current_action.speed }
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # ● 刷新画面 (主回合)
  70.   #--------------------------------------------------------------------------
  71.   def update_phase4
  72.     case @phase4_step
  73.     when 1
  74.       update_phase4_step1
  75.     when 2
  76.       update_phase4_step2
  77.     when 3
  78.       update_phase4_step3
  79.     when 4
  80.       update_phase4_step4
  81.     when 5
  82.       update_phase4_step5
  83.     when 6
  84.       update_phase4_step6
  85.     end
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # ● 刷新画面 (主回合步骤 1 : 准备行动)
  89.   #--------------------------------------------------------------------------
  90.   def update_phase4_step1
  91.     # 隐藏帮助窗口
  92.     @help_window.visible = false
  93.     # 判定胜败
  94.     if judge
  95.       # 胜利或者失败的情况下 : 过程结束
  96.       return
  97.     end
  98.     # 强制行动的战斗者不存在的情况下
  99.     if $game_temp.forcing_battler == nil
  100.       # 设置战斗事件
  101.       setup_battle_event
  102.       # 执行战斗事件中的情况下
  103.       if $game_system.battle_interpreter.running?
  104.         return
  105.       end
  106.     end
  107.     # 强制行动的战斗者存在的情况下
  108.     if $game_temp.forcing_battler != nil
  109.       # 在头部添加后移动
  110.       @action_battlers.delete($game_temp.forcing_battler)
  111.       @action_battlers.unshift($game_temp.forcing_battler)
  112.     end
  113.     # 未行动的战斗者不存在的情况下 (全员已经行动)
  114.     if @action_battlers.size == 0
  115.       # 开始同伴命令回合
  116.       start_phase2
  117.       return
  118.     end
  119.     # 初始化动画 ID 和公共事件 ID
  120.     @animation1_id = 0
  121.     @animation2_id = 0
  122.     @common_event_id = 0
  123.     # 未行动的战斗者移动到序列的头部
  124.     @active_battler = @action_battlers.shift
  125.     # 如果已经在战斗之外的情况下
  126.     if @active_battler.index == nil
  127.       return
  128.     end
  129.     # 连续伤害
  130.     if @active_battler.hp > 0 and @active_battler.slip_damage?
  131.       @active_battler.slip_damage_effect
  132.       @active_battler.damage_pop = true
  133.     end
  134.     # 自然解除状态
  135.     @active_battler.remove_states_auto
  136.     # 刷新状态窗口
  137.     @status_window.refresh
  138.     # 移至步骤 2
  139.     @phase4_step = 2
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # ● 刷新画面 (主回合步骤 2 : 开始行动)
  143.   #--------------------------------------------------------------------------
  144.   def update_phase4_step2
  145.     # 如果不是强制行动
  146.     unless @active_battler.current_action.forcing
  147.       # 限制为 [敌人为普通攻击] 或 [我方为普通攻击] 的情况下
  148.       if @active_battler.restriction == 2 or @active_battler.restriction == 3
  149.         # 设置行动为攻击
  150.         @active_battler.current_action.kind = 0
  151.         @active_battler.current_action.basic = 0
  152.       end
  153.       # 限制为 [不能行动] 的情况下
  154.       if @active_battler.restriction == 4
  155.         # 清除行动强制对像的战斗者
  156.         $game_temp.forcing_battler = nil
  157.         # 移至步骤 1
  158.         @phase4_step = 1
  159.         return
  160.       end
  161.     end
  162.     # 清除对像战斗者
  163.     @target_battlers = []
  164.     # 行动种类分支
  165.     case @active_battler.current_action.kind
  166.     when 0  # 基本
  167.       make_basic_action_result
  168.     when 1  # 特技
  169.       make_skill_action_result
  170.     when 2  # 物品
  171.       make_item_action_result
  172.     end
  173.     # 移至步骤 3
  174.     if @phase4_step == 2
  175.       @phase4_step = 3
  176.     end
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # ● 生成基本行动结果
  180.   #--------------------------------------------------------------------------
  181.   def make_basic_action_result
  182.     # 攻击的情况下
  183.     if @active_battler.current_action.basic == 0
  184.       # 设置攻击 ID
  185.       @animation1_id = @active_battler.animation1_id
  186.       @animation2_id = @active_battler.animation2_id
  187.       # 行动方的战斗者是敌人的情况下
  188.       if @active_battler.is_a?(Game_Enemy)
  189.         if @active_battler.restriction == 3
  190.           target = $game_troop.random_target_enemy
  191.         elsif @active_battler.restriction == 2
  192.           target = $game_party.random_target_actor
  193.         else
  194.           index = @active_battler.current_action.target_index
  195.           target = $game_party.smooth_target_actor(index)
  196.         end
  197.       end
  198.       # 行动方的战斗者是角色的情况下
  199.       if @active_battler.is_a?(Game_Actor)
  200.         if @active_battler.restriction == 3
  201.           target = $game_party.random_target_actor
  202.         elsif @active_battler.restriction == 2
  203.           target = $game_troop.random_target_enemy
  204.         else
  205.           index = @active_battler.current_action.target_index
  206.           target = $game_troop.smooth_target_enemy(index)
  207.         end
  208.       end
  209.       # 设置对像方的战斗者序列
  210.       #k_特殊武器begin.....................
  211.       if @active_battler.is_a?(Game_Actor) and wqpd(20)
  212.       @target_battlers = $game_troop.enemies
  213.       else
  214.       @target_battlers = [target]
  215.       end
  216.      #k_特殊武器over.....................
  217.       # 应用通常攻击效果
  218.       for target in @target_battlers   
  219.         target.attack_effect(@active_battler)
  220.       end
  221.       return
  222.     end
  223.     # 防御的情况下
  224.     if @active_battler.current_action.basic == 1
  225.       # 帮助窗口显示"防御"
  226.       @help_window.set_text($data_system.words.guard, 1)
  227.       return
  228.     end
  229.     # 逃跑的情况下
  230.     if @active_battler.is_a?(Game_Enemy) and
  231.        @active_battler.current_action.basic == 2
  232.       #  帮助窗口显示"逃跑"
  233.       @help_window.set_text("逃跑", 1)
  234.       # 逃跑
  235.       @active_battler.escape
  236.       return
  237.     end
  238.     # 什么也不做的情况下
  239.     if @active_battler.current_action.basic == 3
  240.       # 清除强制行动对像的战斗者
  241.       $game_temp.forcing_battler = nil
  242.       # 移至步骤 1
  243.       @phase4_step = 1
  244.       return
  245.     end
  246.   end
  247.   #--------------------------------------------------------------------------
  248.   # ● 设置物品或特技对像方的战斗者
  249.   #     scope : 特技或者是物品的范围
  250.   #--------------------------------------------------------------------------
  251.   def set_target_battlers(scope)
  252.     # 行动方的战斗者是敌人的情况下
  253.     if @active_battler.is_a?(Game_Enemy)
  254.       # 效果范围分支
  255.       case scope
  256.       when 1  # 敌单体
  257.         index = @active_battler.current_action.target_index
  258.         @target_battlers.push($game_party.smooth_target_actor(index))
  259.       when 2  # 敌全体
  260.         for actor in $game_party.actors
  261.           if actor.exist?
  262.             @target_battlers.push(actor)
  263.           end
  264.         end
  265.       when 3  # 我方单体
  266.         index = @active_battler.current_action.target_index
  267.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  268.       when 4  # 我方全体
  269.         for enemy in $game_troop.enemies
  270.           if enemy.exist?
  271.             @target_battlers.push(enemy)
  272.           end
  273.         end
  274.       when 5  # 我方单体 (HP 0)
  275.         index = @active_battler.current_action.target_index
  276.         enemy = $game_troop.enemies[index]
  277.         if enemy != nil and enemy.hp0?
  278.           @target_battlers.push(enemy)
  279.         end
  280.       when 6  # 我方全体 (HP 0)
  281.         for enemy in $game_troop.enemies
  282.           if enemy != nil and enemy.hp0?
  283.             @target_battlers.push(enemy)
  284.           end
  285.         end
  286.       when 7  # 使用者
  287.         @target_battlers.push(@active_battler)
  288.       end
  289.     end
  290.     # 行动方的战斗者是角色的情况下
  291.     if @active_battler.is_a?(Game_Actor)
  292.       # 效果范围分支
  293.       case scope
  294.       when 1  # 敌单体
  295.         index = @active_battler.current_action.target_index
  296.         @target_battlers.push($game_troop.smooth_target_enemy(index))
  297.       when 2  # 敌全体
  298.         for enemy in $game_troop.enemies
  299.           if enemy.exist?
  300.             @target_battlers.push(enemy)
  301.           end
  302.         end
  303.       when 3  # 我方单体
  304.         index = @active_battler.current_action.target_index
  305.         @target_battlers.push($game_party.smooth_target_actor(index))
  306.       when 4  # 我方全体
  307.         for actor in $game_party.actors
  308.           if actor.exist?
  309.             @target_battlers.push(actor)
  310.           end
  311.         end
  312.       when 5  # 我方单体 (HP 0)
  313.         index = @active_battler.current_action.target_index
  314.         actor = $game_party.actors[index]
  315.         if actor != nil and actor.hp0?
  316.           @target_battlers.push(actor)
  317.         end
  318.       when 6  # 我方全体 (HP 0)
  319.         for actor in $game_party.actors
  320.           if actor != nil and actor.hp0?
  321.             @target_battlers.push(actor)
  322.           end
  323.         end
  324.       when 7  # 使用者
  325.         @target_battlers.push(@active_battler)
  326.       end
  327.     end
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # ● 生成特技行动结果
  331.   #--------------------------------------------------------------------------
  332.   def make_skill_action_result
  333.     # 获取特技
  334.     @skill = $data_skills[@active_battler.current_action.skill_id]
  335.     # 如果不是强制行动
  336.     unless @active_battler.current_action.forcing
  337.       # 因为 SP 耗尽而无法使用的情况下
  338.       unless @active_battler.skill_can_use?(@skill.id)
  339.         # 清除强制行动对像的战斗者
  340.         $game_temp.forcing_battler = nil
  341.         # 移至步骤 1
  342.         @phase4_step = 1
  343.         return
  344.       end
  345.     end
  346.     # 消耗 SP
  347.     @active_battler.sp -= @skill.sp_cost
  348.     # 刷新状态窗口
  349.     @status_window.refresh
  350.     # 在帮助窗口显示特技名
  351.     @help_window.set_text(@skill.name, 1)
  352.     # 设置动画 ID
  353.     @animation1_id = @skill.animation1_id
  354.     @animation2_id = @skill.animation2_id
  355.     # 设置公共事件 ID
  356.     @common_event_id = @skill.common_event_id
  357.     # 设置对像侧战斗者
  358.     set_target_battlers(@skill.scope)
  359.     # 应用特技效果
  360.     for target in @target_battlers
  361.       target.skill_effect(@active_battler, @skill)
  362.     end
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # ● 生成物品行动结果
  366.   #--------------------------------------------------------------------------
  367.   def make_item_action_result
  368.     # 获取物品
  369.     @item = $data_items[@active_battler.current_action.item_id]
  370.     # 因为物品耗尽而无法使用的情况下
  371.     unless $game_party.item_can_use?(@item.id)
  372.       # 移至步骤 1
  373.       @phase4_step = 1
  374.       return
  375.     end
  376.     # 消耗品的情况下
  377.     if @item.consumable
  378.       # 使用的物品减 1
  379.       $game_party.lose_item(@item.id, 1)
  380.     end
  381.     # 在帮助窗口显示物品名
  382.     @help_window.set_text(@item.name, 1)
  383.     # 设置动画 ID
  384.     @animation1_id = @item.animation1_id
  385.     @animation2_id = @item.animation2_id
  386.     # 设置公共事件 ID
  387.     @common_event_id = @item.common_event_id
  388.     # 确定对像
  389.     index = @active_battler.current_action.target_index
  390.     target = $game_party.smooth_target_actor(index)
  391.     # 设置对像侧战斗者
  392.     set_target_battlers(@item.scope)
  393.     # 应用物品效果
  394.     for target in @target_battlers
  395.       target.item_effect(@item)
  396.     end
  397.   end
  398.   #--------------------------------------------------------------------------
  399.   # ● 刷新画面 (主回合步骤 3 : 行动方动画)
  400.   #--------------------------------------------------------------------------
  401.   def update_phase4_step3
  402.     # 行动方动画 (ID 为 0 的情况下是白色闪烁)
  403.     if @animation1_id == 0
  404.       @active_battler.white_flash = true
  405.     else
  406.       @active_battler.animation_id = @animation1_id
  407.       @active_battler.animation_hit = true
  408.     end
  409.     # 移至步骤 4
  410.     @phase4_step = 4
  411.   end
  412.   #--------------------------------------------------------------------------
  413.   # ● 刷新画面 (主回合步骤 4 : 对像方动画)
  414.   #--------------------------------------------------------------------------
  415.   def update_phase4_step4
  416.     # 对像方动画
  417.     for target in @target_battlers
  418.       target.animation_id = @animation2_id
  419.       target.animation_hit = (target.damage != "Miss")
  420.     end
  421.     # 限制动画长度、最低 8 帧
  422.     @wait_count = 8
  423.     # 移至步骤 5
  424.     @phase4_step = 5
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # ● 刷新画面 (主回合步骤 5 : 显示伤害)
  428.   #--------------------------------------------------------------------------
  429.   def update_phase4_step5
  430.     # 隐藏帮助窗口
  431.     @help_window.visible = false
  432.     # 刷新状态窗口
  433.     @status_window.refresh
  434.     # 显示伤害
  435.     for target in @target_battlers
  436.       if target.damage != nil
  437.         target.damage_pop = true
  438.       end
  439.     end
  440.     # 移至步骤 6
  441.     #k_特殊武器begin...........................................
  442.     if @active_battler.is_a?(Game_Actor)
  443.     if  wqpd(17) and @lianji == 1
  444.       if wqpd(18)
  445.       for target in @target_battlers
  446.       if target.damage != nil and target.damage != "Miss"
  447.         @active_battler.hp += target.damage
  448.         @active_battler.damage = 0 - target.damage
  449.         @active_battler.damage_pop = true
  450.       end
  451.      end
  452.      end
  453.       j = 0
  454.       for i in $game_troop.enemies
  455.         j += i.hp
  456.       end
  457.        @phase4_step = 2 if j != 0
  458.     @lianji -= 1
  459.     elsif wqpd(18)
  460.       for target in @target_battlers
  461.       if target.damage != nil and target.damage != "Miss"
  462.         @active_battler.hp += target.damage
  463.         @active_battler.damage = 0 - target.damage
  464.         @active_battler.damage_pop = true
  465.       end
  466.       end
  467.     @phase4_step = 6
  468.     @lianji = 1
  469.    else
  470.     @phase4_step = 6
  471.     @lianji = 1
  472.    end
  473.    else
  474.    @phase4_step = 6
  475.    end
  476.    #k_特殊武器over...........................................
  477. end
  478.  
  479. def wqpd(id) #武器判定
  480.   return (@active_battler.weapon_id == 0 ? false :$data_weapons[@active_battler.weapon_id].element_set.include?(id) and (rand(100) < $data_system.elements[id].split(/,/)[1].to_i))
  481.   end
  482.   #--------------------------------------------------------------------------
  483.   # ● 刷新画面 (主回合步骤 6 : 刷新)
  484.   #--------------------------------------------------------------------------
  485.   def update_phase4_step6
  486.     # 清除强制行动对像的战斗者
  487.     $game_temp.forcing_battler = nil
  488.     # 公共事件 ID 有效的情况下
  489.     if @common_event_id > 0
  490.       # 设置事件
  491.       common_event = $data_common_events[@common_event_id]
  492.       $game_system.battle_interpreter.setup(common_event.list, 0)
  493.     end
  494.     # 移至步骤 1
  495.     @phase4_step = 1
  496.   end
  497. end





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1