Advertisement
ezmash

Cross Reference System (XP)

Apr 21st, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 38.17 KB | None | 0 0
  1. #==============================================================================
  2. # Cross Reference System (XP)
  3. # by Shaz
  4. # Version 1.00
  5. #==============================================================================
  6. # Place script into new slot above Main
  7. # F9 debug now offers a choice between the old debug and the Cross Reference
  8. # system
  9. #
  10. # May not work if you have other scripts that modify the Scene_Map.call_debug
  11. # method
  12. #
  13. #==============================================================================
  14. # This is a development tool and should be removed prior to releasing your game
  15. # Do not repost this script.  Link back to original thread only:
  16. # https://forums.rpgmakerweb.com/index.php?threads/cross-reference-script-xp.94371/
  17. #==============================================================================
  18.  
  19.  
  20. module XRef
  21.   VAREXP = /\\v\[(\d+)\]/i
  22.    
  23.   class EventRef
  24.     def initialize(evt_id, evt_name, evt_page, evt_line)
  25.       @evt_id = evt_id
  26.       @evt_name = evt_name
  27.       @evt_page = evt_page
  28.       @evt_line = evt_line
  29.     end
  30.     attr_accessor :evt_id   # only for map events
  31.     attr_accessor :evt_name # only for map events
  32.     attr_accessor :evt_page # only for map and troop events
  33.     attr_accessor :evt_line # only for map, troop and common events
  34.   end # class EventRef
  35.  
  36.   class Reference
  37.     def initialize(obj_type, obj_id, src_type, src_id, evt, ref, seq)
  38.       @obj_type = obj_type
  39.       @obj_id = obj_id
  40.       @src_type = src_type
  41.       @src_id = src_id
  42.       @evt = evt
  43.       @ref = ref
  44.       @seq = seq
  45.     end
  46.     attr_accessor :obj_type   # referenced object - :switch, :variable, etc
  47.     attr_accessor :obj_id     # object id from database, or variable/switch id
  48.     attr_accessor :src_type   # referencing object type - :actor, :map, etc
  49.     attr_accessor :src_id     # referencing object id - actor id, map id, etc
  50.     attr_accessor :evt        # event info
  51.     attr_accessor :ref        # type of reference (command code or field)
  52.     attr_accessor :seq        # sequence within reference
  53.   end # class Reference
  54.    
  55.   class References
  56.     def initialize
  57.       @references = []
  58.     end
  59.    
  60.     def add(ref)
  61.       @references.push(ref)
  62.     end
  63.    
  64.     def refs
  65.       @references
  66.     end
  67.   end # class References
  68.  
  69.   class ReferencedObjects
  70.     def initialize
  71.       @objects = Hash.new { |hash, key| hash[key] = References.new }
  72.     end
  73.    
  74.     def add(ref)
  75.       @objects[ref.obj_id].add(ref)
  76.     end
  77.    
  78.     def ids
  79.       @objects.keys
  80.     end
  81.    
  82.     def xrefs(id)
  83.       @objects[id].refs
  84.     end
  85.   end # class ReferencedObjects
  86.  
  87.   class CrossReferences
  88.     def initialize
  89.       @referenced_objects = Hash.new { |hash, key| hash[key] = ReferencedObjects.new }
  90.     end
  91.    
  92.     def add(ref)
  93.       @referenced_objects[ref.obj_type].add(ref)
  94.       prttxt = sprintf('%s^%d^%s^', XRef.data_title(ref.obj_type), ref.obj_id,
  95.         XRef.obj_name(ref.obj_type, ref.obj_id))
  96.       prttxt += sprintf('%s^%d^%s^', XRef.data_title(ref.src_type), ref.src_id,
  97.         XRef.obj_name(ref.src_type, ref.src_id))
  98.       if ref.evt && ref.evt.evt_id
  99.         prttxt += sprintf('EV%03d^%s^', ref.evt.evt_id, ref.evt.evt_name)
  100.       else
  101.         prttxt += sprintf('^^')
  102.       end
  103.       if ref.evt
  104.         prttxt += sprintf('%s^%s^', ref.evt.evt_page.to_s, ref.evt.evt_line.to_s)
  105.       else
  106.         prttxt += sprintf('^^')
  107.       end
  108.       prttxt += sprintf('%s', XRef.command(ref.ref))
  109.       $xref_file.puts prttxt
  110.     end
  111.    
  112.     def xrefs(type, id)
  113.       @referenced_objects[type].xrefs(id)
  114.     end
  115.    
  116.     def xref_ids(type)
  117.       @referenced_objects[type].ids
  118.     end
  119.    
  120.     def xref_types
  121.       @referenced_objects.keys
  122.     end
  123.   end # class CrossReferences
  124.  
  125.   #--------------------------------------------------------------------------
  126.   # * XRef Builder
  127.   #--------------------------------------------------------------------------
  128.   def self.data_sources(sym)
  129.     src =  {:switches       =>      $data_system.switches,
  130.             :variables      =>      $data_system.variables,
  131.             :common_events  =>      $data_common_events,
  132.             :actors         =>      $data_actors,
  133.             :classes        =>      $data_classes,
  134.             :skills         =>      $data_skills,
  135.             :items          =>      $data_items,
  136.             :weapons        =>      $data_weapons,
  137.             :armors         =>      $data_armors,
  138.             :enemies        =>      $data_enemies,
  139.             :troops         =>      $data_troops,
  140.             :states         =>      $data_states,
  141.             :animations     =>      $data_animations,
  142.             :system         =>      $data_system,
  143.             :maps           =>      $data_mapinfos}
  144.     return src[sym]
  145.   end
  146.      
  147.   def self.data_title(sym)
  148.     title = {:switches       =>      'Switch',
  149.              :variables      =>      'Variable',
  150.              :common_events  =>      'Common Event',
  151.              :actors         =>      'Actor',
  152.              :classes        =>      'Class',
  153.              :skills         =>      'Skill',
  154.              :items          =>      'Item',
  155.              :weapons        =>      'Weapon',
  156.              :armors         =>      'Armor',
  157.              :enemies        =>      'Enemy',
  158.              :troops         =>      'Troop',
  159.              :states         =>      'State',
  160.              :animations     =>      'Animation',
  161.              :system         =>      'System',
  162.              :maps           =>      'Map'}
  163.     return title[sym]
  164.   end
  165.    
  166.   def self.command(code)
  167.     codes =  {101 => 'Show Text',
  168.               401 => 'Show Text', # continuation
  169.               102 => 'Show Choices',
  170.               103 => 'Input Number',
  171.               105 => 'Button Input Processing',
  172.               111 => 'Conditional Branch',
  173.               117 => 'Call Common Event',
  174.               121 => 'Control Switches',
  175.               122 => 'Control Variables',
  176.               125 => 'Change Gold',
  177.               126 => 'Change Items',
  178.               127 => 'Change Weapons',
  179.               128 => 'Change Armor',
  180.               129 => 'Change Party Member',
  181.               201 => 'Transfer Player',
  182.               202 => 'Set Event Location',
  183.               207 => 'Show Animation',
  184.               231 => 'Show Picture',
  185.               232 => 'Move Picture',
  186.               301 => 'Battle Processing',
  187.               302 => 'Shop Processing',
  188.               605 => 'Shop Processing', # continuation
  189.               303 => 'Name Input Processing',
  190.               311 => 'Change HP',
  191.               312 => 'Change SP',
  192.               313 => 'Change State',
  193.               314 => 'Recover All',
  194.               315 => 'Change EXP',
  195.               316 => 'Change Level',
  196.               317 => 'Change Parameters',
  197.               318 => 'Change Skills',
  198.               319 => 'Change Equipment',
  199.               320 => 'Change Name',
  200.               321 => 'Change Class',
  201.               322 => 'Change Actor Graphic',
  202.               331 => 'Change Enemy HP',
  203.               332 => 'Change Enemy SP',
  204.               333 => 'Change Enemy State',
  205.               336 => 'Enemy Transform',
  206.               337 => 'Show Battle Animation',
  207.               338 => 'Deal Damage',
  208.               339 => 'Force Action',
  209.               509 => 'Set Move Route',
  210.               :condition => 'Condition',
  211.               :name => 'Name',
  212.               :cls => 'Class',
  213.               :equips => 'Equips',
  214.               :learnings => 'Learnings',
  215.               :description => 'Description',
  216.               :animations => 'Animation',
  217.               :common_events => 'Common Event',
  218.               :states => 'State',
  219.               :drop_items => 'Drop Items',
  220.               :action_pattersn => 'Action Patterns',
  221.               :member => 'Members',
  222.               :encounters => 'Encounters',
  223.               :starting_members => 'Starting Members',
  224.               :plus_state => 'Add State',
  225.               :minus_state => 'Remove State',
  226.               :guard_state => 'Guard State'
  227.              }
  228.     return codes.has_key?(code) ? codes[code] : code.to_s
  229.   end
  230.    
  231.   def self.obj_name(obj_type, id)
  232.     case obj_type
  233.     when :system
  234.       'Party Members'
  235.     when :switches, :variables
  236.       data_sources(obj_type)[id]
  237.     else
  238.       data_sources(obj_type)[id] ? data_sources(obj_type)[id].name : ''
  239.     end
  240.   end
  241.  
  242.   def self.obj_types
  243.     @cross_references.xref_types
  244.   end
  245.    
  246.   def self.refs(obj_type, obj_id)
  247.     @cross_references.xrefs(obj_type, obj_id)
  248.   end
  249.  
  250.   def self.load_xrefs
  251.     return if !@cross_references.nil?
  252.      
  253.     $xref_file = File.open('Xrefs.txt', 'w')
  254.    
  255.     @cross_references = CrossReferences.new
  256.    
  257.     $data_mapinfos        = load_data("Data/MapInfos.rxdata")
  258.    
  259.     $data_actors.compact.each         {|actor|  build_actor_xrefs(actor)}
  260.     $data_classes.compact.each        {|cls|    build_class_xrefs(cls)}
  261.     $data_skills.compact.each         {|skill|  build_skill_xrefs(skill)}
  262.     $data_items.compact.each          {|item|   build_item_xrefs(item)}
  263.     $data_weapons.compact.each        {|weapon| build_weapon_xrefs(weapon)}
  264.     $data_armors.compact.each         {|armor|  build_armor_xrefs(armor)}
  265.     $data_enemies.compact.each        {|enemy|  build_enemy_xrefs(enemy)}
  266.     $data_troops.compact.each         {|troop|  build_troop_xrefs(troop)}
  267.     $data_states.compact.each         {|state|  build_state_xrefs(state)}
  268.     $data_common_events.compact.each  {|evt|    build_common_event_xrefs(evt)}
  269.     build_system_xrefs
  270.      
  271.     Dir.glob('Data/Map???.rxdata').each {|filename| build_map_xrefs(filename)}
  272.    
  273.     $xref_file.close
  274.   end
  275.    
  276.   def self.save(obj_type, obj_id, ref = @cmd_code, seq = nil)
  277.     if @evt_id || @evt_page || @evt_line
  278.       evt = EventRef.new(@evt_id, @evt_name, @evt_page, @evt_line)
  279.     else
  280.       evt = nil
  281.     end
  282.     xref = Reference.new(obj_type, obj_id, @src_type, @src_id, evt, ref, seq)
  283.     @cross_references.add(xref)
  284.   end
  285.    
  286.   def self.scan_db_text(text, ref = @cmd_code)
  287.     seq = 0
  288.     text.scan(VAREXP).flatten.map {|val| val.to_i}.each do |var|
  289.       save(:variables, var, ref, seq)
  290.       seq += 1
  291.     end
  292.   end
  293.    
  294.   def self.build_actor_xrefs(actor)
  295.     @src_type = :actors
  296.     @src_id = actor.id
  297.      
  298.     # Text fields
  299.     scan_db_text(actor.name, :name)
  300.      
  301.     # Class
  302.     save(:classes, actor.class_id, :cls)
  303.    
  304.     # Starting equipment
  305.     save(:weapons, actor.weapon_id, :equips) if actor.weapon_id > 0
  306.     save(:armors, actor.armor1_id, :equips, 1) if actor.armor1_id > 0
  307.     save(:armors, actor.armor2_id, :equips, 2) if actor.armor2_id > 0
  308.     save(:armors, actor.armor3_id, :equips, 3) if actor.armor3_id > 0
  309.     save(:armors, actor.armor4_id, :equips, 4) if actor.armor4_id > 0
  310.   end
  311.    
  312.   def self.build_class_xrefs(cls)
  313.     @src_type = :classes
  314.     @src_id = cls.id
  315.    
  316.     # Text fields
  317.     scan_db_text(cls.name, :name)
  318.    
  319.     # Weapons
  320.     cls.weapon_set.each {|weapon| save(:weapons, weapon, :equips)}
  321.    
  322.     # Armors
  323.     cls.armor_set.each {|armor| save(:armors, armor, :equips)}
  324.    
  325.     # Learnings
  326.     cls.learnings.each_index do |index|
  327.       skill = cls.learnings[index]
  328.       save(:skills, skill.skill_id, :learnings, index) if !skill.nil?
  329.     end
  330.   end
  331.    
  332.   def self.build_skill_xrefs(skill)
  333.     @src_type = :skills
  334.     @src_id = skill.id
  335.    
  336.     # Text fields
  337.     scan_db_text(skill.name, :name)
  338.     scan_db_text(skill.description, :description)
  339.    
  340.     # Animation
  341.     save(:animations, skill.animation1_id, :animations, 1) if skill.animation1_id > 0
  342.     save(:animations, skill.animation2_id, :animations, 2) if skill.animation2_id > 0
  343.    
  344.     # Common event
  345.     save(:common_events, skill.common_event_id, :common_events) if skill.common_event_id > 0
  346.    
  347.     # States
  348.     skill.plus_state_set.each do |state|
  349.       save(:states, state, :plus_state)
  350.     end
  351.     skill.minus_state_set.each do |state|
  352.       save(:states, state, :minus_state)
  353.     end
  354.   end
  355.    
  356.   def self.build_item_xrefs(item)
  357.     @src_type = :items
  358.     @src_id = item.id
  359.    
  360.     # Text fields
  361.     scan_db_text(item.name, :name)
  362.     scan_db_text(item.description, :description)
  363.    
  364.     # Animation
  365.     save(:animations, item.animation1_id, :animations, 1) if item.animation1_id > 0
  366.     save(:animations, item.animation2_id, :animations, 2) if item.animation2_id > 0
  367.    
  368.     # Common event
  369.     save(:common_events, item.common_event_id, :common_events) if item.common_event_id > 0
  370.    
  371.     # States
  372.     item.plus_state_set.each do |state|
  373.       save(:states, state, :plus_state)
  374.     end
  375.     item.minus_state_set.each do |state|
  376.       save(:states, state, :minus_state)
  377.     end
  378.   end
  379.    
  380.   def self.build_weapon_xrefs(weapon)
  381.     @src_type = :weapons
  382.     @src_id = weapon.id
  383.    
  384.     # Text fields
  385.     scan_db_text(weapon.name, :name)
  386.     scan_db_text(weapon.description, :description)
  387.    
  388.     # Animation
  389.     save(:animations, weapon.animation1_id, :animations, 1) if weapon.animation1_id > 0
  390.     save(:animations, weapon.animation2_id, :animations, 2) if weapon.animation2_id > 0
  391.    
  392.     # States
  393.     weapon.plus_state_set.each do |state|
  394.       save(:states, state, :plus_state)
  395.     end
  396.     weapon.minus_state_set.each do |state|
  397.       save(:states, state, :minus_state)
  398.     end
  399.   end
  400.    
  401.   def self.build_armor_xrefs(armor)
  402.     @src_type = :armors
  403.     @src_id = armor.id
  404.    
  405.     # Text fields
  406.     scan_db_text(armor.name, :name)
  407.     scan_db_text(armor.description, :description)
  408.    
  409.     # State
  410.     save(:states, armor.auto_state_id, :states) if armor.auto_state_id > 0
  411.    
  412.     # States
  413.     armor.guard_state_set.each do |state|
  414.       save(:states, state, :guard_state)
  415.     end
  416.   end
  417.    
  418.   def self.build_enemy_xrefs(enemy)
  419.     @src_type = :enemies
  420.     @src_id = enemy.id
  421.    
  422.     # Text fields
  423.     scan_db_text(enemy.name, :name)
  424.    
  425.     # Animation
  426.     save(:animations, enemy.animation1_id, :animations, 1) if enemy.animation1_id > 0
  427.     save(:animations, enemy.animation2_id, :animations, 2) if enemy.animation2_id > 0
  428.    
  429.     # Drop Items
  430.     save(:items, enemy.item_id, :drop_items) if enemy.item_id > 0
  431.     save(:weapons, enemy.weapon_id, :drop_items) if enemy.weapon_id > 0
  432.     save(:armors, enemy.armor_id, :drop_items) if enemy.armor_id > 0
  433.    
  434.     # Actions
  435.     enemy.actions.each_index do |index|
  436.       action = enemy.actions[index]
  437.       save(:skills, action.skill_id, :action_pattern, index) if action.skill_id > 0
  438.       save(:switches, action.condition_switch_id, :action_pattern, index) if action.condition_switch_id > 0
  439.     end
  440.   end
  441.    
  442.   def self.build_troop_xrefs(troop)
  443.     @src_type = :troops
  444.     @src_id = troop.id
  445.    
  446.     # Text fields
  447.     scan_db_text(troop.name, :name)
  448.    
  449.     # Members
  450.     used = []
  451.     troop.members.each_index do |index|
  452.       enemy = troop.members[index].enemy_id
  453.       if !used.include?(enemy)
  454.         save(:enemies, enemy, :member, index)
  455.         used.push(enemy)
  456.       end
  457.     end
  458.    
  459.     # Pages
  460.     troop.pages.each_index do |page|
  461.       @evt_page = page + 1
  462.       @evt_line = nil
  463.      
  464.       # Page condition
  465.       cond = troop.pages[page].condition
  466.       save(:actors, cond.actor_id, :condition) if cond.actor_valid
  467.       save(:switches, cond.switch_id, :condition) if cond.switch_valid
  468.      
  469.       # Event commands
  470.       @list = troop.pages[page].list
  471.       build_event_xrefs
  472.     end
  473.    
  474.     @evt_page = nil
  475.     @evt_line = nil
  476.   end
  477.    
  478.   def self.build_state_xrefs(state)
  479.     @src_type = :states
  480.     @src_id = state.id
  481.    
  482.     # Text fields
  483.     scan_db_text(state.name, :name)
  484.    
  485.     # Animation
  486.     save(:animations, state.animation_id, :animations) if state.animation_id > 0
  487.    
  488.     # States
  489.     state.plus_state_set.each do |state|
  490.       save(:states, state, :plus_state)
  491.     end
  492.     state.minus_state_set.each do |state|
  493.       save(:states, state, :minus_state)
  494.     end
  495.   end
  496.    
  497.   def self.build_common_event_xrefs(evt)
  498.     @src_type = :common_events
  499.     @src_id = evt.id
  500.    
  501.     # Text fields
  502.     scan_db_text(evt.name, :name)
  503.    
  504.     # Conditions
  505.     save(:switches, evt.switch_id, :condition) if evt.trigger > 0
  506.    
  507.     # Event commands
  508.     @list = evt.list
  509.     build_event_xrefs
  510.    
  511.     @evt_line = nil
  512.   end
  513.    
  514.   def self.build_map_xrefs(filename)
  515.     $xref_file.puts(filename)
  516.     map_id = /Data\/Map(\d+)\.rxdata/.match(filename)[1].to_i
  517.     $xref_file.puts(map_id)
  518.     @src_type = :maps
  519.     @src_id = map_id
  520.     map = load_data(filename)
  521.    
  522.     # Text fields
  523.     scan_db_text($data_mapinfos[map_id].name, :name) if $data_mapinfos[map_id]
  524.    
  525.     # Encounters
  526.     map.encounter_list.each do |troop_id|
  527.       save(:troops, troop_id, :encounters)
  528.     end
  529.    
  530.     # Events
  531.     map.events.each do |evt_id, evt|
  532.       next if evt.nil? || evt.pages.nil?
  533.       @evt_id = evt_id
  534.       @evt_name = evt.name
  535.      
  536.       evt.pages.each_index do |page|
  537.         @evt_page = page + 1
  538.         @evt_line = nil
  539.        
  540.         # Conditions
  541.         cond = evt.pages[page].condition
  542.         save(:switches, cond.switch1_id, :condition, 1) if cond.switch1_valid
  543.         save(:switches, cond.switch2_id, :condition, 2) if cond.switch2_valid
  544.         save(:variables, cond.variable_id, :condition, 3) if cond.variable_valid
  545.        
  546.         # Event commands
  547.         @list = evt.pages[page].list
  548.         build_event_xrefs
  549.       end
  550.     end
  551.    
  552.     @evt_page = nil
  553.     @evt_line = nil
  554.   end
  555.  
  556.   def self.build_system_xrefs
  557.     @src_type = :system
  558.     @src_id = 0
  559.    
  560.     # Members
  561.     $data_system.party_members.each do |actor_id|
  562.       save(:actors, actor_id, :starting_members)
  563.     end
  564.   end
  565.  
  566.   def self.build_event_xrefs
  567.     return if @list.nil?
  568.     @list.each_index do |line|
  569.       @evt_line = line + 1
  570.       @cmd_code = @list[line].code
  571.       @params = @list[line].parameters.clone
  572.      
  573.       $xref_file.puts("command " + @cmd_code.to_s + ": " + @params.to_s)
  574.      
  575.       method_name = "build_xrefs_command_#{@cmd_code}"
  576.       send(method_name) if respond_to?(method_name)
  577.     end
  578.   end
  579.  
  580.   # Show Text
  581.   def self.build_xrefs_command_101
  582.     scan_db_text(@params[0])
  583.   end
  584.  
  585.   def self.build_xrefs_command_401
  586.     scan_db_text(@params[0])
  587.   end
  588.  
  589.   # Show Choices
  590.   def self.build_xrefs_command_102
  591.     @params[0].each {|choice| scan_db_text(choice) }
  592.   end
  593.  
  594.   # Input Number
  595.   def self.build_xrefs_command_103
  596.     save(:variables, @params[0])
  597.   end
  598.  
  599.   # Button Input Processing
  600.   def self.build_xrefs_command_105
  601.     save(:variables, @params[0])
  602.   end
  603.  
  604.   # Conditional Branch
  605.   def self.build_xrefs_command_111
  606.     case @params[0]
  607.     when 0 # Switch
  608.       save(:switches, @params[1])
  609.     when 1 # Variable
  610.       save(:variables, @params[1])
  611.       save(:variables, @params[3]) if @params[2] != 0
  612.     when 4 # Actor
  613.       save(:actors, @params[1])
  614.       save(:skills, @params[3]) if @params[2] == 2
  615.       save(:weapons, @params[3]) if @params[2] == 3
  616.       save(:armors, @params[3]) if @params[2] == 4
  617.       save(:states, @params[3]) if @params[2] == 5
  618.     when 5 # Enemy
  619.       save(:states, @params[3]) if @params[2] == 1
  620.     when 8 # Item
  621.       save(:items, @params[1])
  622.     when 9 # Weapons
  623.       save(:weapons, @params[1])
  624.     when 10 # Armors
  625.       save(:armors, @params[1])
  626.     end
  627.   end
  628.  
  629.   # Common Event
  630.   def self.build_xrefs_command_117
  631.     save(:common_events, @params[0])
  632.   end
  633.  
  634.   # Control Switches
  635.   def self.build_xrefs_command_121
  636.     (@params[0]..@params[1]).each do |switch|
  637.       save(:switches, switch)
  638.     end
  639.   end
  640.  
  641.   # Control Variables
  642.   def self.build_xrefs_command_122
  643.     (@params[0]..@params[1]).each do |variable|
  644.       save(:variables, variable)
  645.     end
  646.     save(:variables, @params[4]) if @params[3] == 1
  647.     save(:items, @params[4]) if @params[3] == 3
  648.     save(:actors, @params[4]) if @params[3] == 4
  649.   end
  650.  
  651.   # Change Gold
  652.   def self.build_xrefs_command_125
  653.     save(:variables, @params[2]) if @params[1] != 0
  654.   end
  655.  
  656.   # Change Items
  657.   def self.build_xrefs_command_126
  658.     save(:items, @params[0])
  659.     save(:variables, @params[3]) if @params[2] != 0
  660.   end
  661.  
  662.   # Change Weapons
  663.   def self.build_xrefs_command_127
  664.     save(:weapons, @params[0])
  665.     save(:variables, @params[3]) if @params[2] != 0
  666.   end
  667.  
  668.   # Change Armor
  669.   def self.build_xrefs_command_128
  670.     save(:armors, @params[0])
  671.     save(:variables, @params[3]) if @params[2] != 0
  672.   end
  673.  
  674.   # Change Party Member
  675.   def self.build_xrefs_command_129
  676.     save(:actors, @params[0])
  677.   end
  678.    
  679.   # Transfer Player
  680.   def self.build_xrefs_command_201
  681.     if @params[0] != 0
  682.       save(:variables, @params[1])
  683.       save(:variables, @params[2])
  684.       save(:variables, @params[3])
  685.     end
  686.   end
  687.  
  688.   # Set Event Location
  689.   def self.build_xrefs_command_202
  690.     if @params[1] != 0
  691.       save(:variables, @params[2])
  692.       save(:variables, @params[3])
  693.     end
  694.   end
  695.  
  696.   # Show Animation
  697.   def self.build_xrefs_command_207
  698.     save(:animations, @params[1])
  699.   end
  700.  
  701.   # Set Move Route
  702.   def self.build_xrefs_command_509
  703.     save(:switches, @params[0].parameters[0]) if [27,28].include?(@params[0].code)
  704.   end
  705.  
  706.   # Show Picture
  707.   def self.build_xrefs_command_231
  708.     if @params[3] != 0
  709.       save(:variables, @params[4])
  710.       save(:variables, @params[5])
  711.     end
  712.   end
  713.  
  714.   # Move Picture
  715.   def self.build_xrefs_command_232
  716.     if @params[3] != 0
  717.       save(:variables, @params[4])
  718.       save(:variables, @params[5])
  719.     end
  720.   end
  721.  
  722.   # Battle Processing
  723.   def self.build_xrefs_command_301
  724.     save(:troops, @params[0])
  725.   end
  726.  
  727.   # Shop Processing
  728.   def self.build_xrefs_command_302
  729.     save([:items, :weapons, :armors][@params[0]], @params[1])
  730.   end
  731.  
  732.   def self.build_xrefs_command_605
  733.     save([:items, :weapons, :armors][@params[0]], @params[1])
  734.   end
  735.  
  736.   # Name Input Processing
  737.   def self.build_xrefs_command_303
  738.     save(:actors, @params[0])
  739.   end
  740.  
  741.   # Change HP
  742.   def self.build_xrefs_command_311
  743.     if @params[0] == 0
  744.       $data_actors.compact.each do |actor|
  745.         save(:actors, actor.id)
  746.       end
  747.     else
  748.       save(:actors, @params[0])
  749.     end
  750.     save(:variables, @params[3]) if @params[2] != 0
  751.   end
  752.  
  753.   # Change SP
  754.   def self.build_xrefs_command_312
  755.     if @params[0] == 0
  756.       $data_actors.compact.each do |actor|
  757.         save(:actors, actor.id)
  758.       end
  759.     else
  760.       save(:actors, @params[0])
  761.     end
  762.     save(:variables, @params[3]) if @params[2] != 0
  763.   end
  764.  
  765.   # Change State
  766.   def self.build_xrefs_command_313
  767.     if @params[0] == 0
  768.       $data_actors.compact.each do |actor|
  769.         save(:actors, actor.id)
  770.       end
  771.     else
  772.       save(:actors, @params[0])
  773.     end
  774.     save(:states, @params[3])
  775.   end
  776.  
  777.   # Recover All
  778.   def self.build_xrefs_command_314
  779.     if @params[0] == 0
  780.       $data_actors.compact.each do |actor|
  781.         save(:actors, actor.id)
  782.       end
  783.     else
  784.       save(:actors, @params[0])
  785.     end
  786.   end
  787.  
  788.   # Change EXP
  789.   def self.build_xrefs_command_315
  790.       if @params[0] == 0
  791.       $data_actors.compact.each do |actor|
  792.         save(:actors, actor.id)
  793.       end
  794.     else
  795.       save(:actors, @params[0])
  796.     end
  797.     save(:variables, @params[3]) if @params[2] != 0
  798.   end
  799.  
  800.   # Change Level
  801.   def self.build_xrefs_command_316
  802.     if @params[0] == 0
  803.       $data_actors.compact.each do |actor|
  804.         save(:actors, actor.id)
  805.       end
  806.     else
  807.       save(:actors, @params[0])
  808.     end
  809.   end
  810.  
  811.   # Change Parameters
  812.   def self.build_xrefs_command_317
  813.     if @params[0] == 0
  814.       $data_actors.compact.each do |actor|
  815.         save(:actors, actor.id)
  816.       end
  817.     else
  818.       save(:actors, @params[0])
  819.     end
  820.   end
  821.  
  822.   # Change Skills
  823.   def self.build_xrefs_command_318
  824.     save(:actors, @params[0])
  825.     save(:skills, @params[2])
  826.   end
  827.  
  828.   # Change Equipment
  829.   def self.build_xrefs_command_319
  830.     save(:actors, @params[0])
  831.     save(:weapons, @params[2]) if @params[1] == 0
  832.     save(:armors, @params[2]) if @params[1] != 0
  833.   end
  834.  
  835.   # Change Actor Name
  836.   def self.build_xrefs_command_320
  837.     save(:actors, @params[0])
  838.   end
  839.  
  840.   # Change Actor Class
  841.   def self.build_xrefs_command_321
  842.     save(:actors, @params[0])
  843.     save(:classes, @params[1])
  844.   end
  845.  
  846.   # Change Actor Graphic
  847.   def self.build_xrefs_command_322
  848.     save(:actors, @params[0])
  849.   end
  850.  
  851.   # Change Enemy HP
  852.   def self.build_xrefs_command_331
  853.     save(:variables, @params[3]) if @params[2] != 0
  854.   end
  855.  
  856.   # Change Enemy SP
  857.   def self.build_xrefs_command_332
  858.     save(:variables, @params[3]) if @params[2] != 0
  859.   end
  860.  
  861.   # Change Enemy State
  862.   def self.build_xrefs_command_333
  863.     save(:states, @params[2])
  864.   end
  865.  
  866.   # Enemy Transform
  867.   def self.build_xrefs_command_336
  868.     save(:enemies, @params[1])
  869.   end
  870.  
  871.   # Show Battle Animation
  872.   def self.build_xrefs_command_337
  873.     save(:animations, @params[2])
  874.   end
  875.  
  876.   # Deal Damage
  877.   def self.build_xrefs_command_338
  878.     save(:variables, @params[3]) if @params[2] != 0
  879.   end
  880.  
  881.   # Force Action
  882.   def self.build_xrefs_command_339
  883.     save(:skills, @params[3]) if @params[2] != 0
  884.   end    
  885. end
  886.  
  887.  
  888. class Window_XRef_Selection < Window_Selectable
  889.   def initialize
  890.     super(0, 0, 480, 480)
  891.     self.contents = Bitmap.new(width - 32, height - 32)
  892.     self.active = false
  893.     self.index = 0
  894.     @column_max = 2
  895.     @mode = nil
  896.   end
  897.  
  898.   def set_mode(mode)
  899.     @mode = mode
  900.     refresh
  901.   end
  902.  
  903.   def refresh
  904.     if self.contents != nil
  905.       self.contents.dispose
  906.       self.contents = nil
  907.     end
  908.     @data = Array.new(XRef.data_sources(@mode).size - 1) {|id| id + 1}
  909.     @item_max = @data.size
  910.     self.contents = Bitmap.new(width - 32, row_max * 32)
  911.     for i in 0...@item_max
  912.       draw_item(i)
  913.     end    
  914.     self.index = 0
  915.   end
  916.  
  917.   def item
  918.     @data && index >= 0 ? @data[index] : nil
  919.   end
  920.  
  921.   def draw_item(index)
  922.     item = @data[index]
  923.     return if item.nil?
  924.    
  925.     x = 4 + index % 2 * (208 + 32)
  926.     y = index / 2 * 32
  927.    
  928.     id_text = sprintf('%04d: %s', item, XRef.obj_name(@mode, item))
  929.    
  930.     self.contents.font.color = XRef.refs(@mode, item).empty? ? disabled_color : normal_color
  931.     self.contents.draw_text(x + 4, y + 4, width / 2 - 48, 32, id_text)
  932.   end    
  933. end
  934.  
  935. class Window_XRef_Result < Window_Selectable
  936.   def initialize
  937.     super(0, 64, 640, 416)
  938.     self.contents = Bitmap.new(width - 32, height - 32)
  939.     self.active = false
  940.     self.index = 0
  941.     @column_max = 1
  942.     @mode = nil
  943.     @obj = nil
  944.   end
  945.  
  946.   def set_ref(mode, obj)
  947.     @mode = mode
  948.     @obj = obj
  949.     refresh
  950.   end
  951.  
  952.   def refresh
  953.     if self.contents != nil
  954.       self.contents.dispose
  955.       self.contents = nil
  956.     end
  957.     @data = XRef.refs(@mode, @obj)
  958.     @item_max = @data.size
  959.     self.contents = Bitmap.new(width - 32, row_max * 32)
  960.     for i in 0...@item_max
  961.       draw_item(i)
  962.     end    
  963.     self.index = 0
  964.   end
  965.  
  966.   def draw_item(index)
  967.     item = @data[index]
  968.    
  969.     x = 4 + index % 2 * (288 + 32)
  970.     y = index * 32
  971.    
  972.     rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  973.     self.contents.fill_rect(rect, Color.new(0,0,0,0))
  974.     text = sprintf('%s %d: %s', XRef.data_title(item.src_type), item.src_id, XRef.obj_name(item.src_type, item.src_id))
  975.     self.contents.draw_text(0, y, 288, 32, text)
  976.     if item.evt && item.evt.evt_id
  977.       text =  sprintf('EV%03d: %s', item.evt.evt_id, item.evt.evt_name)
  978.       self.contents.draw_text(300, y, 288, 32, text)
  979.     end
  980.   end
  981.    
  982.   def update_help
  983.     help_text = ''
  984.     item = @data[self.index]
  985.     if !item.nil?
  986.       help_text += sprintf('Page: %s  Line: %s  ',
  987.         item.evt.evt_page.to_s, item.evt.evt_line.to_s) if item.evt
  988.       help_text += XRef.command(item.ref)
  989.     end
  990.     @help_window.set_text(help_text)
  991.   end
  992. end
  993.  
  994.  
  995. #==============================================================================
  996. # ** Scene_XRef
  997. #------------------------------------------------------------------------------
  998. #  This class performs cross reference processing.
  999. #==============================================================================
  1000.  
  1001. class Scene_XRef
  1002.   #--------------------------------------------------------------------------
  1003.   # * Object Initialization
  1004.   #     menu_index : command cursor's initial position
  1005.   #--------------------------------------------------------------------------
  1006.   def initialize(menu_index = 0)
  1007.     @menu_index = menu_index
  1008.     @commands = [:switches, :variables, :common_events, :actors, :classes,
  1009.                  :skills, :items, :weapons, :armors, :enemies, :troops,
  1010.                  :states, :animations]
  1011.   end
  1012.   #--------------------------------------------------------------------------
  1013.   # * Main Processing
  1014.   #--------------------------------------------------------------------------
  1015.   def main
  1016.     create_command_window
  1017.     create_selection_window
  1018.     create_help_window
  1019.     create_result_window
  1020.    
  1021.     # Execute transition
  1022.     Graphics.transition
  1023.     # Main loop
  1024.     loop do
  1025.       # Update game screen
  1026.       Graphics.update
  1027.       # Update input information
  1028.       Input.update
  1029.       # Frame update
  1030.       update
  1031.       # Abort loop if screen is changed
  1032.       if $scene != self
  1033.         break
  1034.       end
  1035.     end
  1036.    
  1037.     # Prepare for transition
  1038.     Graphics.freeze
  1039.     # Dispose of windows
  1040.     @command_window.dispose
  1041.     @selection_window.dispose
  1042.     @help_window.dispose
  1043.     @result_window.dispose
  1044.   end
  1045.   #--------------------------------------------------------------------------
  1046.   # * Create Command Window
  1047.   #--------------------------------------------------------------------------
  1048.   def create_command_window
  1049.     s1 = "Switches"
  1050.     s2 = "Variables"
  1051.     s3 = "Common Events"
  1052.     s4 = "Actors"
  1053.     s5 = "Classes"
  1054.     s6 = "Skills"
  1055.     s7 = "Items"
  1056.     s8 = "Weapons"
  1057.     s9 = "Armors"
  1058.     s10 = "Enemies"
  1059.     s11 = "Troops"
  1060.     s12 = "States"
  1061.     s13 = "Animations"
  1062.                
  1063.     @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13])
  1064.     @command_window.disable_item(0) if !XRef.obj_types.include?(:switches)
  1065.     @command_window.disable_item(1) if !XRef.obj_types.include?(:variables)
  1066.     @command_window.disable_item(2) if !XRef.obj_types.include?(:common_events)
  1067.     @command_window.disable_item(3) if !XRef.obj_types.include?(:actors)
  1068.     @command_window.disable_item(4) if !XRef.obj_types.include?(:classes)
  1069.     @command_window.disable_item(5) if !XRef.obj_types.include?(:skills)
  1070.     @command_window.disable_item(6) if !XRef.obj_types.include?(:items)
  1071.     @command_window.disable_item(7) if !XRef.obj_types.include?(:weapons)
  1072.     @command_window.disable_item(8) if !XRef.obj_types.include?(:armors)
  1073.     @command_window.disable_item(9) if !XRef.obj_types.include?(:enemies)
  1074.     @command_window.disable_item(10) if !XRef.obj_types.include?(:troops)
  1075.     @command_window.disable_item(11) if !XRef.obj_types.include?(:states)
  1076.     @command_window.disable_item(12) if !XRef.obj_types.include?(:animations)
  1077.    
  1078.     @command_window.index = @menu_index
  1079.   end
  1080.   #--------------------------------------------------------------------------
  1081.   # * Create Selection Window
  1082.   #--------------------------------------------------------------------------
  1083.   def create_selection_window
  1084.     @selection_window = Window_XRef_Selection.new
  1085.     @selection_window.x = 160
  1086.     @selection_window.y = 0
  1087.     @selection_window.visible = false
  1088.     @selection_window.active = false
  1089.   end
  1090.   #--------------------------------------------------------------------------
  1091.   # * Create Help Window
  1092.   #--------------------------------------------------------------------------
  1093.   def create_help_window
  1094.     @help_window = Window_Help.new
  1095.     @help_window.visible = false
  1096.   end
  1097.   #--------------------------------------------------------------------------
  1098.   # * Create Result Window
  1099.   #--------------------------------------------------------------------------
  1100.   def create_result_window
  1101.     @result_window = Window_XRef_Result.new
  1102.     @result_window.visible = false
  1103.     @result_window.active = false
  1104.     @result_window.help_window = @help_window
  1105.   end
  1106.   #--------------------------------------------------------------------------
  1107.   # * Frame Update
  1108.   #--------------------------------------------------------------------------
  1109.   def update
  1110.     # Update windows
  1111.     @command_window.update
  1112.     @selection_window.update
  1113.     @result_window.update
  1114.     @help_window.update
  1115.  
  1116.     if @command_window.active
  1117.       update_command
  1118.       return
  1119.     end
  1120.    
  1121.     if @selection_window.active
  1122.       update_selection
  1123.       return
  1124.     end
  1125.    
  1126.     if @result_window.active
  1127.       update_result
  1128.       return
  1129.     end
  1130.   end
  1131.   #--------------------------------------------------------------------------
  1132.   # * Frame Update (when command window is active)
  1133.   #--------------------------------------------------------------------------
  1134.   def update_command
  1135.     # If B button was pressed
  1136.     if Input.trigger?(Input::B)
  1137.       # Play cancel SE
  1138.       $game_system.se_play($data_system.cancel_se)
  1139.       # Switch to map screen
  1140.       $scene = Scene_Map.new
  1141.       return
  1142.     end
  1143.     # If C button was pressed
  1144.     if Input.trigger?(Input::C)
  1145.         # Play decision SE
  1146.         $game_system.se_play($data_system.decision_se)
  1147.         @selection_window.set_mode(@commands[@command_window.index])
  1148.        
  1149.         @command_window.active = false
  1150.         @selection_window.visible = true
  1151.         @selection_window.active = true
  1152.       return
  1153.     end
  1154.   end
  1155.   #--------------------------------------------------------------------------
  1156.   # * Frame Update (when selection window is active)
  1157.   #--------------------------------------------------------------------------
  1158.   def update_selection
  1159.     # If B button was pressed
  1160.     if Input.trigger?(Input::B)
  1161.       # Play cancel SE
  1162.       $game_system.se_play($data_system.cancel_se)
  1163.       # Make command window active
  1164.       @command_window.active = true
  1165.       @selection_window.active = false
  1166.       @selection_window.visible = false
  1167.       return
  1168.     end
  1169.     # If C button was pressed
  1170.     if Input.trigger?(Input::C)
  1171.       if XRef.refs(@commands[@command_window.index], @selection_window.item).empty?
  1172.         # Play buzzer SE
  1173.         $game_system.se_play($data_system.buzzer_se)
  1174.       else
  1175.         # Play decision SE
  1176.         $game_system.se_play($data_system.decision_se)
  1177.        
  1178.         @result_window.set_ref(@commands[@command_window.index], @selection_window.item)
  1179.         @command_window.visible = false
  1180.         @selection_window.active = false
  1181.         @selection_window.visible = false
  1182.         @result_window.active = true
  1183.         @result_window.visible = true
  1184.         @help_window.visible = true
  1185.       end
  1186.       return
  1187.     end
  1188.   end
  1189.   #--------------------------------------------------------------------------
  1190.   # * Frame Update (when result window is active)
  1191.   #--------------------------------------------------------------------------
  1192.   def update_result
  1193.     # If B button was pressed
  1194.     if Input.trigger?(Input::B)
  1195.       # Play cancel SE
  1196.       $game_system.se_play($data_system.cancel_se)
  1197.       # Make selection window active
  1198.       @help_window.visible = false
  1199.       @result_window.active = false
  1200.       @result_window.visible = false
  1201.       @selection_window.active = true
  1202.       @selection_window.visible = true
  1203.       @command_window.visible = true
  1204.       return
  1205.     end
  1206.   end
  1207. end
  1208.  
  1209.  
  1210. #==============================================================================
  1211. # ** Scene_F9
  1212. #------------------------------------------------------------------------------
  1213. #  This class allows the user to choose between the debug and XRef menu.
  1214. #==============================================================================
  1215.  
  1216. class Scene_F9
  1217.   #--------------------------------------------------------------------------
  1218.   # * Main Processing
  1219.   #--------------------------------------------------------------------------
  1220.   def main
  1221.     # Make command window
  1222.     s1 = "Debug"
  1223.     s2 = "Cross Reference"
  1224.     @command_window = Window_Command.new(250, [s1, s2])
  1225.     @command_window.back_opacity = 160
  1226.     @command_window.x = 320 - @command_window.width / 2
  1227.     @command_window.y = 288
  1228.    
  1229.     # Execute transition
  1230.     Graphics.transition
  1231.    
  1232.     # Main loop
  1233.     loop do
  1234.       # Update game screen
  1235.       Graphics.update
  1236.       # Update input information
  1237.       Input.update
  1238.       # Frame update
  1239.       update
  1240.       # Abort loop if screen is changed
  1241.       if $scene != self
  1242.         break
  1243.       end
  1244.     end
  1245.    
  1246.     # Prepare for transition
  1247.     Graphics.freeze
  1248.    
  1249.     # Dispose of command window
  1250.     @command_window.dispose
  1251.   end
  1252.  
  1253.   #--------------------------------------------------------------------------
  1254.   # * Frame Update
  1255.   #--------------------------------------------------------------------------
  1256.   def update
  1257.     # Update command window
  1258.     @command_window.update
  1259.  
  1260.     # If B button was pressed
  1261.     if Input.trigger?(Input::B)
  1262.       # Play cancel SE
  1263.       $game_system.se_play($data_system.cancel_se)
  1264.       # Switch to map screen
  1265.       $scene = Scene_Map.new
  1266.       return
  1267.     end
  1268.    
  1269.     # If C button was pressed
  1270.     if Input.trigger?(Input::C)
  1271.       # Branch by command window cursor position
  1272.       case @command_window.index
  1273.       when 0  # Debug Menu
  1274.         $game_system.se_play($data_system.decision_se)
  1275.         $scene = Scene_Debug.new
  1276.       when 1  # Cross References
  1277.         $game_system.se_play($data_system.decision_se)
  1278.         XRef.load_xrefs
  1279.         $scene = Scene_XRef.new
  1280.       end
  1281.     end
  1282.   end
  1283.  
  1284. end
  1285.  
  1286.  
  1287. #==============================================================================
  1288. # ** Scene_Map
  1289. #------------------------------------------------------------------------------
  1290. #  This class performs map screen processing.
  1291. #==============================================================================
  1292.  
  1293. class Scene_Map
  1294.   #--------------------------------------------------------------------------
  1295.   # * Debug Call
  1296.   #--------------------------------------------------------------------------
  1297.   def call_debug
  1298.     # Clear debug call flag
  1299.     $game_temp.debug_calling = false
  1300.     # Play decision SE
  1301.     $game_system.se_play($data_system.decision_se)
  1302.     # Straighten player position
  1303.     $game_player.straighten
  1304.     # Switch to debug screen
  1305.     $scene = Scene_F9.new
  1306.   end
  1307. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement