Many more Rubocop-inspired code improvements

This commit is contained in:
Maruno17
2021-12-18 19:06:22 +00:00
parent d17fc40a47
commit 13a238cc6a
107 changed files with 651 additions and 652 deletions

View File

@@ -11,8 +11,8 @@ class Battle
when 2
idxOther = (idxBattler + 2) % 4
when 3
return false if idxBattler == 2 || idxBattler == 3 # In middle spot already
idxOther = ((idxBattler % 2) == 0) ? 2 : 3
return false if [2, 3].include?(idxBattler) # In middle spot already
idxOther = (idxBattler.even?) ? 2 : 3
end
return false if pbGetOwnerIndexFromBattlerIndex(idxBattler) != pbGetOwnerIndexFromBattlerIndex(idxOther)
return true

View File

@@ -162,8 +162,10 @@ class Battle
allBattlers.each { |b| b.pbCheckFormOnWeatherChange }
pbEndPrimordialWeather
allBattlers.each { |b| b.pbAbilityOnTerrainChange }
allBattlers.each { |b| b.pbCheckFormOnMovesetChange }
allBattlers.each { |b| b.pbCheckFormOnStatusChange }
allBattlers.each do |b|
b.pbCheckFormOnMovesetChange
b.pbCheckFormOnStatusChange
end
end
#=============================================================================

View File

@@ -10,7 +10,6 @@ class Battle::Battler
attr_accessor :ability_id
attr_accessor :item_id
attr_accessor :moves
attr_accessor :gender
attr_accessor :attack
attr_accessor :spatk
attr_accessor :speed
@@ -739,7 +738,7 @@ class Battle::Battler
# Returns an array containing all unfainted ally Pokémon.
def allAllies
return @battle.allSameSideBattlers(@index).select { |b| b.index != @index }
return @battle.allSameSideBattlers(@index).reject { |b| b.index == @index }
end
# Yields each unfainted opposing Pokémon.

View File

@@ -234,12 +234,12 @@ class Battle::Battler
# Darmanitan - Zen Mode
if isSpecies?(:DARMANITAN) && self.ability == :ZENMODE
if @hp <= @totalhp / 2
if (@form % 2) == 0
if @form.even?
@battle.pbShowAbilitySplash(self, true)
@battle.pbHideAbilitySplash(self)
pbChangeForm(@form + 1, _INTL("{1} triggered!", abilityName))
end
elsif (@form % 2) != 0
elsif @form.odd?
@battle.pbShowAbilitySplash(self, true)
@battle.pbHideAbilitySplash(self)
pbChangeForm(@form - 1, _INTL("{1} triggered!", abilityName))

View File

@@ -72,7 +72,6 @@ class Battle::Battler
# in and not at any later times, even if a traceable ability turns
# up later. Essentials ignores this, and allows Trace to trigger
# whenever it can even in the old battle mechanics.
choices = []
choices = @battle.allOtherSideBattlers(@index).select { |b|
next !b.ungainableAbility? &&
![:POWEROFALCHEMY, :RECEIVER, :TRACE].include?(b.ability_id)

View File

@@ -22,7 +22,7 @@ class Battle::Battler
idxOther = (@index + 2) % 4
when 3
if @index != 2 && @index != 3 # If not in middle spot already
idxOther = ((@index % 2) == 0) ? 2 : 3
idxOther = (@index.even?) ? 2 : 3
end
end
if idxOther >= 0

View File

@@ -22,9 +22,10 @@ class Battle::Battler
@battle.scene.pbDamageAnimation(user)
user.pbReduceHP(user.totalhp / 4, false)
end
if target.form == 1 # Gulping Form
case target.form
when 1 # Gulping Form
user.pbLowerStatStageByAbility(:DEFENSE, 1, target, false)
elsif target.form == 2 # Gorging Form
when 2 # Gorging Form
target.pbParalyze(user) if target.pbCanParalyze?(user, false)
end
@battle.pbHideAbilitySplash(target)

View File

@@ -396,15 +396,17 @@ class Battle::Move
# Weather
case user.effectiveWeather
when :Sun, :HarshSun
if type == :FIRE
case type
when :FIRE
multipliers[:final_damage_multiplier] *= 1.5
elsif type == :WATER
when :WATER
multipliers[:final_damage_multiplier] /= 2
end
when :Rain, :HeavyRain
if type == :FIRE
case type
when :FIRE
multipliers[:final_damage_multiplier] /= 2
elsif type == :WATER
when :WATER
multipliers[:final_damage_multiplier] *= 1.5
end
when :Sandstorm

View File

@@ -490,9 +490,10 @@ class Battle::Move::CureUserPartyStatus < Battle::Move
def pbShowAnimation(id, user, targets, hitNum = 0, showAnimation = true)
super
if @id == :AROMATHERAPY
case @id
when :AROMATHERAPY
@battle.pbDisplay(_INTL("A soothing aroma wafted through the area!"))
elsif @id == :HEALBELL
when :HEALBELL
@battle.pbDisplay(_INTL("A bell chimed!"))
end
end

View File

@@ -200,7 +200,7 @@ class Battle::Scene
# Start Bag screen
itemScene = PokemonBag_Scene.new
itemScene.pbStartScene($bag, true,
Proc.new { |item|
proc { |item|
useType = GameData::Item.get(item).battle_use
next useType && useType > 0
}, false)
@@ -368,7 +368,7 @@ class Battle::Scene
when :Foe, :Other
indices = @battle.pbGetOpposingIndicesInOrder(idxBattler)
indices.each { |i| return i if !@battle.battlers[i].fainted? }
indices.each { |i| return i }
return indices.first if !indices.empty?
end
return idxBattler # Target the user initially
end
@@ -391,7 +391,7 @@ class Battle::Scene
# Update selected command
if mode == 0 # Choosing just one target, can change index
if Input.trigger?(Input::LEFT) || Input.trigger?(Input::RIGHT)
inc = ((cw.index % 2) == 0) ? -2 : 2
inc = (cw.index.even?) ? -2 : 2
inc *= -1 if Input.trigger?(Input::RIGHT)
indexLength = @battle.sideSizes[cw.index % 2] * 2
newIndex = cw.index
@@ -402,8 +402,8 @@ class Battle::Scene
cw.index = newIndex
break
end
elsif (Input.trigger?(Input::UP) && (cw.index % 2) == 0) ||
(Input.trigger?(Input::DOWN) && (cw.index % 2) == 1)
elsif (Input.trigger?(Input::UP) && cw.index.even?) ||
(Input.trigger?(Input::DOWN) && cw.index.odd?)
tryIndex = @battle.pbGetOpposingIndicesInOrder(cw.index)
tryIndex.each do |idxBattlerTry|
next if texts[idxBattlerTry].nil?

View File

@@ -479,7 +479,7 @@ class Battle::Scene::TargetMenu < Battle::Scene::MenuBase
# NOTE: Battler indexes go from left to right from the perspective of
# that side's trainer, so inc is different for each side for the
# same value of i/2.
inc = ((i % 2) == 0) ? i / 2 : numButtons - 1 - i / 2
inc = (i.even?) ? i / 2 : numButtons - 1 - i / 2
button = SpriteWrapper.new(viewport)
button.bitmap = @buttonBitmap.bitmap
button.src_rect.width = (@smallButtons) ? CMD_BUTTON_WIDTH_SMALL : @buttonBitmap.width / 2
@@ -530,7 +530,7 @@ class Battle::Scene::TargetMenu < Battle::Scene::MenuBase
if @texts[i]
sel ||= (@mode == 0 && i == @index)
sel ||= (@mode == 1)
buttonType = ((i % 2) == 0) ? 1 : 2
buttonType = (i.even?) ? 1 : 2
end
buttonType = 2 * buttonType + ((@smallButtons) ? 1 : 0)
button.src_rect.x = (sel) ? @buttonBitmap.width / 2 : 0

View File

@@ -39,7 +39,7 @@ class Battle::Scene::PokemonDataBox < SpriteWrapper
end
def initializeDataBoxGraphic(sideSize)
onPlayerSide = ((@battler.index % 2) == 0)
onPlayerSide = @battler.index.even?
# Get the data box graphic and set whether the HP numbers/Exp bar are shown
if sideSize == 1 # One Pokémon on side, use the regular dara box BG
bgFilename = ["Graphics/Pictures/Battle/databox_normal",
@@ -537,7 +537,7 @@ class Battle::Scene::BattlerSprite < RPG::Sprite
def pbSetPosition
return if !@_iconBitmap
pbSetOrigin
if (@index % 2) == 0
if @index.even?
self.z = 50 + 5 * @index / 2
else
self.z = 50 - 5 * (@index + 1) / 2

View File

@@ -34,7 +34,7 @@ class Battle::Scene::Animation::Intro < Battle::Scene::Animation
end
# Shadows
for i in 0...@battle.battlers.length
makeSlideSprite("shadow_#{i}", ((i % 2) == 0) ? 1 : -1, appearTime, PictureOrigin::Center)
makeSlideSprite("shadow_#{i}", (i.even?) ? 1 : -1, appearTime, PictureOrigin::Center)
end
# Fading blackness over whole screen
blackScreen = addNewSprite(0, 0, "Graphics/Battle animations/black_screen")
@@ -196,7 +196,7 @@ class Battle::Scene::Animation::DataBoxAppear < Battle::Scene::Animation
return if !@sprites["dataBox_#{@idxBox}"]
box = addSprite(@sprites["dataBox_#{@idxBox}"])
box.setVisible(0, true)
dir = ((@idxBox % 2) == 0) ? 1 : -1
dir = (@idxBox.even?) ? 1 : -1
box.setDelta(0, dir * Graphics.width / 2, 0)
box.moveDelta(0, 8, -dir * Graphics.width / 2, 0)
end
@@ -216,7 +216,7 @@ class Battle::Scene::Animation::DataBoxDisappear < Battle::Scene::Animation
def createProcesses
return if !@sprites["dataBox_#{@idxBox}"] || !@sprites["dataBox_#{@idxBox}"].visible
box = addSprite(@sprites["dataBox_#{@idxBox}"])
dir = ((@idxBox % 2) == 0) ? 1 : -1
dir = (@idxBox.even?) ? 1 : -1
box.moveDelta(0, 8, dir * Graphics.width / 2, 0)
box.setVisible(8, false)
end

View File

@@ -1689,12 +1689,8 @@ class Battle::AI
when "PowerHigherWithUserHeavierThanTarget"
#---------------------------------------------------------------------------
when "PowerUpAllyMove"
hasAlly = false
user.allAllies.each do |b|
hasAlly = true
score += 30
break
end
hasAlly = !user.allAllies.empty?
score += 30 if hasAlly
score -= 90 if !hasAlly
#---------------------------------------------------------------------------
when "StartWeakenElectricMoves"
@@ -1826,8 +1822,6 @@ class Battle::AI
#---------------------------------------------------------------------------
when "HitTwoTimes"
#---------------------------------------------------------------------------
when "HitTwoTimesPoisonTarget"
#---------------------------------------------------------------------------
when "HitThreeTimesPowersUpWithEachHit"
#---------------------------------------------------------------------------
when "HitTwoToFiveTimes"

View File

@@ -273,12 +273,11 @@ class Battle::AI
targetTypes = target.pbTypes(true)
mult = Effectiveness.calculate(:FLYING,
targetTypes[0], targetTypes[1], targetTypes[2])
baseDmg = (baseDmg.to_f * mult / Effectiveness::NORMAL_EFFECTIVE).round
else
mult = Effectiveness.calculate(:FLYING,
target.types[0], target.types[1], target.effects[PBEffects::Type3])
baseDmg = (baseDmg.to_f * mult / Effectiveness::NORMAL_EFFECTIVE).round
end
baseDmg = (baseDmg.to_f * mult / Effectiveness::NORMAL_EFFECTIVE).round
end
baseDmg *= 2 if skill >= PBTrainerAI.mediumSkill && target.effects[PBEffects::Minimize]
when "DoublePowerIfUserLastMoveFailed" # Stomping Tantrum
@@ -472,15 +471,17 @@ class Battle::AI
if skill >= PBTrainerAI.mediumSkill
case user.effectiveWeather
when :Sun, :HarshSun
if type == :FIRE
case type
when :FIRE
multipliers[:final_damage_multiplier] *= 1.5
elsif type == :WATER
when :WATER
multipliers[:final_damage_multiplier] /= 2
end
when :Rain, :HeavyRain
if type == :FIRE
case type
when :FIRE
multipliers[:final_damage_multiplier] /= 2
elsif type == :WATER
when :WATER
multipliers[:final_damage_multiplier] *= 1.5
end
when :Sandstorm

View File

@@ -1582,7 +1582,7 @@ Battle::AbilityEffects::DamageCalcFromTarget.add(:PUNKROCK,
Battle::AbilityEffects::DamageCalcFromTarget.add(:THICKFAT,
proc { |ability, user, target, move, mults, baseDmg, type|
mults[:base_damage_multiplier] /= 2 if type == :FIRE || type == :ICE
mults[:base_damage_multiplier] /= 2 if [:FIRE, :ICE].include?(type)
}
)

View File

@@ -726,7 +726,7 @@ Battle::ItemEffects::AccuracyCalcFromTarget.copy(:BRIGHTPOWDER, :LAXINCENSE)
Battle::ItemEffects::DamageCalcFromUser.add(:ADAMANTORB,
proc { |item, user, target, move, mults, baseDmg, type|
if user.isSpecies?(:DIALGA) && (type == :DRAGON || type == :STEEL)
if user.isSpecies?(:DIALGA) && [:DRAGON, :STEEL].include?(type)
mults[:base_damage_multiplier] *= 1.2
end
}
@@ -854,7 +854,7 @@ Battle::ItemEffects::DamageCalcFromUser.add(:GRASSGEM,
Battle::ItemEffects::DamageCalcFromUser.add(:GRISEOUSORB,
proc { |item, user, target, move, mults, baseDmg, type|
if user.isSpecies?(:GIRATINA) && (type == :DRAGON || type == :GHOST)
if user.isSpecies?(:GIRATINA) && [:DRAGON, :GHOST].include?(type)
mults[:base_damage_multiplier] *= 1.2
end
}
@@ -898,7 +898,7 @@ Battle::ItemEffects::DamageCalcFromUser.add(:LIGHTBALL,
Battle::ItemEffects::DamageCalcFromUser.add(:LUSTROUSORB,
proc { |item, user, target, move, mults, baseDmg, type|
if user.isSpecies?(:PALKIA) && (type == :DRAGON || type == :WATER)
if user.isSpecies?(:PALKIA) && [:DRAGON, :WATER].include?(type)
mults[:base_damage_multiplier] *= 1.2
end
}
@@ -1029,7 +1029,7 @@ Battle::ItemEffects::DamageCalcFromUser.add(:SOULDEW,
proc { |item, user, target, move, mults, baseDmg, type|
next if !user.isSpecies?(:LATIAS) && !user.isSpecies?(:LATIOS)
if Settings::SOUL_DEW_POWERS_UP_TYPES
mults[:final_damage_multiplier] *= 1.2 if type == :PSYCHIC || type == :DRAGON
mults[:final_damage_multiplier] *= 1.2 if [:DRAGON, :PSYCHIC].include?(type)
else
if move.specialMove? && !user.battle.rules["souldewclause"]
mults[:attack_multiplier] *= 1.5
@@ -1880,7 +1880,6 @@ Battle::ItemEffects::EndOfRoundEffect.add(:FLAMEORB,
Battle::ItemEffects::EndOfRoundEffect.add(:STICKYBARB,
proc { |item, battler, battle|
next if !battler.takesIndirectDamage?
oldHP = battler.hp
battle.scene.pbDamageAnimation(battler)
battler.pbTakeEffectDamage(battler.totalhp / 8, false) { |hp_lost|
battle.pbDisplay(_INTL("{1} is hurt by its {2}!", battler.pbThis, battler.itemName))

View File

@@ -95,17 +95,10 @@ class BattlePalaceBattle < Battle
def pbRegisterMove(idxBattler, idxMove, _showMessages = true)
this_battler = @battlers[idxBattler]
if idxMove == -2
@choices[idxBattler][0] = :UseMove # "Use move"
@choices[idxBattler][1] = -2 # "Incapable of using its power..."
@choices[idxBattler][2] = @struggle
@choices[idxBattler][3] = -1
else
@choices[idxBattler][0] = :UseMove # "Use move"
@choices[idxBattler][1] = idxMove # Index of move to be used
@choices[idxBattler][2] = this_battler.moves[idxMove] # Battle::Move object
@choices[idxBattler][3] = -1 # No target chosen yet
end
@choices[idxBattler][0] = :UseMove
@choices[idxBattler][1] = idxMove # Index of move to be used (-2="Incapable of using its power...")
@choices[idxBattler][2] = (idxMove == -2) ? @struggle : this_battler.moves[idxMove] # Battle::Move object
@choices[idxBattler][3] = -1 # No target chosen yet
end
def pbAutoFightMenu(idxBattler)

View File

@@ -17,9 +17,10 @@ class Battle::SuccessState
end
def updateSkill
if @useState == 1
case @useState
when 1
@skill = -2 if !@protected
elsif @useState == 2
when 2
if Effectiveness.super_effective?(@typeMod)
@skill = 2
elsif Effectiveness.normal?(@typeMod)

View File

@@ -6,10 +6,10 @@ module RecordedBattleModule
attr_reader :rounds
module Commands
Fight = 0
Bag = 1
Pokemon = 2
Run = 3
FIGHT = 0
BAG = 1
POKEMON = 2
RUN = 3
end
def initialize(*arg)
@@ -81,7 +81,7 @@ module RecordedBattleModule
def pbRegisterMove(idxBattler, idxMove, showMessages = true)
if super
@rounds[@roundindex][idxBattler] = [Commands::Fight, idxMove]
@rounds[@roundindex][idxBattler] = [Commands::FIGHT, idxMove]
return true
end
return false
@@ -94,19 +94,19 @@ module RecordedBattleModule
def pbRun(idxBattler, duringBattle = false)
ret = super
@rounds[@roundindex][idxBattler] = [Commands::Run, @decision]
@rounds[@roundindex][idxBattler] = [Commands::RUN, @decision]
return ret
end
def pbAutoChooseMove(idxBattler, showMessages = true)
ret = super
@rounds[@roundindex][idxBattler] = [Commands::Fight, -1]
@rounds[@roundindex][idxBattler] = [Commands::FIGHT, -1]
return ret
end
def pbRegisterSwitch(idxBattler, idxParty)
if super
@rounds[@roundindex][idxBattler] = [Commands::Pokemon, idxParty]
@rounds[@roundindex][idxBattler] = [Commands::POKEMON, idxParty]
return true
end
return false
@@ -114,7 +114,7 @@ module RecordedBattleModule
def pbRegisterItem(idxBattler, item, idxTarget = nil, idxMove = nil)
if super
@rounds[@roundindex][idxBattler] = [Commands::Bag, item, idxTarget, idxMove]
@rounds[@roundindex][idxBattler] = [Commands::BAG, item, idxTarget, idxMove]
return true
end
return false
@@ -140,10 +140,10 @@ end
#===============================================================================
module RecordedBattlePlaybackModule
module Commands
Fight = 0
Bag = 1
Pokemon = 2
Run = 3
FIGHT = 0
BAG = 1
POKEMON = 2
RUN = 3
end
def initialize(scene, battle)
@@ -206,7 +206,7 @@ module RecordedBattlePlaybackModule
next if @rounds[@roundindex][i].length == 0
pbClearChoice(i)
case @rounds[@roundindex][i][0]
when Commands::Fight
when Commands::FIGHT
if @rounds[@roundindex][i][1] == -1
pbAutoChooseMove(i, false)
else
@@ -215,11 +215,11 @@ module RecordedBattlePlaybackModule
if @rounds[@roundindex][i][2]
pbRegisterTarget(i, @rounds[@roundindex][i][2])
end
when Commands::Bag
when Commands::BAG
pbRegisterItem(i, @rounds[@roundindex][i][1], @rounds[@roundindex][i][2], @rounds[@roundindex][i][3])
when Commands::Pokemon
when Commands::POKEMON
pbRegisterSwitch(i, @rounds[@roundindex][i][1])
when Commands::Run
when Commands::RUN
@decision = @rounds[@roundindex][i][1]
end
end