Fixed code assuming map metadata exists, fixed misplaced species data methods, rewrote class PokeBattle_Pokemon

This commit is contained in:
Maruno17
2021-01-20 20:22:31 +00:00
parent 7f254c6434
commit 736bb9ed10
24 changed files with 283 additions and 198 deletions

View File

@@ -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)<weather[1]
else
oldweather = GameData::MapMetadata.get(oldid).weather
$game_screen.weather(weather[0],8,20) if weather && !oldweather && rand(100)<weather[1]
end
next if old_map_ID == 0 || old_map_ID == $game_map.map_id
next if !new_map_metadata || !new_map_metadata.weather
map_infos = load_data("Data/MapInfos.rxdata")
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
end
new_weather = new_map_metadata.weather
$game_screen.weather(new_weather[0], 8, 20) if rand(100) < new_weather[1]
}
Events.onMapSceneChange += proc { |_sender,e|
Events.onMapSceneChange += proc { |_sender, e|
scene = e[0]
mapChanged = e[1]
next if !scene || !scene.spriteset
# Update map trail
if $game_map
$PokemonGlobal.mapTrail = [] if !$PokemonGlobal.mapTrail
if $PokemonGlobal.mapTrail[0]!=$game_map.map_id
$PokemonGlobal.mapTrail[3] = $PokemonGlobal.mapTrail[2] if $PokemonGlobal.mapTrail[2]
$PokemonGlobal.mapTrail[2] = $PokemonGlobal.mapTrail[1] if $PokemonGlobal.mapTrail[1]
$PokemonGlobal.mapTrail[1] = $PokemonGlobal.mapTrail[0] if $PokemonGlobal.mapTrail[0]
if $PokemonGlobal.mapTrail[0] != $game_map.map_id
$PokemonGlobal.mapTrail.pop if $PokemonGlobal.mapTrail.length >= 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

View File

@@ -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 = ""

View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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