Update 6.8

This commit is contained in:
chardub
2026-07-10 15:42:06 -04:00
parent 5b85e72cb2
commit 6a6f126a18
7871 changed files with 493194 additions and 224826 deletions
+65 -88
View File
@@ -1,5 +1,5 @@
# frozen_string_literal: true
SURF_SPLASH_ANIMATION_ID = 30
SURF_SPLASH_ANIMATION_ID = 31
class Game_Temp
attr_accessor :surf_patches
@@ -9,8 +9,8 @@ class Game_Temp
end
def clearSurfSplashPatches
return unless $game_temp.surf_patches
$game_temp.surf_patches.clear
return unless @surf_patches
@surf_patches.clear
end
end
@@ -21,21 +21,20 @@ class Spriteset_Map
return unless $scene.is_a?(Scene_Map)
return unless Settings::GAME_ID == :IF_HOENN
return unless $PokemonGlobal.surfing
return if Graphics.frame_count % 32 != 0
return if Graphics.frame_count % 60 != 0
animate_surf_water_splashes
end
end
class SurfPatch
MAX_NUMBER_SURF_SPLASHES = 6
MAX_NUMBER_SURF_SPLASHES = 4
attr_accessor :shape #Array of tiles coordinates (ex: [[10,20],[1,5]])
attr_accessor :shape
def initialize(patch_size)
x, y = getRandomPositionOnPerimeter(8, 6, $game_player.x, $game_player.y, 2)
variance = rand(5..8)
@shape =getRandomSplashPatch(patch_size,x,y,variance)
@shape = getRandomSplashPatch(patch_size, x, y, variance)
end
def getRandomSplashPatch(tile_count, center_x, center_y, variance = rand(4))
@@ -43,24 +42,33 @@ class SurfPatch
center_pos = getRandomPositionOnPerimeter(tile_count, tile_count, center_x, center_y, variance)
area = [center_pos]
visited = { center_pos => true }
visited = {} # Use hash with key format "x,y" for O(1) lookups
visited["#{center_pos[0]},#{center_pos[1]}"] = true
queue = [center_pos]
# Pre-shuffle directions once
directions = [[1, 0], [-1, 0], [0, 1], [0, -1],
[1, 1], [-1, -1], [1, -1], [-1, 1]] # 8 directions
[1, 1], [-1, -1], [1, -1], [-1, 1]].shuffle
map_id = $game_map.map_id # Cache map_id
while area.length < tile_count && !queue.empty?
current = queue.sample
queue.delete(current)
cx, cy = current
# Randomize how many directions to try (1 to 4)
directions.shuffle.take(rand(1..4)).each do |dx, dy|
directions.take(rand(1..4)).each do |dx, dy|
nx, ny = cx + dx, cy + dy
new_pos = [nx, ny]
next if visited[new_pos]
key = "#{nx},#{ny}"
next if visited[key]
visited[new_pos] = true
# Check terrain validity immediately before adding
terrain = $MapFactory.getTerrainTag(map_id, nx, ny, false)
next unless terrain&.can_surf
next unless $game_map.playerPassable?(nx, ny, 2)
visited[key] = true
new_pos = [nx, ny]
area << new_pos
queue << new_pos
@@ -68,98 +76,67 @@ class SurfPatch
end
end
# Filter to keep only water tiles
map_id = $game_map.map_id
area.select! do |pos|
x, y = pos
terrain = $MapFactory.getTerrainTag(map_id, x, y, false)
next false unless terrain&.can_surf # Only water/surfable tiles
$game_map.playerPassable?(x, y, 2) # Direction 2 (down) or any direction for checking passability
end
return area
area
end
end
def animate_surf_water_splashes
animation_frequency = 16 #in frames
return unless $game_temp.surf_patches
return unless Graphics.frame_count % animation_frequency == 0
$game_temp.surf_patches.each do |patch|
next if patch.nil? || patch.shape.empty?
patch.shape.each do |splash_tile|
x_position= splash_tile[0]
y_position = splash_tile[1]
$scene.spriteset.addUserAnimation(SURF_SPLASH_ANIMATION_ID, x_position, y_position, true, 0)
patch.shape.each do |x_pos, y_pos|
$scene.spriteset.addUserAnimation(SURF_SPLASH_ANIMATION_ID, x_pos, y_pos, true, -1)
end
end
end
def try_spawn_surf_water_splashes
water_splash_chance = 0.1 #Chance each step 10%
steps_interval = 5 # Only check once every 5 steps
return if $PokemonGlobal.stepcount % steps_interval != 0
return unless rand < water_splash_chance
return if $PokemonGlobal.stepcount % 5 != 0
return unless rand < 0.1
spawnSurfSplashPatch
end
Events.onStepTaken += proc { |sender, e|
water_encounter_chance = 25
next unless $scene.is_a?(Scene_Map)
next unless Settings::GAME_ID == :IF_HOENN
next unless $PokemonGlobal.surfing
player_x = $game_player.x
player_y = $game_player.y
if $game_temp.surf_patches
$game_temp.surf_patches.each_with_index do |patch,index|
next unless patch && patch.shape
if patch.shape.include?([player_x, player_y])
next if rand(100) > water_encounter_chance
$game_temp.surf_patches.delete_at(index)
echoln "surf patch encounter!"
wild_pokemon = $PokemonEncounters.choose_wild_pokemon(:Water)
if wild_pokemon
species = wild_pokemon[0]
level = wild_pokemon[1]
pbWildBattle(species, level)
break
else
pbItemBall(:OLDBOOT)
end
end
end
end
try_spawn_surf_water_splashes
}
# Events.onStepTaken += proc { |sender, e|
# next unless $scene.is_a?(Scene_Map)
# next unless Settings::GAME_ID == :IF_HOENN
# next unless $PokemonGlobal.surfing
#
# player_pos = [$game_player.x, $game_player.y] # Cache player position
#
# if $game_temp.surf_patches
# # Use reverse_each to safely delete while iterating
# $game_temp.surf_patches.reverse_each.with_index do |patch, reverse_idx|
# next unless patch && patch.shape
#
# if patch.shape.include?(player_pos)
# next if rand(100) > 25
#
# # Calculate actual index for deletion
# actual_idx = $game_temp.surf_patches.length - 1 - reverse_idx
# $game_temp.surf_patches.delete_at(actual_idx)
#
# echoln "surf patch encounter!"
# wild_pokemon = $PokemonEncounters.choose_wild_pokemon(:Water)
# if wild_pokemon
# pbWildBattle(wild_pokemon[0], wild_pokemon[1])
# else
# pbItemBall(:OLDBOOT)
# end
# break
# end
# end
# end
#
# try_spawn_surf_water_splashes
# }
def spawnSurfSplashPatch
$game_temp.initializeSurfPatches unless $game_temp.surf_patches
patch_size = [3,4,5,6].sample
patch_size = rand(3..6) # Faster than .sample for small ranges
splash_patch = SurfPatch.new(patch_size)
$game_temp.surf_patches << splash_patch
$game_temp.surf_patches.shift if $game_temp.surf_patches.length >= SurfPatch::MAX_NUMBER_SURF_SPLASHES
$game_temp.surf_patches.shift if $game_temp.surf_patches.length > SurfPatch::MAX_NUMBER_SURF_SPLASHES
echoln $game_temp.surf_patches
end
end