Refactored AI switching code, added "UsePokemonInOrder" skill flag

This commit is contained in:
Maruno17
2023-02-14 16:40:52 +00:00
parent a8e024eb3e
commit 81d069eef1
16 changed files with 353 additions and 235 deletions

View File

@@ -431,6 +431,8 @@ Battle::AI::Handlers::MoveEffectScore.add("EnsureNextCriticalHit",
next Battle::AI::MOVE_USELESS_SCORE if user.effects[PBEffects::LaserFocus] > 0
# Useless if the user's critical hit stage ensures critical hits already, or
# critical hits are impossible (e.g. via Lucky Chant)
# TODO: Critical hit rate is calculated using a target, but this move
# doesn't have a target. An error is shown when trying it.
crit_stage = move.rough_critical_hit_stage
if crit_stage < 0 ||
crit_stage >= Battle::Move::CRITICAL_HIT_RATIOS.length ||
@@ -491,7 +493,7 @@ Battle::AI::Handlers::MoveEffectScore.add("StartPreventCriticalHitsAgainstUserSi
next if crit_stage < 0
end
crit_stage += b.effects[PBEffects::FocusEnergy]
crit_stage += 1 if m.check_for_move { |m| m.highCriticalRate? }
crit_stage += 1 if b.check_for_move { |m| m.highCriticalRate? }
crit_stage = [crit_stage, Battle::Move::CRITICAL_HIT_RATIOS.length - 1].min
crit_stage = 3 if crit_stage < 3 && m.check_for_move { |m| m.pbCritialOverride(b.battler, user.battler) > 0 }
# TODO: Change the score depending on how much of an effect a critical hit
@@ -750,7 +752,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUser",
end
# Don't prefer if the user used a protection move last turn, making this one
# less likely to work
score -= (user.effects[PBEffects::ProtectRate] - 1) * (Settings::MECHANICS_GENERATION >= 6) ? 12 : 8
score -= (user.effects[PBEffects::ProtectRate] - 1) * ((Settings::MECHANICS_GENERATION >= 6) ? 12 : 8)
next score
}
)
@@ -801,7 +803,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserBanefulBunker",
end
# Don't prefer if the user used a protection move last turn, making this one
# less likely to work
score -= (user.effects[PBEffects::ProtectRate] - 1) * (Settings::MECHANICS_GENERATION >= 6) ? 12 : 8
score -= (user.effects[PBEffects::ProtectRate] - 1) * ((Settings::MECHANICS_GENERATION >= 6) ? 12 : 8)
next score
}
)
@@ -852,7 +854,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserFromDamagingMovesKingsShie
end
# Don't prefer if the user used a protection move last turn, making this one
# less likely to work
score -= (user.effects[PBEffects::ProtectRate] - 1) * (Settings::MECHANICS_GENERATION >= 6) ? 12 : 8
score -= (user.effects[PBEffects::ProtectRate] - 1) * ((Settings::MECHANICS_GENERATION >= 6) ? 12 : 8)
next score
}
)
@@ -902,7 +904,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserFromDamagingMovesObstruct"
end
# Don't prefer if the user used a protection move last turn, making this one
# less likely to work
score -= (user.effects[PBEffects::ProtectRate] - 1) * (Settings::MECHANICS_GENERATION >= 6) ? 12 : 8
score -= (user.effects[PBEffects::ProtectRate] - 1) * ((Settings::MECHANICS_GENERATION >= 6) ? 12 : 8)
next score
}
)
@@ -951,7 +953,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserFromTargetingMovesSpikyShi
end
# Don't prefer if the user used a protection move last turn, making this one
# less likely to work
score -= (user.effects[PBEffects::ProtectRate] - 1) * (Settings::MECHANICS_GENERATION >= 6) ? 12 : 8
score -= (user.effects[PBEffects::ProtectRate] - 1) * ((Settings::MECHANICS_GENERATION >= 6) ? 12 : 8)
next score
}
)
@@ -1086,7 +1088,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserSideFromPriorityMoves",
end
# Don't prefer if the user used a protection move last turn, making this one
# less likely to work
score -= (user.effects[PBEffects::ProtectRate] - 1) * (Settings::MECHANICS_GENERATION >= 6) ? 12 : 8
score -= (user.effects[PBEffects::ProtectRate] - 1) * ((Settings::MECHANICS_GENERATION >= 6) ? 12 : 8)
next score
}
)
@@ -1105,7 +1107,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserSideFromMultiTargetDamagin
next Battle::AI::MOVE_USELESS_SCORE if user.effects[PBEffects::ProtectRate] >= 4
# Score changes for each foe
useless = true
ai.each_battler(user.side) do |b, i|
ai.each_battler do |b, i|
next if b.index == user.index || !b.can_attack?
next if !b.check_for_move { |m| (Settings::MECHANICS_GENERATION >= 7 || move.damagingMove?) &&
m.pbTarget(b.battler).num_targets > 1 }
@@ -1132,7 +1134,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserSideFromMultiTargetDamagin
end
# Don't prefer if the user used a protection move last turn, making this one
# less likely to work
score -= (user.effects[PBEffects::ProtectRate] - 1) * (Settings::MECHANICS_GENERATION >= 6) ? 12 : 8
score -= (user.effects[PBEffects::ProtectRate] - 1) * ((Settings::MECHANICS_GENERATION >= 6) ? 12 : 8)
next score
}
)

View File

@@ -366,7 +366,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TwoTurnAttackInvulnerabl
score = Battle::AI::Handlers.apply_move_effect_against_target_score("TwoTurnAttack",
score, move, user, target, ai, battle)
# Score for being semi-invulnerable underground
user.each_foe_battler(user.side) do |b, i|
ai.each_foe_battler(user.side) do |b, i|
if b.check_for_move { |m| m.hitsDiggingTargets? }
score -= 8
else
@@ -386,7 +386,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TwoTurnAttackInvulnerabl
score = Battle::AI::Handlers.apply_move_effect_against_target_score("TwoTurnAttack",
score, move, user, target, ai, battle)
# Score for being semi-invulnerable underwater
user.each_foe_battler(user.side) do |b, i|
ai.each_foe_battler(user.side) do |b, i|
if b.check_for_move { |m| m.hitsDivingTargets? }
score -= 8
else
@@ -406,7 +406,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TwoTurnAttackInvulnerabl
score = Battle::AI::Handlers.apply_move_effect_against_target_score("TwoTurnAttack",
score, move, user, target, ai, battle)
# Score for being semi-invulnerable in the sky
user.each_foe_battler(user.side) do |b, i|
ai.each_foe_battler(user.side) do |b, i|
if b.check_for_move { |m| m.hitsFlyingTargets? }
score -= 8
else

View File

@@ -116,7 +116,7 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("SwitchOutTargetStatusMo
if battle.trainerBattle?
will_fail = true
battle.eachInTeamFromBattlerIndex(target.index) do |_pkmn, i|
next if !battle.pbCanSwitchLax?(target.index, i)
next if !battle.pbCanSwitchIn?(target.index, i)
will_fail = false
break
end
@@ -315,8 +315,8 @@ Battle::AI::Handlers::MoveEffectScore.add("UsedAfterAllyRoundWithDoublePower",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveEffectScore.add("TargetActsNext",
proc { |score, move, user, ai, battle|
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TargetActsNext",
proc { |score, move, user, target, ai, battle|
# Useless if the target is a foe
next Battle::AI::MOVE_USELESS_SCORE if target.opposes?(user)
# Compare the speeds of all battlers