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

@@ -197,12 +197,8 @@ class BattleChallengeData
end
def setParty(value)
if @inProgress
$player.party = value
@party = value
else
@party = value
end
$player.party = value if @inProgress
@party = value
end
def pbStart(t, numRounds)

View File

@@ -87,7 +87,7 @@ def pbOrganizedBattleEx(opponent, challengedata, endspeech, endspeechwin)
end
# Save the record of the battle
$game_temp.last_battle_record = nil
if decision == 1 || decision == 2 || decision == 5 # if win, loss or draw
if [1, 2, 5].include?(decision) # if win, loss or draw
$game_temp.last_battle_record = battle.pbDumpRecord
end
case decision

View File

@@ -104,9 +104,10 @@ class BattleSwapScene
def pbUpdateChoices(choices)
commands = pbGetCommands(@rentals, choices)
@choices = choices
if choices.length == 0
case choices.length
when 0
@sprites["help"].text = _INTL("Choose the first Pokémon.")
elsif choices.length == 1
when 1
@sprites["help"].text = _INTL("Choose the second Pokémon.")
else
@sprites["help"].text = _INTL("Choose the third Pokémon.")
@@ -162,9 +163,10 @@ class BattleSwapScreen
end
commands.push(_INTL("OTHERS"))
command = @scene.pbShowCommands(commands)
if command == 0
case command
when 0
@scene.pbSummary(rentals, index)
elsif command == 1
when 1
if chosen.include?(index)
chosen.delete(index)
@scene.pbUpdateChoices(chosen.clone)
@@ -194,9 +196,10 @@ class BattleSwapScreen
if pkmn >= 0
commands = [_INTL("SUMMARY"), _INTL("SWAP"), _INTL("RECHOOSE")]
command = @scene.pbShowCommands(commands)
if command == 0
case command
when 0
@scene.pbSummary(currentPokemon, pkmn)
elsif command == 1
when 1
@scene.pbSwapChosen(pkmn)
yourPkmn = pkmn
loop do

View File

@@ -4,7 +4,7 @@ class BugContestState
attr_accessor :lastPokemon
attr_reader :timer
ContestantNames = [
CONTESTANT_NAMES = [
_INTL("Bug Catcher Ed"),
_INTL("Bug Catcher Benny"),
_INTL("Bug Catcher Josh"),
@@ -14,7 +14,7 @@ class BugContestState
_INTL("Picnicker Cindy"),
_INTL("Youngster Samuel")
]
TimerSeconds = Settings::BUG_CONTEST_TIME
TIME_ALLOWED = Settings::BUG_CONTEST_TIME
def initialize
clear
@@ -29,8 +29,8 @@ class BugContestState
def expired?
return false if !undecided?
return false if TimerSeconds <= 0
curtime = @timer + TimerSeconds * Graphics.frame_rate
return false if TIME_ALLOWED <= 0
curtime = @timer + TIME_ALLOWED * Graphics.frame_rate
curtime = [curtime - Graphics.frame_count, 0].max
return (curtime <= 0)
end
@@ -65,8 +65,8 @@ class BugContestState
@chosenPokemon = chosenpoke
end
# Reception map is handled separately from contest map since the reception map
# can be outdoors, with its own grassy patches.
# Reception map is handled separately from contest map since the reception map
# can be outdoors, with its own grassy patches.
def pbSetReception(*arg)
@reception = []
for i in arg
@@ -96,16 +96,6 @@ class BugContestState
if @lastPokemon
judgearray.push([-1, @lastPokemon.species, pbBugContestScore(@lastPokemon)])
end
@contestants = []
[5, ContestantNames.length].min.times do
loop do
value = rand(ContestantNames.length)
if !@contestants.any? { |i| i == value }
@contestants.push(value)
break
end
end
end
enctype = :BugContest
if !$PokemonEncounters.map_has_encounter_type?(@contestMap, enctype)
enctype = :Land
@@ -134,7 +124,7 @@ class BugContestState
if cont < 0
$game_variables[1] = $player.name
else
$game_variables[1] = ContestantNames[cont]
$game_variables[1] = CONTESTANT_NAMES[cont]
end
$game_variables[2] = GameData::Species.get(@places[place][1]).name
$game_variables[3] = @places[place][2]
@@ -177,13 +167,12 @@ class BugContestState
@otherparty.push($player.party[i]) if i != @chosenPokemon
end
@contestants = []
[5, ContestantNames.length].min.times do
[5, CONTESTANT_NAMES.length].min.times do
loop do
value = rand(ContestantNames.length)
if !@contestants.any? { |i| i == value }
@contestants.push(value)
break
end
value = rand(CONTESTANT_NAMES.length)
next if @contestants.include?(value)
@contestants.push(value)
break
end
end
$player.party = [chosenpkmn]
@@ -303,10 +292,10 @@ Events.onMapChange += proc { |_sender, _e|
Events.onMapSceneChange += proc { |_sender, e|
scene = e[0]
if pbInBugContest? && pbBugContestState.decision == 0 && BugContestState::TimerSeconds > 0
if pbInBugContest? && pbBugContestState.decision == 0 && BugContestState::TIME_ALLOWED > 0
scene.spriteset.addUserSprite(TimerDisplay.new(
pbBugContestState.timer,
BugContestState::TimerSeconds * Graphics.frame_rate))
BugContestState::TIME_ALLOWED * Graphics.frame_rate))
end
}
@@ -373,7 +362,7 @@ def pbBugContestBattle(species, level)
pbBattleAnimation(pbGetWildBattleBGM(foeParty), 0, foeParty) {
decision = battle.pbStartBattle
pbAfterBattle(decision, true)
if decision == 2 || decision == 5 # Lost or drew
if [2, 5].include?(decision) # Lost or drew
$game_system.bgm_unpause
$game_system.bgs_unpause
pbBugContestStartOver

View File

@@ -57,9 +57,10 @@ end
def withRestr(_rule, minbs, maxbs, legendary)
ret = PokemonChallengeRules.new.addPokemonRule(BaseStatRestriction.new(minbs, maxbs))
if legendary == 0
case legendary
when 0
ret.addPokemonRule(NonlegendaryRestriction.new)
elsif legendary == 1
when 1
ret.addPokemonRule(InverseRestriction.new(NonlegendaryRestriction.new))
end
return ret
@@ -298,14 +299,16 @@ def pbWriteCup(id, rules)
else
cmd = pbMessage(_INTL("Generate Pokémon teams for this challenge?"),
[_INTL("YES"), _INTL("NO")], 2)
if cmd == 0
case cmd
when 0
cmd = 2
elsif cmd == 1
when 1
cmd = 0
end
end
return if cmd == 0 # No
if cmd == 1 # Yes, use existing
case cmd
when 1 # Yes, use existing
cmd = pbMessage(_INTL("Choose a challenge."), list, -1)
if cmd >= 0
pbMessage(_INTL("This challenge will use the Pokémon list from {1}.", list[cmd]))
@@ -321,7 +324,7 @@ def pbWriteCup(id, rules)
Compiler.write_trainer_lists
end
return
elsif cmd == 2 # Yes, use new
when 2 # Yes, use new
return if !pbConfirmMessage(_INTL("This may take a long time. Are you sure?"))
mw = pbCreateMessageWindow
t = Time.now

View File

@@ -159,7 +159,7 @@ def pbRandomPokemonFromRule(rules, trainer)
r = rand(20)
bst = baseStatTotal(species)
next if level < minimumLevel(species)
if iteration % 2 == 0
if iteration.even?
next if r < 16 && bst < 400
next if r < 13 && bst < 500
else
@@ -339,7 +339,7 @@ def pbRandomPokemonFromRule(rules, trainer)
break
end
end
if item == :LIGHTCLAY && !moves.any? { |m| m == :LIGHTSCREEN || m == :REFLECT }
if item == :LIGHTCLAY && !moves.any? { |m| [:LIGHTSCREEN, :REFLECT].include?(m) }
item = :LEFTOVERS
end
if item == :BLACKSLUDGE

View File

@@ -60,7 +60,7 @@ class RuledTeam
def updateRating
@totalGames = 0 if !@totalGames
oldgames = self.games
@history.updateAndClear()
@history.updateAndClear
newgames = self.games
@totalGames += (oldgames - newgames)
end
@@ -420,10 +420,11 @@ def pbRuledBattle(team1, team2, rule)
p.item = items2[i]
end
end
if decision == 1 # Team 1 wins
case decision
when 1 # Team 1 wins
team1.addMatch(team2, 1)
team2.addMatch(team1, 0)
elsif decision == 2 # Team 2 wins
when 2 # Team 2 wins
team1.addMatch(team2, 0)
team2.addMatch(team1, 1)
else