Battle::AI::Handlers::PokemonItemEffectScore.add(:FULLHEAL,
proc { |item, score, pkmn, battler, move, ai, battle|
old_score = score
tryItems = []
tryScores = []
case pkmn.status
when :BURN then tryItems.push(:BURNHEAL)
when :POISON then tryItems.push(:ANTIDOTE)
when :PARALYSIS then tryItems.push(:PARALYZEHEAL)
when :SLEEP, :DROWSY then tryItems.push(:AWAKENING)
when :FROZEN, :FROSTBITE then tryItems.push(:ICEHEAL)
end
opposes = battler.opposes?(ai.trainer)
logName = (battler) ? battler.name : pkmn.name
tryItems.push(:PERSIMBERRY) if battler && battler.effects[PBEffects::Confusion] > 0
# Do not use Full Heal on the opponent if they have Guts and are in a "real" status.
if opposes && (battler.pokemon.hasAbility?(:GUTS))
has_real_status = battler.pokemon.status != :NONE
if has_real_status
score = Battle::AI::ITEM_USELESS_SCORE
PBDebug.log_score_change(score - old_score, "avoid using Full Heal on opposing Guts user")
next score
end
end
if tryItems.empty?
score = Battle::AI::ITEM_USELESS_SCORE
PBDebug.log_score_change(score - old_score, "useless because #{logName} has no condition to heal")
else
items = battle.pbGetOwnerItems(ai.user.index)
tryItems.each_with_index do |itm, i|
itemData = GameData::Item.get(itm)
if itm == :PERSIMBERRY
tryScore = Battle::AI::Handlers.battler_item_score(itm, score, battler, ai, battle)
else
tryScore = Battle::AI::Handlers.pokemon_item_score(itm, score, pkmn, battler, move, ai, battle)
end
temp_score = tryScore
if tryScore > Battle::AI::ITEM_USELESS_SCORE
if !opposes && tryItems.length == 1 && items.include?(itm)
tryScore -= 10
PBDebug.log_score_change(tryScore - temp_score, "prefers to use #{itemData.name}")
elsif i > 0
(opposes) ? tryScore -= 10 : tryScore += 10
PBDebug.log_score_change(tryScore - temp_score, "cures multiple conditions")
end
end
tryScores.push(tryScore - old_score)
end
score += tryScores.sum
end
next score
}
)