mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 14:14:59 +00:00
Waged war against TODO comments in the AI, some refactoring of AI
This commit is contained in:
@@ -138,10 +138,10 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("FailsIfUserDamagedThisTu
|
||||
#===============================================================================
|
||||
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("FailsIfTargetActed",
|
||||
proc { |score, move, user, target, ai, battle|
|
||||
# Check whether user is faster than its foe(s) and could use this move
|
||||
# Check whether user is faster than the target and could use this move
|
||||
next Battle::AI::MOVE_USELESS_SCORE if target.faster_than?(user)
|
||||
# TODO: Predict the target switching/using an item.
|
||||
# TODO: Predict the target using a damaging move or Me First.
|
||||
# Check whether the target has any damaging moves it could use
|
||||
next Battle::AI::MOVE_USELESS_SCORE if !target.check_for_move { |m| m.damagingMove? }
|
||||
# Don't risk using this move if target is weak
|
||||
if ai.trainer.has_skill_flag?("HPAware")
|
||||
score -= 10 if target.hp <= target.totalhp / 2
|
||||
@@ -157,7 +157,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("FailsIfTargetActed",
|
||||
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("CrashDamageIfFailsUnusableInGravity",
|
||||
proc { |score, move, user, target, ai, battle|
|
||||
if user.battler.takesIndirectDamage?
|
||||
score -= (0.4 * (100 - move.rough_accuracy)).to_i # -0 (100%) to -40 (1%)
|
||||
score -= (0.6 * (100 - move.rough_accuracy)).to_i # -0 (100%) to -60 (1%)
|
||||
end
|
||||
next score
|
||||
}
|
||||
@@ -367,17 +367,9 @@ Battle::AI::Handlers::MoveEffectScore.add("AddSpikesToFoeSide",
|
||||
battle.pbParty(user.idxOpposingSide).each_with_index do |pkmn, idxParty|
|
||||
next if !pkmn || !pkmn.able? || inBattleIndices.include?(idxParty)
|
||||
if ai.trainer.medium_skill?
|
||||
# Check affected by entry hazard
|
||||
next if pkmn.hasItem?(:HEAVYDUTYBOOTS)
|
||||
# Check can take indirect damage
|
||||
next if ai.pokemon_airborne?(pkmn)
|
||||
next if pkmn.hasAbility?(:MAGICGUARD)
|
||||
# Check airborne
|
||||
if !pkmn.hasItem?(:IRONBALL) &&
|
||||
battle.field.effects[PBEffects::Gravity] == 0
|
||||
next if pkmn.hasType?(:FLYING)
|
||||
next if pkmn.hasAbility?(:LEVITATE)
|
||||
next if pkmn.hasItem?(:AIRBALLOON)
|
||||
end
|
||||
end
|
||||
foe_reserves.push(pkmn) # pkmn will be affected by Spikes
|
||||
end
|
||||
@@ -403,25 +395,9 @@ Battle::AI::Handlers::MoveEffectScore.add("AddToxicSpikesToFoeSide",
|
||||
battle.pbParty(user.idxOpposingSide).each_with_index do |pkmn, idxParty|
|
||||
next if !pkmn || !pkmn.able? || inBattleIndices.include?(idxParty)
|
||||
if ai.trainer.medium_skill?
|
||||
# Check affected by entry hazard
|
||||
next if pkmn.hasItem?(:HEAVYDUTYBOOTS)
|
||||
# Check pkmn's immunity to being poisoned
|
||||
next if battle.field.terrain == :Misty
|
||||
next if pkmn.hasType?(:POISON)
|
||||
next if pkmn.hasType?(:STEEL)
|
||||
next if pkmn.hasAbility?(:IMMUNITY)
|
||||
next if pkmn.hasAbility?(:PASTELVEIL)
|
||||
next if pkmn.hasAbility?(:FLOWERVEIL) && pkmn.hasType?(:GRASS)
|
||||
next if pkmn.hasAbility?(:LEAFGUARD) && [:Sun, :HarshSun].include?(battle.pbWeather)
|
||||
next if pkmn.hasAbility?(:COMATOSE) && pkmn.isSpecies?(:KOMALA)
|
||||
next if pkmn.hasAbility?(:SHIELDSDOWN) && pkmn.isSpecies?(:MINIOR) && pkmn.form < 7
|
||||
# Check airborne
|
||||
if !pkmn.hasItem?(:IRONBALL) &&
|
||||
battle.field.effects[PBEffects::Gravity] == 0
|
||||
next if pkmn.hasType?(:FLYING)
|
||||
next if pkmn.hasAbility?(:LEVITATE)
|
||||
next if pkmn.hasItem?(:AIRBALLOON)
|
||||
end
|
||||
next if ai.pokemon_airborne?(pkmn)
|
||||
next if !ai.pokemon_can_be_poisoned?(pkmn)
|
||||
end
|
||||
foe_reserves.push(pkmn) # pkmn will be affected by Toxic Spikes
|
||||
end
|
||||
@@ -447,9 +423,7 @@ Battle::AI::Handlers::MoveEffectScore.add("AddStealthRocksToFoeSide",
|
||||
battle.pbParty(user.idxOpposingSide).each_with_index do |pkmn, idxParty|
|
||||
next if !pkmn || !pkmn.able? || inBattleIndices.include?(idxParty)
|
||||
if ai.trainer.medium_skill?
|
||||
# Check affected by entry hazard
|
||||
next if pkmn.hasItem?(:HEAVYDUTYBOOTS)
|
||||
# Check can take indirect damage
|
||||
next if pkmn.hasAbility?(:MAGICGUARD)
|
||||
end
|
||||
foe_reserves.push(pkmn) # pkmn will be affected by Stealth Rock
|
||||
@@ -475,15 +449,8 @@ Battle::AI::Handlers::MoveEffectScore.add("AddStickyWebToFoeSide",
|
||||
battle.pbParty(user.idxOpposingSide).each_with_index do |pkmn, idxParty|
|
||||
next if !pkmn || !pkmn.able? || inBattleIndices.include?(idxParty)
|
||||
if ai.trainer.medium_skill?
|
||||
# Check affected by entry hazard
|
||||
next if pkmn.hasItem?(:HEAVYDUTYBOOTS)
|
||||
# Check airborne
|
||||
if !pkmn.hasItem?(:IRONBALL) &&
|
||||
battle.field.effects[PBEffects::Gravity] == 0
|
||||
next if pkmn.hasType?(:FLYING)
|
||||
next if pkmn.hasAbility?(:LEVITATE)
|
||||
next if pkmn.hasItem?(:AIRBALLOON)
|
||||
end
|
||||
next if ai.pokemon_airborne?(pkmn)
|
||||
end
|
||||
foe_reserves.push(pkmn) # pkmn will be affected by Sticky Web
|
||||
end
|
||||
|
||||
@@ -516,7 +516,9 @@ Battle::AI::Handlers::MoveEffectScore.add("CureUserPartyStatus",
|
||||
proc { |score, move, user, ai, battle|
|
||||
score = Battle::AI::MOVE_BASE_SCORE # Ignore the scores for each targeted battler calculated earlier
|
||||
battle.pbParty(user.index).each do |pkmn|
|
||||
score += 12 if pkmn && pkmn.status != :NONE
|
||||
next if !pkmn || pkmn.status == :NONE
|
||||
next if pkmn.status == :SLEEP && pkmn.statusCount == 1 # About to wake up
|
||||
score += 12
|
||||
end
|
||||
next score
|
||||
}
|
||||
@@ -1071,6 +1073,7 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("NegateTargetAbility",
|
||||
)
|
||||
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("NegateTargetAbility",
|
||||
proc { |score, move, user, target, ai, battle|
|
||||
next Battle::AI::MOVE_USELESS_SCORE if !target.ability_active?
|
||||
target_ability_rating = target.wants_ability?(target.ability_id)
|
||||
side_mult = (target.opposes?(user)) ? 1 : -1
|
||||
if target_ability_rating > 0
|
||||
@@ -1087,8 +1090,8 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("NegateTargetAbility",
|
||||
#===============================================================================
|
||||
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("NegateTargetAbilityIfTargetActed",
|
||||
proc { |score, move, user, target, ai, battle|
|
||||
next score if target.effects[PBEffects::Substitute] > 0 || target.effects[PBEffects::GastroAcid]
|
||||
next score if target.battler.unstoppableAbility?
|
||||
next score if target.effects[PBEffects::Substitute] > 0
|
||||
next score if target.battler.unstoppableAbility? || !target.ability_active?
|
||||
next score if user.faster_than?(target)
|
||||
target_ability_rating = target.wants_ability?(target.ability_id)
|
||||
side_mult = (target.opposes?(user)) ? 1 : -1
|
||||
|
||||
@@ -559,7 +559,6 @@ Battle::AI::Handlers::MoveEffectScore.add("UserEnduresFaintingThisTurn",
|
||||
# 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) * 8
|
||||
# TODO: Check for combos with Flail/Endeavor?
|
||||
next score
|
||||
}
|
||||
)
|
||||
@@ -1353,7 +1352,8 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("EnsureNextMoveAlwaysHits
|
||||
score += 8 if acc <= 50 && acc != 0
|
||||
score += 8 if m.is_a?(Battle::Move::OHKO)
|
||||
end
|
||||
# TODO: Prefer if target has increased evasion.
|
||||
# Prefer if the target has increased evasion
|
||||
score += 5 * target.stages[:EVASION] if target.stages[:EVASION] > 0
|
||||
# Not worth it if the user or the target is at low HP
|
||||
if ai.trainer.has_skill_flag?("HPAware")
|
||||
score -= 10 if user.hp < user.totalhp / 2
|
||||
|
||||
@@ -15,7 +15,6 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("HitTwoTimes",
|
||||
num_hits = move.move.pbNumHits(user.battler, [target.battler])
|
||||
score += 10 if target.effects[PBEffects::Substitute] < dmg * (num_hits - 1) / num_hits
|
||||
end
|
||||
# TODO: Consider effects that trigger per hit.
|
||||
next score
|
||||
}
|
||||
)
|
||||
@@ -80,7 +79,6 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("HitThreeTimesPowersUpWit
|
||||
dmg = move.rough_damage
|
||||
score += 10 if target.effects[PBEffects::Substitute] < dmg / 2
|
||||
end
|
||||
# TODO: Consider effects that trigger per hit.
|
||||
next score
|
||||
}
|
||||
)
|
||||
@@ -111,7 +109,6 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("HitTwoToFiveTimes",
|
||||
num_hits = (user.has_active_ability?(:SKILLLINK)) ? 5 : 3 # 3 is about average
|
||||
score += 10 if target.effects[PBEffects::Substitute] < dmg * (num_hits - 1) / num_hits
|
||||
end
|
||||
# TODO: Consider effects that trigger per hit.
|
||||
next score
|
||||
}
|
||||
)
|
||||
@@ -183,7 +180,6 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("HitOncePerUserTeamMember
|
||||
end
|
||||
score += 10 if target.effects[PBEffects::Substitute] < dmg * (num_hits - 1) / num_hits
|
||||
end
|
||||
# TODO: Consider effects that trigger per hit.
|
||||
next score
|
||||
}
|
||||
)
|
||||
|
||||
@@ -159,8 +159,9 @@ 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 or it has no effect.
|
||||
# TODO: Useless if target's item cannot be negated.
|
||||
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
|
||||
next score
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user