# 事件管理器 v1.1 bug 修正
# 优化默认脚本事件运行效率
class Game_Event
attr(:copy_id, :map_id)
attr_accessor :copy_self_switch
# 开始
# 默认脚本距离屏幕比较远的事件是不会自主移动的
# 这段脚本让全屏的事件都可以按照设置好的自身移动路线前进,如果静止的事件比较多会
# 比较省资源。如果不需要这个功能,就删除 开始 ~ 结束 之间的脚本
def update_self_movement
if @stop_count > stop_count_threshold
case @move_type
when 1; move_type_random
when 2; move_type_toward_player
when 3; move_type_custom
end
end
end
# 结束
alias_method :sEventManager_init_public_members, :init_public_members
def init_public_members #覆盖
@gridding = $game_map.gridding
sEventManager_init_public_members
end
def moveto(x, y) #修改父类方法
gridding_remove
super
gridding_insert
end
def move_straight(d, turn_ok = true) #修改父类方法
gridding_remove
super
gridding_insert
end
def move_diagonal(horz, vert) #修改父类方法
gridding_remove
super
gridding_insert
end
def gridding_remove
@gridding[@x][@y].delete(self)
end
def gridding_insert
@gridding[@x][@y].push(self)
end
end
class Game_Map
attr(:gridding)
alias_method :sEventManager_setup_events, :setup_events
def setup_events
@gridding = Array.new(width + 1) { Array.new(height + 1) {[]} }
sEventManager_setup_events
end
def refresh_tile_events #覆盖
end
def events_xy(x, y) #覆盖
@gridding[x][y]
end
def events_xy_nt(x, y) #覆盖
@gridding[x][y].select {|event| !event.through}
end
def tile_events_xy(x, y) #覆盖
@gridding[x][y].select {|event| event.tile? && !event.through}
end
end
#
# 精灵管理
class Spriteset_Map
# 设置事件直径,如果你使用的事件图片较大可以适当增大这个数值
# 以防止事件进入画面但是没有显示出来。
EventRadius = 2
alias_method :sEventManager_create_characters, :create_characters
def create_characters
sEventManager_create_characters
setup_event_sprites
end
def setup_event_sprites
@events_sprites = {}
@character_sprites.each {|sp|
@events_sprites[sp.character] = sp if sp.character.class == Game_Event
}
@events_sprites.each_value {|sp| @character_sprites.delete(sp)}
end
alias_method :sEventManager_dispose_characters, :dispose_characters
def dispose_characters
@events_sprites.each_value {|sprite| sprite.dispose if sprite}
sEventManager_dispose_characters
end
alias_method :sEventManager_update_characters, :update_characters
def update_characters
sEventManager_update_characters
update_event_sprites
end
def update_event_sprites
ox = $game_map.display_x - EventRadius
ex = $game_map.display_x + Graphics.width / 32.0 + EventRadius - 1
oy = $game_map.display_y - EventRadius
ey = $game_map.display_y + Graphics.height / 32.0 + EventRadius - 0.875
mw = $game_map.width
mh = $game_map.height
lv = $game_map.loop_vertical?
lh = $game_map.loop_horizontal?
@events_sprites.each {|event, sprite|
x = event.real_x
y = event.real_y
if (x > ox && x < ex || lv && x + mw > ox && x + mw < ex) &&
(y > oy && y < ey || lh && y + mh > oy && y + mh < ey)
sprite ? sprite.update :
@events_sprites[event] = Sprite_Character.new(@viewport1, event)
elsif sprite
sprite.dispose
@events_sprites[event] = nil
end
}
end
end