=begin #=======================================================================
Sion Mouse System v1.3
Changlog
2013.6.15 v1.3f
1.3f 卷动地图 bug 修正
1.3e: 逻辑优化;提供解除鼠标固定的接口
在事件中执行脚本 Mouse.lock_mouse_in_screen 将鼠标锁定在屏幕内
Mouse.unlock_mouse_in_screen 解除锁定
1.3f: bug修正
1.3d: 常数设置增加:Menu_Set_Pos,用来设置打开菜单时鼠标是否移动到光标处以及
关闭菜单时,鼠标是否移动到原来的位置。
1.3c: 打开菜单、光标移动时鼠标会移动到光标位置处
1.3b: 修正一些罕见的bug;
1.3a: 代码小修改;
加入了鼠标点击启动事件的功能,
在事件中加入“注释”: 鼠标启动 ,
该事件将无法用其它方式启动,只能用鼠标左键点击启动。
2013.2.12 v1.2
寻路逻辑优化;
优化了事件判断,现在点击事件附近的格子,移动到指定点后不会触发该事件了;
现在支持用鼠标来操作载具了。
2013.2.8 v1.1
优化了事件判断,现在可以方便地启动柜台后面的事件;
修复了某些菜单(例如更换装备的菜单)掉帧的问题;
移动时,路径指示点的绘制更加稳定;
现在支持默认存档画面的鼠标操作了。
OrigenVersion
2013.2.7 v1.0
主要功能
使用鼠标进行各种操作...
将鼠标锁定在游戏窗口内
自动寻路,按住 D 键可以扩大寻路的范围
双击鼠标进行冲刺
更改地图卷动方式以适应鼠标移动
变量输入框改良
★ 鼠标指针图片 Cursor.png 放入 Graphics\System 文件夹
★ 路径点指示图片 $Arrow.png 放入 Graphics\Characters 文件夹
★ 如果未放入会弹出提示,并使用RM自带图片代替缺失文件;该提示可以在下面关闭
=end #★★★★★★★★ 可能需要设置的参数都在下面用“★”标出了 ★★★★★★★★★★
$no_arrowpic_warn = false # ★ 设置为false不弹出图片缺失提示
#==============================================================================
# ■ 常数设置
#==============================================================================
module KsOfSion
Clip_Cursor = false # ★ 鼠标锁定在游戏窗口内,需要关闭设置为false
Dbclick_Frame = 15 # ★ 双击的最大间隔帧数。在地图画面双击进行奔跑
New_Scroll = true # ★ 更改地图卷动方式,需要关闭设置为false
Map_Scroll_Spd = 1.0 # ★ 更改地图卷动速率,请确保此值为大于0的float变量
Menu_Set_Pos = true # ★ 打开菜单时将鼠标移动到光标处
Break_Steps = 30 # ★ 鼠标寻路最大步数,防止路径太长导致卡帧
# “30” 是默认显示格子数 长(17) + 宽(13)
Find_Path_Key = :Z # ★ 扩大寻路范围至全地图按键 :Z 对应 D键
# RM几个内置的空键位 (:X = A)(:Y = S)(:Z = D)
end
#==============================================================================
# ■ 用来显示路径点的类
#==============================================================================
class Move_Sign < Game_Character
#--------------------------------------------------------------------------
# ● 设置目标点指示图的各种参数,请注意要使用的图片是行走图
#--------------------------------------------------------------------------
def init_public_members
@character_name = '!$Arrow'# ★ 路径点箭头,置于.\Graphics\Characters文件夹
@character_index = 0 # ★ 图片索引。$开头的行走图设为0
@move_speed = 5 # ★ 踏步速度
@step_anime = true # ★ 踏步动画(如果想使用静态图标就关闭这个)
[url=home.php?mod=space&uid=316553]@opacity[/url] = 255 # ★ 不透明度
@blend_type = 0 # ★ 图片合成方式,默认为0(正常)
@direction = 2 # ★ 朝向,2 4 6 8 分别对应行走图第1 2 3 4 列
@priority_type = 1 # ★ 优先级(默认与人物同级:1)
# ★★★★★★★★★★★★★★★ 参数设置完毕 ★★★★★★★★★★★★★★★★★★★
# 如果 $Arrow.png 不在对应的文件夹内,弹出提示,并使用游戏一张内置的行走图
unless File.exist?('Graphics/Characters/' + @character_name + '.png')
if $no_arrowpic_warn
Mouse::Show_Cursor.call(1)
msgbox('未找到文件:Graphics\Characters\\' + @character_name + '.png
“路径指示点”将使用游戏自带图片
该提示可以在脚本内关闭')
Mouse::Show_Cursor.call(0)
$no_arrowpic_warn = false
end
@character_name = '!Flame'
@character_index = 6
end
@direction_fix = false # 固定朝向
@move_frequency = 6 # 移动频率
@walk_anime = true # 步行动画
@pattern = 1 # 图案
@through = true # 穿透
@bush_depth = 0 # 草木深度
@animation_id = 0 # 动画 ID
@balloon_id = 0 # 心情 ID
@transparent = true # 透明
@id = 0
@x = 0
@y = 0
@real_x = 0
@real_y = 0
@tile_id = 0
end
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :direction
end
#==============================================================================
# ■ Module Mouse
#==============================================================================
module Mouse
#--------------------------------------------------------------------------
# ● API
#--------------------------------------------------------------------------
Show_Cursor = Win32API.new('user32', 'ShowCursor', 'i', 'l')
Get_Cursor_Pos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
Set_Cursor_Pos = Win32API.new('user32', 'SetCursorPos', 'ii', 'l')
Screen_To_Client = Win32API.new('user32', 'ScreenToClient', 'ip', 'i')
Get_Active_Window = Win32API.new('user32', 'GetActiveWindow', nil, 'l')
Clip_Cursor = Win32API.new('user32', 'ClipCursor', 'p', 'l')
Get_Key_State = Win32API.new('user32', 'GetKeyState', 'i', 'i')
Window_Hwnd = Get_Active_Window.call
class << self
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def init
lock_mouse_in_screen if KsOfSion::Clip_Cursor
@left_state = 0
@right_state = 0
@ck_count = 0 # 帧数计,单击以后从0开始
@dk_count = 0 # 用于双击的判定
@clicked = false
creat_mouse_sprite
update
end
#--------------------------------------------------------------------------
# ● 鼠标指针精灵
#--------------------------------------------------------------------------
def creat_mouse_sprite
@mouse_sprite = Sprite.new
if File.exist?('Graphics/System/Cursor.png')
@mouse_sprite.bitmap = Bitmap.new('Graphics/System/Cursor')
else
if $no_arrowpic_warn
msgbox('未找到文件:Graphics\System\Cursor.png
“鼠标指针”将使用游戏自带图片
该提示可以在脚本内关闭')
end
@mouse_sprite.bitmap = Bitmap.new(24, 24)
@mouse_sprite.bitmap.blt(0, 0, Cache.system('Iconset'),
Rect.new(5 * 24, 24 * 24, 24, 24))
end
@mouse_sprite.z = 9999
Show_Cursor.call(0)
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
def update
@mouse_sprite.x, @mouse_sprite.y = get_mouse_pos
left_state = Get_Key_State.call(0x01)
left_state[7] == 1 ? @left_state +=1 : @left_state = 0
right_state = Get_Key_State.call(0x02)
right_state[7] == 1 ? @right_state +=1 : @right_state = 0
update_double_click
@left_state == 1 ? @ck_count = 0 : @ck_count += 1
end
#--------------------------------------------------------------------------
# ● 获取鼠标坐标
#--------------------------------------------------------------------------
def get_mouse_pos
arg = [0, 0].pack('ll')
Get_Cursor_Pos.call(arg)
Screen_To_Client.call(Window_Hwnd, arg)
x, y = arg.unpack('ll')
return x, y
end
#--------------------------------------------------------------------------
# ● 将鼠标固定在屏幕内
#--------------------------------------------------------------------------
def lock_mouse_in_screen
arg = [0, 0].pack('ll')
Screen_To_Client.call(Window_Hwnd, arg)
x, y = arg.unpack('ll')
Clip_Cursor.call([-x, -y, Graphics.width-x, Graphics.height-y].pack('llll'))
end
#--------------------------------------------------------------------------
# ● 解除鼠标固定
#--------------------------------------------------------------------------
def unlock_mouse_in_screen
Clip_Cursor.call(0)
end
#--------------------------------------------------------------------------
# ● 鼠标双击判定
#--------------------------------------------------------------------------
def update_double_click
@clicked = true if @left_state == 1
if @dk_count > 0 && @left_state == 1
@dk_count = 0; @clicked = false
return @double_click = true
elsif @clicked
if @dk_count < KsOfSion::Dbclick_Frame
@dk_count += 1
else
@dk_count = 0; @clicked = false
end
end
@double_click = false
end
#--------------------------------------------------------------------------
# ● 按键被按下就返回true
#--------------------------------------------------------------------------
def press?(button)
case button
when 0x01; return !@left_state.zero?
when 0x02; return !@right_state.zero?
end
return false
end
#--------------------------------------------------------------------------
# ● 按键刚被按下则返回true
#--------------------------------------------------------------------------
def trigger?(button)
case button
when 0x01; return @left_state == 1
when 0x02; return @right_state == 1
end
return false
end
#--------------------------------------------------------------------------
# ● 持续按住键一段时间的话,每隔5帧返回一次true
#--------------------------------------------------------------------------
def repeat?(button)
case button
when 0x01; return @left_state == 1 ||
(@left_state > 22 && (@left_state % 6).zero?)
when 0x02; return @right_state == 1 ||
(@right_state > 22 && (@right_state % 6).zero?)
end
return false
end
#--------------------------------------------------------------------------
# ● 判断是否双击鼠标
#--------------------------------------------------------------------------
def double_click?
@double_click
end
#--------------------------------------------------------------------------
# ● 获取@ck_count(每一帧+=1,单击后重置为0)
#--------------------------------------------------------------------------
def click_count
@ck_count
end
#--------------------------------------------------------------------------
# ● 获取@left_state(按住左键每一帧+=1)
#--------------------------------------------------------------------------
def left_state
@left_state
end
#--------------------------------------------------------------------------
# ● 获取鼠标的x坐标
#--------------------------------------------------------------------------
def mouse_x
@mouse_sprite.x
end
#--------------------------------------------------------------------------
# ● 获取鼠标的y坐标
#--------------------------------------------------------------------------
def mouse_y
@mouse_sprite.y
end
#--------------------------------------------------------------------------
# ● 设置鼠标坐标
#--------------------------------------------------------------------------
def set_mouse_pos(new_x, new_y)
arg = [0, 0].pack('ll')
Screen_To_Client.call(Window_Hwnd, arg)
x, y = arg.unpack('ll')
Set_Cursor_Pos.call(new_x - x, new_y - y)
end
end #end of: class << self
end
#==============================================================================
# ■ SceneManager
#==============================================================================
class << SceneManager
#--------------------------------------------------------------------------
# ● alias
#--------------------------------------------------------------------------
unless self.method_defined?(:sion_mouse_run)
alias_method :sion_mouse_run, :run
alias_method :sion_mouse_call, :call
alias_method :sion_mouse_return, :return
end
#--------------------------------------------------------------------------
# ● 运行
#--------------------------------------------------------------------------
def run
Mouse.init
sion_mouse_run
end
#--------------------------------------------------------------------------
# ● 切换
#--------------------------------------------------------------------------
def call(scene_class)
$game_map.prepare_reset_mouse_pos if @scene.instance_of?(Scene_Map)
sion_mouse_call(scene_class)
end
#--------------------------------------------------------------------------
# ● 返回到上一个场景
#--------------------------------------------------------------------------
def return
sion_mouse_return
$game_map.reset_mouse_pos if KsOfSion::Menu_Set_Pos &&
@scene.instance_of?(Scene_Map)
end
end
#==============================================================================
# ■ Module Input
#==============================================================================
class << Input
#--------------------------------------------------------------------------
# ● alias
#--------------------------------------------------------------------------
unless self.method_defined?(:sion_mouse_update)
alias_method :sion_mouse_update, :update
alias_method :sion_mouse_press?, :press?
alias_method :sion_mouse_trigger?, :trigger?
alias_method :sion_mouse_repeat?, :repeat?
end
#--------------------------------------------------------------------------
# ● 更新鼠标
#--------------------------------------------------------------------------
def update
Mouse.update
sion_mouse_update
end
#--------------------------------------------------------------------------
# ● 按键被按下就返回true
#--------------------------------------------------------------------------
def press?(key)
return true if sion_mouse_press?(key)
return Mouse.press?(0x01) if key == :C
return Mouse.press?(0x02) if key == :B
return false
end
#--------------------------------------------------------------------------
# ● 按键刚被按下则返回true
#--------------------------------------------------------------------------
def trigger?(key)
return true if sion_mouse_trigger?(key)
return Mouse.trigger?(0x01) if key == :C
return Mouse.trigger?(0x02) if key == :B
return false
end
#--------------------------------------------------------------------------
# ● 持续按住键一段时间的话,每隔5帧返回一次true
#--------------------------------------------------------------------------
def repeat?(key)
return true if sion_mouse_repeat?(key)
return Mouse.repeat?(0x01) if key == :C
return Mouse.repeat?(0x02) if key == :B
return false
end
end
#==============================================================================
# ■ Window_Selectable
#------------------------------------------------------------------------------
# 拥有光标移动、滚动功能的窗口
#==============================================================================
class Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
alias sion_mouse_initialize initialize
def initialize(x, y, width, height)
sion_mouse_initialize(x, y, width, height)
@move_state = 0
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
alias sion_mouse_update update
def update
sion_mouse_update
update_mouse_cursor
end
#--------------------------------------------------------------------------
# ● 启动后设置鼠标到index位置
#--------------------------------------------------------------------------
def activate
@need_set_pos = true if KsOfSion::Menu_Set_Pos
super
end
#--------------------------------------------------------------------------
# ● 更新鼠标和光标的位置
#--------------------------------------------------------------------------
def update_mouse_cursor
if active
if @need_set_pos
@need_set_pos = nil
set_mouse_pos
elsif cursor_movable?
Input.dir4.zero? ? set_cursor : set_mouse_pos
end
end
end
#--------------------------------------------------------------------------
# ● 将光标设置到鼠标所在的位置,附带卷动菜单的功能
#--------------------------------------------------------------------------
def set_cursor
mouse_row, mouse_col = mouse_window_area
if mouse_row == -1
@move_state += 1 if need_scroll?
cursor_up if (@move_state - 1) % 4 == 0 && !is_horzcommand?
elsif mouse_row == -2
@move_state += 1 if need_scroll?
cursor_down if (@move_state - 1) % 4 == 0 && !is_horzcommand?
elsif mouse_col == -1
@move_state += 1 if need_scroll?
cursor_left if (@move_state - 1) % 16 == 0 && is_horzcommand?
elsif mouse_col == -2
@move_state += 1 if need_scroll?
cursor_right if (@move_state - 1) % 16 == 0 && is_horzcommand?
else
@move_state = 0
new_index = (top_row + mouse_row) * col_max + mouse_col
select(new_index) if new_index < item_max && new_index != @index
end
end
#--------------------------------------------------------------------------
# ● 判断鼠标位于菜单的第几行、第几列
#--------------------------------------------------------------------------
def mouse_window_area
if viewport.nil? # necessary!
vp_x, vp_y = 0, 0
else
vp_x = viewport.rect.x - viewport.ox
vp_y = viewport.rect.y - viewport.oy
end
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
item_x1 = vp_x + x + standard_padding
item_y1 = vp_y + y + standard_padding
item_x2 = vp_x + x - standard_padding + width
item_y2 = vp_y + y - standard_padding + height
if mouse_x < item_x1
mouse_col = -1
elsif mouse_x > item_x2
mouse_col = -2
else
mouse_col = col_max * (mouse_x - item_x1) / (item_x2 - item_x1)
end
if mouse_y < item_y1
mouse_row = -1
elsif mouse_y > item_y2
mouse_row = -2
else
mouse_row = page_row_max * (mouse_y - item_y1 - 1) / (item_y2 - item_y1)
end
return mouse_row, mouse_col
end
#--------------------------------------------------------------------------
# ● 方向键移动光标时将鼠标移动到对应的光标位置
#--------------------------------------------------------------------------
def set_mouse_pos
if viewport.nil? # necessary!
vp_x, vp_y = 0, 0
else
vp_x = viewport.rect.x - viewport.ox
vp_y = viewport.rect.y - viewport.oy
end
item_x1 = vp_x + x + standard_padding
item_y1 = vp_y + y + standard_padding
get_index = [url=home.php?mod=space&uid=370741]@Index[/url] < 0 ? 0 : @index
row = get_index / col_max - top_row
col = get_index % col_max
new_x = item_x1 + item_width * (col + 0.5)
new_y = item_y1 + item_height * (row + 0.5)
Mouse.set_mouse_pos(new_x, new_y)
end
#--------------------------------------------------------------------------
# ● 判断菜单是否需要卷动
#--------------------------------------------------------------------------
def need_scroll?
item_max > col_max * page_row_max
end
#--------------------------------------------------------------------------
# ● 判断是否为水平卷动菜单
#--------------------------------------------------------------------------
def is_horzcommand?
return false
end
end
class Window_HorzCommand
#--------------------------------------------------------------------------
# ● 判断是否为水平卷动菜单
#--------------------------------------------------------------------------
def is_horzcommand?
return true
end
end
#==============================================================================
# ■ Window_NameInput
#------------------------------------------------------------------------------
# 名字输入画面中,选择文字的窗口。
#==============================================================================
class Window_NameInput
#--------------------------------------------------------------------------
# ● 设置列数
#--------------------------------------------------------------------------
def col_max
return 10
end
#--------------------------------------------------------------------------
# ● 设置填充的Item个数
#--------------------------------------------------------------------------
def item_max
return 90
end
#--------------------------------------------------------------------------
# ● 设置填充的Item个数
#--------------------------------------------------------------------------
def item_width
return 32
end
#--------------------------------------------------------------------------
# ● 判断鼠标位于菜单的第几行、第几列
#--------------------------------------------------------------------------
def mouse_window_area
if viewport.nil?
vp_x, vp_y = 0, 0
else
vp_x = viewport.rect.x - viewport.ox
vp_y = viewport.rect.y - viewport.oy
end
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
item_x1 = vp_x + x + standard_padding
item_y1 = vp_y + y + standard_padding
item_x2 = vp_x + x - standard_padding + width
item_y2 = vp_y + y - standard_padding + height
if mouse_x < item_x1
mouse_col = -1
elsif mouse_x > item_x2
mouse_col = -2
elsif mouse_x < item_x1 + 160
mouse_col = (mouse_x - item_x1)/32
elsif mouse_x > item_x2 - 160
mouse_col = 9 - (item_x2 - mouse_x)/32
else
mouse_col = mouse_x > x + width/2 ? 5 : 4
end
if mouse_y < item_y1
mouse_row = -1
elsif mouse_y > item_y2
mouse_row = -2
else
mouse_row = page_row_max * (mouse_y - item_y1 - 1)/(item_y2 - item_y1)
end
return mouse_row, mouse_col
end
#--------------------------------------------------------------------------
# ● 方向键移动光标时将鼠标移动到对应的光标位置
#--------------------------------------------------------------------------
def set_mouse_pos
if viewport.nil? # necessary!
vp_x, vp_y = 0, 0
else
vp_x = viewport.rect.x - viewport.ox
vp_y = viewport.rect.y - viewport.oy
end
item_x1 = vp_x + x + standard_padding
item_y1 = vp_y + y + standard_padding
get_index = @index < 0 ? 0 : @index
row = get_index / col_max - top_row
col = get_index % col_max
new_x = item_x1 + item_width * (col + 0.5)
new_y = item_y1 + item_height * (row + 0.5)
new_x += 14 if col > 4
Mouse.set_mouse_pos(new_x, new_y)
end
end
#==============================================================================
# ■ Window_NumberInput
#------------------------------------------------------------------------------
# 重写了数值输入的方法以适应鼠标
#==============================================================================
class Window_NumberInput < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :extra_window
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
alias sion_mouse_initialize initialize
def initialize(arg)
sion_mouse_initialize(arg)
create_extra_window
end
#--------------------------------------------------------------------------
# ● 启动
#--------------------------------------------------------------------------
alias sion_mouse_start start
def start
sion_mouse_start
deactivate
extra_start
end
#--------------------------------------------------------------------------
# ● 创建新的数值输入窗口
#--------------------------------------------------------------------------
def create_extra_window
@extra_window = Window_NumberInput_Ex.new
@extra_window.x = (Graphics.width - @extra_window.width) / 2
@extra_window.number_proc = Proc.new {|n| [url=home.php?mod=space&uid=27178]@Number[/url] = n }
@extra_window.index_proc = Proc.new {|n| @index = n }
@extra_window.close_proc = Proc.new { close }
@extra_window.refresh_proc = Proc.new { refresh }
end
#--------------------------------------------------------------------------
# ● 激活新窗口
#--------------------------------------------------------------------------
def extra_start
case $game_message.position
when 0; @extra_window.y = y + height + 4
when 1; @extra_window.y = @message_window.y - @extra_window.height - 8
when 2; @extra_window.y = y - @extra_window.height - 4
else ; @extra_window.y = 8
end
@extra_window.variable_id = $game_message.num_input_variable_id
@extra_window.digits_max = @digits_max
@extra_window.number = @number
@extra_window.open
@extra_window.activate
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
def update
super
@extra_window.update
update_cursor
end
#--------------------------------------------------------------------------
# ● 关闭窗口
#--------------------------------------------------------------------------
def close
super
@extra_window.close
@extra_window.deactivate
end
end
#==============================================================================
# ■ Window_NumberInput_Ex
#------------------------------------------------------------------------------
# 新的数值输入窗口(NewClass)
#==============================================================================
class Window_NumberInput_Ex < Window_Selectable
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :number_proc
attr_accessor :index_proc
attr_accessor :close_proc
attr_accessor :refresh_proc
attr_accessor :number
attr_accessor :digits_max
attr_accessor :variable_id
#--------------------------------------------------------------------------
# ● 数字表
#--------------------------------------------------------------------------
TABLE = [ 7, 8, 9,
4, 5, 6,
1, 2, 3,
'←',0,'确定',]
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(0, 0, 120, fitting_height(4))
self.openness = 0
@index = 0
@number = 0
@old_window_index = 0
@digits_max = 0
12.times {|i| draw_text(item_rect(i), TABLE[i], 1) }
end
#--------------------------------------------------------------------------
# ● 获取项目的绘制矩形
#--------------------------------------------------------------------------
def item_rect(index)
rect = Rect.new
rect.x = index % 3 * 32
rect.y = index / 3 * line_height
rect.width = 32
rect.height = line_height
return rect
end
#--------------------------------------------------------------------------
# ● 将光标设置到鼠标所在的位置
#--------------------------------------------------------------------------
def set_cursor
mouse_row, mouse_col = mouse_window_area
if mouse_row >= 0 && mouse_col >= 0
new_index = mouse_row * 3 + mouse_col
select(new_index) if new_index <= 11
end
end
#--------------------------------------------------------------------------
# ● 判断鼠标位于新数值输入窗口的第几行、第几列
#--------------------------------------------------------------------------
def mouse_window_area
if viewport.nil?
vp_x, vp_y = 0, 0
else
vp_x = viewport.rect.x - viewport.ox
vp_y = viewport.rect.y - viewport.oy
end
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
item_x1 = vp_x + x + standard_padding
item_y1 = vp_y + y + standard_padding
item_x2 = vp_x + x - standard_padding + width
item_y2 = vp_y + y - standard_padding + height
if mouse_x < item_x1
mouse_col = -1
elsif mouse_x > item_x2
mouse_col = -2
else
mouse_col = (mouse_x - item_x1) / 32
end
if mouse_y < item_y1
mouse_row = -1
elsif mouse_y > item_y2
mouse_row = -2
else
mouse_row = 4 * (mouse_y - item_y1 - 1) / (item_y2 - item_y1)
end
return mouse_row, mouse_col
end
#--------------------------------------------------------------------------
# ● 获取文字
#--------------------------------------------------------------------------
def get_number
return false if @index == 9 || @index == 11
return TABLE[@index]
end
#--------------------------------------------------------------------------
# ● 判定光标位置是否在“退格”上
#--------------------------------------------------------------------------
def is_delete?
@index == 9
end
#--------------------------------------------------------------------------
# ● 判定光标位置是否在“确定”上
#--------------------------------------------------------------------------
def is_ok?
@index == 11
end
#--------------------------------------------------------------------------
# ● 更新光标
#--------------------------------------------------------------------------
def update_cursor
cursor_rect.set(item_rect(@index))
end
#--------------------------------------------------------------------------
# ● 判定光标是否可以移动
#--------------------------------------------------------------------------
def cursor_movable?
active
end
#--------------------------------------------------------------------------
# ● 光标向下移动
# wrap : 允许循环
#--------------------------------------------------------------------------
def cursor_down(wrap)
if @index < 9 or wrap
@index = (index + 3) % 12
end
end
#--------------------------------------------------------------------------
# ● 光标向上移动
# wrap : 允许循环
#--------------------------------------------------------------------------
def cursor_up(wrap)
if @index >= 3 or wrap
@index = (index + 9) % 12
end
end
#--------------------------------------------------------------------------
# ● 光标向右移动
# wrap : 允许循环
#--------------------------------------------------------------------------
def cursor_right(wrap)
if @index % 3 < 2
@index += 1
elsif wrap
@index -= 2
end
end
#--------------------------------------------------------------------------
# ● 光标向左移动
# wrap : 允许循环
#--------------------------------------------------------------------------
def cursor_left(wrap)
if @index % 3 > 0
@index -= 1
elsif wrap
@index += 2
end
end
#--------------------------------------------------------------------------
# ● 处理光标的移动
#--------------------------------------------------------------------------
def process_cursor_move
super
update_cursor
end
#--------------------------------------------------------------------------
# ● “确定”、“删除字符”和“取消输入”的处理
#--------------------------------------------------------------------------
def process_handling
return unless open? && active
process_jump if Input.trigger?(:A)
process_back if Input.repeat?(:B)
process_ok if Input.trigger?(:C)
end
#--------------------------------------------------------------------------
# ● 跳转“确定”
#--------------------------------------------------------------------------
def process_jump
if @index != 11
@index = 11
Sound.play_cursor
end
end
#--------------------------------------------------------------------------
# ● 后退一个字符
#--------------------------------------------------------------------------
def process_back
Sound.play_cancel
place = 10 ** (@digits_max - 1 - @old_window_index)
n = (@number / place) % 10
@number -= n * place
@number_proc.call(@number)
@old_window_index -= 1 if @old_window_index > 0
@index_proc.call(@old_window_index)
@refresh_proc.call
end
#--------------------------------------------------------------------------
# ● 按下确定键时的处理
#--------------------------------------------------------------------------
def process_ok
if get_number
Sound.play_cursor
place = 10 ** (@digits_max - 1 - @old_window_index)
n = get_number - (@number / place) % 10
@number += n * place
@number_proc.call(@number)
@old_window_index += 1 if @old_window_index < @digits_max - 1
@index_proc.call(@old_window_index)
@refresh_proc.call
elsif is_delete?
process_back
elsif is_ok?
on_input_ok
end
end
#--------------------------------------------------------------------------
# ● 确定
#--------------------------------------------------------------------------
def on_input_ok
@index = 0
@old_window_index = 0
$game_variables[@variable_id] = @number
Sound.play_ok
@close_proc.call
end
#--------------------------------------------------------------------------
# ● 方向键移动光标时将鼠标移动到对应的光标位置
#--------------------------------------------------------------------------
def set_mouse_pos
if viewport.nil? # necessary!
vp_x, vp_y = 0, 0
else
vp_x = viewport.rect.x - viewport.ox
vp_y = viewport.rect.y - viewport.oy
end
item_x1 = vp_x + x + standard_padding
item_y1 = vp_y + y + standard_padding
get_index = @index < 0 ? 0 : @index
new_x = item_x1 + 32 * (get_index % 3 + 0.5)
new_y = item_y1 + 24 * (get_index / 3 + 0.5)
Mouse.set_mouse_pos(new_x, new_y)
end
end
#==============================================================================
# ■ Window_Message
#------------------------------------------------------------------------------
# 显示文字信息的窗口。
#==============================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ● 处理数值的输入(覆盖原方法)
#--------------------------------------------------------------------------
def input_number
@number_window.start
Fiber.yield while @number_window.extra_window.active
end
end
#==============================================================================
# ■ Window_PartyCommand
#------------------------------------------------------------------------------
# 战斗画面中,选择“战斗/撤退”的窗口。
#==============================================================================
class Window_PartyCommand < Window_Command
#--------------------------------------------------------------------------
# ● 方向键移动光标时将鼠标移动到对应的光标位置
#--------------------------------------------------------------------------
def set_mouse_pos
if viewport.nil?
vp_x, vp_y = 0, 0
else
#vp_x = viewport.rect.x - viewport.ox
vp_y = viewport.rect.y - viewport.oy
end
item_x1 = x + standard_padding
item_y1 = vp_y + y + standard_padding
get_index = @index < 0 ? 0 : @index
row = get_index / col_max - top_row
col = get_index % col_max
new_x = item_x1 + item_width * (col + 0.5)
new_y = item_y1 + item_height * (row + 0.5)
Mouse.set_mouse_pos(new_x, new_y)
end
end
#==============================================================================
# ■ Window_ActorCommand
#------------------------------------------------------------------------------
# 战斗画面中,选择角色行动的窗口。
#==============================================================================
class Window_ActorCommand < Window_Command
#--------------------------------------------------------------------------
# ● 方向键移动光标时将鼠标移动到对应的光标位置
#--------------------------------------------------------------------------
def set_mouse_pos
if viewport.nil?
vp_x, vp_y = 0, 0
else
#vp_x = viewport.rect.x - viewport.ox
vp_y = viewport.rect.y - viewport.oy
end
item_x1 = Graphics.width - width + standard_padding
item_y1 = vp_y + y + standard_padding
get_index = @index < 0 ? 0 : @index
row = get_index / col_max - top_row
col = get_index % col_max
new_x = item_x1 + item_width * (col + 0.5)
new_y = item_y1 + item_height * (row + 0.5)
Mouse.set_mouse_pos(new_x, new_y)
end
end
#==============================================================================
# ■ Game_Player
#------------------------------------------------------------------------------
# 处理玩家人物的类。拥有事件启动的判定、地图的卷动等功能。
# 本类的实例请参考 $game_player 。
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● 由方向移动(覆盖原方法)
#--------------------------------------------------------------------------
def move_by_input
return if !movable? || $game_map.interpreter.running?
if Input.dir4 > 0
move_straight(Input.dir4)
reset_move_path
else
move_by_mouse
end
end
#--------------------------------------------------------------------------
# ● 非移动中的处理(覆盖原方法)
# last_moving : 此前是否正在移动
#--------------------------------------------------------------------------
def update_nonmoving(last_moving)
return if $game_map.interpreter.running?
if last_moving
$game_party.on_player_walk
return if check_touch_event
end
if movable? && Input.trigger?(:C)
return if Mouse.press?(0x01) # 防止按下鼠标左键绘制路径时触发事件或载具切换
return if get_on_off_vehicle
return if check_action_event
end
update_encounter if last_moving
end
#--------------------------------------------------------------------------
# ● 判定是否跑步状态(覆盖原方法)
#--------------------------------------------------------------------------
def dash?
return false if @move_route_forcing
return false if $game_map.disable_dash?
return false if vehicle
return Input.press?(:A) || @mouse_dash
end
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
alias sion_mouse_initialize initialize
def initialize
sion_mouse_initialize
reset_move_path
@moveto_x = 0
@moveto_y = 0
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
alias sion_mouse_update update
def update
sion_mouse_update
clear_unreachable_sign
end
#--------------------------------------------------------------------------
# ● 处理卷动
#--------------------------------------------------------------------------
alias sion_mouse_update_scroll update_scroll
def update_scroll(last_real_x, last_real_y)
return if $game_map.scrolling?
KsOfSion::New_Scroll ? new_update_scroll :
sion_mouse_update_scroll(last_real_x, last_real_y)
end
#--------------------------------------------------------------------------
# ● 重置移动路径相关信息
#--------------------------------------------------------------------------
def reset_move_path
@mouse_dash = false
@mouse_move_path = []
$mouse_move_sign.transparent = true
end
#--------------------------------------------------------------------------
# ● 新的卷动地图方法
#--------------------------------------------------------------------------
def new_update_scroll
horz_speed = 2 ** @move_speed * KsOfSion::Map_Scroll_Spd / Graphics.width
vert_speed = 2 ** @move_speed * KsOfSion::Map_Scroll_Spd / Graphics.height
ax = $game_map.adjust_x(@real_x)
ay = $game_map.adjust_y(@real_y)
$game_map.scroll_down (vert_speed * (ay - center_y)) if ay > center_y
$game_map.scroll_left (horz_speed * (center_x - ax)) if ax < center_x
$game_map.scroll_right(horz_speed * (ax - center_x)) if ax > center_x
$game_map.scroll_up (vert_speed * (center_y - ay)) if ay < center_y
end
#--------------------------------------------------------------------------
# ● 消除不能抵达图标
#--------------------------------------------------------------------------
def clear_unreachable_sign
return if Mouse.press?(0x01)
if $mouse_move_sign.direction == 4 && Mouse.click_count % 20 == 0
$mouse_move_sign.transparent = true
$mouse_move_sign.direction = 2
end
end
#--------------------------------------------------------------------------
# ● 由鼠标移动
#--------------------------------------------------------------------------
def move_by_mouse
unless @mouse_move_path.empty? # 移动路线数组不为空则执行移动
dir = @mouse_move_path.shift
if passable?(x, y, dir) && !@mouse_move_path.empty?
move_straight(dir)
elsif @mouse_move_path.empty? # 判断是否是最后一步
x2 = $game_map.round_x_with_direction(x, dir)
y2 = $game_map.round_y_with_direction(y, dir)
move_straight(dir) unless dir.zero?
unless x == x2 && y == y2 # 如果移动失败,检查是否启动前方事件、上下载具
check_event_trigger_there([0,1,2])
get_on_off_vehicle unless $game_map.setup_starting_event
end
$mouse_move_sign.transparent = true if $mouse_move_sign.direction == 2
@mouse_dash = false
elsif @mouse_move_path[0].zero? # 目标点无法抵达,调整朝向→目标点
@mouse_move_path.shift
@direction = dir
@mouse_dash = false
else
draw_move_path
end
end
end
#--------------------------------------------------------------------------
# ● 地图界面按下鼠标左键的处理
#--------------------------------------------------------------------------
def left_button_action
return if !drawable? || $game_map.interpreter.running?
get_mouse_pos
$mouse_move_sign.moveto(@moveto_x, @moveto_y) # 移动路径点指示图
if @shift_event
if Mouse.trigger?(0x01)
@shift_event.jump(@moveto_x - @shift_event.x,
@moveto_y - @shift_event.y)
@shift_event = nil
end
return
end
if @moveto_x == x && @moveto_y == y # 判断目标点是否与角色重合
return if moving? || (vehicle && !vehicle.movable?)
check_event_trigger_here([0]) # 判断是否触发重合点事件
get_on_off_vehicle if !$game_map.setup_starting_event &&
$game_map.airship.pos?(x, y) # 判断是否要上、下飞艇
return
end
# 判断是否用鼠标启动事件
$game_map.events_xy(@moveto_x, @moveto_y).each do |event|
if event.mouse_start?
reset_move_path
event.start if Mouse.trigger?(0x01)
return
end
end
@mouse_dash = true if Mouse.double_click? # 双击冲刺
return if Mouse.left_state % 10 != 1 # 按住鼠标左键10帧绘制1次路径
for i in 1..4 # 判断目标点是否为角色周围四点
if x == $game_map.round_x_with_direction(@moveto_x, i * 2) &&
y == $game_map.round_y_with_direction(@moveto_y, i * 2)
$mouse_move_sign.transparent = true
@mouse_move_path = [10 - i * 2] if Mouse.trigger?(0x01)
return; end
end
draw_move_path
end
#--------------------------------------------------------------------------
# ● 取得鼠标处对应地图坐标点
#--------------------------------------------------------------------------
def get_mouse_pos
$game_map.get_mouse_map_xy
@moveto_x = $game_map.mouse_map_x
@moveto_y = $game_map.mouse_map_y
#mouse_x, mouse_y = Mouse.get_mouse_pos
#@moveto_x = $game_map.round_x(x + (mouse_x -
# ($game_map.adjust_x(x) * 32 + 16).to_i + 16) / 32)
#@moveto_y = $game_map.round_y(y + 1 + (mouse_y -
# ($game_map.adjust_y(y) * 32 + 16).to_i - 16) / 32)
end
#--------------------------------------------------------------------------
# ● 绘制移动路径 @array[move_directions...]
#--------------------------------------------------------------------------
def draw_move_path
#temp = Time.now
case @vehicle_type
when :walk
draw_walk_path
when :boat
draw_boat_path
when :ship
draw_ship_path
when :airship
draw_air_path
end
#p (Time.now.to_f - temp.to_f) # 测试效率
end
#--------------------------------------------------------------------------
# ● 判定是否可以绘制移动路径
#--------------------------------------------------------------------------
def drawable?
return false if @move_route_forcing || @followers.gathering?
return false if @vehicle_getting_on || @vehicle_getting_off
return false if $game_message.busy? || $game_message.visible
return true
end
#--------------------------------------------------------------------------
# ● 绘制walk移动路径 @array[move_directions...]
#--------------------------------------------------------------------------
def draw_walk_path
# 准备绘制路径表格
sheet = Table.new($game_map.width, $game_map.height)
reversed_chase_path = []; chase_path = []
reversed_chase_point = []; chase_point = []
new_start_points = [x, y]; new_end_points = [@moveto_x, @moveto_y]
sheet[x, y] = 1; sheet[@moveto_x, @moveto_y] = 2
reach_point = false
step = 3
loop do #loop1 开始填充表格
draw_path = false
check_points = new_start_points
new_start_points = []
loop do #loop2 从起点开始正向填充
point_x = check_points.shift
break if point_x == nil
point_y = check_points.shift
left_x = $game_map.round_x(point_x - 1)
right_x = $game_map.round_x(point_x + 1)
up_y = $game_map.round_y(point_y - 1)
down_y = $game_map.round_y(point_y + 1)
# 判断路径是否连通
path_step = step - 1
if sheet[left_x, point_y] == path_step &&
$game_map.passable?(left_x, point_y, 6) &&
$game_map.passable?(point_x, point_y, 4)
chase_path.push(4)
chase_point = [left_x, point_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[right_x, point_y] == path_step &&
$game_map.passable?(right_x, point_y, 4) &&
$game_map.passable?(point_x, point_y, 6)
chase_path.push(6)
chase_point = [right_x, point_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[point_x, up_y] == path_step &&
$game_map.passable?(point_x, up_y, 2) &&
$game_map.passable?(point_x, point_y, 8)
chase_path.push(8)
chase_point = [point_x, up_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[point_x, down_y] == path_step &&
$game_map.passable?(point_x, down_y, 8) &&
$game_map.passable?(point_x, point_y, 2)
chase_path.push(2)
chase_point = [point_x, down_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
end
# 以需要抵达该点的步数填充路径表格 #
if sheet[left_x, point_y] == 0 &&
$game_map.passable?(left_x, point_y, 6) &&
!collide_with_events?(left_x, point_y) &&
$game_map.passable?(point_x, point_y, 4) &&
!collide_with_vehicles?(left_x, point_y) #judge_end
sheet[left_x, point_y] = step
draw_path = true
new_start_points.push(left_x, point_y)
end
if sheet[right_x, point_y] == 0 &&
$game_map.passable?(right_x, point_y, 4) &&
!collide_with_events?(right_x, point_y) &&
$game_map.passable?(point_x, point_y, 6) &&
!collide_with_vehicles?(right_x, point_y)#judge_end
sheet[right_x, point_y] = step
draw_path = true
new_start_points.push(right_x, point_y)
end
if sheet[point_x, up_y] == 0 &&
$game_map.passable?(point_x, up_y, 2) &&
!collide_with_events?(point_x, up_y) &&
$game_map.passable?(point_x, point_y, 8) &&
!collide_with_vehicles?(point_x, up_y) #judge_end
sheet[point_x, up_y] = step
draw_path = true
new_start_points.push(point_x, up_y)
end
if sheet[point_x, down_y] == 0 &&
$game_map.passable?(point_x, down_y, 8) &&
!collide_with_events?(point_x, down_y) &&
$game_map.passable?(point_x, point_y, 2) &&
!collide_with_vehicles?(point_x, down_y) #judge_end
sheet[point_x, down_y] = step
draw_path = true
new_start_points.push(point_x, down_y)
end
end#endOfLoop2
break if !draw_path || reach_point
draw_path = false
check_points = new_end_points
new_end_points = []
step += 1
break if step > KsOfSion::Break_Steps &&
!Input.press?(KsOfSion::Find_Path_Key)
loop do #loop3 从终点开始反向填充
point_x = check_points.shift
break if point_x == nil
point_y = check_points.shift
left_x = $game_map.round_x(point_x - 1)
right_x = $game_map.round_x(point_x + 1)
up_y = $game_map.round_y(point_y - 1)
down_y = $game_map.round_y(point_y + 1)
# 判断路径是否连通
path_step = step - 1
if sheet[left_x, point_y] == path_step &&
$game_map.passable?(left_x, point_y, 6) &&
$game_map.passable?(point_x, point_y, 4)
chase_path.push(6)
chase_point = [point_x, point_y]
reversed_chase_point = [left_x, point_y]
reach_point = true; break
elsif sheet[right_x, point_y] == path_step &&
$game_map.passable?(right_x, point_y, 4) &&
$game_map.passable?(point_x, point_y, 6)
chase_path.push(4)
chase_point = [point_x, point_y]
reversed_chase_point = [right_x, point_y]
reach_point = true; break
elsif sheet[point_x, up_y] == path_step &&
$game_map.passable?(point_x, up_y, 2) &&
$game_map.passable?(point_x, point_y, 8)
chase_path.push(2)
chase_point = [point_x, point_y]
reversed_chase_point = [point_x, up_y]
reach_point = true; break
elsif sheet[point_x, down_y] == path_step &&
$game_map.passable?(point_x, down_y, 8) &&
$game_map.passable?(point_x, point_y, 2)
chase_path.push(8)
chase_point = [point_x, point_y]
reversed_chase_point = [point_x, down_y]
reach_point = true; break
end
# 以需要抵达该点的步数填充路径表格 #
if sheet[left_x, point_y] == 0 &&
$game_map.passable?(left_x, point_y, 6) &&
!collide_with_events?(left_x, point_y) &&
$game_map.passable?(point_x, point_y, 4) &&
!collide_with_vehicles?(left_x, point_y) #judge_end
sheet[left_x, point_y] = step
draw_path = true
new_end_points.push(left_x, point_y)
end
if sheet[right_x, point_y] == 0 &&
$game_map.passable?(right_x, point_y, 4) &&
!collide_with_events?(right_x, point_y) &&
$game_map.passable?(point_x, point_y, 6) &&
!collide_with_vehicles?(right_x, point_y)#judge_end
sheet[right_x, point_y] = step
draw_path = true
new_end_points.push(right_x, point_y)
end
if sheet[point_x, up_y] == 0 &&
$game_map.passable?(point_x, up_y, 2) &&
!collide_with_events?(point_x, up_y) &&
$game_map.passable?(point_x, point_y, 8) &&
!collide_with_vehicles?(point_x, up_y) #judge_end
sheet[point_x, up_y] = step
draw_path = true
new_end_points.push(point_x, up_y)
end
if sheet[point_x, down_y] == 0 &&
$game_map.passable?(point_x, down_y, 8) &&
!collide_with_events?(point_x, down_y) &&
$game_map.passable?(point_x, point_y, 2) &&
!collide_with_vehicles?(point_x, down_y) #judge_end
sheet[point_x, down_y] = step
draw_path = true
new_end_points.push(point_x, down_y)
end
end#endOfLoop3
break if !draw_path || reach_point
step += 1
end #endOfLoop1 路径表格填充完毕
$mouse_move_sign.transparent = false
# 判断指定地点能否抵达
if reach_point
$mouse_move_sign.direction = 2
else
not_reach_point
return
end
# 根据路径表格绘制最短移动路径(反向)
steps = step / 2 * 2 + 1
loop_times = step / 2
point_x, point_y = reversed_chase_point[0], reversed_chase_point[1]
for i in 1..loop_times # forLoop
steps -= 2
if (@moveto_x - point_x).abs < (@moveto_y - point_y).abs #反过来?蛋疼了……
if sheet[$game_map.round_x(point_x - 1), point_y] == steps &&
$game_map.passable?($game_map.round_x(point_x - 1), point_y, 6) &&
$game_map.passable?(point_x, point_y, 4) #judge_end
reversed_chase_path.push(6)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps &&
$game_map.passable?($game_map.round_x(point_x + 1), point_y, 4) &&
$game_map.passable?(point_x, point_y, 6) #judge_end
reversed_chase_path.push(4)
point_x = $game_map.round_x(point_x + 1)
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps &&
$game_map.passable?(point_x, $game_map.round_y(point_y + 1), 8) &&
$game_map.passable?(point_x, point_y, 2) #judge_end
reversed_chase_path.push(8)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps &&
$game_map.passable?(point_x, $game_map.round_y(point_y - 1), 2) &&
$game_map.passable?(point_x, point_y, 8) #judge_end
reversed_chase_path.push(2)
point_y = $game_map.round_y(point_y - 1)
end
else
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps &&
$game_map.passable?(point_x, $game_map.round_y(point_y + 1), 8) &&
$game_map.passable?(point_x, point_y, 2) #judge_end
reversed_chase_path.push(8)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps &&
$game_map.passable?(point_x, $game_map.round_y(point_y - 1), 2) &&
$game_map.passable?(point_x, point_y, 8) #judge_end
reversed_chase_path.push(2)
point_y = $game_map.round_y(point_y - 1)
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps &&
$game_map.passable?($game_map.round_x(point_x - 1), point_y, 6) &&
$game_map.passable?(point_x, point_y, 4) #judge_end
reversed_chase_path.push(6)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps &&
$game_map.passable?($game_map.round_x(point_x + 1), point_y, 4) &&
$game_map.passable?(point_x, point_y, 6) #judge_end
reversed_chase_path.push(4)
point_x = $game_map.round_x(point_x + 1)
end
end
end #endOfForLoop
# 根据路径表格绘制最短移动路径(正向)
steps = step / 2 * 2
loop_times = step / 2
point_x, point_y = chase_point[0], chase_point[1]
for i in 2..loop_times # forLoop
steps -= 2
if (@moveto_x - point_x).abs < (@moveto_y - point_y).abs
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps &&
$game_map.passable?(point_x, $game_map.round_y(point_y + 1), 8) &&
$game_map.passable?(point_x, point_y, 2) #judge_end
chase_path.push(2)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps &&
$game_map.passable?(point_x, $game_map.round_y(point_y - 1), 2) &&
$game_map.passable?(point_x, point_y, 8) #judge_end
chase_path.push(8)
point_y = $game_map.round_y(point_y - 1)
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps &&
$game_map.passable?($game_map.round_x(point_x - 1), point_y, 6) &&
$game_map.passable?(point_x, point_y, 4) #judge_end
chase_path.push(4)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps &&
$game_map.passable?($game_map.round_x(point_x + 1), point_y, 4) &&
$game_map.passable?(point_x, point_y, 6) #judge_end
chase_path.push(6)
point_x = $game_map.round_x(point_x + 1)
end
else
if sheet[$game_map.round_x(point_x - 1), point_y] == steps &&
$game_map.passable?($game_map.round_x(point_x - 1), point_y, 6) &&
$game_map.passable?(point_x, point_y, 4) #judge_end
chase_path.push(4)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps &&
$game_map.passable?($game_map.round_x(point_x + 1), point_y, 4) &&
$game_map.passable?(point_x, point_y, 6) #judge_end
chase_path.push(6)
point_x = $game_map.round_x(point_x + 1)
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps &&
$game_map.passable?(point_x, $game_map.round_y(point_y + 1), 8) &&
$game_map.passable?(point_x, point_y, 2) #judge_end
chase_path.push(2)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps &&
$game_map.passable?(point_x, $game_map.round_y(point_y - 1), 2) &&
$game_map.passable?(point_x, point_y, 8) #judge_end
chase_path.push(8)
point_y = $game_map.round_y(point_y - 1)
end
end
end #endOfForLoop
@mouse_move_path = reversed_chase_path.reverse + chase_path
end#walk
#--------------------------------------------------------------------------
# ● 绘制boat的移动路径 @array[move_directions...]
#--------------------------------------------------------------------------
def draw_boat_path
# 准备绘制路径表格
sheet = Table.new($game_map.width, $game_map.height)
reversed_chase_path = []; chase_path = []
reversed_chase_point = []; chase_point = []
new_start_points = [x, y]; new_end_points = [@moveto_x, @moveto_y]
sheet[x, y] = 1; sheet[@moveto_x, @moveto_y] = 2
reach_point = false
step = 3
loop do #loop1 开始填充表格
draw_path = false
check_points = new_start_points
new_start_points = []
loop do #loop2 从起点开始正向填充
point_x = check_points.shift
break if point_x == nil
point_y = check_points.shift
left_x = $game_map.round_x(point_x - 1)
right_x = $game_map.round_x(point_x + 1)
up_y = $game_map.round_y(point_y - 1)
down_y = $game_map.round_y(point_y + 1)
# 判断路径是否连通
path_step = step - 1
if sheet[left_x, point_y] == path_step
chase_path.push(4)
chase_point = [left_x, point_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[right_x, point_y] == path_step
chase_path.push(6)
chase_point = [right_x, point_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[point_x, up_y] == path_step
chase_path.push(8)
chase_point = [point_x, up_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[point_x, down_y] == path_step
chase_path.push(2)
chase_point = [point_x, down_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
end
# 以需要抵达该点的步数填充路径表格 #
if sheet[left_x, point_y] == 0 &&
$game_map.boat_passable?(left_x, point_y) &&
!collide_with_events?(left_x, point_y) &&
!collide_with_vehicles?(left_x, point_y) #judge_end
sheet[left_x, point_y] = step
draw_path = true
new_start_points.push(left_x, point_y)
end
if sheet[right_x, point_y] == 0 &&
$game_map.boat_passable?(right_x, point_y) &&
!collide_with_events?(right_x, point_y) &&
!collide_with_vehicles?(right_x, point_y) #judge_end
sheet[right_x, point_y] = step
draw_path = true
new_start_points.push(right_x, point_y)
end
if sheet[point_x, up_y] == 0 &&
$game_map.boat_passable?(point_x, up_y) &&
!collide_with_events?(point_x, up_y) &&
!collide_with_vehicles?(point_x, up_y) #judge_end
sheet[point_x, up_y] = step
draw_path = true
new_start_points.push(point_x, up_y)
end
if sheet[point_x, down_y] == 0 &&
$game_map.boat_passable?(point_x, down_y) &&
!collide_with_events?(point_x, down_y) &&
!collide_with_vehicles?(point_x, down_y) #judge_end
sheet[point_x, down_y] = step
draw_path = true
new_start_points.push(point_x, down_y)
end
end#endOfLoop2
break if !draw_path || reach_point
draw_path = false
check_points = new_end_points
new_end_points = []
step += 1
break if step > KsOfSion::Break_Steps &&
!Input.press?(KsOfSion::Find_Path_Key)
loop do #loop3 从终点开始反向填充
point_x = check_points.shift
break if point_x == nil
point_y = check_points.shift
left_x = $game_map.round_x(point_x - 1)
right_x = $game_map.round_x(point_x + 1)
up_y = $game_map.round_y(point_y - 1)
down_y = $game_map.round_y(point_y + 1)
# 判断路径是否连通
path_step = step - 1
if sheet[left_x, point_y] == path_step
chase_path.push(6)
chase_point = [point_x, point_y]
reversed_chase_point = [left_x, point_y]
reach_point = true; break
elsif sheet[right_x, point_y] == path_step
chase_path.push(4)
chase_point = [point_x, point_y]
reversed_chase_point = [right_x, point_y]
reach_point = true; break
elsif sheet[point_x, up_y] == path_step
chase_path.push(2)
chase_point = [point_x, point_y]
reversed_chase_point = [point_x, up_y]
reach_point = true; break
elsif sheet[point_x, down_y] == path_step
chase_path.push(8)
chase_point = [point_x, point_y]
reversed_chase_point = [point_x, down_y]
reach_point = true; break
end
# 以需要抵达该点的步数填充路径表格 #
if sheet[left_x, point_y] == 0 &&
$game_map.boat_passable?(left_x, point_y) &&
!collide_with_events?(left_x, point_y) &&
!collide_with_vehicles?(left_x, point_y) #judge_end
sheet[left_x, point_y] = step
draw_path = true
new_end_points.push(left_x, point_y)
end
if sheet[right_x, point_y] == 0 &&
$game_map.boat_passable?(right_x, point_y) &&
!collide_with_events?(right_x, point_y) &&
!collide_with_vehicles?(right_x, point_y) #judge_end
sheet[right_x, point_y] = step
draw_path = true
new_end_points.push(right_x, point_y)
end
if sheet[point_x, up_y] == 0 &&
$game_map.boat_passable?(point_x, up_y) &&
!collide_with_events?(point_x, up_y) &&
!collide_with_vehicles?(point_x, up_y) #judge_end
sheet[point_x, up_y] = step
draw_path = true
new_end_points.push(point_x, up_y)
end
if sheet[point_x, down_y] == 0 &&
$game_map.boat_passable?(point_x, down_y) &&
!collide_with_events?(point_x, down_y) &&
!collide_with_vehicles?(point_x, down_y) #judge_end
sheet[point_x, down_y] = step
draw_path = true
new_end_points.push(point_x, down_y)
end
end#endOfLoop3
break if !draw_path || reach_point
step += 1
end #endOfLoop1 路径表格填充完毕
$mouse_move_sign.transparent = false
# 判断指定地点能否抵达
if reach_point
$mouse_move_sign.direction = 2
else
not_reach_point
return
end
# 根据路径表格绘制最短移动路径(正向)
steps = step / 2 * 2
loop_times = step / 2
point_x, point_y = chase_point[0], chase_point[1]
for i in 2..loop_times # forLoop
steps -= 2
if (@moveto_x - point_x).abs < (@moveto_y - point_y).abs
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps
chase_path.push(2)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
chase_path.push(8)
point_y = $game_map.round_y(point_y - 1)
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps
chase_path.push(4)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
chase_path.push(6)
point_x = $game_map.round_x(point_x + 1)
end
else
if sheet[$game_map.round_x(point_x - 1), point_y] == steps
chase_path.push(4)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
chase_path.push(6)
point_x = $game_map.round_x(point_x + 1)
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps
chase_path.push(2)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
chase_path.push(8)
point_y = $game_map.round_y(point_y - 1)
end
end
end #endOfForLoop
# 如果指定点无法抵达或者登陆
return not_reach_point unless landable?(@moveto_x, @moveto_y, chase_path)
# 根据路径表格绘制最短移动路径(反向)
steps = step / 2 * 2 + 1
loop_times = step / 2
point_x, point_y = reversed_chase_point[0], reversed_chase_point[1]
for i in 1..loop_times # forLoop
steps -= 2
if (@moveto_x - point_x).abs < (@moveto_y - point_y).abs
if sheet[$game_map.round_x(point_x - 1), point_y] == steps
reversed_chase_path.push(6)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
reversed_chase_path.push(4)
point_x = $game_map.round_x(point_x + 1)
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps
reversed_chase_path.push(8)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
reversed_chase_path.push(2)
point_y = $game_map.round_y(point_y - 1)
end
else
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps
reversed_chase_path.push(8)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
reversed_chase_path.push(2)
point_y = $game_map.round_y(point_y - 1)
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps
reversed_chase_path.push(6)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
reversed_chase_path.push(4)
point_x = $game_map.round_x(point_x + 1)
end
end
end #endOfForLoop
@mouse_move_path = reversed_chase_path.reverse + chase_path
end#boat
#--------------------------------------------------------------------------
# ● 绘制ship的移动路径 @array[move_directions...]
#--------------------------------------------------------------------------
def draw_ship_path
# 准备绘制路径表格
sheet = Table.new($game_map.width, $game_map.height)
reversed_chase_path = []; chase_path = []
reversed_chase_point = []; chase_point = []
new_start_points = [x, y]; new_end_points = [@moveto_x, @moveto_y]
sheet[x, y] = 1; sheet[@moveto_x, @moveto_y] = 2
reach_point = false
step = 3
loop do #loop1 开始填充表格
draw_path = false
check_points = new_start_points
new_start_points = []
loop do #loop2 从起点开始正向填充
point_x = check_points.shift
break if point_x == nil
point_y = check_points.shift
left_x = $game_map.round_x(point_x - 1)
right_x = $game_map.round_x(point_x + 1)
up_y = $game_map.round_y(point_y - 1)
down_y = $game_map.round_y(point_y + 1)
# 判断路径是否连通
path_step = step - 1
if sheet[left_x, point_y] == path_step
chase_path.push(4)
chase_point = [left_x, point_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[right_x, point_y] == path_step
chase_path.push(6)
chase_point = [right_x, point_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[point_x, up_y] == path_step
chase_path.push(8)
chase_point = [point_x, up_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
elsif sheet[point_x, down_y] == path_step
chase_path.push(2)
chase_point = [point_x, down_y]
reversed_chase_point = [point_x, point_y]
reach_point = true; break
end
# 以需要抵达该点的步数填充路径表格 #
if sheet[left_x, point_y] == 0 &&
$game_map.ship_passable?(left_x, point_y) &&
!collide_with_events?(left_x, point_y) &&
!collide_with_vehicles?(left_x, point_y) #judge_end
sheet[left_x, point_y] = step
draw_path = true
new_start_points.push(left_x, point_y)
end
if sheet[right_x, point_y] == 0 &&
$game_map.ship_passable?(right_x, point_y) &&
!collide_with_events?(right_x, point_y) &&
!collide_with_vehicles?(right_x, point_y) #judge_end
sheet[right_x, point_y] = step
draw_path = true
new_start_points.push(right_x, point_y)
end
if sheet[point_x, up_y] == 0 &&
$game_map.ship_passable?(point_x, up_y) &&
!collide_with_events?(point_x, up_y) &&
!collide_with_vehicles?(point_x, up_y) #judge_end
sheet[point_x, up_y] = step
draw_path = true
new_start_points.push(point_x, up_y)
end
if sheet[point_x, down_y] == 0 &&
$game_map.ship_passable?(point_x, down_y) &&
!collide_with_events?(point_x, down_y) &&
!collide_with_vehicles?(point_x, down_y) #judge_end
sheet[point_x, down_y] = step
draw_path = true
new_start_points.push(point_x, down_y)
end
end#endOfLoop2
break if !draw_path || reach_point
draw_path = false
check_points = new_end_points
new_end_points = []
step += 1
break if step > KsOfSion::Break_Steps &&
!Input.press?(KsOfSion::Find_Path_Key)
loop do #loop3 从终点开始反向填充
point_x = check_points.shift
break if point_x == nil
point_y = check_points.shift
left_x = $game_map.round_x(point_x - 1)
right_x = $game_map.round_x(point_x + 1)
up_y = $game_map.round_y(point_y - 1)
down_y = $game_map.round_y(point_y + 1)
# 判断路径是否连通
path_step = step - 1
if sheet[left_x, point_y] == path_step
chase_path.push(6)
chase_point = [point_x, point_y]
reversed_chase_point = [left_x, point_y]
reach_point = true; break
elsif sheet[right_x, point_y] == path_step
chase_path.push(4)
chase_point = [point_x, point_y]
reversed_chase_point = [right_x, point_y]
reach_point = true; break
elsif sheet[point_x, up_y] == path_step
chase_path.push(2)
chase_point = [point_x, point_y]
reversed_chase_point = [point_x, up_y]
reach_point = true; break
elsif sheet[point_x, down_y] == path_step
chase_path.push(8)
chase_point = [point_x, point_y]
reversed_chase_point = [point_x, down_y]
reach_point = true; break
end
# 以需要抵达该点的步数填充路径表格 #
if sheet[left_x, point_y] == 0 &&
$game_map.ship_passable?(left_x, point_y) &&
!collide_with_events?(left_x, point_y) &&
!collide_with_vehicles?(left_x, point_y) #judge_end
sheet[left_x, point_y] = step
draw_path = true
new_end_points.push(left_x, point_y)
end
if sheet[right_x, point_y] == 0 &&
$game_map.ship_passable?(right_x, point_y) &&
!collide_with_events?(right_x, point_y) &&
!collide_with_vehicles?(right_x, point_y) #judge_end
sheet[right_x, point_y] = step
draw_path = true
new_end_points.push(right_x, point_y)
end
if sheet[point_x, up_y] == 0 &&
$game_map.ship_passable?(point_x, up_y) &&
!collide_with_events?(point_x, up_y) &&
!collide_with_vehicles?(point_x, up_y) #judge_end
sheet[point_x, up_y] = step
draw_path = true
new_end_points.push(point_x, up_y)
end
if sheet[point_x, down_y] == 0 &&
$game_map.ship_passable?(point_x, down_y) &&
!collide_with_events?(point_x, down_y) &&
!collide_with_vehicles?(point_x, down_y) #judge_end
sheet[point_x, down_y] = step
draw_path = true
new_end_points.push(point_x, down_y)
end
end#endOfLoop3
break if !draw_path || reach_point
step += 1
end #endOfLoop1 路径表格填充完毕
$mouse_move_sign.transparent = false
# 判断指定地点能否抵达
if reach_point
$mouse_move_sign.direction = 2
else
not_reach_point
return
end
# 根据路径表格绘制最短移动路径(正向)
steps = step / 2 * 2
loop_times = step / 2
point_x, point_y = chase_point[0], chase_point[1]
for i in 2..loop_times # forLoop
steps -= 2
if (@moveto_x - point_x).abs < (@moveto_y - point_y).abs
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps
chase_path.push(2)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
chase_path.push(8)
point_y = $game_map.round_y(point_y - 1)
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps
chase_path.push(4)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
chase_path.push(6)
point_x = $game_map.round_x(point_x + 1)
end
else
if sheet[$game_map.round_x(point_x - 1), point_y] == steps
chase_path.push(4)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
chase_path.push(6)
point_x = $game_map.round_x(point_x + 1)
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps
chase_path.push(2)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
chase_path.push(8)
point_y = $game_map.round_y(point_y - 1)
end
end
end #endOfForLoop
# 如果指定点无法抵达或者登陆
return not_reach_point unless landable?(@moveto_x, @moveto_y, chase_path)
# 根据路径表格绘制最短移动路径(反向)
steps = step / 2 * 2 + 1
loop_times = step / 2
point_x, point_y = reversed_chase_point[0], reversed_chase_point[1]
for i in 1..loop_times # forLoop
steps -= 2
if (@moveto_x - point_x).abs < (@moveto_y - point_y).abs
if sheet[$game_map.round_x(point_x - 1), point_y] == steps
reversed_chase_path.push(6)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
reversed_chase_path.push(4)
point_x = $game_map.round_x(point_x + 1)
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == steps
reversed_chase_path.push(8)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
reversed_chase_path.push(2)
point_y = $game_map.round_y(point_y - 1)
end
else
if sheet[point_x, $game_map.round_y(point_y + 1)] == steps
reversed_chase_path.push(8)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == steps
reversed_chase_path.push(2)
point_y = $game_map.round_y(point_y - 1)
elsif sheet[$game_map.round_x(point_x - 1), point_y] == steps
reversed_chase_path.push(6)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == steps
reversed_chase_path.push(4)
point_x = $game_map.round_x(point_x + 1)
end
end
end #endOfForLoop
@mouse_move_path = reversed_chase_path.reverse + chase_path
end#ship
#--------------------------------------------------------------------------
# ● 绘制airship的移动路径 @array[move_directions...]
#--------------------------------------------------------------------------
def draw_air_path
$mouse_move_sign.transparent = false
# 准备绘制路径表格
sheet = Table.new($game_map.width, $game_map.height)
new_check_point = [x, y]; sheet[x, y] = 1
reach_point = false; step = 2
loop do #loop1
check_point = new_check_point
new_check_point = []
loop do #loop2
point_x = check_point.shift
break if point_x == nil
point_y = check_point.shift
if point_x == @moveto_x && point_y == @moveto_y
reach_point = true; break
end
left_x = $game_map.round_x(point_x - 1)
right_x = $game_map.round_x(point_x + 1)
up_y = $game_map.round_y(point_y - 1)
down_y = $game_map.round_y(point_y + 1)
# 以需要抵达该点的步数填充路径表格 #
if sheet[left_x, point_y] == 0
sheet[left_x, point_y] = step
new_check_point.push(left_x, point_y)
end
if sheet[right_x, point_y] == 0
sheet[right_x, point_y] = step
new_check_point.push(right_x, point_y)
end
if sheet[point_x, up_y] == 0
sheet[point_x, up_y] = step
new_check_point.push(point_x, up_y)
end
if sheet[point_x, down_y] == 0
sheet[point_x, down_y] = step
new_check_point.push(point_x, down_y)
end
end#endOfLoop2
break if reach_point
step += 1
end #endOfLoop1
# 根据路径表格绘制最短移动路径 #
reversed_chase_path = []; step -= 1
point_x, point_y = @moveto_x, @moveto_y
for i in 2..step
step -= 1
if (@moveto_x - point_x).abs < (@moveto_y - point_y).abs
if sheet[$game_map.round_x(point_x - 1), point_y] == step
reversed_chase_path.push(6)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == step
reversed_chase_path.push(4)
point_x = $game_map.round_x(point_x + 1)
elsif sheet[point_x, $game_map.round_y(point_y + 1)] == step
reversed_chase_path.push(8)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == step
reversed_chase_path.push(2)
point_y = $game_map.round_y(point_y - 1)
end
else
if sheet[point_x, $game_map.round_y(point_y + 1)] == step
reversed_chase_path.push(8)
point_y = $game_map.round_y(point_y + 1)
elsif sheet[point_x, $game_map.round_y(point_y - 1)] == step
reversed_chase_path.push(2)
point_y = $game_map.round_y(point_y - 1)
elsif sheet[$game_map.round_x(point_x - 1), point_y] == step
reversed_chase_path.push(6)
point_x = $game_map.round_x(point_x - 1)
elsif sheet[$game_map.round_x(point_x + 1), point_y] == step
reversed_chase_path.push(4)
point_x = $game_map.round_x(point_x + 1)
end
end
end #endOfForLoop
@mouse_move_path = reversed_chase_path.reverse
end#airship
#--------------------------------------------------------------------------
# ● 目标点无法抵达时的处理,用于各路径绘制方法内部
#--------------------------------------------------------------------------
def not_reach_point
$mouse_move_sign.direction = 4
dx = 0; dy = 0; dir = 0
if @moveto_x - x > 0
if @moveto_x - x > $game_map.width - @moveto_x + x &&
$game_map.loop_vertical?
dx = $game_map.width - @moveto_x + x; dir = 4
else
dx = @moveto_x - x; dir = 6
end
else
if x - @moveto_x > $game_map.width - x + @moveto_x &&
$game_map.loop_vertical?
dx = $game_map.width - x + @moveto_x; dir = 6
else
dx = x - @moveto_x; dir = 4
end
end
if @moveto_y - y > 0
if @moveto_y - y > $game_map.height - @moveto_y + y &&
$game_map.loop_horizontal?
dy = $game_map.height - @moveto_y + y
dir = 8 if dy > dx
else
dy = @moveto_y - y
dir = 2 if dy > dx
end
else
if y - @moveto_y > $game_map.height - y + @moveto_y &&
$game_map.loop_horizontal?
dy = $game_map.height - y + @moveto_y
dir = 2 if dy > dx
else
dy = y - @moveto_y
dir = 8 if dy > dx
end
end
@mouse_move_path = [dir, 0] # 0方向用于防止移动过程中触发事件
end
#--------------------------------------------------------------------------
# ● 判断目标点是否能抵达、登陆,用于船只路径绘制
#--------------------------------------------------------------------------
def landable?(x, y, path)
case @vehicle_type
when :ship; return $game_map.ship_passable?(x, y) ||
$game_map.passable?(x, y, 10 - path[-1])
when :boat; return $game_map.boat_passable?(x, y) ||
$game_map.passable?(x, y, 10 - path[-1])
end
end
end
#==============================================================================
# ■ Game_Map
#------------------------------------------------------------------------------
# 管理地图的类。拥有卷动地图以及判断通行度的功能。
# 本类的实例请参考 $game_map 。
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :mouse_map_x # 使用前需先使用 get_mouse_map_xy 方法来更新数据
attr_reader :mouse_map_y # 同上
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
alias sion_mouse_initialize initialize
def initialize
sion_mouse_initialize
creat_move_sign ###
set_constants
end
#--------------------------------------------------------------------------
# ● 更新画面
# main : 事件解释器更新的标志
#--------------------------------------------------------------------------
alias sion_mouse_update update
def update(main = false)
sion_mouse_update(main)
update_move_sign
end
#--------------------------------------------------------------------------
# ● 创建显示路径点的事件
#--------------------------------------------------------------------------
def creat_move_sign
$mouse_move_sign = Move_Sign.new
end
#--------------------------------------------------------------------------
# ● 更新显示路径点的事件
#--------------------------------------------------------------------------
def set_constants
@mouse_pos_setted = true
@set_pos_prepared = false
@mouse_old_x = 0
@mouse_old_y = 0
end
#--------------------------------------------------------------------------
# ● 更新显示路径点的事件
#--------------------------------------------------------------------------
def update_move_sign
$mouse_move_sign.update
end
#--------------------------------------------------------------------------
# ● 获取鼠标位于的地图块的x、y坐标
#--------------------------------------------------------------------------
def get_mouse_map_xy
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
@mouse_map_x = round_x((@display_x + mouse_x / 32.0).to_i)
@mouse_map_y = round_y((@display_y + mouse_y / 32.0).to_i)
end
#--------------------------------------------------------------------------
# ● 返回地图画面时重设鼠标坐标
#--------------------------------------------------------------------------
def reset_mouse_pos
return if @mouse_pos_setted
Mouse.set_mouse_pos(@mouse_old_x, @mouse_old_y)
@mouse_pos_setted = true
@set_pos_prepared = false
end
#--------------------------------------------------------------------------
# ● 重设鼠标的坐标
#--------------------------------------------------------------------------
def prepare_reset_mouse_pos
return if @set_pos_prepared
@mouse_pos_setted = false
@mouse_old_x = Mouse.mouse_x
@mouse_old_y = Mouse.mouse_y
@set_pos_prepared = true
end
end
#==============================================================================
# ■ Spriteset_Map
#------------------------------------------------------------------------------
# 处理地图画面精灵和图块的类。本类在 Scene_Map 类的内部使用。
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# ● 生成路径点精灵
#--------------------------------------------------------------------------
alias sion_mouse_create_characters create_characters
def create_characters
sion_mouse_create_characters
@character_sprites.push(Sprite_Character.new(@viewport1, $mouse_move_sign))
end
end
#==============================================================================
# ■ Scene_Map
#------------------------------------------------------------------------------
# 地图画面
#==============================================================================
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# ● 画面更新
#--------------------------------------------------------------------------
alias sion_mouse_update_scene update_scene
def update_scene
sion_mouse_update_scene
update_mouse_action unless scene_changing?
end
#--------------------------------------------------------------------------
# ● 场所移动前的处理
#--------------------------------------------------------------------------
alias sion_mouse_pre_transfer pre_transfer
def pre_transfer
$game_player.reset_move_path
sion_mouse_pre_transfer
end
#--------------------------------------------------------------------------
# ● 监听鼠标左键的按下
#--------------------------------------------------------------------------
def update_mouse_action
$game_player.left_button_action if Mouse.press?(0x01)
end
end
#==============================================================================
# ■ Scene_File
#------------------------------------------------------------------------------
# 存档画面和读档画面共同的父类
#==============================================================================
class Scene_File < Scene_MenuBase
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
alias sion_mouse_start start
def start
sion_mouse_start
@move_state = 0
set_mouse_pos
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
alias sion_mouse_update update
def update
sion_mouse_update
Input.dir4.zero? ? set_cursor : set_mouse_pos
end
#--------------------------------------------------------------------------
# ● 更新光标
#--------------------------------------------------------------------------
def set_cursor
@move_state += 1
last_index = @index
if mouse_which_window == -2
if (@move_state - 1) % 6 == 0
@index = (@index + 1) % item_max if @index < item_max - 1
end
elsif mouse_which_window == -1
if (@move_state - 1) % 6 == 0
@index = (@index - 1 + item_max) % item_max if @index > 0
end
else
@move_state = 0
@index = top_index + mouse_which_window
end
ensure_cursor_visible
if @index != last_index
@savefile_windows[last_index].selected = false
@savefile_windows[@index].selected = true
end
end
#--------------------------------------------------------------------------
# ● 判断鼠标位于哪个窗口
#--------------------------------------------------------------------------
def mouse_which_window
mouse_x, mouse_y = Mouse.mouse_x, Mouse.mouse_y
if mouse_y < @help_window.height + 14
mouse_row = -1
elsif mouse_y > Graphics.height - 14
mouse_row = -2
else
mouse_row = 4 * (mouse_y - @help_window.height) /
(Graphics.height - @help_window.height)
end
return mouse_row
end
#--------------------------------------------------------------------------
# ● 方向键移动光标时将鼠标移动到对应的光标位置
#--------------------------------------------------------------------------
def set_mouse_pos
new_x = 40
new_y = @help_window.height + savefile_height * (@index - top_index) + 24
Mouse.set_mouse_pos(new_x, new_y)
end
end
#==============================================================================
# ■ Game_Event
#------------------------------------------------------------------------------
# 处理事件的类。拥有条件判断、事件页的切换、并行处理、执行事件等功能。
# 在 Game_Map 类的内部使用。
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# ● 事件启动
#--------------------------------------------------------------------------
alias sion_mouse_start start
def start
return if mouse_start? && !Mouse.press?(0x01)
sion_mouse_start
end
#--------------------------------------------------------------------------
# ● 判断事件是否由鼠标启动
#--------------------------------------------------------------------------
def mouse_start?
return false if empty?
@list.each do |index|
return true if (index.code == 108 || index.code == 408) &&
index.parameters[0].include?('鼠标启动')
end
return false
end
end
####泥煤的height
# @height = height
class Area_Response
attr_accessor :type
attr_reader :ox
attr_reader :oy
attr_reader :width
attr_reader :height
attr_reader :switch_id
def initialize(type, ox, oy, width = 32, height = 32, switch_id = nil)
@type = type
@ox = ox
@oy = oy
@width = width
@height = height
@switch_id = switch_id
end
end
$area_responses = []
class Scene_Map
alias update_mouse_2013421 update_mouse_action
def update_mouse_action
update_area_response
update_mouse_2013421
end
def update_area_response
responses = $area_responses
responses.each {|response|
ox = response.ox
oy = response.oy
width = response.width
height = response.height
switch_id = response.switch_id
case response.type
when 0
if mouse_in_area?(ox, oy, width, height)
$game_switches[switch_id] = true
$area_responses.delete(response)
end
when 1
if mouse_in_area?(ox, oy, width, height) && Mouse.trigger?(0x01)
$game_switches[switch_id] = true
$area_responses.delete(response)
end
when 2
if mouse_in_area?(ox, oy, width, height)
$game_switches[switch_id] = true
else
$game_switches[switch_id] = false
end
when 3
if mouse_in_area?((ox - $game_map.display_x) * 32 ,
(oy - $game_map.display_y) * 32, width, height)
$game_map.events_xy(ox, oy).each {|event|
event.start
$area_responses.delete(response)
return
}
end
when 4
if mouse_in_area?((ox - $game_map.display_x) * 32,
(oy - $game_map.display_y) * 32, width, height)
$game_map.events_xy(ox, oy).each {|event|
event.start
return
}
end
end
}
end
def mouse_in_area?(ox, oy, width, height)
Mouse.mouse_x >= ox && Mouse.mouse_x <= ox + width &&
Mouse.mouse_y >= oy && Mouse.mouse_y <= oy + height
end
end
class Game_Interpreter
def area_response(*arg)
$area_responses.push(Area_Response.new(*arg))
end
end