# 范围触发2.1 by 灯笼菜刀君 2018.12.16
#
# 使用方法: 事件触发条件改为"接触事件", 然后用注释写下
#
# [范围]起始点x,y,终点x,y,朝向(可省略),要重复触发(省略为不触发)
# [范围]的触发范围为起始点到终点的圈起来的矩形,朝向写2468,省略或者0为全方向触发
# 栗子: [范围]0,0,19,14,0,yes #=> 宽20,高15的触发范围,全方向,每步触发
#
# [身旁]x轴距离,y轴距离,要重复触发(省略为不触发)
# [身旁]的触发范围为自身为中心 x轴距离和y轴距离圈起来的矩形
# 栗子: [身旁]5,5 #=> 以事件为中心,5格范围内的范围,不重复触发
#
# [视野]有效距离,要重复触发(省略为不触发)
# [视野]的触发范围为事件面朝方向N格距离的三角形
# 栗子: [视野]2,yes #=> 视野2格范围内,重复触发
# □□■□
# □■■□
# →■■□
# □■■□
# □□■□
#-----------------------------------------------------------
# 注意: 以上触发条件都为"主角移动",主角不移动的话进入范围也不会触发,
# 需要以事件移动为刷新条件, 打开下面的开关(打开开关后,触发范围重叠的话
# 可能会引起判断异常,非必要别开开关)
CAIDAO_EVENT_FANWEI = 1 #允许以事件移动来触发范围的开关ID
#-----------------------------------------------------------
def 范围触发
for event in $game_map.events.values
next if event.list.nil?
for i in event.list
if i.code == 108 or i.code == 408
if i.parameters[0] =~ /[范围]/
b = i.parameters[0].gsub("[范围]", "").split(/,/)
if b.size > 3 and $game_player.x >= b[0].to_i and \
$game_player.x <= b[2].to_i and $game_player.y >= b[1].to_i and \
$game_player.y <= b[3].to_i
@触范 = [0] if b[5] != nil
if b[4] != nil and b[4] != "0"
return [event.id] if $game_player.direction == b[4].to_i
else
return [event.id]
end
end
end
if i.parameters[0] =~ /[身旁]/
b = i.parameters[0].gsub("[身旁]", "").split(/,/)
if b.size > 1 and ($game_player.x - event.x).abs <= b[0].to_i and \
($game_player.y - event.y).abs <= b[1].to_i
@触范 = [0] if b[2] != nil
return [-event.id,[event.x,event.y]]
end
end
if i.parameters[0] =~ /[视野]/
b = i.parameters[0].gsub("[视野]", "").split(/,/)
if b.size > 0
@触范 = [0] if b[1] != nil
case event.direction
when 2
if $game_player.y > event.y and \
$game_player.y <= event.y + b[0].to_i and \
($game_player.y - event.y).abs >= ($game_player.x - event.x).abs
return [-event.id,[event.x,event.y,2]]
end
when 8
if $game_player.y < event.y and \
$game_player.y >= event.y - b[0].to_i and \
($game_player.y - event.y).abs >= ($game_player.x - event.x).abs
return [-event.id,[event.x,event.y,8]]
end
when 4
if $game_player.x < event.x and \
$game_player.x >= event.x - b[0].to_i and \
($game_player.y - event.y).abs <= ($game_player.x - event.x).abs
return [-event.id,[event.x,event.y,4]]
end
when 6
if $game_player.x > event.x and \
$game_player.x <= event.x + b[0].to_i and \
($game_player.y - event.y).abs <= ($game_player.x - event.x).abs
return [-event.id,[event.x,event.y,6]]
end
end
end
end
end
end
end
return [0]
end
class Game_Player < Game_Character
def initialize
super()
@触范 = [0]
end
def update
# 本地变量记录移动信息
last_moving = moving?
# 移动中、事件执行中、强制移动路线中、
# 信息窗口一个也不显示的时候
f = @触范 #菜刀王到此一游
unless moving? or $game_system.map_interpreter.running?
@move_route_forcing or $game_temp.message_window_showing
# 如果方向键被按下、主角就朝那个方向移动
case Input.dir4
when 2
move_down
f = 范围触发 #菜刀王到此一游
when 4
move_left
f = 范围触发 #菜刀王到此一游
when 6
move_right
f = 范围触发 #菜刀王到此一游
when 8
move_up
f = 范围触发 #菜刀王到此一游
end
end
# 本地变量记忆坐标
last_real_x = @real_x
last_real_y = @real_y
super
# 角色向下移动、画面上的位置在中央下方的情况下
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
# 画面向下卷动
$game_map.scroll_down(@real_y - last_real_y)
end
# 角色向左移动、画面上的位置在中央左方的情况下
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
# 画面向左卷动
$game_map.scroll_left(last_real_x - @real_x)
end
# 角色向右移动、画面上的位置在中央右方的情况下
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
# 画面向右卷动
$game_map.scroll_right(@real_x - last_real_x)
end
# 角色向上移动、画面上的位置在中央上方的情况下
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
# 画面向上卷动
$game_map.scroll_up(last_real_y - @real_y)
end
#-菜刀王到此一游----------------------------------------------
if @触范[0] != f[0] or (f[0] < 0 and @触范[1] != f[1])
if f[0] == 0
@触范 = f
else
event = $game_map.events[f[0].abs]
if event != nil and event.trigger == 1 and !event.jumping?
event.start
@触范 = f
return
end
end
end
#-------------------------------------------------------------
# 不在移动中的情况下
unless moving?
# 上次主角移动中的情况
if last_moving
# 与同位置的事件接触就判定为事件启动
result = check_event_trigger_here([1,2])
# 没有可以启动的事件的情况下
if result == false
# 调试模式为 ON 并且按下 CTRL 键的情况下除外
unless $DEBUG and Input.press?(Input::CTRL)
# 遇敌计数下降
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 判定为同位置以及正面的事件启动
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
end
end
class Game_Event < Game_Character
alias oxox_initialize initialize
def initialize(map_id, event)
oxox_initialize(map_id,event)
@范触 = []
end
alias oxox_check_event_trigger_auto check_event_trigger_auto
def check_event_trigger_auto
oxox_check_event_trigger_auto
if @trigger == 1 and $game_switches[CAIDAO_EVENT_FANWEI]
f = 范围触发
if f[0] == -@id and @范触 != f[1]
start
@范触 = f[1]
end
end
end
end