#===============================================================================
# Group Encounter System
# By Lecode
# For Strashiner
# ------------------------------------------------------------------------------
# Terms of Use:
# ------------------------------------------------------------------------------
# -Credit is required (Lecode)
# -For Strashiner project only
#===============================================================================
module Lecode
module GroupEncounter
Chase_Duration = 180
Chase_Emoticon = 1
Formations = {
#Nbr of enemies => Troop_id
1 => 7,
2 => 8,
3 => 9,
4 => 10,
5 => 11,
6 => 12,
7 => 13,
8 => 14
}
end
end
class Game_Event
include Lecode::GroupEncounter
attr_reader :legrenc_valid
attr_reader :legrenc_enemy_id
attr_reader :legrenc_chasing
attr_reader :legrenc_call_group
attr_reader :legrenc_group_id
alias legrenc_initialize initialize
def initialize(*args)
@true_move_info = {}
@legrenc_chasing = false
@legrenc_valid = false
@legrenc_chase_duration = Chase_Duration
legrenc_initialize(*args)
read_legrenc_coms
end
def read_legrenc_coms
text = ""
for command in @list
if command.code == 108 or command.code == 408 #- Comments
text += command.parameters[0]
end
end
#- Process text
if text =~ /<group encounter>/
@legrenc_valid = true
@legrenc_switch = nil
text.gsub!("<group encounter>","")
text.gsub!("</group encounter>","")
text.gsub!("\n","")
@legrenc_group_id = $1.to_i if text =~ /group_id:[ ]?(\d+);/i
@legrenc_range = $1.to_i if text =~ /range:[ ]?(\d+);/i
@legrenc_enemy_id = $1.to_i if text =~ /enemy_id:[ ]?(\d+);/i
@legrenc_call_group = $1.to_i if text =~ /call_group:[ ]?(\d+);/i
@legrenc_switch = $1.to_s if text =~ /switch:[ ]?(.+);/i
#- Verifications
if false
puts "Group_id: #{@legrenc_group_id}"
puts "Range: #{@legrenc_range}"
puts "Enemy_id: #{@legrenc_enemy_id}"
puts "Call_group: #{@legrenc_call_group}"
end
end
end
alias legrenc_sps setup_page_settings
def setup_page_settings
legrenc_sps
@true_move_info[:move_type] = @move_type
@true_move_info[:move_speed] = @move_speed
@true_move_info[:move_frequency] = @move_frequency
end
alias legrenc_update update
def update
legrenc_check_range if @legrenc_valid
legrenc_update
end
def legrenc_check_range
return if @erased
if @legrenc_chasing
@balloon_id = legrenc_chase_emoticon
@legrenc_chase_duration -= 1
legrenc_exit_chase if @legrenc_chase_duration == 0
return
end
legrenc_chase_player if legrenc_player_in_range
end
def legrenc_player_in_range
dx = distance_x_from($game_player.x)
dy = distance_y_from($game_player.y)
range = @legrenc_range
distance = Math.sqrt(dx*dx + dy*dy)
return distance <= range
end
def legrenc_chase_player
@legrenc_chasing = true
@legrenc_chase_duration = Chase_Duration
@move_type = 2
update_self_movement
end
def legrenc_exit_chase
@legrenc_chasing = false
@move_route_index = 0
@move_type = @true_move_info[:move_type]
@balloon_id = 0
end
def legrenc_activate_switch
return if @legrenc_switch.nil?
key = [@map_id, @event.id, @legrenc_switch]
$game_self_switches[key] = true
update
refresh
end
alias legrenc_erase erase
def erase
legrenc_exit_chase
legrenc_erase
end
def legrenc_chase_emoticon
Chase_Emoticon
end
end
class Game_Map
def setup_starting_map_event
event = @events.values.find {|event| event.starting }
if event
event.clear_starting_flag
@interpreter.setup(event.list, event.id)
@interpreter.set_legrenc_event(event)
end
event
end
end
class Game_Interpreter
def set_legrenc_event(event)
@legrenc_event = event
end
alias legrenc_command_301 command_301
def command_301
if @legrenc_event && @legrenc_event.legrenc_valid
$game_system.legrenc_event = @legrenc_event
end
legrenc_command_301
$game_system.legrenc_event = nil
end
end
module BattleManager
class << self
alias legrenc_setup setup
end
def self.setup(troop_id, can_escape = true, can_lose = false)
legrenc_setup(troop_id, can_escape = true, can_lose = false)
unless $game_system.legrenc_event.nil?
event = $game_system.legrenc_event
ids = legrenc_get_group
$game_troop.group_setup(troop_id,ids)
make_escape_ratio
end
end
def self.legrenc_get_group
ids = []
$game_map.events.values.each do |event|
next unless event.legrenc_valid
call_id = $game_system.legrenc_event.legrenc_call_group
next unless event.legrenc_group_id == call_id
next unless event.legrenc_chasing
event.legrenc_activate_switch
ids.push(event.legrenc_enemy_id)
end
return ids
end
end
class Game_Troop
def group_setup(troop_id,ids)
clear
@troop_id = troop_id
@enemies = []
formation_id = Lecode::GroupEncounter::Formations[ids.size]
dummy_troop = $data_troops[formation_id]
ids.each_with_index do |id,i|
next unless $data_enemies[id]
enemy = Game_Enemy.new(@enemies.size, id)
#- enemy.hide if member.hidden
enemy.screen_x = dummy_troop.members.x
enemy.screen_y = dummy_troop.members.y
@enemies.push(enemy)
end
init_screen_tone
make_unique_names
end
end
class Game_System
attr_accessor :legrenc_event
alias legrenc_initialize initialize
def initialize
@legrenc_event = nil
legrenc_initialize
end
end