查看: 2405|回复: 3

[已经解决] 角色仓库(战斗换人)脚本 和 自动战斗脚本产生了冲突...

[复制链接]
梦石
0
星屑
94
在线时间
157 小时
注册时间
2006-7-2
回帖
250
发表于 2015-9-10 13:42:53 | 显示全部楼层 |阅读模式

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

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

×

请教各位大虾,现在我用了以上两个脚本但是发生了冲突。
这两个脚本中都有增加战斗时候的选项框,结果导致无法兼容。

角色仓库脚本 增加了  “换人”的选项
自动战斗脚本  增加了  “自动” 和 “逃跑”选项

请教这两个脚本要怎么改才能够兼容呢。。。

角色仓库脚本

[pre lang="ruby"]#=============================================================================
# 队伍系统 Ver 2.0
#-----------------------------------------------------------------------------
# 类似于 Aveyond 的队伍系统(根据阿月系列的游戏产生的灵感)
# By :RyanBern
#-----------------------------------------------------------------------------
# 功能特色:
#-----------------------------------------------------------------------------
# 1.更改队伍中成员的最大数量,有四名出战队员,但是替补队员可以有很多个。
# 2.对 Game_Party 的队员设置和 Scene_Battle 的部分方法有较大改动,可能造成脚本
#   冲突。
# 3.为队伍增加“领队”角色,作为“领队”的成员在地图上显示他的图形。
# 4.在战斗命令中增添“换人”命令,可以将替补队员换上场。
# 5.如果队伍的出战队员全部阵亡,则直接判定玩家全灭,不管有无替补队员。但是如果
#   在地图上,则是所有队员阵亡才会被判定全灭。
# 6.事件编译器中,对全体同伴的处理均包括对替补队员的处理。
#-----------------------------------------------------------------------------
# 使用方法:
#-----------------------------------------------------------------------------
# 1.粘贴到默认脚本后面,Main组前面即可。
# 2.在菜单中,左侧窗口被激活时,按 A 键可以改变领队(leader)的设置,按 S 键
#   可以改变出战的队员。 (要按空格来切换)
# 3.为队员设置“无法出战”的状态,即该队员不能被设置为出战队员。具体方法是
#   使用事件脚本,例如,让 1 号角色无法出战:
#   $game_actors[1].battle_disabled = true
#   让 1 号角色恢复可以出战的状态:
#   $game_actors[1].battle_disabled = false
#   ###
# 4.可在下方设置替补队员在战斗胜利之后是否获得 EXP 奖励。
#=============================================================================


module RB
end

module RB::Party
  # “换人”命令的术语
  Words_Swap = "换人"
  
  # 替补队员是否能在战斗胜利后获得 EXP 奖励,设置为 true 时可以获得奖励,设置
  # 为 false 时则不能。
  Get_Exp_Reserve = true
end

class Game_Temp
  attr_accessor :gain_exp_flag
end

class Game_Party
  attr_reader :leader
  attr_reader :battle_actors
  alias old_ini initialize
  def initialize
    @leader = nil
    @battle_actors = []
    old_ini
  end
  def leader=(leader)
    @leader = leader
    $game_player.refresh
    $game_map.need_refresh = true
  end
  def set_leader(actor_id)
    self.leader = $game_actors[actor_id]
  end
  def actors
    all_flag = !$game_temp.in_battle || (RB::Party::Get_Exp_Reserve && $game_temp.gain_exp_flag)
    return all_flag ? @actors : @battle_actors
  end
  def all_actors
    return @actors
  end
  #--------------------------------------------------------------------------
  # ● 加入同伴
  #     actor_id : 角色 ID
  #--------------------------------------------------------------------------
  def add_actor(actor_id)
    # 获取角色
    actor = $game_actors[actor_id]
    # 同伴人数未满 4 人、本角色不在队伍中的情况下
    unless @actors.include?(actor)
      # 添加角色
      @actors.push(actor)
      @battle_actors.push(actor) if @battle_actors.size < 4
      self.leader = actor if self.leader.nil?
      # 还原主角
      $game_player.refresh
    end
  end
  #--------------------------------------------------------------------------
  # ● 角色离开
  #     actor_id : 角色 ID
  #--------------------------------------------------------------------------
  def remove_actor(actor_id)
    actor = $game_actors[actor_id]
    # 删除角色
    @actors.delete(actor)
    @battle_actors.delete(actor)
    self.leader = self.actors[0] if self.leader == actor
    # 还原主角
    $game_player.refresh
  end
  #--------------------------------------------------------------------------
  # ● 设置初期同伴
  #--------------------------------------------------------------------------
  def setup_starting_members
    @actors = []
    @battle_actors = []
    for i in $data_system.party_members
      @actors.push($game_actors)
      @battle_actors.push($game_actors) if @battle_actors.size < 4
    end
    self.leader = @actors[0]
  end
  #--------------------------------------------------------------------------
  # ● 设置战斗测试用同伴
  #--------------------------------------------------------------------------
  def setup_battle_test_members
    @actors = []
    @battle_actors = []
    for battler in $data_system.test_battlers
      actor = $game_actors[battler.actor_id]
      actor.level = battler.level
      gain_weapon(battler.weapon_id, 1)
      gain_armor(battler.armor1_id, 1)
      gain_armor(battler.armor2_id, 1)
      gain_armor(battler.armor3_id, 1)
      gain_armor(battler.armor4_id, 1)
      actor.equip(0, battler.weapon_id)
      actor.equip(1, battler.armor1_id)
      actor.equip(2, battler.armor2_id)
      actor.equip(3, battler.armor3_id)
      actor.equip(4, battler.armor4_id)
      actor.recover_all
      @actors.push(actor)
      @battle_actors.push(actor)
    end
    @items = {}
    for i in 1...$data_items.size
      if $data_items.name != ""
        occasion = $data_items.occasion
        if occasion == 0 or occasion == 1
          @items = 99
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 同伴成员的还原
  #--------------------------------------------------------------------------
  def refresh
    # 游戏数据载入后角色对像直接从 $game_actors
    # 分离。
    # 回避由于载入造成的角色再设置的问题。
    new_actors = []
    new_battle_actors = []
    @actors.each do |actor|
      if $data_actors[actor.id] != nil
        new_actors.push($game_actors[actor.id])
      end
    end
    @battle_actors.each do |actor|
      if $data_actors[actor.id] != nil
        new_battle_actors.push($game_actors[actor.id])
      end
    end
    @actors = new_actors
    @battle_actors = new_battle_actors
  end
  #--------------------------------------------------------------------------
  # ● 全灭判定
  #--------------------------------------------------------------------------
  def all_dead?
    # 同伴人数为 0 的情况下
    if self.actors.size == 0
      return false
    end
    # 同伴中无人 HP 在 0 以上
    for actor in self.actors
      if actor.hp > 0
        return false
      end
    end
    # 全灭
    return true
  end
  #--------------------------------------------------------------------------
  # ● 对像角色的随机确定
  #     hp0 : 限制为 HP 0 的角色
  #--------------------------------------------------------------------------
  def random_target_actor(hp0 = false)
    # 初始化轮流
    roulette = []
    # 循环
    for actor in @battle_actors
      # 符合条件的场合
      if (not hp0 and actor.exist?) or (hp0 and actor.hp0?)
        # 获取角色职业的位置 [位置]
        position = $data_classes[actor.class_id].position
        # 前卫的话 n = 4、中卫的话 n = 3、后卫的话 n = 2
        n = 4 - position
        # 添加角色的轮流 n 回
        n.times do
          roulette.push(actor)
        end
      end
    end
    # 轮流大小为 0 的情况
    if roulette.size == 0
      return nil
    end
    # 转轮盘赌,决定角色
    return roulette[rand(roulette.size)]
  end
  #--------------------------------------------------------------------------
  # ● 对像角色的顺序确定
  #     actor_index : 角色索引
  #--------------------------------------------------------------------------
  def smooth_target_actor(actor_index)
    # 取得对像
    actor = @battle_actors[actor_index]
    # 对像存在的情况下
    if actor != nil and actor.exist?
      return actor
    end
    # 循环
    for actor in @actors
      # 对像存在的情况下
      if actor.exist?
        return actor
      end
    end
  end

end

class Game_Actor
  attr_reader :battle_disabled
  def leader?
    return self == $game_party.leader
  end
  def active
    return $game_party.battle_actors.include?(self)
  end
  def battle_disabled=(bool)
    @battle_disabled = bool
    $game_party.battle_actors.delete(self) if bool
  end
end

class Game_Player
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    # 同伴人数为 0 的情况下
    if $game_party.actors.size == 0 or $game_party.leader == nil
      # 清除角色的文件名及对像
      @character_name = ""
      @character_hue = 0
      # 分支结束
      return
    end
    # 获取带头的角色
    if $game_party.leader != nil
      actor = $game_party.leader
      # 设置角色的文件名及对像
      @character_name = actor.character_name
      @character_hue = actor.character_hue
      # 初始化不透明度和合成方式子
      @opacity = 255
      @blend_type = 0
    end
  end
end

class Game_BattleAction
  attr_accessor :reserved_actor_id
  unless method_defined? :rb_clear_20150422
    alias rb_clear_20150422 clear
    def clear
      rb_clear_20150422
      @reserved_actor_id = 0
    end
  end
end

class Window_Base < Window
  def draw_actor_battle_position(actor, x, y)
    if actor.leader?
      if actor.active
        text = "领队|出战"
      else
        text = "领队"
      end
      color = knockout_color
    else
      color = disabled_color
      if actor.battle_disabled
        text = "无法出战"
      elsif actor.active
        text = "出战"
        color = normal_color
      else
        text = "待机"
      end
    end
    self.contents.font.color = color
    self.contents.draw_text(x, y, 120, 32, text)
  end
end

#==============================================================================
# ■ Window_Selectable
#------------------------------------------------------------------------------
#  拥有光标的移动以及滚动功能的窗口类。
#==============================================================================

class Window_Selectable < Window_Base
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_accessor :row_height               # 行高
  #--------------------------------------------------------------------------
  # ● 初始画对像
  #     x      : 窗口的 X 坐标
  #     y      : 窗口的 Y 坐标
  #     width  : 窗口的宽
  #     height : 窗口的高
  #     row_height : 行高 默认是32
  #--------------------------------------------------------------------------
  alias rb_initialize_20150421 initialize
  def initialize(x, y, width, height, row_height = 32)
    @row_height = row_height
    rb_initialize_20150421(x, y, width, height)
  end
  #--------------------------------------------------------------------------
  # ● 获取开头行
  #--------------------------------------------------------------------------
  def top_row
    # 将窗口内容的传送源 Y 坐标、1 行的高 @row_height 等分
    return self.oy / @row_height
  end
  #--------------------------------------------------------------------------
  # ● 设置开头行
  #     row : 显示开头的行
  #--------------------------------------------------------------------------
  def top_row=(row)
    # row 未满 0 的场合更正为 0
    if row < 0
      row = 0
    end
    # row 超过 row_max - 1 的情况下更正为 row_max - 1
    if row > row_max - 1
      row = row_max - 1
    end
    # row 1 行高的 @row_height 倍、窗口内容的传送源 Y 坐标
    self.oy = row * @row_height
  end
  #--------------------------------------------------------------------------
  # ● 获取 1 页可以显示的行数
  #--------------------------------------------------------------------------
  def page_row_max
    # 窗口的高度,设置画面的高度减去 32 ,除以 1 行的高度 @row_height
    return (self.height - 32) / @row_height
  end
  #--------------------------------------------------------------------------
  # ● 更新光标举行
  #--------------------------------------------------------------------------
  def update_cursor_rect
    # 光标位置不满 0 的情况下
    if @index < 0
      self.cursor_rect.empty
      return
    end
    # 获取当前的行
    row = @index / @column_max
    # 当前行被显示开头行前面的情况下
    if row < self.top_row
      # 从当前行向开头行滚动
      self.top_row = row
    end
    # 当前行被显示末尾行之后的情况下
    if row > self.top_row + (self.page_row_max - 1)
      # 从当前行向末尾滚动
      self.top_row = row - (self.page_row_max - 1)
    end
    # 计算光标的宽
    cursor_width = self.width / @column_max - 32
    # 计算光标坐标
    x = @index % @column_max * (cursor_width + 32)
    y = @index / @column_max * @row_height - self.oy
    # 更新国标矩形
    self.cursor_rect.set(x, y, cursor_width, @row_height)
  end
end

class Window_MenuStatus
  def initialize
    super(0, 0, 480, 480, 112)
    refresh
    self.active = false
    self.index = -1
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @item_max = $game_party.actors.size
    self.contents = Bitmap.new(width - 32, @item_max == 0 ? 32 : @item_max * 112)
    for i in 0...$game_party.actors.size
      x = 64
      y = i * 112
      actor = $game_party.actors
      draw_actor_graphic(actor, x - 40, y + 80)
      draw_actor_name(actor, x, y)
      draw_actor_class(actor, x + 144, y)
      draw_actor_level(actor, x, y + 32)
      draw_actor_state(actor, x + 90, y + 32)
      draw_actor_exp(actor, x, y + 64)
      draw_actor_hp(actor, x + 236, y + 32)
      draw_actor_sp(actor, x + 236, y + 64)
      draw_actor_battle_position(actor, x + 236, y)
    end
  end
  def update_cursor_rect
    super
  end
end

class Window_Target
  def initialize
    super(0, 0, 336, 480, 112)
    self.z += 10
    @item_max = $game_party.actors.size
    self.contents = Bitmap.new(width - 32, @item_max == 0 ? 32 : @item_max * 112)
    refresh
  end
  def update_cursor_rect
    super
  end
end

class Window_ReservedActors < Window_Selectable
  def initialize
    super(0, 64, 640, 256, 112)
    self.opacity = 160
    self.index = 0
    self.active = true
    @column_max = 2
    refresh
  end
  def actor
    return @data[self.index]
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    $game_party.all_actors.each do |actor|
      @data << actor unless actor.active || actor.battle_disabled
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new (width - 32, (@item_max + 1) / 2 * 128)
      @data.each_with_index do |actor, index|
        x = 4 + index % 2 * (288 + 32)
        y = index / 2 * 112
        draw_actor_graphic(actor, x + 16, y + 80)
        draw_actor_hp(actor, x + 48, y + 20)
        draw_actor_sp(actor, x + 48, y + 52)
      end
    end
  end
  def update_help
    # 帮助窗口显示角色的状态
    self.actor == nil ? @help_window.set_text("") : @help_window.set_actor(self.actor)
  end
end

class Scene_Menu
  unless method_defined? :rb_update_command_20150421
    alias rb_update_command_20150421 update_command
    def update_command
      if Input.trigger?(Input::X)
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
        @leader_adjust = true
        return
      end
      if Input.trigger?(Input::Y)
        $game_system.se_play($data_system.decision_se)
        @command_window.active = false
        @status_window.active = true
        @status_window.index = 0
        @battler_adjust = true
        return
      end
      rb_update_command_20150421
    end
  end
  unless method_defined? :rb_update_status_20150421
    alias rb_update_status_20150421 update_status
    def update_status
      if @leader_adjust
        update_leader
        return
      end
      if @battler_adjust
        update_battler
        return
      end
      rb_update_status_20150421
    end
  end
  def update_leader
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @leader_adjust = false
      @status_window.active = false
      @status_window.index = -1
      @command_window.active = true
      return
    end
    if Input.trigger?(Input::C)
      if $game_party.actors.size == 0
        $game_system.se_play($data_system.buzzer_se)
      else
        $game_system.se_play($data_system.decision_se)
        $game_party.leader = $game_party.actors[@status_window.index]
        @status_window.refresh
      end
    end
  end
  def update_battler
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @battler_adjust = false
      @status_window.active = false
      @status_window.index = -1
      @command_window.active = true
      return
    end
    if Input.trigger?(Input::C)
      actor = $game_party.actors[@status_window.index]
      if actor == nil || actor.battle_disabled ||
        (actor.active && $game_party.battle_actors.size == 1) ||
        (!actor.active && $game_party.battle_actors.size == 4)
        $game_system.se_play($data_system.buzzer_se)
      else
        $game_system.se_play($data_system.decision_se)
        actor.active ? $game_party.battle_actors.delete(actor) : $game_party.battle_actors.push(actor)
        @status_window.refresh
      end
    end
  end
end

class Scene_Battle
  def generate_modified_command_window
    if @actor_command_window != nil
      @actor_command_window.dispose
      @actor_command_window = nil
    end
    s1 = $data_system.words.attack
    s2 = $data_system.words.skill
    s3 = $data_system.words.guard
    s4 = $data_system.words.item
    s5 = RB::Party::Words_Swap
    @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4, s5])
    @actor_command_window.y = 128
    @actor_command_window.back_opacity = 160
    @actor_command_window.active = false
    @actor_command_window.visible = false
    @modified_generated = true
  end
  unless method_defined? :rb_phase3_setup_command_window_20150422
    alias rb_phase3_setup_command_window_20150422 phase3_setup_command_window
    def phase3_setup_command_window
      generate_modified_command_window unless @modified_generated
      rb_phase3_setup_command_window_20150422
    end
  end
  def update_phase3_basic_command
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 转向前一个角色的指令输入
      phase3_prior_actor
      return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 角色指令窗口光标位置分之
      case @actor_command_window.index
      when 0  # 攻击
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 设置行动
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 0
        # 开始选择敌人
        start_enemy_select
      when 1  # 特技
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 设置行动
        @active_battler.current_action.kind = 1
        # 开始选择特技
        start_skill_select
      when 2  # 防御
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 设置行动
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 1
        # 转向下一位角色的指令输入
        phase3_next_actor
      when 3  # 物品
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 设置行动
        @active_battler.current_action.kind = 2
        # 开始选择物品
        start_item_select
      when 4  # 换人
        $game_system.se_play($data_system.decision_se)
        @active_battler.current_action.kind = 3
        start_reserved_actor_select
      end
      return
    end
  end
  unless method_defined? :rb_update_phase3_20150422
    alias rb_update_phase3_20150422 update_phase3
    def update_phase3
      if @actor_window != nil
        update_phase3_reserved_actor_select
        return
      end
      rb_update_phase3_20150422
    end
  end
  def start_reserved_actor_select
    # 生成特技窗口
    @actor_window = Window_ReservedActors.new
    # 关联帮助窗口
    @actor_window.help_window = @help_window
    @help_window.visible = true
    # 无效化角色指令窗口
    @actor_command_window.active = false
    @actor_command_window.visible = false
  end
  def end_reserved_actor_select
    # 释放特技窗口
    @actor_window.dispose
    @actor_window = nil
    # 隐藏帮助窗口
    @help_window.visible = false
    # 有效化角色指令窗口
    @actor_command_window.active = true
    @actor_command_window.visible = true
  end
  def update_phase3_reserved_actor_select
    @actor_window.visible = true
    # 刷新特技窗口
    @actor_window.update
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 结束特技选择
      end_reserved_actor_select
      return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 获取特技选择窗口现在选择的特技的数据
      @reserved_actor = @actor_window.actor
      # 无法使用的情况下
      if @reserved_actor == nil
        # 演奏冻结 SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 演奏确定 SE
      $game_system.se_play($data_system.decision_se)
      # 设置行动
      @active_battler.current_action.reserved_actor_id = @reserved_actor.id
      # 设置特技窗口为不可见状态
      @actor_window.visible = false
      end_reserved_actor_select
      phase3_next_actor
      return
    end
  end
  def update_phase4_step2
    # 如果不是强制行动
    unless @active_battler.current_action.forcing
      # 限制为 [敌人为普通攻击] 或 [我方为普通攻击] 的情况下
      if @active_battler.restriction == 2 or @active_battler.restriction == 3
        # 设置行动为攻击
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 0
      end
      # 限制为 [不能行动] 的情况下
      if @active_battler.restriction == 4
        # 清除行动强制对像的战斗者
        $game_temp.forcing_battler = nil
        # 移至步骤 1
        @phase4_step = 1
        return
      end
    end
    # 清除对像战斗者
    @target_battlers = []
    # 行动种类分支
    case @active_battler.current_action.kind
    when 0  # 基本
      make_basic_action_result
    when 1  # 特技
      make_skill_action_result
    when 2  # 物品
      make_item_action_result
    when 3  # 换人
      make_swap_action_result
    end
    # 移至步骤 3
    if @phase4_step == 2
      @phase4_step = 3
    end
  end
  def make_swap_action_result
    # 获取角色
    @reserved_actor = $game_actors[@active_battler.current_action.reserved_actor_id]
    # 无法替换的情况下
    if @reserved_actor == nil || @reserved_actor.active
      # 移至步骤 1
      @phase4_step = 1
      return
    end
    # 在帮助窗口显示文字
    text = "与#{@reserved_actor.name}交换"
    @help_window.set_text(text, 1)
    # 设置动画 ID
    @animation1_id = 0
    index = $game_party.actors.index(@active_battler)
    $game_party.actors[index] = @reserved_actor
  end
  unless method_defined? :rb_start_phase5_20150422
    alias rb_start_phase5_20150422 start_phase5
    def start_phase5
      $game_temp.gain_exp_flag = true
      rb_start_phase5_20150422
      $game_temp.gain_exp_flag = false
    end
  end
end

    [/pre]


自动战斗脚本

[pre lang="ruby"]#==============================================================================
# ★【  自动战斗  】★
#==============================================================================
#  by -> 芯☆淡如水
#==============================================================================
# ● 使用方法:复制该脚本,插入到 main 前。
#==============================================================================
# ● 说明:
#         自动战斗,顾名思义,就是角色选择“自动战斗”后,无需玩家给角色下达
#      指令,角色仍可自己行动。
#        
#         该自动战斗有 2 个模式:普通自动战斗 和 AI自动战斗。2 种模式的切换
#       使用下面设置项的开关。
#
#         角色在 普通自动战斗 时,只是普通攻击敌人。选择的敌人目标偏向血较少
#      者。
#
#         角色在 AI自动战斗 时,判断角色行动类型的流程为:复活同伴 --》 恢复
#      同伴(HP和SP)--》攻击。
#         如果队伍中有同伴死亡,有很大几率复活同伴(具体多大几率就不透露),
#      死亡的同伴个数越多,几率越大。复活同伴的前提条件是有复活类药品或特技。
#         跳过复活同伴是恢复同伴,恢复同伴的几率以整体的剩余HP/SP的百分比来
#      算,百分比越小,几率越高。单体恢复同伴HP/SP的恢复对象,偏向HP/SP较少
#      者。恢复同伴的前提条件是有恢复类药品或特技。
#         最后是攻击,攻击判断之前有一定的几率对同伴使用 增益特技。攻击分为
#      普通攻击和使用特技,几率以角色的不同而不同,如果是战士类型的角色,普通
#      攻击的几率高于使用特技的几率;法师类型的角色则相反。使用特技时有一定的
#      几率使用不良状态特技。所有使用特技都是以角色已习得的特技为基础。普通攻
#      击和使用单体攻击特技的对象目标,也是偏向血较少者。
#
#
#   ■ 恢复:     自动战斗者在恢复同伴时,首先确定恢复对象,根据对象需要恢复的
#               HP/SP 的多少,来确定使用的物品或特技。需要恢复的对象越多,使用
#               “己方全体”的物品或特技的几率越大,单个的恢复对象是不会使用
#               “己方全体”的物品或特技。
#              
#                比如确定了某个恢复对象,该对象需要回复 HP 100 ,所能使用的物品
#               或特技有 3 种:回复 HP 60 ;回复 HP 110 ;回复 HP 220 。那么自动
#               战斗者会选择 “回复 HP 110” 的这个物品或特技来恢复该对象。
#
#
#   ■ 特技攻击:  如果自动战斗者能够使用“敌全体”特技,并且敌人的数量是 2 个
#               或以上时,自动战斗者有几率使用“敌全体”特技,敌人数量越多,几
#               率越大。
#
#                  如果是单个攻击对象,首先确定对象,根据该对象剩余的 HP 来选择
#               特技。在这之前会先判断普通攻击能否打倒该对象,如果能打倒该对象,
#               就使用普通攻击,而不使用特技了。
#
#               比如:例1:攻击对象剩余HP:160 ,自动战斗者可使用的特技有:对该
#                          对象伤害 HP 180 和 伤害 HP 260 两个特技,但自动战斗者
#                          对该对象的普通攻击伤害为:HP 200 ,那么自动战斗者会
#                          选择普通攻击而不使用特技。
#
#                     例2:攻击对象剩余HP:2000 ,自动战斗者可使用的特技有:对该
#                          对象伤害 HP 200 ; 伤害 HP 600 ;伤害 HP 1000 三种,
#                          那么自动战斗者会选择 伤害 HP 1000 的这个特技来攻击该
#                          对象。
#==============================================================================
# ● 设置:
#------------------------------------------------------------------------------
# 打开或关闭 自动战斗功能 的开关 ID。
AUTO_SWEITCHE = 593
#------------------------------------------------------------------------------
# 是否 AI自动战斗 的开关 ID。该开关打开为 AI自动;关闭为 普通自动。
AI_AUTO_SWEITCHE = 594
#------------------------------------------------------------------------------
# 角色自动战斗时,自动提示的等待时间(帧)。
WAIT_TIME = 50
#------------------------------------------------------------------------------
# 增益状态 特技 ID 。
UP_PLUS_SKILLS = [53, 54]
#------------------------------------------------------------------------------
# 不良状态 特技 ID 。
DOWN_PLUS_SKILLS = [41, 46]
#=============================================================================
##############################################################################
#=============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  attr_accessor :auto_battle
  attr_accessor :auto_battle_targets
  #--------------------------------------------------------------------------
  alias add_setup_xdrs setup
  def setup(actor_id)
    @auto_battle = false
    @auto_battle_targets = []
    add_setup_xdrs(actor_id)
  end
end
#==============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  def main
    # 初始化战斗用的各种暂时数据
    $game_temp.in_battle = true
    $game_temp.battle_turn = 0
    $game_temp.battle_event_flags.clear
    $game_temp.battle_abort = false
    $game_temp.battle_main_phase = false
    $game_temp.battleback_name = $game_map.battleback_name
    $game_temp.forcing_battler = nil
    # 初始化战斗用事件解释器
    $game_system.battle_interpreter.setup(nil, 0)
    # 准备队伍
    @troop_id = $game_temp.battle_troop_id
    $game_troop.setup(@troop_id)
    # 生成角色命令窗口
    s1 = $data_system.words.attack
    s2 = $data_system.words.skill
    s3 = $data_system.words.guard
    s4 = $data_system.words.item
    s5 = "自动"
    s6 = "逃跑"
    if $game_switches[AUTO_SWEITCHE]
      @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
      @actor_command_window.y = 96
    else
      @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4, s6])
      @actor_command_window.y = 128
    end
    @actor_command_window.back_opacity = 160
    @actor_command_window.active = false
    @actor_command_window.visible = false
    # 生成其它窗口
    #
    @auto_top = Window_Base.new(0, 256, 160, 64)
    @auto_top.contents = Bitmap.new(@auto_top.width - 32, @auto_top.height - 32)
    @auto_top.contents.draw_text(0, 0, 138, 32,"确定键:取消自动")
    @auto_top.back_opacity = 160
    @auto_top.visible = false
    #
    @party_command_window = Window_PartyCommand.new
    @help_window = Window_Help.new
    @help_window.back_opacity = 160
    @help_window.visible = false
    @status_window = Window_BattleStatus.new
    @message_window = Window_Message.new
    # 生成活动块
    @spriteset = Spriteset_Battle.new
    # 初始化等待计数
    @wait_count = 0
    @auto_wait_count = 0
    # 执行过渡
    if $data_system.battle_transition == ""
      Graphics.transition(20)
    else
      Graphics.transition(40, "Graphics/Transitions/" +
        $data_system.battle_transition)
    end
    # 开始自由战斗回合
    start_phase1
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果画面切换的话就中断循环
      if $scene != self
        break
      end
    end
    # 刷新地图
    $game_map.refresh
    # 准备过渡
    Graphics.freeze
    # 释放窗口
    @auto_top.dispose
    @actor_command_window.dispose
    @party_command_window.dispose
    @help_window.dispose
    @status_window.dispose
    @message_window.dispose
    if @skill_window != nil
      @skill_window.dispose
    end
    if @item_window != nil
      @item_window.dispose
    end
    if @result_window != nil
      @result_window.dispose
    end
    # 释放活动块
    @spriteset.dispose
    # 标题画面切换中的情况
    if $scene.is_a?(Scene_Title)
      # 淡入淡出画面
      Graphics.transition
      Graphics.freeze
    end
    # 战斗测试或者游戏结束以外的画面切换中的情况
    if $BTEST and not $scene.is_a?(Scene_Gameover)
      $scene = nil
    end
  end
  #--------------------------------------------------------------------------
  def start_phase2
    # 转移到回合 2
    @phase = 2
    # 设置角色为非选择状态
    @actor_index = -1
    @active_battler = nil
    unless $game_party.inputable?
      # 开始主回合
      start_phase4
      return
    end
    start_phase3
  end
  #--------------------------------------------------------------------------
  def phase3_prior_actor
    # 循环
    begin
      # 角色的明灭效果 OFF
      if @active_battler != nil
        @active_battler.blink = false
      end
      # 最初的角色的情况下
      if @actor_index == 0
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # 返回角色索引
      @actor_index -= 1
      @active_battler = $game_party.actors[@actor_index]
      @active_battler.blink = true
    # 如果角色是在无法接受指令的状态就再试
    end until @active_battler.inputable?
    # 设置角色的命令窗口
    phase3_setup_command_window
  end
#--------------------------------------------------------------------------
  def update_phase3_basic_command
    # 按下 B 键的情况下
    if Input.trigger?(Input::B)
      # 演奏取消 SE
      $game_system.se_play($data_system.cancel_se)
      # 转向前一个角色的指令输入
      phase3_prior_actor
      return
    end
    # 按下 C 键的情况下
    if Input.trigger?(Input::C)
      # 角色指令窗口光标位置分之
      case @actor_command_window.index
      when 0  # 攻击
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 设置行动
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 0
        # 开始选择敌人
        start_enemy_select
      when 1  # 特技
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 设置行动
        @active_battler.current_action.kind = 1
        # 开始选择特技
        start_skill_select
      when 2  # 防御
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 设置行动
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 1
        # 转向下一位角色的指令输入
        phase3_next_actor
      when 3  # 物品
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 设置行动
        @active_battler.current_action.kind = 2
        # 开始选择物品
        start_item_select
      when 4  # 自动
        if $game_switches[AUTO_SWEITCHE]
          # 演奏确定 SE
          $game_system.se_play($data_system.decision_se)
          @actor_command_window.active = false
          @actor_command_window.visible = false
          @active_battler.auto_battle = true
          phase3_next_actor
        else
           # 演奏确定 SE
          $game_system.se_play($data_system.decision_se)
          # 逃走处理
          update_phase2_escape
        end        
      when 5  # 逃跑
        # 不能逃跑的情况下
        if $game_temp.battle_can_escape == false
          # 演奏冻结 SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # 演奏确定 SE
        $game_system.se_play($data_system.decision_se)
        # 逃走处理
        update_phase2_escape
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  alias add_phase3_setup_command_window_xdrs phase3_setup_command_window
  def phase3_setup_command_window
    if @active_battler.auto_battle
      @auto_wait_count = WAIT_TIME
      @actor_command_window.active = false
      @actor_command_window.visible = false
      @auto_top.visible = true
      @auto_top.x = @actor_index * 160
      return
    end
    add_phase3_setup_command_window_xdrs
  end
  #--------------------------------------------------------------------------
  alias add_update_phase3_xdrs update_phase3
  def update_phase3
    if @auto_wait_count > 0
      update_wait_at
      return
    end
    add_update_phase3_xdrs
  end
  #--------------------------------------------------------------------------
  def update_wait_at
    @auto_wait_count -= 1
    if @auto_wait_count == 0
      $game_system.se_play($data_system.decision_se)
      @auto_top.visible = false
      phase3_next_actor
      return
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      @auto_wait_count = 0
      phase3_prior_actor
      return
    end
    if Input.trigger?(Input::C)
      $game_system.se_play($data_system.decision_se)
      @auto_wait_count = 0
      @active_battler.auto_battle = false
      @auto_top.visible = false
      @actor_index -= 1
      phase3_next_actor
    end
  end
  #--------------------------------------------------------------------------
  def update_phase4_step2
    # 如果不是强制行动
    unless @active_battler.current_action.forcing
      # 限制为 [敌人为普通攻击] 或 [我方为普通攻击] 的情况下
      if @active_battler.restriction == 2 or @active_battler.restriction == 3
        # 设置行动为攻击
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 0
      end
      # 限制为 [不能行动] 的情况下
      if @active_battler.restriction == 4
        # 清除行动强制对像的战斗者
        $game_temp.forcing_battler = nil
        # 移至步骤 1
        @phase4_step = 1
        return
      end
    end
    # 清除对像战斗者
    @target_battlers = []
    if @active_battler.is_a?(Game_Actor)
      if @active_battler.auto_battle and not @active_battler.dead?
        set_auto_battle
        case @active_battler.current_action.kind
        when 0  
          make_basic_auto
        when 1  
          make_skill_auto
        when 2  
          make_item_auto
        end
        if @phase4_step == 2
          @phase4_step = 3
        end
        return
      end
    end
    # 行动种类分支
    case @active_battler.current_action.kind
    when 0  # 基本
      make_basic_action_result
    when 1  # 特技
      make_skill_action_result
    when 2  # 物品
      make_item_action_result
    end
    # 移至步骤 3
    if @phase4_step == 2
      @phase4_step = 3
    end
  end
  #--------------------------------------------------------------------------
  def make_basic_auto
    case @active_battler.current_action.basic
    when 0
      @animation1_id = @active_battler.animation1_id
      @animation2_id = @active_battler.animation2_id
      if @active_battler.restriction == 3
        target = $game_party.random_target_actor
        @active_battler.auto_battle_targets = []
        @active_battler.auto_battle_targets.push(target)
      elsif @active_battler.restriction == 2
        target = $game_troop.random_target_enemy
        @active_battler.auto_battle_targets = []
        @active_battler.auto_battle_targets.push(target)
      end
      @target_battlers = @active_battler.auto_battle_targets
      for target in @target_battlers
        target.attack_effect(@active_battler)
      end
      return
    when 1
      @help_window.set_text($data_system.words.guard, 1)
      return
    end
  end
  #--------------------------------------------------------------------------
  def make_skill_auto
    @skill = $data_skills[@active_battler.current_action.skill_id]
    unless @active_battler.current_action.forcing
      unless @active_battler.skill_can_use?(@skill.id)
        $game_temp.forcing_battler = nil
        @phase4_step = 1
        return
      end
    end
    @active_battler.sp -= @skill.sp_cost
    @status_window.refresh
    @help_window.set_text(@skill.name, 1)
    @animation1_id = @skill.animation1_id
    @animation2_id = @skill.animation2_id
    @common_event_id = @skill.common_event_id
    @target_battlers = @active_battler.auto_battle_targets
    for target in @target_battlers
      target.skill_effect(@active_battler, @skill)
    end
  end
  #--------------------------------------------------------------------------
  def make_item_auto
    @item = $data_items[@active_battler.current_action.item_id]
    unless $game_party.item_can_use?(@item.id)
      @phase4_step = 1
      return
    end
    if @item.consumable
      $game_party.lose_item(@item.id, 1)
    end
    @help_window.set_text(@item.name, 1)
    @animation1_id = @item.animation1_id
    @animation2_id = @item.animation2_id
    @common_event_id = @item.common_event_id
    @target_battlers = @active_battler.auto_battle_targets
    for target in @target_battlers
      target.item_effect(@item)
    end
  end
  #--------------------------------------------------------------------------
  alias add_update_phase4_step6_xdrs update_phase4_step6
  def update_phase4_step6
    @active_battler.auto_battle_targets = [] if @active_battler.is_a?(Game_Actor)
    add_update_phase4_step6_xdrs
  end
  #==============================================================================
  #==============================================================================
  def set_auto_battle
    if $game_switches[AI_AUTO_SWEITCHE]
      ai_auto_battle
    else
      base_atk
    end
  end
  #----------------------------------------------------------------------------
  def ai_auto_battle
    set_probability
    if rand (100) < @f_probability
      f_actor
      return
    end
    judge_r_actor
  end
  #----------------------------------------------------------------------------
  def set_probability
    @f_probability = 0
    h = mh = s = ms = 0.0
    if dead_actors != []
      @f_probability = 70
      @f_probability += (dead_actors.size - 1) * 20
    end
    for actor in all_actors
      h += actor.hp
      mh += actor.maxhp
      s += actor.sp
      ms += actor.maxsp
    end
    @rh_probability = 100 - (h / mh * 100).ceil
    @rh_probability += pressing_actor_hp.size * 30
    @rs_probability = 100 - (s / ms * 100).ceil
    @rs_probability += pressing_actor_sp.size * 30
  end
  #----------------------------------------------------------------------------
  def f_actor
    @f_skills = @f_items = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and [5, 6].include?(skill.scope)
        @f_skills.push(skill)
      end
    end
    for id in 1...$data_items.size
      item = $data_items[id]
      if $game_party.item_number(id) > 0 and [5, 6].include?(item.scope)
        @f_items.push(item)
      end
    end
    if @f_skills != [] or @f_items != []
      if rand (2) == 0
        if @f_skills != []
          f_actor_skill
          return
        end
        f_actor_item
        return
      else
        if @f_items != []
          f_actor_item
          return
        end
        f_actor_skill
        return
      end
    end
    judge_r_actor
  end
  #----------------------------------------------------------------------------
  def f_actor_skill
    @active_battler.current_action.kind = 1
    skill = @f_skills[rand (@f_skills.size)]
    @active_battler.current_action.skill_id = skill.id
    set_autobattler_targets
  end
  #----------------------------------------------------------------------------
  def f_actor_item
    @active_battler.current_action.kind = 2
    item = @f_items[rand (@f_items.size)]
    @active_battler.current_action.item_id = item.id
    set_autobattler_targets
  end
  #----------------------------------------------------------------------------
  def judge_r_actor
    if @rh_probability >= 30 and rand (120) < @rh_probability
      r_actor_hp
      return
    end
    if @rs_probability >= 50 and rand (150) < @rs_probability
      r_actor_sp
      return
    end
    judge_battle
  end
  #----------------------------------------------------------------------------
  def r_actor_hp
    if recover_hp_items != [] or recover_hp_skills != []   
      if rand (2) == 0
        if recover_hp_items != []
          r_hp_item
          return
        end
        r_hp_skill
        return
      else
        if recover_hp_skills != []
          r_hp_skill
          return
        end
        r_hp_item
        return
      end
    end
    if @rs_probability >= 50 and rand (150) < @rs_probability
      r_actor_sp
      return
    end
    judge_battle
  end
  #----------------------------------------------------------------------------
  def r_actor_sp
    if recover_sp_items != []   
      r_sp_item
      return
    end
    judge_battle
  end
  #----------------------------------------------------------------------------
  def r_hp_item
    @active_battler.current_action.kind = 2
    date = []
    items = []
    for actor in all_actors
      if actor.hp * 100 < actor.maxhp * 90
        date.push(actor)
      end
    end
    for item in recover_hp_items
      items.push(item) if item.scope == 4
    end
    if ! items.empty? and date.size >= 2
      n = 10
      n += (date.size - 1) * 20
      if rand (100) < n
        item = items[rand (items.size)]
        @active_battler.current_action.item_id = item.id
        @active_battler.auto_battle_targets = all_actors
        return
      end
    end
    now_items = recover_hp_items - items
    if now_items.empty?
      judge_battle
      return
    end
    @active_battler.auto_battle_targets.push(targets_actor_hp)
    target = @active_battler.auto_battle_targets[0]
    set_use_item(now_items, target, 0)
  end
  #----------------------------------------------------------------------------
  def r_sp_item
    @active_battler.current_action.kind = 2
    date = []
    items = []
    for actor in all_actors
      if actor.sp * 100 < actor.maxsp * 60
        date.push(actor)
      end
    end
    for item in recover_sp_items
      items.push(item) if item.scope == 4
    end
    if ! items.empty? and date.size >= 2
      n = 10
      n += (date.size - 1) * 20
      if rand (100) < n
        item = items[rand (items.size)]
        @active_battler.current_action.item_id = item.id
        @active_battler.auto_battle_targets = all_actors
        return
      end
    end
    now_items = recover_sp_items - items
    if now_items.empty?
      judge_battle
      return
    end
    @active_battler.auto_battle_targets.push(targets_actor_sp)
    target = @active_battler.auto_battle_targets[0]
    set_use_item(now_items, target, 1)
  end
  #----------------------------------------------------------------------------
  def r_hp_skill
    date = []
    skills = []
    for actor in all_actors
      if actor.hp * 100 < actor.maxhp * 90
        date.push(actor)
      end
    end
    for skill in recover_hp_skills
      skills.push(skill) if skill.scope == 4
    end
    if ! skills.empty? and date.size >= 2
      n = 20
      n += (date.size - 1) * 20
      if rand (100) < n
        @active_battler.current_action.kind = 1
        skill = skills[rand(skills.size)]
        @active_battler.current_action.skill_id = skill.id
        @active_battler.auto_battle_targets = all_actors
        return
      end
    end
    now_skills = recover_hp_skills - skills
    if now_skills.empty?
      judge_battle
      return
    end
    @active_battler.current_action.kind = 1
    @active_battler.auto_battle_targets.push(targets_actor_hp)
    target = @active_battler.auto_battle_targets[0]
    set_use_skill(now_skills, target)
  end
  #---------------------------------------------------------------------------
  def judge_battle
    if up_plus_skills != []
      if rand (100) < 20
        use_up_skill
        return
      end
    end
    battle
  end
  #---------------------------------------------------------------------------
  def battle
    n = 100 - @active_battler.hp * 100 / @active_battler.maxhp
    if n > 80
      if rand (150) < n
        @active_battler.current_action.kind = 0
        @active_battler.current_action.basic = 1
        return
      end
    end
    if @active_battler.int > @active_battler.str
      n = 80
    elsif @active_battler.int == @active_battler.str
      n = 60
    else
      n = 40
    end
    if rand (100) < n
      use_skill
    else
      base_atk
    end
  end
  #---------------------------------------------------------------------------
  def use_skill
    if down_plus_skills != []
      if rand (100) < 20
        use_down_skill
        return
      end
    end
    if att_skills != []
      use_att_skill
      return
    end
    base_atk
  end
  #---------------------------------------------------------------------------
  def use_up_skill
    @active_battler.current_action.kind = 1
    skill = up_plus_skills[rand (up_plus_skills.size)]
    @active_battler.current_action.skill_id = skill.id
    set_autobattler_targets
  end
  #--------------------------------------------------------------------------
  def use_down_skill
    @active_battler.current_action.kind = 1
    skill = down_plus_skills[rand (down_plus_skills.size)]
    @active_battler.current_action.skill_id = skill.id
    set_autobattler_targets
  end
  #--------------------------------------------------------------------------
  def use_att_skill
    @active_battler.current_action.kind = 1
    date = []
    for skill in att_skills
      date.push(skill) if skill.scope == 2
    end
    if all_enemys.size >= 2
      n = 10
      n += (all_enemys.size - 1) * 10
      n = [n, 80].min
      if rand (100) < n and ! date.empty?
        skill = date[rand (date.size)]
        @active_battler.current_action.skill_id = skill.id
        @active_battler.auto_battle_targets = all_enemys
        return
      end
    end
    now_skills = att_skills - date
    if now_skills.empty?
      base_atk
      return
    end
    @active_battler.auto_battle_targets.push(targets_enemy_hp)
    target = @active_battler.auto_battle_targets[0]
    if use_base_atk?(target)
      base_atk
      return
    end
    set_use_skill(now_skills, target)
  end
  #----------------------------------------------------------------------------
  def base_atk
    @active_battler.current_action.kind = 0
    @active_battler.current_action.basic = 0
    if @active_battler.auto_battle_targets.empty?
      @active_battler.auto_battle_targets.push(targets_enemy_hp)
    end
  end
  ############################################################################
  #----------------------------------------------------------------------------
  def rand_actors
    date = []
    while date.size != $game_party.actors.size
      actor = $game_party.actors[rand ($game_party.actors.size)]
      date.push(actor) if not date.include?(actor)
    end
    return date
  end
  #----------------------------------------------------------------------------
  def dead_actors
    date = []
    for actor in rand_actors
      date.push(actor) if actor.dead?
    end
    return date
  end
  #----------------------------------------------------------------------------
  def all_actors
    date = []
    for actor in rand_actors
      date.push(actor) if actor.exist?
    end
    return date
  end
  #----------------------------------------------------------------------------
  def targets_actor_hp
    if pressing_actor_hp != []      
      target = pressing_actor_hp[rand (pressing_actor_hp.size)]
      return target
    end
    date = []
    for actor in all_actors
      if actor.hp * 100 < actor.maxhp * 90
        date.push(actor)
      end
    end
    target = nil
    if date != []
      for actor in date
        hn = 100 - actor.hp * 100 / actor.maxhp
        if rand (100) < hn
          target = actor
          break
        end
      end
      target = date[rand (date.size)] if target == nil
    end
    target = all_actors[rand (all_actors.size)] if target == nil
    return target
  end
  #----------------------------------------------------------------------------
  def targets_actor_sp
    if pressing_actor_sp != []      
      target = pressing_actor_sp[rand (pressing_actor_sp.size)]
      return target
    end
    date = []
    for actor in all_actors
      if actor.sp * 100 < actor.maxsp * 80
        date.push(actor)
      end
    end
    target = nil
    if date != []
      for actor in date
        sn = 100 - actor.sp * 100 / actor.maxsp
        if rand (100) < sn
          target = actor
          break
        end
      end
      target = date[rand (date.size)] if target == nil
    end
    target = all_actors[rand (all_actors.size)] if target == nil
    return target
  end
  #----------------------------------------------------------------------------
  def pressing_actor_hp
    date = []
    for actor in all_actors
      if actor.hp * 100 <= actor.maxhp * 30
        date.push(actor)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def pressing_actor_sp
    date = []
    for actor in all_actors
      if actor.sp * 100 <= actor.maxsp * 10
        date.push(actor)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def recover_hp_items
    date = []
    for i in 1...$data_items.size
      item = $data_items
      if $game_party.item_number(i) > 0 and [0, 1].include?(item.occasion)
        if not [5, 6].include?(item.scope)
          date.push(item) if item.recover_hp_rate > 0 or item.recover_hp > 0
        end
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def recover_sp_items
    date = []
    for i in 1...$data_items.size
      item = $data_items
      if $game_party.item_number(i) > 0 and [0, 1].include?(item.occasion)
        date.push(item) if item.recover_sp_rate > 0 or item.recover_sp > 0
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def all_enemys
    date = []
    for enemy in $game_troop.enemies
      date.push(enemy) if enemy.exist?
    end
    return date
  end
  #----------------------------------------------------------------------------
  def targets_enemy_hp
    date = []
    for enemy in all_enemys
      if enemy.hp < enemy.maxhp
        date.push(enemy)
      end
    end
    target = nil
    if date != []
      for enemy in date
        hn = 100 - enemy.hp * 100 / enemy.maxhp
        if rand (100) < hn
          target = enemy
          break
        end
      end
    end
    target = all_enemys[rand (all_enemys.size)] if target == nil
    return target
  end
  #----------------------------------------------------------------------------
  def recover_hp_skills
    date = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and skill.power < 0
        date.push(skill)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def att_skills
    date = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and skill.power > 0
        date.push(skill)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def up_plus_skills
    date = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and UP_PLUS_SKILLS.include?(id)
        date.push(skill)
      end
    end
    return date
  end
  #----------------------------------------------------------------------------
  def down_plus_skills
    date = []
    for id in @active_battler.skills
      skill = $data_skills[id]
      if @active_battler.skill_can_use?(id) and DOWN_PLUS_SKILLS.include?(id)
        date.push(skill)
      end
    end
    return date
  end
  #---------------------------------------------------------------------------
  def set_use_item(items, target, toyp)
    @item = nil
    case toyp
    when 0
      date = []
      for item in items
        recover = item.recover_hp + item.recover_hp_rate * target.maxhp
        n = (recover - (target.maxhp - target.hp)).abs
        date.push(n)
      end
      date.sort!
      for item in items
        recover = item.recover_hp + item.recover_hp_rate * target.maxhp
        n = (recover - (target.maxhp - target.hp)).abs
        if n == date[0]
          @item = item
          break
        end
      end
    when 1
      date = []
      for item in items
        recover = item.recover_sp + item.recover_sp_rate * target.maxsp
        n = (recover - (target.maxsp - target.sp)).abs
        date.push(n)
      end
      date.sort!
      for item in items
        recover = item.recover_sp + item.recover_sp_rate * target.maxsp
        n = (recover - (target.maxsp - target.sp)).abs
        if n == date[0]
          @item = item
          break
        end
      end
    end
    @item = items[rand(items.size)] if @item == nil
    @active_battler.current_action.item_id = @item.id
  end
  #---------------------------------------------------------------------------
  def set_use_skill(skills, target)
    r_skills = []
    a_skills = []
    skill = nil
    for i in skills
      damage = count_skill_damage(i, target)
      if damage < 0
        n = (target.maxhp - target.hp + damage).abs
        r_skills.push(n)
      else
        n = (target.hp - damage).abs
        a_skills.push(n)
      end
    end
    r_skills.sort!
    a_skills.sort!
    for i in skills
      damage = count_skill_damage(i, target)
      if damage < 0
        n = (target.maxhp - target.hp + damage).abs
        skill = i if n == r_skills[0]
      else
        n = (target.hp - damage).abs
        skill = i if n == a_skills[0]
      end
    end
    skill = skills[rand (skills.sizs)] if skill == nil
    @active_battler.current_action.skill_id = skill.id
  end
  #----------------------------------------------------------------------------
  def count_skill_damage(skill, target)
    power = skill.power + @active_battler.atk * skill.atk_f / 100
    if power > 0
      power -= target.pdef * skill.pdef_f / 200
      power -= target.mdef * skill.mdef_f / 200
      power = [power, 0].max
    end
    rate = 20
    rate += (target.str * skill.str_f / 100)
    rate += (target.dex * skill.dex_f / 100)
    rate += (target.agi * skill.agi_f / 100)
    rate += (target.int * skill.int_f / 100)
    damage = power * rate / 20
    if skill.element_set == []
      rn = 100
    else
      rn = -100
      for i in skill.element_set
        rn = [rn, target.element_rate(i)].max
      end
    end
    damage = damage * rn / 100
    return damage
  end
  #----------------------------------------------------------------------------
  def use_base_atk?(target)
    atk = [@active_battler.atk - target.pdef / 2, 0].max
    damage = atk * (20 + @active_battler.str) / 20
    if @active_battler.element_set == []
      rn = 100
    else
      rn = -100
      for i in skill.element_set
        rn = [rn, target.element_rate(i)].max
      end
    end
    damage = damage * rn / 100
    n = target.hp - damage
    return true if n <= 0
    return false
  end
  #--------------------------------------------------------------------------
  def set_autobattler_targets
    case @active_battler.current_action.kind
    when 0
      @active_battler.auto_battle_targets.push(targets_enemy_hp)
    when 1
      skill = $data_skills[@active_battler.current_action.skill_id]
      if [5, 6].include?(skill.scope) and dead_actors != []
        if skill.scope == 5
          target = dead_actors[rand (dead_actors.size)]
          @active_battler.auto_battle_targets.push(target)
        else
          @active_battler.auto_battle_targets = dead_actors
        end
        return
      end
      if UP_PLUS_SKILLS.include?(skill.id)
        if skill.scope == 3
          target = all_actors[rand (all_actors.size)]
          @active_battler.auto_battle_targets.push(target)
        elsif skill.scope == 4
          @active_battler.auto_battle_targets = all_actors
        elsif skill.scope == 7
          @active_battler.auto_battle_targets.push(@active_battler)
        end
        return
      end
      if DOWN_PLUS_SKILLS.include?(skill.id)
        if skill.scope == 1
          target = all_enemys[rand (all_enemys.size)]
          @active_battler.auto_battle_targets.push(target)
        elsif skill.scope == 2
          @active_battler.auto_battle_targets = all_enemys
        end
        return
      end
      if skill.power > 0
        if skill.scope == 1
          @active_battler.auto_battle_targets.push(targets_enemy_hp)
        elsif skill.scope == 2
          @active_battler.auto_battle_targets = all_enemys
        end
      elsif skill.power < 0
        if skill.scope == 3
          @active_battler.auto_battle_targets.push(targets_actor_hp)
        elsif skill.scope == 4
          @active_battler.auto_battle_targets = all_actors
        end
      end
    when 2
      item = $data_items[@active_battler.current_action.item_id]
      case item.scope
      when 1
        @active_battler.auto_battle_targets.push(targets_enemy_hp)
      when 2
        @active_battler.auto_battle_targets = all_enemys
      when 3
        if (item.recover_sp_rate > 0 or item.recover_sp > 0) and
          (item.recover_hp_rate > 0 or item.recover_hp > 0)
          if rand (100) < 50
            @active_battler.auto_battle_targets.push(targets_actor_sp)
          else
            @active_battler.auto_battle_targets.push(targets_actor_hp)
          end
          return
        end
        if item.recover_hp_rate > 0 or item.recover_hp > 0
          @active_battler.auto_battle_targets.push(targets_actor_hp)
          return
        end
        if item.recover_sp_rate > 0 or item.recover_sp > 0
          @active_battler.auto_battle_targets.push(targets_actor_sp)
          return
        end
      when 4
        @active_battler.auto_battle_targets = all_actors
      when 5
        target = dead_actors[rand (dead_actors.size)]
        @active_battler.auto_battle_targets.push(target)
      when 6
        @active_battler.auto_battle_targets = dead_actors
      when 7
        @active_battler.auto_battle_targets.push(@active_battler)
      end
    end
  end
end
#==============================================================================
###############################################################################
#==============================================================================[/pre]

自动战斗 角色仓库.rar

203.62 KB, 下载次数: 93

评分

参与人数 1星屑 +35 收起 理由
RyanBern + 35 手动认可奖励

查看全部评分

甘泉幻想物语 试玩版4.0
https://rpg.blue/forum.php?mod=viewthread&tid=369490&page=1&extra=#pid2534710
梦石
0
星屑
76
在线时间
1379 小时
注册时间
2012-7-5
回帖
1643

开拓者

发表于 2015-9-10 15:44:41 | 显示全部楼层
@RB版主 @芯大
↑这种时候就可以直接找作者本人
机器比对的结果是:
  1. phase3_setup_command_window
  2. update_phase3_basic_command
  3. update_phase3
  4. update_phase4_step2
复制代码
上面四个方法产生了重定义(冲突) 期待楼下解决兼容

点评

谢谢回复,等待解救~~~  发表于 2015-9-11 07:17

  -fk: -azogi:
回复

使用道具 举报

路人党员

梦石
0
星屑
52
在线时间
2276 小时
注册时间
2010-12-30
回帖
3011
发表于 2015-9-10 16:38:29 | 显示全部楼层
  1. $orig_wnd_cmd = Window_Command.clone unless $orig_wnd_cmd
  2. class Window_Command < $orig_wnd_cmd
  3.   def initialize(width, cmds)
  4.     if $scene.is_a?(Scene_Battle)
  5.       cmds.push("自动") if $game_switches[AUTO_SWEITCHE]
  6.       cmds.push("逃跑")
  7.     end
  8.     super(width, cmds)
  9.   end
  10.   def y=(v)
  11.     v = 480 - 160 - self.height if $scene.is_a?(Scene_Battle)
  12.     super(v)
  13.   end
  14. end
  15. $orig_scene_btl = Scene_Battle.clone unless $orig_scene_btl
  16. class Scene_Battle < $orig_scene_btl
  17.   def update_phase3_basic_command
  18.     if Input.trigger?(Input::B)
  19.       $game_system.se_play($data_system.cancel_se)
  20.       phase3_prior_actor
  21.       return
  22.     end
  23.     if Input.trigger?(Input::C)
  24.       case @actor_command_window.index
  25.       when 5
  26.         if $game_switches[AUTO_SWEITCHE]
  27.           $game_system.se_play($data_system.decision_se)
  28.           @actor_command_window.active = false
  29.           @actor_command_window.visible = false
  30.           @active_battler.auto_battle = true
  31.           phase3_next_actor
  32.         else
  33.           $game_system.se_play($data_system.decision_se)
  34.           update_phase2_escape
  35.         end
  36.       when 6
  37.         if $game_temp.battle_can_escape == false
  38.           $game_system.se_play($data_system.buzzer_se)
  39.           return
  40.         end
  41.         $game_system.se_play($data_system.decision_se)
  42.         update_phase2_escape
  43.       else
  44.         super
  45.       end
  46.       return
  47.     end
  48.   end
  49.   def update_phase4_step2
  50.     unless @active_battler.current_action.forcing
  51.       if @active_battler.restriction == 2 or @active_battler.restriction == 3
  52.         @active_battler.current_action.kind = 0
  53.         @active_battler.current_action.basic = 0
  54.       end
  55.       if @active_battler.restriction == 4
  56.         $game_temp.forcing_battler = nil
  57.         @phase4_step = 1
  58.         return
  59.       end
  60.     end
  61.     @target_battlers = []
  62.     if @active_battler.is_a?(Game_Actor)
  63.       if @active_battler.auto_battle and not @active_battler.dead?
  64.         set_auto_battle
  65.         case @active_battler.current_action.kind
  66.         when 0  
  67.           make_basic_auto
  68.         when 1  
  69.           make_skill_auto
  70.         when 2  
  71.           make_item_auto
  72.         end
  73.         if @phase4_step == 2
  74.           @phase4_step = 3
  75.         end
  76.         return
  77.       end
  78.     end
  79.     case @active_battler.current_action.kind
  80.     when 0
  81.       make_basic_action_result
  82.     when 1
  83.       make_skill_action_result
  84.     when 2
  85.       make_item_action_result
  86.     when 3
  87.       make_swap_action_result
  88.     end
  89.     if @phase4_step == 2
  90.       @phase4_step = 3
  91.     end
  92.   end
  93. end
复制代码
XP的战斗类脚本的整合最讨厌了,把这个脚本插入在那两个脚本下面就行了

点评

谢谢提示,我这里试验成功了。1.自动。 2.换人 3.防冲突 才可以。 1.换人, 2.自动 3.防冲突 不行。 非常感谢  发表于 2015-9-12 08:40
请确保脚本顺序如下排列:1.换人脚本 2.自动战斗 3.我的脚本  发表于 2015-9-11 19:14
不好意思,错怪大神了,只用这三个脚本没有冲突。可能和其他的战斗脚本冲突了,不好意思。我再思考一下。  发表于 2015-9-11 11:53
大神你好,非常脚本的提供,我试验了一下。确实战斗选项框都出现了,但是无论是选“自动”还是选“换人”都变成了自动战斗,换人的功能消失.....  发表于 2015-9-11 07:18
第一次见到这种写法,我领会一下  发表于 2015-9-10 17:03

评分

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

查看全部评分

本人擅长XP,如果有脚本或者Ruby方面的问题欢迎发电邮到engshun@1ppl.me咨询,本人很少检查电邮所以不一定会及时回复,本人不会直接出手解决问题只会提供一个方向,所以谢绝伸手党
回复

使用道具 举报

梦石
0
星屑
94
在线时间
157 小时
注册时间
2006-7-2
回帖
250
 楼主| 发表于 2015-9-11 07:35:30 | 显示全部楼层
本帖最后由 gkl0510 于 2015-9-11 11:54 编辑
英顺的马甲 发表于 2015-9-10 16:38
XP的战斗类脚本的整合最讨厌了,把这个脚本插入在那两个脚本下面就行了


不好意思,错怪大神了,只用这三个脚本没有冲突。可能和其他的战斗脚本冲突了,不好意思。我再思考一下。
甘泉幻想物语 试玩版4.0
https://rpg.blue/forum.php?mod=viewthread&tid=369490&page=1&extra=#pid2534710
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部