#============================================================================== # ★【 自动战斗 】★ #============================================================================== # 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[i] 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[i] 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 #============================================================================== ############################################################################### #==============================================================================
195.22 KB, 下载次数: 59
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |