#==============================================================================
# 〓 鼠标点击自寻路 〓 Integration: 芯☆淡茹水
#==============================================================================
# 鼠标脚本,来自 [url]www.66RPG.com[/url] , 未署名。
#==============================================================================
# GET事件的名字
class Game_Event < Game_Character
def scname
@event.name
end
end
#==============================================================================
class Game_Temp; attr_accessor :move_position; end
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
def distance(x1, y1, x2, y2)
return delta_x(x1, x2).abs + delta_y(y1, y2).abs
end
#--------------------------------------------------------------------------
def loop_horizontal?
return false
end
#--------------------------------------------------------------------------
def loop_vertical?
return false
end
#--------------------------------------------------------------------------
def delta_x(x1, x2)
result = x1 - x2
if loop_horizontal? && result.abs > width / 2
result += result < 0 ? width : -width
end
return result
end
#--------------------------------------------------------------------------
def delta_y(y1, y2)
result = y1 - y2
if loop_vertical? && result.abs > height / 2
result += result < 0 ? height : -height
end
return result
end
end
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
alias xr_mv_initialize initialize
def initialize
xr_mv_initialize
@search_limit = 99
end
#--------------------------------------------------------------------------
def delta_x_from(x)
return $game_map.delta_x(@x, x)
end
#--------------------------------------------------------------------------
def delta_y_from(y)
return $game_map.delta_y(@y, y)
end
#--------------------------------------------------------------------------
def move_straight(direction)
return if direction == 0
@direction = direction
passable?(@x, @y, direction) && move_forward
end
#--------------------------------------------------------------------------
# 判断是否有阻障
def is_block?(sc_x, sc_y, *sc_arg)
$game_map.events.each do |key, value|
if sc_x == value.x and sc_y == value.y and sc_arg.include?(value.scname)
return false
end
end
return true
end
#--------------------------------------------------------------------------
def find_direction(x, y)
return 0 if @x == x && @y == y
goal_x = x; goal_y = y
map_width = $game_map.width
node_list = []; open_list = []; closed_list = []
start = {}; best = start
start[:parent] = nil; start[:x] = @x; start[:y] = @y; start[:g] = 0
start[:xr] = $game_map.distance(start[:x], start[:y], goal_x, goal_y);
node_list.push(start)
open_list.push(start[:y] * map_width + start[:x])
while node_list.size > 0
best_index = 0
node_list.size.times do |i|
best_index = i if node_list[i][:xr] < node_list[best_index][:xr]
end
current = node_list[best_index]
x1 = current[:x]; y1 = current[:y]
pos1 = y1 * map_width + x1
g1 = current[:g]
node_list.delete(current)
open_list.delete(pos1)
closed_list << pos1
if current[:x] == goal_x && current[:y] == goal_y
best = current
break
end
next if g1 >= @search_limit
4.times do |j|
direction = 2 + j * 2
x2 = x1 + (direction == 6 ? 1 : direction == 4 ? -1 : 0)
y2 = y1 + (direction == 2 ? 1 : direction == 8 ? -1 : 0)
pos2 = y2 * map_width + x2
x3 = x1 + (direction == 6 ? -1 : direction == 4 ? 1 : 0)
y3 = y1 + (direction == 2 ? -1 : direction == 8 ? 1 : 0)
next if !is_block?(x1, y1, "上楼") && is_block?(start[:x], start[:y], "上楼")
next if !is_block?(x1, y1, "下楼") && is_block?(start[:x], start[:y], "下楼")
next if closed_list.include?(pos2)
next if (!passable?(x1, y1, direction))
=begin
if (!passable?(x1, y1, direction)) and ((x2 != x) or (y2 != y)) and
((x3 != x) or (y3 != y))
next
end
=end
g2 = g1 + 1
index2 = open_list.index(pos2)
if index2 == nil || g2 < node_list[index2][:g]
if index2 != nil
neighbor = node_list[index2]
else
neighbor = {}; node_list << neighbor; open_list << pos2
end
neighbor[:parent] = current
neighbor[:x] = x2
neighbor[:y] = y2
neighbor[:g] = g2
neighbor[:xr] = g2 + $game_map.distance(x2, y2, goal_x, goal_y)
if !best || neighbor[:xr] - neighbor[:g] < best[:xr] - best[:g]
best = neighbor
end
end
end
end
node = best
while node[:parent] && node[:parent] != start
node = node[:parent]
end
# return 0 if node_list.size < 1
delta_x1 = $game_map.delta_x(node[:x], start[:x])
delta_y1 = $game_map.delta_y(node[:y], start[:y])
if delta_y1 > 0
return 2
elsif delta_x1 < 0
return 4
elsif delta_x1 > 0
return 6
elsif delta_y1 < 0
return 8
end
delta_x2 = delta_x_from(goal_x)
delta_y2 = delta_y_from(goal_y)
if delta_x2.abs > delta_y2.abs
return delta_x2 > 0 ? 4 : 6
elsif delta_y2 != 0
return delta_y2 > 0 ? 8 : 2
end
return 0
end
end
#==============================================================================
class Position_hints < Sprite
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
@x = @y = 0
@data_state = nil
@flash_count = 0
self.ox = 16; self.oy = 32
self.visible = false
self.bitmap = Bitmap.new(32,32)
self.bitmap.fill_rect(0,0,32,32,Color.new(255,255,255,120))
end
#--------------------------------------------------------------------------
def dispose
self.bitmap.dispose
super
end
#--------------------------------------------------------------------------
def state_changed?
return @data_state != $game_temp.move_position
end
#--------------------------------------------------------------------------
def update
super
update_state
update_flash
update_position
end
#--------------------------------------------------------------------------
def update_state
return unless state_changed?
self.visible = ($game_temp.move_position != nil)
if $game_temp.move_position
@x = $game_temp.move_position[0]; @y = $game_temp.move_position[1]
@flash_count = 0
update_flash
update_position
end
@data_state = $game_temp.move_position ? $game_temp.move_position.clone : nil
end
#--------------------------------------------------------------------------
def update_flash
return if !self.visible
@flash_count = (@flash_count + 1) % 40
if @flash_count < 20
opacity = (20 - @flash_count) * 8
else
opacity = (@flash_count - 20) * 8
end
self.opacity = opacity
end
#--------------------------------------------------------------------------
def update_position
return if !self.visible
self.x = (@x * 128 - $game_map.display_x + 3) / 4 + 16
self.y = (@y * 128 - $game_map.display_y + 3) / 4 + 32
self.z = self.y - 1
end
end
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
alias xr_new_mouse_initialize initialize
def initialize
xr_new_mouse_initialize
@position_hints = Position_hints.new(@viewport1)
end
#--------------------------------------------------------------------------
alias xr_new_mouse_dispose dispose
def dispose
@position_hints.dispose
xr_new_mouse_dispose
end
#--------------------------------------------------------------------------
alias xr_new_mouse_update update
def update
@position_hints && @position_hints.update
xr_new_mouse_update
end
end
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
alias xr_new_mouse_update update
def update
xr_new_mouse_update
(Mouse.trigger?(Mouse::LEFT) || Mouse.press?(Mouse::LEFT)) && set_move_position
end
#--------------------------------------------------------------------------
def player_can_move?
return false if $game_temp.message_window_showing
return false if $game_system.map_interpreter.running?
return false if $game_temp.player_transferring
return !$game_player.move_route_forcing
end
#--------------------------------------------------------------------------
def set_move_position
return unless player_can_move?
cx, cy = Mouse.mouse_cd_pos
$game_temp.move_position = [cx, cy]
end
#--------------------------------------------------------------------------
alias xr_new_mouse_transfer_player transfer_player
def transfer_player
$game_temp.move_position = nil
xr_new_mouse_transfer_player
end
end
#==============================================================================
# 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
#==============================================================================
#以下两个用来调整战斗时的手感问题,可以自己试试。
$敌人选框扩大 = 20
$角色选框扩大 = 30
#==============================================================================
# API调用
#==============================================================================
$ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
$GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
$ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
$GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
$Window_HWND = $GetActiveWindow.call
$GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
#$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
#$HookStart = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
#$HookEnd = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
#$GetMouseStatus = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
#$Window_HWND = $FindWindow.call(nil, 'mousetry')
#==============================================================================
module Mouse
LEFT = 0x01
RIGHT = 0x02
def self.init(sprite = nil)
# $HookStart.call($Window_HWND)
$ShowCursor.call(0)
@show_cursor = false
@mouse_sprite = Sprite.new
@mouse_sprite.z = 99999
@mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/SCMouseIcon.png')
#修改为自己的路径↑
#@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))
@left_press = false
@right_press = false
@left_trigger = false
@right_trigger = false
@left_repeat = false
@right_repeat = false
@click_lock = false
update
end
def self.exit
@mouse_sprite.bitmap.dispose
@mouse_sprite.dispose
@show_cursor = true
# $HookEnd.call
$ShowCursor.call(1)
end
def self.mouse_debug
return @mouse_debug.bitmap
end
def self.update
@mouse_sprite.visible = $xiaolv20
left_down = $GetKeyState.call(0x01)
right_down = $GetKeyState.call(0x02)
@click_lock = false
mouse_x, mouse_y = self.get_mouse_pos
if @mouse_sprite != nil
@mouse_sprite.x = mouse_x
@mouse_sprite.y = mouse_y
end
if left_down[7] == 1
@left_repeat = (not @left_repeat)
@left_trigger = (not @left_press)
@left_press = true
else
@left_press = false
@left_trigger = false
@left_repeat = false
end
if right_down[7] == 1
@right_repeat = (not @right_repeat)
@right_trigger = (not @right_press)
@right_press = true
else
@right_press = false
@right_trigger = false
@right_repeat = false
end
end
def self.get_mouse_pos
return 0,0 unless $xiaolv20
point_var = [0, 0].pack('ll')
if $GetCursorPos.call(point_var) != 0
if $ScreenToClient.call($Window_HWND, point_var) != 0
x, y = point_var.unpack('ll')
if (x < 0) or (x > 10000) then x = 0 end
if (y < 0) or (y > 10000) then y = 0 end
if x > 640 then x = 640 end
if y > 480 then y = 480 end
return x, y
else
return 0, 0
end
else
return 0, 0
end
end
def self.mouse_cd_pos
x, y = self.get_mouse_pos
x /= 32; y /= 32
x += $game_map.display_x / 128
y += $game_map.display_y / 128
return x, y
end
def self.press?(mouse_code)
return false unless $xiaolv20
if mouse_code == LEFT
if @click_lock
return false
else
return @left_press
end
elsif mouse_code == RIGHT
return @right_press
else
return false
end
end
def self.trigger?(mouse_code)
return false unless $xiaolv20
if mouse_code == LEFT
if @click_lock
return false
else
return @left_trigger
end
elsif mouse_code == RIGHT
return @right_trigger
else
return false
end
end
def self.repeat?(mouse_code)
return false unless $xiaolv20
if mouse_code == LEFT
if @click_lock
return false
else
return @left_repeat
end
elsif mouse_code == RIGHT
return @right_repeat
else
return false
end
end
def self.click_lock?
return @click_lock
end
def self.click_lock
@click_lock = true
end
def self.click_unlock
@click_lock = false
end
end
$xiaolv20 = true
module Input
if @self_update == nil
@self_update = method('update')
@self_press = method('press?')
@self_trigger = method('trigger?')
@self_repeat = method('repeat?')
end
def self.update
@self_update.call
Mouse.update
end
def self.press?(key_code)
if @self_press.call(key_code)
return true
end
if key_code == C
return Mouse.press?(Mouse::LEFT)
elsif key_code == B
return Mouse.press?(Mouse::RIGHT)
else
return @self_press.call(key_code)
end
end
def self.trigger?(key_code)
if @self_trigger.call(key_code)
return true
end
if key_code == C
return Mouse.trigger?(Mouse::LEFT)
elsif key_code == B
return Mouse.trigger?(Mouse::RIGHT)
else
return @self_trigger.call(key_code)
end
end
def self.repeat?(key_code)
if @self_repeat.call(key_code)
return true
end
if key_code == C
return Mouse.repeat?(Mouse::LEFT)
elsif key_code == B
return Mouse.repeat?(Mouse::RIGHT)
else
return @self_repeat.call(key_code)
end
end
end
class Window_Selectable
if @self_alias == nil
alias self_update update
@self_alias = true
end
def update
#self.cursor_rect.empty
self_update
if self.active and @item_max > 0
index_var = @index
tp_index = @index
mouse_x, mouse_y = Mouse.get_mouse_pos
mouse_not_in_rect = true
for i in 0...@item_max
@index = i
update_cursor_rect
top_x = self.cursor_rect.x + self.x + 16
top_y = self.cursor_rect.y + self.y + 16
bottom_x = top_x + self.cursor_rect.width
bottom_y = top_y + self.cursor_rect.height
if (mouse_x > top_x) and (mouse_y > top_y) and
(mouse_x < bottom_x) and (mouse_y < bottom_y)
mouse_not_in_rect = false
if tp_index != @index
tp_index = @index
$game_system.se_play($data_system.cursor_se)
end
break
end
end
if mouse_not_in_rect
@index = index_var
update_cursor_rect
Mouse.click_lock
else
Mouse.click_unlock
end
end
end
end
class Window_NameInput
if @self_alias == nil
alias self_update update
@self_alias = true
end
def update
#self.cursor_rect.empty
self_update
if self.active
index_var = @index
mouse_x, mouse_y = Mouse.get_mouse_pos
mouse_not_in_rect = true
for i in (0...CHARACTER_TABLE.size).to_a.push(180)
@index = i
update_cursor_rect
top_x = self.cursor_rect.x + self.x + 16
top_y = self.cursor_rect.y + self.y + 16
bottom_x = top_x + self.cursor_rect.width
bottom_y = top_y + self.cursor_rect.height
#
if (mouse_x > top_x) and (mouse_y > top_y) and
(mouse_x < bottom_x) and (mouse_y < bottom_y)
mouse_not_in_rect = false
break
end
end
if mouse_not_in_rect
@index = index_var
update_cursor_rect
Mouse.click_lock
else
Mouse.click_unlock
end
end
end
end
class Window_InputNumber
if @self_alias == nil
alias self_update update
@self_alias = true
end
def update
#self.cursor_rect.empty
self_update
mouse_x, mouse_y = Mouse.get_mouse_pos
if self.active and @digits_max > 0
index_var = @index
mouse_not_in_rect = true
for i in 0...@digits_max
@index = i
update_cursor_rect
top_x = self.cursor_rect.x + self.x + 16
bottom_x = top_x + self.cursor_rect.width
#
if (mouse_x > top_x) and (mouse_x < bottom_x)
mouse_not_in_rect = false
break
end
end
if mouse_not_in_rect
@index = index_var
update_cursor_rect
Mouse.click_lock
else
Mouse.click_unlock
end
end
if @last_mouse_y == nil
@last_mouse_y = mouse_y
end
check_pos = (@last_mouse_y - mouse_y).abs
if check_pos > 10
$game_system.se_play($data_system.cursor_se)
place = 10 ** (@digits_max - 1 - @index)
n = @number / place % 10
@number -= n * place
n = (n + 1) % 10 if mouse_y < @last_mouse_y
n = (n + 9) % 10 if mouse_y > @last_mouse_y
@number += n * place
refresh
@last_mouse_y = mouse_y
end
end
end
class Scene_File
if @self_alias == nil
alias self_update update
@self_alias = true
end
def update
# 此处做了修改,存读档请按左右键翻页
sc_top = @help_window.height
sc_height = (480 - sc_top) / 4
mouse_x, mouse_y = Mouse.get_mouse_pos
Mouse.click_lock if mouse_y <= sc_top
sc_a = @file_index - @file_index % 4
sc_b = -1
for i in 0..3
if (mouse_y > sc_top + (i * sc_height)) and (mouse_y < sc_top + ((i + 1) * sc_height))
sc_b = sc_a + i
break
end
end
if sc_b != -1 and @file_index != sc_b
@savefile_windows[@file_index].selected = false
@file_index = sc_b
@savefile_windows[sc_b].selected = true
$game_system.se_play($data_system.cursor_se)
Mouse.click_unlock
end
self_update
end
end
class Arrow_Enemy
if @self_alias == nil
alias self_update update
@self_alias = true
end
def update
mouse_x, mouse_y = Mouse.get_mouse_pos
idx = 0
for i in $game_troop.enemies do
if i.exist?
top_x = i.screen_x - self.ox
top_y = i.screen_y - self.oy
bottom_x = top_x + self.src_rect.width
bottom_y = top_y + self.src_rect.height
if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
(mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
if @index != idx
$game_system.se_play($data_system.cursor_se)
@index = idx
end
end
end
idx += 1
end
self_update
end
end
class Arrow_Actor
if @self_alias == nil
alias self_update update
@self_alias = true
end
def update
mouse_x, mouse_y = Mouse.get_mouse_pos
idx = 0
for i in $game_party.actors do
if i.exist?
top_x = i.screen_x - self.ox
top_y = i.screen_y - self.oy
bottom_x = top_x + self.src_rect.width
bottom_y = top_y + self.src_rect.height
if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
(mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
if @index != idx
$game_system.se_play($data_system.cursor_se)
@index = idx
end
end
end
idx += 1
end
self_update
end
end
class Game_Player
if @self_alias == nil
alias self_update update
@self_alias = true
end
def update
update_point_movement
self_update
end
def update_point_movement
return if !$game_temp.move_position || moving?
tx = $game_temp.move_position[0]; ty = $game_temp.move_position[1]
direction = find_direction(tx, ty)
if direction == 0 || Input.dir8 > 0
$game_temp.move_position = nil
return
end
move_straight(direction)
end
#--------------------------------------------------------------------------
def move_straight(direction)
# 此处修改了,不到终点不触发
@direction = direction
if !passable?(@x, @y, direction)
x_sc = @x + (direction == 6 ? 1 : direction == 4 ? -1 : 0)
y_sc = @y + (direction == 2 ? 1 : direction == 8 ? -1 : 0)
end_sc = (x_sc != $game_temp.move_position[0] ||
y_sc != $game_temp.move_position[1])
$game_temp.move_position = nil
return if end_sc
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
return
end
super(direction)
end
#--------------------------------------------------------------------------
alias xr_new_mouse_check_event_trigger_here check_event_trigger_here
def check_event_trigger_here(triggers)
return false if Mouse.trigger?(Mouse::LEFT)
return xr_new_mouse_check_event_trigger_here(triggers)
end
#--------------------------------------------------------------------------
alias xr_new_mouse_check_event_trigger_there check_event_trigger_there
def check_event_trigger_there(triggers)
return false if Mouse.trigger?(Mouse::LEFT)
return xr_new_mouse_check_event_trigger_there(triggers)
end
end
Mouse.init
END { Mouse.exit }
#==============================================================================
# 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
#==============================================================================