From f68e699cc97c4c14ca98ba960e35c5127ed7e8e1 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Sun, 13 Feb 2022 00:57:54 +0000 Subject: [PATCH] More Rubocop changes --- .rubocop.yml | 5 + Data/Scripts/001_Settings.rb | 2 +- .../001_Debugging/002_DebugConsole.rb | 40 +++---- .../001_Debugging/005_Deprecation.rb | 6 +- .../001_Technical/002_Files/001_FileTests.rb | 26 ++-- .../002_Files/003_HTTP_Utilities.rb | 6 +- .../001_Technical/002_RubyUtilities.rb | 10 +- .../001_Technical/003_Intl_Messages.rb | 4 +- .../001_Technical/005_PluginManager.rb | 24 ++-- Data/Scripts/001_Technical/006_RPG_Sprite.rb | 42 +++---- Data/Scripts/002_Save data/001_SaveData.rb | 18 +-- .../002_Save data/002_SaveData_Value.rb | 10 +- .../002_Save data/003_SaveData_Conversion.rb | 12 +- .../002_Save data/005_Game_SaveConversions.rb | 28 ++--- .../003_Game processing/001_StartGame.rb | 20 ++-- .../003_Game processing/002_Scene_Map.rb | 4 +- .../003_Game processing/003_Interpreter.rb | 8 +- .../004_Interpreter_Commands.rb | 2 +- .../001_Game_Temp.rb | 2 +- .../002_Game_Switches.rb | 2 +- .../004_Game classes/002_Game_System.rb | 10 +- Data/Scripts/004_Game classes/004_Game_Map.rb | 36 +++--- .../005_Game_Map_Autoscroll.rb | 12 +- .../004_Game classes/006_Game_MapFactory.rb | 4 +- .../004_Game classes/007_Game_Character.rb | 2 +- .../004_Game classes/008_Game_Event.rb | 2 +- .../004_Game classes/009_Game_Player.rb | 16 +-- .../004_Game classes/010_Game_CommonEvent.rb | 15 +-- .../004_Game classes/011_Game_Follower.rb | 4 +- .../012_Game_FollowerFactory.rb | 16 +-- .../005_Sprites/003_Sprite_Character.rb | 4 +- .../005_Sprites/009_Sprite_DynamicShadows.rb | 39 +++--- .../Scripts/005_Sprites/010_ParticleEngine.rb | 4 +- Data/Scripts/005_Sprites/011_PictureEx.rb | 11 +- .../006_Map renderer/004_TileDrawingHelper.rb | 9 +- .../002_MessageConfig.rb | 8 +- .../004_SpriteWindow.rb | 2 +- .../006_SpriteWindow_pictures.rb | 2 +- .../008_AnimatedBitmap.rb | 4 +- .../007_Objects and windows/011_Messages.rb | 18 ++- Data/Scripts/009_Scenes/001_Transitions.rb | 9 +- .../011_Battle/001_Battle/001_Battle.rb | 6 +- .../001_Battle/002_Battle_StartAndEnd.rb | 5 +- .../002_Battler/007_Battler_UseMove.rb | 2 +- .../003_Move/010_MoveEffects_Healing.rb | 4 +- .../012_MoveEffects_ChangeMoveEffect.rb | 2 +- .../011_Battle/004_Scene/001_Battle_Scene.rb | 9 +- .../004_Scene/003_Scene_ChooseCommands.rb | 4 +- .../004_Scene/004_Scene_PlayAnimations.rb | 4 +- .../004_Scene/005_Battle_Scene_Menus.rb | 4 +- .../005_AI/005_AI_Move_EffectScores.rb | 2 +- .../007_BattleAnimationPlayer.rb | 112 ++++++++---------- .../008_Battle_AbilityEffects.rb | 2 +- .../009_Battle_ItemEffects.rb | 2 +- .../010_Battle_PokeBallEffects.rb | 4 +- .../005_RecordedBattle.rb | 6 +- .../001_Overworld_Weather.rb | 2 +- .../002_Overworld_Overlays.rb | 4 +- .../001_Overworld_BattleStarting.rb | 11 +- .../012_Overworld/002_Overworld_Metadata.rb | 9 +- .../012_Overworld/004_Overworld_FieldMoves.rb | 6 +- .../012_Overworld/007_Overworld_DayCare.rb | 18 +-- .../008_Overworld_RandomDungeons.rb | 13 +- Data/Scripts/013_Items/001_Item_Utilities.rb | 35 +++--- Data/Scripts/013_Items/005_Item_PokeRadar.rb | 24 ++-- Data/Scripts/013_Items/008_PokemonBag.rb | 30 ++--- .../001_Pokemon-related/001_FormHandlers.rb | 29 +++-- .../002_ShadowPokemon_Other.rb | 21 ++-- .../001_Pokemon-related/004_PokemonStorage.rb | 24 ++-- Data/Scripts/014_Pokemon/001_Pokemon.rb | 14 +-- Data/Scripts/014_Pokemon/005_Pokemon_Owner.rb | 2 +- .../015_Trainers and player/001_Trainer.rb | 2 +- .../005_Player_Pokedex.rb | 2 +- .../001_UI_SplashesAndTitleScreen.rb | 6 +- Data/Scripts/016_UI/003_UI_Pokedex_Main.rb | 16 +-- Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb | 50 ++++---- Data/Scripts/016_UI/005_UI_Party.rb | 3 +- Data/Scripts/016_UI/006_UI_Summary.rb | 17 ++- Data/Scripts/016_UI/007_UI_Bag.rb | 25 ++-- Data/Scripts/016_UI/013_UI_Load.rb | 32 ++--- Data/Scripts/016_UI/014_UI_Save.rb | 18 +-- Data/Scripts/016_UI/015_UI_Options.rb | 6 +- Data/Scripts/016_UI/017_UI_PokemonStorage.rb | 11 +- Data/Scripts/016_UI/022_UI_PurifyChamber.rb | 29 +++-- .../017_Minigames/002_Minigame_TripleTriad.rb | 15 +-- .../017_Minigames/004_Minigame_VoltorbFlip.rb | 18 ++- .../017_Minigames/005_Minigame_Lottery.rb | 32 ++--- .../017_Minigames/007_Minigame_TilePuzzles.rb | 11 +- .../001_Battle Frontier/002_Challenge_Data.rb | 2 +- .../001_ChallengeGenerator_Data.rb | 17 +-- .../002_ChallengeGenerator_Pokemon.rb | 17 ++- .../003_ChallengeGenerator_Trainers.rb | 24 ++-- Data/Scripts/019_Utilities/001_Utilities.rb | 2 +- .../003_EditorScreens_MapConnections.rb | 10 +- .../004_EditorScreens_SpritePositioning.rb | 17 ++- .../Scripts/020_Debug/001_Editor_Utilities.rb | 11 +- .../001_AnimEditor_SceneElements.rb | 30 +++-- .../005_AnimEditor_Functions.rb | 14 +-- .../Scripts/020_Debug/002_Editor_DataTypes.rb | 10 +- .../003_Debug menus/002_Debug_MenuCommands.rb | 2 +- .../003_Debug_MenuExtraCode.rb | 17 ++- .../006_Debug_FilenameUpdater.rb | 10 +- .../007_Debug_BattleCommands.rb | 2 +- .../008_Debug_BattlePkmnCommands.rb | 15 ++- Data/Scripts/021_Compiler/001_Compiler.rb | 13 +- .../021_Compiler/002_Compiler_CompilePBS.rb | 24 ++-- .../021_Compiler/003_Compiler_WritePBS.rb | 2 +- .../004_Compiler_MapsAndEvents.rb | 76 ++++++------ 108 files changed, 708 insertions(+), 808 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a241762be..7e36688f0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -111,6 +111,11 @@ Style/HashSyntax: Style/NegatedIf: Enabled: false +# .zero?, .positive? and .negative? are more wordy than == 0, > 0 and < 0. They +# also aren't consistent with other value comparisons, e.g. x > 42. +Style/NumericPredicate: + EnforcedStyle: comparison + # Following this just means that calls to an affected method need to know what # that method calls its parameters, which is ridiculous. Keep things short and # simple. diff --git a/Data/Scripts/001_Settings.rb b/Data/Scripts/001_Settings.rb index 229df4d42..82fd9c97c 100644 --- a/Data/Scripts/001_Settings.rb +++ b/Data/Scripts/001_Settings.rb @@ -6,7 +6,7 @@ module Settings # The version of your game. It has to adhere to the MAJOR.MINOR.PATCH format. - GAME_VERSION = '1.0.0' + GAME_VERSION = "1.0.0" # The generation that the battle system follows. Used throughout the battle # scripts, and also by some other settings which are used in and out of battle diff --git a/Data/Scripts/001_Technical/001_Debugging/002_DebugConsole.rb b/Data/Scripts/001_Technical/001_Debugging/002_DebugConsole.rb index b5b7ee302..775afb84c 100644 --- a/Data/Scripts/001_Technical/001_Debugging/002_DebugConsole.rb +++ b/Data/Scripts/001_Technical/001_Debugging/002_DebugConsole.rb @@ -77,8 +77,8 @@ module Console # list item def echo_li(msg, pad = 0, color = :brown) - echo markup_style(' -> ', text: color) - pad = (pad - msg.length) > 0 ? '.' * (pad - msg.length) : '' + echo markup_style(" -> ", text: color) + pad = (pad - msg.length) > 0 ? "." * (pad - msg.length) : "" echo markup(msg + pad) end @@ -106,18 +106,18 @@ module Console # status output def echo_status(status) if status - echoln markup_style('OK', text: :green) + echoln markup_style("OK", text: :green) else - echoln markup_style('FAIL', text: :red) + echoln markup_style("FAIL", text: :red) end end # completion output def echo_done(status) if status - echoln markup_style('done', text: :green) + echoln markup_style("done", text: :green) else - echoln markup_style('error', text: :red) + echoln markup_style("error", text: :red) end end @@ -126,39 +126,39 @@ module Console #----------------------------------------------------------------------------- def string_colors { - default: '38', black: '30', red: '31', green: '32', brown: '33', - blue: '34', purple: '35', cyan: '36', gray: '37', - dark_gray: '1;30', light_red: '1;31', light_green: '1;32', yellow: '1;33', - light_blue: '1;34', light_purple: '1;35', light_cyan: '1;36', white: '1;37' + default: "38", black: "30", red: "31", green: "32", brown: "33", + blue: "34", purple: "35", cyan: "36", gray: "37", + dark_gray: "1;30", light_red: "1;31", light_green: "1;32", yellow: "1;33", + light_blue: "1;34", light_purple: "1;35", light_cyan: "1;36", white: "1;37" } end def background_colors { - default: '0', black: '40', red: '41', green: '42', brown: '43', - blue: '44', purple: '45', cyan: '46', gray: '47', - dark_gray: '100', light_red: '101', light_green: '102', yellow: '103', - light_blue: '104', light_purple: '105', light_cyan: '106', white: '107' + default: "0", black: "40", red: "41", green: "42", brown: "43", + blue: "44", purple: "45", cyan: "46", gray: "47", + dark_gray: "100", light_red: "101", light_green: "102", yellow: "103", + light_blue: "104", light_purple: "105", light_cyan: "106", white: "107" } end def font_options { - bold: '1', dim: '2', italic: '3', underline: '4', reverse: '7', - hidden: '8' + bold: "1", dim: "2", italic: "3", underline: "4", reverse: "7", + hidden: "8" } end # Text markup that turns text between them a certain color def markup_colors { - '`' => :cyan, '"' => :purple, "'" => :purple, '$' => :green, '~' => :red + "`" => :cyan, '"' => :purple, "'" => :purple, "$" => :green, "~" => :red } end def markup_options { - '__' => :underline, '*' => :bold, '|' => :italic + "__" => :underline, "*" => :bold, "|" => :italic } end @@ -169,9 +169,9 @@ module Console code_bg = background_colors[bg] # get options options_pool = options.select { |key, val| font_options.key?(key) && val } - markup_pool = options_pool.keys.map { |opt| font_options[opt] }.join(';').squeeze + markup_pool = options_pool.keys.map { |opt| font_options[opt] }.join(";").squeeze # return formatted string - "\e[#{code_bg};#{markup_pool};#{code_text}m#{string}\e[0m".squeeze(';') + "\e[#{code_bg};#{markup_pool};#{code_text}m#{string}\e[0m".squeeze(";") end #----------------------------------------------------------------------------- diff --git a/Data/Scripts/001_Technical/001_Debugging/005_Deprecation.rb b/Data/Scripts/001_Technical/001_Debugging/005_Deprecation.rb index 913459f22..ab7689d7b 100644 --- a/Data/Scripts/001_Technical/001_Debugging/005_Deprecation.rb +++ b/Data/Scripts/001_Technical/001_Debugging/005_Deprecation.rb @@ -40,11 +40,11 @@ class Module raise ArgumentError, "#{class_name} does not have method #{aliased_method} defined" end - delimiter = class_method ? '.' : '#' + delimiter = class_method ? "." : "#" target.define_method(name) do |*args, **kvargs| - alias_name = sprintf('%s%s%s', class_name, delimiter, name) - aliased_method_name = sprintf('%s%s%s', class_name, delimiter, aliased_method) + alias_name = sprintf("%s%s%s", class_name, delimiter, name) + aliased_method_name = sprintf("%s%s%s", class_name, delimiter, aliased_method) Deprecation.warn_method(alias_name, removal_in, aliased_method_name) method(aliased_method).call(*args, **kvargs) end diff --git a/Data/Scripts/001_Technical/002_Files/001_FileTests.rb b/Data/Scripts/001_Technical/002_Files/001_FileTests.rb index 92ff55426..31534e57d 100644 --- a/Data/Scripts/001_Technical/002_Files/001_FileTests.rb +++ b/Data/Scripts/001_Technical/002_Files/001_FileTests.rb @@ -56,7 +56,7 @@ class File #----------------------------------------------------------------------------- def self.safe?(file) ret = false - self.open(file, 'rb') { ret = true } rescue nil + self.open(file, "rb") { ret = true } rescue nil return ret end #----------------------------------------------------------------------------- @@ -258,8 +258,8 @@ end module FileTest - IMAGE_EXTENSIONS = ['.png', '.gif'] # '.jpg', '.jpeg', '.bmp', - AUDIO_EXTENSIONS = ['.mid', '.midi', '.ogg', '.wav', '.wma'] # '.mp3' + IMAGE_EXTENSIONS = [".png", ".gif"] # ".jpg", ".jpeg", ".bmp", + AUDIO_EXTENSIONS = [".mid", ".midi", ".ogg", ".wav", ".wma"] # ".mp3" def self.audio_exist?(filename) return RTP.exists?(filename, AUDIO_EXTENSIONS) @@ -318,7 +318,7 @@ def pbGetFileChar(file) canon_file = canonicalize(file) if !safeExists?("./Game.rgssad") return nil if !safeExists?(canon_file) - return nil if file.last == '/' # Is a directory + return nil if file.last == "/" # Is a directory begin File.open(canon_file, "rb") { |f| return f.read(1) } # read one byte rescue Errno::ENOENT, Errno::EINVAL, Errno::EACCES, Errno::EISDIR @@ -336,7 +336,7 @@ end def pbTryString(x) ret = pbGetFileChar(x) - return (ret != nil && ret != "") ? x : nil + return nil_or_empty?(ret) ? nil : x end # Gets the contents of a file. Doesn't check RTP, but does check @@ -401,7 +401,7 @@ class StringInput end def close - raise IOError, 'closed stream' if @closed + raise IOError, "closed stream" if @closed @pos = nil @closed = true end @@ -409,7 +409,7 @@ class StringInput def closed?; @closed; end def pos - raise IOError, 'closed stream' if @closed + raise IOError, "closed stream" if @closed [@pos, @string.size].min end @@ -420,7 +420,7 @@ class StringInput def pos=(value); seek(value); end def seek(offset, whence = IO::SEEK_SET) - raise IOError, 'closed stream' if @closed + raise IOError, "closed stream" if @closed case whence when IO::SEEK_SET then @pos = offset when IO::SEEK_CUR then @pos += offset @@ -434,12 +434,12 @@ class StringInput end def eof? - raise IOError, 'closed stream' if @closed + raise IOError, "closed stream" if @closed @pos > @string.size end def each(&block) - raise IOError, 'closed stream' if @closed + raise IOError, "closed stream" if @closed begin @string.each(&block) ensure @@ -448,7 +448,7 @@ class StringInput end def gets - raise IOError, 'closed stream' if @closed + raise IOError, "closed stream" if @closed idx = @string.index("\n", @pos) if idx idx += 1 # "\n".size @@ -464,7 +464,7 @@ class StringInput end def getc - raise IOError, 'closed stream' if @closed + raise IOError, "closed stream" if @closed ch = @string[@pos] @pos += 1 @pos += 1 if @pos == @string.size @@ -472,7 +472,7 @@ class StringInput end def read(len = nil) - raise IOError, 'closed stream' if @closed + raise IOError, "closed stream" if @closed if !len return nil if eof? rest = @string[@pos...@string.size] diff --git a/Data/Scripts/001_Technical/002_Files/003_HTTP_Utilities.rb b/Data/Scripts/001_Technical/002_Files/003_HTTP_Utilities.rb index b6f02864a..d989107a0 100644 --- a/Data/Scripts/001_Technical/002_Files/003_HTTP_Utilities.rb +++ b/Data/Scripts/001_Technical/002_Files/003_HTTP_Utilities.rb @@ -12,10 +12,10 @@ def pbPostData(url, postdata, filename = nil, depth = 0) body = postdata.map { |key, value| keyString = key.to_s valueString = value.to_s - keyString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf('%%%02x', s[0]) } - valueString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf('%%%02x', s[0]) } + keyString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf("%%%02x", s[0]) } + valueString.gsub!(/[^a-zA-Z0-9_\.\-]/n) { |s| sprintf("%%%02x", s[0]) } next "#{keyString}=#{valueString}" - }.join('&') + }.join("&") ret = HTTPLite.post_body( url, body, diff --git a/Data/Scripts/001_Technical/002_RubyUtilities.rb b/Data/Scripts/001_Technical/002_RubyUtilities.rb index 0e1426fd5..39e361db9 100644 --- a/Data/Scripts/001_Technical/002_RubyUtilities.rb +++ b/Data/Scripts/001_Technical/002_RubyUtilities.rb @@ -23,7 +23,7 @@ end #=============================================================================== class String def starts_with_vowel? - return ['a', 'e', 'i', 'o', 'u'].include?(self[0, 1].downcase) + return ["a", "e", "i", "o", "u"].include?(self[0, 1].downcase) end def first(n = 1); return self[0...n]; end @@ -97,7 +97,7 @@ class Hash h = self.clone # failsafe return h if !hash.is_a?(Hash) - hash.keys.each do |key| + hash.each_key do |key| if self[key].is_a?(Hash) h.deep_merge!(hash[key]) else @@ -109,7 +109,7 @@ class Hash def deep_merge!(hash) return if !hash.is_a?(Hash) - hash.keys.each do |key| + hash.each_key do |key| if self[key].is_a?(Hash) self[key].deep_merge!(hash[key]) else @@ -138,7 +138,7 @@ class File def self.copy(source, destination) data = "" t = Time.now - File.open(source, 'rb') do |f| + File.open(source, "rb") do |f| loop do r = f.read(4096) break if !r @@ -150,7 +150,7 @@ class File end end File.delete(destination) if File.file?(destination) - f = File.new(destination, 'wb') + f = File.new(destination, "wb") f.write data f.close end diff --git a/Data/Scripts/001_Technical/003_Intl_Messages.rb b/Data/Scripts/001_Technical/003_Intl_Messages.rb index 01f4d0b27..8fcfc2244 100644 --- a/Data/Scripts/001_Technical/003_Intl_Messages.rb +++ b/Data/Scripts/001_Technical/003_Intl_Messages.rb @@ -108,7 +108,7 @@ def pbSetTextMessages items.concat(choices) MessageTypes.setMapMessagesAsHash(0, items) mapinfos = pbLoadMapInfos - mapinfos.keys.each do |id| + mapinfos.each_key do |id| if Time.now.to_i - t >= 5 t = Time.now.to_i Graphics.update @@ -118,7 +118,7 @@ def pbSetTextMessages map = load_data(filename) items = [] choices = [] - map.events.values.each do |event| + map.events.each_value do |event| if Time.now.to_i - t >= 5 t = Time.now.to_i Graphics.update diff --git a/Data/Scripts/001_Technical/005_PluginManager.rb b/Data/Scripts/001_Technical/005_PluginManager.rb index 5ab2c700b..c2a8375ac 100644 --- a/Data/Scripts/001_Technical/005_PluginManager.rb +++ b/Data/Scripts/001_Technical/005_PluginManager.rb @@ -332,7 +332,7 @@ module PluginManager self.error("Invalid plugin registry key '#{key}'.") end end - @@Plugins.values.each do |plugin| + @@Plugins.each_value do |plugin| if plugin[:incompatibilities]&.include?(name) self.error("Plugin '#{plugin[:name]}' is incompatible with '#{name}'. " + "They cannot both be used at the same time.") @@ -488,14 +488,14 @@ module PluginManager raise _INTL("Bad line syntax (expected syntax like XXX=YYY)\r\n{1}", FileLineData.linereport) end property = $~[1].upcase - data = $~[2].split(',') + data = $~[2].split(",") data.each_with_index { |value, i| data[i] = value.strip } # begin formatting data hash case property - when 'ESSENTIALS' + when "ESSENTIALS" meta[:essentials] = [] if !meta[:essentials] data.each { |ver| meta[:essentials].push(ver) } - when 'REQUIRES' + when "REQUIRES" meta[:dependencies] = [] if !meta[:dependencies] if data.length < 2 # No version given, just push name of plugin dependency meta[:dependencies].push(data[0]) @@ -505,23 +505,23 @@ module PluginManager else # Push dependency type, name and version of plugin dependency meta[:dependencies].push([data[2].downcase.to_sym, data[0], data[1]]) end - when 'EXACT' + when "EXACT" next if data.length < 2 # Exact dependencies must have a version given; ignore if not meta[:dependencies] = [] if !meta[:dependencies] meta[:dependencies].push([:exact, data[0], data[1]]) - when 'OPTIONAL' + when "OPTIONAL" next if data.length < 2 # Optional dependencies must have a version given; ignore if not meta[:dependencies] = [] if !meta[:dependencies] meta[:dependencies].push([:optional, data[0], data[1]]) - when 'CONFLICTS' + when "CONFLICTS" meta[:incompatibilities] = [] if !meta[:incompatibilities] data.each { |value| meta[:incompatibilities].push(value) if value && !value.empty? } - when 'SCRIPTS' + when "SCRIPTS" meta[:scripts] = [] if !meta[:scripts] data.each { |scr| meta[:scripts].push(scr) } - when 'CREDITS' + when "CREDITS" meta[:credits] = data - when 'LINK', 'WEBSITE' + when "LINK", "WEBSITE" meta[:link] = data[0] else meta[property.downcase.to_sym] = data[0] @@ -665,7 +665,7 @@ module PluginManager dat = [o, meta, []] # iterate through each file to deflate plugins[o][:scripts].each do |file| - File.open("#{plugins[o][:dir]}/#{file}", 'rb') do |f| + File.open("#{plugins[o][:dir]}/#{file}", "rb") do |f| dat[2].push([file, Zlib::Deflate.deflate(f.read)]) end end @@ -673,7 +673,7 @@ module PluginManager scripts.push(dat) end # save to main `PluginScripts.rxdata` file - File.open("Data/PluginScripts.rxdata", 'wb') { |f| Marshal.dump(scripts, f) } + File.open("Data/PluginScripts.rxdata", "wb") { |f| Marshal.dump(scripts, f) } # collect garbage GC.start Console.echo_done(true) diff --git a/Data/Scripts/001_Technical/006_RPG_Sprite.rb b/Data/Scripts/001_Technical/006_RPG_Sprite.rb index e4b99f4dd..0b5c0cf81 100644 --- a/Data/Scripts/001_Technical/006_RPG_Sprite.rb +++ b/Data/Scripts/001_Technical/006_RPG_Sprite.rb @@ -92,7 +92,7 @@ class SpriteAnimation def dispose_animation return if @_animation_sprites.nil? sprite = @_animation_sprites[0] - if sprite != nil + if sprite @@_reference_count[sprite.bitmap] -= 1 if @@_reference_count[sprite.bitmap] == 0 sprite.bitmap.dispose @@ -108,7 +108,7 @@ class SpriteAnimation def dispose_loop_animation return if @_loop_animation_sprites.nil? sprite = @_loop_animation_sprites[0] - if sprite != nil + if sprite @@_reference_count[sprite.bitmap] -= 1 if @@_reference_count[sprite.bitmap] == 0 sprite.bitmap.dispose @@ -122,7 +122,7 @@ class SpriteAnimation end def active? - return @_loop_animation_sprites != nil || @_animation_sprites != nil + return @_loop_animation_sprites || @_animation_sprites end def effect? @@ -130,7 +130,7 @@ class SpriteAnimation end def update - if @_animation != nil + if @_animation quick_update = true if Graphics.frame_count % @_animation_frame_skip == 0 @_animation_duration -= 1 @@ -138,7 +138,7 @@ class SpriteAnimation end update_animation(quick_update) end - if @_loop_animation != nil + if @_loop_animation quick_update = (Graphics.frame_count % @_loop_animation_frame_skip != 0) update_loop_animation(quick_update) if !quick_update @@ -180,7 +180,7 @@ class SpriteAnimation sprite_x = 320 sprite_y = 240 if position == 3 - if self.viewport != nil + if self.viewport sprite_x = self.viewport.rect.width / 2 sprite_y = self.viewport.rect.height - 160 end @@ -194,7 +194,7 @@ class SpriteAnimation sprite = sprites[i] pattern = cell_data[i, 0] if sprite.nil? || pattern.nil? || pattern == -1 - sprite.visible = false if sprite != nil + sprite.visible = false if sprite next end sprite.x = sprite_x + cell_data[i, 1] @@ -232,9 +232,7 @@ class SpriteAnimation when 1 self.flash(timing.flash_color, timing.flash_duration * 2) when 2 - if self.viewport != nil - self.viewport.flash(timing.flash_color, timing.flash_duration * 2) - end + self.viewport.flash(timing.flash_color, timing.flash_duration * 2) if self.viewport when 3 self.flash(nil, timing.flash_duration * 2) end @@ -244,30 +242,22 @@ class SpriteAnimation def x=(x) sx = x - self.x return if sx == 0 - if @_animation_sprites != nil - 16.times do |i| - @_animation_sprites[i].x += sx - end + if @_animation_sprites + 16.times { |i| @_animation_sprites[i].x += sx } end - if @_loop_animation_sprites != nil - 16.times do |i| - @_loop_animation_sprites[i].x += sx - end + if @_loop_animation_sprites + 16.times { |i| @_loop_animation_sprites[i].x += sx } end end def y=(y) sy = y - self.y return if sy == 0 - if @_animation_sprites != nil - 16.times do |i| - @_animation_sprites[i].y += sy - end + if @_animation_sprites + 16.times { |i| @_animation_sprites[i].y += sy } end - if @_loop_animation_sprites != nil - 16.times do |i| - @_loop_animation_sprites[i].y += sy - end + if @_loop_animation_sprites + 16.times { |i| @_loop_animation_sprites[i].y += sy } end end end diff --git a/Data/Scripts/002_Save data/001_SaveData.rb b/Data/Scripts/002_Save data/001_SaveData.rb index 43c8b10f8..6a7b76628 100644 --- a/Data/Scripts/002_Save data/001_SaveData.rb +++ b/Data/Scripts/002_Save data/001_SaveData.rb @@ -6,9 +6,9 @@ module SaveData # Contains the file path of the save file. FILE_PATH = if File.directory?(System.data_directory) - System.data_directory + '/Game.rxdata' + System.data_directory + "/Game.rxdata" else - './Game.rxdata' + "./Game.rxdata" end # @return [Boolean] whether the save file exists @@ -45,7 +45,7 @@ module SaveData save_data = get_data_from_file(file_path) save_data = to_hash_format(save_data) if save_data.is_a?(Array) if !save_data.empty? && run_conversions(save_data) - File.open(file_path, 'wb') { |file| Marshal.dump(save_data, file) } + File.open(file_path, "wb") { |file| Marshal.dump(save_data, file) } end return save_data end @@ -57,14 +57,14 @@ module SaveData def self.save_to_file(file_path) validate file_path => String save_data = self.compile_save_hash - File.open(file_path, 'wb') { |file| Marshal.dump(save_data, file) } + File.open(file_path, "wb") { |file| Marshal.dump(save_data, file) } end # Deletes the save file (and a possible .bak backup file if one exists) # @raise [Error::ENOENT] def self.delete_file File.delete(FILE_PATH) - File.delete(FILE_PATH + '.bak') if File.file?(FILE_PATH + '.bak') + File.delete(FILE_PATH + ".bak") if File.file?(FILE_PATH + ".bak") end # Converts the pre-v19 format data to the new format. @@ -85,12 +85,12 @@ module SaveData # already exists in {FILE_PATH}. def self.move_old_windows_save return if File.file?(FILE_PATH) - game_title = System.game_title.gsub(/[^\w ]/, '_') - home = ENV['HOME'] || ENV['HOMEPATH'] + game_title = System.game_title.gsub(/[^\w ]/, "_") + home = ENV["HOME"] || ENV["HOMEPATH"] return if home.nil? - old_location = File.join(home, 'Saved Games', game_title) + old_location = File.join(home, "Saved Games", game_title) return unless File.directory?(old_location) - old_file = File.join(old_location, 'Game.rxdata') + old_file = File.join(old_location, "Game.rxdata") return unless File.file?(old_file) File.move(old_file, FILE_PATH) end diff --git a/Data/Scripts/002_Save data/002_SaveData_Value.rb b/Data/Scripts/002_Save data/002_SaveData_Value.rb index 1ba2feb11..5a5b4426b 100644 --- a/Data/Scripts/002_Save data/002_SaveData_Value.rb +++ b/Data/Scripts/002_Save data/002_SaveData_Value.rb @@ -114,21 +114,21 @@ module SaveData # Requires a block with the loaded value as its parameter. # @see SaveData.register def load_value(&block) - raise ArgumentError, 'No block given to load_value' unless block_given? + raise ArgumentError, "No block given to load_value" unless block_given? @load_proc = block end # Defines what is saved into save data. Requires a block. # @see SaveData.register def save_value(&block) - raise ArgumentError, 'No block given to save_value' unless block_given? + raise ArgumentError, "No block given to save_value" unless block_given? @save_proc = block end # If present, defines what the value is set to at the start of a new game. # @see SaveData.register def new_game_value(&block) - raise ArgumentError, 'No block given to new_game_value' unless block_given? + raise ArgumentError, "No block given to new_game_value" unless block_given? @new_game_value_proc = block end @@ -142,7 +142,7 @@ module SaveData # save format. Requires a block with the old format array as its parameter. # @see SaveData.register def from_old_format(&block) - raise ArgumentError, 'No block given to from_old_format' unless block_given? + raise ArgumentError, "No block given to from_old_format" unless block_given? @old_format_get_proc = block end @@ -185,7 +185,7 @@ module SaveData def self.register(id, &block) validate id => Symbol unless block_given? - raise ArgumentError, 'No block given to SaveData.register' + raise ArgumentError, "No block given to SaveData.register" end @values << Value.new(id, &block) end diff --git a/Data/Scripts/002_Save data/003_SaveData_Conversion.rb b/Data/Scripts/002_Save data/003_SaveData_Conversion.rb index 0c2836aeb..9131f13a9 100644 --- a/Data/Scripts/002_Save data/003_SaveData_Conversion.rb +++ b/Data/Scripts/002_Save data/003_SaveData_Conversion.rb @@ -112,7 +112,7 @@ module SaveData # @see SaveData.register_conversion def to_value(value_id, &block) validate value_id => Symbol - raise ArgumentError, 'No block given to to_value' unless block_given? + raise ArgumentError, "No block given to to_value" unless block_given? if @value_procs[value_id].is_a?(Proc) raise "Multiple to_value definitions in conversion #{@id} for #{value_id}" end @@ -122,7 +122,7 @@ module SaveData # Defines a conversion to the entire save data. # @see SaveData.register_conversion def to_all(&block) - raise ArgumentError, 'No block given to to_all' unless block_given? + raise ArgumentError, "No block given to to_all" unless block_given? if @all_proc.is_a?(Proc) raise "Multiple to_all definitions in conversion #{@id}" end @@ -156,7 +156,7 @@ module SaveData def self.register_conversion(id, &block) validate id => Symbol unless block_given? - raise ArgumentError, 'No block given to SaveData.register_conversion' + raise ArgumentError, "No block given to SaveData.register_conversion" end conversion = Conversion.new(id, &block) @conversions[conversion.trigger_type][conversion.version] ||= [] @@ -168,8 +168,8 @@ module SaveData def self.get_conversions(save_data) conversions_to_run = [] versions = { - essentials: save_data[:essentials_version] || '18.1', - game: save_data[:game_version] || '0.0.0' + essentials: save_data[:essentials_version] || "18.1", + game: save_data[:game_version] || "0.0.0" } [:essentials, :game].each do |trigger_type| # Ensure the versions are sorted from lowest to highest @@ -194,7 +194,7 @@ module SaveData validate save_data => Hash conversions_to_run = self.get_conversions(save_data) return false if conversions_to_run.none? - File.open(SaveData::FILE_PATH + '.bak', 'wb') { |f| Marshal.dump(save_data, f) } + File.open(SaveData::FILE_PATH + ".bak", "wb") { |f| Marshal.dump(save_data, f) } Console.echo_h1 "Running #{conversions_to_run.length} save file conversions" conversions_to_run.each do |conversion| Console.echo_li "#{conversion.title}..." diff --git a/Data/Scripts/002_Save data/005_Game_SaveConversions.rb b/Data/Scripts/002_Save data/005_Game_SaveConversions.rb index f00dcd2ee..619b4a4e0 100644 --- a/Data/Scripts/002_Save data/005_Game_SaveConversions.rb +++ b/Data/Scripts/002_Save data/005_Game_SaveConversions.rb @@ -9,7 +9,7 @@ # of them in order to convert planted berry data properly. SaveData.register_conversion(:v19_2_fix_planted_berry_numerical_ids) do essentials_version 19.2 - display_title 'Fixing berry plant IDs data' + display_title "Fixing berry plant IDs data" to_value :global_metadata do |global| berry_conversion = { 389 => :CHERIBERRY, @@ -100,7 +100,7 @@ end SaveData.register_conversion(:v20_refactor_planted_berries_data) do essentials_version 20 - display_title 'Updating berry plant data format' + display_title "Updating berry plant data format" to_value :global_metadata do |global| if global.eventvars global.eventvars.each_pair do |key, value| @@ -144,7 +144,7 @@ end SaveData.register_conversion(:v20_refactor_follower_data) do essentials_version 20 - display_title 'Updating follower data format' + display_title "Updating follower data format" to_value :global_metadata do |global| # NOTE: dependentEvents is still defined in class PokemonGlobalMetadata just # for the sake of this conversion. It will be removed in future. @@ -167,7 +167,7 @@ end SaveData.register_conversion(:v20_refactor_day_care_variables) do essentials_version 20 - display_title 'Refactoring Day Care variables' + display_title "Refactoring Day Care variables" to_value :global_metadata do |global| global.instance_eval do @day_care = DayCare.new if @day_care.nil? @@ -205,7 +205,7 @@ end SaveData.register_conversion(:v20_rename_bag_variables) do essentials_version 20 - display_title 'Renaming Bag variables' + display_title "Renaming Bag variables" to_value :bag do |bag| bag.instance_eval do if !@lastpocket.nil? @@ -232,7 +232,7 @@ end SaveData.register_conversion(:v20_increment_player_character_id) do essentials_version 19.1 - display_title 'Incrementing player character ID' + display_title "Incrementing player character ID" to_value :player do |player| player.character_ID += 1 end @@ -242,7 +242,7 @@ end SaveData.register_conversion(:v20_add_pokedex_records) do essentials_version 20 - display_title 'Adding more Pokédex records' + display_title "Adding more Pokédex records" to_value :player do |player| player.pokedex.instance_eval do @caught_counts = {} if @caught_counts.nil? @@ -261,7 +261,7 @@ end SaveData.register_conversion(:v20_add_default_nicknaming_option) do essentials_version 20 - display_title 'Updating Options to include nicknaming setting' + display_title "Updating Options to include nicknaming setting" to_value :pokemon_system do |option| option.givenicknames = 0 if option.givenicknames.nil? end @@ -271,7 +271,7 @@ end SaveData.register_conversion(:v20_fix_default_weather_type) do essentials_version 20 - display_title 'Fixing weather type 0 in effect' + display_title "Fixing weather type 0 in effect" to_value :game_screen do |game_screen| game_screen.instance_eval do @weather_type = :None if @weather_type == 0 @@ -283,7 +283,7 @@ end SaveData.register_conversion(:v20_add_stats) do essentials_version 20 - display_title 'Adding stats to save data' + display_title "Adding stats to save data" to_all do |save_data| unless save_data.has_key?(:stats) save_data[:stats] = GameStats.new @@ -298,7 +298,7 @@ end SaveData.register_conversion(:v20_convert_pokemon_markings) do essentials_version 20 - display_title 'Updating format of Pokémon markings' + display_title "Updating format of Pokémon markings" to_all do |save_data| # Create a lambda function that updates a Pokémon's markings update_markings = lambda do |pkmn| @@ -338,10 +338,10 @@ SaveData.register_conversion(:v20_convert_pokemon_markings) do variables = save_data[:variables] (0..5000).each do |i| value = variables[i] - next if value.nil? - if value.is_a?(Array) + case value + when Array value.each { |value2| update_markings.call(value2) if value2.is_a?(Pokemon) } - elsif value.is_a?(Pokemon) + when Pokemon update_markings.call(value) end end diff --git a/Data/Scripts/003_Game processing/001_StartGame.rb b/Data/Scripts/003_Game processing/001_StartGame.rb index 0b0fe4b48..b803a2e94 100644 --- a/Data/Scripts/003_Game processing/001_StartGame.rb +++ b/Data/Scripts/003_Game processing/001_StartGame.rb @@ -4,15 +4,15 @@ module Game def self.initialize $game_temp = Game_Temp.new $game_system = Game_System.new - $data_animations = load_data('Data/Animations.rxdata') - $data_tilesets = load_data('Data/Tilesets.rxdata') - $data_common_events = load_data('Data/CommonEvents.rxdata') - $data_system = load_data('Data/System.rxdata') + $data_animations = load_data("Data/Animations.rxdata") + $data_tilesets = load_data("Data/Tilesets.rxdata") + $data_common_events = load_data("Data/CommonEvents.rxdata") + $data_system = load_data("Data/System.rxdata") pbLoadBattleAnimations GameData.load_all - map_file = sprintf('Data/Map%03d.rxdata', $data_system.start_map_id) + map_file = sprintf("Data/Map%03d.rxdata", $data_system.start_map_id) if $data_system.start_map_id == 0 || !pbRgssExists?(map_file) - raise _INTL('No starting position was set in the map editor.') + raise _INTL("No starting position was set in the map editor.") end end @@ -31,7 +31,7 @@ module Game # Set language (and choose language if there is no save file) if Settings::LANGUAGES.length >= 2 $PokemonSystem.language = pbChooseLanguage if save_data.empty? - pbLoadMessages('Data/' + Settings::LANGUAGES[$PokemonSystem.language][1]) + pbLoadMessages("Data/" + Settings::LANGUAGES[$PokemonSystem.language][1]) end end @@ -81,13 +81,13 @@ module Game $map_factory.setup($game_map.map_id) rescue Errno::ENOENT if $DEBUG - pbMessage(_INTL('Map {1} was not found.', $game_map.map_id)) + pbMessage(_INTL("Map {1} was not found.", $game_map.map_id)) map = pbWarpToMap exit unless map $map_factory.setup(map[0]) $game_player.moveto(map[1], map[2]) else - raise _INTL('The map was not found. The game cannot continue.') + raise _INTL("The map was not found. The game cannot continue.") end end $game_player.center($game_player.x, $game_player.y) @@ -95,7 +95,7 @@ module Game $map_factory.setMapChanged($game_map.map_id) end if $game_map.events.nil? - raise _INTL('The map is corrupt. The game cannot continue.') + raise _INTL("The map is corrupt. The game cannot continue.") end $PokemonEncounters = PokemonEncounters.new $PokemonEncounters.setup($game_map.map_id) diff --git a/Data/Scripts/003_Game processing/002_Scene_Map.rb b/Data/Scripts/003_Game processing/002_Scene_Map.rb index 6bcb3ea49..c1b345a61 100644 --- a/Data/Scripts/003_Game processing/002_Scene_Map.rb +++ b/Data/Scripts/003_Game processing/002_Scene_Map.rb @@ -9,7 +9,7 @@ class Scene_Map def spriteset(map_id = -1) return @spritesets[map_id] if map_id > 0 && @spritesets[map_id] - @spritesets.values.each do |i| + @spritesets.each_value do |i| return i if i.map == $game_map end return @spritesets.values[0] @@ -36,7 +36,7 @@ class Scene_Map def disposeSpritesets return if !@spritesets - @spritesets.keys.each do |i| + @spritesets.each_key do |i| next if !@spritesets[i] @spritesets[i].dispose @spritesets[i] = nil diff --git a/Data/Scripts/003_Game processing/003_Interpreter.rb b/Data/Scripts/003_Game processing/003_Interpreter.rb index 28e309d11..b7fea5939 100644 --- a/Data/Scripts/003_Game processing/003_Interpreter.rb +++ b/Data/Scripts/003_Game processing/003_Interpreter.rb @@ -22,7 +22,7 @@ class Interpreter def inspect str = super.chop - str << sprintf(' @event_id: %d>', @event_id) + str << sprintf(" @event_id: %d>", @event_id) return str end @@ -62,7 +62,7 @@ class Interpreter return end # Check all map events for one that wants to start, and set it up - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if !event.starting if event.trigger < 3 # Isn't autorun or parallel processing event.lock @@ -80,7 +80,7 @@ class Interpreter end def running? - return @list != nil + return !@list.nil? end #----------------------------------------------------------------------------- # * Frame Update @@ -109,7 +109,7 @@ class Interpreter # Do nothing if any event or the player is in the middle of a move route if @move_route_waiting return if $game_player.move_route_forcing - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| return if event.move_route_forcing end $game_temp.followers.each_follower do |event, follower| diff --git a/Data/Scripts/003_Game processing/004_Interpreter_Commands.rb b/Data/Scripts/003_Game processing/004_Interpreter_Commands.rb index d096029fa..b0317366f 100644 --- a/Data/Scripts/003_Game processing/004_Interpreter_Commands.rb +++ b/Data/Scripts/003_Game processing/004_Interpreter_Commands.rb @@ -1019,7 +1019,7 @@ class Interpreter $player.name = pbEnterPlayerName(_INTL("Your name?"), 1, @parameters[1], $player.name) return true end - if $game_actors && $data_actors && $data_actors[@parameters[0]] != nil + if $game_actors && $data_actors && $data_actors[@parameters[0]] $game_temp.battle_abort = true pbFadeOutIn { sscene = PokemonEntryScene.new diff --git a/Data/Scripts/004_Game classes/001_Switches and Variables/001_Game_Temp.rb b/Data/Scripts/004_Game classes/001_Switches and Variables/001_Game_Temp.rb index 4e3d285a0..61f28fe52 100644 --- a/Data/Scripts/004_Game classes/001_Switches and Variables/001_Game_Temp.rb +++ b/Data/Scripts/004_Game classes/001_Switches and Variables/001_Game_Temp.rb @@ -65,7 +65,7 @@ class Game_Temp @ending_surf = false @in_mini_update = false # Battle - @battleback_name = '' + @battleback_name = "" @force_single_battle = false # Player transfers @player_transferring = false diff --git a/Data/Scripts/004_Game classes/001_Switches and Variables/002_Game_Switches.rb b/Data/Scripts/004_Game classes/001_Switches and Variables/002_Game_Switches.rb index 5dc91702f..7f09ba2d2 100644 --- a/Data/Scripts/004_Game classes/001_Switches and Variables/002_Game_Switches.rb +++ b/Data/Scripts/004_Game classes/001_Switches and Variables/002_Game_Switches.rb @@ -16,7 +16,7 @@ class Game_Switches # switch_id : switch ID #----------------------------------------------------------------------------- def [](switch_id) - return @data[switch_id] if switch_id <= 5000 && @data[switch_id] != nil + return @data[switch_id] if switch_id <= 5000 && @data[switch_id] return false end #----------------------------------------------------------------------------- diff --git a/Data/Scripts/004_Game classes/002_Game_System.rb b/Data/Scripts/004_Game classes/002_Game_System.rb index 6d2ba8fdf..9b0353956 100644 --- a/Data/Scripts/004_Game classes/002_Game_System.rb +++ b/Data/Scripts/004_Game classes/002_Game_System.rb @@ -62,7 +62,7 @@ class Game_System def bgm_play_internal(bgm, position) # :nodoc: @bgm_position = position if !@bgm_paused @playing_bgm = bgm&.clone - if bgm != nil && bgm.name != "" + if bgm && bgm.name != "" if !@defaultBGM && FileTest.audio_exist?("Audio/BGM/" + bgm.name) bgm_play_internal2("Audio/BGM/" + bgm.name, bgm.volume, bgm.pitch, @bgm_position) end @@ -132,7 +132,7 @@ class Game_System def setDefaultBGM(bgm, volume = 80, pitch = 100) bgm = RPG::AudioFile.new(bgm, volume, pitch) if bgm.is_a?(String) @defaultBGM = nil - if bgm != nil && bgm.name != "" + if bgm && bgm.name != "" self.bgm_play(bgm) @defaultBGM = bgm.clone else @@ -144,7 +144,7 @@ class Game_System def me_play(me) me = RPG::AudioFile.new(me) if me.is_a?(String) - if me != nil && me.name != "" + if me && me.name != "" if FileTest.audio_exist?("Audio/ME/" + me.name) vol = me.volume vol *= $PokemonSystem.bgmvolume / 100.0 @@ -161,7 +161,7 @@ class Game_System def bgs_play(bgs) @playing_bgs = (bgs.nil?) ? nil : bgs.clone - if bgs != nil && bgs.name != "" + if bgs && bgs.name != "" if FileTest.audio_exist?("Audio/BGS/" + bgs.name) vol = bgs.volume vol *= $PokemonSystem.sevolume / 100.0 @@ -228,7 +228,7 @@ class Game_System def se_play(se) se = RPG::AudioFile.new(se) if se.is_a?(String) - if se != nil && se.name != "" && FileTest.audio_exist?("Audio/SE/" + se.name) + if se && se.name != "" && FileTest.audio_exist?("Audio/SE/" + se.name) vol = se.volume vol *= $PokemonSystem.sevolume / 100.0 vol = vol.to_i diff --git a/Data/Scripts/004_Game classes/004_Game_Map.rb b/Data/Scripts/004_Game classes/004_Game_Map.rb index bef809143..7a3ad2719 100644 --- a/Data/Scripts/004_Game classes/004_Game_Map.rb +++ b/Data/Scripts/004_Game classes/004_Game_Map.rb @@ -59,7 +59,7 @@ class Game_Map @need_refresh = false EventHandlers.trigger(:on_game_map_setup, map_id, @map, tileset) @events = {} - @map.events.keys.each do |i| + @map.events.each_key do |i| @events[i] = Game_Event.new(@map_id, @map.events[i], self) end @common_events = {} @@ -144,7 +144,7 @@ class Game_Map def passable?(x, y, d, self_event = nil) return false if !valid?(x, y) bit = (1 << ((d / 2) - 1)) & 0x0f - events.values.each do |event| + events.each_value do |event| next if event.tile_id <= 0 next if event == self_event next if !event.at_coordinate?(x, y) @@ -186,7 +186,7 @@ class Game_Map tile_id = data[x, y, i] terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id]) # If already on water, only allow movement to another water tile - if self_event != nil && terrain.can_surf_freely + if self_event && terrain.can_surf_freely [2, 1, 0].each do |j| facing_tile_id = data[newx, newy, j] return false if facing_tile_id.nil? @@ -199,7 +199,7 @@ class Game_Map # Can't walk onto ice elsif terrain.ice return false - elsif self_event != nil && self_event.x == x && self_event.y == y + elsif self_event && self_event.x == x && self_event.y == y # Can't walk onto ledges [2, 1, 0].each do |j| facing_tile_id = data[newx, newy, j] @@ -209,12 +209,11 @@ class Game_Map break if facing_terrain.id != :None && !facing_terrain.ignore_passability end end + next if terrain&.ignore_passability # Regular passability checks - if !terrain || !terrain.ignore_passability - passage = @passages[tile_id] - return false if passage & bit != 0 || passage & 0x0f == 0x0f - return true if @priorities[tile_id] == 0 - end + passage = @passages[tile_id] + return false if passage & bit != 0 || passage & 0x0f == 0x0f + return true if @priorities[tile_id] == 0 end return true end @@ -237,11 +236,10 @@ class Game_Map return (passage & bit == 0 && passage & 0x0f != 0x0f) end end + next if terrain&.ignore_passability # Regular passability checks - if !terrain || !terrain.ignore_passability - return false if passage & bit != 0 || passage & 0x0f == 0x0f - return true if @priorities[tile_id] == 0 - end + return false if passage & bit != 0 || passage & 0x0f == 0x0f + return true if @priorities[tile_id] == 0 end return true end @@ -250,7 +248,7 @@ class Game_Map # event there, and the tile is fully passable in all directions) def passableStrict?(x, y, d, self_event = nil) return false if !valid?(x, y) - events.values.each do |event| + events.each_value do |event| next if event == self_event || event.tile_id < 0 || event.through next if !event.at_coordinate?(x, y) next if GameData::TerrainTag.try_get(@terrain_tags[event.tile_id]).ignore_passability @@ -310,7 +308,7 @@ class Game_Map # Unused. def check_event(x, y) - self.events.values.each do |event| + self.events.each_value do |event| return event.id if event.at_coordinate?(x, y) end end @@ -390,10 +388,10 @@ class Game_Map end def refresh - @events.values.each do |event| + @events.each_value do |event| event.refresh end - @common_events.values.each do |common_event| + @common_events.each_value do |common_event| common_event.refresh end @need_refresh = false @@ -420,11 +418,11 @@ class Game_Map @scroll_rest -= distance end # Only update events that are on-screen - @events.values.each do |event| + @events.each_value do |event| event.update end # Update common events - @common_events.values.each do |common_event| + @common_events.each_value do |common_event| common_event.update end # Update fog diff --git a/Data/Scripts/004_Game classes/005_Game_Map_Autoscroll.rb b/Data/Scripts/004_Game classes/005_Game_Map_Autoscroll.rb index bfa58138b..76cea20e3 100644 --- a/Data/Scripts/004_Game classes/005_Game_Map_Autoscroll.rb +++ b/Data/Scripts/004_Game classes/005_Game_Map_Autoscroll.rb @@ -81,10 +81,10 @@ class Interpreter if $game_map.scrolling? return false elsif !$game_map.valid?(x, y) - print 'Map Autoscroll: given x,y is invalid' + print "Map Autoscroll: given x,y is invalid" return command_skip elsif !(1..6).include?(speed) - print 'Map Autoscroll: invalid speed (1-6 only)' + print "Map Autoscroll: invalid speed (1-6 only)" return command_skip end center_x = ((Graphics.width / 2) - (Game_Map::TILE_WIDTH / 2)) * 4 # X coordinate in the center of the screen @@ -126,12 +126,8 @@ class Interpreter end count = [count_x.abs, count_y.abs].min end - $game_map.start_scroll(dir, count, speed) if dir != nil - if @diag - return false - else - return true - end + $game_map.start_scroll(dir, count, speed) if dir + return !@diag end #----------------------------------------------------------------------------- diff --git a/Data/Scripts/004_Game classes/006_Game_MapFactory.rb b/Data/Scripts/004_Game classes/006_Game_MapFactory.rb index 3a6c48caf..e8dd9b177 100644 --- a/Data/Scripts/004_Game classes/006_Game_MapFactory.rb +++ b/Data/Scripts/004_Game classes/006_Game_MapFactory.rb @@ -180,7 +180,7 @@ class PokemonMapFactory return false unless map.passable?(x, y, 0, thisEvent) end # Check passability of event(s) in that spot - map.events.values.each do |event| + map.events.each_value do |event| next if event == thisEvent || !event.at_coordinate?(x, y) return false if !event.through && event.character_name != "" end @@ -207,7 +207,7 @@ class PokemonMapFactory elsif !map.passableStrict?(x, y, 0, thisEvent) return false end - map.events.values.each do |event| + map.events.each_value do |event| next if event == thisEvent || !event.at_coordinate?(x, y) return false if !event.through && event.character_name != "" end diff --git a/Data/Scripts/004_Game classes/007_Game_Character.rb b/Data/Scripts/004_Game classes/007_Game_Character.rb index 9665627fd..74d1d8ab4 100644 --- a/Data/Scripts/004_Game classes/007_Game_Character.rb +++ b/Data/Scripts/004_Game classes/007_Game_Character.rb @@ -241,7 +241,7 @@ class Game_Character return false unless self.map.passable?(x, y, d, self) return false unless self.map.passable?(new_x, new_y, 10 - d, self) end - self.map.events.values.each do |event| + self.map.events.each_value do |event| next if self == event || !event.at_coordinate?(new_x, new_y) || event.through return false if self != $game_player || event.character_name != "" end diff --git a/Data/Scripts/004_Game classes/008_Game_Event.rb b/Data/Scripts/004_Game classes/008_Game_Event.rb index 8280311ff..202157ed3 100644 --- a/Data/Scripts/004_Game classes/008_Game_Event.rb +++ b/Data/Scripts/004_Game classes/008_Game_Event.rb @@ -270,7 +270,7 @@ class Game_Event < Game_Character refresh end check_event_trigger_auto - if @interpreter != nil + if @interpreter unless @interpreter.running? @interpreter.setup(@list, @event.id, @map_id) end diff --git a/Data/Scripts/004_Game classes/009_Game_Player.rb b/Data/Scripts/004_Game classes/009_Game_Player.rb index c5d6388ae..d22943179 100644 --- a/Data/Scripts/004_Game classes/009_Game_Player.rb +++ b/Data/Scripts/004_Game classes/009_Game_Player.rb @@ -188,7 +188,7 @@ class Game_Player < Game_Character # If event is running return result if checkIfRunning && $game_system.map_interpreter.running? # All event loops - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if !triggers.include?(event.trigger) next if !event.name[/trainer\((\d+)\)/i] distance = $~[1].to_i @@ -204,7 +204,7 @@ class Game_Player < Game_Character # If event is running return result if checkIfRunning && $game_system.map_interpreter.running? # All event loops - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if !triggers.include?(event.trigger) next if !event.name[/counter\((\d+)\)/i] distance = $~[1].to_i @@ -238,7 +238,7 @@ class Game_Player < Game_Character new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0) new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) return nil if !$game_map.valid?(new_x, new_y) - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if !event.at_coordinate?(new_x, new_y) next if event.jumping? || event.over_trigger? return event @@ -247,7 +247,7 @@ class Game_Player < Game_Character if $game_map.counter?(new_x, new_y) new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0) new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if !event.at_coordinate?(new_x, new_y) next if event.jumping? || event.over_trigger? return event @@ -332,7 +332,7 @@ class Game_Player < Game_Character # If event is running return result if $game_system.map_interpreter.running? # All event loops - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| # If event coordinates and triggers are consistent next if !event.at_coordinate?(@x, @y) next if !triggers.include?(event.trigger) @@ -356,7 +356,7 @@ class Game_Player < Game_Character new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) return false if !$game_map.valid?(new_x, new_y) # All event loops - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if !triggers.include?(event.trigger) # If event coordinates and triggers are consistent next if !event.at_coordinate?(new_x, new_y) @@ -372,7 +372,7 @@ class Game_Player < Game_Character new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) return false if !$game_map.valid?(new_x, new_y) # All event loops - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if !triggers.include?(event.trigger) # If event coordinates and triggers are consistent next if !event.at_coordinate?(new_x, new_y) @@ -394,7 +394,7 @@ class Game_Player < Game_Character # All event loops x_offset = (dir == 4) ? -1 : (dir == 6) ? 1 : 0 y_offset = (dir == 8) ? -1 : (dir == 2) ? 1 : 0 - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if ![1, 2].include?(event.trigger) # Player touch, event touch # If event coordinates and triggers are consistent next if !event.at_coordinate?(@x + x_offset, @y + y_offset) diff --git a/Data/Scripts/004_Game classes/010_Game_CommonEvent.rb b/Data/Scripts/004_Game classes/010_Game_CommonEvent.rb index ffd91eba6..1917758f2 100644 --- a/Data/Scripts/004_Game classes/010_Game_CommonEvent.rb +++ b/Data/Scripts/004_Game classes/010_Game_CommonEvent.rb @@ -67,15 +67,10 @@ class Game_CommonEvent # * Frame Update #----------------------------------------------------------------------------- def update - # If parallel process is valid - if @interpreter != nil - # If not running - unless @interpreter.running? - # Set up event - @interpreter.setup(self.list, 0) - end - # Update interpreter - @interpreter.update - end + return if !@interpreter + # Set up event if interpreter is not running + @interpreter.setup(self.list, 0) if !@interpreter.running? + # Update interpreter + @interpreter.update end end diff --git a/Data/Scripts/004_Game classes/011_Game_Follower.rb b/Data/Scripts/004_Game classes/011_Game_Follower.rb index 873b15f82..de06b11be 100644 --- a/Data/Scripts/004_Game classes/011_Game_Follower.rb +++ b/Data/Scripts/004_Game classes/011_Game_Follower.rb @@ -167,7 +167,7 @@ class Game_Follower < Game_Event passed_tile_checks = false bit = (1 << ((direction / 2) - 1)) & 0x0f # Check all events for ones using tiles as graphics, and see if they're passable - this_map.events.values.each do |event| + this_map.events.each_value do |event| next if event.tile_id < 0 || event.through || !event.at_coordinate?(x, y) tile_data = GameData::TerrainTag.try_get(this_map.terrain_tags[event.tile_id]) next if tile_data.ignore_passability @@ -195,7 +195,7 @@ class Game_Follower < Game_Event end end # Check all events on the map to see if any are in the way - this_map.events.values.each do |event| + this_map.events.each_value do |event| next if !event.at_coordinate?(x, y) return false if !event.through && event.character_name != "" end diff --git a/Data/Scripts/004_Game classes/012_Game_FollowerFactory.rb b/Data/Scripts/004_Game classes/012_Game_FollowerFactory.rb index ebd54e344..24d8e7ffa 100644 --- a/Data/Scripts/004_Game classes/012_Game_FollowerFactory.rb +++ b/Data/Scripts/004_Game classes/012_Game_FollowerFactory.rb @@ -180,9 +180,9 @@ class Game_FollowerFactory vector = $map_factory.getRelativePos(event.map.map_id, event.x, event.y, leader[0], leader[1], leader[2]) if vector[0] != 0 - move_route.prepend((vector[0].positive?) ? PBMoveRoute::Right : PBMoveRoute::Left) + move_route.prepend((vector[0] > 0) ? PBMoveRoute::Right : PBMoveRoute::Left) elsif vector[1] != 0 - move_route.prepend((vector[1].positive?) ? PBMoveRoute::Down : PBMoveRoute::Up) + move_route.prepend((vector[1] > 0) ? PBMoveRoute::Down : PBMoveRoute::Up) end pbMoveRoute(event, move_route + [PBMoveRoute::Opacity, 0]) end @@ -397,36 +397,36 @@ end #=============================================================================== # @deprecated This method is slated to be removed in v21. def pbAddDependency2(event_id, name, common_event_id) - Deprecation.warn_method('pbAddDependency2', 'v21', 'Followers.add(event_id, name, common_event_id)') + Deprecation.warn_method("pbAddDependency2", "v21", "Followers.add(event_id, name, common_event_id)") Followers.add(event_id, name, common_event_id) end # @deprecated This method is slated to be removed in v21. def pbAddDependency(event) - Deprecation.warn_method('pbAddDependency', 'v21', 'Followers.add_event(event)') + Deprecation.warn_method("pbAddDependency", "v21", "Followers.add_event(event)") Followers.add_event(event) end # @deprecated This method is slated to be removed in v21. def pbRemoveDependency2(name) - Deprecation.warn_method('pbRemoveDependency2', 'v21', 'Followers.remove(name)') + Deprecation.warn_method("pbRemoveDependency2", "v21", "Followers.remove(name)") Followers.remove(name) end # @deprecated This method is slated to be removed in v21. def pbRemoveDependency(event) - Deprecation.warn_method('pbRemoveDependency', 'v21', 'Followers.remove_event(event)') + Deprecation.warn_method("pbRemoveDependency", "v21", "Followers.remove_event(event)") Followers.remove_event(event) end # @deprecated This method is slated to be removed in v21. def pbRemoveDependencies - Deprecation.warn_method('pbRemoveDependencies', 'v21', 'Followers.clear') + Deprecation.warn_method("pbRemoveDependencies", "v21", "Followers.clear") Followers.clear end # @deprecated This method is slated to be removed in v21. def pbGetDependency(name) - Deprecation.warn_method('pbGetDependency', 'v21', 'Followers.get(name)') + Deprecation.warn_method("pbGetDependency", "v21", "Followers.get(name)") Followers.get(name) end diff --git a/Data/Scripts/005_Sprites/003_Sprite_Character.rb b/Data/Scripts/005_Sprites/003_Sprite_Character.rb index dadce49d9..2178062bb 100644 --- a/Data/Scripts/005_Sprites/003_Sprite_Character.rb +++ b/Data/Scripts/005_Sprites/003_Sprite_Character.rb @@ -117,9 +117,9 @@ class Sprite_Character < RPG::Sprite self.oy = @ch else @charbitmap = AnimatedBitmap.new( - 'Graphics/Characters/' + @character_name, @character_hue + "Graphics/Characters/" + @character_name, @character_hue ) - RPG::Cache.retain('Graphics/Characters/', @character_name, @character_hue) if @character == $game_player + RPG::Cache.retain("Graphics/Characters/", @character_name, @character_hue) if @character == $game_player @charbitmapAnimated = true @bushbitmap&.dispose @bushbitmap = nil diff --git a/Data/Scripts/005_Sprites/009_Sprite_DynamicShadows.rb b/Data/Scripts/005_Sprites/009_Sprite_DynamicShadows.rb index b48e7e15c..ea9aa9e79 100644 --- a/Data/Scripts/005_Sprites/009_Sprite_DynamicShadows.rb +++ b/Data/Scripts/005_Sprites/009_Sprite_DynamicShadows.rb @@ -45,7 +45,7 @@ class Sprite_Shadow < RPG::Sprite self.ox = 16 self.oy = 32 else - @chbitmap = AnimatedBitmap.new('Graphics/Characters/' + @character.character_name, + @chbitmap = AnimatedBitmap.new("Graphics/Characters/" + @character.character_name, @character.character_hue) @cw = @chbitmap.width / 4 @ch = @chbitmap.height / 4 @@ -134,7 +134,7 @@ class Sprite_Character < RPG::Sprite def setShadows(map, shadows) if character.is_a?(Game_Event) && shadows.length > 0 params = XPML_read(map, "Shadow", @character, 4) - if params != nil + if params shadows.each do |shadow| @ombrelist.push(Sprite_Shadow.new(viewport, @character, shadows)) end @@ -186,10 +186,10 @@ class Spriteset_Map map = $game_map if !map map.events.keys.sort.each do |k| ev = map.events[k] - warn = true if ev.list != nil && ev.list.length > 0 && ev.list[0].code == 108 && + warn = true if ev.list && ev.list.length > 0 && ev.list[0].code == 108 && (ev.list[0].parameters == ["s"] || ev.list[0].parameters == ["o"]) params = XPML_read(map, "Shadow Source", ev, 4) - @shadows.push([ev] + params) if params != nil + @shadows.push([ev] + params) if params end if warn == true p "Warning : At least one event on this map uses the obsolete way to add shadows" @@ -227,26 +227,19 @@ def XPML_read(map, markup, event, max_param_number = 0) parameter_list = nil return nil if !event || event.list.nil? event.list.size.times do |i| - if event.list[i].code == 108 && - event.list[i].parameters[0].downcase == "begin " + markup.downcase - parameter_list = [] if parameter_list.nil? - ((i + 1)...event.list.size).each do |j| - if event.list[j].code == 108 - parts = event.list[j].parameters[0].split - if parts.size != 1 && parts[0].downcase != "begin" - if parts[1].to_i != 0 || parts[1] == "0" - parameter_list.push(parts[1].to_i) - else - parameter_list.push(parts[1]) - end - else - return parameter_list - end - else - return parameter_list - end - return parameter_list if max_param_number != 0 && j == i + max_param_number + next unless event.list[i].code == 108 && + event.list[i].parameters[0].downcase == "begin " + markup.downcase + parameter_list = [] if parameter_list.nil? + ((i + 1)...event.list.size).each do |j| + return parameter_list if event.list[j].code != 108 + parts = event.list[j].parameters[0].split + return parameter_list if parts.size == 1 || parts[0].downcase == "begin" + if parts[1].to_i != 0 || parts[1] == "0" + parameter_list.push(parts[1].to_i) + else + parameter_list.push(parts[1]) end + return parameter_list if max_param_number != 0 && j == i + max_param_number end end return parameter_list diff --git a/Data/Scripts/005_Sprites/010_ParticleEngine.rb b/Data/Scripts/005_Sprites/010_ParticleEngine.rb index 1f8aefe21..8f4d7255a 100644 --- a/Data/Scripts/005_Sprites/010_ParticleEngine.rb +++ b/Data/Scripts/005_Sprites/010_ParticleEngine.rb @@ -80,7 +80,7 @@ class Particle_Engine def update if @firsttime @firsttime = false - @map.events.values.each do |event| + @map.events.each_value do |event| remove_effect(event) add_effect(event) end @@ -349,7 +349,7 @@ class ParticleEffect_Event < ParticleEffect @particles.each do |particle| particle.dispose end - @bitmaps.values.each do |bitmap| + @bitmaps.each_value do |bitmap| bitmap.dispose end @particles.clear diff --git a/Data/Scripts/005_Sprites/011_PictureEx.rb b/Data/Scripts/005_Sprites/011_PictureEx.rb index 8a75607d4..3949525ac 100644 --- a/Data/Scripts/005_Sprites/011_PictureEx.rb +++ b/Data/Scripts/005_Sprites/011_PictureEx.rb @@ -436,12 +436,11 @@ class PictureEx end # Increase frame counter process[3] += 1 - if process[3] > process[2] - # Process has ended, erase it - callback(process[4]) if process[4] - @processes[i] = nil - procEnded = true - end + next if process[3] <= process[2] + # Process has ended, erase it + callback(process[4]) if process[4] + @processes[i] = nil + procEnded = true end # Clear out empty spaces in @processes array caused by finished processes @processes.compact! if procEnded diff --git a/Data/Scripts/006_Map renderer/004_TileDrawingHelper.rb b/Data/Scripts/006_Map renderer/004_TileDrawingHelper.rb index 8373b2190..d68041980 100644 --- a/Data/Scripts/006_Map renderer/004_TileDrawingHelper.rb +++ b/Data/Scripts/006_Map renderer/004_TileDrawingHelper.rb @@ -215,11 +215,10 @@ def getPassabilityMinimap(mapid) neighbors = TileDrawingHelper::NEIGHBORS_TO_AUTOTILE_INDEX map.width.times do |i| map.height.times do |j| - if passtable[i, j] == 0 - nb = TileDrawingHelper.tableNeighbors(passtable, i, j) - tile = neighbors[nb] - bltMinimapAutotile(ret, i * 6, j * 6, minimap.bitmap, tile) - end + next if passtable[i, j] != 0 + nb = TileDrawingHelper.tableNeighbors(passtable, i, j) + tile = neighbors[nb] + bltMinimapAutotile(ret, i * 6, j * 6, minimap.bitmap, tile) end end minimap.disposes diff --git a/Data/Scripts/007_Objects and windows/002_MessageConfig.rb b/Data/Scripts/007_Objects and windows/002_MessageConfig.rb index 933dcaa15..99664fa5b 100644 --- a/Data/Scripts/007_Objects and windows/002_MessageConfig.rb +++ b/Data/Scripts/007_Objects and windows/002_MessageConfig.rb @@ -503,7 +503,7 @@ end # Disposes all objects in the specified hash. def pbDisposeSpriteHash(sprites) return if !sprites - sprites.keys.each do |i| + sprites.each_key do |i| pbDisposeSprite(sprites, i) end sprites.clear @@ -665,7 +665,7 @@ end # _activeStatuses_ is the result of a previous call to pbActivateWindows def pbRestoreActivations(sprites, activeStatuses) return if !sprites || !activeStatuses - activeStatuses.keys.each do |k| + activeStatuses.each_key do |k| if sprites[k].is_a?(Window) && !pbDisposed?(sprites[k]) sprites[k].active = activeStatuses[k] ? true : false end @@ -723,7 +723,7 @@ def addBackgroundPlane(sprites, planename, background, viewport = nil) sprites[planename].visible = false else sprites[planename].setBitmap(bitmapName) - sprites.values.each do |spr| + sprites.each_value do |spr| if spr.is_a?(Window) spr.windowskin = nil end @@ -745,7 +745,7 @@ def addBackgroundOrColoredPlane(sprites, planename, background, color, viewport else sprites[planename] = AnimatedPlane.new(viewport) sprites[planename].setBitmap(bitmapName) - sprites.values.each do |spr| + sprites.each_value do |spr| if spr.is_a?(Window) spr.windowskin = nil end diff --git a/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb b/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb index 55eae493f..dfd57fa56 100644 --- a/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb +++ b/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb @@ -317,7 +317,7 @@ class SpriteWindow < Window end privRefresh if mustchange if @flash > 0 - @sprites.values.each do |i| + @sprites.each_value do |i| i.update end @flash -= 1 diff --git a/Data/Scripts/007_Objects and windows/006_SpriteWindow_pictures.rb b/Data/Scripts/007_Objects and windows/006_SpriteWindow_pictures.rb index cf0f75a33..a5e248da0 100644 --- a/Data/Scripts/007_Objects and windows/006_SpriteWindow_pictures.rb +++ b/Data/Scripts/007_Objects and windows/006_SpriteWindow_pictures.rb @@ -93,7 +93,7 @@ class PictureWindow < SpriteWindow_Base # is ignored unless pathOrBitmap is a filename) def setBitmap(pathOrBitmap, hue = 0) clearBitmaps - if pathOrBitmap != nil && pathOrBitmap != "" + if pathOrBitmap && pathOrBitmap != "" case pathOrBitmap when Bitmap @_iconbitmap = pathOrBitmap diff --git a/Data/Scripts/007_Objects and windows/008_AnimatedBitmap.rb b/Data/Scripts/007_Objects and windows/008_AnimatedBitmap.rb index ab78018d0..0a5aea4ee 100644 --- a/Data/Scripts/007_Objects and windows/008_AnimatedBitmap.rb +++ b/Data/Scripts/007_Objects and windows/008_AnimatedBitmap.rb @@ -6,10 +6,10 @@ class AnimatedBitmap raise "Filename is nil (missing graphic)." if file.nil? path = file filename = "" - if file.last != '/' # Isn't just a directory + if file.last != "/" # Isn't just a directory split_file = file.split(/[\\\/]/) filename = split_file.pop - path = split_file.join('/') + '/' + path = split_file.join("/") + "/" end if filename[/^\[\d+(?:,\d+)?\]/] # Starts with 1 or 2 numbers in square brackets @bitmap = PngAnimatedBitmap.new(path, filename, hue) diff --git a/Data/Scripts/007_Objects and windows/011_Messages.rb b/Data/Scripts/007_Objects and windows/011_Messages.rb index aba65ddbf..1b6efc2eb 100644 --- a/Data/Scripts/007_Objects and windows/011_Messages.rb +++ b/Data/Scripts/007_Objects and windows/011_Messages.rb @@ -30,16 +30,14 @@ def pbEventCommentInput(*args) return nil if list.nil? return nil unless list.is_a?(Array) list.each do |item| - next unless item.code == 108 || item.code == 408 - if item.parameters[0] == trigger - start = list.index(item) + 1 - finish = start + elements - (start...finish).each do |id| - next if !list[id] - parameters.push(list[id].parameters[0]) - end - return parameters + next if ![108, 108].include?(item.code) + next if item.parameters[0] != trigger + start = list.index(item) + 1 + finish = start + elements + (start...finish).each do |id| + parameters.push(list[id].parameters[0]) if list[id] end + return parameters end return nil end @@ -557,7 +555,7 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni end end end - if startSE != nil + if startSE pbSEPlay(pbStringToAudioFile(startSE)) elsif signWaitCount == 0 && letterbyletter pbPlayDecisionSE diff --git a/Data/Scripts/009_Scenes/001_Transitions.rb b/Data/Scripts/009_Scenes/001_Transitions.rb index 14bac461a..f8a620b48 100644 --- a/Data/Scripts/009_Scenes/001_Transitions.rb +++ b/Data/Scripts/009_Scenes/001_Transitions.rb @@ -572,11 +572,10 @@ module Transitions size = (@timer - @timings[i]) / TIME_TO_ZOOM sprite.zoom_x = @zoom_x_target * size sprite.zoom_y = @zoom_y_target * size - if size >= 1.0 - sprite.zoom_x = @zoom_x_target - sprite.zoom_y = @zoom_y_target - @timings[i] = -1 - end + next if size < 1.0 + sprite.zoom_x = @zoom_x_target + sprite.zoom_y = @zoom_y_target + @timings[i] = -1 end end end diff --git a/Data/Scripts/011_Battle/001_Battle/001_Battle.rb b/Data/Scripts/011_Battle/001_Battle/001_Battle.rb index 4d7df4a0a..5f64b57e6 100644 --- a/Data/Scripts/011_Battle/001_Battle/001_Battle.rb +++ b/Data/Scripts/011_Battle/001_Battle/001_Battle.rb @@ -266,11 +266,9 @@ class Battle if opposes?(idxBattler) return [] if !@items return @items[pbGetOwnerIndexFromBattlerIndex(idxBattler)] - else - return [] if !@ally_items - return @ally_items[pbGetOwnerIndexFromBattlerIndex(idxBattler)] end - return [] + return [] if !@ally_items + return @ally_items[pbGetOwnerIndexFromBattlerIndex(idxBattler)] end # Returns whether the battler in position idxBattler is owned by the same diff --git a/Data/Scripts/011_Battle/001_Battle/002_Battle_StartAndEnd.rb b/Data/Scripts/011_Battle/001_Battle/002_Battle_StartAndEnd.rb index 11696b6fc..83d3ce8f6 100644 --- a/Data/Scripts/011_Battle/001_Battle/002_Battle_StartAndEnd.rb +++ b/Data/Scripts/011_Battle/001_Battle/002_Battle_StartAndEnd.rb @@ -60,10 +60,11 @@ class Battle end sideCounts.each_with_index do |_count, i| if !requireds[i] || requireds[i] == 0 - if side == 0 + case side + when 0 raise _INTL("Player-side trainer {1} has no battler position for their Pokémon to go (trying {2}v{3} battle)", i + 1, @sideSizes[0], @sideSizes[1]) - elsif side == 1 + when 1 raise _INTL("Opposing trainer {1} has no battler position for their Pokémon to go (trying {2}v{3} battle)", i + 1, @sideSizes[0], @sideSizes[1]) end diff --git a/Data/Scripts/011_Battle/002_Battler/007_Battler_UseMove.rb b/Data/Scripts/011_Battle/002_Battler/007_Battler_UseMove.rb index 2e8209c8f..d73705479 100644 --- a/Data/Scripts/011_Battle/002_Battler/007_Battler_UseMove.rb +++ b/Data/Scripts/011_Battle/002_Battler/007_Battler_UseMove.rb @@ -431,7 +431,7 @@ class Battle::Battler # NOTE: If a multi-hit move becomes disabled partway through doing those # hits (e.g. by Cursed Body), the rest of the hits continue as # normal. - break if !targets.any? { |t| !t.fainted? } # All targets are fainted + break if targets.none? { |t| !t.fainted? } # All targets are fainted end # Battle Arena only - attack is successful @battle.successStates[user.index].useState = 2 diff --git a/Data/Scripts/011_Battle/003_Move/010_MoveEffects_Healing.rb b/Data/Scripts/011_Battle/003_Move/010_MoveEffects_Healing.rb index 40b86fe8d..88065aa99 100644 --- a/Data/Scripts/011_Battle/003_Move/010_MoveEffects_Healing.rb +++ b/Data/Scripts/011_Battle/003_Move/010_MoveEffects_Healing.rb @@ -462,7 +462,7 @@ class Battle::Move::UserLosesHalfOfTotalHPExplosive < Battle::Move def pbMoveFailed?(user, targets) if !@battle.moldBreaker bearer = @battle.pbCheckGlobalAbility(:DAMP) - if bearer != nil + if bearer @battle.pbShowAbilitySplash(bearer) if Battle::Scene::USE_ABILITY_SPLASH @battle.pbDisplay(_INTL("{1} cannot use {2}!", user.pbThis, @name)) @@ -494,7 +494,7 @@ class Battle::Move::UserFaintsExplosive < Battle::Move def pbMoveFailed?(user, targets) if !@battle.moldBreaker bearer = @battle.pbCheckGlobalAbility(:DAMP) - if bearer != nil + if bearer @battle.pbShowAbilitySplash(bearer) if Battle::Scene::USE_ABILITY_SPLASH @battle.pbDisplay(_INTL("{1} cannot use {2}!", user.pbThis, @name)) diff --git a/Data/Scripts/011_Battle/003_Move/012_MoveEffects_ChangeMoveEffect.rb b/Data/Scripts/011_Battle/003_Move/012_MoveEffects_ChangeMoveEffect.rb index d4ce5ea0a..ef42aa86e 100644 --- a/Data/Scripts/011_Battle/003_Move/012_MoveEffects_ChangeMoveEffect.rb +++ b/Data/Scripts/011_Battle/003_Move/012_MoveEffects_ChangeMoveEffect.rb @@ -762,7 +762,7 @@ class Battle::Move::UseLastMoveUsedByTarget < Battle::Move def pbFailsAgainstTarget?(user, target, show_message) if !target.lastRegularMoveUsed || - !GameData::Move.get(target.lastRegularMoveUsed).flags.any? { |f| f[/^CanMirrorMove$/i] } + GameData::Move.get(target.lastRegularMoveUsed).flags.none? { |f| f[/^CanMirrorMove$/i] } @battle.pbDisplay(_INTL("The mirror move failed!")) if show_message return true end diff --git a/Data/Scripts/011_Battle/004_Scene/001_Battle_Scene.rb b/Data/Scripts/011_Battle/004_Scene/001_Battle_Scene.rb index 226eb5466..3db856e96 100644 --- a/Data/Scripts/011_Battle/004_Scene/001_Battle_Scene.rb +++ b/Data/Scripts/011_Battle/004_Scene/001_Battle_Scene.rb @@ -88,11 +88,10 @@ class Battle::Scene shouldCompact = false @animations.each_with_index do |a, i| a.update - if a.animDone? - a.dispose - @animations[i] = nil - shouldCompact = true - end + next if !a.animDone? + a.dispose + @animations[i] = nil + shouldCompact = true end @animations.compact! if shouldCompact end diff --git a/Data/Scripts/011_Battle/004_Scene/003_Scene_ChooseCommands.rb b/Data/Scripts/011_Battle/004_Scene/003_Scene_ChooseCommands.rb index 19ab86127..06c17bd05 100644 --- a/Data/Scripts/011_Battle/004_Scene/003_Scene_ChooseCommands.rb +++ b/Data/Scripts/011_Battle/004_Scene/003_Scene_ChooseCommands.rb @@ -195,8 +195,8 @@ class Battle::Scene # Set Bag starting positions oldLastPocket = $bag.last_viewed_pocket oldChoices = $bag.last_pocket_selections.clone - $bag.last_viewed_pocket = @bagLastPocket if @bagLastPocket != nil - $bag.last_pocket_selections = @bagChoices if @bagChoices != nil + $bag.last_viewed_pocket = @bagLastPocket if @bagLastPocket + $bag.last_pocket_selections = @bagChoices if @bagChoices # Start Bag screen itemScene = PokemonBag_Scene.new itemScene.pbStartScene($bag, true, diff --git a/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb b/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb index 9af5b7e15..21c0a99ce 100644 --- a/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb +++ b/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb @@ -137,7 +137,7 @@ class Battle::Scene a[2] = true if a[1].animDone? end pbUpdate - if !inPartyAnimation? && !sendOutAnims.any? { |a| !a[2] } + if !inPartyAnimation? && sendOutAnims.none? { |a| !a[2] } break end end @@ -515,7 +515,7 @@ class Battle::Scene return if !animations animations.each do |a| next if !a || a.name != "Common:" + animName - pbAnimationCore(a, user, (target != nil) ? target : user) + pbAnimationCore(a, user, target || user) return end end diff --git a/Data/Scripts/011_Battle/004_Scene/005_Battle_Scene_Menus.rb b/Data/Scripts/011_Battle/004_Scene/005_Battle_Scene_Menus.rb index 8008de645..6c1a5a62d 100644 --- a/Data/Scripts/011_Battle/004_Scene/005_Battle_Scene_Menus.rb +++ b/Data/Scripts/011_Battle/004_Scene/005_Battle_Scene_Menus.rb @@ -174,9 +174,7 @@ class Battle::Scene::CommandMenu < Battle::Scene::MenuBase @msgBox.text = value[0] return if USE_GRAPHICS commands = [] - (1..4).each do |i| - commands.push(value[i]) if value[i] && value[i] != nil - end + (1..4).each { |i| commands.push(value[i]) if value[i] } @cmdWindow.commands = commands end diff --git a/Data/Scripts/011_Battle/005_AI/005_AI_Move_EffectScores.rb b/Data/Scripts/011_Battle/005_AI/005_AI_Move_EffectScores.rb index 3e9a2bf4c..08a635dde 100644 --- a/Data/Scripts/011_Battle/005_AI/005_AI_Move_EffectScores.rb +++ b/Data/Scripts/011_Battle/005_AI/005_AI_Move_EffectScores.rb @@ -1748,7 +1748,7 @@ class Battle::AI score -= 40 if skill >= PBTrainerAI.highSkill score -= 100 if !target.lastRegularMoveUsed || - !GameData::Move.get(target.lastRegularMoveUsed).flags.any? { |f| f[/^CanMirrorMove$/i] } + GameData::Move.get(target.lastRegularMoveUsed).flags.none? { |f| f[/^CanMirrorMove$/i] } end #--------------------------------------------------------------------------- when "UseLastMoveUsed" diff --git a/Data/Scripts/011_Battle/006_Other battle code/007_BattleAnimationPlayer.rb b/Data/Scripts/011_Battle/006_Other battle code/007_BattleAnimationPlayer.rb index 7480b6ac3..672ba28b7 100644 --- a/Data/Scripts/011_Battle/006_Other battle code/007_BattleAnimationPlayer.rb +++ b/Data/Scripts/011_Battle/006_Other battle code/007_BattleAnimationPlayer.rb @@ -287,58 +287,46 @@ class PBAnimTiming when 1 text = sprintf("[%d] Set BG: \"%s\"", @frame + 1, name) text += sprintf(" (color=%s,%s,%s,%s)", - (@colorRed != nil) ? @colorRed.to_i : "-", - (@colorGreen != nil) ? @colorGreen.to_i : "-", - (@colorBlue != nil) ? @colorBlue.to_i : "-", - (@colorAlpha != nil) ? @colorAlpha.to_i : "-") - text += sprintf(" (opacity=%s)", @opacity.to_i) - text += sprintf(" (coords=%s,%s)", - (@bgX != nil) ? @bgX : "-", - (@bgY != nil) ? @bgY : "-") + @colorRed || "-", + @colorGreen || "-", + @colorBlue || "-", + @colorAlpha || "-") + text += sprintf(" (opacity=%d)", @opacity) + text += sprintf(" (coords=%s,%s)", @bgX || "-", @bgY || "-") return text when 2 text = sprintf("[%d] Change BG: @%d", @frame + 1, duration) - if @colorRed != nil || @colorGreen != nil || @colorBlue != nil || @colorAlpha != nil + if @colorRed || @colorGreen || @colorBlue || @colorAlpha text += sprintf(" (color=%s,%s,%s,%s)", - (@colorRed != nil) ? @colorRed.to_i : "-", - (@colorGreen != nil) ? @colorGreen.to_i : "-", - (@colorBlue != nil) ? @colorBlue.to_i : "-", - (@colorAlpha != nil) ? @colorAlpha.to_i : "-") - end - text += sprintf(" (opacity=%s)", @opacity.to_i) if @opacity != nil - if @bgX != nil || @bgY != nil - text += sprintf(" (coords=%s,%s)", - (@bgX != nil) ? @bgX : "-", - (@bgY != nil) ? @bgY : "-") + @colorRed || "-", + @colorGreen || "-", + @colorBlue || "-", + @colorAlpha || "-") end + text += sprintf(" (opacity=%d)", @opacity) if @opacity + text += sprintf(" (coords=%s,%s)", @bgX || "-", @bgY || "-") if @bgX || @bgY return text when 3 text = sprintf("[%d] Set FG: \"%s\"", @frame + 1, name) text += sprintf(" (color=%s,%s,%s,%s)", - (@colorRed != nil) ? @colorRed.to_i : "-", - (@colorGreen != nil) ? @colorGreen.to_i : "-", - (@colorBlue != nil) ? @colorBlue.to_i : "-", - (@colorAlpha != nil) ? @colorAlpha.to_i : "-") - text += sprintf(" (opacity=%s)", @opacity.to_i) - text += sprintf(" (coords=%s,%s)", - (@bgX != nil) ? @bgX : "-", - (@bgY != nil) ? @bgY : "-") + @colorRed || "-", + @colorGreen | "-", + @colorBlue || "-", + @colorAlpha || "-") + text += sprintf(" (opacity=%d)", @opacity) + text += sprintf(" (coords=%s,%s)", @bgX || "-", @bgY || "-") return text when 4 text = sprintf("[%d] Change FG: @%d", @frame + 1, duration) - if @colorRed != nil || @colorGreen != nil || @colorBlue != nil || @colorAlpha != nil + if @colorRed || @colorGreen || @colorBlue || @colorAlpha text += sprintf(" (color=%s,%s,%s,%s)", - (@colorRed != nil) ? @colorRed.to_i : "-", - (@colorGreen != nil) ? @colorGreen.to_i : "-", - (@colorBlue != nil) ? @colorBlue.to_i : "-", - (@colorAlpha != nil) ? @colorAlpha.to_i : "-") - end - text += sprintf(" (opacity=%s)", @opacity.to_i) if @opacity != nil - if @bgX != nil || @bgY != nil - text += sprintf(" (coords=%s,%s)", - (@bgX != nil) ? @bgX : "-", - (@bgY != nil) ? @bgY : "-") + @colorRed || "-", + @colorGreen || "-", + @colorBlue || "-", + @colorAlpha || "-") end + text += sprintf(" (opacity=%d)", @opacity) if @opacity + text += sprintf(" (coords=%s,%s)", @bgX || "-", @bgY || "-") if @bgX || @bgY return text end return "" @@ -563,20 +551,20 @@ class PBAnimation < Array next if frame < i.frame || frame > i.frame + i.duration fraction = (frame - i.frame).to_f / i.duration if bgGraphic.bitmap.nil? - bgColor.opacity = oldbg[2] + ((i.opacity - oldbg[2]) * fraction) if i.opacity != nil - cr = (i.colorRed != nil) ? oldbg[3].red + ((i.colorRed - oldbg[3].red) * fraction) : oldbg[3].red - cg = (i.colorGreen != nil) ? oldbg[3].green + ((i.colorGreen - oldbg[3].green) * fraction) : oldbg[3].green - cb = (i.colorBlue != nil) ? oldbg[3].blue + ((i.colorBlue - oldbg[3].blue) * fraction) : oldbg[3].blue - ca = (i.colorAlpha != nil) ? oldbg[3].alpha + ((i.colorAlpha - oldbg[3].alpha) * fraction) : oldbg[3].alpha + bgColor.opacity = oldbg[2] + ((i.opacity - oldbg[2]) * fraction) if i.opacity + cr = (i.colorRed) ? oldbg[3].red + ((i.colorRed - oldbg[3].red) * fraction) : oldbg[3].red + cg = (i.colorGreen) ? oldbg[3].green + ((i.colorGreen - oldbg[3].green) * fraction) : oldbg[3].green + cb = (i.colorBlue) ? oldbg[3].blue + ((i.colorBlue - oldbg[3].blue) * fraction) : oldbg[3].blue + ca = (i.colorAlpha) ? oldbg[3].alpha + ((i.colorAlpha - oldbg[3].alpha) * fraction) : oldbg[3].alpha bgColor.color = Color.new(cr, cg, cb, ca) else - bgGraphic.ox = oldbg[0] - ((i.bgX - oldbg[0]) * fraction) if i.bgX != nil - bgGraphic.oy = oldbg[1] - ((i.bgY - oldbg[1]) * fraction) if i.bgY != nil - bgGraphic.opacity = oldbg[2] + ((i.opacity - oldbg[2]) * fraction) if i.opacity != nil - cr = (i.colorRed != nil) ? oldbg[3].red + ((i.colorRed - oldbg[3].red) * fraction) : oldbg[3].red - cg = (i.colorGreen != nil) ? oldbg[3].green + ((i.colorGreen - oldbg[3].green) * fraction) : oldbg[3].green - cb = (i.colorBlue != nil) ? oldbg[3].blue + ((i.colorBlue - oldbg[3].blue) * fraction) : oldbg[3].blue - ca = (i.colorAlpha != nil) ? oldbg[3].alpha + ((i.colorAlpha - oldbg[3].alpha) * fraction) : oldbg[3].alpha + bgGraphic.ox = oldbg[0] - ((i.bgX - oldbg[0]) * fraction) if i.bgX + bgGraphic.oy = oldbg[1] - ((i.bgY - oldbg[1]) * fraction) if i.bgY + bgGraphic.opacity = oldbg[2] + ((i.opacity - oldbg[2]) * fraction) if i.opacity + cr = (i.colorRed) ? oldbg[3].red + ((i.colorRed - oldbg[3].red) * fraction) : oldbg[3].red + cg = (i.colorGreen) ? oldbg[3].green + ((i.colorGreen - oldbg[3].green) * fraction) : oldbg[3].green + cb = (i.colorBlue) ? oldbg[3].blue + ((i.colorBlue - oldbg[3].blue) * fraction) : oldbg[3].blue + ca = (i.colorAlpha) ? oldbg[3].alpha + ((i.colorAlpha - oldbg[3].alpha) * fraction) : oldbg[3].alpha bgGraphic.color = Color.new(cr, cg, cb, ca) end when 4 @@ -584,20 +572,20 @@ class PBAnimation < Array next if frame < i.frame || frame > i.frame + i.duration fraction = (frame - i.frame).to_f / i.duration if foGraphic.bitmap.nil? - foColor.opacity = oldfo[2] + ((i.opacity - oldfo[2]) * fraction) if i.opacity != nil - cr = (i.colorRed != nil) ? oldfo[3].red + ((i.colorRed - oldfo[3].red) * fraction) : oldfo[3].red - cg = (i.colorGreen != nil) ? oldfo[3].green + ((i.colorGreen - oldfo[3].green) * fraction) : oldfo[3].green - cb = (i.colorBlue != nil) ? oldfo[3].blue + ((i.colorBlue - oldfo[3].blue) * fraction) : oldfo[3].blue - ca = (i.colorAlpha != nil) ? oldfo[3].alpha + ((i.colorAlpha - oldfo[3].alpha) * fraction) : oldfo[3].alpha + foColor.opacity = oldfo[2] + ((i.opacity - oldfo[2]) * fraction) if i.opacity + cr = (i.colorRed) ? oldfo[3].red + ((i.colorRed - oldfo[3].red) * fraction) : oldfo[3].red + cg = (i.colorGreen) ? oldfo[3].green + ((i.colorGreen - oldfo[3].green) * fraction) : oldfo[3].green + cb = (i.colorBlue) ? oldfo[3].blue + ((i.colorBlue - oldfo[3].blue) * fraction) : oldfo[3].blue + ca = (i.colorAlpha) ? oldfo[3].alpha + ((i.colorAlpha - oldfo[3].alpha) * fraction) : oldfo[3].alpha foColor.color = Color.new(cr, cg, cb, ca) else - foGraphic.ox = oldfo[0] - ((i.bgX - oldfo[0]) * fraction) if i.bgX != nil - foGraphic.oy = oldfo[1] - ((i.bgY - oldfo[1]) * fraction) if i.bgY != nil - foGraphic.opacity = oldfo[2] + ((i.opacity - oldfo[2]) * fraction) if i.opacity != nil - cr = (i.colorRed != nil) ? oldfo[3].red + ((i.colorRed - oldfo[3].red) * fraction) : oldfo[3].red - cg = (i.colorGreen != nil) ? oldfo[3].green + ((i.colorGreen - oldfo[3].green) * fraction) : oldfo[3].green - cb = (i.colorBlue != nil) ? oldfo[3].blue + ((i.colorBlue - oldfo[3].blue) * fraction) : oldfo[3].blue - ca = (i.colorAlpha != nil) ? oldfo[3].alpha + ((i.colorAlpha - oldfo[3].alpha) * fraction) : oldfo[3].alpha + foGraphic.ox = oldfo[0] - ((i.bgX - oldfo[0]) * fraction) if i.bgX + foGraphic.oy = oldfo[1] - ((i.bgY - oldfo[1]) * fraction) if i.bgY + foGraphic.opacity = oldfo[2] + ((i.opacity - oldfo[2]) * fraction) if i.opacity + cr = (i.colorRed) ? oldfo[3].red + ((i.colorRed - oldfo[3].red) * fraction) : oldfo[3].red + cg = (i.colorGreen) ? oldfo[3].green + ((i.colorGreen - oldfo[3].green) * fraction) : oldfo[3].green + cb = (i.colorBlue) ? oldfo[3].blue + ((i.colorBlue - oldfo[3].blue) * fraction) : oldfo[3].blue + ca = (i.colorAlpha) ? oldfo[3].alpha + ((i.colorAlpha - oldfo[3].alpha) * fraction) : oldfo[3].alpha foGraphic.color = Color.new(cr, cg, cb, ca) end end diff --git a/Data/Scripts/011_Battle/006_Other battle code/008_Battle_AbilityEffects.rb b/Data/Scripts/011_Battle/006_Other battle code/008_Battle_AbilityEffects.rb index bea15e390..76a25259c 100644 --- a/Data/Scripts/011_Battle/006_Other battle code/008_Battle_AbilityEffects.rb +++ b/Data/Scripts/011_Battle/006_Other battle code/008_Battle_AbilityEffects.rb @@ -68,7 +68,7 @@ module Battle::AbilityEffects def self.trigger(hash, *args, ret: false) new_ret = hash.trigger(*args) - return (new_ret != nil) ? new_ret : ret + return (!new_ret.nil?) ? new_ret : ret end #============================================================================= diff --git a/Data/Scripts/011_Battle/006_Other battle code/009_Battle_ItemEffects.rb b/Data/Scripts/011_Battle/006_Other battle code/009_Battle_ItemEffects.rb index 62a95cc22..1be990b7b 100644 --- a/Data/Scripts/011_Battle/006_Other battle code/009_Battle_ItemEffects.rb +++ b/Data/Scripts/011_Battle/006_Other battle code/009_Battle_ItemEffects.rb @@ -52,7 +52,7 @@ module Battle::ItemEffects def self.trigger(hash, *args, ret: false) new_ret = hash.trigger(*args) - return (new_ret != nil) ? new_ret : ret + return (!new_ret.nil?) ? new_ret : ret end #============================================================================= diff --git a/Data/Scripts/011_Battle/006_Other battle code/010_Battle_PokeBallEffects.rb b/Data/Scripts/011_Battle/006_Other battle code/010_Battle_PokeBallEffects.rb index 2d4a5aff5..aa9557a8a 100644 --- a/Data/Scripts/011_Battle/006_Other battle code/010_Battle_PokeBallEffects.rb +++ b/Data/Scripts/011_Battle/006_Other battle code/010_Battle_PokeBallEffects.rb @@ -9,12 +9,12 @@ module Battle::PokeBallEffects def self.isUnconditional?(ball, battle, battler) ret = IsUnconditional.trigger(ball, battle, battler) - return (ret != nil) ? ret : false + return (!ret.nil?) ? ret : false end def self.modifyCatchRate(ball, catchRate, battle, battler) ret = ModifyCatchRate.trigger(ball, catchRate, battle, battler) - return (ret != nil) ? ret : catchRate + return (!ret.nil?) ? ret : catchRate end def self.onCatch(ball, battle, pkmn) diff --git a/Data/Scripts/011_Battle/007_Other battle types/005_RecordedBattle.rb b/Data/Scripts/011_Battle/007_Other battle types/005_RecordedBattle.rb index 3fdffb6d8..545c5644b 100644 --- a/Data/Scripts/011_Battle/007_Other battle types/005_RecordedBattle.rb +++ b/Data/Scripts/011_Battle/007_Other battle types/005_RecordedBattle.rb @@ -277,14 +277,12 @@ module RecordedBattle::PlaybackHelper trainer.each do |tr| if tr.length == 4 # Player t = Player.new(tr[1], tr[0]) - t.id = tr[2] t.badges = tr[3] - ret.push(t) else # NPCTrainer t = NPCTrainer.new(tr[1], tr[0]) - t.id = tr[2] - ret.push(t) end + t.id = tr[2] + ret.push(t) end return ret end diff --git a/Data/Scripts/012_Overworld/001_Overworld visuals/001_Overworld_Weather.rb b/Data/Scripts/012_Overworld/001_Overworld visuals/001_Overworld_Weather.rb index ec8f335c7..56822729f 100644 --- a/Data/Scripts/012_Overworld/001_Overworld visuals/001_Overworld_Weather.rb +++ b/Data/Scripts/012_Overworld/001_Overworld visuals/001_Overworld_Weather.rb @@ -457,7 +457,7 @@ module RPG end # End fading if @fade_time >= ((@target_type == :None) ? FADE_OLD_PARTICLES_END : FADE_NEW_TILES_END) - @time_shift && - !@sprites.any? { |sprite| sprite.visible } + @sprites.none? { |sprite| sprite.visible } @type = @target_type @max = @target_max @target_type = nil diff --git a/Data/Scripts/012_Overworld/001_Overworld visuals/002_Overworld_Overlays.rb b/Data/Scripts/012_Overworld/001_Overworld visuals/002_Overworld_Overlays.rb index 0ba7e1c61..3871c7e9d 100644 --- a/Data/Scripts/012_Overworld/001_Overworld visuals/002_Overworld_Overlays.rb +++ b/Data/Scripts/012_Overworld/001_Overworld visuals/002_Overworld_Overlays.rb @@ -93,7 +93,7 @@ end class LightEffect def initialize(event, viewport = nil, map = nil, filename = nil) @light = IconSprite.new(0, 0, viewport) - if filename != nil && filename != "" && pbResolveBitmap("Graphics/Pictures/" + filename) + if !nil_or_empty?(filename) && pbResolveBitmap("Graphics/Pictures/" + filename) @light.setBitmap("Graphics/Pictures/" + filename) else @light.setBitmap("Graphics/Pictures/LE") @@ -208,7 +208,7 @@ end EventHandlers.add(:on_new_spriteset_map, :add_light_effects, proc { |spriteset, viewport| map = spriteset.map # Map associated with the spriteset (not necessarily the current map) - map.events.keys.each do |i| + map.events.each_key do |i| if map.events[i].name[/^outdoorlight\((\w+)\)$/i] filename = $~[1].to_s spriteset.addUserSprite(LightEffect_DayNight.new(map.events[i], viewport, map, filename)) diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb b/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb index 61e7f0796..649ff7efe 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb @@ -632,13 +632,12 @@ def pbEvolutionCheck new_species = pkmn.check_evolution_on_level_up end new_species = pkmn.check_evolution_after_battle(i) if new_species.nil? + next if new_species.nil? # Evolve Pokémon if possible - if !new_species.nil? - evo = PokemonEvolutionScene.new - evo.pbStartScreen(pkmn, new_species) - evo.pbEvolution - evo.pbEndScreen - end + evo = PokemonEvolutionScene.new + evo.pbStartScreen(pkmn, new_species) + evo.pbEvolution + evo.pbEndScreen end end diff --git a/Data/Scripts/012_Overworld/002_Overworld_Metadata.rb b/Data/Scripts/012_Overworld/002_Overworld_Metadata.rb index e1b4c1b49..5a0077c45 100644 --- a/Data/Scripts/012_Overworld/002_Overworld_Metadata.rb +++ b/Data/Scripts/012_Overworld/002_Overworld_Metadata.rb @@ -154,10 +154,7 @@ class PokemonMapMetadata def updateMap @erasedEvents.each do |i| - if i[0][0] == $game_map.map_id && i[1] - event = $game_map.events[i[0][1]] - event&.erase - end + $game_map.events[i[0][1]]&.erase if i[0][0] == $game_map.map_id && i[1] end @movedEvents.each do |i| if i[0][0] == $game_map.map_id && i[1] @@ -170,9 +167,7 @@ class PokemonMapMetadata when 8 then $game_map.events[i[0][1]].turn_up end end - if i[1][3] != nil - $game_map.events[i[0][1]].through = i[1][3] - end + $game_map.events[i[0][1]].through = i[1][3] if i[1][3] end end end diff --git a/Data/Scripts/012_Overworld/004_Overworld_FieldMoves.rb b/Data/Scripts/012_Overworld/004_Overworld_FieldMoves.rb index c1cba2e1d..c269ec5f6 100644 --- a/Data/Scripts/012_Overworld/004_Overworld_FieldMoves.rb +++ b/Data/Scripts/012_Overworld/004_Overworld_FieldMoves.rb @@ -11,7 +11,7 @@ module HiddenMoveHandlers def self.addUseMove(item, proc); UseMove.add(item, proc); end def self.hasHandler(item) - return CanUseMove[item] != nil && UseMove[item] != nil + return !CanUseMove[item].nil? && !UseMove[item].nil? end # Returns whether move can be used @@ -370,7 +370,7 @@ end # @deprecated This method is slated to be removed in v21. def pbTransferUnderwater(mapid, x, y, direction = $game_player.direction) - Deprecation.warn_method('pbTransferUnderwater', 'v21', '"Transfer Player" event command') + Deprecation.warn_method("pbTransferUnderwater", "v21", '"Transfer Player" event command') pbFadeOutIn { $game_temp.player_new_map_id = mapid $game_temp.player_new_x = x @@ -787,7 +787,7 @@ end # @deprecated This method is slated to be removed in v21. def pbTransferSurfing(mapid, xcoord, ycoord, direction = $game_player.direction) - Deprecation.warn_method('pbTransferSurfing', 'v21', '"Transfer Player" event command') + Deprecation.warn_method("pbTransferSurfing", "v21", '"Transfer Player" event command') pbFadeOutIn { $game_temp.player_new_map_id = mapid $game_temp.player_new_x = xcoord diff --git a/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb b/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb index b10188289..ecc82c368 100644 --- a/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb +++ b/Data/Scripts/012_Overworld/007_Overworld_DayCare.rb @@ -568,54 +568,54 @@ EventHandlers.add(:on_player_step_taken, :update_day_care, #=============================================================================== # @deprecated This method is slated to be removed in v21. def pbDayCareDeposited - Deprecation.warn_method('pbDayCareDeposited', 'v21', 'DayCare.count') + Deprecation.warn_method("pbDayCareDeposited", "v21", "DayCare.count") return DayCare.count end # @deprecated This method is slated to be removed in v21. def pbDayCareGetDeposited(index, name_var, cost_var) - Deprecation.warn_method('pbDayCareGetDeposited', 'v21', 'DayCare.get_details(index, name_var, cost_var)') + Deprecation.warn_method("pbDayCareGetDeposited", "v21", "DayCare.get_details(index, name_var, cost_var)") DayCare.get_details(index, name_var, cost_var) end # @deprecated This method is slated to be removed in v21. def pbDayCareGetLevelGain(index, name_var, level_var) - Deprecation.warn_method('pbDayCareGetLevelGain', 'v21', 'DayCare.get_level_gain(index, name_var, level_var)') + Deprecation.warn_method("pbDayCareGetLevelGain", "v21", "DayCare.get_level_gain(index, name_var, level_var)") DayCare.get_level_gain(index, name_var, level_var) end # @deprecated This method is slated to be removed in v21. def pbDayCareDeposit(party_index) - Deprecation.warn_method('pbDayCareDeposit', 'v21', 'DayCare.deposit(party_index)') + Deprecation.warn_method("pbDayCareDeposit", "v21", "DayCare.deposit(party_index)") DayCare.deposit(party_index) end # @deprecated This method is slated to be removed in v21. def pbDayCareWithdraw(index) - Deprecation.warn_method('pbDayCareWithdraw', 'v21', 'DayCare.withdraw(index)') + Deprecation.warn_method("pbDayCareWithdraw", "v21", "DayCare.withdraw(index)") DayCare.withdraw(index) end # @deprecated This method is slated to be removed in v21. def pbDayCareChoose(text, choice_var) - Deprecation.warn_method('pbDayCareChoose', 'v21', 'DayCare.choose(text, choice_var)') + Deprecation.warn_method("pbDayCareChoose", "v21", "DayCare.choose(text, choice_var)") DayCare.choose(text, choice_var) end # @deprecated This method is slated to be removed in v21. def pbDayCareGetCompatibility(compat_var) - Deprecation.warn_method('pbDayCareGetCompatibility', 'v21', 'DayCare.get_compatibility(compat_var)') + Deprecation.warn_method("pbDayCareGetCompatibility", "v21", "DayCare.get_compatibility(compat_var)") DayCare.get_compatibility(compat_var) end # @deprecated This method is slated to be removed in v21. def pbEggGenerated? - Deprecation.warn_method('pbEggGenerated?', 'v21', 'DayCare.egg_generated?') + Deprecation.warn_method("pbEggGenerated?", "v21", "DayCare.egg_generated?") return DayCare.egg_generated? end # @deprecated This method is slated to be removed in v21. def pbDayCareGenerateEgg - Deprecation.warn_method('pbDayCareGenerateEgg', 'v21', 'DayCare.collect_egg') + Deprecation.warn_method("pbDayCareGenerateEgg", "v21", "DayCare.collect_egg") DayCare.collect_egg end diff --git a/Data/Scripts/012_Overworld/008_Overworld_RandomDungeons.rb b/Data/Scripts/012_Overworld/008_Overworld_RandomDungeons.rb index b68e7bfe7..fce58313d 100644 --- a/Data/Scripts/012_Overworld/008_Overworld_RandomDungeons.rb +++ b/Data/Scripts/012_Overworld/008_Overworld_RandomDungeons.rb @@ -622,12 +622,11 @@ module RandomDungeonGenerator ((tiles.length + 1) * 1000).times do x = ar1.get y = ar2.get - if dungeon.isRoom?(x, y) && - !tiles.any? { |item| (item[0] - x).abs < 2 && (item[1] - y).abs < 2 } - ret = [x, y] - tiles.push(ret) - return ret - end + next if !dungeon.isRoom?(x, y) || + tiles.any? { |item| (item[0] - x).abs < 2 && (item[1] - y).abs < 2 } + ret = [x, y] + tiles.push(ret) + return ret end return nil end @@ -652,7 +651,7 @@ EventHandlers.add(:on_game_map_setup, :random_dungeon, dungeon.generateMapInPlace(map) roomtiles = [] # Reposition events - map.events.values.each do |event| + map.events.each_value do |event| tile = RandomDungeonGenerator.pbRandomRoomTile(dungeon, roomtiles) if tile event.x = tile[0] diff --git a/Data/Scripts/013_Items/001_Item_Utilities.rb b/Data/Scripts/013_Items/001_Item_Utilities.rb index 9b628f024..773d2d288 100644 --- a/Data/Scripts/013_Items/001_Item_Utilities.rb +++ b/Data/Scripts/013_Items/001_Item_Utilities.rb @@ -14,35 +14,35 @@ module ItemHandlers BattleUseOnPokemon = ItemHandlerHash.new def self.hasUseText(item) - return UseText[item] != nil + return !UseText[item].nil? end def self.hasOutHandler(item) # Shows "Use" option in Bag - return UseFromBag[item] != nil || UseInField[item] != nil || UseOnPokemon[item] != nil + return !UseFromBag[item].nil? || !UseInField[item].nil? || !UseOnPokemon[item].nil? end def self.hasUseInFieldHandler(item) # Shows "Register" option in Bag - return UseInField[item] != nil + return !UseInField[item].nil? end def self.hasUseOnPokemon(item) - return UseOnPokemon[item] != nil + return !UseOnPokemon[item].nil? end def self.hasUseOnPokemonMaximum(item) - return UseOnPokemonMaximum[item] != nil + return !UseOnPokemonMaximum[item].nil? end def self.hasUseInBattle(item) - return UseInBattle[item] != nil + return !UseInBattle[item].nil? end def self.hasBattleUseOnBattler(item) - return BattleUseOnBattler[item] != nil + return !BattleUseOnBattler[item].nil? end def self.hasBattleUseOnPokemon(item) - return BattleUseOnPokemon[item] != nil + return !BattleUseOnPokemon[item].nil? end # Returns text to display instead of "Use" @@ -551,7 +551,7 @@ def pbClosestHiddenItem result = [] playerX = $game_player.x playerY = $game_player.y - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| next if !event.name[/hiddenitem/i] next if (playerX - event.x).abs >= 8 next if (playerY - event.y).abs >= 6 @@ -674,16 +674,13 @@ def pbUseItem(bag, item, bagscene = nil) ) screen.scene.pbSetHelpText("") if screen.is_a?(PokemonPartyScreen) end - if qty >= 1 - ret = ItemHandlers.triggerUseOnPokemon(item, qty, pkmn, screen) - if ret && itm.consumed_after_use? - bag.remove(item, qty) - if !bag.has?(item) - pbMessage(_INTL("You used your last {1}.", itm.name)) { screen.pbUpdate } - break - end - end - end + next if qty <= 0 + ret = ItemHandlers.triggerUseOnPokemon(item, qty, pkmn, screen) + next unless ret && itm.consumed_after_use? + bag.remove(item, qty) + next if bag.has?(item) + pbMessage(_INTL("You used your last {1}.", itm.name)) { screen.pbUpdate } + break end screen.pbEndScene bagscene&.pbRefresh diff --git a/Data/Scripts/013_Items/005_Item_PokeRadar.rb b/Data/Scripts/013_Items/005_Item_PokeRadar.rb index 0da167dd4..d853bfa7f 100644 --- a/Data/Scripts/013_Items/005_Item_PokeRadar.rb +++ b/Data/Scripts/013_Items/005_Item_PokeRadar.rb @@ -74,20 +74,18 @@ def pbPokeRadarHighlightGrass(showmessage = true) y = $game_player.y + i + 1 end # Add tile to grasses array if it's a valid grass tile - if x >= 0 && x < $game_map.width && - y >= 0 && y < $game_map.height - terrain = $game_map.terrain_tag(x, y) - if terrain.land_wild_encounters && terrain.shows_grass_rustle - # Choose a rarity for the grass (0=normal, 1=rare, 2=shiny) - s = (rand(100) < 25) ? 1 : 0 - if $game_temp.poke_radar_data && $game_temp.poke_radar_data[2] > 0 - v = [(65_536 / Settings::SHINY_POKEMON_CHANCE) - ([$game_temp.poke_radar_data[2], 40].min * 200), 200].max - v = (65_536 / v.to_f).ceil - s = 2 if rand(65_536) < v - end - grasses.push([x, y, i, s]) - end + next if x < 0 || x >= $game_map.width || + y < 0 || y >= $game_map.height + terrain = $game_map.terrain_tag(x, y) + next if !terrain.land_wild_encounters || !terrain.shows_grass_rustle + # Choose a rarity for the grass (0=normal, 1=rare, 2=shiny) + s = (rand(100) < 25) ? 1 : 0 + if $game_temp.poke_radar_data && $game_temp.poke_radar_data[2] > 0 + v = [(65_536 / Settings::SHINY_POKEMON_CHANCE) - ([$game_temp.poke_radar_data[2], 40].min * 200), 200].max + v = (65_536 / v.to_f).ceil + s = 2 if rand(65_536) < v end + grasses.push([x, y, i, s]) end if grasses.length == 0 # No shaking grass found, break the chain diff --git a/Data/Scripts/013_Items/008_PokemonBag.rb b/Data/Scripts/013_Items/008_PokemonBag.rb index e7bb9d3e5..778b443bd 100644 --- a/Data/Scripts/013_Items/008_PokemonBag.rb +++ b/Data/Scripts/013_Items/008_PokemonBag.rb @@ -339,91 +339,91 @@ end class PokemonBag # @deprecated This method is slated to be removed in v21. def pbQuantity(item) - Deprecation.warn_method('pbQuantity', 'v21', '$bag.quantity(item)') + Deprecation.warn_method("pbQuantity", "v21", "$bag.quantity(item)") return quantity(item) end # @deprecated This method is slated to be removed in v21. def pbHasItem?(item) - Deprecation.warn_method('pbHasItem?', 'v21', '$bag.has?(item)') + Deprecation.warn_method("pbHasItem?", "v21", "$bag.has?(item)") return has?(item) end # @deprecated This method is slated to be removed in v21. def pbCanStore?(item, quantity = 1) - Deprecation.warn_method('pbCanStore?', 'v21', '$bag.can_add?(item, quantity)') + Deprecation.warn_method("pbCanStore?", "v21", "$bag.can_add?(item, quantity)") return can_add?(item, quantity) end # @deprecated This method is slated to be removed in v21. def pbStoreItem(item, quantity = 1) - Deprecation.warn_method('pbStoreItem', 'v21', '$bag.add(item, quantity)') + Deprecation.warn_method("pbStoreItem", "v21", "$bag.add(item, quantity)") return add(item, quantity) end # @deprecated This method is slated to be removed in v21. def pbStoreAllOrNone(item, quantity = 1) - Deprecation.warn_method('pbStoreAllOrNone', 'v21', '$bag.add_all(item, quantity)') + Deprecation.warn_method("pbStoreAllOrNone", "v21", "$bag.add_all(item, quantity)") return add_all(item, quantity) end # @deprecated This method is slated to be removed in v21. def pbChangeItem(old_item, new_item) - Deprecation.warn_method('pbChangeItem', 'v21', '$bag.replace_item(old_item, new_item)') + Deprecation.warn_method("pbChangeItem", "v21", "$bag.replace_item(old_item, new_item)") return replace_item(old_item, new_item) end # @deprecated This method is slated to be removed in v21. def pbDeleteItem(item, quantity = 1) - Deprecation.warn_method('pbDeleteItem', 'v21', '$bag.remove(item, quantity)') + Deprecation.warn_method("pbDeleteItem", "v21", "$bag.remove(item, quantity)") return remove(item, quantity) end # @deprecated This method is slated to be removed in v21. def pbIsRegistered?(item) - Deprecation.warn_method('pbIsRegistered?', 'v21', '$bag.registered?(item)') + Deprecation.warn_method("pbIsRegistered?", "v21", "$bag.registered?(item)") return registered?(item) end # @deprecated This method is slated to be removed in v21. def pbRegisterItem(item) - Deprecation.warn_method('pbRegisterItem', 'v21', '$bag.register(item)') + Deprecation.warn_method("pbRegisterItem", "v21", "$bag.register(item)") register(item) end # @deprecated This method is slated to be removed in v21. def pbUnregisterItem(item) - Deprecation.warn_method('pbUnregisterItem', 'v21', '$bag.unregister(item)') + Deprecation.warn_method("pbUnregisterItem", "v21", "$bag.unregister(item)") unregister(item) end end # @deprecated This method is slated to be removed in v21. def pbQuantity(item) - Deprecation.warn_method('pbQuantity', 'v21', '$bag.quantity(item)') + Deprecation.warn_method("pbQuantity", "v21", "$bag.quantity(item)") return $bag.quantity(item) end # @deprecated This method is slated to be removed in v21. def pbHasItem?(item) - Deprecation.warn_method('pbHasItem?', 'v21', '$bag.has?(item)') + Deprecation.warn_method("pbHasItem?", "v21", "$bag.has?(item)") return $bag.has?(item) end # @deprecated This method is slated to be removed in v21. def pbCanStore?(item, quantity = 1) - Deprecation.warn_method('pbCanStore?', 'v21', '$bag.can_add?(item, quantity)') + Deprecation.warn_method("pbCanStore?", "v21", "$bag.can_add?(item, quantity)") return $bag.can_add?(item, quantity) end # @deprecated This method is slated to be removed in v21. def pbStoreItem(item, quantity = 1) - Deprecation.warn_method('pbStoreItem', 'v21', '$bag.add(item, quantity)') + Deprecation.warn_method("pbStoreItem", "v21", "$bag.add(item, quantity)") return $bag.add(item, quantity) end # @deprecated This method is slated to be removed in v21. def pbStoreAllOrNone(item, quantity = 1) - Deprecation.warn_method('pbStoreAllOrNone', 'v21', '$bag.add_all(item, quantity)') + Deprecation.warn_method("pbStoreAllOrNone", "v21", "$bag.add_all(item, quantity)") return $bag.add_all(item, quantity) end diff --git a/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb b/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb index 85513cff0..5ff9f7206 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb @@ -40,21 +40,20 @@ def drawSpot(bitmap, spotpattern, x, y, red, green, blue) height.times do |yy| spot = spotpattern[yy] width.times do |xx| - if spot[xx] == 1 - xOrg = (x + xx) << 1 - yOrg = (y + yy) << 1 - color = bitmap.get_pixel(xOrg, yOrg) - r = color.red + red - g = color.green + green - b = color.blue + blue - color.red = [[r, 0].max, 255].min - color.green = [[g, 0].max, 255].min - color.blue = [[b, 0].max, 255].min - bitmap.set_pixel(xOrg, yOrg, color) - bitmap.set_pixel(xOrg + 1, yOrg, color) - bitmap.set_pixel(xOrg, yOrg + 1, color) - bitmap.set_pixel(xOrg + 1, yOrg + 1, color) - end + next if spot[xx] != 1 + xOrg = (x + xx) << 1 + yOrg = (y + yy) << 1 + color = bitmap.get_pixel(xOrg, yOrg) + r = color.red + red + g = color.green + green + b = color.blue + blue + color.red = [[r, 0].max, 255].min + color.green = [[g, 0].max, 255].min + color.blue = [[b, 0].max, 255].min + bitmap.set_pixel(xOrg, yOrg, color) + bitmap.set_pixel(xOrg + 1, yOrg, color) + bitmap.set_pixel(xOrg, yOrg + 1, color) + bitmap.set_pixel(xOrg + 1, yOrg + 1, color) end end end diff --git a/Data/Scripts/014_Pokemon/001_Pokemon-related/002_ShadowPokemon_Other.rb b/Data/Scripts/014_Pokemon/001_Pokemon-related/002_ShadowPokemon_Other.rb index a6adb1480..fbd334f5a 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon-related/002_ShadowPokemon_Other.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon-related/002_ShadowPokemon_Other.rb @@ -149,7 +149,7 @@ end # #=============================================================================== def pbRelicStone - if !$player.party.any? { |pkmn| pkmn.purifiable? } + if $player.party.none? { |pkmn| pkmn.purifiable? } pbMessage(_INTL("You have no Pokémon that can be purified.")) return end @@ -421,17 +421,16 @@ EventHandlers.add(:on_player_step_taken, :lower_heart_gauges, next if pkmn.heart_gauge == 0 pkmn.heart_gauge_step_counter = 0 if !pkmn.heart_gauge_step_counter pkmn.heart_gauge_step_counter += 1 - if pkmn.heart_gauge_step_counter >= 256 - old_stage = pkmn.heartStage - pkmn.change_heart_gauge("walking") - new_stage = pkmn.heartStage - if new_stage == 0 - pkmn.check_ready_to_purify - elsif new_stage != old_stage - pkmn.update_shadow_moves - end - pkmn.heart_gauge_step_counter = 0 + next if pkmn.heart_gauge_step_counter < 256 + old_stage = pkmn.heartStage + pkmn.change_heart_gauge("walking") + new_stage = pkmn.heartStage + if new_stage == 0 + pkmn.check_ready_to_purify + elsif new_stage != old_stage + pkmn.update_shadow_moves end + pkmn.heart_gauge_step_counter = 0 end $PokemonGlobal.purifyChamber&.update } diff --git a/Data/Scripts/014_Pokemon/001_Pokemon-related/004_PokemonStorage.rb b/Data/Scripts/014_Pokemon/001_Pokemon-related/004_PokemonStorage.rb index df6b48497..4dc0c1a73 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon-related/004_PokemonStorage.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon-related/004_PokemonStorage.rb @@ -212,15 +212,14 @@ class PokemonStorage def pbMoveCaughtToBox(pkmn, box) maxPokemon(box).times do |i| - if self[box, i].nil? - if Settings::HEAL_STORED_POKEMON && box >= 0 - old_ready_evo = pkmn.ready_to_evolve - pkmn.heal - pkmn.ready_to_evolve = old_ready_evo - end - self[box, i] = pkmn - return true + next unless self[box, i].nil? + if Settings::HEAL_STORED_POKEMON && box >= 0 + old_ready_evo = pkmn.ready_to_evolve + pkmn.heal + pkmn.ready_to_evolve = old_ready_evo end + self[box, i] = pkmn + return true end return false end @@ -239,11 +238,10 @@ class PokemonStorage end self.maxBoxes.times do |j| maxPokemon(j).times do |i| - if self[j, i].nil? - self[j, i] = pkmn - @currentBox = j - return @currentBox - end + next unless self[j, i].nil? + self[j, i] = pkmn + @currentBox = j + return @currentBox end end return -1 diff --git a/Data/Scripts/014_Pokemon/001_Pokemon.rb b/Data/Scripts/014_Pokemon/001_Pokemon.rb index 4d4069fab..6a1cad90b 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon.rb @@ -106,7 +106,7 @@ class Pokemon def inspect str = super.chop - str << sprintf(' %s Lv.%s>', @species, @level.to_s || '???') + str << sprintf(" %s Lv.%s>", @species, @level.to_s || "???") return str end @@ -143,7 +143,7 @@ class Pokemon return @forced_form if !@forced_form.nil? return @form if $game_temp.in_battle || $game_temp.in_storage calc_form = MultipleForms.call("getForm", self) - self.form = calc_form if calc_form != nil && calc_form != @form + self.form = calc_form if calc_form && calc_form != @form return @form end @@ -250,7 +250,7 @@ class Pokemon return if !able? new_status = GameData::Status.try_get(value) if !new_status - raise ArgumentError, _INTL('Attempted to set {1} as Pokémon status', value.class.name) + raise ArgumentError, _INTL("Attempted to set {1} as Pokémon status", value.class.name) end @status = new_status.id end @@ -311,13 +311,13 @@ class Pokemon # @deprecated This method is slated to be removed in v21. def type1 - Deprecation.warn_method('type1', 'v21', 'pkmn.types') + Deprecation.warn_method("type1", "v21", "pkmn.types") return types[0] end # @deprecated This method is slated to be removed in v21. def type2 - Deprecation.warn_method('type2', 'v21', 'pkmn.types') + Deprecation.warn_method("type2", "v21", "pkmn.types") return types[1] || types[0] end @@ -588,7 +588,7 @@ class Pokemon # @param mail [Mail, nil] mail to be held by this Pokémon def mail=(mail) if !mail.nil? && !mail.is_a?(Mail) - raise ArgumentError, _INTL('Invalid value {1} given', mail.inspect) + raise ArgumentError, _INTL("Invalid value {1} given", mail.inspect) end @mail = mail end @@ -1185,7 +1185,7 @@ class Pokemon when Player, NPCTrainer @owner = Owner.new_from_trainer(owner) else - @owner = Owner.new(0, '', 2, 2) + @owner = Owner.new(0, "", 2, 2) end @obtain_method = 0 # Met @obtain_method = 4 if $game_switches && $game_switches[Settings::FATEFUL_ENCOUNTER_SWITCH] diff --git a/Data/Scripts/014_Pokemon/005_Pokemon_Owner.rb b/Data/Scripts/014_Pokemon/005_Pokemon_Owner.rb index d671ee5f2..08d4f9f6b 100644 --- a/Data/Scripts/014_Pokemon/005_Pokemon_Owner.rb +++ b/Data/Scripts/014_Pokemon/005_Pokemon_Owner.rb @@ -37,7 +37,7 @@ class Pokemon # @param gender [Integer] owner gender # @param language [Integer] owner language # @return [Owner] foreign Owner object - def self.new_foreign(name = '', gender = 2, language = 2) + def self.new_foreign(name = "", gender = 2, language = 2) return new($player.make_foreign_ID, name, gender, language) end diff --git a/Data/Scripts/015_Trainers and player/001_Trainer.rb b/Data/Scripts/015_Trainers and player/001_Trainer.rb index 301643ce0..a9ca34466 100644 --- a/Data/Scripts/015_Trainers and player/001_Trainer.rb +++ b/Data/Scripts/015_Trainers and player/001_Trainer.rb @@ -11,7 +11,7 @@ class Trainer def inspect str = super.chop party_str = @party.map { |p| p.species_data.species }.inspect - str << sprintf(' %s @party=%s>', self.full_name, party_str) + str << sprintf(" %s @party=%s>", self.full_name, party_str) return str end diff --git a/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb b/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb index 28e46bee7..58289aa6d 100644 --- a/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb +++ b/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb @@ -7,7 +7,7 @@ class Player < Trainer def inspect str = super.chop - str << sprintf(' seen: %d, owned: %d>', self.seen_count, self.owned_count) + str << sprintf(" seen: %d, owned: %d>", self.seen_count, self.owned_count) return str end diff --git a/Data/Scripts/016_UI/001_Non-interactive UI/001_UI_SplashesAndTitleScreen.rb b/Data/Scripts/016_UI/001_Non-interactive UI/001_UI_SplashesAndTitleScreen.rb index d6a4f1b20..f56f5354b 100644 --- a/Data/Scripts/016_UI/001_Non-interactive UI/001_UI_SplashesAndTitleScreen.rb +++ b/Data/Scripts/016_UI/001_Non-interactive UI/001_UI_SplashesAndTitleScreen.rb @@ -1,9 +1,9 @@ class IntroEventScene < EventScene # Splash screen images that appear for a few seconds and then disappear. - SPLASH_IMAGES = ['splash1', 'splash2'] + SPLASH_IMAGES = ["splash1", "splash2"] # The main title screen background image. - TITLE_BG_IMAGE = 'title' - TITLE_START_IMAGE = 'start' + TITLE_BG_IMAGE = "title" + TITLE_START_IMAGE = "start" TITLE_START_IMAGE_X = 0 TITLE_START_IMAGE_Y = 322 SECONDS_PER_SPLASH = 2 diff --git a/Data/Scripts/016_UI/003_UI_Pokedex_Main.rb b/Data/Scripts/016_UI/003_UI_Pokedex_Main.rb index 9790c48e9..17a506daf 100644 --- a/Data/Scripts/016_UI/003_UI_Pokedex_Main.rb +++ b/Data/Scripts/016_UI/003_UI_Pokedex_Main.rb @@ -419,7 +419,7 @@ class PokemonPokedex_Scene dexname = _INTL("Pokédex") if $player.pokedex.dexes_count > 1 thisdex = Settings.pokedex_names[pbGetSavePositionIndex] - if thisdex != nil + if thisdex dexname = (thisdex.is_a?(Array)) ? thisdex[0] : thisdex end end @@ -1166,40 +1166,40 @@ class PokemonPokedex_Scene case index when 0 # Choose sort order newparam = pbDexSearchCommands(0, [params[0]], index) - params[0] = newparam[0] if newparam != nil + params[0] = newparam[0] if newparam pbRefreshDexSearch(params, index) when 1 # Filter by name newparam = pbDexSearchCommands(1, [params[1]], index) - params[1] = newparam[0] if newparam != nil + params[1] = newparam[0] if newparam pbRefreshDexSearch(params, index) when 2 # Filter by type newparam = pbDexSearchCommands(2, [params[2], params[3]], index) - if newparam != nil + if newparam params[2] = newparam[0] params[3] = newparam[1] end pbRefreshDexSearch(params, index) when 3 # Filter by height range newparam = pbDexSearchCommands(3, [params[4], params[5]], index) - if newparam != nil + if newparam params[4] = newparam[0] params[5] = newparam[1] end pbRefreshDexSearch(params, index) when 4 # Filter by weight range newparam = pbDexSearchCommands(4, [params[6], params[7]], index) - if newparam != nil + if newparam params[6] = newparam[0] params[7] = newparam[1] end pbRefreshDexSearch(params, index) when 5 # Filter by color filter newparam = pbDexSearchCommands(5, [params[8]], index) - params[8] = newparam[0] if newparam != nil + params[8] = newparam[0] if newparam pbRefreshDexSearch(params, index) when 6 # Filter by shape newparam = pbDexSearchCommands(6, [params[9]], index) - params[9] = newparam[0] if newparam != nil + params[9] = newparam[0] if newparam pbRefreshDexSearch(params, index) when 7 # Clear filters 10.times do |i| diff --git a/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb b/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb index 20e290451..f81c6a539 100644 --- a/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb +++ b/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb @@ -27,14 +27,13 @@ class PokemonPokedexInfo_Scene @sprites["areamap"].x += (Graphics.width - @sprites["areamap"].bitmap.width) / 2 @sprites["areamap"].y += (Graphics.height + 32 - @sprites["areamap"].bitmap.height) / 2 Settings::REGION_MAP_EXTRAS.each do |hidden| - if hidden[0] == @region && hidden[1] > 0 && $game_switches[hidden[1]] - pbDrawImagePositions( - @sprites["areamap"].bitmap, - [["Graphics/Pictures/#{hidden[4]}", - hidden[2] * PokemonRegionMap_Scene::SQUARE_WIDTH, - hidden[3] * PokemonRegionMap_Scene::SQUARE_HEIGHT]] - ) - end + next if hidden[0] != @region || hidden[1] <= 0 || !$game_switches[hidden[1]] + pbDrawImagePositions( + @sprites["areamap"].bitmap, + [["Graphics/Pictures/#{hidden[4]}", + hidden[2] * PokemonRegionMap_Scene::SQUARE_WIDTH, + hidden[3] * PokemonRegionMap_Scene::SQUARE_HEIGHT]] + ) end @sprites["areahighlight"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport) @sprites["areaoverlay"] = IconSprite.new(0, 0, @viewport) @@ -331,24 +330,23 @@ class PokemonPokedexInfo_Scene sqwidth = PokemonRegionMap_Scene::SQUARE_WIDTH sqheight = PokemonRegionMap_Scene::SQUARE_HEIGHT points.length.times do |j| - if points[j] - x = (j % mapwidth) * sqwidth - x += (Graphics.width - @sprites["areamap"].bitmap.width) / 2 - y = (j / mapwidth) * sqheight - y += (Graphics.height + 32 - @sprites["areamap"].bitmap.height) / 2 - @sprites["areahighlight"].bitmap.fill_rect(x, y, sqwidth, sqheight, pointcolor) - if j - mapwidth < 0 || !points[j - mapwidth] - @sprites["areahighlight"].bitmap.fill_rect(x, y - 2, sqwidth, 2, pointcolorhl) - end - if j + mapwidth >= points.length || !points[j + mapwidth] - @sprites["areahighlight"].bitmap.fill_rect(x, y + sqheight, sqwidth, 2, pointcolorhl) - end - if j % mapwidth == 0 || !points[j - 1] - @sprites["areahighlight"].bitmap.fill_rect(x - 2, y, 2, sqheight, pointcolorhl) - end - if (j + 1) % mapwidth == 0 || !points[j + 1] - @sprites["areahighlight"].bitmap.fill_rect(x + sqwidth, y, 2, sqheight, pointcolorhl) - end + next if !points[j] + x = (j % mapwidth) * sqwidth + x += (Graphics.width - @sprites["areamap"].bitmap.width) / 2 + y = (j / mapwidth) * sqheight + y += (Graphics.height + 32 - @sprites["areamap"].bitmap.height) / 2 + @sprites["areahighlight"].bitmap.fill_rect(x, y, sqwidth, sqheight, pointcolor) + if j - mapwidth < 0 || !points[j - mapwidth] + @sprites["areahighlight"].bitmap.fill_rect(x, y - 2, sqwidth, 2, pointcolorhl) + end + if j + mapwidth >= points.length || !points[j + mapwidth] + @sprites["areahighlight"].bitmap.fill_rect(x, y + sqheight, sqwidth, 2, pointcolorhl) + end + if j % mapwidth == 0 || !points[j - 1] + @sprites["areahighlight"].bitmap.fill_rect(x - 2, y, 2, sqheight, pointcolorhl) + end + if (j + 1) % mapwidth == 0 || !points[j + 1] + @sprites["areahighlight"].bitmap.fill_rect(x + sqwidth, y, 2, sqheight, pointcolorhl) end end # Set the text diff --git a/Data/Scripts/016_UI/005_UI_Party.rb b/Data/Scripts/016_UI/005_UI_Party.rb index f33552dea..25174adc3 100644 --- a/Data/Scripts/016_UI/005_UI_Party.rb +++ b/Data/Scripts/016_UI/005_UI_Party.rb @@ -593,7 +593,7 @@ class PokemonParty_Scene end def pbHasAnnotations? - return @sprites["pokemon0"].text != nil + return !@sprites["pokemon0"].text.nil? end def pbAnnotate(annot) @@ -1328,7 +1328,6 @@ MenuHandlers.add(:party_menu, :item, { "order" => 50, "condition" => proc { |screen, party, party_idx| next !party[party_idx].egg? && !party[party_idx].mail }, "effect" => proc { |screen, party, party_idx| - pkmn = party[party_idx] # Get all commands command_list = [] commands = [] diff --git a/Data/Scripts/016_UI/006_UI_Summary.rb b/Data/Scripts/016_UI/006_UI_Summary.rb index 765c41e04..b822ec413 100644 --- a/Data/Scripts/016_UI/006_UI_Summary.rb +++ b/Data/Scripts/016_UI/006_UI_Summary.rb @@ -1048,15 +1048,14 @@ class PokemonSummary_Scene hasMovedCursor = true pbPlayCursorSE end - if hasMovedCursor - @ribbonOffset = (selribbon / 4).floor if selribbon < @ribbonOffset * 4 - @ribbonOffset = (selribbon / 4).floor - 2 if selribbon >= (@ribbonOffset + 3) * 4 - @ribbonOffset = 0 if @ribbonOffset < 0 - @ribbonOffset = numRows - 3 if @ribbonOffset > numRows - 3 - @sprites["ribbonsel"].index = selribbon - (@ribbonOffset * 4) - @sprites["ribbonpresel"].index = oldselribbon - (@ribbonOffset * 4) - drawSelectedRibbon(@pokemon.ribbons[selribbon]) - end + next if !hasMovedCursor + @ribbonOffset = (selribbon / 4).floor if selribbon < @ribbonOffset * 4 + @ribbonOffset = (selribbon / 4).floor - 2 if selribbon >= (@ribbonOffset + 3) * 4 + @ribbonOffset = 0 if @ribbonOffset < 0 + @ribbonOffset = numRows - 3 if @ribbonOffset > numRows - 3 + @sprites["ribbonsel"].index = selribbon - (@ribbonOffset * 4) + @sprites["ribbonpresel"].index = oldselribbon - (@ribbonOffset * 4) + drawSelectedRibbon(@pokemon.ribbons[selribbon]) end @sprites["ribbonsel"].visible = false end diff --git a/Data/Scripts/016_UI/007_UI_Bag.rb b/Data/Scripts/016_UI/007_UI_Bag.rb index 3a5c6d8c0..a4c355a55 100644 --- a/Data/Scripts/016_UI/007_UI_Bag.rb +++ b/Data/Scripts/016_UI/007_UI_Bag.rb @@ -270,11 +270,10 @@ class PokemonBag_Scene @sprites["pocketicon"].bitmap.clear if @choosing && @filterlist (1...@bag.pockets.length).each do |i| - if @filterlist[i].length == 0 - @sprites["pocketicon"].bitmap.blt( - 6 + ((i - 1) * 22), 6, @pocketbitmap.bitmap, Rect.new((i - 1) * 20, 28, 20, 20) - ) - end + next if @filterlist[i].length > 0 + @sprites["pocketicon"].bitmap.blt( + 6 + ((i - 1) * 22), 6, @pocketbitmap.bitmap, Rect.new((i - 1) * 20, 28, 20, 20) + ) end end @sprites["pocketicon"].bitmap.blt( @@ -685,16 +684,14 @@ class PokemonBagScreen if qty > 1 qty = @scene.pbChooseNumber(_INTL("Toss out how many {1}?", itemnameplural), qty) end - if qty > 0 - itemname = itemnameplural if qty > 1 - if pbConfirm(_INTL("Is it OK to throw away {1} {2}?", qty, itemname)) - if !storage.remove(item, qty) - raise "Can't delete items from storage" - end - @scene.pbRefresh - pbDisplay(_INTL("Threw away {1} {2}.", qty, itemname)) - end + next if qty <= 0 + itemname = itemnameplural if qty > 1 + next if !pbConfirm(_INTL("Is it OK to throw away {1} {2}?", qty, itemname)) + if !storage.remove(item, qty) + raise "Can't delete items from storage" end + @scene.pbRefresh + pbDisplay(_INTL("Threw away {1} {2}.", qty, itemname)) end @scene.pbEndScene end diff --git a/Data/Scripts/016_UI/013_UI_Load.rb b/Data/Scripts/016_UI/013_UI_Load.rb index c23024e85..4a4dfc145 100644 --- a/Data/Scripts/016_UI/013_UI_Load.rb +++ b/Data/Scripts/016_UI/013_UI_Load.rb @@ -226,9 +226,9 @@ class PokemonLoadScreen def load_save_file(file_path) save_data = SaveData.read_from_file(file_path) unless SaveData.valid?(save_data) - if File.file?(file_path + '.bak') - pbMessage(_INTL('The save file is corrupt. A backup will be loaded.')) - save_data = load_save_file(file_path + '.bak') + if File.file?(file_path + ".bak") + pbMessage(_INTL("The save file is corrupt. A backup will be loaded.")) + save_data = load_save_file(file_path + ".bak") else self.prompt_save_deletion return {} @@ -240,9 +240,9 @@ class PokemonLoadScreen # Called if all save data is invalid. # Prompts the player to delete the save files. def prompt_save_deletion - pbMessage(_INTL('The save file is corrupt, or is incompatible with this game.')) + pbMessage(_INTL("The save file is corrupt, or is incompatible with this game.")) exit unless pbConfirmMessageSerious( - _INTL('Do you want to delete the save file and start anew?') + _INTL("Do you want to delete the save file and start anew?") ) self.delete_save_data $game_system = Game_System.new @@ -270,9 +270,9 @@ class PokemonLoadScreen def delete_save_data begin SaveData.delete_file - pbMessage(_INTL('The saved data was deleted.')) + pbMessage(_INTL("The saved data was deleted.")) rescue SystemCallError - pbMessage(_INTL('All saved data could not be deleted.')) + pbMessage(_INTL("All saved data could not be deleted.")) end end @@ -287,16 +287,16 @@ class PokemonLoadScreen cmd_quit = -1 show_continue = !@save_data.empty? if show_continue - commands[cmd_continue = commands.length] = _INTL('Continue') + commands[cmd_continue = commands.length] = _INTL("Continue") if @save_data[:player].mystery_gift_unlocked - commands[cmd_mystery_gift = commands.length] = _INTL('Mystery Gift') + commands[cmd_mystery_gift = commands.length] = _INTL("Mystery Gift") end end - commands[cmd_new_game = commands.length] = _INTL('New Game') - commands[cmd_options = commands.length] = _INTL('Options') - commands[cmd_language = commands.length] = _INTL('Language') if Settings::LANGUAGES.length >= 2 - commands[cmd_debug = commands.length] = _INTL('Debug') if $DEBUG - commands[cmd_quit = commands.length] = _INTL('Quit Game') + commands[cmd_new_game = commands.length] = _INTL("New Game") + commands[cmd_options = commands.length] = _INTL("Options") + commands[cmd_language = commands.length] = _INTL("Language") if Settings::LANGUAGES.length >= 2 + commands[cmd_debug = commands.length] = _INTL("Debug") if $DEBUG + commands[cmd_quit = commands.length] = _INTL("Quit Game") map_id = show_continue ? @save_data[:map_factory].map.map_id : 0 @scene.pbStartScene(commands, show_continue, @save_data[:player], @save_data[:frame_count] || 0, @save_data[:stats], map_id) @@ -325,10 +325,10 @@ class PokemonLoadScreen when cmd_language @scene.pbEndScene $PokemonSystem.language = pbChooseLanguage - pbLoadMessages('Data/' + Settings::LANGUAGES[$PokemonSystem.language][1]) + pbLoadMessages("Data/" + Settings::LANGUAGES[$PokemonSystem.language][1]) if show_continue @save_data[:pokemon_system] = $PokemonSystem - File.open(SaveData::FILE_PATH, 'wb') { |file| Marshal.dump(@save_data, file) } + File.open(SaveData::FILE_PATH, "wb") { |file| Marshal.dump(@save_data, file) } end $scene = pbCallTitle return diff --git a/Data/Scripts/016_UI/014_UI_Save.rb b/Data/Scripts/016_UI/014_UI_Save.rb index d126894c2..38c168f7d 100644 --- a/Data/Scripts/016_UI/014_UI_Save.rb +++ b/Data/Scripts/016_UI/014_UI_Save.rb @@ -4,8 +4,8 @@ def pbEmergencySave pbMessage(_INTL("The script is taking too long. The game will restart.")) return if !$player if SaveData.exists? - File.open(SaveData::FILE_PATH, 'rb') do |r| - File.open(SaveData::FILE_PATH + '.bak', 'wb') do |w| + File.open(SaveData::FILE_PATH, "rb") do |r| + File.open(SaveData::FILE_PATH + ".bak", "wb") do |w| loop do s = r.read(4096) break if !s @@ -84,19 +84,19 @@ class PokemonSaveScreen def pbSaveScreen ret = false @scene.pbStartScreen - if pbConfirmMessage(_INTL('Would you like to save the game?')) + if pbConfirmMessage(_INTL("Would you like to save the game?")) if SaveData.exists? && $game_temp.begun_new_game - pbMessage(_INTL('WARNING!')) - pbMessage(_INTL('There is a different game file that is already saved.')) + pbMessage(_INTL("WARNING!")) + pbMessage(_INTL("There is a different game file that is already saved.")) pbMessage(_INTL("If you save now, the other file's adventure, including items and Pokémon, will be entirely lost.")) - if !pbConfirmMessageSerious(_INTL('Are you sure you want to save now and overwrite the other save file?')) - pbSEPlay('GUI save choice') + if !pbConfirmMessageSerious(_INTL("Are you sure you want to save now and overwrite the other save file?")) + pbSEPlay("GUI save choice") @scene.pbEndScreen return false end end $game_temp.begun_new_game = false - pbSEPlay('GUI save choice') + pbSEPlay("GUI save choice") if Game.save pbMessage(_INTL("\\se[]{1} saved the game.\\me[GUI save game]\\wtnp[30]", $player.name)) ret = true @@ -105,7 +105,7 @@ class PokemonSaveScreen ret = false end else - pbSEPlay('GUI save choice') + pbSEPlay("GUI save choice") end @scene.pbEndScreen return ret diff --git a/Data/Scripts/016_UI/015_UI_Options.rb b/Data/Scripts/016_UI/015_UI_Options.rb index a9f3b76f9..94bbf70cf 100644 --- a/Data/Scripts/016_UI/015_UI_Options.rb +++ b/Data/Scripts/016_UI/015_UI_Options.rb @@ -193,14 +193,14 @@ class Window_PokemonOption < Window_DrawableCommand when EnumOption if @options[index].values.length > 1 totalwidth = 0 - @options[index].values.each do |value| + @options[index].each_value do |value| totalwidth += self.contents.text_size(value).width end spacing = (rect.width - rect.x - optionwidth - totalwidth) / (@options[index].values.length - 1) spacing = 0 if spacing < 0 xpos = optionwidth + rect.x ivalue = 0 - @options[index].values.each do |value| + @options[index].each_value do |value| pbDrawShadowText(self.contents, xpos, rect.y, optionwidth, rect.height, value, (ivalue == self[index]) ? SEL_VALUE_BASE_COLOR : self.baseColor, (ivalue == self[index]) ? SEL_VALUE_SHADOW_COLOR : self.shadowColor) @@ -215,7 +215,7 @@ class Window_PokemonOption < Window_DrawableCommand when NumberOption value = _INTL("Type {1}/{2}", @options[index].lowest_value + self[index], @options[index].highest_value - @options[index].lowest_value + 1) - xpos = optionwidth + rect.x * 2 + xpos = optionwidth + (rect.x * 2) pbDrawShadowText(self.contents, xpos, rect.y, optionwidth, rect.height, value, SEL_VALUE_BASE_COLOR, SEL_VALUE_SHADOW_COLOR, 1) when SliderOption diff --git a/Data/Scripts/016_UI/017_UI_PokemonStorage.rb b/Data/Scripts/016_UI/017_UI_PokemonStorage.rb index cc8c1d06d..df223ae42 100644 --- a/Data/Scripts/016_UI/017_UI_PokemonStorage.rb +++ b/Data/Scripts/016_UI/017_UI_PokemonStorage.rb @@ -543,12 +543,11 @@ class PokemonBoxPartySprite < SpriteWrapper @pokemonsprites.each { |sprite| sprite&.refresh } Settings::MAX_PARTY_SIZE.times do |j| sprite = @pokemonsprites[j] - if sprite && !sprite.disposed? - sprite.viewport = self.viewport - sprite.x = self.x + xvalues[j] - sprite.y = self.y + yvalues[j] - sprite.z = 0 - end + next if sprite.nil? || sprite.disposed? + sprite.viewport = self.viewport + sprite.x = self.x + xvalues[j] + sprite.y = self.y + yvalues[j] + sprite.z = 0 end end diff --git a/Data/Scripts/016_UI/022_UI_PurifyChamber.rb b/Data/Scripts/016_UI/022_UI_PurifyChamber.rb index fcfa54338..ae35bcc02 100644 --- a/Data/Scripts/016_UI/022_UI_PurifyChamber.rb +++ b/Data/Scripts/016_UI/022_UI_PurifyChamber.rb @@ -126,7 +126,7 @@ class PurifyChamberSet unless value&.shadowPokemon? @list.insert(index + 1, value) @list.compact! - @facing += 1 if @facing > index && value != nil + @facing += 1 if @facing > index && value @facing = [[@facing, @list.length - 1].min, 0].max end end @@ -246,16 +246,16 @@ class PurifyChamber isPurifiableIgnoreRegular?(set) && setCount(set) > 0 end - def update # called each step + # Called upon each step taken in the overworld + def update NUMSETS.times do |set| - # If a shadow Pokemon and a regular Pokemon are on the same set - if @sets[set].shadow && @sets[set].shadow.heart_gauge > 0 - flow = self.chamberFlow(set) - @sets[set].shadow.adjustHeart(-flow) - if isPurifiable?(set) - pbMessage(_INTL("Your {1} in the Purify Chamber is ready for purification!", @sets[set].shadow.name)) - end - end + next if !@sets[set].shadow || @sets[set].shadow.heart_gauge <= 0 + # If a Shadow Pokemon and a regular Pokemon are on the same set + flow = self.chamberFlow(set) + @sets[set].shadow.adjustHeart(-flow) + next if !isPurifiable?(set) + pbMessage(_INTL("Your {1} in the Purify Chamber is ready for purification!", + @sets[set].shadow.name)) end end @@ -1261,11 +1261,10 @@ class PurifyChamberScene set = @sprites["setview"].set (@chamber.setCount(set) * 2).times do |i| p = PurifyChamberHelper.pbGetPokemon2(@chamber, set, i) - if p - startindex = party.length if i == pos - party.push(p) - indexes.push(i) - end + next if !p + startindex = party.length if i == pos + party.push(p) + indexes.push(i) end return if party.length == 0 oldsprites = pbFadeOutAndHide(@sprites) diff --git a/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb b/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb index 409c94ed0..0289d46b0 100644 --- a/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb +++ b/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb @@ -553,11 +553,10 @@ class TriadScene (@battle.width * @battle.height).times do |i| x = i % @battle.width y = i / @battle.width - if @boardSprites[i] - owner = @battle.getOwner(x, y) - @boardSprites[i].bitmap&.dispose - @boardSprites[i].bitmap = @boardCards[i].createBitmap(owner) - end + next if !@boardSprites[i] + @boardSprites[i].bitmap&.dispose + owner = @battle.getOwner(x, y) + @boardSprites[i].bitmap = @boardCards[i].createBitmap(owner) end end @@ -655,7 +654,7 @@ class TriadScreen panels[7] = (@wrapAround ? 0 : @height - 1) if panels[7] > @height - 1 # bottom attacker = attackerParam.nil? ? @board[(y * @width) + x] : attackerParam flips = [] - return nil if attackerParam != nil && @board[(y * @width) + x].owner != 0 + return nil if attackerParam && @board[(y * @width) + x].owner != 0 return nil if !attacker.card || attacker.owner == 0 4.times do |i| defenderX = panels[i * 2] @@ -830,9 +829,7 @@ class TriadScreen y = i / @width square.type = @board[i].type flips = flipBoard(x, y, square) - if flips != nil - scores.push([cardIndex, x, y, flips.length]) - end + scores.push([cardIndex, x, y, flips.length]) if flips end end # Sort by number of flips diff --git a/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb b/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb index 93fc2cdbd..a57accc4a 100644 --- a/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb +++ b/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb @@ -53,11 +53,10 @@ class VoltorbFlip squareValues[i] = rand(2..3) total *= squareValues[i] end - if total > LEVEL_RANGES[@level - 1][1] - # Lowers value of square to 1 if over max - total /= squareValues[i] - squareValues[i] = 1 - end + next if total <= LEVEL_RANGES[@level - 1][1] + # Lowers value of square to 1 if over max + total /= squareValues[i] + squareValues[i] = 1 end # Randomize the values a little 25.times do |i| @@ -67,11 +66,10 @@ class VoltorbFlip squareValues[i] -= 1 total *= squareValues[i] end - if total < LEVEL_RANGES[@level - 1][0] && squareValues[i] > 0 - total /= squareValues[i] - squareValues[i] = temp - total *= squareValues[i] - end + next if total >= LEVEL_RANGES[@level - 1][0] || squareValues[i] <= 0 + total /= squareValues[i] + squareValues[i] = temp + total *= squareValues[i] end # Populate @squares array 25.times do |i| diff --git a/Data/Scripts/017_Minigames/005_Minigame_Lottery.rb b/Data/Scripts/017_Minigames/005_Minigame_Lottery.rb index 79c7eef7a..8851790cc 100644 --- a/Data/Scripts/017_Minigames/005_Minigame_Lottery.rb +++ b/Data/Scripts/017_Minigames/005_Minigame_Lottery.rb @@ -20,33 +20,25 @@ def pbLottery(winnum, nameVar = 2, positionVar = 3, matchedVar = 4) thismatched = 0 id = i.owner.public_id 5.times do |j| - if (id / (10**j)) % 10 == (winnum / (10**j)) % 10 - thismatched += 1 - else - break - end - end - if thismatched > winmatched - winpoke = i.name - winpos = 1 # Party - winmatched = thismatched + break if (id / (10**j)) % 10 != (winnum / (10**j)) % 10 + thismatched += 1 end + next if thismatched <= winmatched + winpoke = i.name + winpos = 1 # Party + winmatched = thismatched end pbEachPokemon { |poke, _box| thismatched = 0 id = poke.owner.public_id 5.times do |j| - if (id / (10**j)) % 10 == (winnum / (10**j)) % 10 - thismatched += 1 - else - break - end - end - if thismatched > winmatched - winpoke = poke.name - winpos = 2 # Storage - winmatched = thismatched + break if (id / (10**j)) % 10 != (winnum / (10**j)) % 10 + thismatched += 1 end + next if thismatched <= winmatched + winpoke = poke.name + winpos = 2 # Storage + winmatched = thismatched } $game_variables[nameVar] = winpoke $game_variables[positionVar] = winpos diff --git a/Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb b/Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb index 3aad737e1..1e7a1cdd3 100644 --- a/Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb +++ b/Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb @@ -73,12 +73,11 @@ class TilePuzzleCursor < BitmapSprite yin = [@tileheight - (@cursorbitmap.height / 2) + expand, (@tileheight - (@cursorbitmap.height / 2)) / 2, (@tileheight - (@cursorbitmap.height / 2)) / 2, -expand] 4.times do |i| - if @arrows[i] - self.bitmap.blt(x + xin[i], y + yin[i], @cursorbitmap.bitmap, - Rect.new((@cursorbitmap.width / 2) + ((i % 2) * (@cursorbitmap.width / 4)), - (i / 2) * (@cursorbitmap.height / 2), - @cursorbitmap.width / 4, @cursorbitmap.height / 2)) - end + next if !@arrows[i] + self.bitmap.blt(x + xin[i], y + yin[i], @cursorbitmap.bitmap, + Rect.new((@cursorbitmap.width / 2) + ((i % 2) * (@cursorbitmap.width / 4)), + (i / 2) * (@cursorbitmap.height / 2), + @cursorbitmap.width / 4, @cursorbitmap.height / 2)) end end end diff --git a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/002_Challenge_Data.rb b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/002_Challenge_Data.rb index 68129aa95..0e8118a8b 100644 --- a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/002_Challenge_Data.rb +++ b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/002_Challenge_Data.rb @@ -44,7 +44,7 @@ def pbEntryScreen(*arg) # Set party pbBattleChallenge.setParty(ret) if ret # Continue (return true) if Pokémon were chosen - retval = (ret != nil && ret.length > 0) + retval = (ret && ret.length > 0) } return retval end diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/001_ChallengeGenerator_Data.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/001_ChallengeGenerator_Data.rb index f0202b60a..b6da49dba 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/001_ChallengeGenerator_Data.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/001_ChallengeGenerator_Data.rb @@ -231,7 +231,7 @@ def pbGenerateChallenge(rule, tag) i = 0 loop do changed = false - teams.length.times { |j| + teams.length.times do |j| yield(nil) other = j 5.times do @@ -241,19 +241,14 @@ def pbGenerateChallenge(rule, tag) next if other == j changed = true pbRuledBattle(teams[j], teams[other], rule) - } + end i += 1 gameCount = 0 - teams.each do |team| - gameCount += team.games - end + teams.each { |team| gameCount += team.games } yield(nil) - if gameCount / teams.length >= 12 - teams.each do |team| - team.updateRating - end - break - end + next if gameCount / teams.length < 12 + teams.each { |team| team.updateRating } + break end teams.sort! { |a, b| b.rating <=> a.rating } save_data(teams, tag + "_teams.rxdata") diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb index c5e34f41a..07efc0b12 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb @@ -305,12 +305,11 @@ def pbRandomPokemonFromRule(rules, trainer) hasNormal = false newmoves.each do |move| d = GameData::Move.get(move) - if d.base_damage >= 1 - totalbasedamage += d.base_damage - hasNormal = true if d.type == :NORMAL - hasPhysical = true if d.category == 0 - hasSpecial = true if d.category == 1 - end + next if d.base_damage == 0 + totalbasedamage += d.base_damage + hasNormal = true if d.type == :NORMAL + hasPhysical = true if d.category == 0 + hasSpecial = true if d.category == 1 end if !hasPhysical && ev.include?(:ATTACK) && rand(100) < 80 # No physical attack, but emphasizes Attack @@ -339,17 +338,17 @@ def pbRandomPokemonFromRule(rules, trainer) break end end - if item == :LIGHTCLAY && !moves.any? { |m| [:LIGHTSCREEN, :REFLECT].include?(m) } + if item == :LIGHTCLAY && moves.none? { |m| [:LIGHTSCREEN, :REFLECT].include?(m) } item = :LEFTOVERS end if item == :BLACKSLUDGE types = GameData::Species.get(species).types item = :LEFTOVERS if !types.include?(:POISON) end - if item == :HEATROCK && !moves.any? { |m| m == :SUNNYDAY } + if item == :HEATROCK && moves.none? { |m| m == :SUNNYDAY } item = :LEFTOVERS end - if item == :DAMPROCK && !moves.any? { |m| m == :RAINDANCE } + if item == :DAMPROCK && moves.none? { |m| m == :RAINDANCE } item = :LEFTOVERS end if moves.any? { |m| m == :REST } diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb index 9f361a654..b131206c2 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb @@ -145,13 +145,12 @@ def pbTrainerInfo(pokemonlist, trfile, rules) numbersPokemon.push(pokemonlist[index]) else t = pkmntypes[index] - t.each { |typ| - if types[typ] > 0 && !numbers.include?(index) - numbers.push(index) - numbersPokemon.push(pokemonlist[index]) - break - end - } + t.each do |typ| + next if types[typ] <= 0 || numbers.include?(index) + numbers.push(index) + numbersPokemon.push(pokemonlist[index]) + break + end end break if numbers.length >= Settings::MAX_PARTY_SIZE && rules.ruleset.hasValidTeam?(numbersPokemon) end @@ -192,12 +191,11 @@ def pbTrainerInfo(pokemonlist, trfile, rules) break end trlists.length.times do |i| - if trlists[i][2].include?(trfile) - trIndex = i - trlists[i][0] = newbttrainers - trlists[i][1] = pbpokemonlist - trlists[i][5] = !hasDefault - end + next if !trlists[i][2].include?(trfile) + trIndex = i + trlists[i][0] = newbttrainers + trlists[i][1] = pbpokemonlist + trlists[i][5] = !hasDefault end yield(nil) if block_given? if trIndex < 0 diff --git a/Data/Scripts/019_Utilities/001_Utilities.rb b/Data/Scripts/019_Utilities/001_Utilities.rb index ed24ad40f..e368b277f 100644 --- a/Data/Scripts/019_Utilities/001_Utilities.rb +++ b/Data/Scripts/019_Utilities/001_Utilities.rb @@ -439,7 +439,7 @@ def pbMoveTutorChoose(move, movelist = nil, bymachine = false, oneusemachine = f pbMessage(_INTL("Eggs can't be taught any moves.")) { screen.pbUpdate } elsif pokemon.shadowPokemon? pbMessage(_INTL("Shadow Pokémon can't be taught any moves.")) { screen.pbUpdate } - elsif movelist && !movelist.any? { |j| j == pokemon.species } + elsif movelist && movelist.none? { |j| j == pokemon.species } pbMessage(_INTL("{1} can't learn {2}.", pokemon.name, movename)) { screen.pbUpdate } elsif !pokemon.compatible_with_move?(move) pbMessage(_INTL("{1} can't learn {2}.", pokemon.name, movename)) { screen.pbUpdate } diff --git a/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb b/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb index 5c84bc977..846a4d7a3 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb @@ -302,7 +302,7 @@ class MapScreenScene def saveMapSpritePos @mapspritepos.clear - @mapsprites.keys.each do |i| + @mapsprites.each_key do |i| s = @mapsprites[i] @mapspritepos[i] = [s.x, s.y] if s && !s.disposed? end @@ -335,7 +335,7 @@ class MapScreenScene conns.each do |map_conns| next if !map_conns map_conns.each do |c| - @mapconns.push(c.clone) if !@mapconns.any? { |x| x[0] == c[0] && x[3] == c[3] } + @mapconns.push(c.clone) if @mapconns.none? { |x| x[0] == c[0] && x[3] == c[3] } end end if $game_map @@ -347,7 +347,7 @@ class MapScreenScene end def setTopSprite(id) - @mapsprites.keys.each do |i| + @mapsprites.each_key do |i| @mapsprites[i].z = (i == id) ? 1 : 0 end end @@ -441,7 +441,7 @@ class MapScreenScene else xpos = x - @dragOffsetX ypos = y - @dragOffsetY - @mapspritepos.keys.each do |i| + @mapspritepos.each_key do |i| sprite = getMapSprite(i) sprite.x = (@mapspritepos[i][0] + xpos) & ~3 sprite.y = (@mapspritepos[i][1] + ypos) & ~3 @@ -456,7 +456,7 @@ class MapScreenScene end def hittest(x, y) - @mapsprites.keys.each do |i| + @mapsprites.each_key do |i| sx = @mapsprites[i].x sy = @mapsprites[i].y sr = sx + @mapsprites[i].bitmap.width diff --git a/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb b/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb index a224f5e06..e395b8676 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb @@ -123,16 +123,15 @@ class SpritePositioner @sprites["pokemon_#{i}"].y = pos[1] metrics_data.apply_metrics_to_sprite(@sprites["pokemon_#{i}"], i) @sprites["pokemon_#{i}"].visible = true - if i == 1 - @sprites["shadow_1"].x = pos[0] - @sprites["shadow_1"].y = pos[1] - if @sprites["shadow_1"].bitmap - @sprites["shadow_1"].x -= @sprites["shadow_1"].bitmap.width / 2 - @sprites["shadow_1"].y -= @sprites["shadow_1"].bitmap.height / 2 - end - metrics_data.apply_metrics_to_sprite(@sprites["shadow_1"], i, true) - @sprites["shadow_1"].visible = true + next if i != 1 + @sprites["shadow_1"].x = pos[0] + @sprites["shadow_1"].y = pos[1] + if @sprites["shadow_1"].bitmap + @sprites["shadow_1"].x -= @sprites["shadow_1"].bitmap.width / 2 + @sprites["shadow_1"].y -= @sprites["shadow_1"].bitmap.height / 2 end + metrics_data.apply_metrics_to_sprite(@sprites["shadow_1"], i, true) + @sprites["shadow_1"].visible = true end end diff --git a/Data/Scripts/020_Debug/001_Editor_Utilities.rb b/Data/Scripts/020_Debug/001_Editor_Utilities.rb index adab28c9d..969735787 100644 --- a/Data/Scripts/020_Debug/001_Editor_Utilities.rb +++ b/Data/Scripts/020_Debug/001_Editor_Utilities.rb @@ -62,7 +62,7 @@ def pbMapTree mapinfos = pbLoadMapInfos maplevels = [] retarray = [] - mapinfos.keys.each do |i| + mapinfos.each_key do |i| info = mapinfos[i] level = -1 while info @@ -98,11 +98,10 @@ def pbMapTree end retarray.push([maplevel[0], mapinfos[maplevel[0]].name, maplevel[1]]) (index + 1...maplevels.length).each do |i| - if maplevels[i][2] == maplevel[0] - stack.push(i) - stack.push(maplevel[0]) - break - end + next if maplevels[i][2] != maplevel[0] + stack.push(i) + stack.push(maplevel[0]) + break end end return retarray diff --git a/Data/Scripts/020_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb b/Data/Scripts/020_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb index 4a16c2022..9e1528260 100644 --- a/Data/Scripts/020_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb +++ b/Data/Scripts/020_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb @@ -269,12 +269,11 @@ class AnimationWindow < SpriteWrapper swatchrects.push(Rect.new(arrowwidth + (i * 96) + self.x, self.y, 96, 96)) end NUMFRAMES.times do |i| - if swatchrects[i].contains(mousepos[0], mousepos[1]) - @selected = @start + i - @changed = true - refresh - return - end + next if !swatchrects[i].contains(mousepos[0], mousepos[1]) + @selected = @start + i + @changed = true + refresh + return end # Left arrow if left.contains(mousepos[0], mousepos[1]) @@ -924,17 +923,16 @@ class AnimationCanvas < Sprite # self.bitmap=@testscreen.bitmap if @currentframe < @animation.length PBAnimation::MAX_SPRITES.times do |i| - if @dirty[i] - if @celsprites[i] - setBitmap(i, @currentframe) - pbSpriteSetAnimFrame(@celsprites[i], @animation[@currentframe][i], @celsprites[0], @celsprites[1], true) - @celsprites[i].x += BORDERSIZE - @celsprites[i].y += BORDERSIZE - end - setPreviousFrame(i) - setFrame(i) - @dirty[i] = false + next if !@dirty[i] + if @celsprites[i] + setBitmap(i, @currentframe) + pbSpriteSetAnimFrame(@celsprites[i], @animation[@currentframe][i], @celsprites[0], @celsprites[1], true) + @celsprites[i].x += BORDERSIZE + @celsprites[i].y += BORDERSIZE end + setPreviousFrame(i) + setFrame(i) + @dirty[i] = false end else PBAnimation::MAX_SPRITES.times do |i| diff --git a/Data/Scripts/020_Debug/002_Animation editor/005_AnimEditor_Functions.rb b/Data/Scripts/020_Debug/002_Animation editor/005_AnimEditor_Functions.rb index 5b8f1d649..1e63b4df9 100644 --- a/Data/Scripts/020_Debug/002_Animation editor/005_AnimEditor_Functions.rb +++ b/Data/Scripts/020_Debug/002_Animation editor/005_AnimEditor_Functions.rb @@ -644,13 +644,13 @@ def pbEditBG(canvas, timing) maxsizewindow.addOptionalSlider(_INTL("Alpha:"), 0, 255, timing.colorAlpha || 0) maxsizewindow.addButton(_INTL("OK")) maxsizewindow.addButton(_INTL("Cancel")) - maxsizewindow.controls[1].checked = (timing.bgX != nil) - maxsizewindow.controls[2].checked = (timing.bgY != nil) - maxsizewindow.controls[3].checked = (timing.opacity != nil) - maxsizewindow.controls[4].checked = (timing.colorRed != nil) - maxsizewindow.controls[5].checked = (timing.colorGreen != nil) - maxsizewindow.controls[6].checked = (timing.colorBlue != nil) - maxsizewindow.controls[7].checked = (timing.colorAlpha != nil) + maxsizewindow.controls[1].checked = !timing.bgX.nil? + maxsizewindow.controls[2].checked = !timing.bgY.nil? + maxsizewindow.controls[3].checked = !timing.opacity.nil? + maxsizewindow.controls[4].checked = !timing.colorRed.nil? + maxsizewindow.controls[5].checked = !timing.colorGreen.nil? + maxsizewindow.controls[6].checked = !timing.colorBlue.nil? + maxsizewindow.controls[7].checked = !timing.colorAlpha.nil? maxsizewindow.opacity = 200 maxsizewindow.viewport = canvas.viewport loop do diff --git a/Data/Scripts/020_Debug/002_Editor_DataTypes.rb b/Data/Scripts/020_Debug/002_Editor_DataTypes.rb index 9799bbc39..8080a2a98 100644 --- a/Data/Scripts/020_Debug/002_Editor_DataTypes.rb +++ b/Data/Scripts/020_Debug/002_Editor_DataTypes.rb @@ -147,7 +147,7 @@ module BooleanProperty2 end def self.format(value) - return (value) ? _INTL("True") : (value != nil) ? _INTL("False") : "-" + return (value) ? _INTL("True") : (!value.nil?) ? _INTL("False") : "-" end end @@ -578,7 +578,7 @@ class IVsProperty next if s.pbs_order < 0 array[s.pbs_order] = value[s.id] || 0 end - return array.join(',') + return array.join(",") end end @@ -624,7 +624,7 @@ class EVsProperty next if s.pbs_order < 0 array[s.pbs_order] = value[s.id] || 0 end - return array.join(',') + return array.join(",") end end @@ -913,7 +913,7 @@ module BaseStatsProperty next if s.pbs_order < 0 array[s.pbs_order] = value[s.id] || 0 end - return array.join(',') + return array.join(",") end end @@ -952,7 +952,7 @@ module EffortValuesProperty next if s.pbs_order < 0 array[s.pbs_order] = value[s.id] || 0 end - return array.join(',') + return array.join(",") end end diff --git a/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb b/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb index 67cb78402..98c7c651e 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb @@ -368,7 +368,7 @@ MenuHandlers.add(:debug_menu, :reset_trainers, { "description" => _INTL("Turn off Self Switches A and B for all events with \"Trainer\" in their name."), "effect" => proc { if $game_map - $game_map.events.values.each do |event| + $game_map.events.each_value do |event| if event.name[/trainer/i] $game_self_switches[[$game_map.map_id, event.id, "A"]] = false $game_self_switches[[$game_map.map_id, event.id, "B"]] = false diff --git a/Data/Scripts/020_Debug/003_Debug menus/003_Debug_MenuExtraCode.rb b/Data/Scripts/020_Debug/003_Debug menus/003_Debug_MenuExtraCode.rb index 1644ba8c1..7f0e21fc4 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/003_Debug_MenuExtraCode.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/003_Debug_MenuExtraCode.rb @@ -20,7 +20,7 @@ def pbWarpToMap y = rand(map.height) next if !map.passableStrict?(x, y, 0, $game_player) blocked = false - map.events.values.each do |event| + map.events.each_value do |event| if event.at_coordinate?(x, y) && !event.through && event.character_name != "" blocked = true end @@ -101,7 +101,7 @@ class SpriteWindow_DebugVariables < Window_DrawableCommand status = $game_variables[index + 1].to_s status = "\"__\"" if nil_or_empty?(status) end - name = '' if name.nil? + name ||= "" id_text = sprintf("%04d:", index + 1) rect = drawCursor(index, rect) totalWidth = rect.width @@ -655,12 +655,11 @@ def pbImportAllAnimations missingFiles.push(textdata.graphic) end textdata.timing.each do |timing| - if timing.name && timing.name != "" && - !safeExists?(folder + "/" + timing.name) && - !FileTest.audio_exist?("Audio/SE/Anim/" + timing.name) - timing.name = "" - missingFiles.push(timing.name) - end + next if !timing.name || timing.name == "" || + safeExists?(folder + "/" + timing.name) || + FileTest.audio_exist?("Audio/SE/Anim/" + timing.name) + timing.name = "" + missingFiles.push(timing.name) end animations[index] = textdata end @@ -706,7 +705,7 @@ def pbDebugFixInvalidTiles end end # Check all events in map for page graphics using a non-existent tile - map.events.keys.each do |key| + map.events.each_key do |key| event = map.events[key] event.pages.each do |page| next if page.graphic.tile_id <= 0 diff --git a/Data/Scripts/020_Debug/003_Debug menus/006_Debug_FilenameUpdater.rb b/Data/Scripts/020_Debug/003_Debug menus/006_Debug_FilenameUpdater.rb index e155c0d5b..f4abbcc07 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/006_Debug_FilenameUpdater.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/006_Debug_FilenameUpdater.rb @@ -24,8 +24,8 @@ module FilenameUpdater # starts automatic renaming files.each_with_index do |file, i| next if file[/^berrytree_/] - next if ["berrytreewet", "berrytreedamp", "berrytreedry", "berrytreeplanted"].include?(file.split('.')[0]) - new_file = file.gsub('berrytree', 'berrytree_') + next if ["berrytreewet", "berrytreedamp", "berrytreedry", "berrytreeplanted"].include?(file.split(".")[0]) + new_file = file.gsub("berrytree", "berrytree_") File.move(src_dir + file, src_dir + new_file) ret = true end @@ -47,7 +47,7 @@ module FilenameUpdater map = mapData.getMap(id) next if !map || !mapData.mapinfos[id] changed = false - map.events.keys.each do |key| + map.events.each_key do |key| if Time.now.to_i - t >= 5 Graphics.update t = Time.now.to_i @@ -56,8 +56,8 @@ module FilenameUpdater next if nil_or_empty?(page.graphic.character_name) char_name = page.graphic.character_name next if !char_name[/^berrytree[^_]+/] - next if ["berrytreewet", "berrytreedamp", "berrytreedry", "berrytreeplanted"].include?(char_name.split('.')[0]) - new_file = page.graphic.character_name.gsub('berrytree', 'berrytree_') + next if ["berrytreewet", "berrytreedamp", "berrytreedry", "berrytreeplanted"].include?(char_name.split(".")[0]) + new_file = page.graphic.character_name.gsub("berrytree", "berrytree_") page.graphic.character_name = new_file changed = true end diff --git a/Data/Scripts/020_Debug/003_Debug menus/007_Debug_BattleCommands.rb b/Data/Scripts/020_Debug/003_Debug menus/007_Debug_BattleCommands.rb index cdd392783..1d2076131 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/007_Debug_BattleCommands.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/007_Debug_BattleCommands.rb @@ -77,7 +77,7 @@ MenuHandlers.add(:battle_debug_menu, :list_foe_battlers, { MenuHandlers.add(:battle_debug_menu, :field, { "name" => _INTL("Field Effects..."), "parent" => :main, - "description" => _INTL("Effects that apply to the whole battlefield."), + "description" => _INTL("Effects that apply to the whole battlefield.") }) MenuHandlers.add(:battle_debug_menu, :weather, { diff --git a/Data/Scripts/020_Debug/003_Debug menus/008_Debug_BattlePkmnCommands.rb b/Data/Scripts/020_Debug/003_Debug menus/008_Debug_BattlePkmnCommands.rb index 7d490a70d..e45082af3 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/008_Debug_BattlePkmnCommands.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/008_Debug_BattlePkmnCommands.rb @@ -707,15 +707,14 @@ MenuHandlers.add(:battle_pokemon_debug_menu, :set_form, { cmd = pbMessage("\\ts[]" + _INTL("Form is {1}.", pkmn.form), formcmds[1], -1, nil, cmd) next if cmd < 0 f = formcmds[0][cmd] - if f != pkmn.form - pkmn.forced_form = nil - if MultipleForms.hasFunction?(pkmn, "getForm") - next if !pbConfirmMessage(_INTL("This species decides its own form. Override?")) - pkmn.forced_form = f - end - pkmn.form_simple = f - battler.form = pkmn.form if battler + next if f == pkmn.form + pkmn.forced_form = nil + if MultipleForms.hasFunction?(pkmn, "getForm") + next if !pbConfirmMessage(_INTL("This species decides its own form. Override?")) + pkmn.forced_form = f end + pkmn.form_simple = f + battler.form = pkmn.form if battler end } }) diff --git a/Data/Scripts/021_Compiler/001_Compiler.rb b/Data/Scripts/021_Compiler/001_Compiler.rb index e76ce8493..f2124fbcd 100644 --- a/Data/Scripts/021_Compiler/001_Compiler.rb +++ b/Data/Scripts/021_Compiler/001_Compiler.rb @@ -586,7 +586,7 @@ module Compiler when Module file.write(getConstantName(enumer, value)) when Hash - enumer.keys.each do |key| + enumer.each_key do |key| if enumer[key] == value file.write(key) break @@ -609,12 +609,11 @@ module Compiler file.write(getConstantNameOrValue(enumer, value)) when Hash hasenum = false - enumer.keys.each do |key| - if enumer[key] == value - file.write(key) - hasenum = true - break - end + enumer.each_key do |key| + next if enumer[key] != value + file.write(key) + hasenum = true + break end file.write(value) unless hasenum end diff --git a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb index fef69e5c1..8cb867cd8 100644 --- a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb +++ b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb @@ -154,7 +154,7 @@ module Compiler contents["InternalName"] = type_id if !type_id[/^\d+/] icon_pos = (type_id[/^\d+/]) ? type_id.to_i : nil # Go through schema hash of compilable data and compile this section - schema.keys.each do |key| + schema.each_key do |key| FileLineData.setSection(type_id, key, contents[key]) # For error reporting # Skip empty properties, or raise an error if a required property is # empty @@ -606,7 +606,7 @@ module Compiler contents["InternalName"] = species_id if !species_id[/^\d+/] # Ensure all required properties have been defined, and raise an error # if not - schema.keys.each do |key| + schema.each_key do |key| next if !nil_or_empty?(contents[key]) if ["Name", "InternalName"].include?(key) raise _INTL("The entry {1} is required in {2} section {3}.", key, path, species_id) @@ -618,7 +618,7 @@ module Compiler raise _INTL("Species ID '{1}' is used twice.\r\n{2}", contents["InternalName"], FileLineData.linereport) end # Go through schema hash of compilable data and compile this section - schema.keys.each do |key| + schema.each_key do |key| next if nil_or_empty?(contents[key]) FileLineData.setSection(species_id, key, contents[key]) # For error reporting # Compile value for key @@ -792,7 +792,7 @@ module Compiler used_forms[species_symbol].push(form) base_data = GameData::Species.get(species_symbol) # Go through schema hash of compilable data and compile this section - schema.keys.each do |key| + schema.each_key do |key| # Skip empty properties (none are required) if nil_or_empty?(contents[key]) contents[key] = nil @@ -988,7 +988,7 @@ module Compiler species_symbol = csvEnumField!(split_section_name[0], :Species, nil, nil) form = (split_section_name[1]) ? csvPosInt!(split_section_name[1]) : 0 # Go through schema hash of compilable data and compile this section - schema.keys.each do |key| + schema.each_key do |key| # Skip empty properties (none are required) if nil_or_empty?(contents[key]) contents[key] = nil @@ -1215,7 +1215,7 @@ module Compiler Graphics.update if idx % 250 == 0 next if line.length == 0 if current_type && line[/^\d+,/] # Species line - values = line.split(',').collect! { |v| v.strip } + values = line.split(",").collect! { |v| v.strip } if !values || values.length < 3 raise _INTL("Expected a species entry line for encounter type {1} for map '{2}', got \"{3}\" instead.\r\n{4}", GameData::EncounterType.get(current_type).real_name, encounter_hash[:map], line, FileLineData.linereport) @@ -1231,7 +1231,7 @@ module Compiler end encounter_hash[:types][current_type].push(values) elsif line[/^\[\s*(.+)\s*\]$/] # Map ID line - values = $~[1].split(',').collect! { |v| v.strip.to_i } + values = $~[1].split(",").collect! { |v| v.strip.to_i } values[1] = 0 if !values[1] map_number = values[0] map_version = values[1] @@ -1272,7 +1272,7 @@ module Compiler raise _INTL("Expected a map number, got \"{1}\" instead.\r\n{2}", line, FileLineData.linereport) else # Check if line is an encounter method name or not - values = line.split(',').collect! { |v| v.strip } + values = line.split(",").collect! { |v| v.strip } current_type = (values[0] && !values[0].empty?) ? values[0].to_sym : nil if current_type && GameData::EncounterType.exists?(current_type) # Start of a new encounter method step_chances[current_type] = values[1].to_i if values[1] && !values[1].empty? @@ -1546,7 +1546,7 @@ module Compiler Graphics.update next if name != "DefaultTrainerList" && name != "TrainerList" rsection = [] - section.keys.each do |key| + section.each_key do |key| FileLineData.setSection(name, key, section[key]) schema = btTrainersRequiredTypes[key] next if key == "Challenges" && name == "DefaultTrainerList" @@ -1608,7 +1608,7 @@ module Compiler FileLineData.file = filename pbEachFileSection(f) { |section, name| rsection = [] - section.keys.each do |key| + section.each_key do |key| FileLineData.setSection(name, key, section[key]) schema = requiredtypes[key] next if !schema @@ -1647,7 +1647,7 @@ module Compiler pbEachFileSectionNumbered(f) { |contents, section_id| schema = (section_id == 0) ? GameData::Metadata::SCHEMA : GameData::PlayerMetadata::SCHEMA # Go through schema hash of compilable data and compile this section - schema.keys.each do |key| + schema.each_key do |key| FileLineData.setSection(section_id, key, contents[key]) # For error reporting # Skip empty properties, or raise an error if a required property is # empty @@ -1731,7 +1731,7 @@ module Compiler idx += 1 Graphics.update if idx % 250 == 0 # Go through schema hash of compilable data and compile this section - schema.keys.each do |key| + schema.each_key do |key| FileLineData.setSection(map_id, key, contents[key]) # For error reporting # Skip empty properties next if contents[key].nil? diff --git a/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb b/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb index d2510383e..387ec5f95 100644 --- a/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb +++ b/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb @@ -736,7 +736,7 @@ module Compiler next if !bttrainers[i] f.write("\#-------------------------------\r\n") f.write(sprintf("[%03d]\r\n", i)) - btTrainersRequiredTypes.keys.each do |key| + btTrainersRequiredTypes.each_key do |key| schema = btTrainersRequiredTypes[key] record = bttrainers[i][schema[0]] next if record.nil? diff --git a/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb b/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb index 794d08786..0c0ef2f77 100644 --- a/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb +++ b/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb @@ -1,37 +1,37 @@ module Compiler SCRIPT_REPLACEMENTS = [ - ['Kernel.', ''], - ['$PokemonBag.pbQuantity', '$bag.quantity'], - ['$PokemonBag.pbHasItem?', '$bag.has?'], - ['$PokemonBag.pbCanStore?', '$bag.can_add?'], - ['$PokemonBag.pbStoreItem', '$bag.add'], - ['$PokemonBag.pbStoreAllOrNone', '$bag.add_all'], - ['$PokemonBag.pbChangeItem', '$bag.replace_item'], - ['$PokemonBag.pbDeleteItem', '$bag.remove'], - ['$PokemonBag.pbIsRegistered?', '$bag.registered?'], - ['$PokemonBag.pbRegisterItem', '$bag.register'], - ['$PokemonBag.pbUnregisterItem', '$bag.unregister'], - ['$PokemonBag', '$bag'], - ['pbQuantity', '$bag.quantity'], - ['pbHasItem?', '$bag.has?'], - ['pbCanStore?', '$bag.can_add?'], - ['pbStoreItem', '$bag.add'], - ['pbStoreAllOrNone', '$bag.add_all'], - ['$Trainer', '$player'], - ['$SaveVersion', '$save_engine_version'], - ['$game_version', '$save_game_version'], - ['$MapFactory', '$map_factory'], - ['pbDayCareDeposited', 'DayCare.count'], - ['pbDayCareGetDeposited', 'DayCare.get_details'], - ['pbDayCareGetLevelGain', 'DayCare.get_level_gain'], - ['pbDayCareDeposit', 'DayCare.deposit'], - ['pbDayCareWithdraw', 'DayCare.withdraw'], - ['pbDayCareChoose', 'DayCare.choose'], - ['pbDayCareGetCompatibility', 'DayCare.get_compatibility'], - ['pbEggGenerated?', 'DayCare.egg_generated?'], - ['pbDayCareGenerateEgg', 'DayCare.collect_egg'], - ['get_character(0)', 'get_self'], - ['get_character(-1)', 'get_player'] + ["Kernel.", ""], + ["$PokemonBag.pbQuantity", "$bag.quantity"], + ["$PokemonBag.pbHasItem?", "$bag.has?"], + ["$PokemonBag.pbCanStore?", "$bag.can_add?"], + ["$PokemonBag.pbStoreItem", "$bag.add"], + ["$PokemonBag.pbStoreAllOrNone", "$bag.add_all"], + ["$PokemonBag.pbChangeItem", "$bag.replace_item"], + ["$PokemonBag.pbDeleteItem", "$bag.remove"], + ["$PokemonBag.pbIsRegistered?", "$bag.registered?"], + ["$PokemonBag.pbRegisterItem", "$bag.register"], + ["$PokemonBag.pbUnregisterItem", "$bag.unregister"], + ["$PokemonBag", "$bag"], + ["pbQuantity", "$bag.quantity"], + ["pbHasItem?", "$bag.has?"], + ["pbCanStore?", "$bag.can_add?"], + ["pbStoreItem", "$bag.add"], + ["pbStoreAllOrNone", "$bag.add_all"], + ["$Trainer", "$player"], + ["$SaveVersion", "$save_engine_version"], + ["$game_version", "$save_game_version"], + ["$MapFactory", "$map_factory"], + ["pbDayCareDeposited", "DayCare.count"], + ["pbDayCareGetDeposited", "DayCare.get_details"], + ["pbDayCareGetLevelGain", "DayCare.get_level_gain"], + ["pbDayCareDeposit", "DayCare.deposit"], + ["pbDayCareWithdraw", "DayCare.withdraw"], + ["pbDayCareChoose", "DayCare.choose"], + ["pbDayCareGetCompatibility", "DayCare.get_compatibility"], + ["pbEggGenerated?", "DayCare.egg_generated?"], + ["pbDayCareGenerateEgg", "DayCare.collect_egg"], + ["get_character(0)", "get_self"], + ["get_character(-1)", "get_player"] ] module_function @@ -52,7 +52,7 @@ module Compiler mapinfos = pbLoadMapInfos maxOrder = 0 # Exclude maps found in mapinfos - mapinfos.keys.each do |id| + mapinfos.each_key do |id| next if !mapinfos[id] mapfiles.delete(id) if mapfiles[id] maxOrder = [maxOrder, mapinfos[id].order].max @@ -61,7 +61,7 @@ module Compiler maxOrder += 1 imported = false count = 0 - mapfiles.keys.each do |id| + mapfiles.each_key do |id| next if id == 999 # Ignore 999 (random dungeon map) mapinfo = RPG::MapInfo.new mapinfo.order = maxOrder @@ -314,7 +314,7 @@ module Compiler @mapHeights[mapID] = map.height mapPositions = [] width = map.width - map.events.values.each do |e| + map.events.each_value do |e| mapPositions[(e.y * width) + e.x] = e if e end @mapxy[mapID] = mapPositions @@ -780,7 +780,7 @@ module Compiler if mapData.switchName(lastPage.condition.switch1_id) == 's:tsOff?("A")' list = event.pages[event.pages.length - 2].list transferCommand = list.find_all { |cmd| cmd.code == 201 } # Transfer Player - if transferCommand.length == 1 && !list.any? { |cmd| cmd.code == 208 } # Change Transparent Flag + if transferCommand.length == 1 && list.none? { |cmd| cmd.code == 208 } # Change Transparent Flag # Rewrite penultimate page list.clear push_move_route_and_wait( # Move Route for door opening @@ -1431,7 +1431,7 @@ module Compiler def check_counters(map, mapID, mapData) toDelete = [] changed = false - map.events.keys.each do |key| + map.events.each_key do |key| event = map.events[key] next if !plain_event_or_mart?(event) # Found an event that is empty or looks like a simple Mart or a Poké @@ -1478,7 +1478,7 @@ module Compiler changed = false map = mapData.getMap(id) next if !map || !mapData.mapinfos[id] - map.events.keys.each do |key| + map.events.each_key do |key| if Time.now.to_i - t >= 5 Graphics.update t = Time.now.to_i