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

@@ -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