#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# This class deals with events. It handles functions including event page
# switching via condition determinants, and running parallel process events.
# It's used within the Game_Map class.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :trigger # trigger
attr_reader :list # list of event commands
attr_reader :starting # starting flag
#--------------------------------------------------------------------------
# * Object Initialization
# map_id : map ID
# event : event (RPG::Event)
#--------------------------------------------------------------------------
def initialize(map_id, event)
super()
@map_id = map_id
@event = event
@id = @event.id
@erased = false
@starting = false
@through = true
# Move to starting position
moveto(@event.x, @event.y)
refresh
end
#--------------------------------------------------------------------------
# * Clear Starting Flag
#--------------------------------------------------------------------------
def clear_starting
@starting = false
end
#--------------------------------------------------------------------------
# * Determine if Over Trigger
# (whether or not same position is starting condition)
#--------------------------------------------------------------------------
def over_trigger?
# If not through situation with character as graphic
if @character_name != "" && !@through
# Starting determinant is face
return false
end
# If this position on the map is impassable
unless $game_map.passable?(@x, @y, 0)
# Starting determinant is face
return false
end
# Starting determinant is same position
return true
end
#--------------------------------------------------------------------------
# * Start Event
#--------------------------------------------------------------------------
def start
# If list of event commands is not empty
if @list.size > 1
@starting = true
end
end
#--------------------------------------------------------------------------
# * Temporarily Erase
#--------------------------------------------------------------------------
def erase
@erased = true
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
new_page = @erased ? nil : find_proper_page
setup_page(new_page) if !new_page || new_page != @page
end
#--------------------------------------------------------------------------
# * Find Event Page Meeting Conditions
#--------------------------------------------------------------------------
def find_proper_page
@event.pages.reverse.find {|page| conditions_met?(page) }
end
#--------------------------------------------------------------------------
# * Determine if Event Page Conditions Are Met
#--------------------------------------------------------------------------
def conditions_met?(page)
c = page.condition
if c.switch1_valid
return false unless $game_switches[c.switch1_id]
end
if c.switch2_valid
return false unless $game_switches[c.switch2_id]
end
if c.variable_valid
return false if $game_variables[c.variable_id] < c.variable_value
end
if c.self_switch_valid
key = [@map_id, @event.id, c.self_switch_ch]
return false if $game_self_switches[key] != true
end
return true
end
#--------------------------------------------------------------------------
# * Event Page Setup
#--------------------------------------------------------------------------
def setup_page(new_page)
@page = new_page
if @page
setup_page_settings
else
clear_page_settings
end
clear_starting
check_event_trigger_auto
end
#--------------------------------------------------------------------------
# * Clear Event Page Settings
#--------------------------------------------------------------------------
def clear_page_settings
@tile_id = 0
@character_name = ""
@character_hue = 0
@move_type = 0
@through = true
@trigger = nil
@list = nil
@interpreter = nil
end
#--------------------------------------------------------------------------
# * Set Up Event Page Settings
#--------------------------------------------------------------------------
def setup_page_settings
@tile_id = @page.graphic.tile_id
@character_name = @page.graphic.character_name
@character_hue = @page.graphic.character_hue
if @original_direction != @page.graphic.direction
@direction = @page.graphic.direction
@original_direction = @direction
@prelock_direction = 0
end
if @original_pattern != @page.graphic.pattern
@pattern = @page.graphic.pattern
@original_pattern = @pattern
end
@opacity = @page.graphic.opacity
@blend_type = @page.graphic.blend_type
@move_type = @page.move_type
@move_speed = @page.move_speed
@move_frequency = @page.move_frequency
@move_route = @page.move_route
@move_route_index = 0
@move_route_forcing = false
@walk_anime = @page.walk_anime
@step_anime = @page.step_anime
@direction_fix = @page.direction_fix
@through = @page.through
@always_on_top = @page.always_on_top
@trigger = @page.trigger
@list = @page.list
@interpreter = @trigger == 4 ? Interpreter.new : nil
end
#--------------------------------------------------------------------------
# * Touch Event Starting Determinant
#--------------------------------------------------------------------------
def check_event_trigger_touch(x, y)
# If event is running
return if $game_system.map_interpreter.running?
# If trigger is [touch from event] and consistent with player coordinates
if @trigger == 2 && x == $game_player.x && y == $game_player.y
# If starting determinant other than jumping is front event
start if !jumping? && !over_trigger?
end
end
#--------------------------------------------------------------------------
# * Automatic Event Starting Determinant
#--------------------------------------------------------------------------
def check_event_trigger_auto
# If trigger is [touch from event] and consistent with player coordinates
if @trigger == 2 && @x == $game_player.x && @y == $game_player.y
# If starting determinant other than jumping is same position event
start if !jumping? && over_trigger?
end
# If trigger is [auto run]
start if @trigger == 3
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
check_event_trigger_auto
if @interpreter != nil
@interpreter.setup(@list, @event.id) unless @interpreter.running?
@interpreter.update
end
end
end