=begin
事件注释(必须在最上边):
[Move_Away_From_Player]
Away_Distance : [警戒距离]
Speed_Plus : [逃跑速度的增加值]
Jump_Distance : [检索的最大跳跃距离]
Terrain_Tags : [可跳跃墙壁的地形标志]
Jump_Se : [跳跃时播放的SE文件名称]
=end
#==============================================================================
# 开始刷新
#==============================================================================
class Game_Character
alias upd_move_away_from_player update
def update
upd_move_away_from_player
if @away_distance and
# 与频率联系
@stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
an_move_away_from_player
end
end
end
class Game_Event < Game_Character
#============================================================================
# 初始化
#============================================================================
def init_move_away_from_player(*args)
args[0].sub(/\[(.+)\]/, "ha ha !")
return !args[1] ? $1 : $1.to_i
end
alias ref_move_away_from_player refresh
def refresh
ref_move_away_from_player
away_page = @event.pages[@event.pages.index(@page)]
list = away_page.list
if list[0].parameters[0] == "[Move_Away_From_Player]"
# 初始化
@away_distance = init_move_away_from_player(list[1].parameters[0], true)#视野
@speed_plus = init_move_away_from_player(list[2].parameters[0], true)#速度附加值
@jump_distance = init_move_away_from_player(list[3].parameters[0], true)#跳跃检查距离
@terrain_tags = init_move_away_from_player(list[4].parameters[0], true)#可跳跃的地形标志
@jump_se = RPG::AudioFile.new
@jump_se.name = init_move_away_from_player(list[5].parameters[0])#跳跃SE
# 备份数据
@old_move_speed = away_page.move_speed
@old_move_frequency = away_page.move_frequency
@old_through = away_page.through
@old_always_on_top = away_page.always_on_top
return
end
# 清理数据
@away_distance = @speed_plus = @check_distance = @terrain_tags = @jump_se = nil
end
#============================================================================
# 执行刷新
#============================================================================
def an_move_away_from_player
sx = @x - $game_player.x
sy = @y - $game_player.y
if sx.abs > @away_distance or sy.abs > @away_distance
# 恢复速度,频率
@move_speed = @old_move_speed
@move_frequency = @old_move_frequency
move_rand
else
# 墙角(???)
#if (@x == $game_map.width - 1 and @y == $game_map.height - 1) or
# (@x == 0 and @y == $game_map.height - 1) or
# (@x == $game_map.width - 1 and @y == 0) or
# (@x == 0 and @y == 0)
# return
#end
# 快速逃离
@move_speed = [@old_move_speed + @speed_plus, 6].min
@move_frequency = 6
# 在墙上远离角色
if $game_map.terrain_tag(@x, @y) == @terrain_tags
move_away_from_player
return
end
# 跳上墙
ax = [*(@x - @jump_distance)..(@x + @jump_distance)]
ay = [*(@y - @jump_distance)..(@y + @jump_distance)]
for ix in 0...ax.size
for iy in 0...ay.size
x = ax[ix]
y = ay[iy]
if not $game_map.valid?(x, y)
next
end
if $game_map.terrain_tag(x, y) == @terrain_tags
# 穿透,置顶
@through = @always_on_top = true
$game_system.se_play(@jump_se)
jump(x - @x, y - @y)
return
end
end
end
# 远离角色
move_away_from_player
end
end
#============================================================================
# 随机移动
#============================================================================
def move_rand
n = rand(4)
# 跳下来
if $game_map.terrain_tag(x, y) == @terrain_tags
case n
when 0
arc = [@x, @y + 1]
arj = [0, 1]
when 1
arc = [@x - 1, @y]
arj = [-1, 0]
when 2
arc = [@x + 1, @y]
arj = [1, 0]
when 3
arc = [@x, @y - 1]
arj = [0, -1]
end
if $game_map.valid?(*arc) and
$game_map.terrain_tag(*arc) != @terrain_tags
$game_system.se_play(@jump_se)
jump(*arj)
# 恢复穿透,置顶设置
@through = @old_through
@always_on_top = @old_always_on_top
return
end
end
# 随机移动
case n
when 0
move_down(false)
when 1
move_left(false)
when 2
move_right(false)
when 3
move_up(false)
end
end
end