AI: Added checks for additional effect chance, Snatch/Magic Coat, more item ratings

This commit is contained in:
Maruno17
2023-03-11 20:13:02 +00:00
parent 5a18f7fd65
commit e9a44377ce
10 changed files with 308 additions and 131 deletions

View File

@@ -540,6 +540,9 @@ 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 += 10 if user.effects[PBEffects::Trapping] > 0
score += 15 if user.effects[PBEffects::LeechSeed] >= 0
if battle.pbAbleNonActiveCount(user.idxOwnSide) > 0

View File

@@ -36,9 +36,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("RaiseUserAttack2IfTarget
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureCheck.copy("RaiseUserAttack2",
Battle::AI::Handlers::MoveFailureCheck.copy("RaiseUserAttack1",
"RaiseUserAttack3")
Battle::AI::Handlers::MoveEffectScore.copy("RaiseUserAttack2",
Battle::AI::Handlers::MoveEffectScore.copy("RaiseUserAttack1",
"RaiseUserAttack3")
#===============================================================================
@@ -282,9 +282,9 @@ Battle::AI::Handlers::MoveEffectScore.add("RaiseUserEvasion2MinimizeUser",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureCheck.copy("RaiseUserEvasion2",
Battle::AI::Handlers::MoveFailureCheck.copy("RaiseUserEvasion1",
"RaiseUserEvasion3")
Battle::AI::Handlers::MoveEffectScore.copy("RaiseUserEvasion2",
Battle::AI::Handlers::MoveEffectScore.copy("RaiseUserEvasion1",
"RaiseUserEvasion3")
#===============================================================================
@@ -763,9 +763,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetAttack1",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetAttack2",
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetAttack1",
"LowerTargetAttack3")
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetAttack2",
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetAttack1",
"LowerTargetAttack3")
#===============================================================================
@@ -800,9 +800,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetDefense1",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetDefense2",
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetDefense1",
"LowerTargetDefense3")
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetDefense2",
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetDefense1",
"LowerTargetDefense3")
#===============================================================================
@@ -839,9 +839,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpAtk2",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetSpAtk2",
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetSpAtk1",
"LowerTargetSpAtk3")
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpAtk2",
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpAtk1",
"LowerTargetSpAtk3")
#===============================================================================
@@ -863,9 +863,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpDef1",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetSpDef2",
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetSpDef1",
"LowerTargetSpDef3")
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpDef2",
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpDef1",
"LowerTargetSpDef3")
#===============================================================================
@@ -925,9 +925,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpeed1",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetSpeed2",
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetSpeed1",
"LowerTargetSpeed3")
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpeed2",
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetSpeed1",
"LowerTargetSpeed3")
#===============================================================================
@@ -949,9 +949,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetAccuracy1",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetAccuracy2",
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetAccuracy1",
"LowerTargetAccuracy3")
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetAccuracy2",
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetAccuracy1",
"LowerTargetAccuracy3")
#===============================================================================
@@ -1028,9 +1028,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetEvasion1",
#===============================================================================
#
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetEvasion2",
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.copy("LowerTargetEvasion1",
"LowerTargetEvasion3")
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetEvasion2",
Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("LowerTargetEvasion1",
"LowerTargetEvasion3")
#===============================================================================

View File

@@ -15,12 +15,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("SleepTarget",
target.has_active_ability?(:HYDRATION) &&
[:Rain, :HeavyRain].include?(target.battler.effectiveWeather)
if target.battler.pbCanSleep?(user.battler, false, move.move)
case move.additional_effect_usability(user, target)
when 1 # Additional effect will be negated
next score
when 3 # Additional effect has an increased chance to work
score += 5
end
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
# Inherent preference
score += 15
# Prefer if the user or an ally has a move/ability that is better if the target is asleep
@@ -107,12 +104,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("PoisonTarget",
target.has_active_ability?(:HYDRATION) &&
[:Rain, :HeavyRain].include?(target.battler.effectiveWeather)
if target.battler.pbCanPoison?(user.battler, false, move.move)
case move.additional_effect_usability(user, target)
when 1 # Additional effect will be negated
next score
when 3 # Additional effect has an increased chance to work
score += 5
end
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
# Inherent preference
score += 10
# Prefer if the target is at high HP
@@ -194,12 +188,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("ParalyzeTarget",
target.has_active_ability?(:HYDRATION) &&
[:Rain, :HeavyRain].include?(target.battler.effectiveWeather)
if target.battler.pbCanParalyze?(user.battler, false, move.move)
case move.additional_effect_usability(user, target)
when 1 # Additional effect will be negated
next score
when 3 # Additional effect has an increased chance to work
score += 5
end
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
# Inherent preference (because of the chance of full paralysis)
score += 10
# Prefer if the target is faster than the user but will become slower if
@@ -291,12 +282,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("BurnTarget",
target.has_active_ability?(:HYDRATION) &&
[:Rain, :HeavyRain].include?(target.battler.effectiveWeather)
if target.battler.pbCanBurn?(user.battler, false, move.move)
case move.additional_effect_usability(user, target)
when 1 # Additional effect will be negated
next score
when 3 # Additional effect has an increased chance to work
score += 5
end
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
# Inherent preference
score += 10
# Prefer if the target knows any physical moves that will be weaked by a burn
@@ -370,12 +358,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("FreezeTarget",
target.has_active_ability?(:HYDRATION) &&
[:Rain, :HeavyRain].include?(target.battler.effectiveWeather)
if target.battler.pbCanFreeze?(user.battler, false, move.move)
case move.additional_effect_usability(user, target)
when 1 # Additional effect will be negated
next score
when 3 # Additional effect has an increased chance to work
score += 5
end
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
# Inherent preference
score += 15
# Prefer if the user or an ally has a move/ability that is better if the target is frozen
@@ -528,10 +513,14 @@ Battle::AI::Handlers::MoveEffectScore.add("CureUserPartyStatus",
#===============================================================================
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("CureTargetBurn",
proc { |score, move, user, target, ai, battle|
add_effect = move.get_score_change_for_additional_effect(user, target)
next score if add_effect == -999 # Additional effect will be negated
if target.status == :BURN
if target.opposes?(user)
score -= add_effect
score -= 10
else
score += add_effect
score += 10
end
end
@@ -573,12 +562,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("FlinchTarget",
proc { |score, move, user, target, ai, battle|
next score if target.faster_than?(user) || target.effects[PBEffects::Substitute] > 0
next score if target.has_active_ability?(:INNERFOCUS) && !battle.moldBreaker
case move.additional_effect_usability(user, target)
when 1 # Additional effect will be negated
next score
when 3 # Additional effect has an increased chance to work
score += 5
end
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
# Inherent preference
score += 10
# Prefer if the target is paralysed, confused or infatuated, to compound the
@@ -631,12 +617,9 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("ConfuseTarget",
# No score modifier if the status problem will be removed immediately
next score if target.has_active_item?(:PERSIMBERRY)
if target.battler.pbCanConfuse?(user.battler, false, move.move)
case move.additional_effect_usability(user, target)
when 1 # Additional effect will be negated
next score
when 3 # Additional effect has an increased chance to work
score += 5
end
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
# Inherent preference
score += 5
# Prefer if the target is at high HP
@@ -668,12 +651,9 @@ Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("AttractTarget",
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("AttractTarget",
proc { |score, move, user, target, ai, battle|
if target.battler.pbCanAttract?(user.battler, false)
case move.additional_effect_usability(user, target)
when 1 # Additional effect will be negated
next score
when 3 # Additional effect has an increased chance to work
score += 5
end
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
# Inherent preference
score += 10
# Prefer if the target is paralysed or confused, to compound the turn skipping

View File

@@ -159,7 +159,7 @@ 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?
item_score = target.wants_item?(target.item_id)
score += item_score * 5
score += item_score * 3
next score
}
)

View File

@@ -207,6 +207,7 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.copy("BindTarget",
#===============================================================================
# TODO: Review score modifiers.
# TODO: Include get_score_change_for_additional_effect usage.
#===============================================================================
Battle::AI::Handlers::MoveFailureAgainstTargetCheck.add("TrapTargetInBattle",
proc { |move, user, target, ai, battle|
@@ -466,9 +467,12 @@ Battle::AI::Handlers::MoveEffectScore.add("StartSlowerBattlersActFirst",
#===============================================================================
Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("LowerPPOfTargetLastMoveBy3",
proc { |score, move, user, target, ai, battle|
add_effect = move.get_score_change_for_additional_effect(user, target)
next score if add_effect == -999 # Additional effect will be negated
if user.faster_than?(target)
last_move = target.battler.pbGetMoveWithID(target.battler.lastRegularMoveUsed)
if last_move && last_move.total_pp > 0
score += add_effect
next score + 20 if last_move.pp <= 3 # Will fully deplete the move's PP
next score + 10 if last_move.pp <= 5
next score - 10 if last_move.pp > 9 # Too much PP left to make a difference
@@ -685,6 +689,10 @@ Battle::AI::Handlers::MoveEffectAgainstTargetScore.add("DisableTargetSoundMoves"
proc { |score, move, user, target, ai, battle|
next score if target.effects[PBEffects::ThroatChop] > 1
next score if !target.check_for_move { |m| m.soundMove? }
# Check additional effect chance
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
# Inherent preference
score += 8
next score