mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 22:24:58 +00:00
Obsoleted battle methods that yield battlers in favour of ones that return all of them at once
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
#=============================================================================
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user