赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 7282 |
最后登录 | 2015-3-1 |
在线时间 | 135 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 135 小时
- 注册时间
- 2012-6-14
- 帖子
- 43
|
7楼
楼主 |
发表于 2013-8-28 09:21:53
|
只看该作者
感谢上面的热情回复
对话选项要求只是我比较习惯这样的...
地图选项是希望能加快游戏进程...
实际上这两个功能并非主要功能...我主要还是要做RPG游戏阿XD
@tseyik
这个鼠标脚本跟我的标题脚本相冲...
而且常常按了没反应OTZ
其实我本来就有一个鼠标脚本了...
能不能就单独把那个判断地图按钮的功能独立出来呢?
又或者可以麻烦帮我看看我在用的鼠标脚本有没有类似的功能吗?
因为看到您提供的脚本我才知道脚本有可能有这功能...
可是我看不懂...找不出来- =begin #=======================================================================
- Sion Mouse System v1.3e
-
- Changlog
-
- 2013.4.21 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 = true # ★ 設置為false不彈出圖片缺失提示
- #==============================================================================
- # ■ 常數設置
- #==============================================================================
- module KsOfSion
- Clip_Cursor = true # ★ 滑鼠鎖定在遊戲視窗內,需要關閉設置為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 = 8 # ★ 踏步速度
- @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
复制代码 我看不懂脚本...也只能拜托各位了 |
|