#===============================================================================
# Lufia Enemy Movement - by GubiD (04/24/2011)
#===============================================================================
#-------------------------------------------------------------------------------
# * Constants
#-------------------------------------------------------------------------------
# ENEMY_COMMENT_IDENTIFIER - text that must be contained in comment for event to
# be recognized as Lufia type enemy.
#-------------------------------------------------------------------------------
ENEMY_COMMENT_IDENTIFIER = "enemy"
#-------------------------------------------------------------------------------
# Game Map
#-------------------------------------------------------------------------------
class Game_Map
#-----------------------------------------------------------------------------
# Setup - Adjusted to setup lufia event hash
#-----------------------------------------------------------------------------
alias setup_gm_map_lufia_movement setup
def setup(map_id)
setup_gm_map_lufia_movement(map_id)
@player_pos = [ $game_player.x, $game_player.y]
refresh_enemy_event_list
end
#-----------------------------------------------------------------------------
# Refresh Enemy List - Method to locate enemies for later updating
#-----------------------------------------------------------------------------
def refresh_enemy_event_list
@l_enemy_list = []
for id in @events.keys
event = @events[id]
if event.list.size > 0
for command in event.list
if command.code == 108 #comment
if command.parameters[0].include?(ENEMY_COMMENT_IDENTIFIER)
@l_enemy_list << id
end
end
end
end
end
end
#-----------------------------------------------------------------------------
# Update - Changed to check for 'player movement' and update enemies when done
#-----------------------------------------------------------------------------
alias upd_gm_map_lufia_movement update
def update
upd_gm_map_lufia_movement
if @l_enemy_list.size > 0
if @player_pos != [ $game_player.x, $game_player.y]
@player_pos = [ $game_player.x, $game_player.y]
move_enemies
end
end
check_for_event_erase
end
#-----------------------------------------------------------------------------
# Check for Event erase - If an event is later erased, it cannot be updated
# so here we remove it from our 'update list'
#-----------------------------------------------------------------------------
def check_for_event_erase
needs_removed = []
for id in @l_enemy_list
event = @events[id]
if event.erased == true
needs_removed << id
end
end
if needs_removed.size > 0
for id in needs_removed
@l_enemy_list.delete(id)
end
end
end
#-----------------------------------------------------------------------------
# Move_enemies - Takes all the enemies from list, and has them move toward player
#-----------------------------------------------------------------------------
def move_enemies
for id in @l_enemy_list
event = @events[id]
event.move_type_toward_player
end
end
end
#-------------------------------------------------------------------------------
# Game Event - Added ability to read if it has been erased
#-----------------------------------------------------------------------------
class Game_Event < Game_Character
attr_reader :erased
end