Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # DSI Patch System
- # -- Last Updated: 2017.06.23
- # -- Author: dsiver144
- # -- Level: Hard
- # -- Requires: n/a
- #==============================================================================
- $imported = {} if $imported.nil?
- $imported["DSI-PatchSystem"] = true
- #==============================================================================
- # + Updates
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # 2017.06.03 - Finish first version of the script!
- # 2017.06.04 - Add Classes tab. Add an option to add new event to existing maps.
- # (This doesn't replace old event with same id)
- # 2017.06.23 - Fix some important bugs.
- # - Cursor remember for "add events to map" tab.
- #==============================================================================
- # + Instructions
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below �� Materials/�f�� but above �� Main. Remember to save.
- #==============================================================================
- module DSIVER144
- module PATCH_SYSTEM
- PATCH_DIR = "DLC"
- PATCH_NAME = "UA_*.dlc"
- #For ex: Patch file will be created at Patches folder
- #which named DLC_1.patch, DLC_2.patch, DLC_3.patch,...
- UNIQUE_KEY = "Z01"
- LOAD_PATCH_WHEN_TEST = true # set to true to see magic!
- #------------------------------------------------------------------------
- # * new method: get_patch_files
- #------------------------------------------------------------------------
- def self.get_patch_files
- files = Dir.glob(PATCH_DIR+'/'+PATCH_NAME)
- files
- end
- #------------------------------------------------------------------------
- # * new method: get_data
- #------------------------------------------------------------------------
- def self.get_data(type)
- case type
- when :item
- return $data_items
- when :weapon
- return $data_weapons
- when :armor
- return $data_armors
- when :actor
- return $data_actors
- when :class
- return $data_classes
- when :skill
- return $data_skills
- when :enemy
- return $data_enemies
- when :troop
- return $data_troops
- when :state
- return $data_states
- when :animation
- return $data_animations
- when :tileset
- return $data_tilesets
- when :common_event
- return $data_common_events
- when :system
- return $data_system
- when :map_info
- return $data_mapinfos
- when :map_event
- return $data_mapinfos
- end
- end
- #------------------------------------------------------------------------
- # * new method: load_patch_data
- #------------------------------------------------------------------------
- def self.load_patch_data
- get_patch_files.each do |file_name|
- file = load_data(file_name)
- next if file[:unique_id] != UNIQUE_KEY
- file[:datas].each_pair do |key, data_array|
- next if (key == :map_info) || (key == :map_event)
- data_array.each do |data|
- next unless data
- get_data(key)[data.id] = data
- end
- end
- if file[:datas].has_key?(:map_event)
- file[:datas][:map_event].each_with_index do |events, map_id|
- next unless events
- next if map_id == 0
- $data_patch_events ||= {}
- $data_patch_events[map_id] ||= []
- $data_patch_events[map_id] += events
- end
- end
- if file[:datas].has_key?(:map_info)
- $data_mapinfos = file[:datas][:map_info][:info]
- $temp_patch_maps = file[:datas][:map_info][:map_datas]
- end
- end
- puts "Load Patch files completed!"
- end
- #------------------------------------------------------------------------
- # * new method: create_patch_file
- #------------------------------------------------------------------------
- def self.create_patch_file(patch_hash)
- old_time = Time.now
- patch_data = {}
- patch_data[:unique_id] = UNIQUE_KEY
- patch_data[:datas] = {}
- patch_hash.each_pair do |key, item_array|
- next if (key == :map_info) || key == :map_event
- patch_data[:datas][key] ||= []
- item_array.each do |index|
- patch_data[:datas][key] << get_data(key)[index]
- end
- end
- if patch_hash.has_key?(:map_info)
- patch_data[:datas][:map_info] = {}
- patch_data[:datas][:map_info][:info] = $data_mapinfos
- patch_data[:datas][:map_info][:map_datas] = {}
- patch_hash[:map_info].each do |map_id|
- next if map_id == 0
- patch_data[:datas][:map_info][:map_datas][map_id] = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
- end
- end
- if patch_hash.has_key?(:map_event)
- patch_hash[:map_event].each_with_index do |event_ids,map_id|
- next unless event_ids
- next if map_id == 0
- map = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
- event_ids.each do |id|
- next unless map.events[id]
- patch_data[:datas][:map_event] ||= []
- patch_data[:datas][:map_event][map_id] ||= []
- patch_data[:datas][:map_event][map_id][id] = map.events[id]
- end
- end
- end
- Dir.mkdir(PATCH_DIR) unless FileTest.directory?(PATCH_DIR)
- index = 1
- while FileTest.exist?(PATCH_DIR + "/" + PATCH_NAME.gsub("*") {"#{index}"})
- index += 1
- end
- File.open(PATCH_DIR + "/" + PATCH_NAME.gsub("*") {"#{index}"}, "wb") do |file|
- Marshal.dump(patch_data, file)
- end
- new_file = PATCH_DIR + "/" + PATCH_NAME.gsub("*") {"#{index}"}
- msgbox_p("New patch file created! Please check [ #{new_file} ]! | Time: #{Time.now - old_time}")
- end
- end # PATCH_SYSTEM
- end # DSIVER144
- module DataManager
- class << self
- alias_method(:dsi_load_database_patch_system, :load_database)
- alias_method(:dsi_reload_map_if_update, :reload_map_if_updated)
- end
- #--------------------------------------------------------------------------
- # * Load Database
- #--------------------------------------------------------------------------
- def self.load_database
- dsi_load_database_patch_system
- end
- #--------------------------------------------------------------------------
- # alias method: reload_map_if_updated
- #--------------------------------------------------------------------------
- def self.reload_map_if_updated
- dsi_reload_map_if_update
- reload_map_if_patched
- end
- #--------------------------------------------------------------------------
- # new method: reload_map_if_patched
- #--------------------------------------------------------------------------
- def self.reload_map_if_patched
- unless $temp_patch_maps[$game_map.map_id].nil?
- $game_map.setup($game_map.map_id)
- $game_player.center($game_player.x, $game_player.y)
- $game_player.make_encounter_count
- end
- end
- end # DataManager
- class Game_Map
- #--------------------------------------------------------------------------
- # overwrite method: setup
- #--------------------------------------------------------------------------
- def setup(map_id)
- @map_id = map_id
- if $temp_patch_maps.nil? || $temp_patch_maps[@map_id].nil?
- @map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))
- else
- @map = $temp_patch_maps[@map_id]
- end
- @tileset_id = @map.tileset_id
- @display_x = 0
- @display_y = 0
- referesh_vehicles
- setup_events
- setup_scroll
- setup_parallax
- setup_battleback
- @need_refresh = false
- end
- #--------------------------------------------------------------------------
- # * new method: find_empty_slot
- #--------------------------------------------------------------------------
- def find_empty_slot(start=1)
- id = start
- while @events[id]
- id += 1
- end
- return id
- end
- #--------------------------------------------------------------------------
- # * overwrite method: setup_events
- #--------------------------------------------------------------------------
- def setup_events
- @events = {}
- @map.events.each do |i, event|
- @events[i] = Game_Event.new(@map_id, event)
- end
- new_id = @events.size
- if $data_patch_events && $data_patch_events[@map_id]
- $data_patch_events[@map_id].each_with_index do |event,id|
- next unless event
- new_id = find_empty_slot(new_id)
- event.id = new_id
- @events[new_id] = Game_Event.new(@map_id, event)
- end
- end
- @common_events = parallel_common_events.collect do |common_event|
- Game_CommonEvent.new(common_event.id)
- end
- refresh_tile_events
- end
- end # Game_Map
- class Scene_Load < Scene_File
- alias_method(:dsi_on_load_success, :on_load_success)
- #--------------------------------------------------------------------------
- # * Confirm Save File
- #--------------------------------------------------------------------------
- def on_savefile_ok
- super
- if ($TEST && DSIVER144::PATCH_SYSTEM::LOAD_PATCH_WHEN_TEST) or !$TEST
- DSIVER144::PATCH_SYSTEM.load_patch_data
- end
- if DataManager.load_game(@index)
- on_load_success
- else
- Sound.play_buzzer
- end
- end
- end
- class Scene_Title
- alias_method(:update_patch_trigger, :update)
- alias_method(:dsi_command_new_game, :command_new_game)
- #--------------------------------------------------------------------------
- # * [New Game] Command
- #--------------------------------------------------------------------------
- def command_new_game
- if ($TEST && DSIVER144::PATCH_SYSTEM::LOAD_PATCH_WHEN_TEST) or !$TEST
- DSIVER144::PATCH_SYSTEM.load_patch_data
- end
- dsi_command_new_game
- end
- #--------------------------------------------------------------------------
- # * method: start
- #--------------------------------------------------------------------------
- def update
- update_patch_trigger
- if Input.trigger?(:F6) && $TEST
- SceneManager.call(Scene_DSIPatch)
- end
- end
- end # Scene_Title
- class Scene_DSIPatch < Scene_Base
- #--------------------------------------------------------------------------
- # * method: start
- #--------------------------------------------------------------------------
- def start
- super
- @patch_window = Window_Patch_Type.new(0,0)
- @patch_window.init_data
- @patch_window.x = (Graphics.width - @patch_window.width)*0.5
- @patch_window.y = (Graphics.height - @patch_window.height)*0.5 - 24
- @patch_window.set_handler(:ok, method(:on_choose_ok))
- ww = @patch_window.width; wh = @patch_window.fitting_height(1)
- wy = @patch_window.height + @patch_window.y
- @patch_help_window = Window_Base.new(@patch_window.x,wy,ww,wh)
- @patch_help_window.draw_text(0,0,@patch_help_window.contents_width,24,"F7: Create New Patch! | F5: (Un)Select All!")
- end
- #--------------------------------------------------------------------------
- # * new method: on_choose_ok
- #--------------------------------------------------------------------------
- def on_choose_ok
- if has_category?
- if @patch_window.current_category == :map_event
- if !@patch_window.second_category
- @last_map_index = @patch_window.index
- @patch_window.second_category = @patch_window.current_symbol.to_s.to_i
- @patch_window.select(0)
- @patch_window.refresh
- @patch_window.activate
- else
- #p @patch_window.current_data
- @patch_window.activate
- map_id = @patch_window.second_category
- @patch_window.selected_data[:map_event] ||= []
- @patch_window.selected_data[:map_event][map_id] ||= []
- if !@patch_window.selected_data[:map_event][map_id].include?(@patch_window.current_item_data[1])
- @patch_window.selected_data[:map_event][map_id] << @patch_window.current_item_data[1]
- else
- @patch_window.selected_data[:map_event][map_id].delete(@patch_window.current_item_data[1])
- end
- p [map_id, @patch_window.selected_data[:map_event][map_id]]
- @patch_window.redraw_current_item
- end
- else
- if @patch_window.has_current_item
- @patch_window.unselect_current_item
- @patch_window.activate
- @patch_window.redraw_current_item
- else
- @patch_window.add_current_item
- @patch_window.activate
- @patch_window.redraw_current_item
- end
- end
- else
- @patch_window.set_category(@patch_window.current_symbol)
- @patch_window.activate
- end
- end
- #--------------------------------------------------------------------------
- # * new method: has_category?
- #--------------------------------------------------------------------------
- def has_category?
- return @patch_window.current_category
- end
- #--------------------------------------------------------------------------
- # * method: update
- #--------------------------------------------------------------------------
- def update
- super
- if Input.trigger?(:F7)
- DSIVER144::PATCH_SYSTEM.create_patch_file(@patch_window.selected_data)
- end
- if Input.trigger?(:F5)
- if !@patch_window.selected_all?
- @patch_window.select_all_item
- @patch_window.refresh
- else
- @patch_window.unselect_all_item
- @patch_window.refresh
- end
- end
- if has_category?
- if Input.trigger?(:B)
- if @patch_window.second_category
- @patch_window.second_category = nil
- if @last_map_index
- @patch_window.select(@last_map_index)
- @last_map_index = nil
- end
- @patch_window.refresh
- else
- @patch_window.clear_category
- end
- end
- end
- end # def update
- end # Scene_DSIPatch
- class Window_Patch_Type < Window_Command
- attr_accessor :current_category
- attr_accessor :second_category
- attr_accessor :last_index
- attr_accessor :selected_data
- #--------------------------------------------------------------------------
- # * new method: init_data
- #--------------------------------------------------------------------------
- def init_data
- @selected_data = {}
- end
- #--------------------------------------------------------------------------
- # * Get Number of Lines to Show
- #--------------------------------------------------------------------------
- def visible_line_number
- return 12
- end
- #----------------------------------------------------------------------------
- # * window_width
- #----------------------------------------------------------------------------
- def window_width
- return 400
- end
- #--------------------------------------------------------------------------
- # * new method: clear_category
- #--------------------------------------------------------------------------
- def clear_category
- @current_category = nil
- refresh
- select(@last_index)
- end
- #--------------------------------------------------------------------------
- # * new method: set_category
- #--------------------------------------------------------------------------
- def set_category(category)
- @last_index = index
- @current_category = category
- refresh
- select(0)
- end
- #--------------------------------------------------------------------------
- # * new method: has_current_item
- #--------------------------------------------------------------------------
- def has_current_item
- type = current_item_data[0]
- id = current_item_data[1]
- @selected_data[type] && @selected_data[type].include?(id)
- end
- #--------------------------------------------------------------------------
- # * new method: unselect_current_item
- #--------------------------------------------------------------------------
- def unselect_current_item
- type = current_item_data[0]
- id = current_item_data[1]
- @selected_data[type].delete(id)
- end
- #--------------------------------------------------------------------------
- # * new method: add_current_item
- #--------------------------------------------------------------------------
- def add_current_item
- type = current_item_data[0]
- id = current_item_data[1]
- add_item(type,id)
- end
- #--------------------------------------------------------------------------
- # * new method: selected_all?
- #--------------------------------------------------------------------------
- def selected_all?
- return if current_item_data.nil?
- type = current_item_data[0]
- @selected_data[type] ||= []
- @selected_data[type].size == item_max+1
- end
- #--------------------------------------------------------------------------
- # * new method: unselect_all_item
- #--------------------------------------------------------------------------
- def unselect_all_item
- type = current_item_data[0]
- @selected_data[type] ||= []
- @selected_data[type].clear
- end
- #--------------------------------------------------------------------------
- # * new method: select_all_item
- #--------------------------------------------------------------------------
- def select_all_item
- return if current_item_data.nil?
- type = current_item_data[0]
- (item_max+1).times do |id|
- @selected_data[type] ||= []
- @selected_data[type] << id
- end
- @selected_data[type].uniq!
- end
- #--------------------------------------------------------------------------
- # * new method: add_item
- #--------------------------------------------------------------------------
- def add_item(type,id)
- @selected_data[type] ||= []
- @selected_data[type] << id
- p @selected_data
- end
- #--------------------------------------------------------------------------
- # * new method: item_data
- #--------------------------------------------------------------------------
- def item_data(index)
- [@list[index][:item_type],@list[index][:item_id]]
- end
- #--------------------------------------------------------------------------
- # * new method: current_item_data
- #--------------------------------------------------------------------------
- def current_item_data
- if current_data
- [current_data[:item_type],current_data[:item_id]]
- end
- end
- #--------------------------------------------------------------------------
- # * overwrite method: draw_item
- #--------------------------------------------------------------------------
- def draw_item(index)
- change_color(normal_color, command_enabled?(index))
- if @current_category
- data = item_data(index)
- if !@second_category
- if @selected_data[data[0]] && @selected_data[data[0]].include?(data[1])
- contents.fill_rect(item_rect_for_text(index), Color.new(200,121,142,200))
- end
- else
- if @selected_data[:map_event] && @selected_data[:map_event][@second_category] && @selected_data[:map_event][@second_category].include?(data[1])
- contents.fill_rect(item_rect_for_text(index), Color.new(200,121,142,200))
- end
- end
- end
- draw_text(item_rect_for_text(index), command_name(index), alignment)
- end
- #----------------------------------------------------------------------------
- # * overwrite method: add_command
- #----------------------------------------------------------------------------
- def add_command(name, symbol, enabled = true, ext = nil, item_id=nil, item_type=nil)
- @list.push({:name=>name, :symbol=>symbol, :enabled=>enabled, :ext=>ext, :item_id=>item_id, :item_type=>item_type})
- end
- #----------------------------------------------------------------------------
- # * alias method: make_command_list
- #----------------------------------------------------------------------------
- def make_command_list
- if @second_category
- map_data = load_data(sprintf("Data/Map%03d.rvdata2", @second_category))
- map_data.events.each_pair do |key,event|
- add_command("#{key} - #{event.name}", event.id.to_s.to_sym, true, nil, key, @current_category)
- end
- return
- end
- if @current_category
- data = DSIVER144::PATCH_SYSTEM.get_data(@current_category)
- if ![:map_info, :map_event].include?(@current_category)
- data.each do |thing|
- next if thing.nil?
- add_command("#{thing.id} - #{thing.name}", thing.name.to_sym, true, nil, thing.id, @current_category)
- end
- else
- data.each_pair do |map_id, map_data|
- map = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
- enabled = @current_category == :map_info ? true : map.events.size > 0
- add_command("#{map_id} - #{map_data.name}", map_id.to_s.to_sym, enabled, nil, map_id, @current_category)
- end
- end
- return
- end
- keys = [:item,:weapon,:armor,:actor,:class,:skill,:enemy,:troop,:state,:animation,:tileset,:common_event,:map_info,:map_event]
- keys.each do |key|
- name = key.to_s
- if key == :map_info; name = "MAPS"; end;
- if key == :map_event; name = "ADD NEW EVENT TO MAP"; end;
- add_command(name.upcase, key)
- end
- end
- end # Window_Patch_Type
- #===============================================================================
- # * END OF SCRIPT
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement