Rewrote AI item usage (inc. adding Revives), various fixes/changes to AI, removed Struggle from PBS files, some bug fixes

This commit is contained in:
Maruno17
2023-04-23 17:52:39 +01:00
parent da182bd98a
commit ce549ab62a
34 changed files with 497 additions and 410 deletions

View File

@@ -1,8 +1,3 @@
#===============================================================================
#
#===============================================================================
# Struggle
#===============================================================================
#
#===============================================================================
@@ -574,9 +569,12 @@ Battle::AI::Handlers::MoveEffectScore.add("UserMakeSubstitute",
#===============================================================================
Battle::AI::Handlers::MoveEffectScore.add("RemoveUserBindingAndEntryHazards",
proc { |score, move, user, ai, battle|
add_effect = move.get_score_change_for_additional_effect(user, target)
next score if add_effect == -999 # Additional effect will be negated
score += add_effect
# Score for raising user's Speed
if Settings::MECHANICS_GENERATION >= 8
score = Battle::AI::Handlers.apply_move_effect_score("RaiseUserSpeed1",
score, move, user, ai, battle)
end
# Score for removing various effects
score += 10 if user.effects[PBEffects::Trapping] > 0
score += 15 if user.effects[PBEffects::LeechSeed] >= 0
if battle.pbAbleNonActiveCount(user.idxOwnSide) > 0

View File

@@ -445,7 +445,7 @@ Battle::AI::Handlers::MoveEffectScore.add("EnsureNextCriticalHit",
# critical hits are impossible (e.g. via Lucky Chant)
crit_stage = 0
crit_stage = -1 if user.battler.pbOwnSide.effects[PBEffects::LuckyChant] > 0
if crit_stage >= 0 && user.ability_active? && ![:MERCILESS].include?(user.ability)
if crit_stage >= 0 && user.ability_active? && ![:MERCILESS].include?(user.ability_id)
crit_stage = Battle::AbilityEffects.triggerCriticalCalcFromUser(user.battler.ability,
user.battler, user.battler, crit_stage)
end
@@ -660,6 +660,8 @@ Battle::AI::Handlers::MoveEffectScore.add("StartWeakenPhysicalDamageAgainstUserS
score += 10
score += 8 if !b.check_for_move { |m| m.specialMove?(m.type) }
end
# Prefer if user has Light Clay
score += 5 if user.has_active_item?(:LIGHTCLAY)
next score
}
)
@@ -688,6 +690,8 @@ Battle::AI::Handlers::MoveEffectScore.add("StartWeakenSpecialDamageAgainstUserSi
score += 10
score += 8 if !b.check_for_move { |m| m.physicalMove?(m.type) }
end
# Prefer if user has Light Clay
score += 5 if user.has_active_item?(:LIGHTCLAY)
next score
}
)
@@ -713,6 +717,8 @@ Battle::AI::Handlers::MoveEffectScore.add("StartWeakenDamageAgainstUserSideIfHai
score -= (20 * (0.75 - (user.hp.to_f / user.totalhp))).to_i # -5 to -15
end
end
# Prefer if user has Light Clay
score += 5 if user.has_active_item?(:LIGHTCLAY)
next score + 15
}
)
@@ -883,7 +889,7 @@ Battle::AI::Handlers::MoveEffectScore.add("ProtectUserFromDamagingMovesKingsShie
# less likely to work
score -= (user.effects[PBEffects::ProtectRate] - 1) * ((Settings::MECHANICS_GENERATION >= 6) ? 15 : 10)
# Aegislash
score += 10 if user.battler.isSpecies?(:AEGISLASH) && user.form == 1 &&
score += 10 if user.battler.isSpecies?(:AEGISLASH) && user.battler.form == 1 &&
user.ability == :STANCECHANGE
next score
}
@@ -1533,7 +1539,7 @@ Battle::AI::Handlers::MoveEffectScore.add("NormalMovesBecomeElectric",
normal_type_better = 0
electric_type_better = 0
ai.each_foe_battler(user.side) do |b, i|
next if move.pbPriority(b.battler) <= 0 && b.faster_than?(user)
next if move.rough_priority(b) <= 0 && b.faster_than?(user)
next if !b.has_damaging_move_of_type?(:NORMAL)
# Normal's effectiveness
eff = user.effectiveness_of_type_against_battler(:NORMAL, b)

View File

@@ -64,6 +64,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("UserTargetSwapItems",
score += target_old_item_preference - target_new_item_preference
# Don't prefer if user used this move in the last round
score -= 15 if user.battler.lastMoveUsed &&
GameData::Move.exists?(user.battler.lastMoveUsed) &&
GameData::Move.get(user.battler.lastMoveUsed).function_code == move.function
next score
}

View File

@@ -265,7 +265,7 @@ Battle::AI::Handlers::MoveEffectScore.add("CounterPhysicalDamage",
score += 5 if b.rough_stat(:ATTACK) > b.rough_stat(:SPECIAL_ATTACK)
# Prefer if the last move the foe used was physical
if ai.trainer.medium_skill? && b.battler.lastMoveUsed
score += 8 if GameData::Move.get(b.battler.lastMoveUsed).physical?
score += 8 if GameData::Move.try_get(b.battler.lastMoveUsed)&.physical?
end
# Prefer if the foe is taunted into using a damaging move
score += 5 if b.effects[PBEffects::Taunt] > 0
@@ -297,7 +297,7 @@ Battle::AI::Handlers::MoveEffectScore.add("CounterSpecialDamage",
score += 5 if b.rough_stat(:SPECIAL_ATTACK) > b.rough_stat(:ATTACK)
# Prefer if the last move the foe used was special
if ai.trainer.medium_skill? && b.battler.lastMoveUsed
score += 8 if GameData::Move.get(b.battler.lastMoveUsed).special?
score += 8 if GameData::Move.try_get(b.battler.lastMoveUsed)&.special?
end
# Prefer if the foe is taunted into using a damaging move
score += 5 if b.effects[PBEffects::Taunt] > 0
@@ -327,7 +327,7 @@ Battle::AI::Handlers::MoveEffectScore.add("CounterDamagePlusHalf",
has_damaging_move = true
# Prefer if the last move the foe used was damaging
if ai.trainer.medium_skill? && b.battler.lastMoveUsed
score += 8 if GameData::Move.get(b.battler.lastMoveUsed).damaging?
score += 8 if GameData::Move.try_get(b.battler.lastMoveUsed)&.damaging?
end
# Prefer if the foe is taunted into using a damaging move
score += 5 if b.effects[PBEffects::Taunt] > 0
@@ -454,7 +454,7 @@ Battle::AI::Handlers::MoveEffectScore.add("WaterPledge",
#===============================================================================
Battle::AI::Handlers::MoveFailureCheck.add("UseLastMoveUsed",
proc { |move, user, ai, battle|
next true if !battle.lastMoveUsed
next true if !battle.lastMoveUsed || !GameData::Move.exists?(battle.lastMoveUsed)
next move.move.moveBlacklist.include?(GameData::Move.get(battle.lastMoveUsed).function_code)
}
)
@@ -468,6 +468,7 @@ Battle::AI::Handlers::MoveFailureCheck.add("UseLastMoveUsed",
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("UseLastMoveUsedByTarget",
proc { |move, user, target, ai, battle|
next true if !target.battler.lastRegularMoveUsed
next true if !GameData::Move.exists?(target.battler.lastRegularMoveUsed)
next !GameData::Move.get(target.battler.lastRegularMoveUsed).has_flag?("CanMirrorMove")
}
)

View File

@@ -434,8 +434,8 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TargetActsNext",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveEffectScore.add("TargetActsLast",
proc { |score, move, user, ai, battle|
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("TargetActsLast",
proc { |score, move, user, target, ai, battle|
# Useless if the target is an ally
next Battle::AI::MOVE_USELESS_SCORE if !target.opposes?(user)
# Useless if the user has no ally (the point of this move is to let the ally
@@ -643,6 +643,7 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("DisableTargetUsingDiffe
proc { |move, user, target, ai, battle|
next true if target.effects[PBEffects::Encore] > 0
next true if !target.battler.lastRegularMoveUsed ||
!GameData::Move.exists?(target.battler.lastRegularMoveUsed) ||
move.move.moveBlacklist.include?(GameData::Move.get(target.battler.lastRegularMoveUsed).function_code)
next true if target.effects[PBEffects::ShellTrap]
next true if move.move.pbMoveFailedAromaVeil?(user.battler, target.battler, false)