mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 06:04:59 +00:00
AI: Added checks for additional effect chance, Snatch/Magic Coat, more item ratings
This commit is contained in:
@@ -24,6 +24,10 @@ class Battle::AI
|
||||
end
|
||||
return get_score_for_target_stat_drop(score, target, stat_changes, whole_effect, fixed_change, true)
|
||||
end
|
||||
# Don't make score changes if the move is a damaging move and its additional
|
||||
# effect (the stat raise(s)) will be negated
|
||||
add_effect = @move.get_score_change_for_additional_effect(@user, target)
|
||||
return score if add_effect == -999 # Additional effect will be negated
|
||||
# Don't make score changes if target will faint from EOR damage
|
||||
if target.rough_end_of_round_damage >= target.hp
|
||||
ret = (whole_effect) ? MOVE_USELESS_SCORE : score
|
||||
@@ -66,6 +70,8 @@ class Battle::AI
|
||||
if real_stat_changes.length == 0
|
||||
return (whole_effect) ? MOVE_USELESS_SCORE : score
|
||||
end
|
||||
# Make score change based on the additional effect chance
|
||||
score += add_effect
|
||||
# Make score changes based on the general concept of raising stats at all
|
||||
score = get_target_stat_raise_score_generic(score, target, real_stat_changes, desire_mult)
|
||||
# Make score changes based on the specific changes to each stat that will be
|
||||
@@ -314,6 +320,10 @@ class Battle::AI
|
||||
end
|
||||
return get_score_for_target_stat_raise(score, target, stat_changes, whole_effect, fixed_change, true)
|
||||
end
|
||||
# Don't make score changes if the move is a damaging move and its additional
|
||||
# effect (the stat drop(s)) will be negated
|
||||
add_effect = @move.get_score_change_for_additional_effect(@user, target)
|
||||
return score if add_effect == -999 # Additional effect will be negated
|
||||
# Don't make score changes if target will faint from EOR damage
|
||||
if target.rough_end_of_round_damage >= target.hp
|
||||
ret = (whole_effect) ? MOVE_USELESS_SCORE : score
|
||||
@@ -354,6 +364,8 @@ class Battle::AI
|
||||
if real_stat_changes.length == 0
|
||||
return (whole_effect) ? MOVE_USELESS_SCORE : score
|
||||
end
|
||||
# Make score change based on the additional effect chance
|
||||
score += add_effect
|
||||
# Make score changes based on the general concept of lowering stats at all
|
||||
score = get_target_stat_drop_score_generic(score, target, real_stat_changes, desire_mult)
|
||||
# Make score changes based on the specific changes to each stat that will be
|
||||
|
||||
@@ -148,15 +148,13 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:thawing_move_against_fr
|
||||
# flinching are dealt with in the function code part of score calculation).
|
||||
# TODO: Review score modifier.
|
||||
#===============================================================================
|
||||
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:flinching_effects,
|
||||
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:external_flinching_effects,
|
||||
proc { |score, move, user, target, ai, battle|
|
||||
if ai.trainer.medium_skill?
|
||||
if ai.trainer.medium_skill? && move.damagingMove? && !move.move.flinchingMove?
|
||||
if (battle.moldBreaker || !target.has_active_ability?([:INNERFOCUS, :SHIELDDUST])) &&
|
||||
target.effects[PBEffects::Substitute] == 0
|
||||
if move.move.flinchingMove? ||
|
||||
(move.damagingMove? &&
|
||||
(user.has_active_item?([:KINGSROCK, :RAZORFANG]) ||
|
||||
user.has_active_ability?(:STENCH)))
|
||||
if user.has_active_item?([:KINGSROCK, :RAZORFANG]) ||
|
||||
user.has_active_ability?(:STENCH)
|
||||
old_score = score
|
||||
score += 8
|
||||
PBDebug.log_score_change(score - old_score, "flinching")
|
||||
@@ -195,7 +193,7 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:flinching_effects,
|
||||
# repeatedly until the target retaliates). Doesn't do a score change if the user
|
||||
# will be immune to Bide's damage.
|
||||
#===============================================================================
|
||||
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:avoid_damaging_a_biding_target,
|
||||
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:damaging_a_biding_target,
|
||||
proc { |score, move, user, target, ai, battle|
|
||||
if ai.trainer.medium_skill? && target.effects[PBEffects::Bide] > 0 && move.damagingMove?
|
||||
eff = user.effectiveness_of_type_against_battler(:NORMAL, target) # Bide is Normal type
|
||||
@@ -216,7 +214,6 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:avoid_damaging_a_biding
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
#===============================================================================
|
||||
# Don't prefer damaging moves that will knock out the target if they are using
|
||||
# Destiny Bond.
|
||||
@@ -224,7 +221,7 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:avoid_damaging_a_biding
|
||||
# => Also don't prefer damaging moves if user is slower than the target, move
|
||||
# is likely to be lethal, and target has previously used Destiny Bond
|
||||
#===============================================================================
|
||||
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:avoid_knocking_out_destiny_bonder,
|
||||
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:knocking_out_a_destiny_bonder,
|
||||
proc { |score, move, user, target, ai, battle|
|
||||
if ai.trainer.medium_skill? && move.damagingMove? && target.effects[PBEffects::DestinyBond]
|
||||
dmg = move.rough_damage
|
||||
@@ -254,34 +251,65 @@ Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:avoid_knocking_out_dest
|
||||
|
||||
#===============================================================================
|
||||
# Don't prefer a move that can be Magic Coated if the target (or any foe if the
|
||||
# move doesn't have a target) has Magic Bounce.
|
||||
# move doesn't have a target) knows Magic Coat/has Magic Bounce.
|
||||
#===============================================================================
|
||||
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:avoid_targeting_bouncable_move_against_Magic_Bouncer,
|
||||
Battle::AI::Handlers::GeneralMoveAgainstTargetScore.add(:target_can_Magic_Coat_or_Bounce_move,
|
||||
proc { |score, move, user, target, ai, battle|
|
||||
# TODO: Modify the semiInvulnerable? check to only apply if the target will
|
||||
# still be invulnerable when the user acts, i.e. compare speeds?
|
||||
if move.statusMove? && move.move.canMagicCoat? &&
|
||||
!battle.moldBreaker && target.has_active_ability?(:MAGICBOUNCE)
|
||||
target.opposes?(user) && !target.battler.semiInvulnerable?
|
||||
old_score = score
|
||||
score = Battle::AI::MOVE_USELESS_SCORE
|
||||
PBDebug.log_score_change(score - old_score, "useless because target will Magic Bounce it")
|
||||
if !battle.moldBreaker && target.has_active_ability?(:MAGICBOUNCE)
|
||||
score = Battle::AI::MOVE_USELESS_SCORE
|
||||
PBDebug.log_score_change(score - old_score, "useless because target will Magic Bounce it")
|
||||
elsif target.has_move_with_function?("BounceBackProblemCausingStatusMoves")
|
||||
score -= 8
|
||||
PBDebug.log_score_change(score - old_score, "target knows Magic Coat and could bounce it")
|
||||
end
|
||||
end
|
||||
next score
|
||||
}
|
||||
)
|
||||
|
||||
Battle::AI::Handlers::GeneralMoveScore.add(:avoid_bouncable_move_with_foe_Magic_Bouncer,
|
||||
Battle::AI::Handlers::GeneralMoveScore.add(:any_foe_can_Magic_Coat_or_Bounce_move,
|
||||
proc { |score, move, user, ai, battle|
|
||||
if move.statusMove? && move.move.canMagicCoat? &&
|
||||
move.pbTarget(user.battler).num_targets == 0 && !battle.moldBreaker
|
||||
has_magic_bounce = false
|
||||
if move.statusMove? && move.move.canMagicCoat? && move.pbTarget(user.battler).num_targets == 0
|
||||
old_score = score
|
||||
ai.each_foe_battler(user.side) do |b, i|
|
||||
next if !b.has_active_ability?(:MAGICBOUNCE)
|
||||
has_magic_bounce = true
|
||||
break
|
||||
# TODO: Modify the semiInvulnerable? check to only apply if the target
|
||||
# will still be invulnerable when the user acts, i.e. compare
|
||||
# speeds?
|
||||
next if b.battler.semiInvulnerable?
|
||||
if b.has_active_ability?(:MAGICBOUNCE) && !battle.moldBreaker
|
||||
score = Battle::AI::MOVE_USELESS_SCORE
|
||||
PBDebug.log_score_change(score - old_score, "useless because a foe will Magic Bounce it")
|
||||
break
|
||||
elsif b.has_move_with_function?("BounceBackProblemCausingStatusMoves")
|
||||
score -= 8
|
||||
PBDebug.log_score_change(score - old_score, "a foe knows Magic Coat and could bounce it")
|
||||
break
|
||||
end
|
||||
end
|
||||
if has_magic_bounce
|
||||
end
|
||||
next score
|
||||
}
|
||||
)
|
||||
|
||||
#===============================================================================
|
||||
# Don't prefer a move that can be Snatched if any other battler knows Snatch.
|
||||
#===============================================================================
|
||||
Battle::AI::Handlers::GeneralMoveScore.add(:any_battler_can_Snatch_move,
|
||||
proc { |score, move, user, ai, battle|
|
||||
if move.statusMove? && move.move.canSnatch?
|
||||
ai.each_battler do |b, i|
|
||||
next if b.index == user.index
|
||||
next if b.effects[PBEffects::SkyDrop] >= 0
|
||||
next if !b.has_move_with_function?("StealAndUseBeneficialStatusMove")
|
||||
old_score = score
|
||||
score = Battle::AI::MOVE_USELESS_SCORE
|
||||
PBDebug.log_score_change(score - old_score, "useless because a foe will Magic Bounce it")
|
||||
score -= 8
|
||||
PBDebug.log_score_change(score - old_score, "another battler could Snatch it")
|
||||
break
|
||||
end
|
||||
end
|
||||
next score
|
||||
@@ -372,7 +400,7 @@ Battle::AI::Handlers::GeneralMoveScore.add(:good_move_for_choice_item,
|
||||
# more (desperate).
|
||||
# TODO: Review score modifier.
|
||||
#===============================================================================
|
||||
Battle::AI::Handlers::GeneralMoveScore.add(:prefer_damaging_moves_if_last_pokemon,
|
||||
Battle::AI::Handlers::GeneralMoveScore.add(:either_side_down_to_last_pokemon,
|
||||
proc { |score, move, user, ai, battle|
|
||||
if ai.trainer.medium_skill? && move.damagingMove?
|
||||
reserves = battle.pbAbleNonActiveCount(user.idxOwnSide)
|
||||
|
||||
@@ -301,34 +301,174 @@ class Battle::AI::AIBattler
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# TODO: Add more items.
|
||||
BASE_ITEM_RATINGS = {
|
||||
:ADAMANTORB => 3,
|
||||
:BLACKBELT => 2,
|
||||
:BLACKGLASSES => 2,
|
||||
:BLACKSLUDGE => -4,
|
||||
:CHARCOAL => 2,
|
||||
:CHOICEBAND => 4,
|
||||
:CHOICESCARF => 4,
|
||||
:CHOICESPECS => 4,
|
||||
:DEEPSEATOOTH => 4,
|
||||
:DRACOPLATE => 2,
|
||||
:DRAGONFANG => 2,
|
||||
:DREADPLATE => 2,
|
||||
:EARTHPLATE => 2,
|
||||
:FISTPLATE => 2,
|
||||
:FLAMEORB => -4,
|
||||
:FLAMEPLATE => 2,
|
||||
:GRISEOUSORB => 3,
|
||||
:HARDSTONE => 2,
|
||||
:ICICLEPLATE => 2,
|
||||
:INSECTPLATE => 2,
|
||||
:IRONBALL => -4,
|
||||
:IRONPLATE => 2,
|
||||
:LAGGINGTAIL => -2,
|
||||
:LEFTOVERS => 4,
|
||||
:LIFEORB => 3,
|
||||
:LIGHTBALL => 4,
|
||||
:LUSTROUSORB => 3,
|
||||
:MAGNET => 2,
|
||||
:MEADOWPLATE => 2,
|
||||
:METALCOAT => 2,
|
||||
:METRONOME => 1,
|
||||
:MINDPLATE => 2,
|
||||
:MIRACLESEED => 2,
|
||||
:MUSCLEBAND => 2,
|
||||
:MYSTICWATER => 2,
|
||||
:NEVERMELTICE => 2,
|
||||
:ODDINCENSE => 2,
|
||||
:PIXIEPLATE => 2,
|
||||
:POISONBARB => 2,
|
||||
:ROCKINCENSE => 2,
|
||||
:ROSEINCENSE => 2,
|
||||
:SEAINCENSE => 2,
|
||||
:SHARPBEAK => 2,
|
||||
:SILKSCARF => 2,
|
||||
:SILVERPOWDER => 2,
|
||||
:SKYPLATE => 2,
|
||||
:SOFTSAND => 2,
|
||||
:SOULDEW => 3,
|
||||
:SPELLTAG => 2,
|
||||
:SPLASHPLATE => 2,
|
||||
:SPOOKYPLATE => 2,
|
||||
:STICKYBARB => -2,
|
||||
:STONEPLATE => 2,
|
||||
:THICKCLUB => 4,
|
||||
:TOXICORB => -4,
|
||||
:TOXICPLATE => 2,
|
||||
:TWISTEDSPOON => 2,
|
||||
:WAVEINCENSE => 2,
|
||||
:WISEGLASSES => 2,
|
||||
:ZAPPLATE => 2
|
||||
}
|
||||
|
||||
# Returns a value indicating how beneficial the given item will be to this
|
||||
# battler if it is holding it.
|
||||
# Return values are typically -2, -1, 0, 1 or 2. 0 is indifferent, positive
|
||||
# Return values are typically between -10 and +10. 0 is indifferent, positive
|
||||
# values mean this battler benefits, negative values mean this battler suffers.
|
||||
def wants_item?(item = :NONE)
|
||||
item == :NONE if item.nil?
|
||||
# TODO: Add more items.
|
||||
preferred_items = [
|
||||
:CHOICESCARF,
|
||||
:LEFTOVERS
|
||||
]
|
||||
preferred_items.push(:BLACKSLUDGE) if has_type?(:POISON)
|
||||
preferred_items.push(:IRONBALL) if has_move_with_function?("ThrowUserItemAtTarget")
|
||||
preferred_items.push(:CHOICEBAND) if check_for_move { |m| m.physicalMove?(m.type) }
|
||||
preferred_items.push(:CHOICESPECS) if check_for_move { |m| m.specialMove?(m.type) }
|
||||
unpreferred_items = [
|
||||
:BLACKSLUDGE,
|
||||
:FLAMEORB,
|
||||
:IRONBALL,
|
||||
:LAGGINGTAIL,
|
||||
:STICKYBARB,
|
||||
:TOXICORB
|
||||
]
|
||||
ret = 0
|
||||
if preferred_items.include?(item)
|
||||
ret = 2
|
||||
elsif unpreferred_items.include?(item)
|
||||
ret = -2
|
||||
def wants_item?(item)
|
||||
item = item.id if !item.is_a?(Symbol) && item.respond_to?("id")
|
||||
return 0 if has_active_ability?(:KLUTZ)
|
||||
# TODO: Unnerve, other item-negating effects.
|
||||
ret = BASE_ITEM_RATINGS[item] || 0
|
||||
case item
|
||||
when :ADAMANTORB
|
||||
ret = 0 if !@battler.isSpecies?(:DIALGA) || !has_damaging_move_of_type?(:DRAGON, :STEEL)
|
||||
when :BLACKBELT, :BLACKGLASSES, :CHARCOAL, :DRAGONFANG, :HARDSTONE, :MAGNET,
|
||||
:METALCOAT, :MIRACLESEED, :MYSTICWATER, :NEVERMELTICE, :POISONBARB,
|
||||
:SHARPBEAK, :SILKSCARF, :SILVERPOWDER, :SOFTSAND, :SPELLTAG,
|
||||
:TWISTEDSPOON,
|
||||
:DRACOPLATE, :DREADPLATE, :EARTHPLATE, :FISTPLATE, :FLAMEPLATE,
|
||||
:ICICLEPLATE, :INSECTPLATE, :IRONPLATE, :MEADOWPLATE, :MINDPLATE,
|
||||
:PIXIEPLATE, :SKYPLATE, :SPLASHPLATE, :SPOOKYPLATE, :STONEPLATE,
|
||||
:TOXICPLATE, :ZAPPLATE,
|
||||
:ODDINCENSE, :ROCKINCENSE, :ROSEINCENSE, :SEAINCENSE, :WAVEINCENSE
|
||||
boosted_type = {
|
||||
:BLACKBELT => :FIGHTING,
|
||||
:BLACKGLASSES => :DARK,
|
||||
:CHARCOAL => :FIRE,
|
||||
:DRAGONFANG => :DRAGON,
|
||||
:HARDSTONE => :ROCK,
|
||||
:MAGNET => :ELECTRIC,
|
||||
:METALCOAT => :STEEL,
|
||||
:MIRACLESEED => :GRASS,
|
||||
:MYSTICWATER => :WATER,
|
||||
:NEVERMELTICE => :ICE,
|
||||
:POISONBARB => :POISON,
|
||||
:SHARPBEAK => :FLYING,
|
||||
:SILKSCARF => :NORMAL,
|
||||
:SILVERPOWDER => :BUG,
|
||||
:SOFTSAND => :GROUND,
|
||||
:SPELLTAG => :GHOST,
|
||||
:TWISTEDSPOON => :PSYCHIC,
|
||||
:DRACOPLATE => :DRAGON,
|
||||
:DREADPLATE => :DARK,
|
||||
:EARTHPLATE => :GROUND,
|
||||
:FISTPLATE => :FIGHTING,
|
||||
:FLAMEPLATE => :FIRE,
|
||||
:ICICLEPLATE => :ICE,
|
||||
:INSECTPLATE => :BUG,
|
||||
:IRONPLATE => :STEEL,
|
||||
:MEADOWPLATE => :GRASS,
|
||||
:MINDPLATE => :PSYCHIC,
|
||||
:PIXIEPLATE => :FAIRY,
|
||||
:SKYPLATE => :FLYING,
|
||||
:SPLASHPLATE => :WATER,
|
||||
:SPOOKYPLATE => :GHOST,
|
||||
:STONEPLATE => :ROCK,
|
||||
:TOXICPLATE => :POISON,
|
||||
:ZAPPLATE => :ELECTRIC,
|
||||
:ODDINCENSE => :PSYCHIC,
|
||||
:ROCKINCENSE => :ROCK,
|
||||
:ROSEINCENSE => :GRASS,
|
||||
:SEAINCENSE => :WATER,
|
||||
:WAVEINCENSE => :WATER
|
||||
}[item]
|
||||
ret = 0 if !has_damaging_move_of_type?(boosted_type)
|
||||
when :BLACKSLUDGE
|
||||
ret = 4 if has_type?(:POISON)
|
||||
when :CHOICEBAND, :MUSCLEBAND
|
||||
ret = 0 if !check_for_move { |m| m.physicalMove?(m.type) }
|
||||
when :CHOICESPECS, :WISEGLASSES
|
||||
ret = 0 if !check_for_move { |m| m.specialMove?(m.type) }
|
||||
when :DEEPSEATOOTH
|
||||
ret = 0 if !@battler.isSpecies?(:CLAMPERL) || !check_for_move { |m| m.specialMove?(m.type) }
|
||||
when :GRISEOUSORB
|
||||
ret = 0 if !@battler.isSpecies?(:GIRATINA) || !has_damaging_move_of_type?(:DRAGON, :GHOST)
|
||||
when :IRONBALL
|
||||
ret = 0 if has_move_with_function?("ThrowUserItemAtTarget")
|
||||
when :LIGHTBALL
|
||||
ret = 0 if !@battler.isSpecies?(:PIKACHU) || !check_for_move { |m| m.damagingMove? }
|
||||
when :LUSTROUSORB
|
||||
ret = 0 if !@battler.isSpecies?(:PALKIA) || !has_damaging_move_of_type?(:DRAGON, :WATER)
|
||||
when :SOULDEW
|
||||
if !@battler.isSpecies?(:LATIAS) && !@battler.isSpecies?(:LATIOS)
|
||||
ret = 0
|
||||
elsif Settings::SOUL_DEW_POWERS_UP_TYPES
|
||||
ret = 0 if !has_damaging_move_of_type?(:PSYCHIC, :DRAGON)
|
||||
else
|
||||
ret -= 2 if !check_for_move { |m| m.specialMove?(m.type) } # Also boosts SpDef
|
||||
end
|
||||
when :THICKCLUB
|
||||
ret = 0 if (!@battler.isSpecies?(:CUBONE) && !@battler.isSpecies?(:MAROWAK)) ||
|
||||
!check_for_move { |m| m.physicalMove?(m.type) }
|
||||
end
|
||||
# Prefer if this battler knows Fling and it will do a lot of damage/have an
|
||||
# additional (negative) effect when flung
|
||||
if has_move_with_function?("ThrowUserItemAtTarget")
|
||||
GameData::Item.get(item).flags.each do |flag|
|
||||
next if !flag[/^Fling_(\d+)$/i]
|
||||
amt = $~[1].to_i
|
||||
ret += 1 if amt >= 80
|
||||
ret += 1 if amt >= 100
|
||||
break
|
||||
end
|
||||
if [:FLAMEORB, :KINGSROCK, :LIGHTBALL, :POISONBARB, :RAZORFANG, :TOXICORB].include?(item)
|
||||
ret += 1
|
||||
end
|
||||
end
|
||||
# Don't prefer if this battler knows Acrobatics
|
||||
if has_move_with_function?("DoublePowerIfUserHasNoItem")
|
||||
|
||||
@@ -546,17 +546,22 @@ class Battle::AI::AIMove
|
||||
|
||||
#=============================================================================
|
||||
|
||||
# Returns:
|
||||
# 0 = move doesn't have an additional effect
|
||||
# 1 = additional effect will be negated
|
||||
# 2 = additional effect will work
|
||||
# 3 = additional effect has an increased chance to work
|
||||
def additional_effect_usability(user, target)
|
||||
return 3 if self.function == "ThrowUserItemAtTarget"
|
||||
return 0 if @move.addlEffect == 0 # Doesn't have an additional effect
|
||||
return 1 if target.has_active_ability?(:SHIELDDUST) && !@ai.battle.moldBreaker
|
||||
return 3 if (Settings::MECHANICS_GENERATION >= 6 || self.function != "EffectDependsOnEnvironment") &&
|
||||
# Return values:
|
||||
# 0: Regular additional effect chance or isn't an additional effect
|
||||
# -999: Additional effect will be negated
|
||||
# Other: Amount to add to a move's score
|
||||
def get_score_change_for_additional_effect(user, target)
|
||||
# Doesn't have an additional effect
|
||||
return 0 if @move.addlEffect == 0
|
||||
# Additional effect will be negated
|
||||
return -999 if user.has_active_ability?(:SHEERFORCE)
|
||||
return -999 if 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 || self.function != "EffectDependsOnEnvironment") &&
|
||||
(user.has_active_ability?(:SERENEGRACE) || user.pbOwnSide.effects[PBEffects::Rainbow] > 0)
|
||||
return 2
|
||||
# No change to score
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user