Errors in the AI no longer cause it to do nothing

This commit is contained in:
Maruno17
2022-10-16 14:52:27 +01:00
parent 58a624060a
commit 43290c39a2
3 changed files with 12 additions and 5 deletions

View File

@@ -3,7 +3,9 @@ class Battle::AI
# Decide whether the opponent should use an item on the Pokémon
#=============================================================================
def pbEnemyShouldUseItem?
item, idxTarget = pbEnemyItemToUse
item = nil
idxTarget = nil
PBDebug.logonerr { item, idxTarget = pbEnemyItemToUse }
return false if !item
# Determine target of item (always the Pokémon choosing the action)
useType = GameData::Item.get(item).battle_use

View File

@@ -3,7 +3,9 @@ class Battle::AI
# Decide whether the opponent should switch Pokémon
#=============================================================================
def pbEnemyShouldWithdraw?
return pbEnemyShouldWithdrawEx?(false)
ret = false
PBDebug.logonerr { ret = pbEnemyShouldWithdrawEx?(false) }
return ret
end
def pbEnemyShouldWithdrawEx?(forceSwitch)

View File

@@ -54,7 +54,8 @@ class Battle::AI
# If move has no targets, affects the user, a side or the whole field, or
# specially affects multiple Pokémon and the AI calculates an overall
# score at once instead of per target
score = pbGetMoveScore(move)
score = 100
PBDebug.logonerr { score = pbGetMoveScore(move) }
choices.push([idxMove, score, -1])
elsif target_data.num_targets > 1
# Includes: AllFoes, AllNearFoes, AllNearOthers
@@ -65,7 +66,8 @@ class Battle::AI
num_targets = 0
@battle.allBattlers.each do |b|
next if !@battle.pbMoveCanTarget?(battler.index, b.index, target_data)
score = pbGetMoveScore(move, b)
score = 100
PBDebug.logonerr { score = pbGetMoveScore(move, b) }
total_score += ((battler.opposes?(b)) ? score : -score)
num_targets += 1
end
@@ -84,7 +86,8 @@ class Battle::AI
# that the target can be immune to by an ability (you may want to
# attack the ally anyway so it gains the effect of that ability).
next if target_data.targets_foe && !battler.opposes?(b)
score = pbGetMoveScore(move, b)
score = 100
PBDebug.logonerr { score = pbGetMoveScore(move, b) }
choices.push([idxMove, score, b.index])
end
end