mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-10 06:34:59 +00:00
6.6 update
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PokemonEncounters
|
||||
WEATHER_ENCOUNTER_BASE_CHANCE = 8 #/100 (for weather intensity of 0)
|
||||
alias pokemonEssentials_PokemonEncounter_choose_wild_pokemon choose_wild_pokemon
|
||||
def choose_wild_pokemon(enc_type, *args)
|
||||
return pokemonEssentials_PokemonEncounter_choose_wild_pokemon(enc_type, *args) if !$game_weather
|
||||
current_weather_type = $game_weather.get_map_weather_type($game_map.map_id)
|
||||
current_weather_intensity = $game_weather.get_map_weather_intensity($game_map.map_id)
|
||||
if can_substitute_for_weather_encounter(enc_type, current_weather_type)
|
||||
#Chance to replace the chosen by one in from the weather pool
|
||||
if roll_for_weather_encounter(current_weather_intensity)
|
||||
weather_encounter_type = get_weather_encounter_type(enc_type,current_weather_type)
|
||||
echoln "weather encounter!"
|
||||
echoln weather_encounter_type
|
||||
return pokemonEssentials_PokemonEncounter_choose_wild_pokemon(weather_encounter_type) if(weather_encounter_type)
|
||||
end
|
||||
end
|
||||
return pokemonEssentials_PokemonEncounter_choose_wild_pokemon(enc_type, *args)
|
||||
end
|
||||
|
||||
|
||||
SUBSTITUTABLE_ENCOUNTER_TYPES = [:Land, :Land1, :Land2, :Land3, :Water]
|
||||
def can_substitute_for_weather_encounter(encounter_type,current_weather)
|
||||
return false if Settings::GAME_ID != :IF_HOENN
|
||||
return false if !SUBSTITUTABLE_ENCOUNTER_TYPES.include?(encounter_type)
|
||||
return false if current_weather.nil? || current_weather == :None
|
||||
return true
|
||||
end
|
||||
|
||||
def get_weather_encounter_type(normal_encounter_type, current_weather_type)
|
||||
base_encounter_type = normal_encounter_type == :Water ? :Water : :Land
|
||||
weather_encounter_type = "#{base_encounter_type}#{current_weather_type}".to_sym
|
||||
return weather_encounter_type if GameData::EncounterType.exists?(weather_encounter_type)
|
||||
return nil
|
||||
end
|
||||
def roll_for_weather_encounter(weather_intensity)
|
||||
weather_encounter_chance = (WEATHER_ENCOUNTER_BASE_CHANCE * weather_intensity)+WEATHER_ENCOUNTER_BASE_CHANCE
|
||||
return rand(100) < weather_encounter_chance
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,76 @@
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandRain,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10]
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandSunny,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandWind,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandFog,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandStorm,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :LandSnow,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterRain,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterSunny,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterWind,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterFog,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterStorm,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
GameData::EncounterType.register({
|
||||
:id => :WaterSnow,
|
||||
:type => :none,
|
||||
:old_slots => [30,30,10,15,5,10],
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
def update_neighbor_map
|
||||
@neighbors_maps = generate_neighbor_map_from_town_map
|
||||
@neighbors_maps = normalize_neighbors(@neighbors_maps)
|
||||
end
|
||||
|
||||
def normalize_neighbors(map)
|
||||
fixed_map = {}
|
||||
|
||||
map.each do |map_id, neighbors|
|
||||
neighbors.each do |neighbor_id|
|
||||
fixed_map[map_id] ||= []
|
||||
fixed_map[neighbor_id] ||= []
|
||||
fixed_map[map_id] |= [neighbor_id]
|
||||
fixed_map[neighbor_id] |= [map_id]
|
||||
end
|
||||
end
|
||||
|
||||
fixed_map
|
||||
end
|
||||
def generate_neighbor_map_from_town_map
|
||||
mapdata = pbLoadTownMapData
|
||||
neighbor_map = {}
|
||||
name_to_map_id = {}
|
||||
name_grid = {}
|
||||
|
||||
# First, build:
|
||||
# - a grid: [x, y] => location_name
|
||||
# - a lookup: location_name => map_id (if one exists)
|
||||
mapdata.each do |region|
|
||||
maps_array = region[2]
|
||||
maps_array.each do |entry|
|
||||
x, y, name, _showname, map_id = entry
|
||||
next unless name.is_a?(String) && !name.empty?
|
||||
|
||||
name_grid[[x, y]] = name
|
||||
if map_id.is_a?(Integer) #&& !is_indoor_map?(map_id)
|
||||
name_to_map_id[name] ||= map_id # Only keep the first valid one
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Now, check each tile against its neighbors (up/down/left/right)
|
||||
name_grid.each do |(x, y), name|
|
||||
[[0, -1], [0, 1], [-1, 0], [1, 0]].each do |dx, dy|
|
||||
neighbor_coords = [x + dx, y + dy]
|
||||
neighbor_name = name_grid[neighbor_coords]
|
||||
|
||||
map1 = name_to_map_id[name]
|
||||
map2 = name_to_map_id[neighbor_name]
|
||||
next unless map1 && map2
|
||||
next if map1 == map2 # Prevent self-linking
|
||||
|
||||
neighbor_map[map1] ||= []
|
||||
neighbor_map[map2] ||= []
|
||||
|
||||
neighbor_map[map1] << map2 unless neighbor_map[map1].include?(map2)
|
||||
neighbor_map[map2] << map1 unless neighbor_map[map2].include?(map1)
|
||||
end
|
||||
end
|
||||
return neighbor_map
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
def generate_neighbor_map_from_connections
|
||||
raw_connections = MapFactoryHelper.getMapConnections
|
||||
neighbor_map = {}
|
||||
|
||||
raw_connections.each_with_index do |conns, map_id|
|
||||
next if conns.nil? || conns.empty?
|
||||
|
||||
conns.each do |conn|
|
||||
next unless conn.is_a?(Array) && conn.length >= 4
|
||||
map1 = conn[0]
|
||||
map2 = conn[3]
|
||||
|
||||
next unless map1.is_a?(Integer) && map2.is_a?(Integer)
|
||||
#next if is_indoor_map?(map1) || is_indoor_map?(map2)
|
||||
|
||||
neighbor_map[map1] ||= []
|
||||
neighbor_map[map2] ||= []
|
||||
neighbor_map[map1] << map2 unless neighbor_map[map1].include?(map2)
|
||||
neighbor_map[map2] << map1 unless neighbor_map[map2].include?(map1)
|
||||
end
|
||||
end
|
||||
|
||||
return neighbor_map
|
||||
end
|
||||
|
||||
def is_indoor_map?(map_id)
|
||||
return false
|
||||
mapMetadata = GameData::MapMetadata.try_get(map_id)
|
||||
return true if !mapMetadata
|
||||
return !mapMetadata.outdoor_map
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
Events.onMapChange+= proc { |_old_map_id|
|
||||
next if !$game_weather || !$game_weather.current_weather || !$game_weather.last_update_time
|
||||
next if !$game_map
|
||||
echoln pbGetTimeNow.to_i
|
||||
update_overworld_weather($game_map.map_id)
|
||||
next if $game_weather.last_update_time.to_i + GameWeather::TIME_BETWEEN_WEATHER_UPDATES > pbGetTimeNow.to_i
|
||||
|
||||
new_map_id = $game_map.map_id
|
||||
mapMetadata = GameData::MapMetadata.try_get(new_map_id)
|
||||
next if mapMetadata.nil?
|
||||
$game_screen.weather(:None,0,0) if !mapMetadata.outdoor_map
|
||||
next unless mapMetadata.outdoor_map
|
||||
$game_weather.update_weather
|
||||
}
|
||||
|
||||
def update_overworld_weather(current_map)
|
||||
return if current_map.nil?
|
||||
return if !$game_weather.current_weather
|
||||
current_weather_array = $game_weather.current_weather[current_map]
|
||||
return if current_weather_array.nil?
|
||||
current_weather_type = current_weather_array[0]
|
||||
current_weather_intensity = current_weather_array[1]
|
||||
current_weather_type = :None if !current_weather_type
|
||||
current_weather_intensity=0 if !current_weather_intensity
|
||||
current_weather_type = :None if PBDayNight.isNight? && current_weather_type == :Sunny
|
||||
$game_screen.weather(current_weather_type,current_weather_intensity,0)
|
||||
end
|
||||
@@ -0,0 +1,131 @@
|
||||
class BetterRegionMap
|
||||
DEBUG_WEATHER = true
|
||||
def update_weather_icon(location)
|
||||
return
|
||||
return nil if !location
|
||||
map_id = location[4]
|
||||
return nil if !map_id
|
||||
|
||||
weather_at_location = $game_weather.current_weather[map_id]
|
||||
return nil if weather_at_location.nil?
|
||||
|
||||
weather_type = weather_at_location[0]
|
||||
weather_intensity = weather_at_location[1]
|
||||
|
||||
icon = get_weather_icon(weather_type,weather_intensity)
|
||||
return nil if icon.nil?
|
||||
icon_path = "Graphics/Pictures/Weather/Cursor/" + icon
|
||||
|
||||
# @sprites["weather"].visible=true
|
||||
@sprites["cursor"].bmp(icon_path)
|
||||
@sprites["cursor"].src_rect.width = @sprites["cursor"].bmp.height
|
||||
return weather_type
|
||||
|
||||
end
|
||||
|
||||
|
||||
def draw_all_weather
|
||||
processed_locations =[]
|
||||
n=0
|
||||
for x in 0...(@window["map"].bmp.width / TileWidth)
|
||||
for y in 0...(@window["map"].bmp.height / TileHeight)
|
||||
|
||||
for location in @data[2]
|
||||
if location[0] == x && location[1] == y
|
||||
|
||||
map_id = location[4]
|
||||
|
||||
next if !map_id
|
||||
next if processed_locations.include?(map_id)
|
||||
|
||||
weather_at_location = $game_weather.current_weather[map_id]
|
||||
next if weather_at_location.nil?
|
||||
|
||||
weather_type = weather_at_location[0]
|
||||
weather_intensity = weather_at_location[1]
|
||||
|
||||
weather_icon = get_full_weather_icon_name(weather_type,weather_intensity)
|
||||
next if weather_icon.nil?
|
||||
weather_icon_path = "Graphics/Pictures/Weather/" + weather_icon
|
||||
@weatherIcons["weather#{n}"] = Sprite.new(@mapvp)
|
||||
@weatherIcons["weather#{n}"].bmp(weather_icon_path)
|
||||
@weatherIcons["weather#{n}"].src_rect.width = @weatherIcons["weather#{n}"].bmp.height
|
||||
@weatherIcons["weather#{n}"].x = TileWidth * x + (TileWidth / 2)
|
||||
@weatherIcons["weather#{n}"].y = TileHeight * y + (TileHeight / 2)
|
||||
@weatherIcons["weather#{n}"].oy = @weatherIcons["weather#{n}"].bmp.height / 2.0
|
||||
@weatherIcons["weather#{n}"].ox = @weatherIcons["weather#{n}"].oy
|
||||
|
||||
processed_locations << map_id
|
||||
n= n+1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def new_weather_cycle
|
||||
return if !$game_weather
|
||||
@weatherIcons.dispose
|
||||
@weatherIcons = SpriteHash.new
|
||||
$game_weather.update_weather
|
||||
draw_all_weather
|
||||
end
|
||||
|
||||
end
|
||||
def get_current_map_weather_icon
|
||||
return if !$game_weather
|
||||
current_weather= $game_weather.current_weather[$game_map.map_id]
|
||||
weather_type = current_weather[0]
|
||||
weather_intensity = current_weather[1]
|
||||
icon = get_full_weather_icon_name(weather_type,weather_intensity)
|
||||
return "Graphics/Pictures/Weather/" +icon if icon
|
||||
return nil
|
||||
end
|
||||
|
||||
def get_weather_icon(weather_type,intensity)
|
||||
case weather_type
|
||||
when :Sunny #&& !PBDayNight.isNight?
|
||||
icon_name = "mapSun"
|
||||
when :Rain
|
||||
icon_name = "mapRain"
|
||||
when :Fog
|
||||
icon_name = "mapFog"
|
||||
when :Wind
|
||||
icon_name = "mapWind"
|
||||
when :Storm
|
||||
icon_name = "mapStorm"
|
||||
when :Sandstorm
|
||||
icon_name = "mapSand"
|
||||
when :Snow
|
||||
icon_name = "mapSnow"
|
||||
when :HeavyRain
|
||||
icon_name = "mapHeavyRain"
|
||||
when :StrongWinds
|
||||
icon_name = "mapStrongWinds"
|
||||
when :HarshSun
|
||||
icon_name = "mapHarshSun"
|
||||
else
|
||||
icon_name = nil
|
||||
end
|
||||
return icon_name
|
||||
end
|
||||
def get_full_weather_icon_name(weather_type,intensity)
|
||||
return nil if !weather_type
|
||||
return nil if !intensity
|
||||
same_intensity_weather_types = [:Sandstorm,:Snow,:StrongWinds,:HeavyRain,:HarshSun]
|
||||
|
||||
base_weather_icon_name = get_weather_icon(weather_type,intensity)
|
||||
icon_name = base_weather_icon_name
|
||||
return nil if !icon_name
|
||||
return icon_name if same_intensity_weather_types.include?(weather_type)
|
||||
if intensity <= 2
|
||||
icon_name += "_light"
|
||||
elsif intensity <=4
|
||||
icon_name += "_medium"
|
||||
else
|
||||
icon_name += "_heavy"
|
||||
end
|
||||
return icon_name
|
||||
end
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
|
||||
def isRaining?()
|
||||
return isWeatherRain? || isWeatherStorm?
|
||||
end
|
||||
|
||||
def isWeatherRain?()
|
||||
return $game_weather.get_map_weather_type($game_map.map_id) == :Rain || $game_weather.get_map_weather_type($game_map.map_id) == :HeavyRain
|
||||
end
|
||||
|
||||
def isWeatherSunny?()
|
||||
return $game_weather.get_map_weather_type($game_map.map_id) == :Sunny || $game_weather.get_map_weather_type($game_map.map_id) == :HarshSun
|
||||
end
|
||||
|
||||
def isWeatherStorm?()
|
||||
return $game_weather.get_map_weather_type($game_map.map_id) == :Storm
|
||||
end
|
||||
|
||||
def isWeatherWind?()
|
||||
return $game_weather.get_map_weather_type($game_map.map_id) == :Wind || $game_weather.get_map_weather_type($game_map.map_id) == :StrongWinds
|
||||
end
|
||||
|
||||
def isWeatherFog?()
|
||||
return $game_weather.get_map_weather_type($game_map.map_id) == :Fog
|
||||
end
|
||||
|
||||
def isWeatherSnow?()
|
||||
return $game_weather.get_map_weather_type($game_map.map_id) == :Fog
|
||||
end
|
||||
|
||||
|
||||
def changeCurrentWeather(weatherType,intensity)
|
||||
new_map_id = $game_map.map_id
|
||||
mapMetadata = GameData::MapMetadata.try_get(new_map_id)
|
||||
return nil if mapMetadata.nil?
|
||||
return nil if !mapMetadata.outdoor_map
|
||||
if $game_weather
|
||||
$game_weather.set_map_weather($game_map.map_id,weatherType,intensity)
|
||||
$game_weather.update_overworld_weather($game_map.map_id)
|
||||
else
|
||||
$game_screen.weather(weatherType,intensity,5)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,376 @@
|
||||
# Dynamic weather system by Chardub, for Pokemon Infinite Fusion
|
||||
|
||||
if Settings::GAME_ID == :IF_HOENN
|
||||
SaveData.register(:weather) do
|
||||
ensure_class :GameWeather
|
||||
save_value { $game_weather }
|
||||
load_value { |value|
|
||||
if value.is_a?(GameWeather)
|
||||
$game_weather = value
|
||||
else
|
||||
$game_weather = GameWeather.new
|
||||
end
|
||||
$game_weather.update_neighbor_map # reupdate the neighbors map to account for new maps added
|
||||
|
||||
$game_weather.initialize_weather unless $game_weather.current_weather
|
||||
}
|
||||
new_game_value { GameWeather.new }
|
||||
end
|
||||
end
|
||||
class GameWeather
|
||||
attr_accessor :current_weather
|
||||
attr_accessor :last_update_time
|
||||
|
||||
TIME_BETWEEN_WEATHER_UPDATES = 12000 # 180 seconds, only actually changes once the player changes map
|
||||
|
||||
CHANCE_OF_NEW_WEATHER = 2 # /100 spontaneous new weather popping up somewhere
|
||||
CHANCE_OF_RAIN = 40 #/100
|
||||
CHANCE_OF_SUNNY = 30 #/100
|
||||
CHANCE_OF_WINDY = 30 #/100
|
||||
CHANCE_OF_FOG = 30 #/100 Only possible in the morning, otherwise, when rain and sun combine
|
||||
|
||||
MAX_INTENSITY_ON_NEW_WEATHER = 4
|
||||
|
||||
|
||||
CHANCES_OF_INTENSITY_INCREASE = 30 # /100
|
||||
CHANCES_OF_INTENSITY_DECREASE = 20 # /100
|
||||
BASE_CHANCE_OF_WEATHER_SPREAD = 15
|
||||
BASE_CHANCES_OF_WEATHER_END = 10 #/100 - For a weather intensity of 10. Chances should increase the lower the intensity is
|
||||
BASE_CHANCES_OF_WEATHER_MOVE = 10
|
||||
DEBUG_PROPAGATION = false
|
||||
|
||||
COLD_MAPS = [444] # Rain is snow on that map (shoal cave)
|
||||
SNOW_LIMITS = [965,951] # Route 121, Pacifidlog - Snow turns to rain if it reaches these maps
|
||||
|
||||
|
||||
SANDSTORM_MAPS = [555] # Always sandstorm, doesn't spread
|
||||
SOOT_MAPS = [] # Always soot, doesn't spread
|
||||
NO_WIND_MAPS = [989] # Sootopolis, Petalburg Forest
|
||||
|
||||
def set_weather(map_id, weather_type, intensity)
|
||||
@current_weather[map_id] = [weather_type, intensity]
|
||||
update_overworld_weather($game_map.map_id)
|
||||
end
|
||||
|
||||
def map_current_weather_type(map_id)
|
||||
map_weather = @current_weather[map_id]
|
||||
return map_weather[0] if map_weather
|
||||
end
|
||||
|
||||
def initialize
|
||||
@last_update_time = pbGetTimeNow
|
||||
echoln @last_update_time
|
||||
# Similar to roaming legendaries: A hash of all the maps accessible from one map
|
||||
@neighbors_maps = generate_neighbor_map_from_town_map
|
||||
initialize_weather
|
||||
end
|
||||
|
||||
def initialize_weather
|
||||
weather = {}
|
||||
@neighbors_maps.keys.each { |map_id|
|
||||
weather[map_id] = select_new_weather_spawn
|
||||
}
|
||||
@current_weather = weather
|
||||
end
|
||||
|
||||
def set_map_weather(map_id,weather_type,intensity)
|
||||
@current_weather[map_id] = [weather_type,intensity]
|
||||
end
|
||||
|
||||
def get_map_weather_type(map_id)
|
||||
if !@current_weather[map_id]
|
||||
@current_weather[map_id] = [:None,0]
|
||||
end
|
||||
return @current_weather[map_id][0]
|
||||
end
|
||||
|
||||
def get_map_weather_intensity(map_id)
|
||||
if !@current_weather[map_id]
|
||||
@current_weather[map_id] = [:None,0]
|
||||
end
|
||||
return @current_weather[map_id][1]
|
||||
end
|
||||
|
||||
#Legendary weather conditions can't dissapear, so they're treated as their full force counterpart for spreading
|
||||
def normalize_legendary_weather(type, intensity)
|
||||
case type
|
||||
when :HarshSun then [:Sunny, 10]
|
||||
when :HeavyRain then [:Rain, 10]
|
||||
when :StrongWinds then [:Wind, 10]
|
||||
else [type, intensity]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
def update_weather()
|
||||
return if !$game_weather
|
||||
new_weather = @current_weather.dup
|
||||
new_weather.each do |map_id, (type, intensity)|
|
||||
try_end_weather(map_id,type, get_map_weather_intensity(map_id))
|
||||
try_spawn_new_weather(map_id,type, intensity)
|
||||
try_propagate_weather_to_neighbors(map_id,type, intensity)
|
||||
echoln @current_weather[954] if @debug_you
|
||||
try_move_weather_to_neighbors(map_id,type, intensity)
|
||||
try_weather_intensity_decrease(map_id,type, intensity)
|
||||
try_weather_intensity_increase(map_id,type, intensity)
|
||||
end
|
||||
update_overworld_weather($game_map.map_id)
|
||||
@last_update_time = pbGetTimeNow
|
||||
end
|
||||
|
||||
def try_propagate_weather_to_neighbors(map_id,propagating_map_weather_type,propagating_map_weather_intensity)
|
||||
propagating_map_neighbors = @neighbors_maps[map_id]
|
||||
|
||||
return if propagating_map_weather_type == :None
|
||||
return unless can_weather_spread(propagating_map_weather_type)
|
||||
propagating_map_weather_type, propagating_map_weather_intensity = normalize_legendary_weather(propagating_map_weather_type, propagating_map_weather_intensity)
|
||||
propagating_map_neighbors.each do |neighbor_id|
|
||||
neighbor_weather_type = get_map_weather_type(neighbor_id)
|
||||
neighbor_weather_intensity = get_map_weather_intensity(neighbor_id)
|
||||
should_propagate = roll_for_weather_propagation(propagating_map_weather_type, propagating_map_weather_intensity, neighbor_weather_type, neighbor_weather_intensity)
|
||||
next if !should_propagate
|
||||
propagated_weather_type = resolve_weather_interaction(propagating_map_weather_type, neighbor_weather_type, propagating_map_weather_intensity, neighbor_weather_intensity)
|
||||
propagated_weather_intensity = [propagating_map_weather_intensity - 1, 1].max
|
||||
new_weather = get_updated_weather(propagated_weather_type, propagated_weather_intensity, neighbor_id)
|
||||
@current_weather[neighbor_id] = new_weather
|
||||
end
|
||||
end
|
||||
|
||||
def try_spawn_new_weather(map_id,map_weather_type,weather_intensity)
|
||||
return if map_weather_type != :None
|
||||
new_weather = select_new_weather_spawn
|
||||
@current_weather[map_id] = adjust_weather_for_map(new_weather,map_id)
|
||||
end
|
||||
|
||||
|
||||
def try_move_weather_to_neighbors(map_id,map_weather_type,weather_intensity)
|
||||
map_neighbors = @neighbors_maps[map_id]
|
||||
return if map_weather_type == :None || weather_intensity <= 1
|
||||
return unless can_weather_spread(map_weather_type)
|
||||
map_weather_type, weather_intensity = normalize_legendary_weather(map_weather_type, weather_intensity)
|
||||
|
||||
map_neighbors.each do |neighbor_id|
|
||||
neighbor_weather_type = get_map_weather_type(neighbor_id)
|
||||
neighbor_weather_intensity = get_map_weather_intensity(neighbor_id)
|
||||
|
||||
should_move_weather = roll_for_weather_move(map_weather_type)
|
||||
next if !should_move_weather
|
||||
next if neighbor_weather_type == map_weather_type && neighbor_weather_intensity >= weather_intensity
|
||||
result_weather_type = resolve_weather_interaction(map_weather_type, neighbor_weather_type, weather_intensity, neighbor_weather_intensity)
|
||||
result_weather_intensity = weather_intensity
|
||||
new_weather = [result_weather_type,result_weather_intensity]
|
||||
@current_weather[neighbor_id] = adjust_weather_for_map(new_weather,map_id)
|
||||
end
|
||||
end
|
||||
|
||||
def try_weather_intensity_decrease(map_id,map_weather_type,weather_intensity)
|
||||
return unless can_weather_decrease(map_weather_type)
|
||||
should_change_intensity = roll_for_weather_decrease(map_weather_type)
|
||||
return if !should_change_intensity
|
||||
new_weather = [map_weather_type,weather_intensity-1]
|
||||
@current_weather[map_id] = adjust_weather_for_map(new_weather,map_id)
|
||||
end
|
||||
|
||||
def try_weather_intensity_increase(map_id,map_weather_type,weather_intensity)
|
||||
return unless can_weather_increase(map_weather_type)
|
||||
should_change_intensity = roll_for_weather_increase(map_weather_type)
|
||||
return if !should_change_intensity
|
||||
new_weather = [map_weather_type,weather_intensity+1]
|
||||
@current_weather[map_id] = adjust_weather_for_map(new_weather,map_id)
|
||||
end
|
||||
|
||||
def try_end_weather(map_id,map_weather_type,weather_intensity)
|
||||
return unless can_weather_end(map_weather_type)
|
||||
|
||||
should_weather_end = roll_for_weather_end(map_weather_type,weather_intensity)
|
||||
return if !should_weather_end
|
||||
if weather_intensity >1
|
||||
map_weather_type = :Rain if map_weather_type == :Storm
|
||||
new_weather = [map_weather_type,0]
|
||||
else
|
||||
new_weather = [:None,0]
|
||||
end
|
||||
@current_weather[map_id] = adjust_weather_for_map(new_weather,map_id)
|
||||
end
|
||||
|
||||
|
||||
def adjust_weather_for_map(map_current_weather,map_id)
|
||||
type = map_current_weather[0]
|
||||
intensity = map_current_weather[1]
|
||||
return get_updated_weather(type,intensity,map_id)
|
||||
end
|
||||
|
||||
def get_updated_weather(type, intensity, map_id)
|
||||
if COLD_MAPS.include?(map_id)
|
||||
type = :Snow if type == :Rain
|
||||
type = :Blizzard if type == :Storm
|
||||
type = :None if type == :Sunny
|
||||
end
|
||||
if SNOW_LIMITS.include?(map_id)
|
||||
type = :Rain if type == :Snow
|
||||
end
|
||||
|
||||
|
||||
if SOOT_MAPS.include?(map_id)
|
||||
type = :SootRain if type == :Rain
|
||||
end
|
||||
if NO_WIND_MAPS.include?(map_id)
|
||||
type = :None if type == :Wind
|
||||
end
|
||||
if SANDSTORM_MAPS.include?(map_id)
|
||||
type = :Sandstorm
|
||||
intensity = 9
|
||||
end
|
||||
if (PBDayNight.isNight? || PBDayNight.isEvening?) && type == :Sunny
|
||||
type = :None
|
||||
intensity = 0
|
||||
end
|
||||
return [type, intensity]
|
||||
end
|
||||
|
||||
def get_map_name(map_id)
|
||||
mapinfos = pbLoadMapInfos
|
||||
if mapinfos[map_id]
|
||||
neighbor_map_name = mapinfos[map_id].name
|
||||
else
|
||||
neighbor_map_name = "Map #{map_id}"
|
||||
end
|
||||
return neighbor_map_name
|
||||
end
|
||||
|
||||
def resolve_weather_interaction(incoming, existing, incoming_intensity, existing_intensity)
|
||||
return existing unless can_weather_end(existing)
|
||||
return incoming if existing == :None
|
||||
return :Fog if incoming == :Rain && existing == :Sunny
|
||||
return :Fog if incoming == :Sunny && existing == :Rain
|
||||
|
||||
if incoming == :Rain && existing == :Wind
|
||||
return :Storm if incoming_intensity >= 5 || existing_intensity >= 5
|
||||
end
|
||||
return incoming
|
||||
end
|
||||
|
||||
def print_current_weather()
|
||||
mapinfos = pbLoadMapInfos
|
||||
echoln "Current weather :"
|
||||
@current_weather.each do |map_id, value|
|
||||
game_map = mapinfos[map_id]
|
||||
if game_map
|
||||
map_name = mapinfos[map_id].name
|
||||
else
|
||||
map_name = map_id
|
||||
end
|
||||
echoln " #{map_name} : #{value}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def can_weather_spread(type)
|
||||
return false if type == :Sandstorm
|
||||
return true
|
||||
end
|
||||
|
||||
def can_weather_move(type)
|
||||
return false if type == :Sandstorm
|
||||
return false if type == :HeavyRain
|
||||
return false if type == :HarshSun
|
||||
return false if type == :StrongWinds
|
||||
return true
|
||||
end
|
||||
|
||||
def can_weather_end(type)
|
||||
return false if type == :Sandstorm
|
||||
return false if type == :HeavyRain
|
||||
return false if type == :HarshSun
|
||||
return false if type == :StrongWinds
|
||||
# Sandstorm and special weathers for kyogre/groudon/rayquaza
|
||||
return true
|
||||
end
|
||||
|
||||
def can_weather_decrease(type)
|
||||
return false if type == :Sandstorm
|
||||
return false if type == :HeavyRain
|
||||
return false if type == :HarshSun
|
||||
return false if type == :StrongWinds
|
||||
# Sandstorm and special weathers for kyogre/groudon/rayquaza
|
||||
return true
|
||||
end
|
||||
|
||||
def can_weather_increase(type)
|
||||
return false if type == :Sandstorm
|
||||
return false if type == :HeavyRain
|
||||
return false if type == :HarshSun
|
||||
return false if type == :StrongWinds
|
||||
# Sandstorm and special weathers for kyogre/groudon/rayquaza
|
||||
return true
|
||||
end
|
||||
|
||||
def roll_for_weather_propagation(propagating_map_weather_type, propagating_map_weather_intensity, destination_map_weather_type, destination_map_weather_intensity)
|
||||
if propagating_map_weather_type == destination_map_weather_type
|
||||
# same weather, use highest intensity
|
||||
intensity_diff = [propagating_map_weather_intensity,destination_map_weather_intensity].max
|
||||
propagation_chance = (intensity_diff * BASE_CHANCE_OF_WEATHER_SPREAD)
|
||||
else
|
||||
intensity_diff = propagating_map_weather_intensity - destination_map_weather_intensity
|
||||
if intensity_diff > 0
|
||||
propagation_chance = (intensity_diff * BASE_CHANCE_OF_WEATHER_SPREAD)
|
||||
else
|
||||
return false# Other map's weather is stronger
|
||||
end
|
||||
end
|
||||
return rand(100) < propagation_chance
|
||||
end
|
||||
|
||||
def roll_for_weather_end(type, current_intensity)
|
||||
return false if !can_weather_end(type)
|
||||
chances = BASE_CHANCES_OF_WEATHER_END
|
||||
chances += (10 - current_intensity) * 5
|
||||
return rand(100) <= chances
|
||||
end
|
||||
|
||||
def roll_for_weather_move(type)
|
||||
return false if !can_weather_spread(type)
|
||||
return rand(100) <= BASE_CHANCES_OF_WEATHER_MOVE
|
||||
end
|
||||
|
||||
def roll_for_weather_increase(type)
|
||||
return false if !can_weather_decrease(type)
|
||||
return rand(100) <= CHANCES_OF_INTENSITY_INCREASE
|
||||
end
|
||||
|
||||
def roll_for_weather_decrease(type)
|
||||
return false if !can_weather_decrease(type)
|
||||
return rand(100) <= CHANCES_OF_INTENSITY_DECREASE
|
||||
end
|
||||
|
||||
def select_new_weather_spawn
|
||||
return [:None, 0] if rand(100) >= CHANCE_OF_NEW_WEATHER
|
||||
|
||||
base_intensity = rand(MAX_INTENSITY_ON_NEW_WEATHER) + 1
|
||||
|
||||
weights = []
|
||||
weights << [:Rain, CHANCE_OF_RAIN]
|
||||
weights << [:Sunny, CHANCE_OF_SUNNY]
|
||||
weights << [:Wind, CHANCE_OF_WINDY]
|
||||
weights << [:Fog, CHANCE_OF_FOG] if PBDayNight.isMorning?
|
||||
|
||||
total = weights.sum { |w| w[1] }
|
||||
roll = rand(total)
|
||||
|
||||
sum = 0
|
||||
weights.each do |type, chance|
|
||||
sum += chance
|
||||
if roll < sum
|
||||
intensity = (type == :Fog) ? base_intensity + 2 : base_intensity
|
||||
return [type, intensity]
|
||||
end
|
||||
end
|
||||
|
||||
return [:None, 0] # Fallback
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user