Yet more Rubocopping

This commit is contained in:
Maruno17
2021-12-23 00:27:17 +00:00
parent 514fe13ca2
commit 132a16950d
171 changed files with 1455 additions and 1647 deletions

View File

@@ -321,7 +321,7 @@ class Battle
def pbAbleCount(idxBattler = 0)
party = pbParty(idxBattler)
count = 0
party.each { |pkmn| count += 1 if pkmn && pkmn.able? }
party.each { |pkmn| count += 1 if pkmn&.able? }
return count
end

View File

@@ -465,11 +465,11 @@ class Battle
end
infected.each do |idxParty|
strain = $player.party[idxParty].pokerusStrain
if idxParty > 0 && $player.party[idxParty - 1].pokerusStage == 0
$player.party[idxParty - 1].givePokerus(strain) if rand(3) == 0 # 33%
if idxParty > 0 && $player.party[idxParty - 1].pokerusStage == 0 && rand(3) == 0 # 33%
$player.party[idxParty - 1].givePokerus(strain)
end
if idxParty < $player.party.length - 1 && $player.party[idxParty + 1].pokerusStage == 0
$player.party[idxParty + 1].givePokerus(strain) if rand(3) == 0 # 33%
if idxParty < $player.party.length - 1 && $player.party[idxParty + 1].pokerusStage == 0 && rand(3) == 0 # 33%
$player.party[idxParty + 1].givePokerus(strain)
end
end
end

View File

@@ -11,13 +11,13 @@ class Battle
expAll = $player.has_exp_all || $bag.has?(:EXPALL)
p1 = pbParty(0)
@battlers.each do |b|
next unless b && b.opposes? # Can only gain Exp from fainted foes
next unless b&.opposes? # Can only gain Exp from fainted foes
next if b.participants.length == 0
next unless b.fainted? || b.captured
# Count the number of participants
numPartic = 0
b.participants.each do |partic|
next unless p1[partic] && p1[partic].able? && pbIsOwner?(0, partic)
next unless p1[partic]&.able? && pbIsOwner?(0, partic)
numPartic += 1
end
# Find which Pokémon have an Exp Share
@@ -199,7 +199,7 @@ class Battle
if curLevel > newLevel
# Gained all the Exp now, end the animation
pkmn.calc_stats
battler.pbUpdate(false) if battler
battler&.pbUpdate(false)
@scene.pbRefreshOne(battler.index) if battler
break
end
@@ -211,11 +211,11 @@ class Battle
oldSpAtk = pkmn.spatk
oldSpDef = pkmn.spdef
oldSpeed = pkmn.speed
if battler && battler.pokemon
if battler&.pokemon
battler.pokemon.changeHappiness("levelup")
end
pkmn.calc_stats
battler.pbUpdate(false) if battler
battler&.pbUpdate(false)
@scene.pbRefreshOne(battler.index) if battler
pbDisplayPaused(_INTL("{1} grew to Lv. {2}!", pkmn.name, curLevel))
@scene.pbLevelUp(pkmn, battler, oldTotalHP, oldAttack, oldDefense,
@@ -260,7 +260,7 @@ class Battle
pbDisplayPaused(_INTL("1, 2, and... ... ... Ta-da!")) { pbSEPlay("Battle ball drop") }
pbDisplayPaused(_INTL("{1} forgot how to use {2}. And...", pkmnName, oldMoveName))
pbDisplay(_INTL("{1} learned {2}!", pkmnName, moveName)) { pbSEPlay("Pkmn move learnt") }
battler.pbCheckFormOnMovesetChange if battler
battler&.pbCheckFormOnMovesetChange
break
elsif pbDisplayConfirm(_INTL("Give up on learning {1}?", moveName))
pbDisplay(_INTL("{1} did not learn {2}.", pkmnName, moveName))

View File

@@ -12,7 +12,7 @@ class Battle
return false if idxParty >= party.length
return false if !party[idxParty]
if party[idxParty].egg?
partyScene.pbDisplay(_INTL("An Egg can't battle!")) if partyScene
partyScene&.pbDisplay(_INTL("An Egg can't battle!"))
return false
end
if !pbIsOwner?(idxBattler, idxParty)
@@ -24,11 +24,11 @@ class Battle
return false
end
if party[idxParty].fainted?
partyScene.pbDisplay(_INTL("{1} has no energy left to battle!", party[idxParty].name)) if partyScene
partyScene&.pbDisplay(_INTL("{1} has no energy left to battle!", party[idxParty].name))
return false
end
if pbFindBattler(idxParty, idxBattler)
partyScene.pbDisplay(_INTL("{1} is already in battle!", party[idxParty].name)) if partyScene
partyScene&.pbDisplay(_INTL("{1} is already in battle!", party[idxParty].name))
return false
end
return true
@@ -45,45 +45,43 @@ class Battle
# Pokémon
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
partyScene&.pbDisplay(_INTL("{1} has already been selected.",
pbParty(idxBattler)[idxParty].name))
return false
end
# Check whether battler can switch out
battler = @battlers[idxBattler]
return true if battler.fainted?
# Ability/item effects that allow switching no matter what
if battler.abilityActive?
if Battle::AbilityEffects.triggerCertainSwitching(battler.ability, battler, self)
return true
end
if battler.abilityActive? &&
Battle::AbilityEffects.triggerCertainSwitching(battler.ability, battler, self)
return true
end
if battler.itemActive?
if Battle::ItemEffects.triggerCertainSwitching(battler.item, battler, self)
return true
end
if battler.itemActive? &&
Battle::ItemEffects.triggerCertainSwitching(battler.item, battler, self)
return true
end
# Other certain switching effects
return true if Settings::MORE_TYPE_EFFECTS && battler.pbHasType?(:GHOST)
# Other certain trapping effects
if battler.trappedInBattle?
partyScene.pbDisplay(_INTL("{1} can't be switched out!", battler.pbThis)) if partyScene
partyScene&.pbDisplay(_INTL("{1} can't be switched out!", battler.pbThis))
return false
end
# Trapping abilities/items
allOtherSideBattlers(idxBattler).each do |b|
next if !b.abilityActive?
if Battle::AbilityEffects.triggerTrappingByTarget(b.ability, battler, b, self)
partyScene.pbDisplay(_INTL("{1}'s {2} prevents switching!",
b.pbThis, b.abilityName)) if partyScene
partyScene&.pbDisplay(_INTL("{1}'s {2} prevents switching!",
b.pbThis, b.abilityName))
return false
end
end
allOtherSideBattlers(idxBattler).each do |b|
next if !b.itemActive?
if Battle::ItemEffects.triggerTrappingByTarget(b.item, battler, b, self)
partyScene.pbDisplay(_INTL("{1}'s {2} prevents switching!",
b.pbThis, b.itemName)) if partyScene
partyScene&.pbDisplay(_INTL("{1}'s {2} prevents switching!",
b.pbThis, b.itemName))
return false
end
end
@@ -119,8 +117,8 @@ class Battle
elsif !pbCanSwitch?(idxBattler, idxParty, partyScene)
next false
end
if shouldRegister
next false if idxParty < 0 || !pbRegisterSwitch(idxBattler, idxParty)
if shouldRegister && (idxParty < 0 || !pbRegisterSwitch(idxBattler, idxParty))
next false
end
ret = idxParty
next true
@@ -187,10 +185,10 @@ class Battle
switched.push(idxBattler)
else # Player's Pokémon has fainted in a wild battle
switch = false
if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
switch = (pbRun(idxBattler, true) <= 0)
else
if pbDisplayConfirm(_INTL("Use next Pokémon?"))
switch = true
else
switch = (pbRun(idxBattler, true) <= 0)
end
if switch
idxPlayerPartyNew = pbGetReplacementPokemonIndex(idxBattler) # Owner chooses

View File

@@ -56,14 +56,14 @@ class Battle
return if !item
return if !GameData::Item.get(item).consumed_after_use?
if pbOwnedByPlayer?(idxBattler)
if $bag && $bag.can_add?(item)
if $bag&.can_add?(item)
$bag.add(item)
else
raise _INTL("Couldn't return unused item to Bag somehow.")
end
else
items = pbGetOwnerItems(idxBattler)
items.push(item) if items
items&.push(item)
end
end

View File

@@ -75,24 +75,22 @@ class Battle
return 1
end
# Abilities that guarantee escape
if battler.abilityActive?
if Battle::AbilityEffects.triggerCertainEscapeFromBattle(battler.ability, battler)
pbShowAbilitySplash(battler, true)
pbHideAbilitySplash(battler)
pbSEPlay("Battle flee")
pbDisplayPaused(_INTL("You got away safely!"))
@decision = 3
return 1
end
if battler.abilityActive? &&
Battle::AbilityEffects.triggerCertainEscapeFromBattle(battler.ability, battler)
pbShowAbilitySplash(battler, true)
pbHideAbilitySplash(battler)
pbSEPlay("Battle flee")
pbDisplayPaused(_INTL("You got away safely!"))
@decision = 3
return 1
end
# Held items that guarantee escape
if battler.itemActive?
if Battle::ItemEffects.triggerCertainEscapeFromBattle(battler.item, battler)
pbSEPlay("Battle flee")
pbDisplayPaused(_INTL("{1} fled using its {2}!", battler.pbThis, battler.itemName))
@decision = 3
return 1
end
if battler.itemActive? &&
Battle::ItemEffects.triggerCertainEscapeFromBattle(battler.item, battler)
pbSEPlay("Battle flee")
pbDisplayPaused(_INTL("{1} fled using its {2}!", battler.pbThis, battler.itemName))
@decision = 3
return 1
end
# Other certain trapping effects
if battler.trappedInBattle?

View File

@@ -161,10 +161,10 @@ class Battle
next if advance
# Check for all done
priority.each do |b|
if !b.fainted? && !b.movedThisRound?
advance = true if @choices[b.index][0] == :UseMove || @choices[b.index][0] == :Shift
end
break if advance
next if b.fainted?
next if b.movedThisRound? || ![:UseMove, :Shift].include?(@choices[b.index][0])
advance = true
break
end
next if advance
# All Pokémon have moved; end the loop

View File

@@ -223,7 +223,7 @@ class Battle
if !moveUser # User isn't in battle, get it from the party
party = pbParty(pos.effects[PBEffects::FutureSightUserIndex])
pkmn = party[pos.effects[PBEffects::FutureSightUserPartyIndex]]
if pkmn && pkmn.able?
if pkmn&.able?
moveUser = Battler.new(self, pos.effects[PBEffects::FutureSightUserIndex])
moveUser.pbInitDummyPokemon(pkmn, pos.effects[PBEffects::FutureSightUserPartyIndex])
end
@@ -504,12 +504,11 @@ class Battle
b.pbItemHPHealCheck
b.pbFaint if b.fainted?
end
if perishSongUsers.length > 0
# If all remaining Pokemon fainted by a Perish Song triggered by a single side
if (perishSongUsers.find_all { |idxBattler| opposes?(idxBattler) }.length == perishSongUsers.length) ||
(perishSongUsers.find_all { |idxBattler| !opposes?(idxBattler) }.length == perishSongUsers.length)
pbJudgeCheckpoint(@battlers[perishSongUsers[0]])
end
# Judge if all remaining Pokemon fainted by a Perish Song triggered by a single side
if perishSongUsers.length > 0 &&
((perishSongUsers.find_all { |idxBattler| opposes?(idxBattler) }.length == perishSongUsers.length) ||
(perishSongUsers.find_all { |idxBattler| !opposes?(idxBattler) }.length == perishSongUsers.length))
pbJudgeCheckpoint(@battlers[perishSongUsers[0]])
end
# Check for end of battle
if @decision > 0