#===============================================================================
# ** Dart Launcher / Long-Range Event Activater
#-------------------------------------------------------------------------------
# By Pyrofied / Liquid_Pencil
# v1.0
#-------------------------------------------------------------------------------
# This script allows you to create a 'dart' event. When thrown, it will
# continue to fly away from the player until it either hits a wall or an
# event. If it hits an 'active' event, it will either run the event or turn
# on a self-switch. If it hits a 'wall' event, then the dart will act as if
# it hit a wall.
#
#---------------------------------INSTRUCTIONS---------------------------------
#
# --------Dart events--------
#
# A dart event is, simply put, the dart you throw. When it hits an active
# event, it runs the event, and when it hits a wall, it disappears.
#
# To set up a 'dart' event, simply put the DART_NAME somewhere in the event
# name box. Create a second page with the condition 'Self Switch A is ON.'
# Set its move frequency to Highest and turn on the 'Through' flag. Create
# a custom move route with only 'Move Away from Player,' as a condition,
# and have the 'Repeat Action' flag on. Set the event graphic for the 'A'
# page to whatever you please.
#
# --------Active events--------
#
# 'Active' events are what the dart will activate when it hits. When hit, it
# will either run said event or activate its self-switch.
#
# To set up an 'active' event, change the event name to this:
#
#
# active_name
#
#
# active_name: The name that sets up an 'active' event. Can be set in the
# ACTIVE_EVENT_NAME.
#
# method: Either 'run' or 'SS' without the quotation marks. If set to 'run',
# then the event will run as if you activated it regularly through touch
# or interaction. If set to 'SS', then the event's self switch will be
# turned ON.
#
# self_switch: The ID of the self switch that will be turned on. Used only
# if method is 'SS'. IF NOT USED, KEEP THE BRACKETS BUT LEAVE IT BLANK.
#
# EXAMPLE NAMES:
#
# activate - When triggered by the dart event, the event will run.
#
# activate - When triggered by the dart event, the event's 'A' self
# switch will be activated.
#
# --------Wall events--------
#
# Wall events behave just like a wall. When the dart runs into it, it will
# disappear.
#
# To set up a wall event, simply put 'wall' without the quotation marks
# somewhere within the event name box.
#
#
# --------Pass Areas--------
#
# Pass areas are areas created over tiles that the player can't walk through,
# but the dart can pass over. You will need to use pass areas over things like
# pits so the player can't pass over it, but the dart can.
#
# To set up a pass area, create the area in the event map, and put 'pass' in
# its area name.
#
#===============================================================================

#-------------------------------------------------------------------------------

# vv--------------Edit below this point--------------vv

module LP_Dart # DO NOT EDIT THIS NAME


# DART_SPEED: Sets the speed of the dart event.
#
# 1 = 8x Slower
# 2 = 4x Slower
# 3 = 2x Slower
# 4 = Normal
# 5 = 2x Faster
# 6 = 4x Faster
#
# You can also set the number to higher than 6 if you want.
DART_SPEED = 7

# DART_THROW_KEY: Sets the button that triggers the dart throw.
DART_THROW_KEY = Input::Y

# NO_DART_MAPS: Array of map IDs that you can't throw darts in.
NO_DART_MAPS =

# USE_DART_ITEM: Whether a dart item is to be set. If set to true, then
# for every throw it will reduce the dart item by 1.
#
# DART_ITEM: The ID of the dart item. Useless if USE_DART_ITEM is set to
# false.
USE_DART_ITEM = true
DART_ITEM = 21

# DART_NAME: Name of the dart event.
DART_NAME = 'dart'

# ACTIVE_EVENT_NAME: Name of an 'active' event.
ACTIVE_EVENT_NAME = 'active'

# ^^--------------Edit above this point--------------^^

#---------NO EDITS BEYOND HTIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING---------

ACTIVE_TAG = /(\w*)\\/i

end

#-------------------------------------------------------------------------------

#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass of the
# Game_Player and Game_Event classes.
#==============================================================================

class Game_Character

#-----------------------------------------------------------------------------
attr_accessor :move_speed # Movement speed of dart
attr_accessor :move_frequency # Movement frequency
#-----------------------------------------------------------------------------

end

#-------------------------------------------------------------------------------

#===============================================================================
# ** 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

#-----------------------------------------------------------------------------
attr_reader :name # Returns name of event
attr_reader :dart # Dart tag
attr_reader :dart_activate # What will event do when activated?
attr_reader :wall # Wall tag
attr_reader :active # 'Active' event tag
attr_accessor :thrown # Is event thrown?
#-----------------------------------------------------------------------------

#=============================================================================
# * alias initialize: name/dart now readable
#=============================================================================

alias dart_check_initialize initialize
def initialize(map_id, event)
dart_check_initialize(map_id, event)
@name = @event.name
@thrown = false
@dart = false
name_check(@name)
end

#=============================================================================
# * new method: in_area?
#=============================================================================
def in_pass?(area)
return false if area == nil
return false if @map_id != area.map_id
if @direction == 2
x = @x
y = @y + 1
elsif @direction == 4
x = @x - 1
y = @y
elsif @direction == 6
x = @x + 1
y = @y
else
x = @x
y = @y - 1
end
return false if x < area.rect.x
return false if y < area.rect.y
return false if x >= area.rect.x + area.rect.width
return false if y >= area.rect.y + area.rect.height
return true
end

#=============================================================================
# * new method: dart_check
#=============================================================================

def name_check(name)
if name.include?(LP_Dart::DART_NAME)
@dart = true
elsif name.include?('wall')
@wall = true
elsif name.include?(LP_Dart::ACTIVE_EVENT_NAME)
LP_Dart::ACTIVE_TAG =~ name
event = $1.to_s
method = $2.to_s
switch = $3.to_s
switch.upcase
@active = true
if method == 'run'
@dart_activate = 'run'
elsif method == 'SS'
@dart_activate =
end
end
end

end

#-------------------------------------------------------------------------------

#===============================================================================
# ** Game_Map
#-------------------------------------------------------------------------------
# This class handles maps. It includes scrolling and passage determination
# functions. The instance of this class is referenced by $game_map.
#===============================================================================

class Game_Map

#-----------------------------------------------------------------------------
attr_reader :dart_event # Array for dart events
attr_reader :map_id # Map ID
attr_reader :pass_areas # Array of passable areas
#-----------------------------------------------------------------------------

#=============================================================================
# * alias initialize: Adds dart_thrown boolean
#=============================================================================

alias dart_check_initialize initialize
def initialize
dart_check_initialize
@pass_areas =
get_pass_areas
end

#=============================================================================
# * alias setup_events: Gets dart event
#=============================================================================

alias dart_check_setup_events setup_events
def setup_events
dart_check_setup_events
for event in @events.values
if event.dart
@dart_event = event
end
end
end

#=============================================================================
# * new method: get_pass_areas
#=============================================================================

def get_pass_areas
for area in $data_areas.values
if area.name.include?('pass')
@pass_areas.push(area)
end
end
end
#=============================================================================
# * alias update: Updates dart if dart is thrown
#=============================================================================

alias dart_check_update update
def update
dart_check_update
unless @dart_event.nil?
if @dart_event.thrown == true
x = @dart_event.x
y = @dart_event.y
update_dart(x, y)
end
end
end

#=============================================================================
# * new method: update_dart
#=============================================================================

def update_dart(x, y)
event = @dart_event
if event.direction == 2
if passable?(x, y+1)
event_check(event, x, y)
else
area_check(event, x, y)
end
elsif event.direction == 4
if passable?(x-1, y)
event_check(event, x, y)
else
area_check(event, x, y)
end
elsif event.direction == 6
if passable?(x+1, y)
event_check(event, x, y)
else
area_check(event, x, y)
end
else
if passable?(x, y-1)
event_check(event, x, y)
else
area_check(event, x, y)
end
end
end

#=============================================================================
# * new method: event_check
#=============================================================================

def event_check(dart_event, x, y)
dart_check = events_xy(x, y)
if dart_check.size > 1
dart_check.delete(dart_event)
ko_event = dart_check.shift
if ko_event.active
if ko_event.dart_activate.is_a?(Array)
switch = ko_event.dart_activate
key =
$game_self_switches = true
ko_event.refresh
stop_dart(dart_event)
elsif ko_event.dart_activate == 'run'
ko_event.start
stop_dart(dart_event)
else
p 'No event activation method defined.'
stop_dart(dart_event)
end
elsif ko_event.wall
stop_dart(dart_event)
end
end
end

#=============================================================================
# * new method: area_check
#=============================================================================

def area_check(event, x, y)
can_pass = false
for area in @pass_areas
if event.in_pass?(area)
if can_pass == false
can_pass = true
end
end
end
if can_pass == true
event_check(event, x, y)
else
stop_dart(event)
end
end

#=============================================================================
# * new method: stop_dart
#=============================================================================

def stop_dart(dart_event)
dart_event.thrown = false
switch = 'A'
key =
$game_self_switches = false
dart_event.refresh
end
end

#-------------------------------------------------------------------------------

#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter

#=============================================================================
# * new method: start_dart_throw
#=============================================================================

def start_dart_throw(x, y)
direc = $game_player.direction
dart = $game_map.dart_event
if direc == 2
y += 1
elsif direc == 4
x -= 1
elsif direc == 6
x += 1
else
y -= 1
end
dart.moveto(x,y)
dart.thrown = true
map = $game_map.map_id
switch = 'A'
key =
$game_self_switches = true
end
end

#-------------------------------------------------------------------------------

#===============================================================================
# ** Scene_Map
#-------------------------------------------------------------------------------
# This class performs the map screen processing.
#===============================================================================

class Scene_Map < Scene_Base

#=============================================================================
# * alias update: checks Input
#=============================================================================

alias dart_throw_update :update
def update
dart_throw_update
update_dart_trigger
end

#=============================================================================
# * new method: update_dart_trigger
#=============================================================================

def update_dart_trigger
if not $game_message.visible and Input.trigger?(LP_Dart::DART_THROW_KEY)
maps = LP_Dart::NO_DART_MAPS
if maps.include?($game_map.map_id)
Sound.play_buzzer
else
x = $game_player.x
y = $game_player.y
if $game_map.dart_event.thrown == true
Sound.play_buzzer
else
if LP_Dart::USE_DART_ITEM == true
item_id = LP_Dart::DART_ITEM
item = $data_items
if $game_party.has_item?(item)
$game_party.lose_item(item, 1)
$game_map.interpreter.start_dart_throw(x, y)
$game_map.dart_event.refresh
$game_map.dart_event.move_speed = LP_Dart::DART_SPEED
else
Sound.play_buzzer
end
else
$game_map.interpreter.start_dart_throw(x, y)
$game_map.dart_event.refresh
$game_map.dart_event.move_speed = LP_Dart::DART_SPEED
$game_map.dart_event.move_frequency = 5
end
end
end
end
end
end