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

View File

@@ -101,14 +101,11 @@ class PokeBattle_Move
def pbFailsAgainstTarget?(user, target, show_message); return false; end
def pbMoveFailedLastInRound?(user, showMessage = true)
unmoved = false
@battle.eachBattler do |b|
next if b.index==user.index
next if @battle.choices[b.index][0]!=:UseMove && @battle.choices[b.index][0]!=:Shift
next if b.movedThisRound?
unmoved = true
break
end
unmoved = @battle.allBattlers.any? { |b|
next b.index != user.index &&
[:UseMove, :Shift].include?(@battle.choices[b.index][0]) &&
!b.movedThisRound?
}
if !unmoved
@battle.pbDisplay(_INTL("But it failed!")) if showMessage
return true
@@ -140,7 +137,7 @@ class PokeBattle_Move
end
return true
end
target.eachAlly do |b|
target.allAllies.each do |b|
next if !b.hasActiveAbility?(:AROMAVEIL)
if showMessage
@battle.pbShowAbilitySplash(target)

View File

@@ -125,7 +125,7 @@ class PokeBattle_Move
BattleHandlers.triggerAccuracyCalcUserAbility(user.ability,
modifiers,user,target,self,@calcType)
end
user.eachAlly do |b|
user.allAllies.each do |b|
next if !b.abilityActive?
BattleHandlers.triggerAccuracyCalcUserAllyAbility(b.ability,
modifiers,user,target,self,@calcType)
@@ -285,7 +285,7 @@ class PokeBattle_Move
# NOTE: It's odd that the user's Mold Breaker prevents its partner's
# beneficial abilities (i.e. Flower Gift boosting Atk), but that's
# how it works.
user.eachAlly do |b|
user.allAllies.each do |b|
next if !b.abilityActive?
BattleHandlers.triggerDamageCalcUserAllyAbility(b.ability,
user,target,self,multipliers,baseDmg,type)
@@ -296,7 +296,7 @@ class PokeBattle_Move
BattleHandlers.triggerDamageCalcTargetAbilityNonIgnorable(target.ability,
user,target,self,multipliers,baseDmg,type)
end
target.eachAlly do |b|
target.allAllies.each do |b|
next if !b.abilityActive?
BattleHandlers.triggerDamageCalcTargetAllyAbility(b.ability,
user,target,self,multipliers,baseDmg,type)
@@ -327,10 +327,8 @@ class PokeBattle_Move
end
# Mud Sport
if type == :ELECTRIC
@battle.eachBattler do |b|
next if !b.effects[PBEffects::MudSport]
if @Battle.allBattlers.any? { |b| b.effects[PBEffects::MudSport] }
multipliers[:base_damage_multiplier] /= 3
break
end
if @battle.field.effects[PBEffects::MudSportField]>0
multipliers[:base_damage_multiplier] /= 3
@@ -338,10 +336,8 @@ class PokeBattle_Move
end
# Water Sport
if type == :FIRE
@battle.eachBattler do |b|
next if !b.effects[PBEffects::WaterSport]
if @Battle.allBattlers.any? { |b| b.effects[PBEffects::WaterSport] }
multipliers[:base_damage_multiplier] /= 3
break
end
if @battle.field.effects[PBEffects::WaterSportField]>0
multipliers[:base_damage_multiplier] /= 3

View File

@@ -698,7 +698,7 @@ class PokeBattle_PledgeMove < PokeBattle_Move
end
return if @pledgeCombo
# Check whether this is the setup of a combo move
user.eachAlly do |b|
user.allAllies.each do |b|
next if @battle.choices[b.index][0]!=:UseMove || b.movedThisRound?
move = @battle.choices[b.index][2]
next if !move

View File

@@ -24,12 +24,7 @@ class PokeBattle_Move_DoesNothingFailsIfNoAlly < PokeBattle_Move
def ignoresSubstitute?(user); return true; end
def pbMoveFailed?(user,targets)
hasAlly = false
user.eachAlly do |_b|
hasAlly = true
break
end
if !hasAlly
if user.allAllies.length == 0
@battle.pbDisplay(_INTL("But it failed!"))
return true
end
@@ -665,7 +660,7 @@ class PokeBattle_Move_UserSwapsPositionsWithAlly < PokeBattle_Move
numTargets = 0
@idxAlly = -1
idxUserOwner = @battle.pbGetOwnerIndexFromBattlerIndex(user.index)
user.eachAlly do |b|
user.allAllies.each do |b|
next if @battle.pbGetOwnerIndexFromBattlerIndex(b.index)!=idxUserOwner
next if !b.near?(user)
numTargets += 1

View File

@@ -1405,7 +1405,7 @@ class PokeBattle_Move_RaiseUserAndAlliesAtkDef1 < PokeBattle_Move
def pbMoveFailed?(user, targets)
@validTargets = []
@battle.eachSameSideBattler(user) do |b|
@battle.allSameSideBattlers(user).each do |b|
next if b.index == user.index
next if !b.pbCanRaiseStatStage?(:ATTACK, user, self) &&
!b.pbCanRaiseStatStage?(:DEFENSE, user, self)
@@ -1454,7 +1454,7 @@ class PokeBattle_Move_RaisePlusMinusUserAndAlliesAtkSpAtk1 < PokeBattle_Move
def pbMoveFailed?(user,targets)
@validTargets = []
@battle.eachSameSideBattler(user) do |b|
@battle.allSameSideBattlers(user).each do |b|
next if !b.hasActiveAbility?([:MINUS,:PLUS])
next if !b.pbCanRaiseStatStage?(:ATTACK,user,self) &&
!b.pbCanRaiseStatStage?(:SPECIAL_ATTACK,user,self)
@@ -1509,7 +1509,7 @@ class PokeBattle_Move_RaisePlusMinusUserAndAlliesDefSpDef1 < PokeBattle_Move
def pbMoveFailed?(user,targets)
@validTargets = []
@battle.eachSameSideBattler(user) do |b|
@battle.allSameSideBattlers(user).each do |b|
next if !b.hasActiveAbility?([:MINUS,:PLUS])
next if !b.pbCanRaiseStatStage?(:DEFENSE,user,self) &&
!b.pbCanRaiseStatStage?(:SPECIAL_DEFENSE,user,self)
@@ -1554,7 +1554,7 @@ end
class PokeBattle_Move_RaiseGroundedGrassBattlersAtkSpAtk1 < PokeBattle_Move
def pbMoveFailed?(user,targets)
@validTargets = []
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
next if !b.pbHasType?(:GRASS)
next if b.airborne? || b.semiInvulnerable?
next if !b.pbCanRaiseStatStage?(:ATTACK,user,self) &&
@@ -1596,7 +1596,7 @@ end
class PokeBattle_Move_RaiseGrassBattlersDef1 < PokeBattle_Move
def pbMoveFailed?(user,targets)
@validTargets = []
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
next if !b.pbHasType?(:GRASS)
next if b.semiInvulnerable?
next if !b.pbCanRaiseStatStage?(:DEFENSE,user,self)
@@ -1788,12 +1788,7 @@ end
#===============================================================================
class PokeBattle_Move_ResetAllBattlersStatStages < PokeBattle_Move
def pbMoveFailed?(user,targets)
failed = true
@battle.eachBattler do |b|
failed = false if b.hasAlteredStatStages?
break if !failed
end
if failed
if @battle.allBattlers.none? { |b| b.hasAlteredStatStages? }
@battle.pbDisplay(_INTL("But it failed!"))
return true
end
@@ -1801,7 +1796,7 @@ class PokeBattle_Move_ResetAllBattlersStatStages < PokeBattle_Move
end
def pbEffectGeneral(user)
@battle.eachBattler { |b| b.pbResetStatStages }
@battle.allBattlers.each { |b| b.pbResetStatStages }
@battle.pbDisplay(_INTL("All stat changes were eliminated!"))
end
end

View File

@@ -342,20 +342,11 @@ class PokeBattle_Move_CureUserPartyStatus < PokeBattle_Move
def worksWithNoTargets?; return true; end
def pbMoveFailed?(user,targets)
failed = true
@battle.eachSameSideBattler(user) do |b|
next if b.status == :NONE
failed = false
break
has_effect = @battle.allSameSideBattlers(user).any? { |b| b.status != :NONE }
if !has_effect
has_effect = @battle.pbParty(user.index).any? { |pkmn| pkmn && pkmn.able? && pkmn.status != :NONE }
end
if failed
@battle.pbParty(user.index).each do |pkmn|
next if !pkmn || !pkmn.able? || pkmn.status == :NONE
failed = false
break
end
end
if failed
if !has_effect
@battle.pbDisplay(_INTL("But it failed!"))
return true
end
@@ -398,9 +389,8 @@ class PokeBattle_Move_CureUserPartyStatus < PokeBattle_Move
# Cure all Pokémon in battle on the user's side. For the benefit of the Gen
# 5 version of this move, to make Pokémon out in battle get cured first.
if pbTarget(user) == :UserSide
@battle.eachSameSideBattler(user) do |b|
next if b.status == :NONE
pbAromatherapyHeal(b.pokemon,b)
@battle.allSameSideBattlers(user).each do |b|
pbAromatherapyHeal(b.pokemon, b) if b.status != :NONE
end
end
# Cure all Pokémon in the user's and partner trainer's party.
@@ -1237,7 +1227,7 @@ class PokeBattle_Move_StartGravity < PokeBattle_Move
def pbEffectGeneral(user)
@battle.field.effects[PBEffects::Gravity] = 5
@battle.pbDisplay(_INTL("Gravity intensified!"))
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
showMessage = false
if b.inTwoTurnAttack?("TwoTurnAttackInvulnerableInSky",
"TwoTurnAttackInvulnerableInSkyParalyzeTarget",

View File

@@ -141,7 +141,7 @@ end
class PokeBattle_Move_DamageTargetAlly < PokeBattle_Move
def pbEffectWhenDealingDamage(user,target)
hitAlly = []
target.eachAlly do |b|
target.allAllies.each do |b|
next if !b.near?(target.index)
next if !b.takesIndirectDamage?
hitAlly.push([b.index,b.hp])
@@ -711,8 +711,7 @@ class PokeBattle_Move_StartWeakenElectricMoves < PokeBattle_Move
return true
end
else
@battle.eachBattler do |b|
next if !b.effects[PBEffects::MudSport]
if @battle.allBattlers.any? { |b| b.effects[PBEffects::MudSport] }
@battle.pbDisplay(_INTL("But it failed!"))
return true
end
@@ -741,8 +740,7 @@ class PokeBattle_Move_StartWeakenFireMoves < PokeBattle_Move
return true
end
else
@battle.eachBattler do |b|
next if !b.effects[PBEffects::WaterSport]
if @battle.allBattlers.any? { |b| b.effects[PBEffects::WaterSport] }
@battle.pbDisplay(_INTL("But it failed!"))
return true
end

View File

@@ -42,7 +42,7 @@ class PokeBattle_Move_HitTwoTimesTargetThenTargetAlly < PokeBattle_Move
def pbModifyTargets(targets, user)
return if targets.length != 1
choices = []
targets[0].eachAlly { |b| user.pbAddTarget(choices, user, b, self) }
targets[0].allAllies.each { |b| user.pbAddTarget(choices, user, b, self) }
return if choices.length == 0
idxChoice = (choices.length > 1) ? @battle.pbRandom(choices.length) : 0
user.pbAddTarget(targets, user, choices[idxChoice], self, !pbTarget(user).can_choose_distant_target?)

View File

@@ -210,13 +210,7 @@ class PokeBattle_Move_HealUserAndAlliesQuarterOfTotalHP < PokeBattle_Move
def healingMove?; return true; end
def pbMoveFailed?(user, targets)
failed = true
@battle.eachSameSideBattler(user) do |b|
next if !b.canHeal?
failed = false
break
end
if failed
if @battle.allSameSideBattlers(user).none? { |b| b.canHeal? }
@battle.pbDisplay(_INTL("But it failed!"))
return true
end
@@ -241,13 +235,7 @@ class PokeBattle_Move_HealUserAndAlliesQuarterOfTotalHPCureStatus < PokeBattle_M
def healingMove?; return true; end
def pbMoveFailed?(user, targets)
failed = true
@battle.eachSameSideBattler(user) do |b|
next if b.status == :NONE && !b.canHeal?
failed = false
break
end
if failed
if @battle.allSameSideBattlers(user).none? { |b| b.canHeal? || b.status != :NONE }
@battle.pbDisplay(_INTL("But it failed!"))
return true
end

View File

@@ -5,7 +5,7 @@
class PokeBattle_Move_RedirectAllMovesToUser < PokeBattle_Move
def pbEffectGeneral(user)
user.effects[PBEffects::FollowMe] = 1
user.eachAlly do |b|
user.allAllies.each do |b|
next if b.effects[PBEffects::FollowMe]<user.effects[PBEffects::FollowMe]
user.effects[PBEffects::FollowMe] = b.effects[PBEffects::FollowMe]+1
end
@@ -23,7 +23,7 @@ class PokeBattle_Move_RedirectAllMovesToTarget < PokeBattle_Move
def pbEffectAgainstTarget(user,target)
target.effects[PBEffects::Spotlight] = 1
target.eachAlly do |b|
target.allAllies.each do |b|
next if b.effects[PBEffects::Spotlight]<target.effects[PBEffects::Spotlight]
target.effects[PBEffects::Spotlight] = b.effects[PBEffects::Spotlight]+1
end
@@ -1202,7 +1202,7 @@ end
class PokeBattle_Move_StealAndUseBeneficialStatusMove < PokeBattle_Move
def pbEffectGeneral(user)
user.effects[PBEffects::Snatch] = 1
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
next if b.effects[PBEffects::Snatch]<user.effects[PBEffects::Snatch]
user.effects[PBEffects::Snatch] = b.effects[PBEffects::Snatch]+1
end

View File

@@ -455,7 +455,7 @@ class PokeBattle_Move_UsedAfterAllyRoundWithDoublePower < PokeBattle_Move
def pbEffectGeneral(user)
user.pbOwnSide.effects[PBEffects::Round] = true
user.eachAlly do |b|
user.allAllies.each do |b|
next if @battle.choices[b.index][0]!=:UseMove || b.movedThisRound?
next if @battle.choices[b.index][2].function!=@function
b.effects[PBEffects::MoveNext] = true
@@ -509,7 +509,7 @@ class PokeBattle_Move_TargetActsLast < PokeBattle_Move
end
# Target is already maximally Quashed and will move last anyway
highestQuash = 0
@battle.battlers.each do |b|
@battle.allBattlers.each do |b|
next if b.effects[PBEffects::Quash]<=highestQuash
highestQuash = b.effects[PBEffects::Quash]
end
@@ -527,7 +527,7 @@ class PokeBattle_Move_TargetActsLast < PokeBattle_Move
def pbEffectAgainstTarget(user,target)
highestQuash = 0
@battle.battlers.each do |b|
@battle.allBattlers.each do |b|
next if b.effects[PBEffects::Quash]<=highestQuash
highestQuash = b.effects[PBEffects::Quash]
end

View File

@@ -72,12 +72,7 @@ module PokeBattle_BattleCommon
else
battler = @battlers[idxBattler].pbDirectOpposing(true)
end
if battler.fainted?
battler.eachAlly do |b|
battler = b
break
end
end
battler = battler.allAllies[0] if battler.fainted?
# Messages
itemName = GameData::Item.get(ball).name
if battler.fainted?

View File

@@ -327,8 +327,7 @@ class PokeBattle_Battle
def pbAbleNonActiveCount(idxBattler=0)
party = pbParty(idxBattler)
inBattleIndices = []
eachSameSideBattler(idxBattler) { |b| inBattleIndices.push(b.pokemonIndex) }
inBattleIndices = allSameSideBattlers(idxBattler).map { |b| b.pokemonIndex }
count = 0
party.each_with_index do |pkmn,idxParty|
next if !pkmn || !pkmn.able?
@@ -343,8 +342,7 @@ class PokeBattle_Battle
end
def pbTeamAbleNonActiveCount(idxBattler = 0)
inBattleIndices = []
eachSameSideBattler(idxBattler) { |b| inBattleIndices.push(b.pokemonIndex) }
inBattleIndices = allSameSideBattlers(idxBattler).map { |b| b.pokemonIndex }
count = 0
eachInTeamFromBattlerIndex(idxBattler) do |pkmn, i|
next if !pkmn || !pkmn.able?
@@ -434,46 +432,57 @@ class PokeBattle_Battle
#=============================================================================
# Iterate through battlers
#=============================================================================
# Unused
def eachBattler
@battlers.each { |b| yield b if b && !b.fainted? }
end
def allBattlers
return @battlers.select { |b| b && !b.fainted? }
end
# Unused
def eachSameSideBattler(idxBattler=0)
idxBattler = idxBattler.index if idxBattler.respond_to?("index")
@battlers.each { |b| yield b if b && !b.fainted? && !b.opposes?(idxBattler) }
end
def allSameSideBattlers(idxBattler = 0)
idxBattler = idxBattler.index if idxBattler.respond_to?("index")
return @battlers.select { |b| b && !b.fainted? && !b.opposes?(idxBattler) }
end
# Unused
def eachOtherSideBattler(idxBattler=0)
idxBattler = idxBattler.index if idxBattler.respond_to?("index")
@battlers.each { |b| yield b if b && !b.fainted? && b.opposes?(idxBattler) }
end
def allOtherSideBattlers(idxBattler = 0)
idxBattler = idxBattler.index if idxBattler.respond_to?("index")
return @battlers.select { |b| b && !b.fainted? && b.opposes?(idxBattler) }
end
def pbSideBattlerCount(idxBattler=0)
ret = 0
eachSameSideBattler(idxBattler) { |_b| ret += 1 }
return ret
return allSameSideBattlers(idxBattler).length
end
def pbOpposingBattlerCount(idxBattler=0)
ret = 0
eachOtherSideBattler(idxBattler) { |_b| ret += 1 }
return ret
return allOtherSideBattlers(idxBattler).length
end
# This method only counts the player's Pokémon, not a partner trainer's.
def pbPlayerBattlerCount
ret = 0
eachSameSideBattler { |b| ret += 1 if b.pbOwnedByPlayer? }
return ret
return allSameSideBattlers(idxBattler).select { |b| b.pbOwnedByPlayer? }.length
end
def pbCheckGlobalAbility(abil)
eachBattler { |b| return b if b.hasActiveAbility?(abil) }
allBattlers.each { |b| return b if b.hasActiveAbility?(abil) }
return nil
end
def pbCheckOpposingAbility(abil,idxBattler=0,nearOnly=false)
eachOtherSideBattler(idxBattler) do |b|
allOtherSideBattlers(idxBattler).each do |b|
next if nearOnly && !b.near?(idxBattler)
return b if b.hasActiveAbility?(abil)
end
@@ -608,7 +617,7 @@ class PokeBattle_Battle
PBEffects::Octolock,
PBEffects::SkyDrop,
PBEffects::TrappingUser]
eachBattler do |b|
allBattlers.each do |b|
for i in effectsToSwap
next if b.effects[i]!=idxA && b.effects[i]!=idxB
b.effects[i] = (b.effects[i]==idxA) ? idxB : idxA
@@ -623,7 +632,7 @@ class PokeBattle_Battle
# Returns the battler representing the Pokémon at index idxParty in its party,
# on the same side as a battler with battler index of idxBattlerOther.
def pbFindBattler(idxParty,idxBattlerOther=0)
eachSameSideBattler(idxBattlerOther) { |b| return b if b.pokemonIndex==idxParty }
allSameSideBattlers(idxBattlerOther).each { |b| return b if b.pokemonIndex==idxParty }
return nil
end
@@ -681,7 +690,7 @@ class PokeBattle_Battle
# Returns the effective weather (note that weather effects can be negated)
def pbWeather
eachBattler { |b| return :None if b.hasActiveAbility?([:CLOUDNINE, :AIRLOCK]) }
return :None if allBattlers.any? { |b| b.hasActiveAbility?([:CLOUDNINE, :AIRLOCK]) }
return @field.weather
end
@@ -709,7 +718,7 @@ class PokeBattle_Battle
when :ShadowSky then pbDisplay(_INTL("A shadow sky appeared!"))
end
# Check for end of primordial weather, and weather-triggered form changes
eachBattler { |b| b.pbCheckFormOnWeatherChange }
allBattlers.each { |b| b.pbCheckFormOnWeatherChange }
pbEndPrimordialWeather
end
@@ -735,7 +744,7 @@ class PokeBattle_Battle
end
if @field.weather!=oldWeather
# Check for form changes caused by the weather changing
eachBattler { |b| b.pbCheckFormOnWeatherChange }
allBattlers.each { |b| b.pbCheckFormOnWeatherChange }
# Start up the default weather
pbStartWeather(nil,@field.defaultWeather) if @field.defaultWeather != :None
end
@@ -770,8 +779,8 @@ class PokeBattle_Battle
pbDisplay(_INTL("The battlefield got weird!"))
end
# Check for abilities/items that trigger upon the terrain changing
eachBattler { |b| b.pbAbilityOnTerrainChange }
eachBattler { |b| b.pbItemTerrainStatBoostCheck }
allBattlers.each { |b| b.pbAbilityOnTerrainChange }
allBattlers.each { |b| b.pbItemTerrainStatBoostCheck }
end
#=============================================================================

View File

@@ -45,7 +45,7 @@ class PokeBattle_Battle
return false if !pbCanSwitchLax?(idxBattler,idxParty,partyScene)
# Make sure another battler isn't already choosing to switch to the party
# Pokémon
eachSameSideBattler(idxBattler) do |b|
allSameSideBattlers(idxBattler).each do |b|
next if choices[b.index][0]!=:SwitchOut || choices[b.index][1]!=idxParty
partyScene.pbDisplay(_INTL("{1} has already been selected.",
pbParty(idxBattler)[idxParty].name)) if partyScene
@@ -73,7 +73,7 @@ class PokeBattle_Battle
return false
end
# Trapping abilities/items
eachOtherSideBattler(idxBattler) do |b|
allOtherSideBattlers(idxBattler).each do |b|
next if !b.abilityActive?
if BattleHandlers.triggerTrappingTargetAbility(b.ability,battler,b,self)
partyScene.pbDisplay(_INTL("{1}'s {2} prevents switching!",
@@ -81,7 +81,7 @@ class PokeBattle_Battle
return false
end
end
eachOtherSideBattler(idxBattler) do |b|
allOtherSideBattlers(idxBattler).each do |b|
next if !b.itemActive?
if BattleHandlers.triggerTrappingTargetItem(b.item,battler,b,self)
partyScene.pbDisplay(_INTL("{1}'s {2} prevents switching!",
@@ -306,11 +306,11 @@ class PokeBattle_Battle
def pbOnAllBattlersEnteringBattle
pbCalculatePriority(true)
battler_indices = []
eachBattler { |b| battler_indices.push(b.index) }
allBattlers.each { |b| battler_indices.push(b.index) }
pbOnBattlerEnteringBattle(battler_indices)
pbCalculatePriority
# Check forms are correct
eachBattler { |b| b.pbCheckForm }
allBattlers.each { |b| b.pbCheckForm }
end
# Called when one or more Pokémon switch in. Does a lot of things, including
@@ -326,7 +326,7 @@ class PokeBattle_Battle
# this resetting would prevent that from happening, so it is skipped
# and instead done earlier in def pbAttackPhaseSwitch.
if !skip_event_reset
eachBattler do |b|
allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end
@@ -370,7 +370,7 @@ class PokeBattle_Battle
break if b.pbItemOnStatDropped
break if b.pbAbilitiesOnDamageTaken
end
eachBattler do |b|
allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end
@@ -382,7 +382,7 @@ class PokeBattle_Battle
@field.effects[PBEffects::AmuletCoin] = true
end
# Update battlers' participants (who will gain Exp/EVs when a battler faints)
eachBattler { |b| b.pbUpdateParticipants }
allBattlers.each { |b| b.pbUpdateParticipants }
end
def pbMessagesOnBattlerEnteringBattle(battler)

View File

@@ -12,7 +12,7 @@ class PokeBattle_Battle
return true if battler.itemActive? &&
BattleHandlers.triggerRunFromBattleItem(battler.item,battler)
return false if battler.trappedInBattle?
eachOtherSideBattler(idxBattler) do |b|
allOtherSideBattlers(idxBattler).each do |b|
return false if b.abilityActive? &&
BattleHandlers.triggerTrappingTargetAbility(b.ability,battler,b,self)
return false if b.itemActive? &&
@@ -101,14 +101,14 @@ class PokeBattle_Battle
return 0
end
# Trapping abilities/items
eachOtherSideBattler(idxBattler) do |b|
allOtherSideBattlers(idxBattler).each do |b|
next if !b.abilityActive?
if BattleHandlers.triggerTrappingTargetAbility(b.ability,battler,b,self)
pbDisplayPaused(_INTL("{1} prevents escape with {2}!",b.pbThis,b.abilityName))
return 0
end
end
eachOtherSideBattler(idxBattler) do |b|
allOtherSideBattlers(idxBattler).each do |b|
next if !b.itemActive?
if BattleHandlers.triggerTrappingTargetItem(b.item,battler,b,self)
pbDisplayPaused(_INTL("{1} prevents escape with {2}!",b.pbThis,b.itemName))
@@ -122,7 +122,7 @@ class PokeBattle_Battle
@runCommand += 1 if !duringBattle # Make it easier to flee next time
speedPlayer = @battlers[idxBattler].speed
speedEnemy = 1
eachOtherSideBattler(idxBattler) do |b|
allOtherSideBattlers(idxBattler).each do |b|
speed = b.speed
speedEnemy = speed if speedEnemy<speed
end

View File

@@ -59,7 +59,7 @@ class PokeBattle_Battle
pbPursuit(b.index)
return if @decision>0
# Switch Pokémon
eachBattler do |b|
allBattlers.each do |b|
b.droppedBelowHalfHP = false
b.statsDropped = false
end

View File

@@ -48,7 +48,7 @@ class PokeBattle_Battle
end
@field.weather = :None
# Check for form changes caused by the weather changing
eachBattler { |b| b.pbCheckFormOnWeatherChange }
allBattlers.each { |b| b.pbCheckFormOnWeatherChange }
# Start up the default weather
pbStartWeather(nil,@field.defaultWeather) if @field.defaultWeather != :None
return if @field.weather == :None
@@ -119,12 +119,12 @@ class PokeBattle_Battle
pbDisplay(_INTL("The weirdness disappeared from the battlefield!"))
end
@field.terrain = :None
eachBattler { |b| b.pbAbilityOnTerrainChange }
allBattlers.each { |b| b.pbAbilityOnTerrainChange }
# Start up the default terrain
if @field.defaultTerrain != :None
pbStartTerrain(nil, @field.defaultTerrain, false)
eachBattler { |b| b.pbAbilityOnTerrainChange }
eachBattler { |b| b.pbItemTerrainStatBoostCheck }
allBattlers.each { |b| b.pbAbilityOnTerrainChange }
allBattlers.each { |b| b.pbItemTerrainStatBoostCheck }
end
return if @field.terrain == :None
end
@@ -152,12 +152,8 @@ class PokeBattle_Battle
next if pbSideSize(side)==1 # Only battlers on sides of size 2+ need to move
# Check if any battler on this side is near any battler on the other side
anyNear = false
eachSameSideBattler(side) do |b|
eachOtherSideBattler(b) do |otherB|
next if !nearBattlers?(otherB.index,b.index)
anyNear = true
break
end
allSameSideBattlers(side).each do |b|
anyNear = allOtherSideBattlers(b).any? { |otherB| nearBattlers?(otherB.index, b.index) }
break if anyNear
end
break if anyNear
@@ -170,7 +166,7 @@ class PokeBattle_Battle
# this code will need revising to account for that, as well as to
# add more complex code to ensure battlers will end up near each
# other.
eachSameSideBattler(side) do |b|
allSameSideBattlers(side).each do |b|
# Get the position to move to
pos = -1
case pbSideSize(side)
@@ -217,7 +213,7 @@ class PokeBattle_Battle
next if pos.effects[PBEffects::FutureSightCounter]>0
next if !@battlers[idxPos] || @battlers[idxPos].fainted? # No target
moveUser = nil
eachBattler do |b|
allBattlers.each do |b|
next if b.opposes?(pos.effects[PBEffects::FutureSightUserIndex])
next if b.pokemonIndex!=pos.effects[PBEffects::FutureSightUserPartyIndex]
moveUser = b
@@ -598,7 +594,7 @@ class PokeBattle_Battle
# Try to make Trace work, check for end of primordial weather
priority.each { |b| b.pbContinualAbilityChecks }
# Reset/count down battler-specific effects (no messages)
eachBattler do |b|
allBattlers.each do |b|
b.effects[PBEffects::BanefulBunker] = false
b.effects[PBEffects::Charge] -= 1 if b.effects[PBEffects::Charge]>0
b.effects[PBEffects::Counter] = -1

View File

@@ -1003,10 +1003,8 @@ BattleHandlers::DamageCalcUserAbility.add(:MEGALAUNCHER,
BattleHandlers::DamageCalcUserAbility.add(:MINUS,
proc { |ability,user,target,move,mults,baseDmg,type|
next if !move.specialMove?
user.eachAlly do |b|
next if !b.hasActiveAbility?([:MINUS, :PLUS])
if user.allAllies.any? { |b| b.hasActiveAbility?([:MINUS, :PLUS]) }
mults[:attack_multiplier] *= 1.5
break
end
}
)
@@ -1416,15 +1414,9 @@ BattleHandlers::TargetAbilityOnHit.add(:ANGERPOINT,
BattleHandlers::TargetAbilityOnHit.add(:COTTONDOWN,
proc { |ability, user, target, move, battle|
has_effect = false
battle.eachBattler do |b|
next if !b.pbCanLowerStatStage?(:DEFENSE, target)
has_effect = true
break
end
next if !has_effect
next if battle.allBattlers.none? { |b| b.pbCanLowerStatStage?(:DEFENSE, target) }
battle.pbShowAbilitySplash(battler)
battle.eachBattler do |b|
battle.allBattlers.each do |b|
b.pbLowerStatStageByAbility(:SPEED, 1, target, false)
end
battle.pbHideAbilitySplash(battler)
@@ -2047,7 +2039,7 @@ BattleHandlers::EORWeatherAbility.add(:SOLARPOWER,
BattleHandlers::EORHealingAbility.add(:HEALER,
proc { |ability,battler,battle|
next unless battle.pbRandom(100)<30
battler.eachAlly do |b|
battler.allAllies.each do |b|
next if b.status == :NONE
battle.pbShowAbilitySplash(battler)
oldStatus = b.status
@@ -2127,7 +2119,7 @@ BattleHandlers::EORHealingAbility.add(:SHEDSKIN,
BattleHandlers::EOREffectAbility.add(:BADDREAMS,
proc { |ability,battler,battle|
battle.eachOtherSideBattler(battler.index) do |b|
battle.allOtherSideBattlers(battler.index).each do |b|
next if !b.near?(battler) || !b.asleep?
battle.pbShowAbilitySplash(battler)
next if !b.takesIndirectDamage?(PokeBattle_SceneConstants::USE_ABILITY_SPLASH)
@@ -2228,7 +2220,7 @@ BattleHandlers::EORGainItemAbility.add(:PICKUP,
foundItem = nil
fromBattler = nil
use = 0
battle.eachBattler do |b|
battle.allBattlers.each do |b|
next if b.index==battler.index
next if b.effects[PBEffects::PickupUse]<=use
foundItem = b.effects[PBEffects::PickupItem]
@@ -2304,7 +2296,7 @@ BattleHandlers::AbilityOnSwitchIn.add(:ANTICIPATION,
type2 = battlerTypes[1] || type1
type3 = battlerTypes[2] || type2
found = false
battle.eachOtherSideBattler(battler.index) do |b|
battle.allOtherSideBattlers(battler.index).each do |b|
b.eachMove do |m|
next if m.statusMove?
if type1
@@ -2365,15 +2357,9 @@ BattleHandlers::AbilityOnSwitchIn.add(:COMATOSE,
BattleHandlers::AbilityOnSwitchIn.add(:CURIOUSMEDICINE,
proc { |ability, battler, battle|
has_effect = false
battler.eachAlly do |b|
next if !b.hasAlteredStatStages?
has_effect = true
break
end
next if !has_effect
next if battler.allAllies.none? { |b| b.hasAlteredStatStages? }
battle.pbShowAbilitySplash(battler)
battler.eachAlly do |b|
battler.allAllies.each do |b|
next if !b.hasAlteredStatStages?
b.pbResetStatStages
if PokeBattle_SceneConstants::USE_ABILITY_SPLASH
@@ -2416,7 +2402,7 @@ BattleHandlers::AbilityOnSwitchIn.add(:DESOLATELAND,
BattleHandlers::AbilityOnSwitchIn.add(:DOWNLOAD,
proc { |ability,battler,battle|
oDef = oSpDef = 0
battle.eachOtherSideBattler(battler.index) do |b|
battle.allOtherSideBattlers(battler.index).each do |b|
oDef += b.defense
oSpDef += b.spdef
end
@@ -2459,7 +2445,7 @@ BattleHandlers::AbilityOnSwitchIn.add(:FOREWARN,
next if !battler.pbOwnedByPlayer?
highestPower = 0
forewarnMoves = []
battle.eachOtherSideBattler(battler.index) do |b|
battle.allOtherSideBattlers(battler.index).each do |b|
b.eachMove do |m|
power = m.baseDamage
power = 160 if ["OHKO", "OHKOIce", "OHKOHitsUndergroundTarget"].include?(m.function)
@@ -2509,10 +2495,7 @@ BattleHandlers::AbilityOnSwitchIn.add(:FOREWARN,
BattleHandlers::AbilityOnSwitchIn.add(:FRISK,
proc { |ability,battler,battle|
next if !battler.pbOwnedByPlayer?
foes = []
battle.eachOtherSideBattler(battler.index) do |b|
foes.push(b) if b.item
end
foes = battle.allOtherSideBattlers(battler.index).select { |b| b.item }
if foes.length>0
battle.pbShowAbilitySplash(battler)
if Settings::MECHANICS_GENERATION >= 6
@@ -2573,7 +2556,7 @@ BattleHandlers::AbilityOnSwitchIn.add(:IMPOSTER,
BattleHandlers::AbilityOnSwitchIn.add(:INTIMIDATE,
proc { |ability,battler,battle|
battle.pbShowAbilitySplash(battler)
battle.eachOtherSideBattler(battler.index) do |b|
battle.allOtherSideBattlers(battler.index).each do |b|
next if !b.near?(battler)
check_item = true
if b.hasActiveAbility?(:CONTRARY)
@@ -2624,7 +2607,7 @@ BattleHandlers::AbilityOnSwitchIn.add(:NEUTRALIZINGGAS,
battle.pbShowAbilitySplash(battler, true)
battle.pbHideAbilitySplash(battler)
battle.pbDisplay(_INTL("Neutralizing gas filled the area!"))
battle.eachBattler do |b|
battle.allBattlers.each do |b|
# Slow Start - end all turn counts
b.effects[PBEffects::SlowStart] = 0
# Truant - let b move on its first turn after Neutralizing Gas disappears
@@ -2648,15 +2631,9 @@ BattleHandlers::AbilityOnSwitchIn.add(:NEUTRALIZINGGAS,
BattleHandlers::AbilityOnSwitchIn.add(:PASTELVEIL,
proc { |ability, battler, battle|
has_effect = false
battler.eachAlly do |b|
next if b.status != :POISON
has_effect = true
break
end
next if !has_effect
next if battler.allAllies.none? { |b| b.status == :POISON }
battle.pbShowAbilitySplash(battler)
battler.eachAlly do |b|
battler.allAllies.each do |b|
next if b.status != :POISON
b.pbCureStatus(PokeBattle_SceneConstants::USE_ABILITY_SPLASH)
if !PokeBattle_SceneConstants::USE_ABILITY_SPLASH

View File

@@ -58,7 +58,7 @@ class PokeBattle_AI
if idxEncoredMove>=0
scoreSum = 0
scoreCount = 0
battler.eachOpposing do |b|
battler.allOpposing.each do |b|
scoreSum += pbGetMoveScore(battler.moves[idxEncoredMove],battler,b,skill)
scoreCount += 1
end
@@ -167,7 +167,7 @@ class PokeBattle_AI
sum = 0
pkmn.moves.each do |m|
next if m.base_damage == 0
@battle.battlers[idxBattler].eachOpposing do |b|
@battle.battlers[idxBattler].allOpposing.each do |b|
bTypes = b.pbTypes(true)
sum += Effectiveness.calculate(m.type, bTypes[0], bTypes[1], bTypes[2])
end

View File

@@ -122,7 +122,7 @@ class PokeBattle_AI
if target_data.num_targets > 1
# If move affects multiple battlers and you don't choose a particular one
totalScore = 0
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
next if !@battle.pbMoveCanTarget?(user.index,b.index,target_data)
score = pbGetMoveScore(move,user,b,skill)
totalScore += ((user.opposes?(b)) ? score : -score)
@@ -135,7 +135,7 @@ class PokeBattle_AI
else
# If move affects one battler and you have to choose which one
scoresAndTargets = []
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
next if !@battle.pbMoveCanTarget?(user.index,b.index,target_data)
next if target_data.targets_foe && !user.opposes?(b)
score = pbGetMoveScore(move,user,b,skill)

View File

@@ -1157,7 +1157,7 @@ class PokeBattle_AI
when "ResetAllBattlersStatStages"
if skill>=PBTrainerAI.mediumSkill
stages = 0
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
totalStages = 0
GameData::Stat.each_battle { |s| totalStages += b.stages[s.id] }
if b.opposes?(user)
@@ -1583,7 +1583,7 @@ class PokeBattle_AI
score -= 90 if target.effects[PBEffects::HyperBeam]>0
#---------------------------------------------------------------------------
when "DamageTargetAlly"
target.eachAlly do |b|
target.allAllies.each do |b|
next if !b.near?(target)
score += 10
end
@@ -1629,7 +1629,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "UsedAfterAllyRoundWithDoublePower"
if skill>=PBTrainerAI.mediumSkill
user.eachAlly do |b|
user.allAllies.each do |b|
next if !b.pbHasMove?(move.id)
score += 20
end
@@ -1690,7 +1690,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "PowerUpAllyMove"
hasAlly = false
user.eachAlly do |b|
user.allAllies.each do |b|
hasAlly = true
score += 30
break
@@ -2252,15 +2252,9 @@ class PokeBattle_AI
if user.pbOpposingSide.effects[PBEffects::Spikes]>=3
score -= 90
else
canChoose = false
user.eachOpposing do |b|
next if !@battle.pbCanChooseNonActive?(b.index)
canChoose = true
break
end
if !canChoose
if user.allOpposing.none? { |b| @battle.pbCanChooseNonActive?(b.index) }
# Opponent can't switch in any Pokemon
score -= 90
score -= 90
else
score += 10*@battle.pbAbleNonActiveCount(user.idxOpposingSide)
score += [40,26,13][user.pbOpposingSide.effects[PBEffects::Spikes]]
@@ -2271,13 +2265,7 @@ class PokeBattle_AI
if user.pbOpposingSide.effects[PBEffects::ToxicSpikes]>=2
score -= 90
else
canChoose = false
user.eachOpposing do |b|
next if !@battle.pbCanChooseNonActive?(b.index)
canChoose = true
break
end
if !canChoose
if user.allOpposing.none? { |b| @battle.pbCanChooseNonActive?(b.index) }
# Opponent can't switch in any Pokemon
score -= 90
else
@@ -2290,13 +2278,7 @@ class PokeBattle_AI
if user.pbOpposingSide.effects[PBEffects::StealthRock]
score -= 90
else
canChoose = false
user.eachOpposing do |b|
next if !@battle.pbCanChooseNonActive?(b.index)
canChoose = true
break
end
if !canChoose
if user.allOpposing.none? { |b| @battle.pbCanChooseNonActive?(b.index) }
# Opponent can't switch in any Pokemon
score -= 90
else
@@ -2412,12 +2394,7 @@ class PokeBattle_AI
when "FailsIfTargetActed"
#---------------------------------------------------------------------------
when "RedirectAllMovesToUser"
hasAlly = false
user.eachAlly do |b|
hasAlly = true
break
end
score -= 90 if !hasAlly
score -= 90 if user.allAllies.length == 0
#---------------------------------------------------------------------------
when "StartGravity"
if @battle.field.effects[PBEffects::Gravity]>0
@@ -2538,7 +2515,7 @@ class PokeBattle_AI
when "RaisePlusMinusUserAndAlliesDefSpDef1"
hasEffect = user.statStageAtMax?(:DEFENSE) &&
user.statStageAtMax?(:SPECIAL_DEFENSE)
user.eachAlly do |b|
user.allAllies.each do |b|
next if b.statStageAtMax?(:DEFENSE) && b.statStageAtMax?(:SPECIAL_DEFENSE)
hasEffect = true
score -= b.stages[:DEFENSE]*10
@@ -2600,7 +2577,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "RaiseGroundedGrassBattlersAtkSpAtk1"
count = 0
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
if b.pbHasType?(:GRASS) && !b.airborne? &&
(!b.statStageAtMax?(:ATTACK) || !b.statStageAtMax?(:SPECIAL_ATTACK))
count += 1
@@ -2616,7 +2593,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "RaiseGrassBattlersDef1"
count = 0
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
if b.pbHasType?(:GRASS) && !b.statStageAtMax?(:DEFENSE)
count += 1
if user.opposes?(b)
@@ -2630,7 +2607,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "LowerPoisonedTargetAtkSpAtkSpd1"
count=0
@battle.eachBattler do |b|
@battle.allBattlers.each do |b|
if b.poisoned? &&
(!b.statStageAtMin?(:ATTACK) ||
!b.statStageAtMin?(:SPECIAL_ATTACK) ||
@@ -2822,7 +2799,7 @@ class PokeBattle_AI
when "RaisePlusMinusUserAndAlliesAtkSpAtk1"
hasEffect = user.statStageAtMax?(:ATTACK) &&
user.statStageAtMax?(:SPECIAL_ATTACK)
user.eachAlly do |b|
user.allAllies.each do |b|
next if b.statStageAtMax?(:ATTACK) && b.statStageAtMax?(:SPECIAL_ATTACK)
hasEffect = true
score -= b.stages[:ATTACK]*10
@@ -2931,12 +2908,7 @@ class PokeBattle_AI
when "TypeIsUserFirstType"
#---------------------------------------------------------------------------
when "RedirectAllMovesToTarget"
hasAlly = false
target.eachAlly do |b|
hasAlly = true
break
end
score -= 90 if !hasAlly
score -= 90 if user.allAllies.length == 0
#---------------------------------------------------------------------------
when "TargetUsesItsLastUsedMoveAgain"
if skill>=PBTrainerAI.mediumSkill
@@ -3098,7 +3070,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "RaiseUserAndAlliesAtkDef1"
has_ally = false
user.eachAlly do |b|
user.allAllies.each do |b|
next if !b.pbCanLowerStatStage?(:ATTACK, user) &&
!b.pbCanLowerStatStage?(:SPECIAL_ATTACK, user)
has_ally = true
@@ -3185,7 +3157,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "CannotBeRedirected"
redirection = false
user.eachOpposing do |b|
user.allOpposing.each do |b|
next if b.index == target.index
if b.effects[PBEffects::RagePowder] ||
b.effects[PBEffects::Spotlight] > 0 ||
@@ -3228,7 +3200,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "HealUserAndAlliesQuarterOfTotalHP"
ally_amt = 30
@battle.eachSameSideBattler(user.index) do |b|
@battle.allSameSideBattlers(user.index).each do |b|
if b.hp == b.totalhp || (skill >= PBTrainerAI.mediumSkill && !b.canHeal?)
score -= ally_amt / 2
elsif b.hp < b.totalhp * 3 / 4
@@ -3238,7 +3210,7 @@ class PokeBattle_AI
#---------------------------------------------------------------------------
when "HealUserAndAlliesQuarterOfTotalHPCureStatus"
ally_amt = 80 / @battle.pbSideSize(user.index)
@battle.eachSameSideBattler(user.index) do |b|
@battle.allSameSideBattlers(user.index).each do |b|
if b.hp == b.totalhp || (skill >= PBTrainerAI.mediumSkill && !b.canHeal?)
score -= ally_amt
elsif b.hp < b.totalhp * 3 / 4
@@ -3307,7 +3279,7 @@ class PokeBattle_AI
:MARANGABERRY, :PECHABERRY, :PERSIMBERRY, :PETAYABERRY,
:RAWSTBERRY, :SALACBERRY, :STARFBERRY, :WIKIBERRY
]
@battle.eachSameSideBattler(user.index) do |b|
@battle.allSameSideBattlers(user.index).each do |b|
if !b.item || !b.item.is_berry? || !b.itemActive?
score -= 100 / @battle.pbSideSize(user.index)
else
@@ -3325,7 +3297,7 @@ class PokeBattle_AI
end
end
if skill >= PBTrainerAI.highSkill
@battle.eachOtherSideBattler(user.index) do |b|
@battle.allOtherSideBattlers(user.index).each do |b|
amt = 10 / @battle.pbSideSize(target.index)
score -= amt if b.hasActiveItem?(useful_berries)
score -= amt if b.canHeal? && b.hp < b.totalhp / 3 && b.hasActiveAbility?(:CHEEKPOUCH)

View File

@@ -8,17 +8,17 @@ class PokeBattle_AI
num_targets = 0
case target_data.id
when :AllAllies
@battle.eachSameSideBattler(user) { |b| num_targets += 1 if b.index != user.index }
@battle.allSameSideBattlers(user).each { |b| num_targets += 1 if b.index != user.index }
when :UserAndAllies
@battle.eachSameSideBattler(user) { |_b| num_targets += 1 }
@battle.allSameSideBattlers(user).each { |_b| num_targets += 1 }
when :AllNearFoes
@battle.eachOtherSideBattler(user) { |b| num_targets += 1 if b.near?(user) }
@battle.allOtherSideBattlers(user).each { |b| num_targets += 1 if b.near?(user) }
when :AllFoes
@battle.eachOtherSideBattler(user) { |_b| num_targets += 1 }
@battle.allOtherSideBattlers(user).each { |_b| num_targets += 1 }
when :AllNearOthers
@battle.eachBattler { |b| num_targets += 1 if b.near?(user) }
@battle.allBattlers.each { |b| num_targets += 1 if b.near?(user) }
when :AllBattlers
@battle.eachBattler { |_b| num_targets += 1 }
@battle.allBattlers.each { |_b| num_targets += 1 }
end
return num_targets > 1
end
@@ -343,7 +343,7 @@ class PokeBattle_AI
end
end
if skill>=PBTrainerAI.mediumSkill && !moldBreaker
user.eachAlly do |b|
user.allAllies.each do |b|
next if !b.abilityActive?
BattleHandlers.triggerDamageCalcUserAllyAbility(b.ability,
user,target,move,multipliers,baseDmg,type)
@@ -365,7 +365,7 @@ class PokeBattle_AI
end
end
if skill>=PBTrainerAI.bestSkill && !moldBreaker
target.eachAlly do |b|
target.allAllies.each do |b|
next if !b.abilityActive?
BattleHandlers.triggerDamageCalcTargetAllyAbility(b.ability,
user,target,move,multipliers,baseDmg,type)
@@ -418,20 +418,16 @@ class PokeBattle_AI
# Mud Sport and Water Sport
if skill>=PBTrainerAI.mediumSkill
if type == :ELECTRIC
@battle.eachBattler do |b|
next if !b.effects[PBEffects::MudSport]
if @battle.allBattlers.any? { |b| b.effects[PBEffects::MudSport] }
multipliers[:base_damage_multiplier] /= 3
break
end
if @battle.field.effects[PBEffects::MudSportField]>0
multipliers[:base_damage_multiplier] /= 3
end
end
if type == :FIRE
@battle.eachBattler do |b|
next if !b.effects[PBEffects::WaterSport]
if @battle.allBattlers.any? { |b| b.effects[PBEffects::WaterSport] }
multipliers[:base_damage_multiplier] /= 3
break
end
if @battle.field.effects[PBEffects::WaterSportField]>0
multipliers[:base_damage_multiplier] /= 3
@@ -645,7 +641,7 @@ class PokeBattle_AI
BattleHandlers.triggerAccuracyCalcUserAbility(user.ability,
modifiers,user,target,move,type)
end
user.eachAlly do |b|
user.allAllies.each do |b|
next if !b.abilityActive?
BattleHandlers.triggerAccuracyCalcUserAllyAbility(b.ability,
modifiers,user,target,move,type)

View File

@@ -103,9 +103,7 @@ BallHandlers::ModifyCatchRate.add(:FASTBALL,proc { |ball,catchRate,battle,battle
BallHandlers::ModifyCatchRate.add(:LEVELBALL,proc { |ball,catchRate,battle,battler,ultraBeast|
maxlevel = 0
battle.eachSameSideBattler do |b|
maxlevel = b.level if b.level>maxlevel
end
battle.allSameSideBattlers.each { |b| maxlevel = b.level if b.level > maxlevel }
if maxlevel >= battler.level * 4
catchRate *= 8
elsif maxlevel >= battler.level * 2
@@ -149,7 +147,7 @@ BallHandlers::ModifyCatchRate.add(:HEAVYBALL,proc { |ball,catchRate,battle,battl
})
BallHandlers::ModifyCatchRate.add(:LOVEBALL,proc { |ball,catchRate,battle,battler,ultraBeast|
battle.eachSameSideBattler do |b|
battle.allSameSideBattlers.each do |b|
next if b.species!=battler.species
next if b.gender==battler.gender || b.gender==2 || battler.gender==2
catchRate *= 8

View File

@@ -281,7 +281,7 @@ class PokeBattle_Scene
when 4 # Use on opposing battler (Poké Balls)
idxTarget = -1
if @battle.pbOpposingBattlerCount(idxBattler)==1
@battle.eachOtherSideBattler(idxBattler) { |b| idxTarget = b.index }
@battle.allOtherSideBattlers(idxBattler).each { |b| idxTarget = b.index }
break if yield item.id, useType, idxTarget, -1, itemScene
else
wasTargeting = true
@@ -351,12 +351,12 @@ class PokeBattle_Scene
def pbFirstTarget(idxBattler,target_data)
case target_data.id
when :NearAlly
@battle.eachSameSideBattler(idxBattler) do |b|
@battle.allSameSideBattlers(idxBattler).each do |b|
next if b.index==idxBattler || !@battle.nearBattlers?(b,idxBattler)
next if b.fainted?
return b.index
end
@battle.eachSameSideBattler(idxBattler) do |b|
@battle.allSameSideBattlers(idxBattler).each do |b|
next if b.index==idxBattler || !@battle.nearBattlers?(b,idxBattler)
return b.index
end

View File

@@ -166,7 +166,7 @@ class PokeBattle_BattlePalace < PokeBattle_Battle
def pbEndOfRoundPhase
super
return if @decision != 0
eachBattler { |b| pbPinchChange(b) }
allBattlers.each { |b| pbPinchChange(b) }
end
end

View File

@@ -65,10 +65,9 @@ class PokeBattle_DebugSceneNoLogging
end
def pbChooseTarget(idxBattler,target_data,visibleSprites=nil)
targets = []
@battle.eachOtherSideBattler(idxBattler) { |b| targets.push(b.index) }
targets = @battle.allOtherSideBattlers(idxBattler).map { |b| b.index }
return -1 if targets.length==0
return targets[rand(targets.length)]
return targets.sample
end
def pbPartyScreen(idxBattler,canCancel=false)

View File

@@ -279,13 +279,7 @@ ItemHandlers::CanUseInBattle.add(:DIREHIT3,proc { |item,pokemon,battler,move,fir
})
ItemHandlers::CanUseInBattle.add(:POKEFLUTE,proc { |item,pokemon,battler,move,firstAction,battle,scene,showMessages|
anyAsleep = false
battle.eachBattler do |b|
next if b.status != :SLEEP || b.hasActiveAbility?(:SOUNDPROOF)
anyAsleep = true
break
end
if !anyAsleep
if battle.allBattlers.none? { |b| b.status == :SLEEP && !b.hasActiveAbility?(:SOUNDPROOF) }
scene.pbDisplay(_INTL("It won't have any effect.")) if showMessages
next false
end
@@ -310,9 +304,8 @@ ItemHandlers::UseInBattle.add(:POKEDOLL,proc { |item,battler,battle|
ItemHandlers::UseInBattle.copy(:POKEDOLL,:FLUFFYTAIL,:POKETOY)
ItemHandlers::UseInBattle.add(:POKEFLUTE,proc { |item,battler,battle|
battle.eachBattler do |b|
next if b.status != :SLEEP || b.hasActiveAbility?(:SOUNDPROOF)
b.pbCureStatus(false)
battle.allBattlers.each do |b|
b.pbCureStatus(false) if b.status == :SLEEP && !b.hasActiveAbility?(:SOUNDPROOF)
end
battle.pbDisplay(_INTL("All Pokémon were roused by the tune!"))
})

View File

@@ -317,13 +317,7 @@ ItemHandlers::BattleUseOnBattler.add(:VIVIDSCENT,proc { |item,battler,scene|
#===============================================================================
class PokeBattle_Move_AllBattlersLoseHalfHPUserSkipsNextTurn < PokeBattle_Move
def pbMoveFailed?(user,targets)
failed = true
@battle.eachBattler do |b|
next if b.hp==1
failed = false
break
end
if failed
if @battle.allBattlers.none? { |b| b.hp > 1 }
@battle.pbDisplay(_INTL("But it failed!"))
return true
end
@@ -331,12 +325,11 @@ class PokeBattle_Move_AllBattlersLoseHalfHPUserSkipsNextTurn < PokeBattle_Move
end
def pbEffectGeneral(user)
@battle.eachBattler do |b|
next if b.hp==1
b.pbReduceHP(b.hp / 2, false)
@battle.allBattlers.each do |b|
b.pbReduceHP(b.hp / 2, false) if b.hp > 1
end
@battle.pbDisplay(_INTL("Each Pokémon's HP was halved!"))
@battle.eachBattler { |b| b.pbItemHPHealCheck }
@battle.allBattlers.each { |b| b.pbItemHPHealCheck }
user.effects[PBEffects::HyperBeam] = 2
user.currentMove = @id
end