#==============================================================================# ☆★☆ 提取放置物脚本(强化) ☆★☆
#------------------------------------------------------------------------------
# - 美兽
# - 2007.4.12
#------------------------------------------------------------------------------
# 爱护环境,人人有责,现实中切勿乱丢垃圾。
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# 脚本原理:
# 是从仓库地图中提取事件,将其拷贝放入指定的位置,
# 依此达成随时随地生成新事件的功能,如此可节省大量用RGSS编写事件所消耗的体力,很多地方写的
# 很保守,尽量减少冲突几率。。
# 此为强化版,可实现新事件的保存,但代价是冲突的随之增大,若只想单纯实现ARPG
# 一类的物品掉落,场所移动后便清除,请使用简洁版。
#------------------------------------------------------------------------------
=begin
Note:
一:生成物品主方法:
Drop_Item.make_events(map_id,event_id,item_x,item_y,save=false)
map_id : 仓库地图的ID。
event_id : 仓库中对应事件的ID。
item_x、item_y :新事件的X与Y坐标
save : 是否存储标志;
默认为false,即不存储,场所移动等转换场景后事件会消失;
true 为存储,取档、关机、登火星,返回后事件仍存在。
二:删除事件方法:
事件名若包含"delete"字段,则执行完毕会立即自我清除;
注:任何事件皆如此。
三:必掌握语句:
$game_map.events[@event_id]
$game_player
事件的脚本使用,表示“本事件”和“角色”,主要为取得事件的坐标,
取得“本事件”X与Y坐标:$game_map.events[@event_id].event.x
$game_map.events[@event_id].event.y
取得“角色”X与Y坐标:$game_player.x
$game_player.y
例如,在某事件左侧生成2号地图的2号事件并永久存储,写法如下。
x = $game_map.events[@event_id].event.x
y = $game_map.events[@event_id].event.y
Drop_Item.make_events(2,2,x-1,y,true)
四:备注:
此脚本用法十分灵活,种植、建设、舍弃、掉宝等功能都可用以达成。
=end
#==============================================================================
module Drop_Item
#生成事件
def self.make_events(warehouse_map_id,event_id,item_x,item_y,save=false)
map_id = $game_map.map_id
map_es = $game_system.map_data[map_id] ||= {}
event = load_data(sprintf("Data/Map%03d.rxdata", warehouse_map_id)).events[event_id]
if event.nil?
event = $game_map.events[event_id] if map_id == warehouse_map_id
event = $game_system.map_data[warehouse_map_id][event_id] if event.nil?
event = event.instance_variable_get(:@event) unless event.nil?
end
event.id = (map_es.empty? ? 2000 : map_es.keys.max + 1)
event.x = item_x
event.y = item_y
if save
$game_system.map_data[map_id][event.id] = event
else
max_id = $game_map.events.keys.max
max_id = 20000 if max_id.nil?
event.id = (max_id < 20000 ? 20000 : max_id + 1)
end
puts "create_event_id:#{event.id}"
$game_map.events[event.id] = Game_Event.new(map_id,event)
refresh_map
end
#删除生成事件
def self.delete_event(map_id, event_id)
if !$game_system.map_data[map_id].nil?
$game_system.map_data[map_id].delete(event_id)
end
$game_map.events.delete(event_id) if $game_map.map_id == map_id
refresh_map
end
#获取地图所有的生成事件
def self.get_map_events(map_id)
map_data = $game_system.map_data[map_id]
result = []
map_data.values.each{|e| result.push(e) } if !map_data.nil?
return result
end
#刷新地图精灵
def self.refresh_map
$scene.instance_variable_get(:@spriteset).dispose
$scene.instance_variable_set(:@spriteset,Spriteset_Map.new)
end
end
class Game_Map
alias qqeat_make_event_game_map_setup setup
def setup(map_id)
qqeat_make_event_game_map_setup(map_id)
$game_system.map_data ||= {}
Drop_Item.get_map_events(map_id).each{|e| @events[e.id] = Game_Event.new(map_id,e) }
end
end
class Interpreter
def command_end
@list = nil
if @main and @event_id > 0 and $game_map.events[@event_id] != nil
if $game_map.events[@event_id].instance_variable_get(:@event).name[/delete/]
Drop_Item.delete_event($game_map.map_id,@event_id)
else
$game_map.events[@event_id].unlock
end
end
end
end
class Scene_Load < Scene_File
alias qqeat_make_event_scene_file_read_save_data read_save_data
def read_save_data(file)
qqeat_make_event_scene_file_read_save_data(file)
$game_map.events.keys.each{|id| $game_map.events.delete(id) if id >= 20000 }
end
end
class Scene_Load2 < Scene_File
alias qqeat_make_event_scene_file_read_save_data read_save_data
def read_save_data(file)
qqeat_make_event_scene_file_read_save_data(file)
$game_map.events.keys.each{|id| $game_map.events.delete(id) if id >= 20000 }
end
end
class Game_System
attr_accessor :map_data
alias qqeat_make_event_game_system_initialize initialize
def initialize
qqeat_make_event_game_system_initialize
@map_data = {}
end
end