| 赞 | 58 |
| VIP | |
| 好人卡 | |
| 积分 | 12 |
| 经验 | |
| 最后登录 | 2023-5-29 |
| 在线时间 | 1017 小时 |
- 梦石
- 0
- 星屑
- 1232
- 在线时间
- 1017 小时
- 注册时间
- 2011-4-30
- 回帖
- 1464
|
发表于 2015-12-2 17:28:48
|
显示全部楼层
本帖最后由 汪汪 于 2015-12-2 18:03 编辑
跨地图的各种修改....做出跨地图移动npc非常简单的....唯一担心的就是你的内存了.....
-
- #--------------------------------------------------------------------------
- # Mod地图修改 1.2
- # ● 参考 yangff 先生 的
- # 我要造房子!修改地图元件 - RPG Maker 技术区 - 66RPG
- # [url]https://rpg.blue/forum.php?mod=viewthread&tid=88421[/url]
- # 额,主要是不读取所有地图,好像也没什么作用。。
- # ● 参考 某位 的 事件位置保存脚本,
- # 由于种种原因,未能找到脚本作者名,十分抱歉。
- # ● 额,
- # 主要是脚本合并,bug 未知,如有请告知,
- # 若原作者不允许对脚本进行修改或有其他意见,万望告知。
- # 作者,修改者:汪汪
- #--------------------------------------------------------------------------
- class Game_Map
- attr_accessor :mod
- attr_accessor :map
- attr_accessor :events
- def initialize
- @map_id = 0
- @display_x = 0
- @display_y = 0
- @mod={}
- end
- #--------------------------------------------------------------------------
- # ● 设置
- # map_id : 地图 ID
- #--------------------------------------------------------------------------
- def setup(map_id)
- save_event_pos
-
- load(map_id)
-
- @map_id = map_id
- tileset = $data_tilesets[@map.tileset_id]
- @tileset_name = tileset.tileset_name
- @autotile_names = tileset.autotile_names
- @panorama_name = tileset.panorama_name
- @panorama_hue = tileset.panorama_hue
- @fog_name = tileset.fog_name
- @fog_hue = tileset.fog_hue
- @fog_opacity = tileset.fog_opacity
- @fog_blend_type = tileset.fog_blend_type
- @fog_zoom = tileset.fog_zoom
- @fog_sx = tileset.fog_sx
- @fog_sy = tileset.fog_sy
- @battleback_name = tileset.battleback_name
- @passages = tileset.passages
- @priorities = tileset.priorities
- @terrain_tags = tileset.terrain_tags
- # 初始化显示坐标
- @display_x = 0
- @display_y = 0
- # 清除刷新要求标志
- @need_refresh = false
- # 设置地图事件数据
- @events = {}
- for i in @map.events.keys
- @events[i] = Game_Event.new(@map_id, @map.events[i])
- end
- # 设置公共事件数据
- @common_events = {}
- for i in 1...$data_common_events.size
- @common_events[i] = Game_CommonEvent.new(i)
- end
- # 初始化雾的各种信息
- @fog_ox = 0
- @fog_oy = 0
- @fog_tone = Tone.new(0, 0, 0, 0)
- @fog_tone_target = Tone.new(0, 0, 0, 0)
- @fog_tone_duration = 0
- @fog_opacity_duration = 0
- @fog_opacity_target = 0
- # 初始化滚动信息
- @scroll_direction = 2
- @scroll_rest = 0
- @scroll_speed = 4
-
- load_event_pos
-
- end
- #--------------------------------------------------------------------------
- # ● 读取 map_id : 地图 ID
- #--------------------------------------------------------------------------
- def load(mapid)
- if FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- @map = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- end
- loadmod(mapid)
- end
- def loadmod(mapid)
- chushimap(mapid)
- mod =@mod[mapid].clone
- if mod != nil
- #地图
- if mod[0] != nil
- w = mod[0][0]
- h = mod[0][1]
- @map=RPG::Map.new(w,h)
- end
- #图块
- if mod[1] != nil
- mod[1].each {|wz,dat|@map.data[wz[0],wz[1],wz[2]]=dat}
- end
- #新事件
- if mod[2] != nil
- mod[2].each {|id,ev|@map.events[id] = ev }
- end
- #事件位置保存记录
- if mod[3] != nil
- mod[3].each {|id,pos|
- @map.events[id].x=pos[0] if pos[0] != nil
- @map.events[id].y=pos[1] if pos[1] != nil
- }
- end
- #事件位置开始页显示
- if mod[4] != nil
- mod[4].each {|id,pos|
- @map.events[id].x=pos[0] if pos[0] != nil
- @map.events[id].y=pos[1] if pos[1] != nil
- @map.events[id].startpage=pos[2] if pos[2] != nil
- }
- end
- end
- end
-
- def chushimap(mapid)
- @mod[mapid]={} if @mod[mapid]==nil
- @mod[mapid][1]={} if @mod[mapid][1] == nil
- @mod[mapid][2]={} if @mod[mapid][2] == nil
- @mod[mapid][3]={} if @mod[mapid][3] == nil
- @mod[mapid][4]={} if @mod[mapid][4] == nil
- @mod[mapid][5]={} if @mod[mapid][5] == nil
- end
- #--------------------------------------------------------------------------
- # ● Mod创建新地图
- #--------------------------------------------------------------------------
- def newmap(mapid,w,h)
- @map=RPG::Map.new(w,h) if mapid==$game_map.map_id
- chushimap(mapid)
- @mod[mapid][0] = [w,h]
- end
- #--------------------------------------------------------------------------
- # ● Mod用图块id改变地图
- #--------------------------------------------------------------------------
- def edit(mapid,x,y,lv,dat)
- @map.data[x,y,lv] = dat if mapid == $game_map.map_id
- chushimap(mapid)
- @mod[mapid][1][[x,y,lv]] = dat
- end
- #--------------------------------------------------------------------------
- # ● Mod用图块id改变地图区域
- #--------------------------------------------------------------------------
- def editarea(mapid,x,y,w,h,lv,dat) #lv=0,1,2
- for x1 in x...w+x
- for y1 in y...y+h
- @map.data[x1,y1,lv] = dat if mapid==$game_map.map_id
- chushimap(mapid)
- @mod[mapid][1][[x1,y1,lv]] = dat
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod用地图的区域改变地图
- #--------------------------------------------------------------------------
- def editbymap(mapid,x,y,lv,mapid1,x1,y1,lv1,w1,h1)
- chushimap(mapid)
- if FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid1))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid1))
- end
- x3 = x
- for y2 in x1..h1+(x1-1)
- for x2 in y1..w1+(y1-1)
- dat = @mod[mapid1][1][x2,y2,lv1]
- dat = map1.data[x2,y2,lv1] if dat == nil
- @map.data[x3,y,lv] = dat if mapid==$game_map.map_id
- @mod[mapid][1][[x3,y,lv]] = dat
- x3 = x3+1
- end
- y = y+1
- x3 = x
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod创建新事件
- #--------------------------------------------------------------------------
- def newev(ev=nil)
- if ev.is_a?(RPG::Event)
- @map.events[ev.id] = ev
- @events[ev.id] = Game_Event.new(@map_id , ev)
- $game_map.need_refresh = true
- $game_map.update
- if $scene.is_a?(Scene_Map)
- $scene.refresh_spriteset #这里要修改
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod复制地图事件到 #添加++++++++++
- #--------------------------------------------------------------------------
- def copyev(fomap=1,foevid=1,tomap=1,x=0,y=0,id=nil)
- ev = nil
- if @mod[fomap] != nil and @mod[fomap][2] != nil
- ev = @mod[fomap][2][foevid].clone if
- @mod[fomap][2][foevid].is_a?(RPG::Event)
- end
- if !ev.is_a?(RPG::Event)
- if FileTest.exist?(sprintf("Data/Map%03d.rxdata", fomap))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", fomap))
- ev = map1.events[foevid].clone if
- map1.events[foevid].is_a?(RPG::Event)
- end
- end
- if ev.is_a?(RPG::Event)
- chushimap(tomap)
- if tomap == @map_id
- if id ==nil
- id=1
- until @events[id] == nil
- id+=1
- end
- end
- ev.id = id
- ev.x = x
- ev.y = y
- @mod[tomap][4].delete(ev.id)
- @mod[tomap][3].delete(ev.id)
- @mod[tomap][2][ev.id]= ev
- newev(ev)
- else
- if FileTest.exist?(sprintf("Data/Map%03d.rxdata", tomap))
- map0 = load_data(sprintf("Data/Map%03d.rxdata", tomap))
- end
- if id ==nil
- id=1
- until (map0.events[id] == nil and @mod[tomap][2][id] == nil )
- id+=1
- end
- end
- ev.id=id
- ev.x=x
- ev.y=y
- @mod[tomap][4].delete(ev.id)
- @mod[tomap][3].delete(ev.id)
- @mod[tomap][2][ev.id]= ev
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod移动事件 #添加++++++++++
- #--------------------------------------------------------------------------
- def evxy(mapid=1,id=1,x=0,y=0)
- chushimap(mapid)
- if mapid == @map_id
- @events[id].moveto(x, y)
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][0] = x
- @mod[mapid][4][id][1] = y
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][0] = x
- @mod[mapid][4][id][1] = y
- end
- end
- end
- #--------------------------------------------------------------------------
- # Mod更改事件初始页 #添加++++++++++
- #--------------------------------------------------------------------------
- def evst(mapid=1,id=1,startpage = 0)
- chushimap(mapid)
- if mapid == @map_id
- @events[id].startpage = startpage
- @events[id].refresh
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][2] = startpage
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][2] = startpage
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod更改事件朝向 #添加++++++++++
- #--------------------------------------------------------------------------
- def evdic(mapid=1,id=1,dic = 0)
- chushimap(mapid)
- if mapid == @map_id
- case dic
- when 2
- @events[id].turn_down
- when 4
- @events[id].turn_left
- when 6
- @events[id].turn_right
- when 8
- @events[id].turn_up
- end
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][3] = dic
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][3] = dic
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod显示隐藏新事件 #添加++++++++++
- #--------------------------------------------------------------------------
- def evxs(mapid,id,erased = true)
- chushimap(mapid)
- if mapid == @map_id
- @events[id].erased = erased
- @events[id].refresh
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][3] = erased
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][4] = erased
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod改变事件 位置 开始页,方向 #添加++++++++++
- #--------------------------------------------------------------------------
- def changev(mapid=1,id=1,x=0,y=0,startpage =0,dic=nil)
- chushimap(mapid)
- if mapid == @map_id
- @events[id].moveto(x, y)
- @events[id].startpage = startpage
- @events[id].refresh
- case dic
- when 2
- @events[id].turn_down
- when 4
- @events[id].turn_left
- when 6
- @events[id].turn_right
- when 8
- @events[id].turn_up
- end
- @mod[mapid][3].delete(id)
- @mod[mapid][4][id] = [x,y,startpage,dic]
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][3].delete(id)
- @mod[mapid][4][id] = [x,y,startpage,dic]
- end
- end
- end
-
- #--------------------------------------------------------------------------
- # ● Mod事件位置重置 #添加++++++++++
- #--------------------------------------------------------------------------
- def evxyre(mapid=1,id=1)
- chushimap(mapid)
- if mapid == @map_id
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][0] = nil
- @mod[mapid][4][id][1] = nil
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][0] = nil
- @mod[mapid][4][id][1] = nil
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod事件初始页重置 #添加++++++++++
- #--------------------------------------------------------------------------
- def evstre(mapid=1,id=1)
- chushimap(mapid)
- if mapid == @map_id
- @events[id].startpage = 0
- @events[id].refresh
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][2] = 0
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][2] = 0
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod事件方向重置 #添加++++++++++
- #--------------------------------------------------------------------------
- def evxyre(mapid=1,id=1)
- chushimap(mapid)
- if mapid == @map_id
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][3] = nil
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][3] = nil
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod事件显示重置 #添加++++++++++
- #--------------------------------------------------------------------------
- def evxyre(mapid=1,id=1)
- chushimap(mapid)
- if mapid == @map_id
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][4] = nil
- else
- ev = false
- if @mod[mapid][2][id].is_a?(RPG::Event)
- ev = true
- end
- if ev !=true and
- FileTest.exist?(sprintf("Data/Map%03d.rxdata", mapid))
- map1 = load_data(sprintf("Data/Map%03d.rxdata", mapid))
- ev = true if map1.events[id].is_a?(RPG::Event)
- end
- if ev = true
- @mod[mapid][4][id]||=[]
- @mod[mapid][4][id][4] = nil
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● Mod事件重置 #添加++++++++++
- #--------------------------------------------------------------------------
- def evre(mapid=1,id=1)
- chushimap(mapid)
- if mapid == @map_id
- @mod[mapid][3].delete(id)
- @mod[mapid][4].delete(id)
- else
- @mod[mapid][3].delete(id)
- @mod[mapid][4].delete(id)
- end
- end
-
-
-
- #--------------------------------------------------------------------------
- # ● 保存事件位置 #添加++++++++++
- #--------------------------------------------------------------------------
- def save_event_pos
- chushimap(@map_id)
- if @events != nil
- @events.each{|i,e|
- if e.save_pos?
- @mod[@map_id][3][i]= [e.x,e.y,e.pagenum,e.direction]
- else
- @mod[@map_id][3][i]= nil
- end}
- end
- end
- #--------------------------------------------------------------------------
- # ● 读取事件位置 #添加++++++++++
- #--------------------------------------------------------------------------
- def load_event_pos
- chushimap(@map_id)
- mod =@mod[@map_id].clone
- if mod[3] != nil
- mod[3].each {|id,pos|
- next if @events[id] == nil
- next if @events[id].pagenum != pos[2]
- case pos[3]
- when 2
- @events[id].turn_down
- when 4
- @events[id].turn_left
- when 6
- @events[id].turn_right
- when 8
- @events[id].turn_up
- end
- }
- end
- if mod[4] != nil
- mod[4].each {|id,pos|
- next if @events[id] == nil
- case pos[3]
- when 2
- @events[id].turn_down
- when 4
- @events[id].turn_left
- when 6
- @events[id].turn_right
- when 8
- @events[id].turn_up
- end
- @events[id].erase if pos[4] == true
- }
- end
- end
- end
- #==============================================================================
- # ■ Game_Event
- #------------------------------------------------------------------------------
- # 处理事件的类。条件判断、事件页的切换、并行处理、执行事件功能
- # 在 Game_Map 类的内部使用。
- #==============================================================================
- module RPG
- class Event
- attr_accessor :startpage
- end
- end
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :trigger # 目标
- attr_reader :list # 执行内容
- attr_reader :starting # 启动中标志
- attr_accessor :erased
- attr_accessor :pagenum
- attr_accessor :startpage
-
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # map_id : 地图 ID
- # event : 事件 (RPG::Event)
- #--------------------------------------------------------------------------
- def initialize(map_id, event)
- super()
- @map_id = map_id
- @event = event
- @id = @event.id
- @erased = false
- @starting = false
- @through = true
- # 初期位置的移动
- moveto(@event.x, @event.y)
-
- #修改
- @pagenum = nil
- if event.startpage == nil
- @startpage = 0
- else
- @startpage = event.startpage
- end
- #修改
-
- refresh
- end
- #--------------------------------------------------------------------------
- # ● 启动事件 #修改++++++++++
- #--------------------------------------------------------------------------
- def start(num = nil)
- @startpage = num if num != nil
- refresh if num != nil
- # 执行内容不为空的情况下
- if @list != nil and @list.size > 1
- @starting = true
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新 #修改++++++++++
- #--------------------------------------------------------------------------
- def refresh
- # 初始化本地变量 new_page
- new_page = nil
- # 无法暂时消失的情况下
- unless @erased
- # 从编号大的事件页按顺序调查
- @pagenum = @event.pages.size + 1
- for page in @event.pages.reverse
-
- #修改++++++++++
- @pagenum -= 1
- new_page = page if @startpage == @pagenum
- break if @startpage == @pagenum
- next if @startpage != 0
- #修改++++++++++
-
-
- # 可以参考事件条件 c
- c = page.condition
- # 确认开关条件 1
- if c.switch1_valid
- if $game_switches[c.switch1_id] == false
- next
- end
- end
- # 确认开关条件 2
- if c.switch2_valid
- if $game_switches[c.switch2_id] == false
- next
- end
- end
- # 确认变量条件
- if c.variable_valid
- if $game_variables[c.variable_id] < c.variable_value
- next
- end
- end
- # 确认独立开关条件
- if c.self_switch_valid
- key = [@map_id, @event.id, c.self_switch_ch]
- if $game_self_switches[key] != true
- next
- end
- end
- # 设置本地变量 new_page
- new_page = page
- # 跳出循环
- break
- end
- end
- # 与上次同一事件页的情况下
- if new_page == @page
- # 过程结束
- return
- end
- # @page 设置为现在的事件页
- @page = new_page
- # 清除启动中标志
- clear_starting
- # 没有满足条件的页面的时候
- if @page == nil
- # 设置各实例变量
- @tile_id = 0
- @character_name = ""
- @character_hue = 0
- @move_type = 0
- @through = true
- @trigger = nil
- @list = nil
- @interpreter = nil
- # 过程结束
- return
- end
- # 设置各实例变量
- @tile_id = @page.graphic.tile_id
- @character_name = @page.graphic.character_name
- @character_hue = @page.graphic.character_hue
- if @original_direction != @page.graphic.direction
- @direction = @page.graphic.direction
- @original_direction = @direction
- @prelock_direction = 0
- end
- if @original_pattern != @page.graphic.pattern
- @pattern = @page.graphic.pattern
- @original_pattern = @pattern
- end
- @opacity = @page.graphic.opacity
- @blend_type = @page.graphic.blend_type
- @move_type = @page.move_type
- @move_speed = @page.move_speed
- @move_frequency = @page.move_frequency
- @move_route = @page.move_route
- @move_route_index = 0
- @move_route_forcing = false
- @walk_anime = @page.walk_anime
- @step_anime = @page.step_anime
- @direction_fix = @page.direction_fix
- @through = @page.through
- @always_on_top = @page.always_on_top
- @trigger = @page.trigger
- @list = @page.list
- @interpreter = nil
- # 目标是 [并行处理] 的情况下
- if @trigger == 4
- # 生成并行处理用解释器
- @interpreter = Interpreter.new
- end
- # 自动事件启动判定
- check_event_trigger_auto
- end
- #--------------------------------------------------------------------------
- # ● 是否储存位置 #修改++++++++++
- #--------------------------------------------------------------------------
- def save_pos?
- return true unless @list
- return true if @list[0].code != 108
- return !@list[0].parameters[0].include?("不保存事件位置")
- end
- end
- class Scene_Map
- #--------------------------------------------------------------------------
- # ● 重新描绘地图 #修改++++++++++
- #--------------------------------------------------------------------------
- def refresh_spriteset
- @spriteset.dispose
- @spriteset = Spriteset_Map.new
- end
- end
复制代码
|
评分
-
查看全部评分
|