From 736bb9ed10d18c1e79bf4018965b513f2fdba9d5 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Wed, 20 Jan 2021 20:22:31 +0000 Subject: [PATCH] Fixed code assuming map metadata exists, fixed misplaced species data methods, rewrote class PokeBattle_Pokemon --- .../003_Game classes/007_Game_Player.rb | 7 +- Data/Scripts/003_Game classes/009_Game_Map.rb | 4 +- .../011_Data/001_Game data/010_Species.rb | 36 +++--- .../Scripts/013_Overworld/002_PField_Field.rb | 111 ++++++++---------- .../013_Overworld/003_PField_Visuals.rb | 3 +- .../013_Overworld/006_PField_Battles.rb | 12 +- .../009_PField_RoamingPokemon.rb | 5 +- .../010_PField_RandomDungeons.rb | 38 +++--- .../013_Overworld/011_PField_FieldMoves.rb | 27 +++-- Data/Scripts/013_Overworld/015_PField_Time.rb | 3 +- Data/Scripts/015_Items/001_PItem_Items.rb | 7 +- Data/Scripts/015_Items/004_PItem_Phone.rb | 22 ++-- Data/Scripts/016_Pokemon/001_Pokemon.rb | 11 +- Data/Scripts/016_Pokemon/002_Pokemon_Forms.rb | 5 +- .../{011_Data => 016_Pokemon}/003_PBMove.rb | 0 .../016_Pokemon/005_Pokemon_Evolution.rb | 8 +- .../016_Pokemon/010_Pokemon_Deprecated.rb | 82 ++++++++++++- .../017_UI/004_PScreen_PokedexEntry.rb | 47 ++++---- Data/Scripts/017_UI/009_PScreen_RegionMap.rb | 5 +- .../019_Other battles/001_PBattle_Safari.rb | 5 +- .../003_PSystem_BattleAudioUtilities.rb | 34 +++--- .../004_PSystem_PokemonUtilities.rb | 2 +- .../005_PSystem_Utilities.rb | 4 +- Data/Scripts/021_Debug/004_Editor_Screens.rb | 3 +- 24 files changed, 283 insertions(+), 198 deletions(-) rename Data/Scripts/{011_Data => 016_Pokemon}/003_PBMove.rb (100%) diff --git a/Data/Scripts/003_Game classes/007_Game_Player.rb b/Data/Scripts/003_Game classes/007_Game_Player.rb index 862cb63a8..00efc93d7 100644 --- a/Data/Scripts/003_Game classes/007_Game_Player.rb +++ b/Data/Scripts/003_Game classes/007_Game_Player.rb @@ -449,9 +449,10 @@ def pbCancelVehicles(destination=nil) end def pbCanUseBike?(map_id) - return true if GameData::MapMetadata.get(map_id).always_bicycle - val = GameData::MapMetadata.get(map_id).can_bicycle - val = GameData::MapMetadata.get(map_id).outdoor_map if val.nil? + map_metadata = GameData::MapMetadata.try_get(map_id) + return false if !map_metadata + return true if map_metadata.always_bicycle + val = map_metadata.can_bicycle || map_metadata.outdoor_map return (val) ? true : false end diff --git a/Data/Scripts/003_Game classes/009_Game_Map.rb b/Data/Scripts/003_Game classes/009_Game_Map.rb index c5aa71391..922755f9a 100644 --- a/Data/Scripts/003_Game classes/009_Game_Map.rb +++ b/Data/Scripts/003_Game classes/009_Game_Map.rb @@ -330,7 +330,7 @@ class Game_Map def display_x=(value) @display_x = value - if GameData::MapMetadata.get(self.map_id).snap_edges + if GameData::MapMetadata.exists?(self.map_id) && GameData::MapMetadata.get(self.map_id).snap_edges max_x = (self.width - Graphics.width*1.0/TILE_WIDTH) * REAL_RES_X @display_x = [0, [@display_x, max_x].min].max end @@ -339,7 +339,7 @@ class Game_Map def display_y=(value) @display_y = value - if GameData::MapMetadata.get(self.map_id).snap_edges + if GameData::MapMetadata.exists?(self.map_id) && GameData::MapMetadata.get(self.map_id).snap_edges max_y = (self.height - Graphics.height*1.0/TILE_HEIGHT) * REAL_RES_Y @display_y = [0, [@display_y, max_y].min].max end diff --git a/Data/Scripts/011_Data/001_Game data/010_Species.rb b/Data/Scripts/011_Data/001_Game data/010_Species.rb index 064c057cb..d185ca34e 100644 --- a/Data/Scripts/011_Data/001_Game data/010_Species.rb +++ b/Data/Scripts/011_Data/001_Game data/010_Species.rb @@ -195,28 +195,28 @@ module GameData def pokedex_entry return pbGetMessage(MessageTypes::Entries, @id_number) end - end - def apply_metrics_to_sprite(sprite, index, shadow = false) - if shadow - if (index & 1) == 1 # Foe Pokémon - sprite.x += @shadow_x * 2 - end - else - if (index & 1) == 0 # Player's Pokémon - sprite.x += @back_sprite_x * 2 - sprite.y += @back_sprite_y * 2 - else # Foe Pokémon - sprite.x += @front_sprite_x * 2 - sprite.y += @front_sprite_y * 2 - sprite.y -= @front_sprite_altitude * 2 + def apply_metrics_to_sprite(sprite, index, shadow = false) + if shadow + if (index & 1) == 1 # Foe Pokémon + sprite.x += @shadow_x * 2 + end + else + if (index & 1) == 0 # Player's Pokémon + sprite.x += @back_sprite_x * 2 + sprite.y += @back_sprite_y * 2 + else # Foe Pokémon + sprite.x += @front_sprite_x * 2 + sprite.y += @front_sprite_y * 2 + sprite.y -= @front_sprite_altitude * 2 + end end end - end - def shows_shadow? - return true -# return @front_sprite_altitude > 0 + def shows_shadow? + return true +# return @front_sprite_altitude > 0 + end end end diff --git a/Data/Scripts/013_Overworld/002_PField_Field.rb b/Data/Scripts/013_Overworld/002_PField_Field.rb index 10f608708..275df3303 100644 --- a/Data/Scripts/013_Overworld/002_PField_Field.rb +++ b/Data/Scripts/013_Overworld/002_PField_Field.rb @@ -406,94 +406,85 @@ end #=============================================================================== # Checks when moving between maps #=============================================================================== -# Clears the weather of the old map, if the old and new maps have different -# names or defined weather -Events.onMapChanging += proc { |_sender,e| - newMapID = e[0] - if newMapID>0 - mapinfos = load_data("Data/MapInfos.rxdata") - oldWeather = GameData::MapMetadata.get($game_map.map_id).weather - if $game_map.name!=mapinfos[newMapID].name - $game_screen.weather(0,0,0) if oldWeather - else - newWeather = GameData::MapMetadata.get(newMapID).weather - $game_screen.weather(0,0,0) if oldWeather && !newWeather - end +# Clears the weather of the old map, if the old map has defined weather and the +# new map either has the same name as the old map or doesn't have defined +# weather. +Events.onMapChanging += proc { |_sender, e| + new_map_ID = e[0] + next if new_map_ID == 0 + old_map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + next if !old_map_metadata || !old_map_metadata.weather + map_infos = load_data("Data/MapInfos.rxdata") + 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 end + $game_screen.weather(0, 0, 0) } # Set up various data related to the new map -Events.onMapChange += proc { |_sender,e| - oldid = e[0] # previous map ID, is 0 if no map ID - healing = GameData::MapMetadata.get($game_map.map_id).teleport_destination - $PokemonGlobal.healingSpot = healing if healing +Events.onMapChange += proc { |_sender, e| + old_map_ID = e[0] # previous map ID, is 0 if no map ID + new_map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + if new_map_metadata && 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 $PokemonGlobal.visitedMaps[$game_map.map_id] = true - if oldid!=0 && oldid!=$game_map.map_id - mapinfos = load_data("Data/MapInfos.rxdata") - weather = GameData::MapMetadata.get($game_map.map_id).weather - if $game_map.name!=mapinfos[oldid].name - $game_screen.weather(weather[0],8,20) if weather && rand(100)= 4 end - $PokemonGlobal.mapTrail[0] = $game_map.map_id + $PokemonGlobal.mapTrail = [$game_map.map_id] + $PokemonGlobal.mapTrail end # Display darkness circle on dark maps - darkmap = GameData::MapMetadata.get($game_map.map_id).dark_map - if darkmap + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + if map_metadata && map_metadata.dark_map + $PokemonTemp.darknessSprite = DarknessSprite.new + scene.spriteset.addUserSprite($PokemonTemp.darknessSprite) if $PokemonGlobal.flashUsed - $PokemonTemp.darknessSprite = DarknessSprite.new - scene.spriteset.addUserSprite($PokemonTemp.darknessSprite) - darkness = $PokemonTemp.darknessSprite - darkness.radius = darkness.radiusMax - else - $PokemonTemp.darknessSprite = DarknessSprite.new - scene.spriteset.addUserSprite($PokemonTemp.darknessSprite) + $PokemonTemp.darknessSprite.radius = $PokemonTemp.darknessSprite.radiusMax end - elsif !darkmap + else $PokemonGlobal.flashUsed = false - if $PokemonTemp.darknessSprite - $PokemonTemp.darknessSprite.dispose - $PokemonTemp.darknessSprite = nil - end + $PokemonTemp.darknessSprite.dispose if $PokemonTemp.darknessSprite + $PokemonTemp.darknessSprite = nil end # Show location signpost - if mapChanged - if GameData::MapMetadata.get($game_map.map_id).announce_location - nosignpost = false - if $PokemonGlobal.mapTrail[1] - for i in 0...NO_SIGNPOSTS.length/2 - nosignpost = true if NO_SIGNPOSTS[2*i]==$PokemonGlobal.mapTrail[1] && NO_SIGNPOSTS[2*i+1]==$game_map.map_id - nosignpost = true if NO_SIGNPOSTS[2*i+1]==$PokemonGlobal.mapTrail[1] && NO_SIGNPOSTS[2*i]==$game_map.map_id - break if nosignpost - end - mapinfos = load_data("Data/MapInfos.rxdata") - oldmapname = mapinfos[$PokemonGlobal.mapTrail[1]].name - nosignpost = true if $game_map.name==oldmapname + if mapChanged && map_metadata && map_metadata.announce_location + nosignpost = false + if $PokemonGlobal.mapTrail[1] + for i in 0...NO_SIGNPOSTS.length / 2 + nosignpost = true if NO_SIGNPOSTS[2 * i] == $PokemonGlobal.mapTrail[1] && NO_SIGNPOSTS[2 * i + 1] == $game_map.map_id + nosignpost = true if NO_SIGNPOSTS[2 * i + 1] == $PokemonGlobal.mapTrail[1] && NO_SIGNPOSTS[2 * i] == $game_map.map_id + break if nosignpost end - scene.spriteset.addUserSprite(LocationWindow.new($game_map.name)) if !nosignpost + mapinfos = load_data("Data/MapInfos.rxdata") + oldmapname = mapinfos[$PokemonGlobal.mapTrail[1]].name + nosignpost = true if $game_map.name == oldmapname end + scene.spriteset.addUserSprite(LocationWindow.new($game_map.name)) if !nosignpost end # Force cycling/walking - if GameData::MapMetadata.get($game_map.map_id).always_bicycle + if map_metadata && map_metadata.always_bicycle pbMountBike elsif !pbCanUseBike?($game_map.map_id) pbDismountBike diff --git a/Data/Scripts/013_Overworld/003_PField_Visuals.rb b/Data/Scripts/013_Overworld/003_PField_Visuals.rb index 316d575c5..6b7b32ac8 100644 --- a/Data/Scripts/013_Overworld/003_PField_Visuals.rb +++ b/Data/Scripts/013_Overworld/003_PField_Visuals.rb @@ -46,7 +46,8 @@ def pbBattleAnimation(bgm=nil,battletype=0,foe=nil) location = 3 elsif $PokemonEncounters.isCave? location = 2 - elsif !GameData::MapMetadata.get($game_map.map_id).outdoor_map + elsif !GameData::MapMetadata.exists?($game_map.map_id) || + !GameData::MapMetadata.get($game_map.map_id).outdoor_map location = 1 end anim = "" diff --git a/Data/Scripts/013_Overworld/006_PField_Battles.rb b/Data/Scripts/013_Overworld/006_PField_Battles.rb index be280d500..336eb1727 100644 --- a/Data/Scripts/013_Overworld/006_PField_Battles.rb +++ b/Data/Scripts/013_Overworld/006_PField_Battles.rb @@ -130,9 +130,9 @@ def pbPrepareBattle(battle) backdrop = $PokemonGlobal.nextBattleBack elsif $PokemonGlobal.surfing backdrop = "water" # This applies wherever you are, including in caves - else + elsif GameData::MapMetadata.exists?($game_map.map_id) back = GameData::MapMetadata.get($game_map.map_id).battle_background - backdrop = back if back && back!="" + backdrop = back if back && back != "" end backdrop = "indoor1" if !backdrop battle.backdrop = backdrop @@ -158,7 +158,8 @@ def pbPrepareBattle(battle) end battle.backdropBase = base if base # Time of day - if GameData::MapMetadata.get($game_map.map_id).battle_environment == PBEnvironment::Cave + if GameData::MapMetadata.exists?($game_map.map_id) && + GameData::MapMetadata.get($game_map.map_id).battle_environment == PBEnvironment::Cave battle.time = 2 # This makes Dusk Balls work properly in caves elsif TIME_SHADING timeNow = pbGetTimeNow @@ -172,8 +173,9 @@ end # Used to determine the environment in battle, and also the form of Burmy/ # Wormadam. def pbGetEnvironment - ret = GameData::MapMetadata.get($game_map.map_id).battle_environment - ret = PBEnvironment::None if !ret + ret = PBEnvironment::None + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + ret = map_metadata.battle_environment if map_metadata && map_metadata.battle_environment if $PokemonTemp.encounterType == EncounterTypes::OldRod || $PokemonTemp.encounterType == EncounterTypes::GoodRod || $PokemonTemp.encounterType == EncounterTypes::SuperRod diff --git a/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb b/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb index c8051cec0..c7f37d718 100644 --- a/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb +++ b/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb @@ -178,8 +178,9 @@ EncounterModifier.register(proc { |encounter| # are in the same region if roamerMap!=$game_map.map_id currentRegion = pbGetCurrentRegion - map_position = GameData::MapMetadata.get(roamerMap).town_map_position - next if !map_position || map_position[0] != currentRegion + map_metadata = GameData::MapMetadata.try_get(roamerMap) + next if !map_metadata || !map_metadata.town_map_position || + map_metadata.town_map_position[0] != currentRegion currentMapName = pbGetMessage(MessageTypes::MapNames,$game_map.map_id) next if pbGetMessage(MessageTypes::MapNames,roamerMap)!=currentMapName end diff --git a/Data/Scripts/013_Overworld/010_PField_RandomDungeons.rb b/Data/Scripts/013_Overworld/010_PField_RandomDungeons.rb index bdcd8736d..a1b796f83 100644 --- a/Data/Scripts/013_Overworld/010_PField_RandomDungeons.rb +++ b/Data/Scripts/013_Overworld/010_PField_RandomDungeons.rb @@ -562,27 +562,27 @@ def pbRandomRoomTile(dungeon,tiles) end Events.onMapCreate += proc { |_sender, e| - mapID=e[0] - map=e[1] - if GameData::MapMetadata.get(mapID).random_dungeon - # this map is a randomly generated dungeon - dungeon=Dungeon.new(map.width,map.height) - dungeon.generate - dungeon.generateMapInPlace(map) - roomtiles=[] - # Reposition events - for event in map.events.values - tile=pbRandomRoomTile(dungeon,roomtiles) - if tile - event.x=tile[0] - event.y=tile[1] - end - end - # Override transfer X and Y + mapID = e[0] + map = e[1] + next if !GameData::MapMetadata.exists?(mapID) || + !GameData::MapMetadata.get(mapID).random_dungeon + # this map is a randomly generated dungeon + dungeon=Dungeon.new(map.width,map.height) + dungeon.generate + dungeon.generateMapInPlace(map) + roomtiles=[] + # Reposition events + for event in map.events.values tile=pbRandomRoomTile(dungeon,roomtiles) if tile - $game_temp.player_new_x=tile[0] - $game_temp.player_new_y=tile[1] + event.x=tile[0] + event.y=tile[1] end end + # Override transfer X and Y + tile=pbRandomRoomTile(dungeon,roomtiles) + if tile + $game_temp.player_new_x=tile[0] + $game_temp.player_new_y=tile[1] + end } diff --git a/Data/Scripts/013_Overworld/011_PField_FieldMoves.rb b/Data/Scripts/013_Overworld/011_PField_FieldMoves.rb index 058592f16..0a85120a4 100644 --- a/Data/Scripts/013_Overworld/011_PField_FieldMoves.rb +++ b/Data/Scripts/013_Overworld/011_PField_FieldMoves.rb @@ -294,8 +294,8 @@ HiddenMoveHandlers::UseMove.add(:DIG,proc { |move,pokemon| # Dive #=============================================================================== def pbDive - divemap = GameData::MapMetadata.get($game_map.map_id).dive_map_id - return false if !divemap + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + return false if !map_metadata || !map_metadata.dive_map_id move = :DIVE movefinder = pbCheckMove(move) if !pbCheckHiddenMoveBadge(BADGE_FOR_DIVE,false) || (!$DEBUG && !movefinder) @@ -307,7 +307,7 @@ def pbDive pbMessage(_INTL("{1} used {2}!",speciesname,GameData::Move.get(move).name)) pbHiddenMoveAnimation(movefinder) pbFadeOutIn { - $game_temp.player_new_map_id = divemap + $game_temp.player_new_map_id = map_metadata.dive_map_id $game_temp.player_new_x = $game_player.x $game_temp.player_new_y = $game_player.y $game_temp.player_new_direction = $game_player.direction @@ -404,7 +404,8 @@ HiddenMoveHandlers::CanUseMove.add(:DIVE,proc { |move,pkmn,showmsg| next false end else - if !GameData::MapMetadata.get($game_map.map_id).dive_map_id + if !GameData::MapMetadata.exists?($game_map.map_id) || + !GameData::MapMetadata.get($game_map.map_id).dive_map_id pbMessage(_INTL("Can't use that here.")) if showmsg next false end @@ -426,7 +427,8 @@ HiddenMoveHandlers::UseMove.add(:DIVE,proc { |move,pokemon| break end else - dive_map_id = GameData::MapMetadata.get($game_map.map_id).dive_map_id + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + dive_map_id = map_metadata.dive_map_id if map_metadata end next false if !dive_map_id if !pbHiddenMoveAnimation(pokemon) @@ -454,7 +456,8 @@ HiddenMoveHandlers::UseMove.add(:DIVE,proc { |move,pokemon| #=============================================================================== HiddenMoveHandlers::CanUseMove.add(:FLASH,proc { |move,pkmn,showmsg| next false if !pbCheckHiddenMoveBadge(BADGE_FOR_FLASH,showmsg) - if !GameData::MapMetadata.get($game_map.map_id).dark_map + if !GameData::MapMetadata.exists?($game_map.map_id) || + !GameData::MapMetadata.get($game_map.map_id).dark_map pbMessage(_INTL("Can't use that here.")) if showmsg next false end @@ -494,7 +497,8 @@ HiddenMoveHandlers::CanUseMove.add(:FLY,proc { |move,pkmn,showmsg| pbMessage(_INTL("It can't be used when you have someone with you.")) if showmsg next false end - if !GameData::MapMetadata.get($game_map.map_id).outdoor_map + if !GameData::MapMetadata.exists?($game_map.map_id) || + !GameData::MapMetadata.get($game_map.map_id).outdoor_map pbMessage(_INTL("Can't use that here.")) if showmsg next false end @@ -753,7 +757,8 @@ end Events.onAction += proc { |_sender,_e| next if $PokemonGlobal.surfing - next if GameData::MapMetadata.get($game_map.map_id).always_bicycle + next if GameData::MapMetadata.exists?($game_map.map_id) && + GameData::MapMetadata.get($game_map.map_id).always_bicycle next if !PBTerrain.isSurfable?(pbFacingTerrainTag) next if !$game_map.passable?($game_player.x,$game_player.y,$game_player.direction,$game_player) pbSurf @@ -769,7 +774,8 @@ HiddenMoveHandlers::CanUseMove.add(:SURF,proc { |move,pkmn,showmsg| pbMessage(_INTL("It can't be used when you have someone with you.")) if showmsg next false end - if GameData::MapMetadata.get($game_map.map_id).always_bicycle + if GameData::MapMetadata.exists?($game_map.map_id) && + GameData::MapMetadata.get($game_map.map_id).always_bicycle pbMessage(_INTL("Let's enjoy cycling!")) if showmsg next false end @@ -850,7 +856,8 @@ HiddenMoveHandlers::UseMove.add(:SWEETSCENT,proc { |move,pokemon| # Teleport #=============================================================================== HiddenMoveHandlers::CanUseMove.add(:TELEPORT,proc { |move,pkmn,showmsg| - if !GameData::MapMetadata.get($game_map.map_id).outdoor_map + if !GameData::MapMetadata.exists?($game_map.map_id) || + !GameData::MapMetadata.get($game_map.map_id).outdoor_map pbMessage(_INTL("Can't use that here.")) if showmsg next false end diff --git a/Data/Scripts/013_Overworld/015_PField_Time.rb b/Data/Scripts/013_Overworld/015_PField_Time.rb index 0e8e51260..a97822106 100644 --- a/Data/Scripts/013_Overworld/015_PField_Time.rb +++ b/Data/Scripts/013_Overworld/015_PField_Time.rb @@ -117,7 +117,8 @@ end def pbDayNightTint(object) return if !$scene.is_a?(Scene_Map) - if TIME_SHADING && GameData::MapMetadata.get($game_map.map_id).outdoor_map + if TIME_SHADING && GameData::MapMetadata.exists?($game_map.map_id) && + GameData::MapMetadata.get($game_map.map_id).outdoor_map tone = PBDayNight.getTone object.tone.set(tone.red,tone.green,tone.blue,tone.gray) else diff --git a/Data/Scripts/015_Items/001_PItem_Items.rb b/Data/Scripts/015_Items/001_PItem_Items.rb index f6a7371f7..ff6335b76 100644 --- a/Data/Scripts/015_Items/001_PItem_Items.rb +++ b/Data/Scripts/015_Items/001_PItem_Items.rb @@ -358,16 +358,15 @@ def pbBikeCheck pbMessage(_INTL("It can't be used when you have someone with you.")) return false end + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) if $PokemonGlobal.bicycle - if GameData::MapMetadata.get($game_map.map_id).always_bicycle + if map_metadata && map_metadata.always_bicycle pbMessage(_INTL("You can't dismount your Bike here.")) return false end return true end - val = GameData::MapMetadata.get($game_map.map_id).can_bicycle - val = GameData::MapMetadata.get($game_map.map_id).outdoor_map if val.nil? - if !val + if !map_metadata || (!map_metadata.can_bicycle && !map_metadata.outdoor_map) pbMessage(_INTL("Can't use that here.")) return false end diff --git a/Data/Scripts/015_Items/004_PItem_Phone.rb b/Data/Scripts/015_Items/004_PItem_Phone.rb index 2d72790ed..19de09285 100644 --- a/Data/Scripts/015_Items/004_PItem_Phone.rb +++ b/Data/Scripts/015_Items/004_PItem_Phone.rb @@ -64,14 +64,16 @@ end def pbRandomPhoneTrainer $PokemonGlobal.phoneNumbers = [] if !$PokemonGlobal.phoneNumbers temparray = [] - currentRegion = GameData::MapMetadata.get($game_map.map_id).town_map_position - return nil if !currentRegion + this_map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + return nil if !this_map_metadata || !this_map_metadata.town_map_position + currentRegion = this_map_metadata.town_map_position[0] for num in $PokemonGlobal.phoneNumbers - next if !num[0] || num.length!=8 # if not visible or not a trainer - next if $game_map.map_id==num[6] # Can't call if on same map - callerRegion = GameData::MapMetadata.get(num[6]).town_map_position + next if !num[0] || num.length != 8 # if not visible or not a trainer + next if $game_map.map_id == num[6] # Can't call if on same map + caller_map_metadata = GameData::MapMetadata.try_get(num[6]) + next if !caller_map_metadata || !caller_map_metadata.town_map_position # Can't call if in different region - next if !callerRegion || callerRegion[0] != currentRegion[0] + next if caller_map_metadata.town_map_position[0] != currentRegion temparray.push(num) end return nil if temparray.length==0 @@ -190,9 +192,11 @@ def pbCallTrainer(trtype,trname) pbMessage(_INTL("The Trainer is close by.\nTalk to the Trainer in person!")) return end - callerregion = GameData::MapMetadata.get(trainer[6]).town_map_position - currentregion = GameData::MapMetadata.get($game_map.map_id).town_map_position - if !callerregion || !currentregion || callerregion[0] != currentregion[0] + caller_map_metadata = GameData::MapMetadata.try_get(trainer[6]) + this_map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + if !caller_map_metadata || !caller_map_metadata.town_map_position || + !this_map_metadata || !this_map_metadata.town_map_position || + caller_map_metadata.town_map_position[0] != this_map_metadata.town_map_position[0] pbMessage(_INTL("The Trainer is out of range.")) return # Can't call if in different region end diff --git a/Data/Scripts/016_Pokemon/001_Pokemon.rb b/Data/Scripts/016_Pokemon/001_Pokemon.rb index bd3d225c4..b5c740977 100644 --- a/Data/Scripts/016_Pokemon/001_Pokemon.rb +++ b/Data/Scripts/016_Pokemon/001_Pokemon.rb @@ -59,7 +59,7 @@ class Pokemon attr_reader :status # @return [Integer] sleep count / toxic flag / 0: # sleep (number of rounds before waking up), toxic (0 = regular poison, 1 = toxic) - attr_reader :statusCount + attr_accessor :statusCount # Another Pokémon which has been fused with this Pokémon (or nil if there is none). # Currently only used by Kyurem, to record a fused Reshiram or Zekrom. # @return [Pokemon, nil] the Pokémon fused into this one (nil if there is none) @@ -751,12 +751,6 @@ class Pokemon @status = new_status end - # Sets a new status count. See {#statusCount} for more information. - # @param new_status_count [Integer] new sleep count / toxic flag - def statusCount=(new_status_count) - @statusCount = new_status_count - end - # @return [Boolean] whether the Pokémon is not fainted and not an egg def able? return !egg? && @hp > 0 @@ -824,7 +818,8 @@ class Pokemon # @param check_species [Integer, Symbol, String] id of the species to check for # @return [Boolean] whether this Pokémon is of the specified species def isSpecies?(check_species) - return @species == check_species || @species == GameData::Species.get(check_species).species + return @species == check_species || (GameData::Species.exists?(check_species) && + @species == GameData::Species.get(check_species).species) end def form diff --git a/Data/Scripts/016_Pokemon/002_Pokemon_Forms.rb b/Data/Scripts/016_Pokemon/002_Pokemon_Forms.rb index 94d4a48dd..18df899a6 100644 --- a/Data/Scripts/016_Pokemon/002_Pokemon_Forms.rb +++ b/Data/Scripts/016_Pokemon/002_Pokemon_Forms.rb @@ -582,8 +582,9 @@ MultipleForms.register(:NECROZMA,{ MultipleForms.register(:PIKACHU, { "getForm" => proc { |pkmn| next if pkmn.formSimple >= 2 - mapPos = GameData::MapMetadata.get($game_map.map_id).town_map_position - next 1 if mapPos && mapPos[0] == 1 # Tiall region + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + next 1 if map_metadata && map_metadata.town_map_position && + map_metadata.town_map_position[0] == 1 # Tiall region next 0 } }) diff --git a/Data/Scripts/011_Data/003_PBMove.rb b/Data/Scripts/016_Pokemon/003_PBMove.rb similarity index 100% rename from Data/Scripts/011_Data/003_PBMove.rb rename to Data/Scripts/016_Pokemon/003_PBMove.rb diff --git a/Data/Scripts/016_Pokemon/005_Pokemon_Evolution.rb b/Data/Scripts/016_Pokemon/005_Pokemon_Evolution.rb index 66ff4ea7f..e29d972c2 100644 --- a/Data/Scripts/016_Pokemon/005_Pokemon_Evolution.rb +++ b/Data/Scripts/016_Pokemon/005_Pokemon_Evolution.rb @@ -401,7 +401,8 @@ PBEvolution.register(:LevelDiving, { PBEvolution.register(:LevelDarkness, { "levelUpCheck" => proc { |pkmn, parameter| - next pkmn.level >= parameter && GameData::MapMetadata.get($game_map.map_id).dark_map + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + next pkmn.level >= parameter && map_metadata && map_metadata.dark_map } }) @@ -660,8 +661,9 @@ PBEvolution.register(:Location, { PBEvolution.register(:Region, { "minimumLevel" => 1, # Needs any level up "levelUpCheck" => proc { |pkmn, parameter| - mapPos = GameData::MapMetadata.get($game_map.map_id).town_map_position - next mapPos && mapPos[0] == parameter + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + next map_metadata && map_metadata.town_map_position && + map_metadata.town_map_position[0] == parameter } }) diff --git a/Data/Scripts/016_Pokemon/010_Pokemon_Deprecated.rb b/Data/Scripts/016_Pokemon/010_Pokemon_Deprecated.rb index 4aae98be1..129a2e36e 100644 --- a/Data/Scripts/016_Pokemon/010_Pokemon_Deprecated.rb +++ b/Data/Scripts/016_Pokemon/010_Pokemon_Deprecated.rb @@ -3,11 +3,85 @@ # These will be removed in a future Essentials version. #=============================================================================== -# @deprecated Use {Pokemon} instead. PokeBattle_Pokemon has been turned into an alias -# and is slated to be removed in v20. -class PokeBattle_Pokemon; end +# @deprecated Use {Pokemon} instead. PokeBattle_Pokemon is slated to be removed +# in v20. +class PokeBattle_Pokemon + attr_reader :name, :species, :form, :formTime, :forcedForm, :fused + attr_reader :personalID, :exp, :hp, :status, :statusCount + attr_reader :abilityflag, :genderflag, :natureflag, :natureOverride, :shinyflag + attr_reader :moves, :firstmoves + attr_reader :item, :mail + attr_reader :iv, :ivMaxed, :ev + attr_reader :happiness, :eggsteps, :pokerus + attr_reader :ballused, :markings, :ribbons + attr_reader :obtainMode, :obtainMap, :obtainText, :obtainLevel, :hatchedMap + attr_reader :timeReceived, :timeEggHatched + attr_reader :cool, :beauty, :cute, :smart, :tough, :sheen + attr_reader :trainerID, :ot, :otgender, :language + attr_reader :shadow, :heartgauge, :savedexp, :savedev, :hypermode + attr_reader :shadowmoves, :shadowmovenum -PokeBattle_Pokemon = Pokemon + def initialise + raise "PokeBattle_Pokemon.new is deprecated. Use Pokemon.new instead." + end + + def self.copy(pkmn) + owner = Pokemon::Owner.new(pkmn.trainerID, pkmn.ot, pkmn.otgender, pkmn.language) + ret = Pokemon.new(pkmn.species, pkmn.level, owner, false) + ret.name = pkmn.name + ret.exp = pkmn.exp + ret.formTime = pkmn.formTime + ret.forcedForm = pkmn.forcedForm + ret.hp = pkmn.hp + ret.abilityflag = pkmn.abilityflag + ret.genderflag = pkmn.genderflag + ret.natureflag = pkmn.natureflag + ret.natureOverride = pkmn.natureOverride + ret.shinyflag = pkmn.shinyflag + ret.item_id = pkmn.item + ret.mail = pkmn.mail + ret.moves = pkmn.moves + ret.firstmoves = pkmn.firstmoves.clone + ret.status = pkmn.status + ret.statusCount = pkmn.statusCount + ret.iv = pkmn.iv.clone + ret.ev = pkmn.ev.clone + ret.ivMaxed = pkmn.ivMaxed if pkmn.ivMaxed + ret.happiness = pkmn.happiness + ret.ballused = pkmn.ballused + ret.eggsteps = pkmn.eggsteps + ret.markings = pkmn.markings if pkmn.markings + ret.ribbons = pkmn.ribbons.clone + ret.pokerus = pkmn.pokerus + ret.personalID = pkmn.personalID + ret.obtainMode = pkmn.obtainMode + ret.obtainMap = pkmn.obtainMap + ret.obtainText = pkmn.obtainText + ret.obtainLevel = pkmn.obtainLevel if pkmn.obtainLevel + ret.hatchedMap = pkmn.hatchedMap + ret.timeReceived = pkmn.timeReceived + ret.timeEggHatched = pkmn.timeEggHatched + ret.cool = pkmn.cool if pkmn.cool + ret.beauty = pkmn.beauty if pkmn.beauty + ret.cute = pkmn.cute if pkmn.cute + ret.smart = pkmn.smart if pkmn.smart + ret.tough = pkmn.tough if pkmn.tough + ret.sheen = pkmn.sheen if pkmn.sheen + if pkmn.fused + ret.fused = PokeBattle_Pokemon.copy(pkmn.fused) if pkmn.fused.is_a?(PokeBattle_Pokemon) + ret.fused = pkmn.fused if pkmn.fused.is_a?(Pokemon) + end + ret.shadow = pkmn.shadow + ret.heartgauge = pkmn.heartgauge + ret.savedexp = pkmn.savedexp + ret.savedev = pkmn.savedev.clone + ret.hypermode = pkmn.hypermode + ret.shadowmoves = pkmn.shadowmoves.clone + ret.shadowmovenum = pkmn.shadowmovenum + # NOTE: Intentionally set last, as it recalculates stats. + ret.formSimple = pkmn.form + end +end class Pokemon # @deprecated Use {MAX_NAME_SIZE} instead. This alias is slated to be removed in v20. diff --git a/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb b/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb index f47566aab..16936164b 100644 --- a/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb +++ b/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb @@ -17,8 +17,9 @@ class PokemonPokedexInfo_Scene @sprites["infosprite"].x = 104 @sprites["infosprite"].y = 136 @mapdata = pbLoadTownMapData - mappos = ($game_map) ? GameData::MapMetadata.get($game_map.map_id).town_map_position : nil - if @region<0 # Use player's current region + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + mappos = (map_metadata) ? map_metadata.town_map_position : nil + if @region < 0 # Use player's current region @region = (mappos) ? mappos[0] : 0 # Region 0 default end @sprites["areamap"] = IconSprite.new(0,0,@viewport) @@ -300,31 +301,29 @@ class PokemonPokedexInfo_Scene encdata = pbLoadEncountersData for enc in encdata.keys enctypes = encdata[enc][1] - if pbFindEncounter(enctypes,@species) - mappos = GameData::MapMetadata.get(enc).town_map_position - if mappos && mappos[0]==@region - showpoint = true - for loc in @mapdata[@region][2] - showpoint = false if loc[0]==mappos[1] && loc[1]==mappos[2] && - loc[7] && !$game_switches[loc[7]] - end - if showpoint - mapsize = GameData::MapMetadata.get(enc).town_map_size - if mapsize && mapsize[0] && mapsize[0]>0 - sqwidth = mapsize[0] - sqheight = (mapsize[1].length*1.0/mapsize[0]).ceil - for i in 0...sqwidth - for j in 0...sqheight - if mapsize[1][i+j*sqwidth,1].to_i>0 - points[mappos[1]+i+(mappos[2]+j)*mapwidth] = true - end - end - end - else - points[mappos[1]+mappos[2]*mapwidth] = true + next if !pbFindEncounter(enctypes, @species) + map_metadata = GameData::MapMetadata.try_get(enc) + mappos = (map_metadata) ? map_metadata.town_map_position : nil + next if !mappos || mappos[0] != @region + showpoint = true + for loc in @mapdata[@region][2] + showpoint = false if loc[0]==mappos[1] && loc[1]==mappos[2] && + loc[7] && !$game_switches[loc[7]] + end + next if !showpoint + mapsize = map_metadata.town_map_size + if mapsize && mapsize[0] && mapsize[0]>0 + sqwidth = mapsize[0] + sqheight = (mapsize[1].length*1.0/mapsize[0]).ceil + for i in 0...sqwidth + for j in 0...sqheight + if mapsize[1][i+j*sqwidth,1].to_i>0 + points[mappos[1]+i+(mappos[2]+j)*mapwidth] = true end end end + else + points[mappos[1]+mappos[2]*mapwidth] = true end end # Draw coloured squares on each square of the region map with a nest diff --git a/Data/Scripts/017_UI/009_PScreen_RegionMap.rb b/Data/Scripts/017_UI/009_PScreen_RegionMap.rb index 863729532..d5b2b8b1c 100644 --- a/Data/Scripts/017_UI/009_PScreen_RegionMap.rb +++ b/Data/Scripts/017_UI/009_PScreen_RegionMap.rb @@ -81,7 +81,8 @@ class PokemonRegionMap_Scene @viewport.z = 99999 @sprites = {} @mapdata = pbLoadTownMapData - playerpos = (!$game_map) ? nil : GameData::MapMetadata.get($game_map.map_id).town_map_position + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + playerpos = (map_metadata) ? map_metadata.town_map_position : nil if !playerpos mapindex = 0 @map = @mapdata[0] @@ -97,7 +98,7 @@ class PokemonRegionMap_Scene @map = @mapdata[playerpos[0]] @mapX = playerpos[1] @mapY = playerpos[2] - mapsize = (!$game_map) ? nil : GameData::MapMetadata.get($game_map.map_id).town_map_size + mapsize = map_metadata.town_map_size if mapsize && mapsize[0] && mapsize[0]>0 sqwidth = mapsize[0] sqheight = (mapsize[1].length*1.0/mapsize[0]).ceil diff --git a/Data/Scripts/019_Other battles/001_PBattle_Safari.rb b/Data/Scripts/019_Other battles/001_PBattle_Safari.rb index 1dc19d316..4a22395ff 100644 --- a/Data/Scripts/019_Other battles/001_PBattle_Safari.rb +++ b/Data/Scripts/019_Other battles/001_PBattle_Safari.rb @@ -61,8 +61,9 @@ def pbInSafari? # Reception map is handled separately from safari map since the reception # map can be outdoors, with its own grassy patches. reception = pbSafariState.pbReceptionMap - return true if $game_map.map_id==reception - return true if GameData::MapMetadata.get($game_map.map_id).safari_map + return true if $game_map.map_id == reception + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + return true if map_metadata && map_metadata.safari_map end return false end diff --git a/Data/Scripts/020_System and utilities/003_PSystem_BattleAudioUtilities.rb b/Data/Scripts/020_System and utilities/003_PSystem_BattleAudioUtilities.rb index 7a899cd55..ed4ac91ad 100644 --- a/Data/Scripts/020_System and utilities/003_PSystem_BattleAudioUtilities.rb +++ b/Data/Scripts/020_System and utilities/003_PSystem_BattleAudioUtilities.rb @@ -8,8 +8,9 @@ def pbGetWildBattleBGM(_wildParty) # wildParty is an array of Pokémon objects ret = nil if !ret # Check map metadata - music = GameData::MapMetadata.get($game_map.map_id).wild_battle_BGM - ret = pbStringToAudioFile(music) if music && music!="" + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + music = (map_metadata) ? map_metadata.wild_battle_BGM : nil + ret = pbStringToAudioFile(music) if music && music != "" end if !ret # Check global metadata @@ -27,8 +28,9 @@ def pbGetWildVictoryME ret = nil if !ret # Check map metadata - music = GameData::MapMetadata.get($game_map.map_id).wild_victory_ME - ret = pbStringToAudioFile(music) if music && music!="" + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + music = (map_metadata) ? map_metadata.wild_victory_ME : nil + ret = pbStringToAudioFile(music) if music && music != "" end if !ret # Check global metadata @@ -47,8 +49,9 @@ def pbGetWildCaptureME ret = nil if !ret # Check map metadata - music = GameData::MapMetadata.get($game_map.map_id).wild_capture_ME - ret = pbStringToAudioFile(music) if music && music!="" + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + music = (map_metadata) ? map_metadata.wild_capture_ME : nil + ret = pbStringToAudioFile(music) if music && music != "" end if !ret # Check global metadata @@ -84,10 +87,9 @@ def pbGetTrainerBattleBGM(trainer) # can be a PokeBattle_Trainer or an array o ret = pbStringToAudioFile(music) if music && music!="" if !ret # Check map metadata - music = GameData::MapMetadata.get($game_map.map_id).trainer_battle_BGM - if music && music!="" - ret = pbStringToAudioFile(music) - end + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + music = (map_metadata) ? map_metadata.trainer_battle_BGM : nil + ret = pbStringToAudioFile(music) if music && music != "" end if !ret # Check global metadata @@ -108,8 +110,9 @@ def pbGetTrainerBattleBGMFromType(trainertype) ret = trainer_type_data.battle_BGM if trainer_type_data.battle_BGM if !ret # Check map metadata - music = GameData::MapMetadata.get($game_map.map_id).trainer_battle_BGM - ret = pbStringToAudioFile(music) if music && music!="" + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + music = (map_metadata) ? map_metadata.trainer_battle_BGM : nil + ret = pbStringToAudioFile(music) if music && music != "" end if !ret # Check global metadata @@ -136,10 +139,9 @@ def pbGetTrainerVictoryME(trainer) # can be a PokeBattle_Trainer or an array o end if !ret # Check map metadata - music = GameData::MapMetadata.get($game_map.map_id).trainer_victory_ME - if music && music!="" - ret = pbStringToAudioFile(music) - end + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + music = (map_metadata) ? map_metadata.trainer_victory_ME : nil + ret = pbStringToAudioFile(music) if music && music != "" end if !ret # Check global metadata diff --git a/Data/Scripts/020_System and utilities/004_PSystem_PokemonUtilities.rb b/Data/Scripts/020_System and utilities/004_PSystem_PokemonUtilities.rb index ea4e78fc8..6bf540de7 100644 --- a/Data/Scripts/020_System and utilities/004_PSystem_PokemonUtilities.rb +++ b/Data/Scripts/020_System and utilities/004_PSystem_PokemonUtilities.rb @@ -79,7 +79,7 @@ def pbAddPokemon(pkmn, level = 1, see_form = true) end def pbAddPokemonSilent(pkmn, level = 1, see_form = true) - return false if !pokemon || pbBoxesFull? + return false if !pkmn || pbBoxesFull? pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon) $Trainer.seen[pkmn.species] = true $Trainer.owned[pkmn.species] = true diff --git a/Data/Scripts/020_System and utilities/005_PSystem_Utilities.rb b/Data/Scripts/020_System and utilities/005_PSystem_Utilities.rb index 1ad39a7b4..aaaa754b6 100644 --- a/Data/Scripts/020_System and utilities/005_PSystem_Utilities.rb +++ b/Data/Scripts/020_System and utilities/005_PSystem_Utilities.rb @@ -392,7 +392,9 @@ end # Returns the ID number of the region containing the player's current location, # as determined by the current map's metadata. def pbGetCurrentRegion(default = -1) - map_pos = ($game_map) ? GameData::MapMetadata.get($game_map.map_id).town_map_position : nil + return default if !$game_map + map_metadata = GameData::MapMetadata.try_get($game_map.map_id) + map_pos = (map_metadata) ? map_metadata.town_map_position : nil return (map_pos) ? map_pos[0] : default end diff --git a/Data/Scripts/021_Debug/004_Editor_Screens.rb b/Data/Scripts/021_Debug/004_Editor_Screens.rb index 2fcba1c95..3304ef7a3 100644 --- a/Data/Scripts/021_Debug/004_Editor_Screens.rb +++ b/Data/Scripts/021_Debug/004_Editor_Screens.rb @@ -612,7 +612,8 @@ def pbEditMetadata(map_id = 0) properties = GameData::Metadata.editor_properties else # Map metadata map_name = mapinfos[map_id].name - metadata = GameData::MapMetadata.get(map_id) + metadata = GameData::MapMetadata.try_get(map_id) + metadata = GameData::Metadata.new({}) if !metadata properties = GameData::MapMetadata.editor_properties end properties.each do |property|