本帖最后由 taroxd 于 2014-7-28 07:44 编辑
DeathKing 发表于 2014-7-26 22:02
看了一下脚本 @feizhaodan 的是直接HOOK Game_Map#setup,在实际执行地图切换前记录事件位置,并直接让Ga ...
class Game_Map alias init_20140728 initialize def initialize init_20140728 @moved_events = {} @removed_events = {} end # default_proc 不能存档简直忧伤…… def get_moved_events(map_id) @moved_events[map_id] ||= {} end def get_removed_events(map_id) @removed_events[map_id] ||= {} end def setup_events @events = {} @map.events.each do |i, event| unless get_removed_events(@map_id)[i] @events[i] = Game_Event.new(@map_id, event) end end get_moved_events(@map_id).each do |i, (x, y, direction, event)| @events[i] = event = Game_Event.new(@map_id, event) event.moveto(x, y) event.set_direction(direction) end @common_events = parallel_common_events.collect do |common_event| Game_CommonEvent.new(common_event.id) end refresh_tile_events end end class Game_Event def moveto_new_map(map_id, x, y, direction = nil) if map_id == @map_id moveto(x, y) set_direction(direction) if direction return end $game_map.get_moved_events(@map_id).delete(@id) $game_map.get_removed_events(@map_id)[@id] = true new_map = load_data(sprintf("Data/Map%03d.rvdata2", map_id)) size = new_map.width * new_map.height begin @event.id = @id = size + rand(0xffff) + @id # just a random number big enough end while $game_map.get_moved_events(map_id).key?(@id) $game_map.get_moved_events(map_id)[@id] = [x, y, (direction || @direction), @event] $game_map.get_removed_events(map_id).delete(@id) end end
class Game_Map
alias init_20140728 initialize
def initialize
init_20140728
@moved_events = {}
@removed_events = {}
end
# default_proc 不能存档简直忧伤……
def get_moved_events(map_id)
@moved_events[map_id] ||= {}
end
def get_removed_events(map_id)
@removed_events[map_id] ||= {}
end
def setup_events
@events = {}
@map.events.each do |i, event|
unless get_removed_events(@map_id)[i]
@events[i] = Game_Event.new(@map_id, event)
end
end
get_moved_events(@map_id).each do |i, (x, y, direction, event)|
@events[i] = event = Game_Event.new(@map_id, event)
event.moveto(x, y)
event.set_direction(direction)
end
@common_events = parallel_common_events.collect do |common_event|
Game_CommonEvent.new(common_event.id)
end
refresh_tile_events
end
end
class Game_Event
def moveto_new_map(map_id, x, y, direction = nil)
if map_id == @map_id
moveto(x, y)
set_direction(direction) if direction
return
end
$game_map.get_moved_events(@map_id).delete(@id)
$game_map.get_removed_events(@map_id)[@id] = true
new_map = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
size = new_map.width * new_map.height
begin
@event.id = @id = size + rand(0xffff) + @id # just a random number big enough
end while $game_map.get_moved_events(map_id).key?(@id)
$game_map.get_moved_events(map_id)[@id] =
[x, y, (direction || @direction), @event]
$game_map.get_removed_events(map_id).delete(@id)
end
end
一个不太完善的版本,仅仅提供一个思路。
有很多问题没有考虑到,比如从当前地图移动走的时候,事件仍然会停留在地图上。
比如独立开关的问题没有处理。
反正我也不需要这个功能,所以也没有太在意美观和可读性什么的。总之就是提供一个思路吧。这些小问题应该都不难解决的。
|