Obsoleted battle methods that yield battlers in favour of ones that return all of them at once

This commit is contained in:
Maruno17
2021-10-27 22:45:34 +01:00
parent 6066797517
commit f3abcb7caf
38 changed files with 213 additions and 321 deletions

View File

@@ -608,7 +608,7 @@ class PokeBattle_Battler
return true if @effects[PBEffects::Trapping] > 0
return true if @effects[PBEffects::MeanLook] >= 0
return true if @effects[PBEffects::JawLock] >= 0
@battle.eachBattler { |b| return true if b.effects[PBEffects::JawLock] == @index }
return true if @battle.allBattlers.any? { |b| b.effects[PBEffects::JawLock] == @index }
return true if @effects[PBEffects::Octolock] >= 0
return true if @effects[PBEffects::Ingrain]
return true if @effects[PBEffects::NoRetreat]
@@ -728,17 +728,29 @@ class PokeBattle_Battler
end
# Yields each unfainted ally Pokémon.
# Unused
def eachAlly
@battle.battlers.each do |b|
yield b if b && !b.fainted? && !b.opposes?(@index) && b.index!=@index
end
end
# Returns an array containing all unfainted ally Pokémon.
def allAllies
return @battle.allSameSideBattlers(@index).select { |b| b.index != @index }
end
# Yields each unfainted opposing Pokémon.
# Unused
def eachOpposing
@battle.battlers.each { |b| yield b if b && !b.fainted? && b.opposes?(@index) }
end
# Returns an array containing all unfainted opposing Pokémon.
def allOpposing
return @battle.allOtherSideBattlers(@index)
end
# Returns the battler that is most directly opposite to self. unfaintedOnly is
# whether it should prefer to return a non-fainted battler.
def pbDirectOpposing(unfaintedOnly=false)

View File

@@ -164,7 +164,7 @@ class PokeBattle_Battler
@movesUsed = []
@turnCount = 0
@effects[PBEffects::Attract] = -1
@battle.eachBattler do |b| # Other battlers no longer attracted to self
@battle.allBattlers.each do |b| # Other battlers no longer attracted to self
b.effects[PBEffects::Attract] = -1 if b.effects[PBEffects::Attract]==@index
end
@effects[PBEffects::BanefulBunker] = false
@@ -210,11 +210,11 @@ class PokeBattle_Battler
@effects[PBEffects::Instruct] = false
@effects[PBEffects::Instructed] = false
@effects[PBEffects::JawLock] = -1
@battle.eachBattler do |b| # Other battlers no longer blocked by self
@battle.allBattlers.each do |b| # Other battlers no longer blocked by self
b.effects[PBEffects::JawLock] = -1 if b.effects[PBEffects::JawLock] == @index
end
@effects[PBEffects::KingsShield] = false
@battle.eachBattler do |b| # Other battlers lose their lock-on against self
@battle.allBattlers.each do |b| # Other battlers lose their lock-on against self
next if b.effects[PBEffects::LockOn]==0
next if b.effects[PBEffects::LockOnPos]!=@index
b.effects[PBEffects::LockOn] = 0
@@ -223,7 +223,7 @@ class PokeBattle_Battler
@effects[PBEffects::MagicBounce] = false
@effects[PBEffects::MagicCoat] = false
@effects[PBEffects::MeanLook] = -1
@battle.eachBattler do |b| # Other battlers no longer blocked by self
@battle.allBattlers.each do |b| # Other battlers no longer blocked by self
b.effects[PBEffects::MeanLook] = -1 if b.effects[PBEffects::MeanLook]==@index
end
@effects[PBEffects::MeFirst] = false
@@ -239,7 +239,7 @@ class PokeBattle_Battler
@effects[PBEffects::NoRetreat] = false
@effects[PBEffects::Obstruct] = false
@effects[PBEffects::Octolock] = -1
@battle.eachBattler do |b| # Other battlers no longer locked by self
@battle.allBattlers.each do |b| # Other battlers no longer locked by self
b.effects[PBEffects::Octolock] = -1 if b.effects[PBEffects::Octolock] == @index
end
@effects[PBEffects::Outrage] = 0
@@ -260,7 +260,7 @@ class PokeBattle_Battler
@effects[PBEffects::Rollout] = 0
@effects[PBEffects::Roost] = false
@effects[PBEffects::SkyDrop] = -1
@battle.eachBattler do |b| # Other battlers no longer Sky Dropped by self
@battle.allBattlers.each do |b| # Other battlers no longer Sky Dropped by self
b.effects[PBEffects::SkyDrop] = -1 if b.effects[PBEffects::SkyDrop]==@index
end
@effects[PBEffects::SlowStart] = 0
@@ -281,7 +281,7 @@ class PokeBattle_Battler
@effects[PBEffects::Trapping] = 0
@effects[PBEffects::TrappingMove] = nil
@effects[PBEffects::TrappingUser] = -1
@battle.eachBattler do |b| # Other battlers no longer trapped by self
@battle.allBattlers.each do |b| # Other battlers no longer trapped by self
next if b.effects[PBEffects::TrappingUser]!=@index
b.effects[PBEffects::Trapping] = 0
b.effects[PBEffects::TrappingUser] = -1
@@ -336,7 +336,7 @@ class PokeBattle_Battler
# Update which Pokémon will gain Exp if this battler is defeated.
def pbUpdateParticipants
return if fainted? || !@battle.opposes?(@index)
eachOpposing do |b|
allOpposing.each do |b|
@participants.push(b.pokemonIndex) if !@participants.include?(b.pokemonIndex)
end
end

View File

@@ -76,10 +76,7 @@ class PokeBattle_Battler
self.statusCount = 0
# Lose happiness
if @pokemon && @battle.internalBattle
badLoss = false
@battle.eachOtherSideBattler(@index) do |b|
badLoss = true if b.level>=self.level+30
end
badLoss = @battle.allOtherSideBattlers(@index).any? { |b| b.level >= self.level + 30 }
@pokemon.changeHappiness((badLoss) ? "faintbad" : "faint")
end
# Reset form

View File

@@ -72,7 +72,7 @@ class PokeBattle_Battler
end
# Uproar immunity
if newStatus == :SLEEP && !(hasActiveAbility?(:SOUNDPROOF) && !@battle.moldBreaker)
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
next if b.effects[PBEffects::Uproar]==0
@battle.pbDisplay(_INTL("But the uproar kept {1} awake!",pbThis(true))) if showMessages
return false
@@ -108,7 +108,7 @@ class PokeBattle_Battler
if abilityActive? && BattleHandlers.triggerStatusImmunityAbility(self.ability,self,newStatus)
immuneByAbility = true
else
eachAlly do |b|
allAllies.each do |b|
next if !b.abilityActive?
next if !BattleHandlers.triggerStatusImmunityAllyAbility(b.ability,self,newStatus)
immuneByAbility = true
@@ -198,7 +198,7 @@ class PokeBattle_Battler
if abilityActive? && BattleHandlers.triggerStatusImmunityAbility(self.ability,self,newStatus)
return false
end
eachAlly do |b|
allAllies.each do |b|
next if !b.abilityActive?
next if !BattleHandlers.triggerStatusImmunityAllyAbility(b.ability,self,newStatus)
return false
@@ -285,9 +285,7 @@ class PokeBattle_Battler
return false if [:Electric, :Misty].include?(@battle.field.terrain)
end
if !hasActiveAbility?(:SOUNDPROOF)
@battle.eachBattler do |b|
return false if b.effects[PBEffects::Uproar]>0
end
return false if @battle.allBattlers.any? { |b| b.effects[PBEffects::Uproar] > 0 }
end
if BattleHandlers.triggerStatusImmunityAbilityNonIgnorable(self.ability, self, :SLEEP)
return false
@@ -298,7 +296,7 @@ class PokeBattle_Battler
if abilityActive? && BattleHandlers.triggerStatusImmunityAbility(self.ability, self, :SLEEP)
return false
end
eachAlly do |b|
allAllies.each do |b|
next if !b.abilityActive?
next if !BattleHandlers.triggerStatusImmunityAllyAbility(b.ability, self, :SLEEP)
return false
@@ -531,7 +529,7 @@ class PokeBattle_Battler
end
return false
else
eachAlly do |b|
allAllies.each do |b|
next if !b.hasActiveAbility?(:AROMAVEIL)
if showMessages
@battle.pbShowAbilitySplash(self)

View File

@@ -144,7 +144,7 @@ class PokeBattle_Battler
self.ability,self,stat,@battle,showFailMsg)
end
if !@battle.moldBreaker
eachAlly do |b|
allAllies.each do |b|
next if !b.abilityActive?
return false if BattleHandlers.triggerStatLossImmunityAllyAbility(
b.ability,b,self,stat,@battle,showFailMsg)
@@ -327,7 +327,7 @@ class PokeBattle_Battler
return false
end
end
eachAlly do |b|
allAllies.each do |b|
next if !b.abilityActive?
if BattleHandlers.triggerStatLossImmunityAllyAbility(b.ability,b,self,:ATTACK,@battle,false)
@battle.pbDisplay(_INTL("{1} is protected from {2}'s {3} by {4}'s {5}!",

View File

@@ -73,11 +73,10 @@ class PokeBattle_Battler
# up later. Essentials ignores this, and allows Trace to trigger
# whenever it can even in the old battle mechanics.
choices = []
@battle.eachOtherSideBattler(@index) do |b|
next if b.ungainableAbility? ||
[:POWEROFALCHEMY, :RECEIVER, :TRACE].include?(b.ability_id)
choices.push(b)
end
choices = @battle.allOtherSideBattlers(@index).select { |b|
next !b.ungainableAbility? &&
![:POWEROFALCHEMY, :RECEIVER, :TRACE].include?(b.ability_id)
}
if choices.length>0
choice = choices[@battle.pbRandom(choices.length)]
@battle.pbShowAbilitySplash(self)

View File

@@ -120,7 +120,7 @@ class PokeBattle_Battler
@effects[PBEffects::Charge] = 0 if @effects[PBEffects::Charge]==1
@effects[PBEffects::GemConsumed] = nil
@effects[PBEffects::ShellTrap] = false
@battle.eachBattler { |b| b.pbContinualAbilityChecks } # Trace, end primordial weathers
@battle.allBattlers.each { |b| b.pbContinualAbilityChecks } # Trace, end primordial weathers
end
def pbConfusionDamage(msg)
@@ -271,7 +271,7 @@ class PokeBattle_Battler
user.pbReducePP(move)
end
if move.pbTarget(user).affects_foe_side
@battle.eachOtherSideBattler(user) do |b|
@battle.allOtherSideBattlers(user).each do |b|
next unless b.hasActiveAbility?(:PRESSURE)
PBDebug.log("[Ability triggered] #{b.pbThis}'s #{b.abilityName}")
user.pbReducePP(move)
@@ -384,7 +384,7 @@ class PokeBattle_Battler
user.lastMoveFailed = true
else # We have targets, or move doesn't use targets
# Reset whole damage state, perform various success checks (not accuracy)
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end
@@ -499,7 +499,7 @@ class PokeBattle_Battler
user.pbFaint if user.fainted?
# External/general effects after all hits. Eject Button, Shell Bell, etc.
pbEffectsAfterMove(user,targets,move,realNumHits)
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end
@@ -509,13 +509,13 @@ class PokeBattle_Battler
# Gain Exp
@battle.pbGainExp
# Battle Arena only - update skills
@battle.eachBattler { |b| @battle.successStates[b.index].updateSkill }
@battle.allBattlers.each { |b| @battle.successStates[b.index].updateSkill }
# Shadow Pokémon triggering Hyper Mode
pbHyperMode if @battle.choices[@index][0]!=:None # Not if self is replaced
# End of move usage
pbEndTurn(choice)
# Instruct
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
next if !b.effects[PBEffects::Instruct] || !b.lastMoveUsed
b.effects[PBEffects::Instruct] = false
idxMove = -1

View File

@@ -12,7 +12,7 @@ class PokeBattle_Battler
if move.statusMove? && move.canSnatch?
newUser = nil
strength = 100
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
next if b.effects[PBEffects::Snatch]==0 ||
b.effects[PBEffects::Snatch]>=strength
next if b.effects[PBEffects::SkyDrop]>=0
@@ -49,12 +49,12 @@ class PokeBattle_Battler
pbAddTarget(targets,user,user,move,true,true)
end
when :AllAllies
@battle.eachSameSideBattler(user.index) do |b|
@battle.allSameSideBattlers(user.index).each do |b|
pbAddTarget(targets,user,b,move,false,true) if b.index != user.index
end
when :UserAndAllies
pbAddTarget(targets,user,user,move,true,true)
@battle.eachSameSideBattler(user.index) { |b| pbAddTarget(targets,user,b,move,false,true) }
@battle.allSameSideBattlers(user.index).each { |b| pbAddTarget(targets, user, b, move, false, true) }
when :NearFoe, :NearOther
targetBattler = (preTarget>=0) ? @battle.battlers[preTarget] : nil
if !pbAddTarget(targets,user,targetBattler,move)
@@ -67,7 +67,7 @@ class PokeBattle_Battler
when :RandomNearFoe
pbAddTargetRandomFoe(targets,user,move)
when :AllNearFoes
@battle.eachOtherSideBattler(user.index) { |b| pbAddTarget(targets,user,b,move) }
@battle.allOtherSideBattlers(user.index).each { |b| pbAddTarget(targets,user,b,move) }
when :Foe, :Other
targetBattler = (preTarget>=0) ? @battle.battlers[preTarget] : nil
if !pbAddTarget(targets,user,targetBattler,move,false)
@@ -78,11 +78,11 @@ class PokeBattle_Battler
end
end
when :AllFoes
@battle.eachOtherSideBattler(user.index) { |b| pbAddTarget(targets,user,b,move,false) }
@battle.allOtherSideBattlers(user.index).each { |b| pbAddTarget(targets,user,b,move,false) }
when :AllNearOthers
@battle.eachBattler { |b| pbAddTarget(targets,user,b,move) }
@battle.allBattlers.each { |b| pbAddTarget(targets, user, b, move) }
when :AllBattlers
@battle.eachBattler { |b| pbAddTarget(targets,user,b,move,false,true) }
@battle.allBattlers.each { |b| pbAddTarget(targets, user, b, move, false, true) }
else
# Used by Counter/Mirror Coat/Metal Burst/Bide
move.pbAddTarget(targets,user) # Move-specific pbAddTarget, not the def below
@@ -181,7 +181,7 @@ class PokeBattle_Battler
def pbAddTargetRandomAlly(targets, user, move, nearOnly = true)
choices = []
user.eachAlly do |b|
user.allAllies.each do |b|
next if nearOnly && !user.near?(b)
pbAddTarget(choices, user, b, move, nearOnly)
end
@@ -192,7 +192,7 @@ class PokeBattle_Battler
def pbAddTargetRandomFoe(targets, user, move, nearOnly =true)
choices = []
user.eachOpposing do |b|
user.allOpposing.each do |b|
next if nearOnly && !user.near?(b)
pbAddTarget(choices, user, b, move, nearOnly)
end

View File

@@ -76,8 +76,7 @@ class PokeBattle_Battler
return false
end
# Imprison
@battle.eachOtherSideBattler(@index) do |b|
next if !b.effects[PBEffects::Imprison] || !b.pbHasMove?(move.id)
if @battle.allOtherSideBattlers(@index).any? { |b| b.effects[PBEffects::Imprison] && b.pbHasMove?(move.id) }
if showMessages
msg = _INTL("{1} can't use its sealed {2}!",pbThis,move.name)
(commandPhase) ? @battle.pbDisplayPaused(msg) : @battle.pbDisplay(msg)

View File

@@ -140,7 +140,7 @@ class PokeBattle_Battler
end
# Room Service
if move.function == "StartSlowerBattlersActFirst" && @battle.field.effects[PBEffects::TrickRoom] > 0
@battle.battlers.each do |b|
@battle.allBattlers.each do |b|
next if !b.hasActiveItem?(:ROOMSERVICE)
next if !b.pbCanLowerStatStage?(:SPEED)
@battle.pbCommonAnimation("UseItem", b)
@@ -172,7 +172,7 @@ class PokeBattle_Battler
pbEffectsAfterMove3(user, targets, move, numHits, switched_battlers)
end
if numHits>0
@battle.eachBattler { |b| b.pbItemEndOfMoveCheck }
@battle.allBattlers.each { |b| b.pbItemEndOfMoveCheck }
end
end