本帖最后由 英顺的马甲 于 2016-8-3 11:33 编辑
def __method__ caller[0][/`([^']*)'/] && $1 end Game_Player = Class.new(Game_Player){ const_set(:MoveHook, true) const_set(:DIRS, {'down' => 2, 'left' => 4, 'right' => 6, 'up' => 8}) superclass.constants.each{|c|const_set(c, superclass.const_get(c))} [:left, :right, :up, :down].each do |d| define_method([:move_, d].join) do |*a| dir = __method__[/[^_]+$/] (self.direction != Game_Player::DIRS[dir] && __move_by_keyboard?) ? __send__("turn_" + dir, true) : (__move_by_keyboard? && @__wait > 0) || super(*a) end end [:left, :right, :up, :down].each do |d| define_method([:turn_, d].join) do |*a| a[0] && @__wait = 5 super end end def update (@__wait||=0) > 0 && @__wait -= 1 super end def __move_by_keyboard? return ([2,4,6,8].include?(Input.dir4) && !moving? && !$game_system.map_interpreter.running? && !@move_route_forcing && !$game_temp.message_window_showing) end } unless defined?(Game_Player::MoveHook)
def __method__
caller[0][/`([^']*)'/] && $1
end
Game_Player = Class.new(Game_Player){
const_set(:MoveHook, true)
const_set(:DIRS, {'down' => 2, 'left' => 4, 'right' => 6, 'up' => 8})
superclass.constants.each{|c|const_set(c, superclass.const_get(c))}
[:left, :right, :up, :down].each do |d|
define_method([:move_, d].join) do |*a|
dir = __method__[/[^_]+$/]
(self.direction != Game_Player::DIRS[dir] && __move_by_keyboard?) ?
__send__("turn_" + dir, true) : (__move_by_keyboard? && @__wait > 0) || super(*a)
end
end
[:left, :right, :up, :down].each do |d|
define_method([:turn_, d].join) do |*a|
a[0] && @__wait = 5
super
end
end
def update
(@__wait||=0) > 0 && @__wait -= 1
super
end
def __move_by_keyboard?
return ([2,4,6,8].include?(Input.dir4) && !moving? &&
!$game_system.map_interpreter.running? &&
!@move_route_forcing && !$game_temp.message_window_showing)
end
} unless defined?(Game_Player::MoveHook)
如果与原本的方向不同就会在转向之后等待五帧 |