Yet more Rubocopping

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

View File

@@ -7,7 +7,7 @@ module PBDebug
rescue
PBDebug.log("")
PBDebug.log("**Exception: #{$!.message}")
PBDebug.log("#{$!.backtrace.inspect}")
PBDebug.log($!.backtrace.inspect.to_s)
PBDebug.log("")
pbPrintException($!) # if $INTERNAL
PBDebug.flush

View File

@@ -37,7 +37,7 @@ def pbPrintException(e)
message += "Exception: #{e.class}\r\n"
message += "Message: "
end
message += "#{emessage}"
message += emessage
# show last 10/25 lines of backtrace
if !e.is_a?(EventScriptError)
message += "\r\n\r\nBacktrace:\r\n"

View File

@@ -378,7 +378,7 @@ class StringInput
f = super
yield f
ensure
f.close if f
f&.close
end
else
super

View File

@@ -137,7 +137,7 @@ class StringInput
end
def each_byte
while !eof?
until eof?
yield getc
end
end

View File

@@ -69,7 +69,7 @@ def pbSetTextMessages
neednewline = false
end
if list.code == 101
lastitem += "#{list.parameters[0]}"
lastitem += list.parameters[0].to_s
neednewline = true
elsif list.code == 102
list.parameters[0].length.times do |k|
@@ -78,7 +78,7 @@ def pbSetTextMessages
neednewline = false
elsif list.code == 401
lastitem += " " if lastitem != ""
lastitem += "#{list.parameters[0]}"
lastitem += list.parameters[0].to_s
neednewline = true
elsif list.code == 355 || list.code == 655
pbAddScriptTexts(items, list.parameters[0])
@@ -93,14 +93,12 @@ def pbSetTextMessages
end
end
end
if neednewline
if lastitem != ""
if neednewline && lastitem != ""
items.push(lastitem)
lastitem = ""
end
end
end
end
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update
@@ -140,7 +138,7 @@ def pbSetTextMessages
neednewline = false
end
if list.code == 101
lastitem += "#{list.parameters[0]}"
lastitem += list.parameters[0].to_s
neednewline = true
elsif list.code == 102
list.parameters[0].length.times do |k|
@@ -149,7 +147,7 @@ def pbSetTextMessages
neednewline = false
elsif list.code == 401
lastitem += " " if lastitem != ""
lastitem += "#{list.parameters[0]}"
lastitem += list.parameters[0].to_s
neednewline = true
elsif list.code == 355 || list.code == 655
pbAddScriptTexts(items, list.parameters[0])
@@ -164,15 +162,13 @@ def pbSetTextMessages
end
end
end
if neednewline
if lastitem != ""
if neednewline && lastitem != ""
items.push(lastitem)
lastitem = ""
end
end
end
end
end
if Time.now.to_i - t >= 5
t = Time.now.to_i
Graphics.update
@@ -210,7 +206,7 @@ def pbEachIntlSection(file)
sectionname = $~[1]
havesection = true
else
if sectionname == nil
if sectionname.nil?
raise _INTL("Expected a section at the beginning of the file (line {1})", lineno)
end
lastsection.push(line.gsub(/\s+$/, ""))
@@ -739,7 +735,7 @@ def _INTL(*arg)
end
string = string.clone
(1...arg.length).each do |i|
string.gsub!(/\{#{i}\}/, "#{arg[i]}")
string.gsub!(/\{#{i}\}/, arg[i].to_s)
end
return string
end
@@ -770,7 +766,7 @@ def _MAPINTL(mapid, *arg)
string = MessageTypes.getFromMapHash(mapid, arg[0])
string = string.clone
(1...arg.length).each do |i|
string.gsub!(/\{#{i}\}/, "#{arg[i]}")
string.gsub!(/\{#{i}\}/, arg[i].to_s)
end
return string
end

View File

@@ -319,10 +319,10 @@ module PluginManager
value = [value] if value.is_a?(String)
if value.is_a?(Array)
value.each do |entry|
if !entry.is_a?(String)
self.error("Plugin '#{name}'s credits array contains a non-string value.")
else
if entry.is_a?(String)
credits << entry
else
self.error("Plugin '#{name}'s credits array contains a non-string value.")
end
end
else
@@ -333,7 +333,7 @@ module PluginManager
end
end
@@Plugins.values.each do |plugin|
if plugin[:incompatibilities] && plugin[:incompatibilities].include?(name)
if plugin[:incompatibilities]&.include?(name)
self.error("Plugin '#{plugin[:name]}' is incompatible with '#{name}'. " +
"They cannot both be used at the same time.")
end
@@ -475,7 +475,7 @@ module PluginManager
print("#{message}\r\nThis exception was logged in #{errorlogline}.\r\nHold Ctrl when closing this message to copy it to the clipboard.")
# Give a ~500ms coyote time to start holding Control
t = System.delta
until (System.delta - t) >= 500000
until (System.delta - t) >= 500_000
Input.update
if Input.press?(Input::CTRL)
Input.clipboard = message

View File

@@ -6,13 +6,11 @@ class SpriteAnimation
@sprite = sprite
end
%w[
x y ox oy viewport flash src_rect opacity tone
].each_with_index do |s, _i|
["x", "y", "ox", "oy", "viewport", "flash", "src_rect", "opacity", "tone"].each do |def_name|
eval <<-__END__
def #{s}(*arg)
@sprite.#{s}(*arg)
def #{def_name}(*arg)
@sprite.#{def_name}(*arg)
end
__END__
@@ -30,7 +28,7 @@ class SpriteAnimation
def animation(animation, hit, height = 3)
dispose_animation
@_animation = animation
return if @_animation == nil
return if @_animation.nil?
@_animation_hit = hit
@_animation_height = height
@_animation_duration = @_animation.frame_max
@@ -66,7 +64,7 @@ class SpriteAnimation
return if animation == @_loop_animation
dispose_loop_animation
@_loop_animation = animation
return if @_loop_animation == nil
return if @_loop_animation.nil?
@_loop_animation_index = 0
fr = 20
if @_animation.name[/\[\s*(\d+?)\s*\]\s*$/]
@@ -92,7 +90,7 @@ class SpriteAnimation
end
def dispose_animation
return if @_animation_sprites == nil
return if @_animation_sprites.nil?
sprite = @_animation_sprites[0]
if sprite != nil
@@_reference_count[sprite.bitmap] -= 1
@@ -108,7 +106,7 @@ class SpriteAnimation
end
def dispose_loop_animation
return if @_loop_animation_sprites == nil
return if @_loop_animation_sprites.nil?
sprite = @_loop_animation_sprites[0]
if sprite != nil
@@_reference_count[sprite.bitmap] -= 1
@@ -195,7 +193,7 @@ class SpriteAnimation
16.times do |i|
sprite = sprites[i]
pattern = cell_data[i, 0]
if sprite == nil || pattern == nil || pattern == -1
if sprite.nil? || pattern.nil? || pattern == -1
sprite.visible = false if sprite != nil
next
end
@@ -377,7 +375,7 @@ module RPG
def pushAnimation(array, anim)
array.length.times do |i|
next if array[i] && array[i].active?
next if array[i]&.active?
array[i] = anim
return
end
@@ -397,7 +395,7 @@ module RPG
end
def dispose_damage
return if @_damage_sprite == nil
return if @_damage_sprite.nil?
@_damage_sprite.bitmap.dispose
@_damage_sprite.dispose
@_damage_sprite = nil
@@ -406,14 +404,14 @@ module RPG
def dispose_animation
@animations.each do |a|
a.dispose_animation if a
a&.dispose_animation
end
@animations.clear
end
def dispose_loop_animation
@loopAnimations.each do |a|
a.dispose_loop_animation if a
a&.dispose_loop_animation
end
@loopAnimations.clear
end
@@ -501,13 +499,13 @@ module RPG
def update_animation
@animations.each do |a|
a.update_animation if a && a.active?
a.update_animation if a&.active?
end
end
def update_loop_animation
@loopAnimations.each do |a|
a.update_loop_animation if a && a.active?
a.update_loop_animation if a&.active?
end
end

View File

@@ -38,7 +38,7 @@ module Game
# Called when starting a new game. Initializes global variables
# and transfers the player into the map scene.
def self.start_new
if $game_map && $game_map.events
if $game_map&.events
$game_map.events.each_value { |event| event.clear_starting }
end
$game_temp.common_event_id = 0 if $game_temp

View File

@@ -61,8 +61,8 @@ class Scene_Map
pbBGMFade(0.8)
end
end
if playingBGS && map.autoplay_bgs
pbBGMFade(0.8) if playingBGS.name != map.bgs.name
if playingBGS && map.autoplay_bgs && playingBGS.name != map.bgs.name
pbBGMFade(0.8)
end
Graphics.frame_reset
end
@@ -145,12 +145,12 @@ class Scene_Map
end
keys = @spritesets.keys.clone
keys.each do |i|
if !$map_factory.hasMap?(i)
@spritesets[i].dispose if @spritesets[i]
if $map_factory.hasMap?(i)
@spritesets[i].update
else
@spritesets[i]&.dispose
@spritesets[i] = nil
@spritesets.delete(i)
else
@spritesets[i].update
end
end
@spritesetGlobal.update

View File

@@ -304,7 +304,7 @@ class Interpreter
def pbEraseThisEvent
if $game_map.events[@event_id]
$game_map.events[@event_id].erase
$PokemonMap.addErasedEvent(@event_id) if $PokemonMap
$PokemonMap&.addErasedEvent(@event_id)
end
@index += 1
return true
@@ -407,7 +407,7 @@ class Interpreter
when 6 then event.move_right
when 8 then event.move_up
end
$PokemonMap.addMovedEvent(@event_id) if $PokemonMap
$PokemonMap&.addMovedEvent(@event_id)
if old_x != event.x || old_y != event.y
$game_player.lock
loop do
@@ -443,7 +443,7 @@ class Interpreter
def pbTrainerEnd
pbGlobalUnlock
event = get_self
event.erase_route if event
event&.erase_route
end
def setPrice(item, buy_price = -1, sell_price = -1)

View File

@@ -414,8 +414,8 @@ class Interpreter
#-----------------------------------------------------------------------------
def command_116
if @event_id > 0
$game_map.events[@event_id].erase if $game_map.events[@event_id]
$PokemonMap.addErasedEvent(@event_id) if $PokemonMap
$game_map.events[@event_id]&.erase
$PokemonMap&.addErasedEvent(@event_id)
end
@index += 1
return false
@@ -512,10 +512,10 @@ class Interpreter
next if $game_variables[i] == value
$game_variables[i] = value
when 1 # add
next if $game_variables[i] >= 99999999
next if $game_variables[i] >= 99_999_999
$game_variables[i] += value
when 2 # subtract
next if $game_variables[i] <= -99999999
next if $game_variables[i] <= -99_999_999
$game_variables[i] -= value
when 3 # multiply
next if value == 1
@@ -527,8 +527,8 @@ class Interpreter
next if [0, 1].include?(value)
$game_variables[i] %= value
end
$game_variables[i] = 99999999 if $game_variables[i] > 99999999
$game_variables[i] = -99999999 if $game_variables[i] < -99999999
$game_variables[i] = 99_999_999 if $game_variables[i] > 99_999_999
$game_variables[i] = -99_999_999 if $game_variables[i] < -99_999_999
$game_map.need_refresh = true
end
return true

View File

@@ -142,7 +142,7 @@ end
def pbToneChangeAll(tone, duration)
$game_screen.start_tone_change(tone, duration * Graphics.frame_rate / 20)
$game_screen.pictures.each do |picture|
picture.start_tone_change(tone, duration * Graphics.frame_rate / 20) if picture
picture&.start_tone_change(tone, duration * Graphics.frame_rate / 20)
end
end

View File

@@ -61,11 +61,10 @@ class Game_System
def bgm_play_internal(bgm, position) # :nodoc:
@bgm_position = position if !@bgm_paused
@playing_bgm = (bgm == nil) ? nil : bgm.clone
@playing_bgm = bgm&.clone
if bgm != nil && bgm.name != ""
if FileTest.audio_exist?("Audio/BGM/" + bgm.name)
bgm_play_internal2("Audio/BGM/" + bgm.name,
bgm.volume, bgm.pitch, @bgm_position) if !@defaultBGM
if !@defaultBGM && FileTest.audio_exist?("Audio/BGM/" + bgm.name)
bgm_play_internal2("Audio/BGM/" + bgm.name, bgm.volume, bgm.pitch, @bgm_position)
end
else
@bgm_position = position if !@bgm_paused
@@ -161,7 +160,7 @@ class Game_System
################################################################################
def bgs_play(bgs)
@playing_bgs = (bgs == nil) ? nil : bgs.clone
@playing_bgs = (bgs.nil?) ? nil : bgs.clone
if bgs != nil && bgs.name != ""
if FileTest.audio_exist?("Audio/BGS/" + bgs.name)
vol = bgs.volume
@@ -258,7 +257,7 @@ class Game_System
################################################################################
def windowskin_name
if @windowskin_name == nil
if @windowskin_name.nil?
return $data_system.windowskin_name
else
return @windowskin_name

View File

@@ -66,7 +66,7 @@ class Game_Picture
@zoom_x = zoom_x.to_f
@zoom_y = zoom_y.to_f
@opacity = opacity.to_f
@blend_type = blend_type ? blend_type : 0
@blend_type = blend_type || 0
@duration = 0
@target_x = @x
@target_y = @y
@@ -98,7 +98,7 @@ class Game_Picture
@target_zoom_x = zoom_x.to_f
@target_zoom_y = zoom_y.to_f
@target_opacity = opacity.to_f
@blend_type = blend_type ? blend_type : 0
@blend_type = blend_type || 0
end
#-----------------------------------------------------------------------------
# * Change Rotation Speed

View File

@@ -193,7 +193,7 @@ class Game_Map
if self_event != nil && terrain.can_surf_freely
[2, 1, 0].each do |j|
facing_tile_id = data[newx, newy, j]
return false if facing_tile_id == nil
return false if facing_tile_id.nil?
facing_terrain = GameData::TerrainTag.try_get(@terrain_tags[facing_tile_id])
if facing_terrain.id != :None && !facing_terrain.ignore_passability
return facing_terrain.can_surf_freely
@@ -207,7 +207,7 @@ class Game_Map
# Can't walk onto ledges
[2, 1, 0].each do |j|
facing_tile_id = data[newx, newy, j]
return false if facing_tile_id == nil
return false if facing_tile_id.nil?
facing_terrain = GameData::TerrainTag.try_get(@terrain_tags[facing_tile_id])
return false if facing_terrain.ledge
break if facing_terrain.id != :None && !facing_terrain.ignore_passability
@@ -326,7 +326,7 @@ class Game_Map
max_x = (self.width - (Graphics.width.to_f / TILE_WIDTH)) * REAL_RES_X
@display_x = [0, [@display_x, max_x].min].max
end
$map_factory.setMapsInRange if $map_factory
$map_factory&.setMapsInRange
end
def display_y=(value)
@@ -336,7 +336,7 @@ class Game_Map
max_y = (self.height - (Graphics.height.to_f / TILE_HEIGHT)) * REAL_RES_Y
@display_y = [0, [@display_y, max_y].min].max
end
$map_factory.setMapsInRange if $map_factory
$map_factory&.setMapsInRange
end
def scroll_up(distance)

View File

@@ -93,7 +93,22 @@ class Interpreter
max_y = ($game_map.height - (Graphics.height.to_f / Game_Map::TILE_HEIGHT)) * 4 * Game_Map::TILE_HEIGHT
count_x = ($game_map.display_x - [0, [(x * Game_Map::REAL_RES_X) - center_x, max_x].min].max) / Game_Map::REAL_RES_X
count_y = ($game_map.display_y - [0, [(y * Game_Map::REAL_RES_Y) - center_y, max_y].min].max) / Game_Map::REAL_RES_Y
if !@diag
if @diag
@diag = false
dir = nil
if count_x != 0 && count_y != 0
return false
elsif count_x > 0
dir = 4
elsif count_x < 0
dir = 6
elsif count_y > 0
dir = 8
elsif count_y < 0
dir = 2
end
count = count_x == 0 ? count_y.abs : count_x.abs
else
@diag = true
dir = nil
if count_x > 0
@@ -110,21 +125,6 @@ class Interpreter
end
end
count = [count_x.abs, count_y.abs].min
else
@diag = false
dir = nil
if count_x != 0 && count_y != 0
return false
elsif count_x > 0
dir = 4
elsif count_x < 0
dir = 6
elsif count_y > 0
dir = 8
elsif count_y < 0
dir = 2
end
count = count_x != 0 ? count_x.abs : count_y.abs
end
$game_map.start_scroll(dir, count, speed) if dir != nil
if @diag

View File

@@ -185,10 +185,10 @@ class PokemonMapFactory
return false if !event.through && event.character_name != ""
end
# Check passability of player
if !thisEvent.is_a?(Game_Player)
if $game_map.map_id == mapID && $game_player.x == x && $game_player.y == y
return false if !$game_player.through && $game_player.character_name != ""
end
if !thisEvent.is_a?(Game_Player) &&
$game_map.map_id == mapID && $game_player.x == x && $game_player.y == y &&
!$game_player.through && $game_player.character_name != ""
return false
end
return true
end
@@ -201,8 +201,8 @@ class PokemonMapFactory
return false if !map.valid?(x, y)
return true if thisEvent.through
if thisEvent == $game_player
if !($DEBUG && Input.press?(Input::CTRL))
return false if !map.passableStrict?(x, y, 0, thisEvent)
if !($DEBUG && Input.press?(Input::CTRL)) && !map.passableStrict?(x, y, 0, thisEvent)
return false
end
elsif !map.passableStrict?(x, y, 0, thisEvent)
return false
@@ -289,12 +289,12 @@ class PokemonMapFactory
# NOTE: Assumes the event is 1x1 tile in size. Only returns one tile.
def getFacingTile(direction = nil, event = nil, steps = 1)
event = $game_player if event == nil
event = $game_player if event.nil?
return [0, 0, 0] if !event
x = event.x
y = event.y
id = event.map.map_id
direction = event.direction if direction == nil
direction = event.direction if direction.nil?
return getFacingTileFromPos(id, x, y, direction, steps)
end
@@ -511,6 +511,6 @@ end
def updateTilesets
maps = $map_factory.maps
maps.each do |map|
map.updateTileset if map
map&.updateTileset
end
end

View File

@@ -244,8 +244,9 @@ class Game_Character
next if self == event || !event.at_coordinate?(new_x, new_y) || event.through
return false if self != $game_player || event.character_name != ""
end
if $game_player.x == new_x && $game_player.y == new_y
return false if !$game_player.through && @character_name != ""
if $game_player.x == new_x && $game_player.y == new_y &&
!$game_player.through && @character_name != ""
return false
end
return true
end
@@ -356,7 +357,7 @@ class Game_Character
end
def force_move_route(move_route)
if @original_move_route == nil
if @original_move_route.nil?
@original_move_route = @move_route
@original_move_route_index = @move_route_index
end

View File

@@ -99,7 +99,7 @@ class Game_Event < Game_Character
return $PokemonGlobal.eventvars[[@map_id, @event.id]].to_i
end
def expired?(secs = 86400)
def expired?(secs = 86_400)
ontime = self.variable
time = pbGetTimeNow
return ontime && (time.to_i > ontime + secs)
@@ -109,8 +109,8 @@ class Game_Event < Game_Character
ontime = self.variable.to_i
return false if !ontime
now = pbGetTimeNow
elapsed = (now.to_i - ontime) / 86400
elapsed += 1 if (now.to_i - ontime) % 86400 > ((now.hour * 3600) + (now.min * 60) + now.sec)
elapsed = (now.to_i - ontime) / 86_400
elapsed += 1 if (now.to_i - ontime) % 86_400 > ((now.hour * 3600) + (now.min * 60) + now.sec)
return elapsed >= days
end
@@ -141,12 +141,12 @@ class Game_Event < Game_Character
def pbCheckEventTriggerAfterTurning
return if $game_system.map_interpreter.running? || @starting
if @event.name[/trainer\((\d+)\)/i]
return if @trigger != 2 # Event touch
return if !@event.name[/trainer\((\d+)\)/i]
distance = $~[1].to_i
if @trigger == 2 && pbEventCanReachPlayer?(self, $game_player, distance)
start if !jumping? && !over_trigger?
end
end
return if !pbEventCanReachPlayer?(self, $game_player, distance)
return if jumping? || over_trigger?
start
end
def check_event_trigger_touch(dir)
@@ -170,8 +170,8 @@ class Game_Event < Game_Character
def check_event_trigger_auto
case @trigger
when 2 # Event touch
if at_coordinate?($game_player.x, $game_player.y)
start if !jumping? && over_trigger?
if at_coordinate?($game_player.x, $game_player.y) && !jumping? && over_trigger?
start
end
when 3 # Autorun
start
@@ -197,7 +197,7 @@ class Game_Event < Game_Character
return if new_page == @page
@page = new_page
clear_starting
if @page == nil
if @page.nil?
@tile_id = 0
@character_name = ""
@character_hue = 0

View File

@@ -185,13 +185,12 @@ class Game_Player < Game_Character
return result if checkIfRunning && $game_system.map_interpreter.running?
# All event loops
$game_map.events.values.each do |event|
next if !triggers.include?(event.trigger)
next if !event.name[/trainer\((\d+)\)/i]
distance = $~[1].to_i
# If event coordinates and triggers are consistent
if pbEventCanReachPlayer?(event, self, distance) && triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
result.push(event) if !event.jumping? && !event.over_trigger?
end
next if !pbEventCanReachPlayer?(event, self, distance)
next if event.jumping? || event.over_trigger?
result.push(event)
end
return result
end
@@ -202,13 +201,12 @@ class Game_Player < Game_Character
return result if checkIfRunning && $game_system.map_interpreter.running?
# All event loops
$game_map.events.values.each do |event|
next if !triggers.include?(event.trigger)
next if !event.name[/counter\((\d+)\)/i]
distance = $~[1].to_i
# If event coordinates and triggers are consistent
if pbEventFacesPlayer?(event, self, distance) && triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
result.push(event) if !event.jumping? && !event.over_trigger?
end
next if !pbEventFacesPlayer?(event, self, distance)
next if event.jumping? || event.over_trigger?
result.push(event)
end
return result
end
@@ -355,34 +353,31 @@ class Game_Player < Game_Character
return false if !$game_map.valid?(new_x, new_y)
# All event loops
$game_map.events.values.each do |event|
next if !triggers.include?(event.trigger)
# If event coordinates and triggers are consistent
next if !event.at_coordinate?(new_x, new_y)
next if !triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
next if event.jumping? || event.over_trigger?
event.start
result = true
end
# If fitting event is not found
if result == false
# If front tile is a counter
if $game_map.counter?(new_x, new_y)
if result == false && $game_map.counter?(new_x, new_y)
# Calculate coordinates of 1 tile further away
new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
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|
next if !triggers.include?(event.trigger)
# If event coordinates and triggers are consistent
next if !event.at_coordinate?(new_x, new_y)
next if !triggers.include?(event.trigger)
# If starting determinant is front event (other than jumping)
next if event.jumping? || event.over_trigger?
event.start
result = true
end
end
end
return result
end
@@ -559,11 +554,10 @@ end
def pbGetPlayerCharset(charset, trainer = nil, force = false)
trainer = $player if !trainer
outfit = (trainer) ? trainer.outfit : 0
if $game_player && $game_player.charsetData && !force
return nil if $game_player.charsetData[0] == trainer.character_ID &&
return nil if !force && $game_player&.charsetData &&
$game_player.charsetData[0] == trainer.character_ID &&
$game_player.charsetData[1] == charset &&
$game_player.charsetData[2] == outfit
end
$game_player.charsetData = [trainer.character_ID, charset, outfit] if $game_player
ret = charset
if pbResolveBitmap("Graphics/Characters/" + ret + "_" + outfit.to_s)

View File

@@ -56,7 +56,7 @@ class Game_CommonEvent
def refresh
# Create an interpreter for parallel process if necessary
if self.trigger == 2 && switchIsOn?(self.switch_id)
if @interpreter == nil
if @interpreter.nil?
@interpreter = Interpreter.new
end
else

View File

@@ -7,11 +7,11 @@ class Sprite_Picture
end
def dispose
@sprite.dispose if @sprite
@sprite&.dispose
end
def update
@sprite.update if @sprite
@sprite&.update
# If picture file name is different from current one
if @picture_name != @picture.name
# Remember file name to instance variables
@@ -27,7 +27,7 @@ class Sprite_Picture
if @picture_name == ""
# Set sprite to invisible
if @sprite
@sprite.dispose if @sprite
@sprite&.dispose
@sprite = nil
end
return

View File

@@ -7,7 +7,7 @@ class Sprite_Timer
end
def dispose
@timer.dispose if @timer
@timer&.dispose
@timer = nil
@disposed = true
end

View File

@@ -8,7 +8,7 @@ class BushBitmap
end
def dispose
@bitmaps.each { |b| b.dispose if b }
@bitmaps.each { |b| b&.dispose }
end
def bitmap
@@ -80,13 +80,13 @@ class Sprite_Character < RPG::Sprite
end
def dispose
@bushbitmap.dispose if @bushbitmap
@bushbitmap&.dispose
@bushbitmap = nil
@charbitmap.dispose if @charbitmap
@charbitmap&.dispose
@charbitmap = nil
@reflection.dispose if @reflection
@reflection&.dispose
@reflection = nil
@surfbase.dispose if @surfbase
@surfbase&.dispose
@surfbase = nil
super
end
@@ -102,12 +102,12 @@ class Sprite_Character < RPG::Sprite
@character_name = @character.character_name
@character_hue = @character.character_hue
@oldbushdepth = @character.bush_depth
@charbitmap.dispose if @charbitmap
@charbitmap&.dispose
if @tile_id >= 384
@charbitmap = pbGetTileBitmap(@character.map.tileset_name, @tile_id,
@character_hue, @character.width, @character.height)
@charbitmapAnimated = false
@bushbitmap.dispose if @bushbitmap
@bushbitmap&.dispose
@bushbitmap = nil
@spriteoffset = false
@cw = Game_Map::TILE_WIDTH * @character.width
@@ -121,7 +121,7 @@ class Sprite_Character < RPG::Sprite
)
RPG::Cache.retain('Graphics/Characters/', @character_name, @character_hue) if @character == $game_player
@charbitmapAnimated = true
@bushbitmap.dispose if @bushbitmap
@bushbitmap&.dispose
@bushbitmap = nil
@spriteoffset = @character_name[/offset/i]
@cw = @charbitmap.width / 4
@@ -163,7 +163,7 @@ class Sprite_Character < RPG::Sprite
animation(animation, true)
@character.animation_id = 0
end
@reflection.update if @reflection
@surfbase.update if @surfbase
@reflection&.update
@surfbase&.update
end
end

View File

@@ -8,12 +8,10 @@ class Sprite_Reflection
@event = event
@height = 0
@fixedheight = false
if @event && @event != $game_player
if @event.name[/reflection\((\d+)\)/i]
if @event != $game_player && @event&.name[/reflection\((\d+)\)/i]
@height = $~[1].to_i || 0
@fixedheight = true
end
end
@viewport = viewport
@disposed = false
update
@@ -21,7 +19,7 @@ class Sprite_Reflection
def dispose
if !@disposed
@sprite.dispose if @sprite
@sprite&.dispose
@sprite = nil
@disposed = true
end

View File

@@ -21,7 +21,7 @@ class Sprite_SurfBase
def dispose
return if @disposed
@sprite.dispose if @sprite
@sprite&.dispose
@sprite = nil
@surfbitmap.dispose
@divebitmap.dispose

View File

@@ -122,10 +122,10 @@ class Spriteset_Map
@character_sprites.each do |sprite|
sprite.update
end
if self.map != $game_map
@weather.fade_in(:None, 0, 20)
else
if self.map == $game_map
@weather.fade_in($game_screen.weather_type, $game_screen.weather_max, $game_screen.weather_duration)
else
@weather.fade_in(:None, 0, 20)
end
@weather.ox = tmox
@weather.oy = tmoy

View File

@@ -19,7 +19,7 @@ class Sprite_Shadow < RPG::Sprite
end
def dispose
@chbitmap.dispose if @chbitmap
@chbitmap&.dispose
super
end
@@ -35,7 +35,7 @@ class Sprite_Shadow < RPG::Sprite
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
@chbitmap.dispose if @chbitmap
@chbitmap&.dispose
if @tile_id >= 384
@chbitmap = pbGetTileBitmap(@character.map.tileset_name,
@tile_id, @character.character_hue)
@@ -89,7 +89,7 @@ class Sprite_Shadow < RPG::Sprite
@deltay = ScreenPosHelper.pbScreenY(@source) - self.y
self.color = Color.new(0, 0, 0)
@distance = ((@deltax**2) + (@deltay**2))
self.opacity = @self_opacity * 13000 / ((@distance * 370 / @distancemax) + 6000)
self.opacity = @self_opacity * 13_000 / ((@distance * 370 / @distancemax) + 6000)
self.angle = 57.3 * Math.atan2(@deltax, @deltay)
@angle_trigo = self.angle + 90
@angle_trigo += 360 if @angle_trigo < 0
@@ -149,7 +149,7 @@ class Sprite_Character < RPG::Sprite
end
def clearShadows
@ombrelist.each { |s| s.dispose if s }
@ombrelist.each { |s| s&.dispose }
@ombrelist.clear
end
@@ -185,9 +185,8 @@ 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 &&
(ev.list[0].parameters == ["s"] || ev.list[0].parameters == ["o"]))
warn = true if ev.list != nil && 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
end
@@ -225,11 +224,11 @@ end
#===================================================
def XPML_read(map, markup, event, max_param_number = 0)
parameter_list = nil
return nil if !event || event.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
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

View File

@@ -57,17 +57,17 @@ class Particle_Engine
def realloc_effect(event, particle)
type = pbEventCommentInput(event, 1, "Particle Engine Type")
if type.nil?
particle.dispose if particle
particle&.dispose
return nil
end
type = type[0].downcase
cls = @effects[type]
if cls.nil?
particle.dispose if particle
particle&.dispose
return nil
end
if !particle || !particle.is_a?(cls)
particle.dispose if particle
particle&.dispose
particle = cls.new(event, @viewport)
end
return particle
@@ -93,7 +93,7 @@ class Particle_Engine
particle = realloc_effect(event, particle)
@effect[i] = particle
end
particle.update if particle
particle&.update
end
end
end
@@ -135,7 +135,7 @@ class ParticleSprite
end
def dispose
@sprite.dispose if @sprite
@sprite&.dispose
end
def bitmap=(value)
@@ -517,9 +517,9 @@ class Particle_Engine::Smokescreen < ParticleEffect_Event
end
multiple = 1.7
xgrav = @xgravity * multiple / @slowdown
xgrav = -xgrav if (rand(2) == 1)
xgrav = -xgrav if rand(2) == 1
ygrav = @ygravity * multiple / @slowdown
ygrav = -ygrav if (rand(2) == 1)
ygrav = -ygrav if rand(2) == 1
@particlex[i] += xgrav
@particley[i] += ygrav
@particlex[i] -= @__offsetx

View File

@@ -29,7 +29,7 @@ module ScreenPosHelper
end
def self.pbScreenZ(ch, height = nil)
if height == nil
if height.nil?
height = 0
if ch.tile_id > 0
height = 32

View File

@@ -171,7 +171,7 @@ class TilemapRenderer
bitmap = @bitmaps[filename]
@frame_counts[filename] = [bitmap.width / SOURCE_TILE_WIDTH, 1].max
if bitmap.height > SOURCE_TILE_HEIGHT && @bitmap_wraps[filename]
@frame_counts[filename] /= 2 if @bitmap_wraps[filename]
@frame_counts[filename] /= 2
end
end
return @frame_counts[filename]

View File

@@ -79,7 +79,7 @@ class TileDrawingHelper
end
def dispose
@tileset.dispose if @tileset
@tileset&.dispose
@tileset = nil
@autotiles.each_with_index do |autotile, i|
autotile.dispose
@@ -187,7 +187,7 @@ def bltMinimapAutotile(dstBitmap, x, y, srcBitmap, id)
end
def passable?(passages, tile_id)
return false if tile_id == nil
return false if tile_id.nil?
passage = passages[tile_id]
return (passage && passage < 15)
end

View File

@@ -27,7 +27,7 @@ module RPG
def self.fromCache(i)
return nil if !@cache.include?(i)
obj = @cache[i]
return nil if obj && obj.disposed?
return nil if obj&.disposed?
return obj
end

View File

@@ -177,7 +177,7 @@ end
def pbBottomLeftLines(window, lines, width = nil)
window.x = 0
window.width = width ? width : Graphics.width
window.width = width || Graphics.width
window.height = (window.borderY rescue 32) + (lines * 32)
window.y = Graphics.height - window.height
end
@@ -393,10 +393,10 @@ end
def pbDoEnsureBitmap(bitmap, dwidth, dheight)
if !bitmap || bitmap.disposed? || bitmap.width < dwidth || bitmap.height < dheight
oldfont = (bitmap && !bitmap.disposed?) ? bitmap.font : nil
bitmap.dispose if bitmap
bitmap&.dispose
bitmap = Bitmap.new([1, dwidth].max, [1, dheight].max)
(oldfont) ? bitmap.font = oldfont : pbSetSystemFont(bitmap)
bitmap.font.shadow = false if bitmap.font && bitmap.font.respond_to?("shadow")
bitmap.font.shadow = false if bitmap.font&.respond_to?("shadow")
end
return bitmap
end
@@ -666,7 +666,7 @@ end
def pbRestoreActivations(sprites, activeStatuses)
return if !sprites || !activeStatuses
activeStatuses.keys.each do |k|
if sprites[k] && sprites[k].is_a?(Window) && !pbDisposed?(sprites[k])
if sprites[k].is_a?(Window) && !pbDisposed?(sprites[k])
sprites[k].active = activeStatuses[k] ? true : false
end
end
@@ -689,7 +689,7 @@ def pbActivateWindow(sprites, key)
return if !sprites
activeStatuses = {}
sprites.each do |i|
if i[1] && i[1].is_a?(Window) && !pbDisposed?(i[1])
if i[1].is_a?(Window) && !pbDisposed?(i[1])
activeStatuses[i[0]] = i[1].active
i[1].active = (i[0] == key)
end
@@ -717,7 +717,7 @@ end
def addBackgroundPlane(sprites, planename, background, viewport = nil)
sprites[planename] = AnimatedPlane.new(viewport)
bitmapName = pbResolveBitmap("Graphics/Pictures/#{background}")
if bitmapName == nil
if bitmapName.nil?
# Plane should exist in any case
sprites[planename].bitmap = nil
sprites[planename].visible = false
@@ -739,7 +739,7 @@ end
# _viewport_ is a viewport to place the background in.
def addBackgroundOrColoredPlane(sprites, planename, background, color, viewport = nil)
bitmapName = pbResolveBitmap("Graphics/Pictures/#{background}")
if bitmapName == nil
if bitmapName.nil?
# Plane should exist in any case
sprites[planename] = ColoredPlane.new(color, viewport)
else
@@ -773,7 +773,7 @@ if !defined?(_INTL)
def _INTL(*args)
string = args[0].clone
(1...args.length).each do |i|
string.gsub!(/\{#{i}\}/, "#{args[i]}")
string.gsub!(/\{#{i}\}/, args[i].to_s)
end
return string
end
@@ -795,7 +795,7 @@ if !defined?(_MAPINTL)
def _MAPINTL(*args)
string = args[1].clone
(2...args.length).each do |i|
string.gsub!(/\{#{i}\}/, "#{args[i + 1]}")
string.gsub!(/\{#{i}\}/, args[i + 1].to_s)
end
return string
end

View File

@@ -127,16 +127,16 @@ class Window
def dispose
if !self.disposed?
@sprites.each do |i|
i[1].dispose if i[1]
i[1]&.dispose
@sprites[i[0]] = nil
end
@sidebitmaps.each_with_index do |bitmap, i|
bitmap.dispose if bitmap
bitmap&.dispose
@sidebitmaps[i] = nil
end
@blankcontents.dispose
@cursorbitmap.dispose if @cursorbitmap
@backbitmap.dispose if @backbitmap
@cursorbitmap&.dispose
@backbitmap&.dispose
@sprites.clear
@sidebitmaps.clear
@_windowskin = nil
@@ -191,7 +191,7 @@ class Window
def windowskin=(value)
@_windowskin = value
if value && value.is_a?(Bitmap) && !value.disposed? && value.width == 128
if value.is_a?(Bitmap) && !value.disposed? && value.width == 128
@rpgvx = true
else
@rpgvx = false
@@ -210,10 +210,10 @@ class Window
end
def cursor_rect=(value)
if !value
@cursor_rect.empty
else
if value
@cursor_rect.set(value.x, value.y, value.width, value.height)
else
@cursor_rect.empty
end
end
@@ -322,7 +322,7 @@ class Window
def ensureBitmap(bitmap, dwidth, dheight)
if !bitmap || bitmap.disposed? || bitmap.width < dwidth || bitmap.height < dheight
bitmap.dispose if bitmap
bitmap&.dispose
bitmap = Bitmap.new([1, dwidth].max, [1, dheight].max)
end
return bitmap
@@ -571,7 +571,12 @@ class Window
@sprites["back"].src_rect.set(0, 0, 0, 0)
end
end
if @openness != 255
if @openness == 255
@spritekeys.each do |k|
sprite = @sprites[k]
sprite.zoom_y = 1.0
end
else
opn = @openness / 255.0
@spritekeys.each do |k|
sprite = @sprites[k]
@@ -580,11 +585,6 @@ class Window
sprite.oy = 0
sprite.y = (@y + (@height / 2.0) + (@height * ratio * opn) - (@height / 2 * opn)).floor
end
else
@spritekeys.each do |k|
sprite = @sprites[k]
sprite.zoom_y = 1.0
end
end
i = 0
# Ensure Z order

View File

@@ -113,16 +113,16 @@ class SpriteWindow < Window
def dispose
if !self.disposed?
@sprites.each do |i|
i[1].dispose if i[1]
i[1]&.dispose
@sprites[i[0]] = nil
end
@sidebitmaps.each_with_index do |bitmap, i|
bitmap.dispose if bitmap
bitmap&.dispose
@sidebitmaps[i] = nil
end
@blankcontents.dispose
@cursorbitmap.dispose if @cursorbitmap
@backbitmap.dispose if @backbitmap
@cursorbitmap&.dispose
@backbitmap&.dispose
@sprites.clear
@sidebitmaps.clear
@_windowskin = nil
@@ -143,7 +143,7 @@ class SpriteWindow < Window
def viewport=(value)
@viewport = value
@spritekeys.each do |i|
@sprites[i].dispose if @sprites[i]
@sprites[i]&.dispose
if @sprites[i].is_a?(Sprite)
@sprites[i] = Sprite.new(@viewport)
else
@@ -189,10 +189,10 @@ class SpriteWindow < Window
end
def cursor_rect=(value)
if !value
@cursor_rect.empty
else
if value
@cursor_rect.set(value.x, value.y, value.width, value.height)
else
@cursor_rect.empty
end
end
@@ -358,7 +358,7 @@ class SpriteWindow < Window
@trim = [16, 16, 16, 16]
end
else
if value && value.is_a?(Bitmap) && !value.disposed? && value.width == 128
if value.is_a?(Bitmap) && !value.disposed? && value.width == 128
@rpgvx = true
else
@rpgvx = false
@@ -442,7 +442,7 @@ class SpriteWindow < Window
def ensureBitmap(bitmap, dwidth, dheight)
if !bitmap || bitmap.disposed? || bitmap.width < dwidth || bitmap.height < dheight
bitmap.dispose if bitmap
bitmap&.dispose
bitmap = Bitmap.new([1, dwidth].max, [1, dheight].max)
end
return bitmap
@@ -631,16 +631,14 @@ class SpriteWindow < Window
end
@sprites["contents"].x = @x + trimStartX
@sprites["contents"].y = @y + trimStartY
if (@compat & CompatBits::ShowScrollArrows) > 0 && @skinformat == 0
# Compatibility mode: Make scroll arrows visible
if @skinformat == 0 && @_windowskin && !@_windowskin.disposed? &&
if (@compat & CompatBits::ShowScrollArrows) > 0 && @skinformat == 0 &&
@_windowskin && !@_windowskin.disposed? &&
@contents && !@contents.disposed?
@sprites["scroll0"].visible = @visible && hascontents && @oy > 0
@sprites["scroll1"].visible = @visible && hascontents && @ox > 0
@sprites["scroll2"].visible = @visible && (@contents.width - @ox) > @width - trimWidth
@sprites["scroll3"].visible = @visible && (@contents.height - @oy) > @height - trimHeight
end
end
if @_windowskin && !@_windowskin.disposed?
borderX = startX + endX
borderY = startY + endY
@@ -781,7 +779,13 @@ class SpriteWindow < Window
@sprites["back"].src_rect.set(0, 0, 0, 0)
end
end
if @openness != 255
if @openness == 255
@spritekeys.each do |k|
sprite = @sprites[k]
sprite.zoom_x = 1.0
sprite.zoom_y = 1.0
end
else
opn = @openness / 255.0
@spritekeys.each do |k|
sprite = @sprites[k]
@@ -791,12 +795,6 @@ class SpriteWindow < Window
sprite.oy = 0
sprite.y = (@y + (@height / 2.0) + (@height * ratio * opn) - (@height / 2 * opn)).floor
end
else
@spritekeys.each do |k|
sprite = @sprites[k]
sprite.zoom_x = 1.0
sprite.zoom_y = 1.0
end
end
i = 0
# Ensure Z order
@@ -861,7 +859,7 @@ class SpriteWindow_Base < SpriteWindow
end
def setSkin(skin) # Filename of windowskin to apply. Supports XP, VX, and animated skins.
@customskin.dispose if @customskin
@customskin&.dispose
@customskin = nil
resolvedName = pbResolveBitmap(skin)
return if nil_or_empty?(resolvedName)
@@ -875,7 +873,7 @@ class SpriteWindow_Base < SpriteWindow
end
def setSystemFrame
@customskin.dispose if @customskin
@customskin&.dispose
@customskin = nil
__setWindowskin(@sysframe.bitmap)
__resolveSystemFrame
@@ -899,7 +897,7 @@ class SpriteWindow_Base < SpriteWindow
if @curframe != MessageConfig.pbGetSystemFrame
@curframe = MessageConfig.pbGetSystemFrame
if @sysframe && !@customskin
@sysframe.dispose if @sysframe
@sysframe&.dispose
@sysframe = AnimatedBitmap.new(@curframe)
RPG::Cache.retain(@curframe) if @curframe && !@curframe.empty?
@resolvedFrame = nil
@@ -924,9 +922,9 @@ class SpriteWindow_Base < SpriteWindow
end
def dispose
self.contents.dispose if self.contents
self.contents&.dispose
@sysframe.dispose
@customskin.dispose if @customskin
@customskin&.dispose
super
end
end

View File

@@ -160,7 +160,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base
def dispose
return if disposed?
@pausesprite.dispose if @pausesprite
@pausesprite&.dispose
@pausesprite = nil
super
end
@@ -490,10 +490,8 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base
drawSingleFormattedChar(self.contents, @fmtchars[i])
@lastDrawnChar = i
end
if !self.letterbyletter
# all characters were drawn, reset old font
self.contents.font = @oldfont if @oldfont
end
self.contents.font = @oldfont if !self.letterbyletter && @oldfont
if numchars > 0 && numchars != @numtextchars
fch = @fmtchars[numchars - 1]
if fch
@@ -579,7 +577,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base
def update
super
@pausesprite.update if @pausesprite && @pausesprite.visible
@pausesprite.update if @pausesprite&.visible
if @waitcount > 0
@waitcount -= 1
return
@@ -601,7 +599,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base
break if @textchars[@curchar] == "\n" || # newline
@textchars[@curchar] == "\1" || # pause
@textchars[@curchar] == "\2" || # letter-by-letter break
@textchars[@curchar] == nil
@textchars[@curchar].nil?
end
end
end

View File

@@ -26,7 +26,7 @@ class IconWindow < SpriteWindow_Base
end
def clearBitmaps
@_iconbitmap.dispose if @_iconbitmap
@_iconbitmap&.dispose
@_iconbitmap = nil
self.contents = nil if !self.disposed?
end
@@ -40,13 +40,13 @@ class IconWindow < SpriteWindow_Base
def setBitmap(file, hue = 0)
clearBitmaps
@name = file
return if file == nil
if file != ""
return if file.nil?
if file == ""
@_iconbitmap = nil
else
@_iconbitmap = AnimatedBitmap.new(file, hue)
# for compatibility
self.contents = @_iconbitmap ? @_iconbitmap.bitmap : nil
else
@_iconbitmap = nil
end
end
end
@@ -84,7 +84,7 @@ class PictureWindow < SpriteWindow_Base
end
def clearBitmaps
@_iconbitmap.dispose if @_iconbitmap
@_iconbitmap&.dispose
@_iconbitmap = nil
self.contents = nil if !self.disposed?
end

View File

@@ -280,19 +280,19 @@ class IconSprite < SpriteWrapper
oldrc = self.src_rect
clearBitmaps
@name = file
return if file == nil
if file != ""
return if file.nil?
if file == ""
@_iconbitmap = nil
else
@_iconbitmap = AnimatedBitmap.new(file, hue)
# for compatibility
self.bitmap = @_iconbitmap ? @_iconbitmap.bitmap : nil
self.src_rect = oldrc
else
@_iconbitmap = nil
end
end
def clearBitmaps
@_iconbitmap.dispose if @_iconbitmap
@_iconbitmap&.dispose
@_iconbitmap = nil
self.bitmap = nil if !self.disposed?
end
@@ -336,7 +336,7 @@ class ChangelingSprite < SpriteWrapper
end
def addBitmap(key, path)
@bitmaps[key].dispose if @bitmaps[key]
@bitmaps[key]&.dispose
@bitmaps[key] = AnimatedBitmap.new(path)
end

View File

@@ -17,7 +17,7 @@ class ColoredPlane < Plane
end
def dispose
self.bitmap.dispose if self.bitmap
self.bitmap&.dispose
super
end
@@ -59,7 +59,7 @@ class AnimatedPlane < Plane
private
def clear_bitmap
@bitmap.dispose if @bitmap
@bitmap&.dispose
@bitmap = nil
self.bitmap = nil if !self.disposed?
end

View File

@@ -174,7 +174,7 @@ def getFormattedTextFast(bitmap, xDst, yDst, widthDst, heightDst, text, lineheig
characters = []
textchunks = []
textchunks.push(text)
text = textchunks.join("")
text = textchunks.join
textchars = text.scan(/./m)
lastword = [0, 0] # position of last word
hadspace = false
@@ -406,7 +406,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
if controls.length == 0
ret = getFormattedTextFast(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight,
newlineBreaks, explicitBreaksOnly)
dummybitmap.dispose if dummybitmap
dummybitmap&.dispose
return ret
end
x = y = 0
@@ -414,7 +414,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
charactersInternal = []
# realtext = nil
# realtextStart = ""
# if !explicitBreaksOnly && textchunks.join("").length == 0
# if !explicitBreaksOnly && textchunks.join.length == 0
# # All commands occurred at the beginning of the text string
# realtext = (newlineBreaks) ? text : text.gsub(/\n/, " ")
# realtextStart = oldtext[0, oldtext.length - realtext.length]
@@ -432,7 +432,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
textlen += textchunks[i].scan(/./m).length
control[2] = textlen
end
text = textchunks.join("")
text = textchunks.join
textchars = text.scan(/./m)
colorstack = []
boldcount = 0
@@ -830,7 +830,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight =
# Remove all characters with Y greater or equal to _yDst_+_heightDst_
characters.delete_if { |ch| ch[2] >= yDst + heightDst } if heightDst >= 0
bitmap.font = oldfont
dummybitmap.dispose if dummybitmap
dummybitmap&.dispose
return characters
end
@@ -854,7 +854,7 @@ def getLineBrokenText(bitmap, value, width, dims)
return ret if !bitmap || bitmap.disposed? || width <= 0
textmsg = value.clone
ret.push(["", 0, 0, 0, bitmap.text_size("X").height, 0, 0, 0, 0])
while ((c = textmsg.slice!(/\n|(\S*([ \r\t\f]?))/)) != nil)
while (c = textmsg.slice!(/\n|(\S*([ \r\t\f]?))/)) != nil
break if c == ""
length = c.scan(/./m).length
ccheck = c
@@ -1083,8 +1083,8 @@ def drawTextEx(bitmap, x, y, width, numlines, text, baseColor, shadowColor)
end
def drawFormattedTextEx(bitmap, x, y, width, text, baseColor = nil, shadowColor = nil, lineheight = 32)
base = !baseColor ? Color.new(12 * 8, 12 * 8, 12 * 8) : baseColor.clone
shadow = !shadowColor ? Color.new(26 * 8, 26 * 8, 25 * 8) : shadowColor.clone
base = baseColor ? baseColor.clone : Color.new(12 * 8, 12 * 8, 12 * 8)
shadow = shadowColor ? shadowColor.clone : Color.new(26 * 8, 26 * 8, 25 * 8)
text = "<c2=" + colorToRgb16(base) + colorToRgb16(shadow) + ">" + text
chars = getFormattedText(bitmap, x, y, width, -1, text, lineheight)
drawFormattedChars(bitmap, chars)

View File

@@ -7,15 +7,15 @@ end
def pbMapInterpreterRunning?
interp = pbMapInterpreter
return interp && interp.running?
return interp&.running?
end
def pbRefreshSceneMap
$scene.miniupdate if $scene && $scene.is_a?(Scene_Map)
$scene.miniupdate if $scene.is_a?(Scene_Map)
end
def pbUpdateSceneMap
$scene.miniupdate if $scene && $scene.is_a?(Scene_Map) && !pbIsFaded?
$scene.miniupdate if $scene.is_a?(Scene_Map) && !pbIsFaded?
end
#===============================================================================
@@ -26,7 +26,7 @@ def pbEventCommentInput(*args)
list = args[0].list # List of commands for event or event page
elements = args[1] # Number of elements
trigger = args[2] # Trigger
return nil if list == nil
return nil if list.nil?
return nil unless list.is_a?(Array)
list.each do |item|
next unless item.code == 108 || item.code == 408
@@ -186,7 +186,7 @@ def pbChooseNumber(msgwindow, params)
Input.update
pbUpdateSceneMap
cmdwindow.update
msgwindow.update if msgwindow
msgwindow&.update
yield if block_given?
if Input.trigger?(Input::USE)
ret = cmdwindow.number
@@ -220,7 +220,7 @@ class FaceWindowVX < SpriteWindow_Base
faceinfo = face.split(",")
facefile = pbResolveBitmap("Graphics/Faces/" + faceinfo[0])
facefile = pbResolveBitmap("Graphics/Pictures/" + faceinfo[0]) if !facefile
self.contents.dispose if self.contents
self.contents&.dispose
@faceIndex = faceinfo[1].to_i
@facebitmaptmp = AnimatedBitmap.new(facefile)
@facebitmap = BitmapWrapper.new(96, 96)
@@ -240,7 +240,7 @@ class FaceWindowVX < SpriteWindow_Base
def dispose
@facebitmaptmp.dispose
@facebitmap.dispose if @facebitmap
@facebitmap&.dispose
super
end
end
@@ -374,10 +374,10 @@ end
#===============================================================================
def pbCreateStatusWindow(viewport = nil)
msgwindow = Window_AdvancedTextPokemon.new("")
if !viewport
msgwindow.z = 99999
else
if viewport
msgwindow.viewport = viewport
else
msgwindow.z = 99999
end
msgwindow.visible = false
msgwindow.letterbyletter = false
@@ -389,10 +389,10 @@ end
def pbCreateMessageWindow(viewport = nil, skin = nil)
msgwindow = Window_AdvancedTextPokemon.new("")
if !viewport
msgwindow.z = 99999
else
if viewport
msgwindow.viewport = viewport
else
msgwindow.z = 99999
end
msgwindow.visible = true
msgwindow.letterbyletter = true
@@ -447,10 +447,10 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni
text.gsub!(/\\pm/i, _INTL("${1}", $player.money.to_s_formatted)) if $player
text.gsub!(/\\n/i, "\n")
text.gsub!(/\\\[([0-9a-f]{8,8})\]/i) { "<c2=" + $1 + ">" }
text.gsub!(/\\pg/i, "\\b") if $player && $player.male?
text.gsub!(/\\pg/i, "\\r") if $player && $player.female?
text.gsub!(/\\pog/i, "\\r") if $player && $player.male?
text.gsub!(/\\pog/i, "\\b") if $player && $player.female?
text.gsub!(/\\pg/i, "\\b") if $player&.male?
text.gsub!(/\\pg/i, "\\r") if $player&.female?
text.gsub!(/\\pog/i, "\\r") if $player&.male?
text.gsub!(/\\pog/i, "\\b") if $player&.female?
text.gsub!(/\\pg/i, "")
text.gsub!(/\\pog/i, "")
text.gsub!(/\\b/i, "<c3=3050C8,D0D0C8>")
@@ -517,7 +517,7 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni
textlen += toUnformattedText(textchunks[i]).scan(/./m).length
controls[i][2] = textlen
end
text = textchunks.join("")
text = textchunks.join
signWaitCount = 0
signWaitTime = Graphics.frame_rate / 2
haveSpecialClose = false
@@ -534,10 +534,10 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni
haveSpecialClose = true
specialCloseSE = param
when "f"
facewindow.dispose if facewindow
facewindow&.dispose
facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
when "ff"
facewindow.dispose if facewindow
facewindow&.dispose
facewindow = FaceWindowVX.new(param)
when "ch"
cmds = param.clone
@@ -588,25 +588,25 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni
param = controls[i][1]
case control
when "f"
facewindow.dispose if facewindow
facewindow&.dispose
facewindow = PictureWindow.new("Graphics/Pictures/#{param}")
pbPositionNearMsgWindow(facewindow, msgwindow, :left)
facewindow.viewport = msgwindow.viewport
facewindow.z = msgwindow.z
when "ff"
facewindow.dispose if facewindow
facewindow&.dispose
facewindow = FaceWindowVX.new(param)
pbPositionNearMsgWindow(facewindow, msgwindow, :left)
facewindow.viewport = msgwindow.viewport
facewindow.z = msgwindow.z
when "g" # Display gold window
goldwindow.dispose if goldwindow
goldwindow&.dispose
goldwindow = pbDisplayGoldWindow(msgwindow)
when "cn" # Display coins window
coinwindow.dispose if coinwindow
coinwindow&.dispose
coinwindow = pbDisplayCoinsWindow(msgwindow, goldwindow)
when "pt" # Display battle points window
battlepointswindow.dispose if battlepointswindow
battlepointswindow&.dispose
battlepointswindow = pbDisplayBattlePointsWindow(msgwindow)
when "wu"
msgwindow.y = 0
@@ -650,7 +650,7 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni
break if !letterbyletter
Graphics.update
Input.update
facewindow.update if facewindow
facewindow&.update
if autoresume && msgwindow.waitcount == 0
msgwindow.resume if msgwindow.busy?
break if !msgwindow.busy?
@@ -677,11 +677,11 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni
if commandProc
ret = commandProc.call(msgwindow)
end
msgback.dispose if msgback
goldwindow.dispose if goldwindow
coinwindow.dispose if coinwindow
battlepointswindow.dispose if battlepointswindow
facewindow.dispose if facewindow
msgback&.dispose
goldwindow&.dispose
coinwindow&.dispose
battlepointswindow&.dispose
facewindow&.dispose
if haveSpecialClose
pbSEPlay(pbStringToAudioFile(specialCloseSE))
atTop = (msgwindow.y == 0)
@@ -752,7 +752,7 @@ def pbShowCommands(msgwindow, commands = nil, cmdIfCancel = 0, defaultCmd = 0)
Graphics.update
Input.update
cmdwindow.update
msgwindow.update if msgwindow
msgwindow&.update
yield if block_given?
if Input.trigger?(Input::BACK)
if cmdIfCancel > 0
@@ -832,7 +832,7 @@ def pbMessageWaitForInput(msgwindow, frames, showPause = false)
frames.times do
Graphics.update
Input.update
msgwindow.update if msgwindow
msgwindow&.update
pbUpdateSceneMap
if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK)
break
@@ -863,7 +863,7 @@ def pbFreeText(msgwindow, currenttext, passwordbox, maxlength, width = 240)
break
end
window.update
msgwindow.update if msgwindow
msgwindow&.update
yield if block_given?
end
Input.text_input = false

View File

@@ -23,7 +23,7 @@ class CharacterEntryHelper
end
def passwordChar=(value)
@passwordChar = value ? value : ""
@passwordChar = value || ""
end
def length
@@ -192,7 +192,7 @@ class Window_TextEntry < SpriteWindow_Base
@helper.cursor = 0 if @helper.cursor < 0
startpos = @helper.cursor
fromcursor = 0
while (startpos > 0)
while startpos > 0
c = (@helper.passwordChar != "") ? @helper.passwordChar : textscan[startpos - 1]
fromcursor += bitmap.text_size(c).width
break if fromcursor > width - 4
@@ -226,7 +226,7 @@ class Window_TextEntry_Keyboard < Window_TextEntry
def update
@frame += 1
@frame %= 20
self.refresh if ((@frame % 10) == 0)
self.refresh if (@frame % 10) == 0
return if !self.active
# Moving cursor
if Input.triggerex?(:LEFT) || Input.repeatex?(:LEFT)
@@ -460,7 +460,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
def update
@frame += 1
@frame %= 20
self.refresh if ((@frame % 10) == 0)
self.refresh if (@frame % 10) == 0
return if !self.active
# Moving cursor
if Input.triggerex?(:UP) || Input.repeatex?(:UP)
@@ -543,7 +543,7 @@ class Window_MultilineTextEntry < SpriteWindow_Base
textheight = text[4]
posToCursor = @cursorColumn - thiscolumn
if posToCursor >= 0
partialString = text[0].scan(/./m)[0, posToCursor].join("")
partialString = text[0].scan(/./m)[0, posToCursor].join
cursorX += bitmap.text_size(partialString).width
end
break

View File

@@ -138,7 +138,7 @@ def getPlayTime2(filename)
loop do
rstr = ""
ateof = false
while !file.eof?
until file.eof?
if (file.read(1)[0] rescue 0) == 0xFF
begin
rstr = file.read(3)
@@ -152,14 +152,14 @@ def getPlayTime2(filename)
if rstr[0] == 0xFB
t = rstr[1] >> 4
next if [0, 15].include?(t)
freqs = [44100, 22050, 11025, 48000]
freqs = [44_100, 22_050, 11_025, 48_000]
bitrates = [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]
bitrate = bitrates[t]
t = (rstr[1] >> 2) & 3
freq = freqs[t]
t = (rstr[1] >> 1) & 1
filesize = FileTest.size(filename)
frameLength = ((144000 * bitrate) / freq) + t
frameLength = ((144_000 * bitrate) / freq) + t
numFrames = filesize / (frameLength + 4)
time = (numFrames * 1152.0 / freq)
break

View File

@@ -58,7 +58,7 @@ def pbBGMPlay(param, volume = nil, pitch = nil)
return
elsif (RPG.const_defined?(:BGM) rescue false)
b = RPG::BGM.new(param.name, param.volume, param.pitch)
if b && b.respond_to?("play")
if b&.respond_to?("play")
b.play
return
end
@@ -108,7 +108,7 @@ def pbMEPlay(param, volume = nil, pitch = nil)
return
elsif (RPG.const_defined?(:ME) rescue false)
b = RPG::ME.new(param.name, param.volume, param.pitch)
if b && b.respond_to?("play")
if b&.respond_to?("play")
b.play
return
end
@@ -125,7 +125,7 @@ def pbMEStop(timeInSeconds = 0.0)
if $game_system && timeInSeconds > 0.0 && $game_system.respond_to?("me_fade")
$game_system.me_fade(timeInSeconds)
return
elsif $game_system && $game_system.respond_to?("me_stop")
elsif $game_system&.respond_to?("me_stop")
$game_system.me_stop(nil)
return
elsif (RPG.const_defined?(:ME) rescue false)
@@ -158,7 +158,7 @@ def pbBGSPlay(param, volume = nil, pitch = nil)
return
elsif (RPG.const_defined?(:BGS) rescue false)
b = RPG::BGS.new(param.name, param.volume, param.pitch)
if b && b.respond_to?("play")
if b&.respond_to?("play")
b.play
return
end
@@ -209,7 +209,7 @@ def pbSEPlay(param, volume = nil, pitch = nil)
end
if (RPG.const_defined?(:SE) rescue false)
b = RPG::SE.new(param.name, param.volume, param.pitch)
if b && b.respond_to?("play")
if b&.respond_to?("play")
b.play
return
end

View File

@@ -38,7 +38,7 @@ module Graphics
def self.update
update_KGC_SpecialTransition
@@transition.update if @@transition && !@@transition.disposed?
@@transition = nil if @@transition && @@transition.disposed?
@@transition = nil if @@transition&.disposed?
end
def self.judge_special_transition(duration, filename)
@@ -137,11 +137,11 @@ module Transitions
def dispose
return if disposed?
dispose_all
@sprites.each { |s| s.dispose if s }
@sprites.each { |s| s&.dispose }
@sprites.clear
@overworld_sprite.dispose
@overworld_bitmap.dispose if @overworld_bitmap
@viewport.dispose if @viewport
@overworld_bitmap&.dispose
@viewport&.dispose
@disposed = true
end
@@ -404,8 +404,8 @@ module Transitions
end
def dispose_all
@buffer_original.dispose if @buffer_original
@buffer_temp.dispose if @buffer_temp
@buffer_original&.dispose
@buffer_temp&.dispose
end
def update_anim
@@ -628,13 +628,13 @@ module Transitions
def dispose_all
# Dispose sprites
@bubbles_sprite.dispose if @bubbles_sprite
@splash_sprite.dispose if @splash_sprite
@black_sprite.dispose if @black_sprite
@bubbles_sprite&.dispose
@splash_sprite&.dispose
@black_sprite&.dispose
# Dispose bitmaps
@bubble_bitmap.dispose if @bubble_bitmap
@splash_bitmap.dispose if @splash_bitmap
@black_bitmap.dispose if @black_bitmap
@bubble_bitmap&.dispose
@splash_bitmap&.dispose
@black_bitmap&.dispose
end
def update_anim
@@ -704,12 +704,12 @@ module Transitions
def dispose_all
# Dispose sprites
if @ball_sprites
@ball_sprites.each { |s| s.dispose if s }
@ball_sprites.each { |s| s&.dispose }
@ball_sprites.clear
end
# Dispose bitmaps
@black_bitmap.dispose if @black_bitmap
@ball_bitmap.dispose if @ball_bitmap
@black_bitmap&.dispose
@ball_bitmap&.dispose
end
def update_anim
@@ -782,20 +782,20 @@ module Transitions
def dispose_all
# Dispose sprites
if @overworld_sprites
@overworld_sprites.each { |s| s.dispose if s }
@overworld_sprites.each { |s| s&.dispose }
@overworld_sprites.clear
end
if @black_sprites
@black_sprites.each { |s| s.dispose if s }
@black_sprites.each { |s| s&.dispose }
@black_sprites.clear
end
if @ball_sprites
@ball_sprites.each { |s| s.dispose if s }
@ball_sprites.each { |s| s&.dispose }
@ball_sprites.clear
end
# Dispose bitmaps
@black_bitmap.dispose if @black_bitmap
@ball_bitmap.dispose if @ball_bitmap
@black_bitmap&.dispose
@ball_bitmap&.dispose
end
def update_anim
@@ -892,12 +892,12 @@ module Transitions
def dispose_all
# Dispose sprites
if @ball_sprites
@ball_sprites.each { |s| s.dispose if s }
@ball_sprites.each { |s| s&.dispose }
@ball_sprites.clear
end
# Dispose bitmaps
@black_bitmap.dispose if @black_bitmap
@ball_bitmap.dispose if @ball_bitmap
@black_bitmap&.dispose
@ball_bitmap&.dispose
end
def update_anim
@@ -966,11 +966,11 @@ module Transitions
def dispose_all
# Dispose sprites
@ball_sprite.dispose if @ball_sprite
@ball_sprite&.dispose
# Dispose bitmaps
@black_bitmap.dispose if @black_bitmap
@curve_bitmap.dispose if @curve_bitmap
@ball_bitmap.dispose if @ball_bitmap
@black_bitmap&.dispose
@curve_bitmap&.dispose
@ball_bitmap&.dispose
end
def update_anim
@@ -1046,16 +1046,16 @@ module Transitions
def dispose_all
# Dispose sprites
if @ball_sprites
@ball_sprites.each { |s| s.dispose if s }
@ball_sprites.each { |s| s&.dispose }
@ball_sprites.clear
end
if @black_trail_sprites
@black_trail_sprites.each { |s| s.dispose if s }
@black_trail_sprites.each { |s| s&.dispose }
@black_trail_sprites.clear
end
# Dispose bitmaps
@black_bitmap.dispose if @black_bitmap
@ball_bitmap.dispose if @ball_bitmap
@black_bitmap&.dispose
@ball_bitmap&.dispose
end
def update_anim
@@ -1122,11 +1122,11 @@ module Transitions
def dispose_all
# Dispose sprites
@ball_sprite.dispose if @ball_sprite
@black_sprite.dispose if @black_sprite
@ball_sprite&.dispose
@black_sprite&.dispose
# Dispose bitmaps
@black_bitmap.dispose if @black_bitmap
@ball_bitmap.dispose if @ball_bitmap
@black_bitmap&.dispose
@ball_bitmap&.dispose
end
def update_anim
@@ -1194,14 +1194,14 @@ module Transitions
def dispose_all
# Dispose sprites
@ball_sprites.each { |s| s.dispose if s }
@ball_sprites.each { |s| s&.dispose }
@ball_sprites.clear
# Dispose bitmaps
@black_1_bitmap.dispose if @black_1_bitmap
@black_2_bitmap.dispose if @black_2_bitmap
@black_3_bitmap.dispose if @black_3_bitmap
@black_4_bitmap.dispose if @black_4_bitmap
@ball_bitmap.dispose if @ball_bitmap
@black_1_bitmap&.dispose
@black_2_bitmap&.dispose
@black_3_bitmap&.dispose
@black_4_bitmap&.dispose
@ball_bitmap&.dispose
end
def update_anim

View File

@@ -10,7 +10,7 @@ class PictureSprite < SpriteWrapper
end
def dispose
@pictureBitmap.dispose if @pictureBitmap
@pictureBitmap&.dispose
super
end
@@ -22,7 +22,7 @@ class PictureSprite < SpriteWrapper
def update
super
@pictureBitmap.update if @pictureBitmap
@pictureBitmap&.update
# If picture file name is different from current one
if @customBitmap && @picture.name == ""
self.bitmap = (@customBitmapIsBitmap) ? @customBitmap : @customBitmap.bitmap
@@ -32,13 +32,13 @@ class PictureSprite < SpriteWrapper
@hue = @picture.hue.to_i
# If file name is not empty
if @picture_name == ""
@pictureBitmap.dispose if @pictureBitmap
@pictureBitmap&.dispose
@pictureBitmap = nil
self.visible = false
return
end
# Get picture graphic
@pictureBitmap.dispose if @pictureBitmap
@pictureBitmap&.dispose
@pictureBitmap = AnimatedBitmap.new(@picture_name, @hue)
self.bitmap = (@pictureBitmap) ? @pictureBitmap.bitmap : nil
elsif @picture_name == ""
@@ -175,7 +175,7 @@ class EventScene
end
def main
while !disposed?
until disposed?
update
end
end

View File

@@ -53,7 +53,7 @@ module GameData
end
def call_after_evolution(*args)
@after_evolution_proc.call(*args) if @after_evolution_proc
@after_evolution_proc&.call(*args)
end
end
end
@@ -500,8 +500,7 @@ GameData::Evolution.register({
:minimum_level => 1, # Needs any level up
:level_up_proc => proc { |pkmn, parameter|
map_metadata = $game_map.metadata
next map_metadata && map_metadata.town_map_position &&
map_metadata.town_map_position[0] == parameter
next map_metadata&.town_map_position && map_metadata.town_map_position[0] == parameter
}
})

View File

@@ -42,11 +42,9 @@ end
#===============================================================================
def pbLoadPhoneData
$game_temp = Game_Temp.new if !$game_temp
if !$game_temp.phone_messages_data
if pbRgssExists?("Data/phone.dat")
if !$game_temp.phone_messages_data && pbRgssExists?("Data/phone.dat")
$game_temp.phone_messages_data = load_data("Data/phone.dat")
end
end
return $game_temp.phone_messages_data
end
@@ -66,11 +64,9 @@ end
#===============================================================================
def pbLoadBattleAnimations
$game_temp = Game_Temp.new if !$game_temp
if !$game_temp.battle_animations_data
if pbRgssExists?("Data/PkmnAnimations.rxdata")
if !$game_temp.battle_animations_data && pbRgssExists?("Data/PkmnAnimations.rxdata")
$game_temp.battle_animations_data = load_data("Data/PkmnAnimations.rxdata")
end
end
return $game_temp.battle_animations_data
end

View File

@@ -188,7 +188,7 @@ module GameData
:KYOGRE => [:BLUEORB],
:GROUDON => [:REDORB]
}
return combos[species] && combos[species].include?(@id)
return combos[species]&.include?(@id)
end
end
end

View File

@@ -51,8 +51,8 @@ module GameData
def self.each_of_version(version = 0)
self.each do |data|
yield data if data.version == version
if version > 0
yield data if data.version == 0 && !self::DATA.has_key?([data.map, version])
if version > 0 && data.version == 0 && !self::DATA.has_key?([data.map, version])
yield data
end
end
end

View File

@@ -48,7 +48,7 @@ module GameData
def self.charset_filename_brief(tr_type)
ret = self.charset_filename(tr_type)
ret.slice!("Graphics/Characters/") if ret
ret&.slice!("Graphics/Characters/")
return ret
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -136,17 +136,17 @@ class Battle::Battler
#=============================================================================
def hasMega?
return false if @effects[PBEffects::Transform]
return @pokemon && @pokemon.hasMegaForm?
return @pokemon&.hasMegaForm?
end
def mega?; return @pokemon && @pokemon.mega?; end
def mega?; return @pokemon&.mega?; end
def hasPrimal?
return false if @effects[PBEffects::Transform]
return @pokemon && @pokemon.hasPrimalForm?
return @pokemon&.hasPrimalForm?
end
def primal?; return @pokemon && @pokemon.primal?; end
def primal?; return @pokemon&.primal?; end
def shadowPokemon?; return false; end
@@ -184,11 +184,11 @@ class Battle::Battler
def shiny?
return @effects[PBEffects::Illusion].shiny? if @effects[PBEffects::Illusion]
return @pokemon && @pokemon.shiny?
return @pokemon&.shiny?
end
def super_shiny?
return @pokemon && @pokemon.super_shiny?
return @pokemon&.super_shiny?
end
def owned?
@@ -295,7 +295,7 @@ class Battle::Battler
end
def isSpecies?(species)
return @pokemon && @pokemon.isSpecies?(species)
return @pokemon&.isSpecies?(species)
end
# Returns the active types of this Pokémon. The array should not include the
@@ -311,8 +311,8 @@ class Battle::Battler
ret.push(:NORMAL) if ret.length == 0
end
# Add the third type specially.
if withType3 && @effects[PBEffects::Type3]
ret.push(@effects[PBEffects::Type3]) if !ret.include?(@effects[PBEffects::Type3])
if withType3 && @effects[PBEffects::Type3] && !ret.include?(@effects[PBEffects::Type3])
ret.push(@effects[PBEffects::Type3])
end
return ret
end

View File

@@ -277,15 +277,14 @@ class Battle::Battler
end
end
# Zygarde - Power Construct
if isSpecies?(:ZYGARDE) && self.ability == :POWERCONSTRUCT && endOfRound
if @hp <= @totalhp / 2 && @form < 2 # Turn into Complete Forme
if isSpecies?(:ZYGARDE) && self.ability == :POWERCONSTRUCT && endOfRound &&
@hp <= @totalhp / 2 && @form < 2 # Turn into Complete Forme
newForm = @form + 2
@battle.pbDisplay(_INTL("You sense the presence of many!"))
@battle.pbShowAbilitySplash(self, true)
@battle.pbHideAbilitySplash(self)
pbChangeForm(newForm, _INTL("{1} transformed into its Complete Forme!", pbThis))
end
end
# Morpeko - Hunger Switch
if isSpecies?(:MORPEKO) && hasActiveAbility?(:HUNGERSWITCH) && endOfRound
# Intentionally doesn't show the ability splash or a message

View File

@@ -281,11 +281,11 @@ class Battle::Battler
def pbCanSleepYawn?
return false if self.status != :NONE
if affectedByTerrain?
return false if [:Electric, :Misty].include?(@battle.field.terrain)
if affectedByTerrain? && [:Electric, :Misty].include?(@battle.field.terrain)
return false
end
if !hasActiveAbility?(:SOUNDPROOF)
return false if @battle.allBattlers.any? { |b| b.effects[PBEffects::Uproar] > 0 }
if !hasActiveAbility?(:SOUNDPROOF) && @battle.allBattlers.any? { |b| b.effects[PBEffects::Uproar] > 0 }
return false
end
if Battle::AbilityEffects.triggerStatusImmunityNonIgnorable(self.ability, self, :SLEEP)
return false
@@ -454,8 +454,7 @@ class Battle::Battler
@battle.pbDisplay(_INTL("{1} surrounds itself with misty terrain!", pbThis(true))) if showMessages
return false
end
if selfInflicted || !@battle.moldBreaker
if hasActiveAbility?(:OWNTEMPO)
if (selfInflicted || !@battle.moldBreaker) && hasActiveAbility?(:OWNTEMPO)
if showMessages
@battle.pbShowAbilitySplash(self)
if Battle::Scene::USE_ABILITY_SPLASH
@@ -467,7 +466,6 @@ class Battle::Battler
end
return false
end
end
if pbOwnSide.effects[PBEffects::Safeguard] > 0 && !selfInflicted &&
!(user && user.hasActiveAbility?(:INFILTRATOR))
@battle.pbDisplay(_INTL("{1}'s team is protected by Safeguard!", pbThis)) if showMessages

View File

@@ -118,7 +118,8 @@ class Battle::Battler
return @stages[stat] <= -6
end
def pbCanLowerStatStage?(stat, user = nil, move = nil, showFailMsg = false, ignoreContrary = false, ignoreMirrorArmor = false)
def pbCanLowerStatStage?(stat, user = nil, move = nil, showFailMsg = false,
ignoreContrary = false, ignoreMirrorArmor = false)
return false if fainted?
if !@battle.moldBreaker
# Contrary
@@ -126,12 +127,14 @@ class Battle::Battler
return pbCanRaiseStatStage?(stat, user, move, showFailMsg, true)
end
# Mirror Armor
if hasActiveAbility?(:MIRRORARMOR) && !ignoreMirrorArmor && user && user.index != @index
return true if !statStageAtMin?(stat)
if hasActiveAbility?(:MIRRORARMOR) && !ignoreMirrorArmor &&
user && user.index != @index && !statStageAtMin?(stat)
return true
end
end
if !user || user.index != @index # Not self-inflicted
if @effects[PBEffects::Substitute] > 0 && (ignoreMirrorArmor || !(move && move.ignoresSubstitute?(user)))
if @effects[PBEffects::Substitute] > 0 &&
(ignoreMirrorArmor || !(move && move.ignoresSubstitute?(user)))
@battle.pbDisplay(_INTL("{1} is protected by its substitute!", pbThis)) if showFailMsg
return false
end
@@ -328,14 +331,13 @@ class Battle::Battler
pbThis, user.pbThis(true), user.abilityName))
return false
end
if abilityActive?
if Battle::AbilityEffects.triggerStatLossImmunity(self.ability, self, :ATTACK, @battle, false) ||
Battle::AbilityEffects.triggerStatLossImmunityNonIgnorable(self.ability, self, :ATTACK, @battle, false)
if abilityActive? &&
(Battle::AbilityEffects.triggerStatLossImmunity(self.ability, self, :ATTACK, @battle, false) ||
Battle::AbilityEffects.triggerStatLossImmunityNonIgnorable(self.ability, self, :ATTACK, @battle, false))
@battle.pbDisplay(_INTL("{1}'s {2} prevented {3}'s {4} from working!",
pbThis, abilityName, user.pbThis(true), user.abilityName))
return false
end
end
allAllies.each do |b|
next if !b.abilityActive?
if Battle::AbilityEffects.triggerStatLossImmunityFromAlly(b.ability, b, self, :ATTACK, @battle, false)

View File

@@ -378,7 +378,7 @@ class Battle::Battler
def pbItemsOnUnnerveEnding
@battle.pbPriority(true).each do |b|
b.pbHeldItemTriggerCheck if b.item && b.item.is_berry?
b.pbHeldItemTriggerCheck if b.item&.is_berry?
end
end

View File

@@ -175,14 +175,13 @@ class Battle::Battler
elsif @effects[PBEffects::Encore] > 0 && choice[1] >= 0 &&
@battle.pbCanShowCommands?(@index)
idxEncoredMove = pbEncoredMoveIndex
if idxEncoredMove >= 0 && @battle.pbCanChooseMove?(@index, idxEncoredMove, false)
if choice[1] != idxEncoredMove # Change move if battler was Encored mid-round
if idxEncoredMove >= 0 && choice[1] != idxEncoredMove &&
@battle.pbCanChooseMove?(@index, idxEncoredMove, false) # Change move if battler was Encored mid-round
choice[1] = idxEncoredMove
choice[2] = @moves[idxEncoredMove]
choice[3] = -1 # No target chosen
end
end
end
# Labels the move being used as "move"
move = choice[2]
return if !move # if move was not chosen somehow
@@ -203,8 +202,7 @@ class Battle::Battler
move = choice[2] # In case disobedience changed the move to be used
return if !move # if move was not chosen somehow
# Subtract PP
if !specialUsage
if !pbReducePP(move)
if !specialUsage && !pbReducePP(move)
@battle.pbDisplay(_INTL("{1} used {2}!", pbThis, move.name))
@battle.pbDisplay(_INTL("But there was no PP left for the move!"))
@lastMoveUsed = nil
@@ -216,7 +214,6 @@ class Battle::Battler
pbEndTurn(choice)
return
end
end
# Stance Change
if isSpecies?(:AEGISLASH) && self.ability == :STANCECHANGE
if move.damagingMove?
@@ -356,8 +353,9 @@ class Battle::Battler
end
end
# Protean
if user.hasActiveAbility?([:LIBERO, :PROTEAN]) && !move.callsAnotherMove? && !move.snatched
if user.pbHasOtherType?(move.calcType) && !GameData::Type.get(move.calcType).pseudo_type
if user.hasActiveAbility?([:LIBERO, :PROTEAN]) &&
!move.callsAnotherMove? && !move.snatched &&
user.pbHasOtherType?(move.calcType) && !GameData::Type.get(move.calcType).pseudo_type
@battle.pbShowAbilitySplash(user)
user.pbChangeTypes(move.calcType)
typeName = GameData::Type.get(move.calcType).name
@@ -372,7 +370,6 @@ class Battle::Battler
targets = pbFindTargets(choice, move, user)
end
end
end
#---------------------------------------------------------------------------
magicCoater = -1
magicBouncer = -1
@@ -486,7 +483,7 @@ class Battle::Battler
end
pbProcessMoveHit(move, b, newTargets, 0, false) if success
b.lastMoveFailed = true if !success
targets.each { |otherB| otherB.pbFaint if otherB && otherB.fainted? }
targets.each { |otherB| otherB.pbFaint if otherB&.fainted? }
user.pbFaint if user.fainted?
end
# Magic Coat's bouncing back (move has no targets)
@@ -502,14 +499,14 @@ class Battle::Battler
success = pbProcessMoveHit(move, mc, [], 0, false)
end
mc.lastMoveFailed = true if !success
targets.each { |b| b.pbFaint if b && b.fainted? }
targets.each { |b| b.pbFaint if b&.fainted? }
user.pbFaint if user.fainted?
end
end
# Move-specific effects after all hits
targets.each { |b| move.pbEffectAfterAllHits(user, b) }
# Faint if 0 HP
targets.each { |b| b.pbFaint if b && b.fainted? }
targets.each { |b| b.pbFaint if b&.fainted? }
user.pbFaint if user.fainted?
# External/general effects after all hits. Eject Button, Shell Bell, etc.
pbEffectsAfterMove(user, targets, move, realNumHits)
@@ -707,7 +704,7 @@ class Battle::Battler
@battle.pbPriority(true).each { |b| b.pbItemHPHealCheck }
# Animate battlers fainting (checks all battlers rather than just targets
# because Flame Burst's splash damage affects non-targets)
@battle.pbPriority(true).each { |b| b.pbFaint if b && b.fainted? }
@battle.pbPriority(true).each { |b| b.pbFaint if b&.fainted? }
end
@battle.pbJudgeCheckpoint(user, move)
# Main effect (recoil/drain, etc.)
@@ -716,7 +713,7 @@ class Battle::Battler
move.pbEffectAgainstTarget(user, b)
end
move.pbEffectGeneral(user)
targets.each { |b| b.pbFaint if b && b.fainted? }
targets.each { |b| b.pbFaint if b&.fainted? }
user.pbFaint if user.fainted?
# Additional effect
if !user.hasActiveAbility?(:SHEERFORCE)
@@ -761,14 +758,13 @@ class Battle::Battler
end
end
# Fainting
targets.each { |b| b.pbFaint if b && b.fainted? }
targets.each { |b| b.pbFaint if b&.fainted? }
user.pbFaint if user.fainted?
# Dragon Darts' second half of attack
if move.pbRepeatHit? && hitNum == 0
if targets.any? { |b| !b.fainted? && !b.damageState.unaffected }
if move.pbRepeatHit? && hitNum == 0 &&
targets.any? { |b| !b.fainted? && !b.damageState.unaffected }
pbProcessMoveHit(move, user, all_targets, 1, skipAccuracyCheck)
end
end
return true
end
end

View File

@@ -265,13 +265,11 @@ class Battle::Battler
end
end
# Paralysis
if @status == :PARALYSIS
if @battle.pbRandom(100) < 25
if @status == :PARALYSIS && @battle.pbRandom(100) < 25
pbContinueStatus
@lastMoveFailed = true
return false
end
end
# Infatuation
if @effects[PBEffects::Attract] >= 0
@battle.pbCommonAnimation("Attract", self)
@@ -358,11 +356,10 @@ class Battle::Battler
end
target.damageState.protected = true
@battle.successStates[user.index].protected = true
if move.pbContactMove?(user) && user.affectedByContactEffect?
if user.pbCanLowerStatStage?(:ATTACK, target)
if move.pbContactMove?(user) && user.affectedByContactEffect? &&
user.pbCanLowerStatStage?(:ATTACK, target)
user.pbLowerStatStage(:ATTACK, (Settings::MECHANICS_GENERATION >= 8) ? 1 : 2, target)
end
end
return false
end
# Spiky Shield
@@ -389,8 +386,9 @@ class Battle::Battler
end
target.damageState.protected = true
@battle.successStates[user.index].protected = true
if move.pbContactMove?(user) && user.affectedByContactEffect?
user.pbPoison(target) if user.pbCanPoison?(target, false)
if move.pbContactMove?(user) && user.affectedByContactEffect? &&
user.pbCanPoison?(target, false)
user.pbPoison(target)
end
return false
end
@@ -402,11 +400,10 @@ class Battle::Battler
end
target.damageState.protected = true
@battle.successStates[user.index].protected = true
if move.pbContactMove?(user) && user.affectedByContactEffect?
if user.pbCanLowerStatStage?(:DEFENSE, target)
if move.pbContactMove?(user) && user.affectedByContactEffect? &&
user.pbCanLowerStatStage?(:DEFENSE, target)
user.pbLowerStatStage(:DEFENSE, 2, target)
end
end
return false
end
# Mat Block
@@ -550,8 +547,8 @@ class Battle::Battler
end
end
if target.effects[PBEffects::SkyDrop] >= 0 &&
target.effects[PBEffects::SkyDrop] != user.index
miss = true if !move.hitsFlyingTargets?
target.effects[PBEffects::SkyDrop] != user.index && !move.hitsFlyingTargets?
miss = true
end
end
target.damageState.invulnerable = true if miss
@@ -572,9 +569,7 @@ class Battle::Battler
def pbMissMessage(move, user, target)
if target.damageState.affection_missed
@battle.pbDisplay(_INTL("{1} avoided the move in time with your shout!", target.pbThis))
elsif move.pbTarget(user).num_targets > 1
@battle.pbDisplay(_INTL("{1} avoided the attack!", target.pbThis))
elsif target.effects[PBEffects::TwoTurnAttack]
elsif move.pbTarget(user).num_targets > 1 || target.effects[PBEffects::TwoTurnAttack]
@battle.pbDisplay(_INTL("{1} avoided the attack!", target.pbThis))
elsif !move.pbMissMessage(user, target)
@battle.pbDisplay(_INTL("{1}'s attack missed!", user.pbThis))

View File

@@ -45,28 +45,27 @@ class Battle::Battler
end
if target.opposes?(user)
# Rage
if target.effects[PBEffects::Rage] && !target.fainted?
if target.pbCanRaiseStatStage?(:ATTACK, target)
if target.effects[PBEffects::Rage] && !target.fainted? &&
target.pbCanRaiseStatStage?(:ATTACK, target)
@battle.pbDisplay(_INTL("{1}'s rage is building!", target.pbThis))
target.pbRaiseStatStage(:ATTACK, 1, target)
end
end
# Beak Blast
if target.effects[PBEffects::BeakBlast]
PBDebug.log("[Lingering effect] #{target.pbThis}'s Beak Blast")
if move.pbContactMove?(user) && user.affectedByContactEffect?
target.pbBurn(user) if target.pbCanBurn?(user, false, self)
if move.pbContactMove?(user) && user.affectedByContactEffect? &&
target.pbCanBurn?(user, false, self)
target.pbBurn(user)
end
end
# Shell Trap (make the trapper move next if the trap was triggered)
if target.effects[PBEffects::ShellTrap] &&
@battle.choices[target.index][0] == :UseMove && !target.movedThisRound?
if target.damageState.hpLost > 0 && !target.damageState.substitute && move.physicalMove?
if target.effects[PBEffects::ShellTrap] && move.physicalMove? &&
@battle.choices[target.index][0] == :UseMove && !target.movedThisRound? &&
target.damageState.hpLost > 0 && !target.damageState.substitute
target.tookPhysicalHit = true
target.effects[PBEffects::MoveNext] = true
target.effects[PBEffects::Quash] = 0
end
end
# Grudge
if target.effects[PBEffects::Grudge] && target.fainted?
move.pp = 0
@@ -74,13 +73,12 @@ class Battle::Battler
user.pbThis, move.name))
end
# Destiny Bond (recording that it should apply)
if target.effects[PBEffects::DestinyBond] && target.fainted?
if user.effects[PBEffects::DestinyBondTarget] < 0
if target.effects[PBEffects::DestinyBond] && target.fainted? &&
user.effects[PBEffects::DestinyBondTarget] < 0
user.effects[PBEffects::DestinyBondTarget] = target.index
end
end
end
end
#=============================================================================
# Effects after all hits (i.e. at end of move usage)
@@ -114,10 +112,10 @@ class Battle::Battler
if user.abilityActive?
Battle::AbilityEffects.triggerOnEndOfUsingMove(user.ability, user, targets, move, @battle)
end
# Greninja - Battle Bond
if !user.fainted? && !user.effects[PBEffects::Transform] &&
user.isSpecies?(:GRENINJA) && user.ability == :BATTLEBOND
if !@battle.pbAllFainted?(user.idxOpposingSide) &&
!@battle.pbAllFainted?(user.idxOpposingSide)
# Greninja - Battle Bond
if user.isSpecies?(:GRENINJA) && user.ability == :BATTLEBOND &&
!@battle.battleBond[user.index & 1][user.pokemonIndex]
numFainted = 0
targets.each { |b| numFainted += 1 if b.damageState.fainted }
@@ -129,11 +127,8 @@ class Battle::Battler
user.pbChangeForm(2, _INTL("{1} became Ash-Greninja!", user.pbThis))
end
end
end
# Cramorant = Gulp Missile
if !user.fainted? && !user.effects[PBEffects::Transform] &&
user.isSpecies?(:CRAMORANT) && user.ability == :GULPMISSILE && user.form == 0
if !@battle.pbAllFainted?(user.idxOpposingSide) &&
if user.isSpecies?(:CRAMORANT) && user.ability == :GULPMISSILE && user.form == 0 &&
((move.id == :SURF && numHits > 0) || (move.id == :DIVE && move.chargingTurn))
# NOTE: Intentionally no ability splash or message here.
user.pbChangeForm((user.hp > user.totalhp / 2) ? 1 : 2, nil)
@@ -181,51 +176,42 @@ class Battle::Battler
def pbEffectsAfterMove2(user, targets, move, numHits, switched_battlers)
# Target's held item (Eject Button, Red Card, Eject Pack)
@battle.pbPriority(true).each do |b|
if targets.any? { |targetB| targetB.index == b.index }
if !b.damageState.unaffected && b.damageState.calcDamage > 0 && b.itemActive?
if targets.any? { |targetB| targetB.index == b.index } &&
!b.damageState.unaffected && b.damageState.calcDamage > 0 && b.itemActive?
Battle::ItemEffects.triggerAfterMoveUseFromTarget(b.item, b, user, move, switched_battlers, @battle)
end
end
# Target's Eject Pack
if switched_battlers.empty? && b.index != user.index
if b.pbItemOnStatDropped(user)
if switched_battlers.empty? && b.index != user.index && b.pbItemOnStatDropped(user)
switched_battlers.push(b.index)
end
end
end
# User's held item (Life Orb, Shell Bell, Throat Spray, Eject Pack)
if !switched_battlers.include?(user.index) && user.itemActive? # Only if user hasn't switched out
Battle::ItemEffects.triggerAfterMoveUseFromUser(user.item, user, targets, move, numHits, @battle)
end
# Target's ability (Berserk, Color Change, Emergency Exit, Pickpocket, Wimp Out)
@battle.pbPriority(true).each do |b|
if targets.any? { |targetB| targetB.index == b.index }
if !b.damageState.unaffected && !switched_battlers.include?(b.index) && b.abilityActive?
if targets.any? { |targetB| targetB.index == b.index } &&
!b.damageState.unaffected && !switched_battlers.include?(b.index) && b.abilityActive?
Battle::AbilityEffects.triggerAfterMoveUseFromTarget(b.ability, b, user, move, switched_battlers, @battle)
end
end
# Target's Emergency Exit, Wimp Out (including for Pokémon hurt by Flame Burst)
if switched_battlers.empty? && move.damagingMove? && b.index != user.index
if b.pbAbilitiesOnDamageTaken(user)
if switched_battlers.empty? && move.damagingMove? &&
b.index != user.index && b.pbAbilitiesOnDamageTaken(user)
switched_battlers.push(b.index)
end
end
end
end
# Everything in this method is negated by Sheer Force.
def pbEffectsAfterMove3(user, targets, move, numHits, switched_battlers)
# User's held item that switches it out (Eject Pack)
if switched_battlers.empty?
if user.pbItemOnStatDropped(user)
if switched_battlers.empty? && user.pbItemOnStatDropped(user)
switched_battlers.push(user.index)
end
end
# User's ability (Emergency Exit, Wimp Out)
if switched_battlers.empty? && move.damagingMove?
if user.pbAbilitiesOnDamageTaken(user)
if switched_battlers.empty? && move.damagingMove? && user.pbAbilitiesOnDamageTaken(user)
switched_battlers.push(user.index)
end
end
end
end

View File

@@ -140,7 +140,7 @@ class Battle::Move
def ignoresSubstitute?(user) # user is the Pokémon using this move
if Settings::MECHANICS_GENERATION >= 6
return true if soundMove?
return true if user && user.hasActiveAbility?(:INFILTRATOR)
return true if user&.hasActiveAbility?(:INFILTRATOR)
end
return false
end

View File

@@ -31,28 +31,29 @@ class Battle::Move
#=============================================================================
def pbCalcTypeModSingle(moveType, defType, user, target)
ret = Effectiveness.calculate_one(moveType, defType)
if Effectiveness.ineffective_type?(moveType, defType)
# Ring Target
if target.hasActiveItem?(:RINGTARGET)
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if Effectiveness.ineffective_type?(moveType, defType)
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
# Foresight
if user.hasActiveAbility?(:SCRAPPY) || target.effects[PBEffects::Foresight]
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if defType == :GHOST &&
Effectiveness.ineffective_type?(moveType, defType)
if (user.hasActiveAbility?(:SCRAPPY) || target.effects[PBEffects::Foresight]) &&
defType == :GHOST
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
# Miracle Eye
if target.effects[PBEffects::MiracleEye]
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if defType == :DARK &&
Effectiveness.ineffective_type?(moveType, defType)
if target.effects[PBEffects::MiracleEye] && defType == :DARK
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
elsif Effectiveness.super_effective_type?(moveType, defType)
# Delta Stream's weather
if target.effectiveWeather == :StrongWinds
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if defType == :FLYING &&
Effectiveness.super_effective_type?(moveType, defType)
if target.effectiveWeather == :StrongWinds && defType == :FLYING
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
end
# Grounded Flying-type Pokémon become susceptible to Ground moves
if !target.airborne?
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if defType == :FLYING && moveType == :GROUND
if !target.airborne? && defType == :FLYING && moveType == :GROUND
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
return ret
end
@@ -493,9 +494,9 @@ class Battle::Move
def pbAdditionalEffectChance(user, target, effectChance = 0)
return 0 if target.hasActiveAbility?(:SHIELDDUST) && !@battle.moldBreaker
ret = (effectChance > 0) ? effectChance : @addlEffect
if Settings::MECHANICS_GENERATION >= 6 || @function != "EffectDependsOnEnvironment"
ret *= 2 if user.hasActiveAbility?(:SERENEGRACE) ||
user.pbOwnSide.effects[PBEffects::Rainbow] > 0
if (Settings::MECHANICS_GENERATION >= 6 || @function != "EffectDependsOnEnvironment") &&
(user.hasActiveAbility?(:SERENEGRACE) || user.pbOwnSide.effects[PBEffects::Rainbow] > 0)
ret *= 2
end
ret = 100 if $DEBUG && Input.press?(Input::CTRL)
return ret
@@ -507,9 +508,8 @@ class Battle::Move
return 0 if flinchingMove?
return 0 if target.hasActiveAbility?(:SHIELDDUST) && !@battle.moldBreaker
ret = 0
if user.hasActiveAbility?(:STENCH, true)
ret = 10
elsif user.hasActiveItem?([:KINGSROCK, :RAZORFANG], true)
if user.hasActiveAbility?(:STENCH, true) ||
user.hasActiveItem?([:KINGSROCK, :RAZORFANG], true)
ret = 10
end
ret *= 2 if user.hasActiveAbility?(:SERENEGRACE) ||

View File

@@ -1427,9 +1427,7 @@ class Battle::Move::RaiseUserAndAlliesAtkDef1 < Battle::Move
def pbEffectAgainstTarget(user, target)
showAnim = true
if target.pbCanRaiseStatStage?(:ATTACK, user, self)
if target.pbRaiseStatStage(:ATTACK, 1, user, showAnim)
showAnim = false
end
showAnim = false if target.pbRaiseStatStage(:ATTACK, 1, user, showAnim)
end
if target.pbCanRaiseStatStage?(:DEFENSE, user, self)
target.pbRaiseStatStage(:DEFENSE, 1, user, showAnim)
@@ -1477,9 +1475,7 @@ class Battle::Move::RaisePlusMinusUserAndAlliesAtkSpAtk1 < Battle::Move
def pbEffectAgainstTarget(user, target)
showAnim = true
if target.pbCanRaiseStatStage?(:ATTACK, user, self)
if target.pbRaiseStatStage(:ATTACK, 1, user, showAnim)
showAnim = false
end
showAnim = false if target.pbRaiseStatStage(:ATTACK, 1, user, showAnim)
end
if target.pbCanRaiseStatStage?(:SPECIAL_ATTACK, user, self)
target.pbRaiseStatStage(:SPECIAL_ATTACK, 1, user, showAnim)
@@ -1532,9 +1528,7 @@ class Battle::Move::RaisePlusMinusUserAndAlliesDefSpDef1 < Battle::Move
def pbEffectAgainstTarget(user, target)
showAnim = true
if target.pbCanRaiseStatStage?(:DEFENSE, user, self)
if target.pbRaiseStatStage(:DEFENSE, 1, user, showAnim)
showAnim = false
end
showAnim = false if target.pbRaiseStatStage(:DEFENSE, 1, user, showAnim)
end
if target.pbCanRaiseStatStage?(:SPECIAL_DEFENSE, user, self)
target.pbRaiseStatStage(:SPECIAL_DEFENSE, 1, user, showAnim)
@@ -1579,9 +1573,7 @@ class Battle::Move::RaiseGroundedGrassBattlersAtkSpAtk1 < Battle::Move
def pbEffectAgainstTarget(user, target)
showAnim = true
if target.pbCanRaiseStatStage?(:ATTACK, user, self)
if target.pbRaiseStatStage(:ATTACK, 1, user, showAnim)
showAnim = false
end
showAnim = false if target.pbRaiseStatStage(:ATTACK, 1, user, showAnim)
end
if target.pbCanRaiseStatStage?(:SPECIAL_ATTACK, user, self)
target.pbRaiseStatStage(:SPECIAL_ATTACK, 1, user, showAnim)
@@ -1729,9 +1721,7 @@ class Battle::Move::UserStealTargetPositiveStatStages < Battle::Move
GameData::Stat.each_battle do |s|
next if target.stages[s.id] <= 0
if user.pbCanRaiseStatStage?(s.id, user, self)
if user.pbRaiseStatStage(s.id, target.stages[s.id], user, showAnim)
showAnim = false
end
showAnim = false if user.pbRaiseStatStage(s.id, target.stages[s.id], user, showAnim)
end
target.statsLoweredThisRound = true
target.statsDropped = true

View File

@@ -209,8 +209,8 @@ class Battle::Move::ParalyzeFlinchTarget < Battle::Move
return if target.damageState.substitute
chance = pbAdditionalEffectChance(user, target, 10)
return if chance == 0
if @battle.pbRandom(100) < chance
target.pbParalyze(user) if target.pbCanParalyze?(user, false, self)
if target.pbCanParalyze?(user, false, self) && @battle.pbRandom(100) < chance
target.pbParalyze(user)
end
target.pbFlinch(user) if @battle.pbRandom(100) < chance
end
@@ -258,8 +258,8 @@ class Battle::Move::BurnFlinchTarget < Battle::Move
return if target.damageState.substitute
chance = pbAdditionalEffectChance(user, target, 10)
return if chance == 0
if @battle.pbRandom(100) < chance
target.pbBurn(user) if target.pbCanBurn?(user, false, self)
if target.pbCanBurn?(user, false, self) && @battle.pbRandom(100) < chance
target.pbBurn(user)
end
target.pbFlinch(user) if @battle.pbRandom(100) < chance
end
@@ -317,8 +317,8 @@ class Battle::Move::FreezeFlinchTarget < Battle::Move
return if target.damageState.substitute
chance = pbAdditionalEffectChance(user, target, 10)
return if chance == 0
if @battle.pbRandom(100) < chance
target.pbFreeze if target.pbCanFreeze?(user, false, self)
if target.pbCanFreeze?(user, false, self) && @battle.pbRandom(100) < chance
target.pbFreeze
end
target.pbFlinch(user) if @battle.pbRandom(100) < chance
end
@@ -429,7 +429,7 @@ class Battle::Move::CureUserPartyStatus < Battle::Move
def pbMoveFailed?(user, targets)
has_effect = @battle.allSameSideBattlers(user).any? { |b| b.status != :NONE }
if !has_effect
has_effect = @battle.pbParty(user.index).any? { |pkmn| pkmn && pkmn.able? && pkmn.status != :NONE }
has_effect = @battle.pbParty(user.index).any? { |pkmn| pkmn&.able? && pkmn.status != :NONE }
end
if !has_effect
@battle.pbDisplay(_INTL("But it failed!"))

View File

@@ -221,14 +221,13 @@ end
class Battle::Move::TwoTurnAttackOneTurnInSun < Battle::Move::TwoTurnMove
def pbIsChargingTurn?(user)
ret = super
if !user.effects[PBEffects::TwoTurnAttack]
if [:Sun, :HarshSun].include?(user.effectiveWeather)
if !user.effects[PBEffects::TwoTurnAttack] &&
[:Sun, :HarshSun].include?(user.effectiveWeather)
@powerHerb = false
@chargingTurn = true
@damagingTurn = true
return false
end
end
return ret
end

View File

@@ -175,9 +175,7 @@ class Battle::Move::CurseTargetOrLowerUserSpd1RaiseUserAtkDef1 < Battle::Move
end
showAnim = true
if user.pbCanRaiseStatStage?(:ATTACK, user, self)
if user.pbRaiseStatStage(:ATTACK, 1, user, showAnim)
showAnim = false
end
showAnim = false if user.pbRaiseStatStage(:ATTACK, 1, user, showAnim)
end
if user.pbCanRaiseStatStage?(:DEFENSE, user, self)
user.pbRaiseStatStage(:DEFENSE, 1, user, showAnim)
@@ -562,9 +560,7 @@ class Battle::Move::PowerDependsOnUserStockpile < Battle::Move
showAnim = true
if user.effects[PBEffects::StockpileDef] > 0 &&
user.pbCanLowerStatStage?(:DEFENSE, user, self)
if user.pbLowerStatStage(:DEFENSE, user.effects[PBEffects::StockpileDef], user, showAnim)
showAnim = false
end
showAnim = false if user.pbLowerStatStage(:DEFENSE, user.effects[PBEffects::StockpileDef], user, showAnim)
end
if user.effects[PBEffects::StockpileSpDef] > 0 &&
user.pbCanLowerStatStage?(:SPECIAL_DEFENSE, user, self)
@@ -611,11 +607,9 @@ class Battle::Move::HealUserDependingOnUserStockpile < Battle::Move
@battle.pbDisplay(_INTL("{1}'s stockpiled effect wore off!", user.pbThis))
showAnim = true
if user.effects[PBEffects::StockpileDef] > 0 &&
user.pbCanLowerStatStage?(:DEFENSE, user, self)
if user.pbLowerStatStage(:DEFENSE, user.effects[PBEffects::StockpileDef], user, showAnim)
user.pbCanLowerStatStage?(:DEFENSE, user, self) && user.pbLowerStatStage(:DEFENSE, user.effects[PBEffects::StockpileDef], user, showAnim)
showAnim = false
end
end
if user.effects[PBEffects::StockpileSpDef] > 0 &&
user.pbCanLowerStatStage?(:SPECIAL_DEFENSE, user, self)
user.pbLowerStatStage(:SPECIAL_DEFENSE, user.effects[PBEffects::StockpileSpDef], user, showAnim)

View File

@@ -112,24 +112,24 @@ class Battle::Scene
end
def pbFrameUpdate(cw = nil)
cw.update if cw
cw&.update
@battle.battlers.each_with_index do |b, i|
next if !b
@sprites["dataBox_#{i}"].update(@frameCounter) if @sprites["dataBox_#{i}"]
@sprites["pokemon_#{i}"].update(@frameCounter) if @sprites["pokemon_#{i}"]
@sprites["shadow_#{i}"].update(@frameCounter) if @sprites["shadow_#{i}"]
@sprites["dataBox_#{i}"]&.update(@frameCounter)
@sprites["pokemon_#{i}"]&.update(@frameCounter)
@sprites["shadow_#{i}"]&.update(@frameCounter)
end
end
def pbRefresh
@battle.battlers.each_with_index do |b, i|
next if !b
@sprites["dataBox_#{i}"].refresh if @sprites["dataBox_#{i}"]
@sprites["dataBox_#{i}"]&.refresh
end
end
def pbRefreshOne(idxBattler)
@sprites["dataBox_#{idxBattler}"].refresh if @sprites["dataBox_#{idxBattler}"]
@sprites["dataBox_#{idxBattler}"]&.refresh
end
def pbRefreshEverything

View File

@@ -70,7 +70,7 @@ class Battle::Scene
cw = @sprites["fightWindow"]
cw.battler = battler
moveIndex = 0
if battler.moves[@lastMove[idxBattler]] && battler.moves[@lastMove[idxBattler]].id
if battler.moves[@lastMove[idxBattler]]&.id
moveIndex = @lastMove[idxBattler]
end
cw.shiftMode = (@battle.pbCanShift?(idxBattler)) ? 1 : 0
@@ -98,14 +98,14 @@ class Battle::Scene
if Input.trigger?(Input::LEFT)
cw.index -= 1 if (cw.index & 1) == 1
elsif Input.trigger?(Input::RIGHT)
if battler.moves[cw.index + 1] && battler.moves[cw.index + 1].id
cw.index += 1 if (cw.index & 1) == 0
if battler.moves[cw.index + 1]&.id && (cw.index & 1) == 0
cw.index += 1
end
elsif Input.trigger?(Input::UP)
cw.index -= 2 if (cw.index & 2) == 2
elsif Input.trigger?(Input::DOWN)
if battler.moves[cw.index + 2] && battler.moves[cw.index + 2].id
cw.index += 2 if (cw.index & 2) == 0
if battler.moves[cw.index + 2]&.id && (cw.index & 2) == 0
cw.index += 2
end
end
pbPlayCursorSE if cw.index != oldIndex

View File

@@ -137,8 +137,8 @@ class Battle::Scene
a[2] = true if a[1].animDone?
end
pbUpdate
if !inPartyAnimation?
break if !sendOutAnims.any? { |a| !a[2] }
if !inPartyAnimation? && !sendOutAnims.any? { |a| !a[2] }
break
end
end
fadeAnim.dispose
@@ -165,7 +165,7 @@ class Battle::Scene
# Recall animation
recallAnim = Animation::BattlerRecall.new(@sprites, @viewport, idxBattler)
loop do
recallAnim.update if recallAnim
recallAnim&.update
pbUpdate
break if recallAnim.animDone?
end
@@ -495,7 +495,7 @@ class Battle::Scene
animID = pbFindMoveAnimation(moveID, user.index, hitNum)
return if !animID
anim = animID[0]
target = (targets && targets.is_a?(Array)) ? targets[0] : targets
target = (targets.is_a?(Array)) ? targets[0] : targets
animations = pbLoadBattleAnimations
return if !animations
pbSaveShadows {
@@ -510,7 +510,7 @@ class Battle::Scene
# Plays a common animation.
def pbCommonAnimation(animName, user = nil, target = nil)
return if nil_or_empty?(animName)
target = target[0] if target && target.is_a?(Array)
target = target[0] if target.is_a?(Array)
animations = pbLoadBattleAnimations
return if !animations
animations.each do |a|
@@ -534,7 +534,7 @@ class Battle::Scene
animPlayer = PBAnimationPlayerX.new(animation, user, target, self, oppMove)
# Apply a transformation to the animation based on where the user and target
# actually are. Get the centres of each sprite.
userHeight = (userSprite && userSprite.bitmap && !userSprite.bitmap.disposed?) ? userSprite.bitmap.height : 128
userHeight = (userSprite&.bitmap && !userSprite.bitmap.disposed?) ? userSprite.bitmap.height : 128
if targetSprite
targetHeight = (targetSprite.bitmap && !targetSprite.bitmap.disposed?) ? targetSprite.bitmap.height : 128
else

View File

@@ -161,7 +161,7 @@ class Battle::Scene::CommandMenu < Battle::Scene::MenuBase
def dispose
super
@buttonBitmap.dispose if @buttonBitmap
@buttonBitmap&.dispose
end
def z=(value)
@@ -191,7 +191,7 @@ class Battle::Scene::CommandMenu < Battle::Scene::MenuBase
def refresh
@msgBox.refresh
@cmdWindow.refresh if @cmdWindow
@cmdWindow&.refresh
refreshButtons
end
end
@@ -310,10 +310,10 @@ class Battle::Scene::FightMenu < Battle::Scene::MenuBase
def dispose
super
@buttonBitmap.dispose if @buttonBitmap
@typeBitmap.dispose if @typeBitmap
@megaEvoBitmap.dispose if @megaEvoBitmap
@shiftBitmap.dispose if @shiftBitmap
@buttonBitmap&.dispose
@typeBitmap&.dispose
@megaEvoBitmap&.dispose
@shiftBitmap&.dispose
end
def z=(value)
@@ -510,7 +510,7 @@ class Battle::Scene::TargetMenu < Battle::Scene::MenuBase
def dispose
super
@buttonBitmap.dispose if @buttonBitmap
@buttonBitmap&.dispose
end
def z=(value)

View File

@@ -52,7 +52,7 @@ class Battle::Scene::PokemonDataBox < SpriteWrapper
bgFilename = ["Graphics/Pictures/Battle/databox_thin",
"Graphics/Pictures/Battle/databox_thin_foe"][@battler.index % 2]
end
@databoxBitmap.dispose if @databoxBitmap
@databoxBitmap&.dispose
@databoxBitmap = AnimatedBitmap.new(bgFilename)
# Determine the co-ordinates of the data box and the left edge padding width
if onPlayerSide
@@ -500,7 +500,7 @@ class Battle::Scene::BattlerSprite < RPG::Sprite
end
def dispose
@_iconBitmap.dispose if @_iconBitmap
@_iconBitmap&.dispose
@_iconBitmap = nil
self.bitmap = nil if !self.disposed?
super
@@ -552,7 +552,7 @@ class Battle::Scene::BattlerSprite < RPG::Sprite
def setPokemonBitmap(pkmn, back = false)
@pkmn = pkmn
@_iconBitmap.dispose if @_iconBitmap
@_iconBitmap&.dispose
@_iconBitmap = GameData::Species.sprite_bitmap_from_pokemon(@pkmn, back)
self.bitmap = (@_iconBitmap) ? @_iconBitmap.bitmap : nil
pbSetPosition
@@ -563,7 +563,7 @@ class Battle::Scene::BattlerSprite < RPG::Sprite
# recommendation is to create a PictureEx animation and push it into
# the @battleAnimations array.
def pbPlayIntroAnimation(pictureEx = nil)
@pkmn.play_cry if @pkmn
@pkmn&.play_cry
end
QUARTER_ANIM_PERIOD = Graphics.frame_rate * 3 / 20
@@ -617,7 +617,7 @@ class Battle::Scene::BattlerShadowSprite < RPG::Sprite
end
def dispose
@_iconBitmap.dispose if @_iconBitmap
@_iconBitmap&.dispose
@_iconBitmap = nil
self.bitmap = nil if !self.disposed?
super
@@ -647,7 +647,7 @@ class Battle::Scene::BattlerShadowSprite < RPG::Sprite
def setPokemonBitmap(pkmn)
@pkmn = pkmn
@_iconBitmap.dispose if @_iconBitmap
@_iconBitmap&.dispose
@_iconBitmap = GameData::Species.shadow_bitmap_from_pokemon(@pkmn)
self.bitmap = (@_iconBitmap) ? @_iconBitmap.bitmap : nil
pbSetPosition

View File

@@ -10,7 +10,7 @@ class Battle::Scene::Animation
end
def dispose
@tempSprites.each { |s| s.dispose if s }
@tempSprites.each { |s| s&.dispose }
end
def createProcesses; end
@@ -47,7 +47,7 @@ class Battle::Scene::Animation
def update
return if @animDone
@tempSprites.each { |s| s.update if s }
@tempSprites.each { |s| s&.update }
finished = true
@pictureEx.each_with_index do |p, i|
next if !p.running?

View File

@@ -140,9 +140,9 @@ class Battle::Scene::Animation::LineupAppear < Battle::Scene::Animation
startsIndex = idxBall / ballsPerTrainer
teamIndex = idxBall % ballsPerTrainer
ret = @partyStarts[startsIndex] + teamIndex
if startsIndex < @partyStarts.length - 1
if startsIndex < @partyStarts.length - 1 && ret >= @partyStarts[startsIndex + 1]
# There is a later trainer, don't spill over into its team
return -1 if ret >= @partyStarts[startsIndex + 1]
return -1
end
return ret
end
@@ -332,7 +332,7 @@ class Battle::Scene::Animation::PlayerFade < Battle::Scene::Animation
end
# Move and fade party bar/balls
delay = 3
if @sprites["partyBar_0"] && @sprites["partyBar_0"].visible
if @sprites["partyBar_0"]&.visible
partyBar = addSprite(@sprites["partyBar_0"])
partyBar.moveDelta(delay, 16, -Graphics.width / 4, 0) if @fullAnim
partyBar.moveOpacity(delay, 12, 0)
@@ -377,7 +377,7 @@ class Battle::Scene::Animation::TrainerFade < Battle::Scene::Animation
end
# Move and fade party bar/balls
delay = 3
if @sprites["partyBar_1"] && @sprites["partyBar_1"].visible
if @sprites["partyBar_1"]&.visible
partyBar = addSprite(@sprites["partyBar_1"])
partyBar.moveDelta(delay, 16, Graphics.width / 4, 0) if @fullAnim
partyBar.moveOpacity(delay, 12, 0)
@@ -722,13 +722,11 @@ class Battle::Scene::Animation::PokeballThrowCapture < Battle::Scene::Animation
ball.setZ(0, batSprite.z + 1)
@ballSpriteIndex = (@success) ? @tempSprites.length - 1 : -1
# Set up trainer sprite (only visible in Safari Zone battles)
if @showingTrainer && traSprite
if traSprite.bitmap.width >= traSprite.bitmap.height * 2
if @showingTrainer && traSprite && traSprite.bitmap.width >= traSprite.bitmap.height * 2
trainer = addSprite(traSprite, PictureOrigin::Bottom)
# Trainer animation
ballStartX, ballStartY = trainerThrowingFrames(ball, trainer, traSprite)
end
end
delay = ball.totalDuration # 0 or 7
# Poké Ball arc animation
ball.setSE(delay, "Battle throw")

View File

@@ -115,13 +115,11 @@ class Battle::AI
end
end
# Log Full Restores (HP healer and status curer)
if losthp > 0 || battler.status != :NONE
if fullRestoreItems.include?(i)
if fullRestoreItems.include?(i) && (losthp > 0 || battler.status != :NONE)
usableHPItems.push([i, (preferFullRestore) ? 3 : 7, 999])
usableStatusItems.push([i, (preferFullRestore) ? 3 : 9])
next
end
end
# Log single status-curing items
if oneStatusItems.include?(i)
usableStatusItems.push([i, 5])

View File

@@ -48,8 +48,8 @@ class Battle::AI
skill >= PBTrainerAI.highSkill
toxicHP = battler.totalhp / 16
nextToxicHP = toxicHP * (battler.effects[PBEffects::Toxic] + 1)
if battler.hp <= nextToxicHP && battler.hp > toxicHP * 2
shouldSwitch = true if pbAIRandom(100) < 80
if battler.hp <= nextToxicHP && battler.hp > toxicHP * 2 && pbAIRandom(100) < 80
shouldSwitch = true
end
end
# Pokémon is Encored into an unfavourable move
@@ -62,8 +62,8 @@ class Battle::AI
scoreSum += pbGetMoveScore(battler.moves[idxEncoredMove], battler, b, skill)
scoreCount += 1
end
if scoreCount > 0 && scoreSum / scoreCount <= 20
shouldSwitch = true if pbAIRandom(100) < 80
if scoreCount > 0 && scoreSum / scoreCount <= 20 && pbAIRandom(100) < 80
shouldSwitch = true
end
end
end
@@ -72,9 +72,9 @@ class Battle::AI
if @battle.pbSideSize(battler.index + 1) == 1 &&
!battler.pbDirectOpposing.fainted? && skill >= PBTrainerAI.highSkill
opp = battler.pbDirectOpposing
if opp.effects[PBEffects::HyperBeam] > 0 ||
(opp.hasActiveAbility?(:TRUANT) && opp.effects[PBEffects::Truant])
shouldSwitch = false if pbAIRandom(100) < 80
if (opp.effects[PBEffects::HyperBeam] > 0 ||
(opp.hasActiveAbility?(:TRUANT) && opp.effects[PBEffects::Truant])) && pbAIRandom(100) < 80
shouldSwitch = false
end
end
# Sudden Death rule - I'm not sure what this means
@@ -103,9 +103,8 @@ class Battle::AI
# Don't switch to this if too little HP
if spikes > 0
spikesDmg = [8, 6, 4][spikes - 1]
if pkmn.hp <= pkmn.totalhp / spikesDmg
next if !pkmn.hasType?(:FLYING) && !pkmn.hasActiveAbility?(:LEVITATE)
end
next if pkmn.hp <= pkmn.totalhp / spikesDmg &&
!pkmn.hasType?(:FLYING) && !pkmn.hasActiveAbility?(:LEVITATE)
end
end
# moveType is the type of the target's last used move
@@ -136,7 +135,7 @@ class Battle::AI
end
if @battle.pbRegisterSwitch(idxBattler, list[0])
PBDebug.log("[AI] #{battler.pbThis} (#{idxBattler}) will switch with " +
"#{@battle.pbParty(idxBattler)[list[0]].name}")
@battle.pbParty(idxBattler)[list[0]].name)
return true
end
end

View File

@@ -61,9 +61,9 @@ class Battle::AI
# Decide whether all choices are bad, and if so, try switching instead
if !wildBattler && skill >= PBTrainerAI.highSkill
badMoves = false
if (maxScore <= 20 && user.turnCount > 2) ||
(maxScore <= 40 && user.turnCount > 5)
badMoves = true if pbAIRandom(100) < 80
if ((maxScore <= 20 && user.turnCount > 2) ||
(maxScore <= 40 && user.turnCount > 5)) && pbAIRandom(100) < 80
badMoves = true
end
if !badMoves && totalScore < 100 && user.turnCount > 1
badMoves = true
@@ -160,15 +160,14 @@ class Battle::AI
return 0 if score <= 0
if skill >= PBTrainerAI.mediumSkill
# Prefer damaging moves if AI has no more Pokémon or AI is less clever
if @battle.pbAbleNonActiveCount(user.idxOwnSide) == 0
if !(skill >= PBTrainerAI.highSkill && @battle.pbAbleNonActiveCount(target.idxOwnSide) > 0)
if @battle.pbAbleNonActiveCount(user.idxOwnSide) == 0 &&
!(skill >= PBTrainerAI.highSkill && @battle.pbAbleNonActiveCount(target.idxOwnSide) > 0)
if move.statusMove?
score /= 1.5
elsif target.hp <= target.totalhp / 2
score *= 1.5
end
end
end
# Don't prefer attacking the target if they'd be semi-invulnerable
if skill >= PBTrainerAI.highSkill && move.accuracy > 0 &&
(target.semiInvulnerable? || target.effects[PBEffects::SkyDrop] >= 0)
@@ -266,19 +265,17 @@ class Battle::AI
end
# Prefer flinching external effects (note that move effects which cause
# flinching are dealt with in the function code part of score calculation)
if skill >= PBTrainerAI.mediumSkill && !move.flinchingMove?
if !target.hasActiveAbility?(:INNERFOCUS) &&
if skill >= PBTrainerAI.mediumSkill && !move.flinchingMove? &&
!target.hasActiveAbility?(:INNERFOCUS) &&
!target.hasActiveAbility?(:SHIELDDUST) &&
target.effects[PBEffects::Substitute] == 0
canFlinch = false
if user.hasActiveItem?([:KINGSROCK, :RAZORFANG])
canFlinch = true
elsif user.hasActiveAbility?(:STENCH)
if user.hasActiveItem?([:KINGSROCK, :RAZORFANG]) ||
user.hasActiveAbility?(:STENCH)
canFlinch = true
end
realDamage *= 1.3 if canFlinch
end
end
# Convert damage to percentage of target's remaining HP
damagePercentage = realDamage * 100.0 / target.hp
# Don't prefer weak attacks

View File

@@ -859,9 +859,7 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetAttack1"
if move.statusMove?
if !target.pbCanLowerStatStage?(:ATTACK, user)
score -= 90
else
if target.pbCanLowerStatStage?(:ATTACK, user)
score += target.stages[:ATTACK] * 20
if skill >= PBTrainerAI.mediumSkill
hasPhysicalAttack = false
@@ -876,6 +874,8 @@ class Battle::AI
score -= 90
end
end
else
score -= 90
end
else
score += 20 if target.stages[:ATTACK] > 0
@@ -892,10 +892,10 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetDefense1"
if move.statusMove?
if !target.pbCanLowerStatStage?(:DEFENSE, user)
score -= 90
else
if target.pbCanLowerStatStage?(:DEFENSE, user)
score += target.stages[:DEFENSE] * 20
else
score -= 90
end
elsif target.stages[:DEFENSE] > 0
score += 20
@@ -903,15 +903,15 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetSpeed1", "LowerTargetSpeed1WeakerInGrassyTerrain"
if move.statusMove?
if !target.pbCanLowerStatStage?(:SPEED, user)
score -= 90
else
if target.pbCanLowerStatStage?(:SPEED, user)
score += target.stages[:SPEED] * 10
if skill >= PBTrainerAI.highSkill
aspeed = pbRoughStat(user, :SPEED, skill)
ospeed = pbRoughStat(target, :SPEED, skill)
score += 30 if aspeed < ospeed && aspeed * 2 > ospeed
end
else
score -= 90
end
elsif user.stages[:SPEED] > 0
score += 20
@@ -919,9 +919,7 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetSpAtk1"
if move.statusMove?
if !target.pbCanLowerStatStage?(:SPECIAL_ATTACK, user)
score -= 90
else
if target.pbCanLowerStatStage?(:SPECIAL_ATTACK, user)
score += user.stages[:SPECIAL_ATTACK] * 20
if skill >= PBTrainerAI.mediumSkill
hasSpecicalAttack = false
@@ -936,6 +934,8 @@ class Battle::AI
score -= 90
end
end
else
score -= 90
end
else
score += 20 if user.stages[:SPECIAL_ATTACK] > 0
@@ -952,10 +952,10 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetSpDef1"
if move.statusMove?
if !target.pbCanLowerStatStage?(:SPECIAL_DEFENSE, user)
score -= 90
else
if target.pbCanLowerStatStage?(:SPECIAL_DEFENSE, user)
score += target.stages[:SPECIAL_DEFENSE] * 20
else
score -= 90
end
elsif target.stages[:SPECIAL_DEFENSE] > 0
score += 20
@@ -963,10 +963,10 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetAccuracy1", "LowerTargetAccuracy2", "LowerTargetAccuracy3"
if move.statusMove?
if !target.pbCanLowerStatStage?(:ACCURACY, user)
score -= 90
else
if target.pbCanLowerStatStage?(:ACCURACY, user)
score += target.stages[:ACCURACY] * 10
else
score -= 90
end
elsif target.stages[:ACCURACY] > 0
score += 20
@@ -974,10 +974,10 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetEvasion1", "LowerTargetEvasion2", "LowerTargetEvasion3"
if move.statusMove?
if !target.pbCanLowerStatStage?(:EVASION, user)
score -= 90
else
if target.pbCanLowerStatStage?(:EVASION, user)
score += target.stages[:EVASION] * 10
else
score -= 90
end
elsif target.stages[:EVASION] > 0
score += 20
@@ -985,10 +985,10 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetEvasion1RemoveSideEffects"
if move.statusMove?
if !target.pbCanLowerStatStage?(:EVASION, user)
score -= 90
else
if target.pbCanLowerStatStage?(:EVASION, user)
score += target.stages[:EVASION] * 10
else
score -= 90
end
elsif target.stages[:EVASION] > 0
score += 20
@@ -1009,9 +1009,7 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetAttack2", "LowerTargetAttack3"
if move.statusMove?
if !target.pbCanLowerStatStage?(:ATTACK, user)
score -= 90
else
if target.pbCanLowerStatStage?(:ATTACK, user)
score += 40 if user.turnCount == 0
score += target.stages[:ATTACK] * 20
if skill >= PBTrainerAI.mediumSkill
@@ -1027,6 +1025,8 @@ class Battle::AI
score -= 90
end
end
else
score -= 90
end
else
score += 10 if user.turnCount == 0
@@ -1044,11 +1044,11 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetDefense2", "LowerTargetDefense3"
if move.statusMove?
if !target.pbCanLowerStatStage?(:DEFENSE, user)
score -= 90
else
if target.pbCanLowerStatStage?(:DEFENSE, user)
score += 40 if user.turnCount == 0
score += target.stages[:DEFENSE] * 20
else
score -= 90
end
else
score += 10 if user.turnCount == 0
@@ -1057,9 +1057,7 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetSpeed2", "LowerTargetSpeed3"
if move.statusMove?
if !target.pbCanLowerStatStage?(:SPEED, user)
score -= 90
else
if target.pbCanLowerStatStage?(:SPEED, user)
score += 20 if user.turnCount == 0
score += target.stages[:SPEED] * 20
if skill >= PBTrainerAI.highSkill
@@ -1067,6 +1065,8 @@ class Battle::AI
ospeed = pbRoughStat(target, :SPEED, skill)
score += 30 if aspeed < ospeed && aspeed * 2 > ospeed
end
else
score -= 90
end
else
score += 10 if user.turnCount == 0
@@ -1078,9 +1078,7 @@ class Battle::AI
target.hasActiveAbility?(:OBLIVIOUS)
score -= 90
elsif move.statusMove?
if !target.pbCanLowerStatStage?(:SPECIAL_ATTACK, user)
score -= 90
else
if target.pbCanLowerStatStage?(:SPECIAL_ATTACK, user)
score += 40 if user.turnCount == 0
score += target.stages[:SPECIAL_ATTACK] * 20
if skill >= PBTrainerAI.mediumSkill
@@ -1096,6 +1094,8 @@ class Battle::AI
score -= 90
end
end
else
score -= 90
end
else
score += 10 if user.turnCount == 0
@@ -1113,11 +1113,11 @@ class Battle::AI
#---------------------------------------------------------------------------
when "LowerTargetSpDef2", "LowerTargetSpDef3"
if move.statusMove?
if !target.pbCanLowerStatStage?(:SPECIAL_DEFENSE, user)
score -= 90
else
if target.pbCanLowerStatStage?(:SPECIAL_DEFENSE, user)
score += 40 if user.turnCount == 0
score += target.stages[:SPECIAL_DEFENSE] * 20
else
score -= 90
end
else
score += 10 if user.turnCount == 0
@@ -1323,9 +1323,7 @@ class Battle::AI
end
#---------------------------------------------------------------------------
when "SetUserTypesToUserMoveType"
if !user.canChangeType?
score -= 90
else
if user.canChangeType?
has_possible_type = false
user.eachMoveWithIndex do |m, i|
break if Settings::MECHANICS_GENERATION >= 6 && i > 0
@@ -1335,6 +1333,8 @@ class Battle::AI
break
end
score -= 90 if !has_possible_type
else
score -= 90
end
#---------------------------------------------------------------------------
when "SetUserTypesToResistLastAttack"
@@ -1350,9 +1350,7 @@ class Battle::AI
aType = m.pbCalcType(user)
break
end
if !aType
score -= 90
else
if aType
has_possible_type = false
GameData::Type.each do |t|
next if t.pseudo_type || user.pbHasType?(t.id) ||
@@ -1361,6 +1359,8 @@ class Battle::AI
break
end
score -= 90 if !has_possible_type
else
score -= 90
end
end
#---------------------------------------------------------------------------
@@ -1793,9 +1793,7 @@ class Battle::AI
if target.effects[PBEffects::Encore] > 0
score -= 90
elsif aspeed > ospeed
if !target.lastRegularMoveUsed
score -= 90
else
if target.lastRegularMoveUsed
moveData = GameData::Move.get(target.lastRegularMoveUsed)
if moveData.category == 2 && # Status move
[:User, :BothSides].include?(moveData.target)
@@ -1805,6 +1803,8 @@ class Battle::AI
Effectiveness.ineffective?(pbCalcTypeMod(moveData.type, target, user))
score += 60
end
else
score -= 90
end
end
#---------------------------------------------------------------------------
@@ -2056,9 +2056,7 @@ class Battle::AI
end
#---------------------------------------------------------------------------
when "SwitchOutUserPassOnEffects"
if !@battle.pbCanChooseNonActive?(user.index)
score -= 100
else
if @battle.pbCanChooseNonActive?(user.index)
score -= 40 if user.effects[PBEffects::Confusion] > 0
total = 0
GameData::Stat.each_battle { |s| total += user.stages[s.id] }
@@ -2075,6 +2073,8 @@ class Battle::AI
end
score += 75 if !hasDamagingMove
end
else
score -= 100
end
#---------------------------------------------------------------------------
when "TrapTargetInBattle"
@@ -2505,9 +2505,7 @@ class Battle::AI
end
#---------------------------------------------------------------------------
when "LowerTargetAttack1BypassSubstitute"
if !target.pbCanLowerStatStage?(:ATTACK, user)
score -= 90
else
if target.pbCanLowerStatStage?(:ATTACK, user)
score += target.stages[:ATTACK] * 20
if skill >= PBTrainerAI.mediumSkill
hasPhysicalAttack = false
@@ -2522,6 +2520,8 @@ class Battle::AI
score -= 90
end
end
else
score -= 90
end
#---------------------------------------------------------------------------
when "LowerTargetAtkSpAtk1"
@@ -2537,11 +2537,11 @@ class Battle::AI
end
#---------------------------------------------------------------------------
when "LowerTargetSpAtk2", "LowerTargetSpAtk3"
if !target.pbCanLowerStatStage?(:SPECIAL_ATTACK, user)
score -= 90
else
if target.pbCanLowerStatStage?(:SPECIAL_ATTACK, user)
score += 40 if user.turnCount == 0
score += target.stages[:SPECIAL_ATTACK] * 20
else
score -= 90
end
#---------------------------------------------------------------------------
when "RaiseGroundedGrassBattlersAtkSpAtk1"
@@ -3005,7 +3005,7 @@ class Battle::AI
end
GameData::Stat.each_main_battle { |s| score += 10 if user.stages[s.id] <= 0 }
if skill >= PBTrainerAI.mediumSkill
hasDamagingAttack = user.moves.any? { |m| next m && m.damagingMove? }
hasDamagingAttack = user.moves.any? { |m| next m&.damagingMove? }
score += 20 if hasDamagingAttack
end
end
@@ -3031,7 +3031,7 @@ class Battle::AI
end
GameData::Stat.each_main_battle { |s| score += 10 if user.stages[s.id] <= 0 }
if skill >= PBTrainerAI.mediumSkill
hasDamagingAttack = user.moves.any? { |m| next m && m.damagingMove? }
hasDamagingAttack = user.moves.any? { |m| next m&.damagingMove? }
score += 20 if hasDamagingAttack
end
end
@@ -3064,11 +3064,11 @@ class Battle::AI
end
#---------------------------------------------------------------------------
when "LowerTargetDefense1DoublePowerInGravity"
if !target.pbCanLowerStatStage?(:DEFENSE, user)
score -= 90
else
if target.pbCanLowerStatStage?(:DEFENSE, user)
score += 20
score += target.stages[:DEFENSE] * 20
else
score -= 90
end
score += 30 if @battle.field.effects[PBEffects::Gravity] > 0
#---------------------------------------------------------------------------

View File

@@ -28,28 +28,29 @@ class Battle::AI
#=============================================================================
def pbCalcTypeModSingle(moveType, defType, user, target)
ret = Effectiveness.calculate_one(moveType, defType)
if Effectiveness.ineffective_type?(moveType, defType)
# Ring Target
if target.hasActiveItem?(:RINGTARGET)
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if Effectiveness.ineffective_type?(moveType, defType)
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
# Foresight
if user.hasActiveAbility?(:SCRAPPY) || target.effects[PBEffects::Foresight]
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if defType == :GHOST &&
Effectiveness.ineffective_type?(moveType, defType)
if (user.hasActiveAbility?(:SCRAPPY) || target.effects[PBEffects::Foresight]) &&
defType == :GHOST
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
# Miracle Eye
if target.effects[PBEffects::MiracleEye]
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if defType == :DARK &&
Effectiveness.ineffective_type?(moveType, defType)
if target.effects[PBEffects::MiracleEye] && defType == :DARK
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
elsif Effectiveness.super_effective_type?(moveType, defType)
# Delta Stream's weather
if target.effectiveWeather == :StrongWinds
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if defType == :FLYING &&
Effectiveness.super_effective_type?(moveType, defType)
if target.effectiveWeather == :StrongWinds && defType == :FLYING
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
end
# Grounded Flying-type Pokémon become susceptible to Ground moves
if !target.airborne?
ret = Effectiveness::NORMAL_EFFECTIVE_ONE if defType == :FLYING && moveType == :GROUND
if !target.airborne? && defType == :FLYING && moveType == :GROUND
ret = Effectiveness::NORMAL_EFFECTIVE_ONE
end
return ret
end
@@ -256,7 +257,7 @@ class Battle::AI
when "HitOncePerUserTeamMember" # Beat Up
mult = 0
@battle.eachInTeamFromBattlerIndex(user.index) do |pkmn, _i|
mult += 1 if pkmn && pkmn.able? && pkmn.status == :NONE
mult += 1 if pkmn&.able? && pkmn.status == :NONE
end
baseDmg *= mult
when "TwoTurnAttackOneTurnInSun" # Solar Beam
@@ -390,26 +391,20 @@ class Battle::AI
)
end
end
if skill >= PBTrainerAI.bestSkill && target.itemActive?
# NOTE: Type-weakening berries aren't suitable for checking at the start
# of the round.
if target.item && !target.item.is_berry?
if skill >= PBTrainerAI.bestSkill && target.itemActive? && (target.item && !target.item.is_berry?)
Battle::ItemEffects.triggerDamageCalcFromTarget(
target.item, user, target, move, multipliers, baseDmg, type
)
end
end
# Global abilities
if skill >= PBTrainerAI.mediumSkill
if (@battle.pbCheckGlobalAbility(:DARKAURA) && type == :DARK) ||
(@battle.pbCheckGlobalAbility(:FAIRYAURA) && type == :FAIRY)
if skill >= PBTrainerAI.mediumSkill && ((@battle.pbCheckGlobalAbility(:DARKAURA) && type == :DARK) ||
(@battle.pbCheckGlobalAbility(:FAIRYAURA) && type == :FAIRY))
if @battle.pbCheckGlobalAbility(:AURABREAK)
multipliers[:base_damage_multiplier] *= 2 / 3.0
else
multipliers[:base_damage_multiplier] *= 4 / 3.0
end
end
end
# Parental Bond
if skill >= PBTrainerAI.mediumSkill && user.hasActiveAbility?(:PARENTALBOND)
multipliers[:base_damage_multiplier] *= 1.25
@@ -418,11 +413,9 @@ class Battle::AI
# TODO
# Helping Hand - n/a
# Charge
if skill >= PBTrainerAI.mediumSkill
if user.effects[PBEffects::Charge] > 0 && type == :ELECTRIC
if skill >= PBTrainerAI.mediumSkill && (user.effects[PBEffects::Charge] > 0 && type == :ELECTRIC)
multipliers[:base_damage_multiplier] *= 2
end
end
# Mud Sport and Water Sport
if skill >= PBTrainerAI.mediumSkill
if type == :ELECTRIC
@@ -456,25 +449,17 @@ class Battle::AI
end
end
# Badge multipliers
if skill >= PBTrainerAI.highSkill
if @battle.internalBattle
# Don't need to check the Atk/Sp Atk-boosting badges because the AI
# won't control the player's Pokémon.
if target.pbOwnedByPlayer?
if skill >= PBTrainerAI.highSkill && @battle.internalBattle && target.pbOwnedByPlayer?
if move.physicalMove?(type) && @battle.pbPlayer.badge_count >= Settings::NUM_BADGES_BOOST_DEFENSE
multipliers[:defense_multiplier] *= 1.1
elsif move.specialMove?(type) && @battle.pbPlayer.badge_count >= Settings::NUM_BADGES_BOOST_SPDEF
multipliers[:defense_multiplier] *= 1.1
end
end
end
end
# Multi-targeting attacks
if skill >= PBTrainerAI.highSkill
if pbTargetsMultiple?(move, user)
if skill >= PBTrainerAI.highSkill && pbTargetsMultiple?(move, user)
multipliers[:final_damage_multiplier] *= 0.75
end
end
# Weather
if skill >= PBTrainerAI.mediumSkill
case user.effectiveWeather
@@ -502,31 +487,26 @@ class Battle::AI
# Critical hits - n/a
# Random variance - n/a
# STAB
if skill >= PBTrainerAI.mediumSkill
if type && user.pbHasType?(type)
if skill >= PBTrainerAI.mediumSkill && (type && user.pbHasType?(type))
if user.hasActiveAbility?(:ADAPTABILITY)
multipliers[:final_damage_multiplier] *= 2
else
multipliers[:final_damage_multiplier] *= 1.5
end
end
end
# Type effectiveness
if skill >= PBTrainerAI.mediumSkill
typemod = pbCalcTypeMod(type, user, target)
multipliers[:final_damage_multiplier] *= typemod.to_f / Effectiveness::NORMAL_EFFECTIVE
end
# Burn
if skill >= PBTrainerAI.highSkill
if user.status == :BURN && move.physicalMove?(type) &&
if skill >= PBTrainerAI.highSkill && (user.status == :BURN && move.physicalMove?(type) &&
!user.hasActiveAbility?(:GUTS) &&
!(Settings::MECHANICS_GENERATION >= 6 && move.function == "DoublePowerIfUserPoisonedBurnedParalyzed") # Facade
!(Settings::MECHANICS_GENERATION >= 6 && move.function == "DoublePowerIfUserPoisonedBurnedParalyzed")) # Facade
multipliers[:final_damage_multiplier] /= 2
end
end
# Aurora Veil, Reflect, Light Screen
if skill >= PBTrainerAI.highSkill
if !move.ignoresReflect? && !user.hasActiveAbility?(:INFILTRATOR)
if skill >= PBTrainerAI.highSkill && (!move.ignoresReflect? && !user.hasActiveAbility?(:INFILTRATOR))
if target.pbOwnSide.effects[PBEffects::AuroraVeil] > 0
if @battle.pbSideBattlerCount(target) > 1
multipliers[:final_damage_multiplier] *= 2 / 3.0
@@ -547,13 +527,10 @@ class Battle::AI
end
end
end
end
# Minimize
if skill >= PBTrainerAI.highSkill
if target.effects[PBEffects::Minimize] && move.tramplesMinimize?(2)
if skill >= PBTrainerAI.highSkill && (target.effects[PBEffects::Minimize] && move.tramplesMinimize?(2))
multipliers[:final_damage_multiplier] *= 2
end
end
# Move-specific base damage modifiers
# TODO
# Move-specific final damage modifiers
@@ -572,20 +549,16 @@ class Battle::AI
if c >= 0 && user.abilityActive?
c = Battle::AbilityEffects.triggerCriticalCalcFromUser(user.ability, user, target, c)
end
if skill >= PBTrainerAI.bestSkill
if c >= 0 && !moldBreaker && target.abilityActive?
if skill >= PBTrainerAI.bestSkill && (c >= 0 && !moldBreaker && target.abilityActive?)
c = Battle::AbilityEffects.triggerCriticalCalcFromTarget(target.ability, user, target, c)
end
end
# Item effects that alter critical hit rate
if c >= 0 && user.itemActive?
c = Battle::ItemEffects.triggerCriticalCalcFromUser(user.item, user, target, c)
end
if skill >= PBTrainerAI.bestSkill
if c >= 0 && target.itemActive?
if skill >= PBTrainerAI.bestSkill && (c >= 0 && target.itemActive?)
c = Battle::ItemEffects.triggerCriticalCalcFromTarget(target.item, user, target, c)
end
end
# Other efffects
c = -1 if target.pbOwnSide.effects[PBEffects::LuckyChant] > 0
if c >= 0
@@ -659,28 +632,22 @@ class Battle::AI
)
end
end
if skill >= PBTrainerAI.bestSkill
if target.abilityActive? && !moldBreaker
if skill >= PBTrainerAI.bestSkill && (target.abilityActive? && !moldBreaker)
Battle::AbilityEffects.triggerAccuracyCalcFromTarget(
target.ability, modifiers, user, target, move, type
)
end
end
# Item effects that alter accuracy calculation
if skill >= PBTrainerAI.mediumSkill
if user.itemActive?
if skill >= PBTrainerAI.mediumSkill && user.itemActive?
Battle::ItemEffects.triggerAccuracyCalcFromUser(
user.item, modifiers, user, target, move, type
)
end
end
if skill >= PBTrainerAI.bestSkill
if target.itemActive?
if skill >= PBTrainerAI.bestSkill && target.itemActive?
Battle::ItemEffects.triggerAccuracyCalcFromTarget(
target.item, modifiers, user, target, move, type
)
end
end
# Other effects, inc. ones that set accuracy_multiplier or evasion_stage to specific values
if skill >= PBTrainerAI.mediumSkill
if @battle.field.effects[PBEffects::Gravity] > 0
@@ -699,15 +666,15 @@ class Battle::AI
user.effects[PBEffects::LockOnPos] == target.index
end
if skill >= PBTrainerAI.highSkill
if move.function == "BadPoisonTarget" # Toxic
modifiers[:base_accuracy] = 0 if Settings::MORE_TYPE_EFFECTS && move.statusMove? &&
user.pbHasType?(:POISON)
if move.function == "BadPoisonTarget" && (Settings::MORE_TYPE_EFFECTS && move.statusMove? &&
user.pbHasType?(:POISON)) # Toxic
modifiers[:base_accuracy] = 0
end
if ["OHKO", "OHKOIce", "OHKOHitsUndergroundTarget"].include?(move.function)
modifiers[:base_accuracy] = move.accuracy + user.level - target.level
modifiers[:accuracy_multiplier] = 0 if target.level > user.level
if skill >= PBTrainerAI.bestSkill
modifiers[:accuracy_multiplier] = 0 if target.hasActiveAbility?(:STURDY)
if skill >= PBTrainerAI.bestSkill && target.hasActiveAbility?(:STURDY)
modifiers[:accuracy_multiplier] = 0
end
end
end

View File

@@ -4,8 +4,9 @@ module Battle::CatchAndStoreMixin
#=============================================================================
def pbStorePokemon(pkmn)
# Nickname the Pokémon (unless it's a Shadow Pokémon)
if !pkmn.shadowPokemon? && $PokemonSystem.givenicknames == 0
if pbDisplayConfirm(_INTL("Would you like to give a nickname to {1}?", pkmn.name))
if !pkmn.shadowPokemon?
if $PokemonSystem.givenicknames == 0 &&
pbDisplayConfirm(_INTL("Would you like to give a nickname to {1}?", pkmn.name))
nickname = @scene.pbNameEntry(_INTL("{1}'s nickname?", pkmn.speciesName), pkmn)
pkmn.name = nickname
end
@@ -166,7 +167,7 @@ module Battle::CatchAndStoreMixin
# Definite capture, no need to perform randomness checks
return 4 if x >= 255 || Battle::PokeBallEffects.isUnconditional?(ball, self, battler)
# Second half of the shakes calculation
y = (65536 / ((255.0 / x)**0.1875)).floor
y = (65_536 / ((255.0 / x)**0.1875)).floor
# Critical capture check
if Settings::ENABLE_CRITICAL_CAPTURES
dex_modifier = 0
@@ -187,7 +188,7 @@ module Battle::CatchAndStoreMixin
# Calculate the number of shakes
if c > 0 && pbRandom(256) < c
@criticalCapture = true
return 4 if pbRandom(65536) < y
return 4 if pbRandom(65_536) < y
return 0
end
end
@@ -195,7 +196,7 @@ module Battle::CatchAndStoreMixin
numShakes = 0
4.times do |i|
break if numShakes < i
numShakes += 1 if pbRandom(65536) < y
numShakes += 1 if pbRandom(65_536) < y
end
return numShakes
end

View File

@@ -494,7 +494,7 @@ class PBAnimation < Array
when 0 # Play SE
if i.name && i.name != ""
pbSEPlay("Anim/" + i.name, i.volume, i.pitch)
elsif user && user.pokemon
elsif user&.pokemon
name = GameData::Species.cry_filename_from_pokemon(user.pokemon)
pbSEPlay(name, i.volume, i.pitch) if name
end
@@ -517,16 +517,16 @@ class PBAnimation < Array
bgColor.opacity = i.opacity || 0
end
when 2 # Move/recolour background graphic
if bgGraphic.bitmap != nil
oldbg[0] = bgGraphic.ox || 0
oldbg[1] = bgGraphic.oy || 0
oldbg[2] = bgGraphic.opacity || 0
oldbg[3] = bgGraphic.color.clone || Color.new(0, 0, 0, 0)
else
if bgGraphic.bitmap.nil?
oldbg[0] = 0
oldbg[1] = 0
oldbg[2] = bgColor.opacity || 0
oldbg[3] = bgColor.color.clone || Color.new(0, 0, 0, 0)
else
oldbg[0] = bgGraphic.ox || 0
oldbg[1] = bgGraphic.oy || 0
oldbg[2] = bgGraphic.opacity || 0
oldbg[3] = bgGraphic.color.clone || Color.new(0, 0, 0, 0)
end
when 3 # Set foreground graphic (immediate)
if i.name && i.name != ""
@@ -543,16 +543,16 @@ class PBAnimation < Array
foColor.opacity = i.opacity || 0
end
when 4 # Move/recolour foreground graphic
if foGraphic.bitmap != nil
oldfo[0] = foGraphic.ox || 0
oldfo[1] = foGraphic.oy || 0
oldfo[2] = foGraphic.opacity || 0
oldfo[3] = foGraphic.color.clone || Color.new(0, 0, 0, 0)
else
if foGraphic.bitmap.nil?
oldfo[0] = 0
oldfo[1] = 0
oldfo[2] = foColor.opacity || 0
oldfo[3] = foColor.color.clone || Color.new(0, 0, 0, 0)
else
oldfo[0] = foGraphic.ox || 0
oldfo[1] = foGraphic.oy || 0
oldfo[2] = foGraphic.opacity || 0
oldfo[3] = foGraphic.color.clone || Color.new(0, 0, 0, 0)
end
end
end
@@ -562,7 +562,14 @@ class PBAnimation < Array
next if !i.duration || i.duration <= 0
next if frame < i.frame || frame > i.frame + i.duration
fraction = (frame - i.frame).to_f / i.duration
if bgGraphic.bitmap != nil
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.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
@@ -571,19 +578,19 @@ class PBAnimation < Array
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.color = Color.new(cr, cg, cb, ca)
else
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.color = Color.new(cr, cg, cb, ca)
end
when 4
next if !i.duration || i.duration <= 0
next if frame < i.frame || frame > i.frame + i.duration
fraction = (frame - i.frame).to_f / i.duration
if foGraphic.bitmap != nil
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.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
@@ -592,13 +599,6 @@ class PBAnimation < Array
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.color = Color.new(cr, cg, cb, ca)
else
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.color = Color.new(cr, cg, cb, ca)
end
end
end
@@ -700,10 +700,10 @@ class PBAnimationPlayerX
@user = (oppMove) ? target : user # Just used for playing user's cry
@usersprite = (user) ? scene.sprites["pokemon_#{user.index}"] : nil
@targetsprite = (target) ? scene.sprites["pokemon_#{target.index}"] : nil
@userbitmap = (@usersprite && @usersprite.bitmap) ? @usersprite.bitmap : nil # not to be disposed
@targetbitmap = (@targetsprite && @targetsprite.bitmap) ? @targetsprite.bitmap : nil # not to be disposed
@userbitmap = @usersprite&.bitmap # not to be disposed
@targetbitmap = @targetsprite&.bitmap # not to be disposed
@scene = scene
@viewport = (scene) ? scene.viewport : nil
@viewport = scene&.viewport
@inEditor = inEditor
@looping = false
@animbitmap = nil # Animation sheet graphic
@@ -761,9 +761,9 @@ class PBAnimationPlayerX
end
def dispose
@animbitmap.dispose if @animbitmap
@animbitmap&.dispose
(2...MAX_SPRITES).each do |i|
@animsprites[i].dispose if @animsprites[i]
@animsprites[i]&.dispose
end
@bgGraphic.dispose
@bgColor.dispose
@@ -792,7 +792,7 @@ class PBAnimationPlayerX
if animFrame >= @animation.length
@frame = (@looping) ? 0 : -1
if @frame < 0
@animbitmap.dispose if @animbitmap
@animbitmap&.dispose
@animbitmap = nil
return
end

View File

@@ -1179,8 +1179,8 @@ Battle::AbilityEffects::AccuracyCalcFromTarget.add(:UNAWARE,
Battle::AbilityEffects::AccuracyCalcFromTarget.add(:WONDERSKIN,
proc { |ability, mods, user, target, move, type|
if move.statusMove? && user.opposes?(target)
mods[:base_accuracy] = 50 if mods[:base_accuracy] > 50
if move.statusMove? && user.opposes?(target) && mods[:base_accuracy] > 50
mods[:base_accuracy] = 50
end
}
)

View File

@@ -1421,12 +1421,11 @@ Battle::ItemEffects::OnBeingHit.add(:STICKYBARB,
user.item = target.item
target.item = nil
target.effects[PBEffects::Unburden] = true if target.hasActiveAbility?(:UNBURDEN)
if battle.wildBattle? && !user.opposes?
if !user.initialItem && user.item == target.initialItem
if battle.wildBattle? && !user.opposes? &&
!user.initialItem && user.item == target.initialItem
user.setInitialItem(user.item)
target.setInitialItem(nil)
end
end
battle.pbDisplay(_INTL("{1}'s {2} was transferred to {3}!",
target.pbThis, user.itemName, user.pbThis(true)))
}

View File

@@ -26,7 +26,7 @@ class Battle::FakeBattler
def super_shiny?; return @pokemon.super_shiny?; end
def isSpecies?(check_species)
return @pokemon && @pokemon.isSpecies?(check_species)
return @pokemon&.isSpecies?(check_species)
end
def fainted?; return false; end

View File

@@ -87,8 +87,9 @@ class BattlePalaceBattle < Battle
return false
end
# though incorrect, just for convenience (actually checks Torment later)
if thispkmn.effects[PBEffects::Torment] && thispkmn.lastMoveUsed
return false if thismove.id == thispkmn.lastMoveUsed
if thispkmn.effects[PBEffects::Torment] &&
thispkmn.lastMoveUsed && thismove.id == thispkmn.lastMoveUsed
return false
end
return true
end

View File

@@ -53,9 +53,7 @@ class BattleArenaBattle < Battle
end
def pbCanSwitchLax?(idxBattler, _idxParty, partyScene = nil)
if partyScene
partyScene.pbDisplay(_INTL("{1} can't be switched out!", @battlers[idxBattler].pbThis))
end
partyScene&.pbDisplay(_INTL("{1} can't be switched out!", @battlers[idxBattler].pbThis))
return false
end
@@ -366,8 +364,8 @@ class Battle::Scene
ensure
pbDisposeMessageWindow(msgwindow)
dimmingvp.dispose
infowindow.contents.dispose if infowindow && infowindow.contents
infowindow.dispose if infowindow
infowindow&.contents&.dispose
infowindow&.dispose
end
end
end

View File

@@ -50,14 +50,14 @@ module RPG
end
def dispose
@sprites.each { |sprite| sprite.dispose if sprite }
@new_sprites.each { |sprite| sprite.dispose if sprite }
@tiles.each { |sprite| sprite.dispose if sprite }
@sprites.each { |sprite| sprite&.dispose }
@new_sprites.each { |sprite| sprite&.dispose }
@tiles.each { |sprite| sprite&.dispose }
@viewport.dispose
@weatherTypes.each_value do |weather|
next if !weather
weather[1].each { |bitmap| bitmap.dispose if bitmap }
weather[2].each { |bitmap| bitmap.dispose if bitmap }
weather[1].each { |bitmap| bitmap&.dispose }
weather[2].each { |bitmap| bitmap&.dispose }
end
end
@@ -83,7 +83,7 @@ module RPG
@time_shift += 1 # No previous tiles to fade out first
end
@fading = true
@new_sprites.each { |sprite| sprite.dispose if sprite }
@new_sprites.each { |sprite| sprite&.dispose }
@new_sprites.clear
ensureSprites
@new_sprites.each_with_index { |sprite, i| set_sprite_bitmap(sprite, i, @target_type) }
@@ -456,8 +456,8 @@ module RPG
@new_sprites.each_with_index { |sprite, i| sprite.visible = (i < @new_max) if sprite }
end
# End fading
if @fade_time >= ((@target_type == :None) ? FADE_OLD_PARTICLES_END : FADE_NEW_TILES_END) - @time_shift
if !@sprites.any? { |sprite| sprite.visible }
if @fade_time >= ((@target_type == :None) ? FADE_OLD_PARTICLES_END : FADE_NEW_TILES_END) - @time_shift &&
!@sprites.any? { |sprite| sprite.visible }
@type = @target_type
@max = @target_max
@target_type = nil
@@ -468,7 +468,7 @@ module RPG
@target_tone = nil
@fade_time = 0.0
@time_shift = 0
@sprites.each { |sprite| sprite.dispose if sprite }
@sprites.each { |sprite| sprite&.dispose }
@sprites = @new_sprites
@new_sprites = []
@sprite_lifetimes = @new_sprite_lifetimes
@@ -476,7 +476,6 @@ module RPG
@fading = false
end
end
end
def update
update_fading
@@ -501,7 +500,7 @@ module RPG
update_sprite_position(@sprites[i], i, false)
end
elsif @sprites.length > 0
@sprites.each { |sprite| sprite.dispose if sprite }
@sprites.each { |sprite| sprite&.dispose }
@sprites.clear
end
# Update new weather particles (while fading in only)
@@ -511,7 +510,7 @@ module RPG
update_sprite_position(@new_sprites[i], i, true)
end
elsif @new_sprites.length > 0
@new_sprites.each { |sprite| sprite.dispose if sprite }
@new_sprites.each { |sprite| sprite&.dispose }
@new_sprites.clear
end
# Update weather tiles (sandstorm/blizzard tiled overlay)
@@ -520,7 +519,7 @@ module RPG
recalculate_tile_positions
@tiles.each_with_index { |sprite, i| update_tile_position(sprite, i) }
elsif @tiles.length > 0
@tiles.each { |sprite| sprite.dispose if sprite }
@tiles.each { |sprite| sprite&.dispose }
@tiles.clear
end
end

View File

@@ -47,23 +47,18 @@ def pbBatteryLow?
end
Events.onMapUpdate += proc { |_sender, _e|
if !$game_temp.warned_low_battery && pbBatteryLow?
if !$game_temp.in_menu && !$game_temp.in_battle &&
!$game_player.move_route_forcing && !$game_temp.message_window_showing &&
!pbMapInterpreterRunning?
if pbGetTimeNow.sec == 0
if !$game_temp.warned_low_battery && pbBatteryLow? &&
!$game_temp.in_menu && !$game_temp.in_battle && !$game_player.move_route_forcing &&
!$game_temp.message_window_showing && !pbMapInterpreterRunning? &&
pbGetTimeNow.sec == 0
pbMessage(_INTL("The game has detected that the battery is low. You should save soon to avoid losing your progress."))
$game_temp.warned_low_battery = true
end
end
end
if $game_temp.cue_bgm_frame_delay
$game_temp.cue_bgm_frame_delay -= 1
if $game_temp.cue_bgm_frame_delay <= 0
$game_temp.cue_bgm_frame_delay = nil
if $game_system.getPlayingBGM == nil
pbBGMPlay($game_temp.cue_bgm)
end
pbBGMPlay($game_temp.cue_bgm) if $game_system.getPlayingBGM.nil?
end
end
}
@@ -133,7 +128,7 @@ Events.onStepTakenFieldMovement += proc { |_sender, e|
map = $map_factory.getMap(thistile[0])
[2, 1, 0].each do |i|
tile_id = map.data[thistile[1], thistile[2], i]
next if tile_id == nil
next if tile_id.nil?
next if GameData::TerrainTag.try_get(map.terrain_tags[tile_id]).id != :SootGrass
if event == $game_player && $bag.has?(:SOOTSACK)
old_soot = $player.soot
@@ -229,7 +224,7 @@ Events.onMapChanging += proc { |_sender, e|
map_infos = pbLoadMapInfos
if $game_map.name == map_infos[new_map_ID].name
new_map_metadata = GameData::MapMetadata.try_get(new_map_ID)
next if new_map_metadata && new_map_metadata.weather
next if new_map_metadata&.weather
end
$game_screen.weather(:None, 0, 0)
}
@@ -238,18 +233,18 @@ Events.onMapChanging += proc { |_sender, e|
Events.onMapChange += proc { |_sender, e|
old_map_ID = e[0] # previous map ID, is 0 if no map ID
new_map_metadata = $game_map.metadata
if new_map_metadata && new_map_metadata.teleport_destination
if new_map_metadata&.teleport_destination
$PokemonGlobal.healingSpot = new_map_metadata.teleport_destination
end
$PokemonMap.clear if $PokemonMap
$PokemonEncounters.setup($game_map.map_id) if $PokemonEncounters
$PokemonMap&.clear
$PokemonEncounters&.setup($game_map.map_id)
$PokemonGlobal.visitedMaps[$game_map.map_id] = true
next if old_map_ID == 0 || old_map_ID == $game_map.map_id
next if !new_map_metadata || !new_map_metadata.weather
map_infos = pbLoadMapInfos
if $game_map.name == map_infos[old_map_ID].name
old_map_metadata = GameData::MapMetadata.try_get(old_map_ID)
next if old_map_metadata && old_map_metadata.weather
next if old_map_metadata&.weather
end
new_weather = new_map_metadata.weather
$game_screen.weather(new_weather[0], 9, 0) if rand(100) < new_weather[1]
@@ -262,14 +257,14 @@ Events.onMapSceneChange += proc { |_sender, e|
# Update map trail
if $game_map
$PokemonGlobal.mapTrail = [] if !$PokemonGlobal.mapTrail
if $PokemonGlobal.mapTrail[0] != $game_map.map_id
$PokemonGlobal.mapTrail.pop if $PokemonGlobal.mapTrail.length >= 4
if $PokemonGlobal.mapTrail[0] != $game_map.map_id && $PokemonGlobal.mapTrail.length >= 4
$PokemonGlobal.mapTrail.pop
end
$PokemonGlobal.mapTrail = [$game_map.map_id] + $PokemonGlobal.mapTrail
end
# Display darkness circle on dark maps
map_metadata = $game_map.metadata
if map_metadata && map_metadata.dark_map
if map_metadata&.dark_map
$game_temp.darkness_sprite = DarknessSprite.new
scene.spriteset.addUserSprite($game_temp.darkness_sprite)
if $PokemonGlobal.flashUsed
@@ -277,7 +272,7 @@ Events.onMapSceneChange += proc { |_sender, e|
end
else
$PokemonGlobal.flashUsed = false
$game_temp.darkness_sprite.dispose if $game_temp.darkness_sprite
$game_temp.darkness_sprite&.dispose
$game_temp.darkness_sprite = nil
end
# Show location signpost
@@ -298,7 +293,7 @@ Events.onMapSceneChange += proc { |_sender, e|
scene.spriteset.addUserSprite(LocationWindow.new($game_map.name)) if !nosignpost
end
# Force cycling/walking
if map_metadata && map_metadata.always_bicycle
if map_metadata&.always_bicycle
pbMountBike
elsif !pbCanUseBike?($game_map.map_id)
pbDismountBike
@@ -517,9 +512,7 @@ def pbMoveRoute(event, commands, waitComplete = false)
end
route.list.push(RPG::MoveCommand.new(PBMoveRoute::ThroughOff))
route.list.push(RPG::MoveCommand.new(0))
if event
event.force_move_route(route)
end
event&.force_move_route(route)
return route
end
@@ -610,7 +603,7 @@ def pbMoveTowardPlayer(event)
pbUpdateSceneMap
end
end
$PokemonMap.addMovedEvent(event.id) if $PokemonMap
$PokemonMap&.addMovedEvent(event.id)
end
def pbJumpToward(dist = 1, playSound = false, cancelSurf = false)

View File

@@ -573,12 +573,10 @@ def pbAfterBattle(decision, canLose)
pkmn.makeUnprimal
end
end
if [2, 5].include?(decision) # if loss or draw
if canLose
if [2, 5].include?(decision) && canLose # if loss or draw
$player.party.each { |pkmn| pkmn.heal }
(Graphics.frame_rate / 4).times { Graphics.update }
end
end
Events.onEndBattle.trigger(nil, decision, canLose)
$game_player.straighten
end

View File

@@ -32,11 +32,11 @@ end
# Battle intro animation
#===============================================================================
def pbSceneStandby
$scene.disposeSpritesets if $scene && $scene.is_a?(Scene_Map)
$scene.disposeSpritesets if $scene.is_a?(Scene_Map)
RPG::Cache.clear
Graphics.frame_reset
yield
$scene.createSpritesets if $scene && $scene.is_a?(Scene_Map)
$scene.createSpritesets if $scene.is_a?(Scene_Map)
end
def pbBattleAnimation(bgm = nil, battletype = 0, foe = nil)
@@ -46,7 +46,7 @@ def pbBattleAnimation(bgm = nil, battletype = 0, foe = nil)
# Set up audio
playingBGS = nil
playingBGM = nil
if $game_system && $game_system.is_a?(Game_System)
if $game_system.is_a?(Game_System)
playingBGS = $game_system.getPlayingBGS
playingBGM = $game_system.getPlayingBGM
$game_system.bgm_pause
@@ -120,7 +120,7 @@ def pbBattleAnimation(bgm = nil, battletype = 0, foe = nil)
end
end
# Take screenshot of game, for use in some animations
$game_temp.background_bitmap.dispose if $game_temp.background_bitmap
$game_temp.background_bitmap&.dispose
$game_temp.background_bitmap = Graphics.snap_to_bitmap
# Play main animation
Graphics.freeze
@@ -138,7 +138,7 @@ def pbBattleAnimation(bgm = nil, battletype = 0, foe = nil)
yield if block_given?
# After the battle
pbPopFade
if $game_system && $game_system.is_a?(Game_System)
if $game_system.is_a?(Game_System)
$game_system.bgm_resume(playingBGM)
$game_system.bgs_resume(playingBGS)
end

View File

@@ -281,25 +281,21 @@ class PokemonEncounters
favored_type = nil
case first_pkmn.ability_id
when :FLASHFIRE
if Settings::MORE_ABILITIES_AFFECT_WILD_ENCOUNTERS
favored_type = :FIRE if GameData::Type.exists?(:FIRE) && rand(100) < 50
end
favored_type = :FIRE if Settings::MORE_ABILITIES_AFFECT_WILD_ENCOUNTERS &&
GameData::Type.exists?(:FIRE) && rand(100) < 50
when :HARVEST
if Settings::MORE_ABILITIES_AFFECT_WILD_ENCOUNTERS
favored_type = :GRASS if GameData::Type.exists?(:GRASS) && rand(100) < 50
end
favored_type = :GRASS if Settings::MORE_ABILITIES_AFFECT_WILD_ENCOUNTERS &&
GameData::Type.exists?(:GRASS) && rand(100) < 50
when :LIGHTNINGROD
if Settings::MORE_ABILITIES_AFFECT_WILD_ENCOUNTERS
favored_type = :ELECTRIC if GameData::Type.exists?(:ELECTRIC) && rand(100) < 50
end
favored_type = :ELECTRIC if Settings::MORE_ABILITIES_AFFECT_WILD_ENCOUNTERS &&
GameData::Type.exists?(:ELECTRIC) && rand(100) < 50
when :MAGNETPULL
favored_type = :STEEL if GameData::Type.exists?(:STEEL) && rand(100) < 50
when :STATIC
favored_type = :ELECTRIC if GameData::Type.exists?(:ELECTRIC) && rand(100) < 50
when :STORMDRAIN
if Settings::MORE_ABILITIES_AFFECT_WILD_ENCOUNTERS
favored_type = :WATER if GameData::Type.exists?(:WATER) && rand(100) < 50
end
favored_type = :WATER if Settings::MORE_ABILITIES_AFFECT_WILD_ENCOUNTERS &&
GameData::Type.exists?(:WATER) && rand(100) < 50
end
if favored_type
new_enc_list = []
@@ -433,7 +429,7 @@ def pbGenerateWildPokemon(species, level, isRoamer = false)
end
end
# Give Pokérus
genwildpoke.givePokerus if rand(65536) < Settings::POKERUS_CHANCE
genwildpoke.givePokerus if rand(65_536) < Settings::POKERUS_CHANCE
# Change wild Pokémon's gender/nature depending on the lead party Pokémon's
# ability
if first_pkmn

View File

@@ -156,7 +156,7 @@ class PokemonMapMetadata
@erasedEvents.each do |i|
if i[0][0] == $game_map.map_id && i[1]
event = $game_map.events[i[0][1]]
event.erase if event
event&.erase
end
end
@movedEvents.each do |i|

View File

@@ -149,9 +149,9 @@ def moonphase(time = nil) # in UTC
]
yy = time.year - ((12 - time.mon) / 10.0).floor
j = (365.25 * (4712 + yy)).floor + ((((time.mon + 9) % 12) * 30.6) + 0.5).floor + time.day + 59
j -= (((yy / 100.0) + 49).floor * 0.75).floor - 38 if j > 2299160
j += (((time.hour * 60) + (time.min * 60)) + time.sec) / 86400.0
v = (j - 2451550.1) / 29.530588853
j -= (((yy / 100.0) + 49).floor * 0.75).floor - 38 if j > 2_299_160
j += (((time.hour * 60) + (time.min * 60)) + time.sec) / 86_400.0
v = (j - 2_451_550.1) / 29.530588853
v = ((v - v.floor) + (v < 0 ? 1 : 0))
ag = v * 29.53
transitions.length.times do |i|

Some files were not shown because too many files have changed in this diff Show More