#==============================================================================
class Game_Event < Game_Character
#变量ID
VAR_ID = 1
#变量值(大于或等于:停止)
VAR_NUM = 3
#--------------------------------------------------------------------------
def is_bird?
return false if @list.nil? || @list[0].code != 108
return @list[0].parameters[0].match(/<Location:(\S+)>/) != nil
end
#--------------------------------------------------------------------------
def target_location
return [0,0] if @list.nil? || @list[0].code != 108
return [0,0] if !@list[0].parameters[0].match(/<Location:(\S+)>/)
data = $1.split(",")
return [data[0].to_i,data[1].to_i]
end
#--------------------------------------------------------------------------
def land?
return is_bird? && $game_variables[VAR_ID] >= VAR_NUM
end
end
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
alias xrdata_move_type_random move_type_random
def move_type_random
if self.is_a?(Game_Event) && land?
moveto_target
return
end
xrdata_move_type_random
end
#--------------------------------------------------------------------------
def moveto_target
sx = @x - target_location[0]
sy = @y - target_location[1]
# 坐标相等情况下
if sx == 0 and sy == 0
key = [$game_map.map_id, @id, "A"]
$game_self_switches[key] = $game_map.need_refresh = true
return
end
# 求得差的绝对值
abs_sx = sx.abs
abs_sy = sy.abs
# 横距离与纵距离相等的情况下
if abs_sx == abs_sy
# 随机将边数增加 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# 横侧距离长的情况下
if abs_sx > abs_sy
# 左右方向优先。向主角移动
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# 竖侧距离长的情况下
else
# 上下方向优先。向主角移动
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
end
#==============================================================================