#========================================================================
# ● Garden: Auto-Battle
# Changes the Actor property "Auto-Battle" to use an Enemy's Action set.
# The Auto-Battle actor will then act as if it's the "enemy", providing
# a much more flexible behavior, and controllable to some extent.
# ~rhyme
#===============================================================================
module RhyAI
# Enables/Disables the script.
AutoBattle = true
# Without a specified enemy data, Auto-battle will use this enemy.
Default_Enemy_ID = 100
# Data for specific Actors.
# Actor ID => Enemy ID
Actor_Enemy_Data = { 1 => 110,
2 => 111,
3 => 112,
4 => 113,
}
# Data for specific Classes.
# Class ID => Enemy ID
Class_Enemy_Data = { 5 => 114,
6 => 115,
7 => 116,
8 => 117,
}
end
#===============================================================================
class Game_Actor < Game_Battler
include RhyAI
alias rhy_ai_make_action make_action
def make_action
if AutoBattle
@action.clear
if Actor_Enemy_Data.include?(@actor_id)
enemy = $data_enemies[Actor_Enemy_Data]
elsif Class_Enemy_Data.include?(@class_id)
enemy = $data_enemies[Class_Enemy_Data]
else
enemy = Default_Enemy_ID
end
return unless movable?
available_actions =
rating_max = 0
for action in enemy.actions
next unless conditions_met?(action)
if action.kind == 1
next unless skill_can_use?($data_skills)
end
available_actions.push(action)
rating_max = .max
end
ratings_total = 0
rating_zero = rating_max - 3
for action in available_actions
next if action.rating <= rating_zero
ratings_total += action.rating - rating_zero
end
return if ratings_total == 0
value = rand(ratings_total)
for action in available_actions
next if action.rating <= rating_zero
if value < action.rating - rating_zero
@action.kind = action.kind
@action.basic = action.basic
@action.skill_id = action.skill_id
@action.decide_random_target
return
else
value -= action.rating - rating_zero
end
end
else
rhy_ai_make_action
end
end
def conditions_met?(action)
case action.condition_type
when 1
n = $game_troop.turn_count
a = action.condition_param1
b = action.condition_param2
return false if (b == 0 and n != a)
return false if (b > 0 and (n < 1 or n < a or n % b != a % b))
when 2
hp_rate = hp * 100.0 / maxhp
return false if hp_rate < action.condition_param1
return false if hp_rate > action.condition_param2
when 3
mp_rate = mp * 100.0 / maxmp
return false if mp_rate < action.condition_param1
return false if mp_rate > action.condition_param2
when 4
return false unless state?(action.condition_param1)
when 5
return false if $game_party.max_level < action.condition_param1
when 6
switch_id = action.condition_param1
return false if $game_switches == false
end
return true
end
end