AI changes, fixed input detection Conditional Branch, Fishious Rend is now a biting move

This commit is contained in:
Maruno17
2024-02-01 23:50:09 +00:00
parent c78e32db09
commit e6fe242d4b
12 changed files with 159 additions and 108 deletions

View File

@@ -192,13 +192,14 @@ Battle::AI::Handlers::ShouldSwitch.add(:perish_song,
Battle::AI::Handlers::ShouldSwitch.add(:significant_eor_damage,
proc { |battler, reserves, ai, battle|
eor_damage = battler.rough_end_of_round_damage
next false if eor_damage <= 0
# Switch if battler will take significant EOR damage
if eor_damage >= battler.hp / 2 || eor_damage >= battler.totalhp / 4
PBDebug.log_ai("#{battler.name} wants to switch because it will take a lot of EOR damage")
next true
end
# Switch to remove certain effects that cause the battler EOR damage
if ai.trainer.high_skill? && eor_damage > 0
if ai.trainer.high_skill?
if battler.effects[PBEffects::LeechSeed] >= 0 && ai.pbAIRandom(100) < 50
PBDebug.log_ai("#{battler.name} wants to switch to get rid of its Leech Seed")
next true

View File

@@ -69,12 +69,19 @@ class Battle::AI
end
# Discard move if it can't raise any stats
if real_stat_changes.length == 0
PBDebug.log(" ignore stat raising (it can't be changed)")
return (whole_effect) ? MOVE_USELESS_SCORE : score
end
# Make score change based on the additional effect chance
score += add_effect
if add_effect != 0
old_score = score
score += add_effect
PBDebug.log_score_change(score - old_score, "stat raising is an additional effect")
end
# Make score changes based on the general concept of raising stats at all
old_score = score
score = get_target_stat_raise_score_generic(score, target, real_stat_changes, desire_mult)
PBDebug.log_score_change(score - old_score, "generic calculations for raising any stat")
# Make score changes based on the specific changes to each stat that will be
# raised
real_stat_changes.each do |change|
@@ -159,15 +166,15 @@ class Battle::AI
total_increment = stat_changes.sum { |change| change[1] }
# Prefer if move is a status move and it's the user's first/second turn
if @user.turnCount < 2 && @move.statusMove?
score += total_increment * desire_mult * 5
score += total_increment * desire_mult * 4
end
if @trainer.has_skill_flag?("HPAware")
# Prefer if user is at high HP, don't prefer if user is at low HP
if target.index != @user.index
score += total_increment * desire_mult * ((100 * @user.hp / @user.totalhp) - 50) / 8 # +6 to -6 per stage
score += total_increment * desire_mult * ((100 * @user.hp / @user.totalhp) - 50) / 12 # +4 to -4 per stage
end
# Prefer if target is at high HP, don't prefer if target is at low HP
score += total_increment * desire_mult * ((100 * target.hp / target.totalhp) - 50) / 8 # +6 to -6 per stage
score += total_increment * desire_mult * ((100 * target.hp / target.totalhp) - 50) / 12 # +4 to -4 per stage
end
# NOTE: There are no abilities that trigger upon stat raise, but this is
# where they would be accounted for if they existed.
@@ -366,12 +373,19 @@ class Battle::AI
end
# Discard move if it can't lower any stats
if real_stat_changes.length == 0
PBDebug.log(" ignore stat lowering (it can't be changed)")
return (whole_effect) ? MOVE_USELESS_SCORE : score
end
# Make score change based on the additional effect chance
score += add_effect
if add_effect != 0
old_score = score
score += add_effect
PBDebug.log_score_change(score - old_score, "stat lowering is an additional effect")
end
# Make score changes based on the general concept of lowering stats at all
old_score = score
score = get_target_stat_drop_score_generic(score, target, real_stat_changes, desire_mult)
PBDebug.log_score_change(score - old_score, "generic calculations for lowering any stat")
# Make score changes based on the specific changes to each stat that will be
# lowered
real_stat_changes.each do |change|
@@ -447,15 +461,15 @@ class Battle::AI
total_decrement = stat_changes.sum { |change| change[1] }
# Prefer if move is a status move and it's the user's first/second turn
if @user.turnCount < 2 && @move.statusMove?
score += total_decrement * desire_mult * 5
score += total_decrement * desire_mult * 4
end
if @trainer.has_skill_flag?("HPAware")
# Prefer if user is at high HP, don't prefer if user is at low HP
if target.index != @user.index
score += total_decrement * desire_mult * ((100 * @user.hp / @user.totalhp) - 50) / 8 # +6 to -6 per stage
score += total_decrement * desire_mult * ((100 * @user.hp / @user.totalhp) - 50) / 12 # +4 to -4 per stage
end
# Prefer if target is at high HP, don't prefer if target is at low HP
score += total_decrement * desire_mult * ((100 * target.hp / target.totalhp) - 50) / 8 # +6 to -6 per stage
score += total_decrement * desire_mult * ((100 * target.hp / target.totalhp) - 50) / 12 # +4 to -4 per stage
end
# Don't prefer if target has an ability that triggers upon stat loss
# (Competitive, Defiant)

View File

@@ -241,6 +241,9 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:target_can_make_moves_E
#===============================================================================
# Don't prefer attacking the target if they'd be semi-invulnerable.
# TODO: Don't treat the move as useless? If the user's moves are all useless
# because of this, it will want to switch instead, which may not be
# desirable.
#===============================================================================
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:target_semi_invulnerable,
proc { |score, move, user, target, ai, battle|
@@ -308,7 +311,7 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:predicted_damage,
PBDebug.log_score_change(score - old_score, "damaging move (predicted damage #{dmg} = #{100 * dmg / target.hp}% of target's HP)")
if ai.trainer.has_skill_flag?("HPAware") && dmg > target.hp * 1.1 # Predicted to KO the target
old_score = score
score += 10
score += 20
PBDebug.log_score_change(score - old_score, "predicted to KO the target")
if move.move.multiHitMove? && target.hp == target.totalhp &&
(target.has_active_ability?(:STURDY) || target.has_active_item?(:FOCUSSASH))
@@ -365,7 +368,7 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:thawing_move_against_fr
# Don't prefer a damaging move if it will trigger the target's ability or held
# item when used, e.g. Effect Spore/Rough Skin, Pickpocket, Rocky Helmet, Red
# Card.
# NOTE: These abilities/items may not be triggerable after all (e.g. they
# TODO: These abilities/items may not be triggerable after all (e.g. they
# require the move to make contact but it doesn't), or may have a negative
# effect for the target (e.g. Air Balloon popping), but it's too much
# effort to go into detail deciding all this.
@@ -378,14 +381,14 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:trigger_target_ability_
(Battle::AbilityEffects::AfterMoveUseFromTarget[target.ability] &&
(!user.has_active_ability?(:SHEERFORCE) || move.move.addlEffect == 0))
old_score = score
score += 8
score -= 8
PBDebug.log_score_change(score - old_score, "can trigger the target's ability")
end
end
if target.battler.isSpecies?(:CRAMORANT) && target.ability == :GULPMISSILE &&
target.battler.form > 0 && !target.effects[PBEffects::Transform]
old_score = score
score += 8
score -= 8
PBDebug.log_score_change(score - old_score, "can trigger the target's ability")
end
if target.item_active?
@@ -393,7 +396,7 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:trigger_target_ability_
(Battle::ItemEffects::AfterMoveUseFromTarget[target.item] &&
(!user.has_active_ability?(:SHEERFORCE) || move.move.addlEffect == 0))
old_score = score
score += 8
score -= 8
PBDebug.log_score_change(score - old_score, "can trigger the target's item")
end
end

View File

@@ -543,21 +543,34 @@ class Battle::AI::AIMove
#-----------------------------------------------------------------------------
# Return values:
# 0: Regular additional effect chance or isn't an additional effect
# 0: Isn't an additional effect or always triggers
# -999: Additional effect will be negated
# Other: Amount to add to a move's score
# TODO: This value just gets added to the score, but it should only modify the
# score for the additional effect and shouldn't reduce that to less than
# 0.
def get_score_change_for_additional_effect(user, target = nil)
chance = @move.addlEffect
# Doesn't have an additional effect
return 0 if @move.addlEffect == 0
return 0 if chance == 0
# Additional effect will be negated
return -999 if user.has_active_ability?(:SHEERFORCE)
return -999 if target && user.index != target.index &&
target.has_active_ability?(:SHIELDDUST) && !@ai.battle.moldBreaker
# Prefer if the additional effect will have an increased chance of working
return 5 if @move.addlEffect < 100 &&
(Settings::MECHANICS_GENERATION >= 6 || function_code != "EffectDependsOnEnvironment") &&
(user.has_active_ability?(:SERENEGRACE) || user.pbOwnSide.effects[PBEffects::Rainbow] > 0)
# No change to score
return 0
# Additional effect will always trigger
return 0 if chance > 100
# Calculate the chance
chance *= 2 if (Settings::MECHANICS_GENERATION >= 6 || function_code != "EffectDependsOnEnvironment") &&
(user.has_active_ability?(:SERENEGRACE) || user.pbOwnSide.effects[PBEffects::Rainbow] > 0)
# Don't prefer if the additional effect has a low chance of happening
ret = 0
if chance <= 10
ret -= 10
elsif chance <= 50
ret -= 5
elsif chance >= 80
ret += 5
end
return ret
end
end