class Game_AllyAI
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(actor)
@actor = actor
clear
end
#--------------------------------------------------------------------------
# * Attack Action Value
#--------------------------------------------------------------------------
def attack_action
return @aggressiveness
end
#--------------------------------------------------------------------------
# * Magic Action Value
#--------------------------------------------------------------------------
def magic_action
return @actor.skills == 0 ? 0 : @magic_casting
end
#--------------------------------------------------------------------------
# * Item Action Value
#--------------------------------------------------------------------------
def item_action
return @item_using
end
#--------------------------------------------------------------------------
# * Defend Action Value
#--------------------------------------------------------------------------
def defend_action
return @defensiveness
end
#--------------------------------------------------------------------------
# * Wait Action Value
#--------------------------------------------------------------------------
def wait_action
return (@laziness + @cowardice) / 2
end
#--------------------------------------------------------------------------
# * Attacking Intelligence Value
#--------------------------------------------------------------------------
def attack_intelligence
int = (1.5 * @intelligence + 1.5 * @strategist - @aggressiveness).to_i
return [int, 50].min
end
#--------------------------------------------------------------------------
# * Magic Offense Value
#--------------------------------------------------------------------------
def magic_offense
return @aggressiveness
end
#--------------------------------------------------------------------------
# * Magic Support Value
#--------------------------------------------------------------------------
def magic_support
return @supportive
end
#--------------------------------------------------------------------------
# * Magic Healing Value
#--------------------------------------------------------------------------
def magic_healing
return @cautiousness
end
#--------------------------------------------------------------------------
# * Magic Status Value
#--------------------------------------------------------------------------
def magic_status
return (@strategist + @supportive + @aggressiveness) / 3
end
#--------------------------------------------------------------------------
# * Magic Strategy Value
#--------------------------------------------------------------------------
def magic_strategy
return (@strategist + @intelligence) / 2
end
#--------------------------------------------------------------------------
# * Magic Heal Percentage
#--------------------------------------------------------------------------
def magic_heal_percent
return ((@supportive / 2 + @cautiousness)/1.5 * 5).to_i
end
#--------------------------------------------------------------------------
# * Magic Heal Multiplier
#--------------------------------------------------------------------------
def magic_heal_multiplier
return (@supportive/2.5 + @cautiousness/1.875).to_i + 1
end
#--------------------------------------------------------------------------
# * Magic Strategy Effective Rate
#--------------------------------------------------------------------------
def magic_strategy_effective
return (2 * @strategist + 3 * @intelligence) / 20
end
#--------------------------------------------------------------------------
# * Magic Status Multiplier
#--------------------------------------------------------------------------
def magic_status_multiplier
return (@strategist/2.5 + @supportive/1.875).to_i + 1
end
#--------------------------------------------------------------------------
# * Magic Strategy Multiplier
#--------------------------------------------------------------------------
def magic_strategy_multiplier
return (@strategist/2.5 + @intelligence/1.875).to_i + 1
end
#--------------------------------------------------------------------------
# * Item Offense Value
#--------------------------------------------------------------------------
def item_offense
return 5 * @aggressiveness / 8 + @intelligence / 8 + @strategist / 4
end
#--------------------------------------------------------------------------
# * Item Support Value
#--------------------------------------------------------------------------
def item_support
return 5 * @supportive / 8 + 3 * @intelligence / 8
end
#--------------------------------------------------------------------------
# * Item Healing Value
#--------------------------------------------------------------------------
def item_healing
return 5 * @cautiousness / 8 + @intelligence / 8 + @strategist / 4
end
#--------------------------------------------------------------------------
# * Item Status Value
#--------------------------------------------------------------------------
def item_status
return (@strategist + @supportive + @intelligence) / 3
end
#--------------------------------------------------------------------------
# * Item Strategy Value
#--------------------------------------------------------------------------
def item_strategy
return (@strategist + @intelligence) / 2
end
#--------------------------------------------------------------------------
# * Item Heal Percentage
#--------------------------------------------------------------------------
def item_heal_percent
return ((@supportive / 2 + @cautiousness)/1.5 * 5).to_i
end
#--------------------------------------------------------------------------
# * Item Heal Multiplier
#--------------------------------------------------------------------------
def item_heal_multiplier
return (@supportive/2.5 + @cautiousness/1.875).to_i + 1
end
#--------------------------------------------------------------------------
# * Item Strategy Effective Rate
#--------------------------------------------------------------------------
def item_strategy_effective
return (3 * @strategist + 2 * @intelligence) / 20
end
#--------------------------------------------------------------------------
# * Item Status Multiplier
#--------------------------------------------------------------------------
def item_status_multiplier
return (@strategist/2.5 + @supportive/1.875).to_i + 1
end
#--------------------------------------------------------------------------
# * Item Strategy Multiplier
#--------------------------------------------------------------------------
def item_strategy_multiplier
return (@strategist/2.5 + @intelligence/1.875).to_i + 1
end
#--------------------------------------------------------------------------
# * Clear
#--------------------------------------------------------------------------
def clear
@aggressiveness = @actor.aggressiveness
@magic_casting = @actor.magic_casting
@item_using = @actor.item_using
@supportive = @actor.supportive
@defensiveness = @actor.defensiveness
@intelligence = @actor.intelligence
@cautiousness = @actor.cautiousness
@laziness = @actor.laziness
@cowardice = @actor.cowardice
@strategist = @actor.strategist
@action_attack = attack_action
@action_magic = magic_action
@action_item = item_action
@action_defend = defend_action
@action_wait = wait_action
@magic_attack = 0
@magic_support = 0
@magic_heal = 0
@magic_status = 0
@magic_strategist = 0
@item_attack = 0
@item_support = 0
@item_heal = 0
@item_status = 0
@item_strategist = 0
# Initialize Useable Skill Array
@useable = []
end
#--------------------------------------------------------------------------
# * Make Action
#--------------------------------------------------------------------------
def make_action
# Clear All Instance Variables
clear
# Initialize Actions Array
actions = []
# Attack Influences
attack_influences
# Magic Influences
magic_influences
# Item Influences
item_influences
# Defend Influences
defend_influences
# Wait Influences
wait_influences
# Push Action Numbers onto actions array
@action_attack.times { actions << 0 }
@action_magic.times { actions << 1 }
@action_item.times { actions << 2 }
@action_defend.times { actions << 3 }
@action_wait.times { actions << 4 }
# Generate a random value
action = actions[rand(actions.size)]
# Branch By Action Number
case action
when 0
make_action_attack
when 1
make_action_magic
when 2
make_action_item
when 3
make_action_defend
when 4
make_action_wait
end
end
#--------------------------------------------------------------------------
# * Attack Influences
#--------------------------------------------------------------------------
def attack_influences
# Initialize Counter
number = 0
# Get Attack Power
atk = @actor.atk
# Run Through Each enemy
$game_troop.enemies.each do |enemy|
# Skip if non existant
next if not enemy.exist?
# Get pdef * Intelligence Rating
pdef = enemy.pdef * attack_intelligence / 50.0
# If actor thinks that can at least do some damage add one
number += 1 if atk > pdef / 2
end
# Add To Instance Variable
@action_attack = @action_attack * number == 0 ? 0 : @action_attack + number
end
#--------------------------------------------------------------------------
# * Magic Influences
#--------------------------------------------------------------------------
def magic_influences
# Initialize Counter
number = 0
# Initialize sp Array
sp = []
# Run Through Each Skill
@actor.skills.each {|skill_id| sp << $data_skills[skill_id].sp_cost}
# If at least one member is in critical condition
if $game_party.critical?
# If knows at least one healing skill that can be used
@actor.skills.each do |skill_id|
# If skill is healing and can use the skill
if $data_skills[skill_id].is_healing? && @actor.skill_can_use?(skill_id)
# Heavy influence for magic
@action_magic = 20
# Break
break
end
end
end
# If Sp is less than the minimum then fail
@action_magic = 0 if @actor.sp < sp.min
end
#--------------------------------------------------------------------------
# * Item Influences
#--------------------------------------------------------------------------
def item_influences
# Initialize Counter
number = 0
# Run Through each available item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If can be used in battle increase number
number += 1 if [0,1].include?($data_items[item_id].occasion)
end
# If at least one member is in critical condition
if $game_party.critical?
# If knows at least one healing skill that can be used
$game_party.items.each do |item_id, amount|
# Skip if amount is 0 or nil
next if amount.to_i == 0
# If skill is healing and can use the item
if $data_items[item_id].is_healing? && $game_party.item_can_use?(item_id)
# Heavy influence for item
@action_item = 20
# Break
break
end
end
end
# If no usable items then fail
@action_item = 0 if number == 0
end
#--------------------------------------------------------------------------
# * Defend Influences
#--------------------------------------------------------------------------
def defend_influences
end
#--------------------------------------------------------------------------
# * Wait Influences
#--------------------------------------------------------------------------
def wait_influences
end
#--------------------------------------------------------------------------
# * Make Action Attack
#--------------------------------------------------------------------------
def make_action_attack
# Initialize Random Array
random = []
# Get Attack Power
atk = @actor.atk
# Run Through Each enemy
$game_troop.enemies.each_with_index do |enemy, index|
# Skip if non existant
next if not enemy.exist?
# Get pdef * Intelligence Rating
pdef = enemy.pdef * attack_intelligence / 50.0
# If actor thinks that can at least do some damage add one
random << index if atk > pdef / 2
end
# Set Target Index
@actor.current_action.target_index = random[rand(random.size)]
# Set Action
@actor.current_action.kind = 0
@actor.current_action.basic = 0
end
#--------------------------------------------------------------------------
# * Make Action Magic
#--------------------------------------------------------------------------
def make_action_magic
# Initialize Action Array
actions = []
@magic_attack = magic_offense
@magic_support = magic_support
@magic_heal = magic_healing
@magic_status = magic_status
@magic_strategist = magic_strategy
# Attack Influences
magic_influences_attack
# Support Influences
magic_influences_support
# Healing Influences
magic_influences_healing
# Status Influences
magic_influences_status
# Strategy Influences
magic_influences_strategy
# Push Action Numbers onto actions array
@magic_attack.times { actions << 0 }
@magic_support.times { actions << 1 }
@magic_heal.times { actions << 2 }
@magic_status.times { actions << 3 }
@magic_strategist.times { actions << 4 }
# Generate a random value
action = actions[rand(actions.size)]
# Branch By Action Number
case action
when 0
make_magic_action_attack
when 1
make_magic_action_support
when 2
make_magic_action_healing
when 3
make_magic_action_status
when 4
make_magic_action_strategist
end
# Make Skill Choice
make_skill_choice
# If skill then make action
if @actor.current_action.skill_id != 0
@actor.current_action.kind = 1
@actor.current_action.basic = 0
end
end
#--------------------------------------------------------------------------
# * Make Action Item
#--------------------------------------------------------------------------
def make_action_item
# Initialize Action Array
actions = []
@item_attack = item_offense
@item_support = item_support
@item_heal = item_healing
@item_status = item_status
@item_strategist = item_strategy
# Attack Influences
item_influences_attack
# Support Influences
item_influences_support
# Healing Influences
item_influences_healing
# Status Influences
item_influences_status
# Strategy Influences
item_influences_strategy
# Push Action Numbers onto actions array
@item_attack.times { actions << 0 }
@item_support.times { actions << 1 }
@item_heal.times { actions << 2 }
@item_status.times { actions << 3 }
@item_strategist.times { actions << 4 }
# Generate a random value
action = actions[rand(actions.size)]
# Branch By Action Number
case action
when 0
make_item_action_attack
when 1
make_item_action_support
when 2
make_item_action_healing
when 3
make_item_action_status
when 4
make_item_action_strategist
end
# Make Item Choice
make_item_choice
# If using an item set action to item
if @actor.current_action.item_id != 0
@actor.current_action.kind = 2
@actor.current_action.basic = 0
end
end
#--------------------------------------------------------------------------
# * Make Action Defend
#--------------------------------------------------------------------------
def make_action_defend
@actor.current_action.kind = 0
@actor.current_action.basic = 1
end
#--------------------------------------------------------------------------
# * Make Action Wait
#--------------------------------------------------------------------------
def make_action_wait
@actor.current_action.kind = 0
@actor.current_action.basic = 3
end
#--------------------------------------------------------------------------
# * Magic Influences Attack
#--------------------------------------------------------------------------
def magic_influences_attack
# Initialize Number Counter
number = 0
# Run Through each actor skill
@actor.skills.each do |skill_id|
# If is an attack skill
if $data_skills[skill_id].is_offensive?
# Increase Counter
number += 1
end
end
# Increase magic attack modifier by amount
@magic_attack += (number / @actor.skills.size.to_f * 4).ceil
# If no attack skills then fail
@magic_attack = number == 0 ? 0 : @magic_attack
end
#--------------------------------------------------------------------------
# * Magic Influences Support
#--------------------------------------------------------------------------
def magic_influences_support
# Initialize Number Counter
number = 0
# Support Skills May be used on first turn
@magic_support += 1 if $game_temp.battle_turn == 0
# Initialize Elements and States Array
elements, states = [], []
# Run Trough Each Enemy gathering there elements
$game_troop.enemies.each {|enemy| elements += enemy.elements}
# Remove Duplicates
elements.uniq!
# Run Through all Helpful States
Ally_AI::Helpful_States.each do |state_id|
# If State has protection against an Element
if $data_states[state_id].guard_element_set.includes_any?(*elements)
# Add State
states << state_id
end
end
# Run Through each actor skill
@actor.skills.each do |skill_id|
# If Has any of the states
if $data_skills[skill_id].plus_state_set.includes_any?(*states)
# Increase Counter
number += 1
end
end
# Increase magic support modifier by amount
@magic_support += (number / @actor.skills.size.to_f * 4).ceil
# If no support skills then fail
@magic_support = number == 0 ? 0 : @magic_support
end
#--------------------------------------------------------------------------
# * Magic Influences Healing
#--------------------------------------------------------------------------
def magic_influences_healing
# Initialize Number Counter
number, healthy = 0, $game_party.actors.size
# Healing modifiers
$game_party.actors.each do |actor|
# Skip if non existing
if not actor.exist?
# Not included
healthy -= 1
# Skip
next
end
# Increase Healing influence if less than heal percent
if (actor.hp * 100.0 / actor.maxhp).to_i <= magic_heal_percent
@magic_heal += 1
else
# Is Healthy
healthy -= 1
end
end
# If game party is in critical state increase chances of using a skill
@magic_heal += 3 if $game_party.critical?
# Run Through each skill
@actor.skills.each do |skill_id|
# Increase by 1 if healing skill
number += 1 if $data_skills[skill_id].is_healing?
end
# Increase magic heal modifier by amount
@magic_heal += (number / @actor.skills.size.to_f * 2).ceil
# If no Healing Skills then can't use a healing skill
@magic_heal = number == 0 ? 0 : @magic_heal
# If all are healty then don't use a healing skill
@magic_heal = healthy == 0 ? 0 : @magic_heal
end
#--------------------------------------------------------------------------
# * Magic Influences Status
#--------------------------------------------------------------------------
def magic_influences_status
# Initialize Number Counter
number = 0
# Initialize Weak States Hash
weak_states = {}
# Run Through Each Enemy
$game_troop.enemies.each do |enemy|
# Skip if not existing
next if not enemy.exist?
# Run Through each Harmful state
Ally_AI::Harmful_States.each do |state_id|
# Get State Effectiveness Value
effective = enemy.state_effectiveness(state_id)
# Push if effective enough
weak_states[state_id] = effective if effective > magic_strategy_effective
end
end
# Run Thorugh each actor skill
@actor.skills.each do |skill_id|
# If Skill has any of the states
if $data_skills[skill_id].plus_state_set.includes_any?(*weak_states.keys)
# Increase Number
number += 1
end
end
# Correction if no weak states
number = 0 if weak_states.keys.size == 0
# Increase magic status modifier by amount
@magic_status += Integer(number / @actor.skills.size.to_f * 4)
# If no Status Skills then can't us a status skill
@magic_status = number == 0 ? 0 : @magic_status
end
#--------------------------------------------------------------------------
# * Magic Influences Strategy
#--------------------------------------------------------------------------
def magic_influences_strategy
# Initialize Weak Elements Array
weak_elements = {}
# Initialize Number Counter
number = 0
# Run Through each enemy
$game_troop.enemies.each do |enemy|
# Skip if not existing enemy
next if not enemy.exist?
# Run Through Real Elements
Ally_AI::Real_Elements.each do |element_id|
# Get Effectiveness
effective = enemy.element_effectiveness(element_id)
# If Greater Than magic effectives value
if effective > magic_strategy_effective
# Add to weak elements hash
weak_elements[element_id] = effective
end
end
end
# Run Through each skill
@actor.skills.each do |skill_id|
# If Skills Element Set includes any element in weak elements
if $data_skills[skill_id].element_set.includes_any?(*weak_elements.keys)
# Increase Counter
number += 1
end
end
# Increase magic strategist modifier by amount
@magic_strategist += (number / @actor.skills.size.to_f * 4).ceil
# Set to 0 if conditions not met (no strategical skills)
@magic_strategist = number == 0 ? 0 : @magic_strategist
end
#--------------------------------------------------------------------------
# * Make Magic Action Attack
#--------------------------------------------------------------------------
def make_magic_action_attack
# Run Through each skill
@actor.skills.each do |skill_id|
# If is an attack skill Push Skill Id onto list
@useable << skill_id if $data_skills[skill_id].is_offensive?
end
end
#--------------------------------------------------------------------------
# * Make Magic Action Support
#--------------------------------------------------------------------------
def make_magic_action_support
# Run Through each skill
@actor.skills.each do |skill_id|
# If is a support skill Push Skill Id onto list
@useable << skill_id if $data_skills[skill_id].is_supporting?
end
end
#--------------------------------------------------------------------------
# * Make Magic Action Healing
#--------------------------------------------------------------------------
def make_magic_action_healing
# Run Through each skill
@actor.skills.each do |skill_id|
# If is a healing skill Push Skill Id onto list
@useable << skill_id if $data_skills[skill_id].is_healing?
end
end
#--------------------------------------------------------------------------
# * Make Magic Action Status
#--------------------------------------------------------------------------
def make_magic_action_status
# Run Through each skill
@actor.skills.each do |skill_id|
# If is a status skill Push skill onto list
@useable << skill_id if $data_skills[skill_id].is_status?
end
end
#--------------------------------------------------------------------------
# * Make Magic Action Strategist
#--------------------------------------------------------------------------
def make_magic_action_strategist
# Initialize elements
elements = []
# Run Through each enemy
$game_troop.enemies.each do |enemy|
# Skip if not existing enemy
next if not enemy.exist?
# Run Through Real Elements
Ally_AI::Real_Elements.each do |element_id|
# Get Effectiveness
effective = enemy.element_effectiveness(element_id)
# If Greater Than magic effectives value
if effective > magic_strategy_effective
# Add to elements
elements << element_id
end
end
end
# Run Through each enemy
$game_troop.enemies.each do |enemy|
# Skip if not existing
next if not enemy.exist?
# Run Through each element
Ally_AI::Real_Elements.each do |element_id|
# Get Effectiveness
effective = enemy.element_effectiveness(element_id)
# Push if effective enough
elements << element_id if effective > magic_strategy_effective
end
end
# Remove Duplicates
elements.uniq!
# Run Through Each Skill
@actor.skills.each do |skill_id|
# Push onto useable list if is strategic with respect to elements
@useable << skill_id if $data_skills[skill_id].is_strategic?(*elements)
end
end
#--------------------------------------------------------------------------
# * Item Influences Attack
#--------------------------------------------------------------------------
def item_influences_attack
# Initialize Number Counter
number = 0
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If is an attack item
if $data_items[item_id].is_offensive?
# Increase Counter
number += 1
end
end
# Increase item attack modifier by amount
@item_attack += number
# If no attack items then fail
@item_attack = number == 0 ? 0 : @item_attack
end
#--------------------------------------------------------------------------
# * Item Influences Support
#--------------------------------------------------------------------------
def item_influences_support
# Initialize Number Counter
number = 0
# Support Items May be used on first turn
@item_support += 1 if $game_temp.battle_turn == 0
# Initialize Elements and States Array
elements, states = [], []
# Run Trough Each Enemy gathering there elements
$game_troop.enemies.each {|enemy| elements += enemy.elements}
# Remove Duplicates
elements.uniq!
# Run Through all Helpful States
Ally_AI::Helpful_States.each do |state_id|
# If State has protection against an Element
if $data_states[state_id].guard_element_set.includes_any?(*elements)
# Add State
states << state_id
end
end
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If Has any of the states
if $data_items[item_id].plus_state_set.includes_any?(*states)
# Increase Counter
number += 1
end
end
# Increase item support modifier by amount
@item_support += number
# If no support items then fail
@item_support = number == 0 ? 0 : @item_support
end
#--------------------------------------------------------------------------
# * Item Influences Healing
#--------------------------------------------------------------------------
def item_influences_healing
# Initialize Number Counter
number, healthy = 0, $game_party.actors.size
# Healing modifiers
$game_party.actors.each do |actor|
# Skip if non existing
if not actor.exist?
# Not included
healthy -= 1
# Skip
next
end
# Increase Healing influence if less than heal percent
if (actor.hp * 100.0 / actor.maxhp).to_i <= item_heal_percent
@item_heal += 1
else
# Is Healthy
healthy -= 1
end
end
# If game party is in critical state increase chances of using a skill
@item_heal += 3 if $game_party.critical?
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# Increase by 1 if healing skill
number += 1 if $data_items[item_id].is_healing?
end
# Increase item heal modifier by amount
@item_heal += number
# If no Healing items then can't use a healing item
@item_heal = number == 0 ? 0 : @item_heal
# If all are healty then don't use a healing item
@item_heal = healthy == 0 ? 0 : @item_heal
end
#--------------------------------------------------------------------------
# * Item Influences Status
#--------------------------------------------------------------------------
def item_influences_status
# Initialize Number Counter
number = 0
# Initialize Weak States Hash
weak_states = {}
# Run Through Each Enemy
$game_troop.enemies.each do |enemy|
# Skip if not existing
next if not enemy.exist?
# Run Through each Harmful state
Ally_AI::Harmful_States.each do |state_id|
# Get State Effectiveness Value
effective = enemy.state_effectiveness(state_id)
# Push if effective enough
weak_states[state_id] = effective if effective > item_strategy_effective
end
end
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If Item has any of the states
if $data_items[item_id].plus_state_set.includes_any?(*weak_states.keys)
# Increase Number
number += 1
end
end
# Correction if no weak states
number = 0 if weak_states.keys.size == 0
# Increase item status modifier by amount
@item_status += number
# If no Status Items then can't us3 a status item
@item_status = number == 0 ? 0 : @item_status
end
#--------------------------------------------------------------------------
# * Item Influences Strategy
#--------------------------------------------------------------------------
def item_influences_strategy
# Initialize Weak Elements Array
weak_elements = {}
# Initialize Number Counter
number = 0
# Run Through each enemy
$game_troop.enemies.each do |enemy|
# Skip if not existing enemy
next if not enemy.exist?
# Run Through Real Elements
Ally_AI::Real_Elements.each do |element_id|
# Get Effectiveness
effective = enemy.element_effectiveness(element_id)
# If Greater Than magic effectives value
if effective > item_strategy_effective
# Add to weak elements hash
weak_elements[element_id] = effective
end
end
end
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If Items Element Set includes any element in weak elements
if $data_items[item_id].element_set.includes_any?(*weak_elements.keys)
# Increase Counter
number += 1
end
end
# Increase item strategist modifier by amount
@item_strategist += number
# Set to 0 if conditions not met (no strategical items)
@item_strategist = number == 0 ? 0 : @item_strategist
end
#--------------------------------------------------------------------------
# * Make Item Action Attack
#--------------------------------------------------------------------------
def make_item_action_attack
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If is an attack item Push Item Id onto list
@useable << item_id if $data_items[item_id].is_offensive?
end
end
#--------------------------------------------------------------------------
# * Make Item Action Support
#--------------------------------------------------------------------------
def make_item_action_support
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If is a support item Push Item Id onto list
@useable << item_id if $data_items[item_id].is_supporting?
end
end
#--------------------------------------------------------------------------
# * Make Item Action Healing
#--------------------------------------------------------------------------
def make_item_action_healing
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If is a healing item Push Item Id onto list
@useable << item_id if $data_items[item_id].is_healing?
end
end
#--------------------------------------------------------------------------
# * Make Item Action Status
#--------------------------------------------------------------------------
def make_item_action_status
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# If is a status item Push item onto list
@useable << item_id if $data_items[item_id].is_status?
end
end
#--------------------------------------------------------------------------
# * Make Item Action Strategist
#--------------------------------------------------------------------------
def make_item_action_strategist
# Initialize elements
elements = []
# Run Through each enemy
$game_troop.enemies.each do |enemy|
# Skip if not existing enemy
next if not enemy.exist?
# Run Through Real Elements
Ally_AI::Real_Elements.each do |element_id|
# Get Effectiveness
effective = enemy.element_effectiveness(element_id)
# If Greater Than magic effectives value
if effective > magic_strategy_effective
# Add to elements
elements << element_id
end
end
end
# Run Through each enemy
$game_troop.enemies.each do |enemy|
# Skip if not existing
next if not enemy.exist?
# Run Through each element
Ally_AI::Real_Elements.each do |element_id|
# Get Effectiveness
effective = enemy.element_effectiveness(element_id)
# Push if effective enough
elements << element_id if effective > magic_strategy_effective
end
end
# Remove Duplicates
elements.uniq!
# Run Through each item
$game_party.items.each do |item_id, amount|
# Skip if amount is nil or 0
next if amount.to_i == 0
# Push onto useable list if is strategic with respect to elements
@useable << item_id if $data_items[item_id].is_strategic?(*elements)
end
end
#--------------------------------------------------------------------------
# * Make Skill Choice
#--------------------------------------------------------------------------
def make_skill_choice
# Get Laziness
chance_lazy = rand(@laziness+1)
# Get Maximum Mp want to use
max_mp_used = (20 - chance_lazy).to_f / 20 * @actor.sp
# Setup Local Useable
useable = []
# Run Through Useable Skills
@useable.each do |skill_id|
# Push if sp cost is less than max mp want to use
useable << skill_id if $data_skills[skill_id].sp_cost <= max_mp_used
end
# Return if size is 0
return if useable.size == 0
# Get Skill Id
skill_id = useable[rand(useable.size)]
# Get Random Skill
@actor.current_action.skill_id = skill_id
# If not Targets All
if not $data_skills[skill_id].targets_all?
# Make Target Choice
make_magic_target_choice
end
end
#--------------------------------------------------------------------------
# * Make Magic Target Choice
#--------------------------------------------------------------------------
def make_magic_target_choice
# Get Skill
skill = $data_skills[@actor.current_action.skill_id]
# Get Scope
scope = skill.scope
# Setup Possible Targets
possible_targets = []
# Branch By Scope
case scope
when 1
# Setup States Element Effeienct Targets and Elements Arrays
states, elem_effiency, targets = [], [], []
# Run Through each enemy
$game_troop.enemies.each_with_index do |enemy, index|
# Skip if non-existant
next if not enemy.exist?
# Setup Local Block Variable elements
elements = []
# If skill is a status skill
if skill.is_status?
# Initialize Enemy Status Points
enemy_status = 0
# Run Through each state
skill.plus_state_set.each do |state_id|
# Add State Effectiveness
enemy_status += enemy.state_effectiveness(state_id)
end
# Set Index to Status Points
states[index] = enemy_status
end
# Run Through each real element
Ally_AI::Real_Elements.each do |element_id|
# Get Element Effectiveness for enemy
effective = enemy.element_effectiveness(element_id)
# Add element id if effective
elements << element_id if effective > magic_strategy_effective
end
# If skill is strategic with respect to elements
if skill.is_strategic?(*elements)
# Set Local Variable Enemy Element
enemy_element = 0
# Run Through each element_id
skill.element_set.each do |element_id|
# Add Effectiveness
enemy_element += enemy.element_effectiveness(element_id)
end
# Add Element Effiency
elem_effiency[index] = enemy_element
end
# If Skill is attacking
if skill.is_offensive?
# Just Push the index
targets << index
end
end
# Add to Possible Targets
magic_status_multiplier.times do
possible_targets += states.find_index(states.max)
end
magic_strategy_multiplier.times do
possible_targets += elem_effiency.find_index(elem_effiency.max)
end
possible_targets += targets
when 3
# Setup Local Hp amount
hp_amount = Array.new($game_party.actors.size) {0}
# Setup Minus States Array (set all indexes to 0)
minus_states = Array.new($game_party.actors.size) {0}
# Setup Status Array (set all indexes to 0)
status = Array.new($game_party.actors.size) {0}
# Run Through Each Actor
$game_party.actors.each_with_index do |actor, index|
# If Skill Is Healing
if skill.is_healing?
# If power is less than 0 (healing hp) and actor exists
if skill.power < 0 and actor.exist?
# Get Percentage
percentage = (actor.hp * 100.0 / actor.maxhp).to_i
# Push Percentage of hp left
hp_amount[index] = 100 - percentage
# Set to 0 if
hp_amount[index] = 0 if percentage > magic_heal_percent
end
# Get Remove Harmful States
remove_states = skill.minus_state_set & Ally_AI::Harmful_States
# Run Through States Removed
remove_states.each do |state_id|
# Get State
state = $data_states[state_id]
# Skip if doesn't have state
next if not actor.state?(state_id)
# If has bad state increase by 1
minus_states[index] += 1
# If bad state restriction > 0 increase by 1
minus_states[index] += 1 if state.restriction > 0
# If Slip Damage increase by 1
minus_states[index] += 1 if state.slip_damage
# If zero hp increase by 2
minus_states[index] += 2 if state.zero_hp
end
end
# Skip if not exists
next if not actor.exist?
# If skill is supporting
if skill.is_supporting?
# Get Skill Helpful States
helpful = skill.plus_state_set & Ally_AI::Helpful_States
# Run Through each actor with index
$game_party.actors.each_with_index do |actor, index|
# Run Through Each Helpful State
helpful.each do |state_id|
# Increase if actor doesn't have state
status[index] += 1 if not actor.state?(state_id)
end
end
end
end
# If not all zeros
if hp_amount.sum != 0
# Get Hp Amounts
rating = hp_amount
# Get Percentage By / by sum
rating.collect! {|rate| rate.to_f / hp_amount.sum}
# Increase Ratings by heal Multiplier rating
rating.collect! {|rate| rate * magic_heal_multiplier}
# Run Through adding indexes and their rating
rating.each_with_index do |rate, index|
# Push onto Possible Targets
possible_targets += Array.new(rate) {index}
end
end
# Run Through adding indexes and their rating
minus_states.each_with_index do |state_rate, index|
# Push onto Possible Targets
possible_targets += Array.new(state_rate) {index}
end
# Run Through adding indexes and their rating
status.each_with_index do |status, index|
# Push onto Possible Targets
possible_targets += Array.new(status) {index}
end
when 5
# Run Through all Actors
$game_party.actors.each_with_index do |actor, index|
# Push index if non existant
possible_targets << index if not actor.exist?
end
when 7
# Push itself
possible_targets << @actor.index
end
target_index = possible_targets[rand(possible_targets.size)]
@actor.current_action.target_index = target_index
end
#--------------------------------------------------------------------------
# * Make Item Choice
#--------------------------------------------------------------------------
def make_item_choice
# Get Item Id
item_id = @useable[rand(@useable.size)]
# Set Random Item
@actor.current_action.item_id = item_id
# If not Targets All
if not $data_items[item_id].targets_all?
# Make Target Choice
make_item_target_choice
end
end
#--------------------------------------------------------------------------
# * Make Item Target Choice
#--------------------------------------------------------------------------
def make_item_target_choice
# Get Item
item = $data_items[@actor.current_action.item_id]
# Get Scope
scope = item.scope
# Setup Possible Targets
possible_targets = []
# Branch By Scope
case scope
when 1
# Setup States Element Effeienct Targets and Elements Arrays
states, elem_effiency, targets = [], [], []
# Run Through each enemy
$game_troop.enemies.each_with_index do |enemy, index|
# Skip if non-existant
next if not enemy.exist?
# Setup Local Block Variable elements
elements = []
# If skill is a status skill
if item.is_status?
# Initialize Enemy Status Points
enemy_status = 0
# Run Through each state
item.plus_state_set.each do |state_id|
# Add State Effectiveness
enemy_status += enemy.state_effectiveness(state_id)
end
# Set Index to Status Points
states[index] = enemy_status
end
# Run Through each real element
Ally_AI::Real_Elements.each do |element_id|
# Get Element Effectiveness for enemy
effective = enemy.element_effectiveness(element_id)
# Add element id if effective
elements << element_id if effective > magic_strategy_effective
end
# If item is strategic with respect to elements
if item.is_strategic?(*elements)
# Set Local Variable Enemy Element
enemy_element = 0
# Run Through each element_id
item.element_set.each do |element_id|
# Add Effectiveness
enemy_element += enemy.element_effectiveness(element_id)
end
# Add Element Effiency
elem_effiency[index] = enemy_element
end
# If Item is attacking
if item.is_offensive?
# Just Push the index
targets << index
end
end
# Add to Possible Targets
item_status_multiplier.times do
possible_targets += states.find_index(states.max)
end
item_strategy_multiplier.times do
possible_targets += elem_effiency.find_index(elem_effiency.max)
end
possible_targets += targets
when 3
# Setup Local Hp amount
hp_amount = Array.new($game_party.actors.size) {0}
# Setup Local Sp amount
sp_amount = Array.new($game_party.actors.size) {0}
# Setup Minus States Array (set all indexes to 0)
minus_states = Array.new($game_party.actors.size) {0}
# Setup Status Array (set all indexes to 0)
status = Array.new($game_party.actors.size) {0}
# Run Through Each Actor
$game_party.actors.each_with_index do |actor, index|
# If Item Is Healing
if item.is_healing?
# If item recover rates is > than 0 (healing hp) and actor exists
if item.recover_hp_rate > 0 || item.recover_hp > 0 and actor.exist?
# Get Percentage
percentage = (actor.hp * 100.0 / actor.maxhp).to_i
# Push Percentage of hp left
hp_amount[index] = 100 - percentage
# Set to 0 if
hp_amount[index] = 0 if percentage > item_heal_percent
end
# If item recover rates is > than 0 (healing sp)
if item.recover_sp_rate > 0 || item.recover_sp > 0
# Get Percentage
percentage = (actor.sp * 100.0 / actor.maxsp).to_i
# Push Percentage of hp left
sp_amount[index] = 100 - percentage
# Set to 0 if
sp_amount[index] = 0 if percentage <= item_heal_percent
end
# Get Remove Harmful States
remove_states = item.minus_state_set & Ally_AI::Harmful_States
# Run Through States Removed
remove_states.each do |state_id|
# Get State
state = $data_states[state_id]
# Skip if doesn't have state
next if not actor.state?(state_id)
# If has bad state increase by 1
minus_states[index] += 1
# If bad state restriction > 0 increase by 1
minus_states[index] += 1 if state.restriction > 0
# If Slip Damage increase by 1
minus_states[index] += 1 if state.slip_damage
# If zero hp increase by 2
minus_states[index] += 2 if state.zero_hp
end
end
# Skip if not exists
next if not actor.exist?
# If item is supporting
if item.is_supporting?
# Get Skill Helpful States
helpful = item.plus_state_set & Ally_AI::Helpful_States
# Run Through each actor with index
$game_party.actors.each_with_index do |actor, index|
# Run Through Each Helpful State
helpful.each do |state_id|
# Increase if actor doesn't have state
status[index] += 1 if not actor.state?(state_id)
end
end
end
end
# If not all zeros
if hp_amount.sum != 0
# Get Hp Amounts
rating = hp_amount
# Get Percentage By / by sum
rating.collect! {|rate| rate.to_f / hp_amount.sum}
# Increase Ratings by heal Multiplier rating
rating.collect! {|rate| rate * item_heal_multiplier}
# Run Through adding indexes and their rating
rating.each_with_index do |rate, index|
# Push onto Possible Targets
possible_targets += Array.new(rate) {index}
end
end
# If not all zeros
if sp_amount.sum != 0
# Get Ratings
rating = sp_amount
# Get Percentage By / by sum
rating.collect! {|rate| rate.to_f / sp_amount.sum}
# Increase Ratings by heal Multiplier rating
rating.collect! {|rate| rate * item_heal_multiplier}
# Run Through adding indexes and their rating
rating.each_with_index do |rate, index|
# Push onto Possible Targets
possible_targets += Array.new(rate) {index}
end
end
# Run Through adding indexes and their rating
minus_states.each_with_index do |state_rate, index|
# Push onto Possible Targets
possible_targets += Array.new(state_rate) {index}
end
# Run Through adding indexes and their rating
status.each_with_index do |status, index|
# Push onto Possible Targets
possible_targets += Array.new(status) {index}
end
when 5
# Run Through all Actors
$game_party.actors.each_with_index do |actor, index|
# Push index if non existant
possible_targets << index if not actor.exist?
end
when 7
# Push itself
possible_targets << @actor.index
end
target_index = possible_targets[rand(possible_targets.size)]
@actor.current_action.target_index = target_index
end
end