#==============================================================================
# ** Sound Interaction System
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 1
# 2007-03-21
#------------------------------------------------------------------------------
# * Version History :
#
# Version 1 ---------------------------------------------------- (2007-03-21)
#------------------------------------------------------------------------------
# * Requirements :
#
#------------------------------------------------------------------------------
# * Description
#
#------------------------------------------------------------------------------
# * Instructions
#
# Place The Script Below the SDK and Above Main.
#------------------------------------------------------------------------------
# * Customization
#
#------------------------------------------------------------------------------
# * Syntax :
#
# Comment : Sound Interaction|type|filename|max_volume|max_distance
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Sound Interaction System', 'SephirothSpawn', 1, '2007-03-21')
SDK.check_requirements(2.2, [1, 2])
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Sound Interaction System')
#==============================================================================
# ** Sound Interaction System
#==============================================================================
module Sound_Interaction
#--------------------------------------------------------------------------
# * Player Movement SE
#--------------------------------------------------------------------------
Player_Movement_SE_Name = '013-Move01'
Player_Movement_SE_Volume = 60
Player_Movement_SE_Frames = [0]
#--------------------------------------------------------------------------
# * Non-Defined Frames To Play Movement SE
#--------------------------------------------------------------------------
Movement_SE_Frames = [0]
end
#==============================================================================
# ** Game_Character
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :sis_movement_se_name
attr_accessor :sis_movement_se_max_volume
attr_accessor :sis_movement_se_max_distance
attr_accessor :sis_movement_se_frames
attr_accessor :sis_range_bgs_name
attr_accessor :sis_range_bgs_max_volume
attr_accessor :sis_range_bgs_max_distance
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_soundintsys_gmchr_ua, :update_animation
#--------------------------------------------------------------------------
# * Frame Update : Animation Counters
#--------------------------------------------------------------------------
def update_animation
# Gets Old Pattern
old_pattern = @pattern
# Original Update Animation Counters
seph_soundintsys_gmchr_ua
# If Play Movement SE
unless @sis_movement_se_name.nil?
# If Pattern is Different
if old_pattern != @pattern &&
# If Movement SE Frame
@sis_movement_se_frames.include?(old_pattern)
# Gets Distance From Player
px, py = $game_player.x, $game_player.y
distance = self == $game_player ? 0 : Math.hypot(@x - px, @y - py)
# Calculates Volume
md = @sis_movement_se_max_distance
mv = @sis_movement_se_max_volume
volume = distance == 0 ? mv : distance > md ? 0 :
mv * ((md - (distance - 1)) / md)
# If Volume Greater Than 0
if volume > 0
# Play Movement SE
Audio.se_play('Audio/SE/' + @sis_movement_se_name, volume)
end
end
end
end
end
#==============================================================================
# ** Game_Event
#==============================================================================
class Game_Event
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_soundintsys_gmevt_refrsh, :refresh
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# Original Refresh
seph_soundintsys_gmevt_refrsh
# Set LD Variables
@sis_movement_se_name = nil
@sis_movement_se_max_volume = 100
@sis_movement_se_max_distance = 10
@sis_range_bgs_name = nil
@sis_range_bgs_max_volume = 100
@sis_range_bgs_max_distance = 10
# Return if Nil Page or Erased
return if @list.nil? || @erased
# Pass Through All Event Commands
for ec in @list
# If Comment Command
if ec.code == 108 &&
# And Comments Include "SOUND INTERACTION"
ec.parameters[0].upcase.include?('SOUND INTERACTION')
# Split Comment Line
parameters = ec.parameters[0].split('|')
# Branch By Type
case parameters[1].upcase
when 'MVT'
# Set Filename, Volume & Distance
@sis_movement_se_name = parameters[2]
@sis_movement_se_max_volume = parameters[3].to_i
@sis_movement_se_max_distance = parameters[4].to_i
if parameters[5].nil?
@sis_movement_se_frames = Sound_Interaction::Movement_SE_Frames
else
@sis_movement_se_frames = eval "[#{parameters[5]}]"
end
when 'RNG'
# Set Filename, Volume & Distance
@sis_range_bgs_name = parameters[2]
@sis_range_bgs_max_volume = parameters[3].to_i
@sis_range_bgs_max_distance = parameters[4].to_i
end
end
end
end
end
#==============================================================================
# ** Game_Player
#==============================================================================
class Game_Player
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :sis_range_bgs
attr_accessor :sis_enabled
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_soundintsys_gmplyr_init, :initialize
alias_method :seph_soundintsys_gmplyr_update, :update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_soundintsys_gmplyr_init
# Enable Sound Interaction
@sis_enabled = true
# Set Movement Distances
@sis_movement_se_name = Sound_Interaction::Player_Movement_SE_Name
@sis_movement_se_max_volume = Sound_Interaction::Player_Movement_SE_Volume
@sis_movement_se_frames = Sound_Interaction::Player_Movement_SE_Frames
# Set Distances
@sis_event_distances = {}
@sis_event_distances.default = nil
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Original Update
seph_soundintsys_gmplyr_update
# Update Sound Interaction
update_sound_interaction
end
#--------------------------------------------------------------------------
# * Event Distances
#--------------------------------------------------------------------------
def sis_event_ranges
# ditance => [event_id]
ranges = {}
for event_id in $game_map.events.keys.sort
event = $game_map.events[event_id]
next if event.sis_range_bgs_name.nil?
distance = Math.hypot(@x - event.x, @y - event.y)
ranges[distance] = [] unless ranges.has_key?(distance)
ranges[distance] << event_id
end
return ranges
end
#--------------------------------------------------------------------------
# * Frame Update : Sound Interaction Range
#--------------------------------------------------------------------------
def update_sound_interaction
# If Not Enabled
unless @sis_enabled
# If BGS Playing
if @sis_range_bgs != nil
# Set Range BGS to Nil
@sis_range_bgs = nil
# Stop BGS
$game_system.bgs_play(nil)
end
return
end
# Gets Event Ranges
event_ranges = sis_event_ranges
# Set Main Break Flag to False
main_break = false
# Pass Through Shortest to Farthest Range
for distance in event_ranges.keys.sort
# Pass Through Events
for event_id in event_ranges[distance].sort
# If Last Event Played & Distance Hasn't Changed
if @sis_range_last_event_id == event_id &&
@sis_event_distances[event_id] == distance
# Break Main Loop
main_break = true
# Break Loop
break
end
# Gets Event Data
event = $game_map.events[event_id]
# If Distance Has Changed
if @sis_event_distances[event_id] != distance
# Record Distance Change
@sis_event_distances[event_id] = distance
# Calculates Volume
md = event.sis_range_bgs_max_distance
mv = event.sis_range_bgs_max_volume
volume = distance == 0 ? mv : distance > md ? 0 :
mv * ((md - (distance - 1)) / md)
# If Volume is Less Than 1
if volume < 1
# If Volume was Playing Before
if @sis_range_bgs == event.sis_range_bgs_name
# Set Previoius BGS to Nil
@sis_range_bgs = nil
# Clear SIS Last Event Range Flag
@sis_range_last_event_id = nil
# Stop BGS
$game_system.bgs_play(nil)
end
next
end
# Record Playing BGS
@sis_range_bgs = event.sis_range_bgs_name
# Record SIS Last Event Range Flag
@sis_range_last_event_id = event_id
# Play BGS
$game_system.bgs_play(RPG::AudioFile.new(@sis_range_bgs, volume))
# Break Main Loop
main_break = true
# Break Loop
break
end
end
# Break if Break Main is True
break if main_break
end
end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_soundintsys_scnmap_cb, :call_battle
#--------------------------------------------------------------------------
# * Frame Update : Call Battle
#--------------------------------------------------------------------------
def call_battle
# If Player Playing Sound Interaction BGS
if $game_player.sis_enabled && $game_player.sis_range_bgs != nil
# Clear BGS
$game_player.sis_range_bgs = nil
# Stop BGS
$game_system.bgs_play(nil)
end
# Original Call Battle
seph_soundintsys_scnmap_cb
end
end
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end