Resolved all remaining TODO comments for AI (except testing), fixed effects of moves that can end the battle

This commit is contained in:
Maruno17
2023-05-13 22:49:09 +01:00
parent 7a8754c425
commit a4d74a9663
16 changed files with 866 additions and 440 deletions

View File

@@ -494,10 +494,6 @@ Battle::AI::Handlers::MoveEffectScore.add("RaiseUserMainStats1TrapUserInBattle",
next (move.damagingMove?) ? score : Battle::AI::MOVE_USELESS_SCORE
end
# Score for user becoming trapped in battle
# TODO: These checks are related to desire to switch, and there can be a lot
# more things to consider, e.g. effectiveness of the target's moves
# against its foes. Also applies to other code that calls
# can_become_trapped?
if user.effects[PBEffects::PerishSong] > 0 ||
user.effects[PBEffects::Attract] >= 0 ||
eor_damage > 0
@@ -632,7 +628,7 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("RaiseTargetAttack2Confu
)
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("RaiseTargetAttack2ConfuseTarget",
proc { |score, move, user, target, ai, battle|
if !target.has_active_ability?(:CONTRARY) || @battle.moldBreaker
if !target.has_active_ability?(:CONTRARY) || battle.moldBreaker
next Battle::AI::MOVE_USELESS_SCORE if !target.battler.pbCanConfuse?(user.battler, false, move.move)
end
# Score for stat raise
@@ -654,7 +650,7 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("RaiseTargetSpAtk1Confus
)
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("RaiseTargetSpAtk1ConfuseTarget",
proc { |score, move, user, target, ai, battle|
if !target.has_active_ability?(:CONTRARY) || @battle.moldBreaker
if !target.has_active_ability?(:CONTRARY) || battle.moldBreaker
next Battle::AI::MOVE_USELESS_SCORE if !target.battler.pbCanConfuse?(user.battler, false, move.move)
end
# Score for stat raise

View File

@@ -240,7 +240,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("ParalyzeTarget",
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("ParalyzeTargetIfNotTypeImmune",
proc { |move, user, target, ai, battle|
eff = target.effectiveness_of_type_against_battler(move.rough_type, user)
eff = target.effectiveness_of_type_against_battler(move.rough_type, user, move)
next true if Effectiveness.ineffective?(eff)
next true if move.statusMove? && !target.battler.pbCanParalyze?(user.battler, false, move.move)
next false

View File

@@ -1094,8 +1094,6 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserSideFromPriorityMoves",
useless = true
ai.each_foe_battler(user.side) do |b, i|
next if !b.can_attack?
# TODO: There are more calculations that could be done to get a more
# accurate priority number.
next if !b.check_for_move { |m| m.pbPriority(b.battler) > 0 && m.canProtectAgainst? }
useless = false
# General preference
@@ -1343,9 +1341,6 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("EnsureNextMoveAlwaysHits
# Prefer if the user knows moves with low accuracy
user.battler.eachMove do |m|
next if target.effects[PBEffects::Minimize] && m.tramplesMinimize? && Settings::MECHANICS_GENERATION >= 6
# TODO: There are other effects that make a move certain to hit. Account
# for those as well. Score this move useless if no moves would
# benefit from locking on.
acc = m.accuracy
acc = m.pbBaseAccuracy(user.battler, target.battler) if ai.trainer.medium_skill?
score += 5 if acc < 90 && acc != 0
@@ -1503,7 +1498,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TargetMovesBecomeElectri
next if !m.damagingMove?
m_type = m.pbCalcType(target.battler)
next if m_type == :ELECTRIC
eff = user.effectiveness_of_type_against_battler(m_type, target)
eff = user.effectiveness_of_type_against_battler(m_type, target, m)
eff *= 1.5 if target.has_type?(m_type) # STAB
case m_type
when :FIRE

View File

@@ -451,6 +451,7 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("TwoTurnAttackInvulnerab
proc { |move, user, target, ai, battle|
next true if !target.opposes?(user)
next true if target.effects[PBEffects::Substitute] > 0 && !move.move.ignoresSubstitute?(user.battler)
next true if target.has_type?(:FLYING)
next true if Settings::MECHANICS_GENERATION >= 6 && target.battler.pbWeight >= 2000 # 200.0kg
next true if target.battler.semiInvulnerable? || target.effects[PBEffects::SkyDrop] >= 0
next false

View File

@@ -11,10 +11,14 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("UserTakesTargetItem",
# User can steal the target's item; score it
user_item_preference = user.wants_item?(target.item_id)
user_no_item_preference = user.wants_item?(:NONE)
user_diff = user_item_preference - user_no_item_preference
user_diff = 0 if !user.item_active?
target_item_preference = target.wants_item?(target.item_id)
target_no_item_preference = target.wants_item?(:NONE)
score += user_item_preference - user_no_item_preference
score += target_item_preference - target_no_item_preference
target_diff = target_no_item_preference - target_item_preference
target_diff = 0 if !target.item_active?
score += user_diff * 4
score -= target_diff * 4
next score
}
)
@@ -33,10 +37,14 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TargetTakesUserItem",
proc { |score, move, user, target, ai, battle|
user_item_preference = user.wants_item?(user.item_id)
user_no_item_preference = user.wants_item?(:NONE)
user_diff = user_no_item_preference - user_item_preference
user_diff = 0 if !user.item_active?
target_item_preference = target.wants_item?(user.item_id)
target_no_item_preference = target.wants_item?(:NONE)
score += user_no_item_preference - user_item_preference
score += target_no_item_preference - target_item_preference
target_diff = target_item_preference - target_no_item_preference
target_diff = 0 if !target.item_active?
score += user_diff * 4
score -= target_diff * 4
next score
}
)
@@ -58,10 +66,14 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("UserTargetSwapItems",
proc { |score, move, user, target, ai, battle|
user_new_item_preference = user.wants_item?(target.item_id)
user_old_item_preference = user.wants_item?(user.item_id)
user_diff = user_new_item_preference - user_old_item_preference
user_diff = 0 if !user.item_active?
target_new_item_preference = target.wants_item?(user.item_id)
target_old_item_preference = target.wants_item?(target.item_id)
score += user_new_item_preference - user_old_item_preference
score += target_old_item_preference - target_new_item_preference
target_diff = target_new_item_preference - target_old_item_preference
target_diff = 0 if !target.item_active?
score += user_diff * 4
score -= target_diff * 4
# Don't prefer if user used this move in the last round
score -= 15 if user.battler.lastMoveUsed &&
GameData::Move.exists?(user.battler.lastMoveUsed) &&
@@ -80,9 +92,10 @@ Battle::AI::Handlers::MoveFailureCheck.add("RestoreUserConsumedItem",
)
Battle::AI::Handlers::MoveEffectScore.add("RestoreUserConsumedItem",
proc { |score, move, user, ai, battle|
user_new_item_preference = user.wants_item?(user.battler.recycleItem)
user_old_item_preference = user.wants_item?(:NONE)
score += (user_new_item_preference - user_old_item_preference) * 2
next Battle::AI::MOVE_USELESS_SCORE if !user.item_active?
item_preference = user.wants_item?(user.battler.recycleItem)
no_item_preference = user.wants_item?(:NONE)
score += (item_preference - no_item_preference) * 4
next score
}
)
@@ -101,10 +114,11 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("RemoveTargetItem",
next score if !target.item || target.battler.unlosableItem?(target.item)
next score if target.effects[PBEffects::Substitute] > 0
next score if target.has_active_ability?(:STICKYHOLD) && !battle.moldBreaker
next score if !target.item_active?
# User can knock off the target's item; score it
target_item_preference = target.wants_item?(target.item_id)
target_no_item_preference = target.wants_item?(:NONE)
score += (target_item_preference - target_no_item_preference) * 2
item_preference = target.wants_item?(target.item_id)
no_item_preference = target.wants_item?(:NONE)
score -= (no_item_preference - item_preference) * 4
next score
}
)
@@ -119,10 +133,11 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("DestroyTargetBerryOrGem"
next score if user.battler.unlosableItem?(target.item)
next score if target.effects[PBEffects::Substitute] > 0
next score if target.has_active_ability?(:STICKYHOLD) && !battle.moldBreaker
next score if !target.item_active?
# User can incinerate the target's item; score it
target_item_preference = target.wants_item?(target.item_id)
target_no_item_preference = target.wants_item?(:NONE)
score += (target_item_preference - target_no_item_preference) * 2
item_preference = target.wants_item?(target.item_id)
no_item_preference = target.wants_item?(:NONE)
score -= (no_item_preference - item_preference) * 4
next score
}
)
@@ -141,9 +156,11 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("CorrodeTargetItem",
)
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("CorrodeTargetItem",
proc { |score, move, user, target, ai, battle|
target_item_preference = target.wants_item?(target.item_id)
target_no_item_preference = target.wants_item?(:NONE)
score += (target_item_preference - target_no_item_preference) * 2
item_preference = target.wants_item?(target.item_id)
no_item_preference = target.wants_item?(:NONE)
target_diff = no_item_preference - item_preference
target_diff = 0 if !target.item_active?
score += target_diff * 4
next score
}
)
@@ -159,7 +176,8 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("StartTargetCannotUseIte
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("StartTargetCannotUseItem",
proc { |score, move, user, target, ai, battle|
next Battle::AI::MOVE_USELESS_SCORE if !target.item || !target.item_active?
# TODO: Useless if target's item cannot be negated.
# NOTE: We won't check if the item has an effect, because if a Pokémon is
# holding an item, it probably does.
item_score = target.wants_item?(target.item_id)
next Battle::AI::MOVE_USELESS_SCORE if item_score <= 0 # Item has no effect or is bad
score += item_score * 2
@@ -179,7 +197,8 @@ Battle::AI::Handlers::MoveEffectScore.add("StartNegateHeldItems",
next if !b.item
# Skip b if its item is disabled
if ai.trainer.medium_skill?
# TODO: Skip b if its item cannot be negated or it has no effect.
# NOTE: We won't check if the item has an effect, because if a Pokémon
# is holding an item, it probably does.
if battle.field.effects[PBEffects::MagicRoom] > 0
# NOTE: Same as b.item_active? but ignoring the Magic Room part.
next if b.effects[PBEffects::Embargo] > 0
@@ -297,9 +316,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("UserConsumeTargetBerry",
score -= 5 if target.has_active_ability?(:UNBURDEN)
end
# Score the target no longer having the item
target_item_preference = target.wants_item?(target.item_id)
target_no_item_preference = target.wants_item?(:NONE)
score += (target_item_preference - target_no_item_preference) * 2
item_preference = target.wants_item?(target.item_id)
no_item_preference = target.wants_item?(:NONE)
score -= (no_item_preference - item_preference) * 3
next score
}
)
@@ -349,9 +368,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("ThrowUserItemAtTarget",
end
# Prefer if the user doesn't want its held item/don't prefer if it wants to
# keep its held item
user_item_preference = user.wants_item?(user.item_id)
user_no_item_preference = user.wants_item?(:NONE)
score += (user_item_preference - user_no_item_preference) * 2
item_preference = user.wants_item?(user.item_id)
no_item_preference = user.wants_item?(:NONE)
score += (no_item_preference - item_preference) * 2
next score
}
)

View File

@@ -3,7 +3,7 @@
#===============================================================================
Battle::AI::Handlers::MoveFailureCheck.add("FleeFromBattle",
proc { |move, user, ai, battle|
next !battle.pbCanRun?(user.index)
next !battle.pbCanRun?(user.index) || (user.wild? && user.battler.allAllies.length > 0)
}
)
Battle::AI::Handlers::MoveEffectScore.add("FleeFromBattle",
@@ -14,35 +14,50 @@ Battle::AI::Handlers::MoveEffectScore.add("FleeFromBattle",
)
#===============================================================================
# TODO: Review score modifiers.
#
#===============================================================================
Battle::AI::Handlers::MoveFailureCheck.add("SwitchOutUserStatusMove",
proc { |move, user, ai, battle|
next !battle.pbCanRun?(user.index) if user.wild?
if user.wild?
next !battle.pbCanRun?(user.index) || user.battler.allAllies.length > 0
end
next !battle.pbCanChooseNonActive?(user.index)
}
)
Battle::AI::Handlers::MoveEffectScore.add("SwitchOutUserStatusMove",
proc { |score, move, user, ai, battle|
# Wild Pokémon run from battle
# Wild Pokémon run from battle - generally don't prefer (don't want to end the battle too easily)
next score - 20 if user.wild?
# Trainer-owned Pokémon switch out
if ai.trainer.has_skill_flag?("ReserveLastPokemon") && battle.pbTeamAbleNonActiveCount(user.index) == 1
next Battle::AI::MOVE_USELESS_SCORE # Don't switch in ace
end
# Prefer if the user switching out will lose a negative effect
score += 20 if user.effects[PBEffects::PerishSong] > 0
score += 10 if user.effects[PBEffects::Confusion] > 1
score += 10 if user.effects[PBEffects::Attract] >= 0
# Consider the user's stat stages
if user.stages.any? { |key, val| val >= 2 }
score -= 15
elsif user.stages.any? { |key, val| val < 0 }
score += 10
end
# Consider the user's end of round damage/healing
eor_damage = user.rough_end_of_round_damage
score += 15 if eor_damage > 0
score -= 15 if eor_damage < 0
# Prefer if the user doesn't have any damaging moves
# TODO: Check effectiveness of moves.
score += 15 if !user.check_for_move { |m| m.damagingMove? }
# Don't prefer the more stat raises the user has
GameData::Stat.each_battle { |s| score -= user.stages[s.id] * 5 }
score += 10 if !user.check_for_move { |m| m.damagingMove? }
# Don't prefer if the user's side has entry hazards on it
score -= 10 if user.pbOwnSide.effects[PBEffects::Spikes] > 0
score -= 10 if user.pbOwnSide.effects[PBEffects::ToxicSpikes] > 0
score -= 10 if user.pbOwnSide.effects[PBEffects::StealthRock]
next score
}
)
#===============================================================================
# TODO: Review score modifiers.
#
#===============================================================================
Battle::AI::Handlers::MoveEffectScore.add("SwitchOutUserDamagingMove",
proc { |score, move, user, ai, battle|
@@ -51,16 +66,29 @@ Battle::AI::Handlers::MoveEffectScore.add("SwitchOutUserDamagingMove",
score -= 20 if ai.trainer.has_skill_flag?("ReserveLastPokemon") &&
battle.pbTeamAbleNonActiveCount(user.index) == 1
# Prefer if the user switching out will lose a negative effect
score += 20 if user.effects[PBEffects::PerishSong] > 0
score += 10 if user.effects[PBEffects::Confusion] > 1
# Don't prefer the more stat raises the user has
GameData::Stat.each_battle { |s| score -= user.stages[s.id] * 5 }
score += 10 if user.effects[PBEffects::Attract] >= 0
# Consider the user's stat stages
if user.stages.any? { |key, val| val >= 2 }
score -= 15
elsif user.stages.any? { |key, val| val < 0 }
score += 10
end
# Consider the user's end of round damage/healing
eor_damage = user.rough_end_of_round_damage
score += 15 if eor_damage > 0
score -= 15 if eor_damage < 0
# Don't prefer if the user's side has entry hazards on it
score -= 10 if user.pbOwnSide.effects[PBEffects::Spikes] > 0
score -= 10 if user.pbOwnSide.effects[PBEffects::ToxicSpikes] > 0
score -= 10 if user.pbOwnSide.effects[PBEffects::StealthRock]
next score
}
)
#===============================================================================
# TODO: Review score modifiers.
# TODO: Might need both MoveEffectScore and MoveEffectAgainstTargetScore.
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("LowerTargetAtkSpAtk1SwitchOutUser",
proc { |move, user, target, ai, battle|
@@ -75,25 +103,14 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("LowerTargetAtkSpAtk1Swi
)
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("LowerTargetAtkSpAtk1SwitchOutUser",
proc { |score, move, user, target, ai, battle|
score = ai.get_score_for_target_stat_drop(score, target, move.move.statDown, false)
if battle.pbCanChooseNonActive?(user.index)
# Don't want to switch in ace
score -= 20 if ai.trainer.has_skill_flag?("ReserveLastPokemon") &&
battle.pbTeamAbleNonActiveCount(user.index) == 1
# Prefer if the user switching out will lose a negative effect
score += 10 if user.effects[PBEffects::Confusion] > 1
# Prefer if the user doesn't have any damaging moves
# TODO: Check effectiveness of moves.
score += 15 if !user.check_for_move { |m| m.damagingMove? }
# Don't prefer the more stat raises the user has
GameData::Stat.each_battle { |s| score -= user.stages[s.id] * 5 }
end
next score
next ai.get_score_for_target_stat_drop(score, target, move.move.statDown, false)
}
)
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("SwitchOutUserDamagingMove",
"LowerTargetAtkSpAtk1SwitchOutUser")
#===============================================================================
# TODO: Review score modifiers.
#
#===============================================================================
Battle::AI::Handlers::MoveFailureCheck.add("SwitchOutUserPassOnEffects",
proc { |move, user, ai, battle|
@@ -107,56 +124,110 @@ Battle::AI::Handlers::MoveEffectScore.add("SwitchOutUserPassOnEffects",
battle.pbTeamAbleNonActiveCount(user.index) == 1
# Don't prefer if the user will pass on a negative effect
score -= 10 if user.effects[PBEffects::Confusion] > 1
score -= 15 if user.effects[PBEffects::Curse]
score -= 10 if user.effects[PBEffects::Embargo] > 1
score -= 15 if user.effects[PBEffects::GastroAcid]
score -= 10 if user.effects[PBEffects::HealBlock] > 1
score -= 10 if user.effects[PBEffects::LeechSeed] >= 0
score -= 20 if user.effects[PBEffects::PerishSong] > 0
# Prefer if the user will pass on a positive effect
score += 10 if user.effects[PBEffects::AquaRing]
score += 10 if user.effects[PBEffects::FocusEnergy] > 0
score += 10 if user.effects[PBEffects::Ingrain]
score += 8 if user.effects[PBEffects::MagnetRise] > 1
score += 10 if user.effects[PBEffects::Substitute] > 0
# Consider the user's stat stages
if user.stages.any? { |key, val| val >= 4 }
score += 25
elsif user.stages.any? { |key, val| val >= 2 }
score += 15
elsif user.stages.any? { |key, val| val < 0 }
score -= 15
end
# Consider the user's end of round damage/healing
eor_damage = user.rough_end_of_round_damage
score += 15 if eor_damage > 0
score -= 15 if eor_damage < 0
# Prefer if the user doesn't have any damaging moves
# TODO: Check effectiveness of moves.
score += 15 if !user.check_for_move { |m| m.damagingMove? }
# Prefer if the user will pass on good stat stages
GameData::Stat.each_battle { |s| score += user.stages[s.id] * 5 }
# Don't prefer if the user's side has entry hazards on it
score -= 10 if user.pbOwnSide.effects[PBEffects::Spikes] > 0
score -= 10 if user.pbOwnSide.effects[PBEffects::ToxicSpikes] > 0
score -= 10 if user.pbOwnSide.effects[PBEffects::StealthRock]
next score
}
)
#===============================================================================
# TODO: Review score modifiers.
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("SwitchOutTargetStatusMove",
proc { |move, user, target, ai, battle|
next true if (!battle.moldBreaker && target.has_active_ability?(:SUCTIONCUPS)) ||
target.effects[PBEffects::Ingrain]
next true if !battle.canRun
next true if battle.wildBattle? && target.level > user.level
if battle.trainerBattle?
will_fail = true
battle.eachInTeamFromBattlerIndex(target.index) do |_pkmn, i|
next if !battle.pbCanSwitchIn?(target.index, i)
will_fail = false
break
end
next will_fail
end
next false
next move.move.pbFailsAgainstTarget?(user.battler, target.battler, false)
}
)
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("SwitchOutTargetStatusMove",
proc { |score, move, user, target, ai, battle|
score += 15 if target.pbOwnSide.effects[PBEffects::Spikes] > 0
score += 15 if target.pbOwnSide.effects[PBEffects::ToxicSpikes] > 0
score += 15 if target.pbOwnSide.effects[PBEffects::StealthRock]
# Ends the battle - generally don't prefer (don't want to end the battle too easily)
next score - 10 if target.wild?
# Switches the target out
next Battle::AI::MOVE_USELESS_SCORE if target.effects[PBEffects::PerishSong] > 0
# Don't prefer if target is at low HP and could be knocked out instead
if ai.trainer.has_skill_flag?("HPAware")
score -= 10 if target.hp <= target.totalhp / 3
end
# Consider the target's stat stages
if target.stages.any? { |key, val| val >= 2 }
score += 15
elsif target.stages.any? { |key, val| val < 0 }
score -= 15
end
# Consider the target's end of round damage/healing
eor_damage = target.rough_end_of_round_damage
score -= 15 if eor_damage > 0
score += 15 if eor_damage < 0
# Prefer if the target's side has entry hazards on it
score += 10 if target.pbOwnSide.effects[PBEffects::Spikes] > 0
score += 10 if target.pbOwnSide.effects[PBEffects::ToxicSpikes] > 0
score += 10 if target.pbOwnSide.effects[PBEffects::StealthRock]
next score
}
)
#===============================================================================
# TODO: Review score modifiers.
#
#===============================================================================
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("SwitchOutTargetDamagingMove",
proc { |score, move, user, target, ai, battle|
if (battle.moldBreaker || !target.has_active_ability?(:SUCTIONCUPS)) &&
!target.effects[PBEffects::Ingrain]
score += 15 if target.pbOwnSide.effects[PBEffects::Spikes] > 0
score += 15 if target.pbOwnSide.effects[PBEffects::ToxicSpikes] > 0
score += 15 if target.pbOwnSide.effects[PBEffects::StealthRock]
next score if target.wild?
# No score modification if the target can't be made to switch out
next score if !battle.moldBreaker && target.has_active_ability?(:SUCTIONCUPS)
next score if target.effects[PBEffects::Ingrain]
# No score modification if the target can't be replaced
can_switch = false
battle.eachInTeamFromBattlerIndex(target.index) do |_pkmn, i|
can_switch = battle.pbCanSwitchIn?(target.index, i)
break if can_switch
end
next score if !can_switch
# Not score modification if the target has a Substitute
next score if target.effects[PBEffects::Substitute] > 0
# Don't want to switch out the target if it will faint from Perish Song
score -= 20 if target.effects[PBEffects::PerishSong] > 0
# Consider the target's stat stages
if target.stages.any? { |key, val| val >= 2 }
score += 15
elsif target.stages.any? { |key, val| val < 0 }
score -= 15
end
# Consider the target's end of round damage/healing
eor_damage = target.rough_end_of_round_damage
score -= 15 if eor_damage > 0
score += 15 if eor_damage < 0
# Prefer if the target's side has entry hazards on it
score += 10 if target.pbOwnSide.effects[PBEffects::Spikes] > 0
score += 10 if target.pbOwnSide.effects[PBEffects::ToxicSpikes] > 0
score += 10 if target.pbOwnSide.effects[PBEffects::StealthRock]
next score
}
)
@@ -242,12 +313,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TrapTargetInBattle",
next score if add_effect == -999 # Additional effect will be negated
score += add_effect
# Score for target becoming trapped in battle
# TODO: These checks are related to desire to switch, and there can be a lot
# more things to consider, e.g. effectiveness of the target's moves
# against its foes. Also applies to other code that calls
# can_become_trapped?
if target.effects[PBEffects::PerishSong] > 0 ||
target.effects[PBEffects::Attract] >= 0 ||
target.effects[PBEffects::Confusion] > 0 ||
eor_damage > 0
score += 15
end
@@ -290,12 +358,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TrapTargetInBattleLowerT
next (move.damagingMove?) ? score : Battle::AI::MOVE_USELESS_SCORE
end
# Score for target becoming trapped in battle
# TODO: These checks are related to desire to switch, and there can be a lot
# more things to consider, e.g. effectiveness of the target's moves
# against its foes. Also applies to other code that calls
# can_become_trapped?
if target.effects[PBEffects::PerishSong] > 0 ||
target.effects[PBEffects::Attract] >= 0 ||
target.effects[PBEffects::Confusion] > 0 ||
eor_damage > 0
score += 15
end
@@ -324,12 +389,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TrapUserAndTargetInBattl
next (move.damagingMove?) ? score : Battle::AI::MOVE_USELESS_SCORE
end
# Score for target becoming trapped in battle
# TODO: These checks are related to desire to switch, and there can be a lot
# more things to consider, e.g. effectiveness of the target's moves
# against its foes. Also applies to other code that calls
# can_become_trapped?
if target.effects[PBEffects::PerishSong] > 0 ||
target.effects[PBEffects::Attract] >= 0 ||
target.effects[PBEffects::Confusion] > 0 ||
eor_damage > 0
score += 15
end
@@ -339,16 +401,22 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TrapUserAndTargetInBattl
)
#===============================================================================
# TODO: Review score modifiers.
#
#===============================================================================
Battle::AI::Handlers::MoveFailureCheck.add("TrapAllBattlersInBattleForOneTurn",
proc { |move, user, ai, battle|
next battle.field.effects[PBEffects::FairyLock] > 0
}
)
Battle::AI::Handlers::MoveEffectScore.add("TrapAllBattlersInBattleForOneTurn",
proc { |score, move, user, ai, battle|
# Trapping for just one turn isn't so significant, so generally don't prefer
next score - 10
}
)
#===============================================================================
# TODO: Review score modifiers.
#
#===============================================================================
# PursueSwitchingFoe
@@ -661,7 +729,6 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("DisableTargetUsingDiffer
if move_data.status?
# Prefer encoring status moves
if [:User, :BothSides].include?(move_data.target)
# TODO: This target distinction was in the old code. Is it appropriate?
score += 10
else
score += 8