#============================================================================
#                        延迟性物品
#                        很可能有BUG
#============================================================================
$item_delay = {17=>1,18=>3}
#设定属性与回合数的联系
#用法 : 属性id =>延迟回合数(为大于0的整数)
#=============================================================================
$item_delay_animation = {33=>23,34=>23}
#延迟的物品真正发动效果时对方的动画 
#用法 :  物品id =>动画id
#=============================================================================
$item_delay_text = "延迟效果发动"
#一个物品真正发动时显示物品名字和上面的字
#用法 : 不解释
#============================================================================
class Game_Battler
  #--------------------------------------------------------------------------
  # ● 初始化改
  # 
  #--------------------------------------------------------------------------
  alias old_initialize initialize
  def initialize
    old_initialize
    @item_delay = {}
  end
  #--------------------------------------------------------------------------
  # ● 记录推迟物品
  #     item : 物品
  #--------------------------------------------------------------------------
  def item_delay_set(item,turn)
    if @item_delay[item.id] == nil
      @item_delay[item.id] = [turn]
    else
      @item_delay[item.id].push(turn)
    end
  end  
  #--------------------------------------------------------------------------
  # ● 药物延迟刷新
  #--------------------------------------------------------------------------
  def item_delay_update
    for i in @item_delay.keys
      for d in 0...@item_delay[i].size
        if @item_delay[i][d] > 0
         @item_delay[i][d] -= 1
       else
          $scene.item_delay_text($data_items[i].name)
          @animation_id = $item_delay_animation[$data_items[i].id] if $item_delay_animation[$data_items[i].id] != nil
          item_effect($data_items[i])
          @item_delay[i].delete(0)
          @item_delay.delete(i) if @item_delay[i] == []
        end
      end  
    end  
  end
end
#=============================================================================
class Game_Actor < Game_Battler
end
class Game_Enemy < Game_Battler
end
#=============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # ● 生成物品行动结果
  #--------------------------------------------------------------------------
  def make_item_action_result
    # 获取物品
    @item = $data_items[@active_battler.current_action.item_id]
    # 因为物品耗尽而无法使用的情况下
    unless $game_party.item_can_use?(@item.id)
      # 移至步骤 1
      @phase4_step = 1
      return
    end
    # 消耗品的情况下
    if @item.consumable
      # 使用的物品减 1
      $game_party.lose_item(@item.id, 1)
    end
    # 在帮助窗口显示物品名
    @help_window.set_text(@item.name, 1)
    # 设置动画 ID
    @animation1_id = @item.animation1_id
    @animation2_id = @item.animation2_id
    # 设置公共事件 ID
    @common_event_id = @item.common_event_id
    # 确定对像
    index = @active_battler.current_action.target_index
    target = $game_party.smooth_target_actor(index)
    # 设置对像侧战斗者
    set_target_battlers(@item.scope)
    # 应用物品效果★
    for target in @target_battlers
      delay = false
      for i in @item.element_set
      if $item_delay[i] != nil
       if target.is_a?(Game_Actor)
      target.item_delay_set(@item,$item_delay[i]-1)
        else
      target.item_delay_set(@item,$item_delay[i])
       end
      delay = true
      end
      end
      target.item_effect(@item) if delay == false
    end
  end
  #--------------------------------------------------------------------------
  # ● 刷新画面 (主回合步骤 1 : 准备行动)
  #--------------------------------------------------------------------------
  def update_phase4_step1
    # 隐藏帮助窗口
    @help_window.visible = false
    # 判定胜败
    if judge
      # 胜利或者失败的情况下 : 过程结束
      return
    end
    # 强制行动的战斗者不存在的情况下
    if $game_temp.forcing_battler == nil
      # 设置战斗事件
      setup_battle_event
      # 执行战斗事件中的情况下
      if $game_system.battle_interpreter.running?
        return
      end
    end
    # 强制行动的战斗者存在的情况下
    if $game_temp.forcing_battler != nil
      # 在头部添加后移动
      @action_battlers.delete($game_temp.forcing_battler)
      @action_battlers.unshift($game_temp.forcing_battler)
    end
    # 未行动的战斗者不存在的情况下 (全员已经行动)
    if @action_battlers.size == 0
      # 开始同伴命令回合
      start_phase2
      return
    end
    # 初始化动画 ID 和公共事件 ID
    @animation1_id = 0
    @animation2_id = 0
    @common_event_id = 0
    # 未行动的战斗者移动到序列的头部
    @active_battler = @action_battlers.shift
    # 如果已经在战斗之外的情况下
    if @active_battler.index == nil
      return
    end
    # 连续伤害
    if @active_battler.hp > 0 and @active_battler.slip_damage?
      @active_battler.slip_damage_effect
      @active_battler.damage_pop = true
    end
    # 自然解除状态
    @active_battler.remove_states_auto
    # 物品延迟刷新★
    @active_battler.item_delay_update
    # 刷新状态窗口
    @status_window.refresh
    # 移至步骤 2
    @phase4_step = 2
  end
  #--------------------------------------------------------------------------
  # ● 延迟物品帮助窗口
  #--------------------------------------------------------------------------
  def item_delay_text(name)
    @help_window.set_text(name+$item_delay_text , 1)
  end
end