Advertisement
ezmash

Cross Reference Tool (VX Ace)

Nov 19th, 2013 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 44.21 KB | None | 0 0
  1. class XReference
  2.   attr_accessor :source
  3.   attr_accessor :location
  4.   attr_accessor :page
  5.   attr_accessor :line
  6.   attr_accessor :reference
  7.  
  8.   def initialize(source, location, page, line, reference)
  9.     @source = source
  10.     @location = location
  11.     @page = page
  12.     @line = line
  13.     @reference = reference
  14.   end
  15. end
  16.  
  17. module SHAZ
  18.   module XRef
  19.     #========================================================================
  20.     # DO NOT MODIFY BELOW THIS LINE
  21.     #========================================================================
  22.     VAREXP = /\\v\[(\d+)\]/i
  23.    
  24.     FEATURE_STATE_RATE      = 13
  25.     FEATURE_STATE_RESIST    = 14
  26.     FEATURE_ATK_STATE       = 32
  27.     FEATURE_SKILL_ADD       = 43
  28.     FEATURE_SKILL_SEAL      = 44
  29.     FEATURE_LIST = [FEATURE_STATE_RATE, FEATURE_STATE_RESIST, FEATURE_ATK_STATE,
  30.                     FEATURE_SKILL_ADD, FEATURE_SKILL_SEAL]
  31.    
  32.     EFFECT_ADD_STATE        = 21
  33.     EFFECT_REMOVE_STATE     = 22
  34.     EFFECT_LEARN_SKILL      = 43
  35.     EFFECT_COMMON_EVENT     = 44
  36.     EFFECT_LIST = [EFFECT_ADD_STATE, EFFECT_REMOVE_STATE,
  37.                    EFFECT_LEARN_SKILL, EFFECT_COMMON_EVENT]
  38.    
  39.     def self.data_sources(sym)
  40.       src =  {:switches       =>      $data_system.switches,
  41.               :variables      =>      $data_system.variables,
  42.               :common_events  =>      $data_common_events,
  43.               :actors         =>      $data_actors,
  44.               :classes        =>      $data_classes,
  45.               :skills         =>      $data_skills,
  46.               :items          =>      $data_items,
  47.               :weapons        =>      $data_weapons,
  48.               :armors         =>      $data_armors,
  49.               :enemies        =>      $data_enemies,
  50.               :troops         =>      $data_troops,
  51.               :states         =>      $data_states,
  52.               :animations     =>      $data_animations}
  53.       return src[sym]
  54.     end
  55.    
  56.     def self.data_title(sym)
  57.       title = {:switches       =>      'Switch',
  58.                :variables      =>      'Variable',
  59.                :common_events  =>      'Common Event',
  60.                :actors         =>      'Actor',
  61.                :classes        =>      'Class',
  62.                :skills         =>      'Skill',
  63.                :items          =>      'Item',
  64.                :weapons        =>      'Weapon',
  65.                :armors         =>      'Armor',
  66.                :enemies        =>      'Enemy',
  67.                :troops         =>      'Troop',
  68.                :states         =>      'State',
  69.                :animations     =>      'Animation'}
  70.       return title[sym]
  71.     end
  72.  
  73.     def self.command(code)
  74.       codes =  {101 => 'Show Text',
  75.                 401 => 'Show Text', # continuation
  76.                 103 => 'Input Number',
  77.                 104 => 'Select Key Item',
  78.                 105 => 'Show Scrolling Text',
  79.                 405 => 'Show Scrolling Text', # continuation
  80.                 111 => 'Conditional Branch',
  81.                 117 => 'Call Common Event',
  82.                 121 => 'Control Switches',
  83.                 122 => 'Control Variables',
  84.                 125 => 'Change Gold',
  85.                 126 => 'Change Items',
  86.                 127 => 'Change Weapons',
  87.                 128 => 'Change Armor',
  88.                 129 => 'Change Party Member',
  89.                 201 => 'Transfer Player',
  90.                 202 => 'Set Vehicle Location',
  91.                 203 => 'Set Event Location',
  92.                 505 => 'Set Move Route', # continuation
  93.                 212 => 'Show Animation',
  94.                 231 => 'Show Picture',
  95.                 232 => 'Move Picture',
  96.                 285 => 'Get Location Info',
  97.                 301 => 'Battle Processing',
  98.                 302 => 'Shop Processing',
  99.                 605 => 'Shop Processing', # continuation
  100.                 303 => 'Name Input Processing',
  101.                 311 => 'Change HP',
  102.                 312 => 'Change MP',
  103.                 313 => 'Change State',
  104.                 314 => 'Recover All',
  105.                 315 => 'Change EXP',
  106.                 316 => 'Change Level',
  107.                 317 => 'Change Parameters',
  108.                 318 => 'Change Skills',
  109.                 319 => 'Change Equipment',
  110.                 320 => 'Change Name',
  111.                 321 => 'Change Class',
  112.                 324 => 'Change Nickname',
  113.                 322 => 'Change Actor Graphic',
  114.                 331 => 'Change Enemy HP',
  115.                 332 => 'Change Enemy MP',
  116.                 333 => 'Change Enemy State',
  117.                 334 => 'Enemy Recover All',
  118.                 335 => 'Enemy Appear',
  119.                 336 => 'Enemy Transform',
  120.                 337 => 'Show Battle Animation',
  121.                 339 => 'Force Action',
  122.                }
  123.       return codes[code]
  124.     end
  125.  
  126.     def self.load_xrefs
  127.       $data_xrefs = {}
  128.      
  129.       $data_actors.compact.each         {|actor|  build_actor_xrefs(actor)}
  130.       $data_classes.compact.each        {|cls|    build_class_xrefs(cls)}
  131.       $data_skills.compact.each         {|skill|  build_skill_xrefs(skill)}
  132.       $data_items.compact.each          {|item|   build_item_xrefs(item)}
  133.       $data_weapons.compact.each        {|weapon| build_weapon_xrefs(weapon)}
  134.       $data_armors.compact.each         {|armor|  build_armor_xrefs(armor)}
  135.       $data_enemies.compact.each        {|enemy|  build_enemy_xrefs(enemy)}
  136.       $data_troops.compact.each         {|troop|  build_troop_xrefs(troop)}
  137.       $data_states.compact.each         {|state|  build_state_xrefs(state)}
  138.       $data_common_events.compact.each  {|evt|    build_common_event_xrefs(evt)}
  139.      
  140.       Dir.glob('Data/Map???.rvdata2').each {|filename| build_map_xrefs(filename)}
  141.     end
  142.    
  143.     def self.save_xref(type, id, reference = command(@cmd))
  144.       $data_xrefs[type] = [] if $data_xrefs[type].nil?
  145.       $data_xrefs[type][id] = [] if $data_xrefs[type][id].nil?
  146.       $data_xrefs[type][id].push(XReference.new(@source, sprintf('%d: %s', @refid, @ref), @page, @line, reference))
  147.     end
  148.    
  149.     def self.scan_db_text(text, reference)
  150.       text.scan(SHAZ::XRef::VAREXP).flatten.map {|val| val.to_i}.each { |var|
  151.         save_xref(:variables, var, reference)
  152.       }
  153.     end
  154.    
  155.     def self.scan_features(features)
  156.       features.select{ |ft| FEATURE_LIST.include?(ft.code) }.each { |feature|
  157.         case feature.code
  158.         when FEATURE_STATE_RATE, FEATURE_STATE_RESIST, FEATURE_ATK_STATE
  159.           save_xref(:states, feature.data_id, 'Features')
  160.         when FEATURE_SKILL_ADD, FEATURE_SKILL_SEAL
  161.           save_xref(:skills, feature.data_id, 'Features')
  162.         end
  163.       }
  164.     end
  165.    
  166.     def self.scan_effects(effects)
  167.       effects.select{ |eft| EFFECT_LIST.include?(eft.code) }.each { |effect|
  168.         case effect.code
  169.         when EFFECT_ADD_STATE, EFFECT_REMOVE_STATE
  170.           save_xref(:states, effect.data_id, 'Effects')
  171.         when EFFECT_LEARN_SKILL
  172.           save_xref(:skills, effect.data_id, 'Effects')
  173.         when EFFECT_COMMON_EVENT
  174.           save_xref(:common_events, effect.value1, 'Effects')
  175.         end
  176.       }
  177.     end
  178.    
  179.     def self.build_actor_xrefs(a)
  180.       @source = 'Actor'
  181.       @refid = a.id
  182.       @ref = a.name
  183.      
  184.       # Text Fields
  185.       scan_db_text(a.name, 'Name')
  186.       scan_db_text(a.nickname, 'Nickname')
  187.       scan_db_text(a.description, 'Description')
  188.      
  189.       # Class
  190.       save_xref(:classes, a.class_id, 'Class')
  191.      
  192.       # Starting Equipment
  193.       5.times { |i|
  194.         e = a.equips[i]
  195.         next if e.nil? || e == 0
  196.         if i == 0 || (i == 1 &&
  197.           (a.features + $data_classes[a.class_id].features).select{|ft| ft.code == 55}.size > 0)
  198.           save_xref(:weapons, e, sprintf('Equip Slot %d', i))
  199.         else
  200.           save_xref(:armors, e, sprintf('Equip Slot %d', i))
  201.         end
  202.       }
  203.      
  204.       # features
  205.       scan_features(a.features)
  206.     end
  207.    
  208.     def self.build_class_xrefs(cls)
  209.       @source = 'Class'
  210.       @refid = cls.id
  211.       @ref = cls.name
  212.      
  213.       # Text Fields
  214.       scan_db_text(cls.name, 'Name')
  215.      
  216.       # Learnings
  217.       cls.learnings.compact.each {|skill|
  218.         save_xref(:skills, skill.skill_id, sprintf('Learnings (Level %d)', skill.level))
  219.       }
  220.      
  221.       # features
  222.       scan_features(cls.features)
  223.     end
  224.    
  225.     def self.build_skill_xrefs(skill)
  226.       @source = 'Skill'
  227.       @refid = skill.id
  228.       @ref = skill.name
  229.      
  230.       # Text Fields
  231.       scan_db_text(skill.name, 'Name')
  232.       scan_db_text(skill.description, 'Description')
  233.       scan_db_text(skill.message1, 'Message 1')
  234.       scan_db_text(skill.message2, 'Message 2')
  235.      
  236.       # Animation
  237.       save_xref(:animations, [skill.animation_id, 1].max, 'Animation') if skill.animation_id != 0
  238.      
  239.       # effects
  240.       scan_effects(skill.effects)
  241.     end
  242.    
  243.     def self.build_item_xrefs(item)
  244.       @source = 'Item'
  245.       @refid = item.id
  246.       @ref = item.name
  247.      
  248.       # Text Fields
  249.       scan_db_text(item.name, 'Name')
  250.       scan_db_text(item.description, 'Description')
  251.      
  252.       # Animation
  253.       save_xref(:animations, [item.animation_id, 1].max, 'Animation') if item.animation_id != 0
  254.      
  255.       # effects
  256.       scan_effects(item.effects)
  257.     end
  258.    
  259.     def self.build_weapon_xrefs(weapon)
  260.       @source = 'Weapon'
  261.       @refid = weapon.id
  262.       @ref = weapon.name
  263.      
  264.       # Text Fields
  265.       scan_db_text(weapon.name, 'Name')
  266.       scan_db_text(weapon.description, 'Description')
  267.      
  268.       # Animation
  269.       save_xref(:animations, [weapon.animation_id, 1].max, 'Animation') if weapon.animation_id != 0
  270.      
  271.       # features
  272.       scan_features(weapon.features)
  273.     end
  274.    
  275.     def self.build_armor_xrefs(armor)
  276.       @source = 'Armor'
  277.       @refid = armor.id
  278.       @ref = armor.name
  279.      
  280.       # Text Fields
  281.       scan_db_text(armor.name, 'Name')
  282.       scan_db_text(armor.description, 'Description')
  283.      
  284.       # features
  285.       scan_features(armor.features)
  286.     end
  287.    
  288.     def self.build_enemy_xrefs(enemy)
  289.       @source = 'Enemy'
  290.       @refid = enemy.id
  291.       @ref = enemy.name
  292.      
  293.       # Text Fields
  294.       scan_db_text(enemy.name, 'Name')
  295.      
  296.       # Drop Items
  297.       enemy.drop_items.each { |dropitem|
  298.         case dropitem.kind
  299.         when 1
  300.           save_xref(:items, dropitem.data_id, 'Drop Items')
  301.         when 2
  302.           save_xref(:weapons, dropitem.data_id, 'Drop Items')
  303.         when 3
  304.           save_xref(:armors, dropitem.data_id, 'Drop Items')
  305.         end
  306.       }
  307.      
  308.       # Action Patterns
  309.       enemy.actions.each { |action|
  310.         save_xref(:skills, action.skill_id, 'Action Patterns')
  311.         case action.condition_type
  312.         when 4
  313.           save_xref(:states, action.condition_param1, sprintf('Action Pattern %s',
  314.             $data_skills[action.skill_id].name))
  315.         when 6
  316.           save_xref(:switches, action.condition_param1, sprintf('Action Pattern %s',
  317.             $data_skills[action.skill_id].name))
  318.         end
  319.       }
  320.      
  321.       # features
  322.       scan_features(enemy.features)
  323.     end
  324.    
  325.     def self.build_troop_xrefs(troop)
  326.       @source = 'Troop'
  327.       @refid = troop.id
  328.       @ref = troop.name
  329.      
  330.       # Text Fields
  331.       scan_db_text(troop.name, 'Name')
  332.      
  333.       # Members
  334.       troop.members.collect{|member| member.enemy_id}.uniq.each { |enemy|
  335.         save_xref(:enemies, enemy, 'Members')
  336.       }
  337.      
  338.       # Pages
  339.       troop.pages.size.times { |page|
  340.         @page = page + 1
  341.         @line = nil
  342.         cond = troop.pages[page].condition
  343.        
  344.         # Conditions
  345.         save_xref(:actors, cond.actor_id, 'Page Conditions') if cond.actor_valid
  346.         save_xref(:switches, cond.switch_id, 'Page Conditions') if cond.switch_valid
  347.        
  348.         # Event Commands
  349.         @list = troop.pages[page].list
  350.         build_event_xrefs
  351.       }
  352.      
  353.       @page = nil
  354.       @line = nil
  355.     end
  356.    
  357.     def self.build_state_xrefs(state)
  358.       @source = 'State'
  359.       @refid = state.id
  360.       @ref = state.name
  361.      
  362.       # Text Fields
  363.       scan_db_text(state.name, 'Name')
  364.       scan_db_text(state.message1, 'Message 1')
  365.       scan_db_text(state.message2, 'Message 2')
  366.       scan_db_text(state.message3, 'Message 3')
  367.       scan_db_text(state.message4, 'Message 4')
  368.  
  369.       # features
  370.       scan_features(state.features)
  371.     end
  372.    
  373.     def self.build_common_event_xrefs(evt)
  374.       @source = 'Common Event'
  375.       @refid = evt.id
  376.       @ref = evt.name
  377.      
  378.       # Conditions
  379.       save_xref(:switches, evt.switch_id, 'Event Conditions') if evt.trigger != 0
  380.      
  381.       # Events
  382.       @list = evt.list
  383.       build_event_xrefs
  384.      
  385.       @line = nil
  386.     end
  387.    
  388.     def self.build_map_xrefs(filename)
  389.       map_id = /Data\/Map(\d+)\.rvdata2/.match(filename)[1].to_i
  390.       map_name = $data_mapinfos[map_id].name
  391.       @source = sprintf('Map %d (%s)', map_id, map_name)
  392.       map = load_data(filename)
  393.      
  394.       # Encounters
  395.       @refid = nil
  396.       @ref = nil
  397.       map.encounter_list.each { |encounter|
  398.         save_xref(:troops, encounter.troop_id, 'Encounter List')
  399.       }
  400.      
  401.       # Events (pages of conditions/event commands)
  402.       map.events.each { |evt_id, evt|
  403.         next if evt.nil? || evt.pages.nil?
  404.         @refid = evt_id
  405.         @ref = evt.name
  406.        
  407.         evt.pages.size.times { |page|
  408.           @page = page + 1
  409.           @line = nil
  410.          
  411.           # Conditions
  412.           cond = evt.pages[page].condition
  413.           save_xref(:switches, cond.switch1_id, 'Page Conditions') if cond.switch1_valid
  414.           save_xref(:switches, cond.switch2_id, 'Page Conditions') if cond.switch2_valid
  415.           save_xref(:variables, cond.variable_id, 'Page Conditions') if cond.variable_valid
  416.           save_xref(:items, cond.item_id, 'Page Conditions') if cond.item_valid
  417.           save_xref(:actors, cond.actor_id, 'Page Conditions') if cond.actor_valid
  418.          
  419.           # Event Commands
  420.           @list = evt.pages[page].list
  421.           build_event_xrefs
  422.         }
  423.       }
  424.      
  425.       @page = nil
  426.       @line = nil
  427.     end
  428.    
  429.     def self.build_event_xrefs
  430.       return if @list.nil?
  431.      
  432.       @list.size.times { |line|
  433.         @line = line + 1
  434.         @cmd = @list[line].code
  435.         @params = @list[line].parameters.clone
  436.         method_name = "build_xrefs_command_#{@cmd}"
  437.         send(method_name) if respond_to?(method_name)
  438.       }
  439.     end
  440.    
  441.     #--------------------------------------------------------------------------
  442.     # * Show Text
  443.     #--------------------------------------------------------------------------
  444.     def self.build_xrefs_command_101
  445.       # no actual text in the 101 line - it's just setup stuff
  446.     end
  447.     def self.build_xrefs_command_401
  448.       scan_db_text(@params[0], 'Show Text')
  449.     end
  450.     #--------------------------------------------------------------------------
  451.     # * Show Choices
  452.     #--------------------------------------------------------------------------
  453.     def self.build_xrefs_command_102
  454.       @params[0].each {|choice| scan_db_text(choice, 'Show Choices')}
  455.     end
  456.     #--------------------------------------------------------------------------
  457.     # * Input Number
  458.     #--------------------------------------------------------------------------
  459.     def self.build_xrefs_command_103
  460.       save_xref(:variables, @params[0])
  461.     end
  462.     #--------------------------------------------------------------------------
  463.     # * Select Item
  464.     #--------------------------------------------------------------------------
  465.     def self.build_xrefs_command_104
  466.       save_xref(:variables, @params[0])
  467.     end
  468.     #--------------------------------------------------------------------------
  469.     # * Show Scrolling Text
  470.     #--------------------------------------------------------------------------
  471.     def self.build_xrefs_command_105
  472.       # no actual text in the 105 line - it's just setup stuff
  473.     end
  474.     def self.build_xrefs_command_405
  475.       scan_db_text(@params[0], 'Show Scrolling Text')
  476.     end
  477.     #--------------------------------------------------------------------------
  478.     # * Conditional Branch
  479.     #--------------------------------------------------------------------------
  480.     def self.build_xrefs_command_111
  481.       result = false
  482.       case @params[0]
  483.       when 0  # Switch
  484.         save_xref(:switches, @params[1])
  485.       when 1  # Variable
  486.         save_xref(:variables, @params[1])
  487.         save_xref(:variables, @params[3]) if @params[2] != 0
  488.       when 4  # Actor
  489.         save_xref(:actors, @params[1])
  490.         save_xref([:classes, :skills, :weapons, :armors, :states][@params[2] - 2],
  491.           @params[3]) if @params[2].between?(2, 6)
  492.       when 5  # Enemy
  493.         save_xref(:states, @params[3]) if @params[2] == 1
  494.       when 8  # Item
  495.         save_xref(:items, @params[1])
  496.       when 9  # Weapon
  497.         save_xref(:weapons, @params[1])
  498.       when 10  # Armor
  499.         save_xref(:armors, @params[1])
  500.       end
  501.     end
  502.     #--------------------------------------------------------------------------
  503.     # * Common Event
  504.     #--------------------------------------------------------------------------
  505.     def self.build_xrefs_command_117
  506.       save_xref(:common_events, @params[0])
  507.     end
  508.     #--------------------------------------------------------------------------
  509.     # * Control Switches
  510.     #--------------------------------------------------------------------------
  511.     def self.build_xrefs_command_121
  512.       (@params[0]..@params[1]).each do |i|
  513.         save_xref(:switches, i)
  514.       end
  515.     end
  516.     #--------------------------------------------------------------------------
  517.     # * Control Variables
  518.     #--------------------------------------------------------------------------
  519.     def self.build_xrefs_command_122
  520.       value = 0
  521.       case @params[3]  # Operand
  522.       when 1  # Variable
  523.         save_xref(:variables, @params[4])
  524.       when 3  # Game Data
  525.         save_xref([:items, :weapons, :armors, :actors][@params[4]], @params[5]) if @params[4] <= 3
  526.       end
  527.       (@params[0]..@params[1]).each do |i|
  528.         save_xref(:variables, i)
  529.       end
  530.     end
  531.     #--------------------------------------------------------------------------
  532.     # * Change Gold
  533.     #--------------------------------------------------------------------------
  534.     def self.build_xrefs_command_125
  535.       save_xref(:variables, @params[2]) if @params[1] != 0
  536.     end
  537.     #--------------------------------------------------------------------------
  538.     # * Change Items
  539.     #--------------------------------------------------------------------------
  540.     def self.build_xrefs_command_126
  541.       save_xref(:items, @params[0])
  542.       save_xref(:variables, @params[3]) if @params[2] != 0
  543.     end
  544.     #--------------------------------------------------------------------------
  545.     # * Change Weapons
  546.     #--------------------------------------------------------------------------
  547.     def self.build_xrefs_command_127
  548.       save_xref(:weapons, @params[0])
  549.       save_xref(:variables, @params[3]) if @params[2] != 0
  550.     end
  551.     #--------------------------------------------------------------------------
  552.     # * Change Armor
  553.     #--------------------------------------------------------------------------
  554.     def self.build_xrefs_command_128
  555.       save_xref(:armors, @params[0])
  556.       save_xref(:variables, @params[3]) if @params[2] != 0
  557.     end
  558.     #--------------------------------------------------------------------------
  559.     # * Change Party Member
  560.     #--------------------------------------------------------------------------
  561.     def self.build_xrefs_command_129
  562.       save_xref(:actors, @params[0])
  563.     end
  564.     #--------------------------------------------------------------------------
  565.     # * Transfer Player
  566.     #--------------------------------------------------------------------------
  567.     def self.build_xrefs_command_201
  568.       if @params[0] != 0
  569.         save_xref(:variables, @params[1])
  570.         save_xref(:variables, @params[2])
  571.         save_xref(:variables, @params[3])
  572.       end
  573.     end
  574.     #--------------------------------------------------------------------------
  575.     # * Set Vehicle Location
  576.     #--------------------------------------------------------------------------
  577.     def self.build_xrefs_command_202
  578.       if @params[1] != 0
  579.         save_xref(:variables, @params[2])
  580.         save_xref(:variables, @params[3])
  581.         save_xref(:variables, @params[4])
  582.       end
  583.     end
  584.     #--------------------------------------------------------------------------
  585.     # * Set Event Location
  586.     #--------------------------------------------------------------------------
  587.     def self.build_xrefs_command_203
  588.       if @params[1] != 0
  589.         save_xref(:variables, @params[2])
  590.         save_xref(:variables, @params[3])
  591.       end
  592.     end
  593.     #--------------------------------------------------------------------------
  594.     # * Set Move Route
  595.     #--------------------------------------------------------------------------
  596.     def self.build_xrefs_command_205
  597.       # nothing in the first line of the command - just setup stuff
  598.     end
  599.     def self.build_xrefs_command_505
  600.       save_xref(:switches, @params[0].parameters[0]) if [27, 28].include?(@params[0].code)
  601.     end
  602.     #--------------------------------------------------------------------------
  603.     # * Show Animation
  604.     #--------------------------------------------------------------------------
  605.     def self.build_xrefs_command_212
  606.       save_xref(:animations, @params[1])
  607.     end
  608.     #--------------------------------------------------------------------------
  609.     # * Show Picture
  610.     #--------------------------------------------------------------------------
  611.     def self.build_xrefs_command_231
  612.       if @params[3] != 0
  613.         save_xref(:variables, @params[4])
  614.         save_xref(:variables, @params[5])
  615.       end
  616.     end
  617.     #--------------------------------------------------------------------------
  618.     # * Move Picture
  619.     #--------------------------------------------------------------------------
  620.     def self.build_xrefs_command_232
  621.       if @params[3] != 0
  622.         save_xref(:variables, @params[4])
  623.         save_xref(:variables, @params[5])
  624.       end
  625.     end
  626.     #--------------------------------------------------------------------------
  627.     # * Get Location Info
  628.     #--------------------------------------------------------------------------
  629.     def command_285
  630.       save_xref(:variables, @params[0])
  631.       if @params[2] != 0
  632.         save_xref(:variables, @params[3])
  633.         save_xref(:variables, @params[4])
  634.       end
  635.     end
  636.     #--------------------------------------------------------------------------
  637.     # * Battle Processing
  638.     #--------------------------------------------------------------------------
  639.     def self.build_xrefs_command_301
  640.       save_xref([:troops, :variables][@params[0]], @params[1]) if @params[0] <= 1
  641.     end
  642.     #--------------------------------------------------------------------------
  643.     # * Shop Processing
  644.     #--------------------------------------------------------------------------
  645.     def self.build_xrefs_command_302
  646.       save_xref([:items, :weapons, :armors][@params[0]], @params[1])
  647.     end
  648.     def self.build_xrefs_command_605
  649.       save_xref([:items, :weapons, :armors][@params[0]], @params[1])
  650.     end
  651.     #--------------------------------------------------------------------------
  652.     # * Name Input Processing
  653.     #--------------------------------------------------------------------------
  654.     def self.build_xrefs_command_303
  655.       save_xref(:actors, @params[0])
  656.     end
  657.     #--------------------------------------------------------------------------
  658.     # * Change HP
  659.     #--------------------------------------------------------------------------
  660.     def self.build_xrefs_command_311
  661.       save_xref(:variables, @params[4]) if @params[3] != 0
  662.       save_xref([:actors, :variables][@params[0]], @params[1])
  663.     end
  664.     #--------------------------------------------------------------------------
  665.     # * Change MP
  666.     #--------------------------------------------------------------------------
  667.     def self.build_xrefs_command_312
  668.       save_xref(:variables, @params[4]) if @params[3] != 0
  669.       save_xref([:actors, :variables][@params[0]], @params[1])
  670.     end
  671.     #--------------------------------------------------------------------------
  672.     # * Change State
  673.     #--------------------------------------------------------------------------
  674.     def self.build_xrefs_command_313
  675.       save_xref([:actors, :variables][@params[0]], @params[1])
  676.       save_xref(:states, @params[3])
  677.     end
  678.     #--------------------------------------------------------------------------
  679.     # * Recover All
  680.     #--------------------------------------------------------------------------
  681.     def self.build_xrefs_command_314
  682.       save_xref([:actors, :variables][@params[0]], @params[1])
  683.     end
  684.     #--------------------------------------------------------------------------
  685.     # * Change EXP
  686.     #--------------------------------------------------------------------------
  687.     def self.build_xrefs_command_315
  688.       save_xref(:variables, @params[4]) if @params[3] != 0
  689.       save_xref([:actors, :variables][@params[0]], @params[1])
  690.     end
  691.     #--------------------------------------------------------------------------
  692.     # * Change Level
  693.     #--------------------------------------------------------------------------
  694.     def self.build_xrefs_command_316
  695.       save_xref(:variables, @params[4]) if @params[3] != 0
  696.       save_xref([:actors, :variables][@params[0]], @params[1])
  697.     end
  698.     #--------------------------------------------------------------------------
  699.     # * Change Parameters
  700.     #--------------------------------------------------------------------------
  701.     def self.build_xrefs_command_317
  702.       save_xref(:variables, @params[5]) if @params[4] != 0
  703.       save_xref([:actors, :variables][@params[0]], @params[1])
  704.     end
  705.     #--------------------------------------------------------------------------
  706.     # * Change Skills
  707.     #--------------------------------------------------------------------------
  708.     def self.build_xrefs_command_318
  709.       save_xref(:skills, @params[3])
  710.       save_xref([:actors, :variables][@params[0]], @params[1])
  711.     end
  712.     #--------------------------------------------------------------------------
  713.     # * Change Equipment
  714.     #--------------------------------------------------------------------------
  715.     def self.build_xrefs_command_319
  716.       save_xref(:actors, @params[0])
  717.       return if @params[2] == 0
  718.       case @params[1]
  719.       when 0 # Weapon
  720.         save_xref(:weapons, @params[2])
  721.       when 1 # Weapon or Armor
  722.         if $data_weapons[@params[2]] && $data_armors[@params[2]]
  723.           save_xref(:weapons, @params[2], 'Change Equipment (*)')
  724.           save_xref(:armors, @params[2], 'Change Equipment (*)')
  725.         elsif $data_weapons[@params[2]]
  726.           save_xref(:weapons, @params[2])
  727.         else
  728.           save_xref(:armors, @params[2])
  729.         end
  730.       else
  731.         save_xref(:armors, @params[2])
  732.       end
  733.     end
  734.     #--------------------------------------------------------------------------
  735.     # * Change Name
  736.     #--------------------------------------------------------------------------
  737.     def self.build_xrefs_command_320
  738.       save_xref(:actors, @params[0])
  739.     end
  740.     #--------------------------------------------------------------------------
  741.     # * Change Class
  742.     #--------------------------------------------------------------------------
  743.     def self.build_xrefs_command_321
  744.       save_xref(:actors, @params[0])
  745.       save_xref(:classes, @params[1])
  746.     end
  747.     #--------------------------------------------------------------------------
  748.     # * Change Actor Graphic
  749.     #--------------------------------------------------------------------------
  750.     def self.build_xrefs_command_322
  751.       save_xref(:actors, @params[0])
  752.     end
  753.     #--------------------------------------------------------------------------
  754.     # * Change Nickname
  755.     #--------------------------------------------------------------------------
  756.     def self.build_xrefs_command_324
  757.       save_xref(:actors, @params[0])
  758.     end
  759.     #--------------------------------------------------------------------------
  760.     # * Change Enemy HP
  761.     #--------------------------------------------------------------------------
  762.     def self.build_xrefs_command_331
  763.       save_xref(:variables, @params[3]) if @params[2] != 0
  764.     end
  765.     #--------------------------------------------------------------------------
  766.     # * Change Enemy MP
  767.     #--------------------------------------------------------------------------
  768.     def self.build_xrefs_command_332
  769.       save_xref(:variables, @params[3]) if @params[2] != 0
  770.     end
  771.     #--------------------------------------------------------------------------
  772.     # * Change Enemy State
  773.     #--------------------------------------------------------------------------
  774.     def self.build_xrefs_command_333
  775.       save_xref(:states, @params[2])
  776.     end
  777.     #--------------------------------------------------------------------------
  778.     # * Enemy Transform
  779.     #--------------------------------------------------------------------------
  780.     def self.build_xrefs_command_336
  781.       save_xref(:enemies, @params[1])
  782.     end
  783.     #--------------------------------------------------------------------------
  784.     # * Show Battle Animation
  785.     #--------------------------------------------------------------------------
  786.     def self.build_xrefs_command_337
  787.       save_xref(:animations, @params[1])
  788.     end
  789.     #--------------------------------------------------------------------------
  790.     # * Force Action
  791.     #--------------------------------------------------------------------------
  792.     def self.build_xrefs_command_339
  793.       save_xref(:actors, @params[1]) if @params[0] != 0
  794.       save_xref(:skills, @params[2])
  795.     end
  796.   end
  797. end
  798.  
  799. module DataManager
  800.   class << self
  801.     alias shaz_xref_load_normal_database load_normal_database
  802.   end
  803.  
  804.   def self.load_normal_database
  805.     shaz_xref_load_normal_database
  806.     $data_xrefs = {}
  807.     SHAZ::XRef::load_xrefs
  808.   end
  809. end
  810.  
  811. class Window_MenuCommand < Window_Command
  812.   alias shaz_xref_window_menucommand_add_original_commands add_original_commands
  813.   def add_original_commands
  814.     add_command('XRef Tool', :xref) if $TEST
  815.   end
  816. end
  817.  
  818. class Scene_Menu < Scene_MenuBase
  819.   alias shaz_xref_scene_menu_create_command_window create_command_window
  820.   def create_command_window
  821.     shaz_xref_scene_menu_create_command_window
  822.     @command_window.set_handler(:xref, method(:command_xref)) if $TEST
  823.   end
  824.  
  825.   def command_xref
  826.     SceneManager.call(Scene_XRef)
  827.   end
  828. end
  829.  
  830. class Window_XRefCommand < Window_Command
  831.   #--------------------------------------------------------------------------
  832.   # * Public Instance Variables
  833.   #--------------------------------------------------------------------------
  834.   attr_reader   :selection_window
  835.   #--------------------------------------------------------------------------
  836.   # * Object Initialization
  837.   #--------------------------------------------------------------------------
  838.   def initialize
  839.     super(0, 0)
  840.     @@last_command_symbol = nil
  841.     select_last
  842.   end
  843.   #--------------------------------------------------------------------------
  844.   # * Get Window Width
  845.   #--------------------------------------------------------------------------
  846.   def window_width
  847.     return 160
  848.   end
  849.   #--------------------------------------------------------------------------
  850.   # * Get Number of Lines to Show
  851.   #--------------------------------------------------------------------------
  852.   def visible_line_number
  853.     item_max
  854.   end
  855.   #--------------------------------------------------------------------------
  856.   # * Frame Update
  857.   #--------------------------------------------------------------------------
  858.   def update
  859.     super
  860.     @selection_window.mode = current_symbol if @selection_window
  861.   end
  862.   #--------------------------------------------------------------------------
  863.   # * Create Command List
  864.   #--------------------------------------------------------------------------
  865.   def make_command_list
  866.     add_command('Switches',      :switches, $data_xrefs[:switches])
  867.     add_command('Variables',     :variables, $data_xrefs[:variables])
  868.     add_command('Common Events', :common_events, $data_xrefs[:common_events])
  869.     add_command('Actors',        :actors, $data_xrefs[:actors])
  870.     add_command('Classes',       :classes, $data_xrefs[:classes])
  871.     add_command('Skills',        :skills, $data_xrefs[:skills])
  872.     add_command('Items',         :items, $data_xrefs[:items])
  873.     add_command('Weapons',       :weapons, $data_xrefs[:weapons])
  874.     add_command('Armors',        :armors, $data_xrefs[:armors])
  875.     add_command('Enemies',       :enemies, $data_xrefs[:enemies])
  876.     add_command('Troops',        :troops, $data_xrefs[:troops])
  877.     add_command('States',        :states, $data_xrefs[:states])
  878.     add_command('Animations',    :animations, $data_xrefs[:animations])
  879.   end
  880.   #--------------------------------------------------------------------------
  881.   # * Set Item Window
  882.   #--------------------------------------------------------------------------
  883.   def selection_window=(selection_window)
  884.     @selection_window = selection_window
  885.     update
  886.   end
  887.   #--------------------------------------------------------------------------
  888.   # * Processing When OK Button Is Pressed
  889.   #--------------------------------------------------------------------------
  890.   def process_ok
  891.     @@last_command_symbol = current_symbol
  892.     super
  893.   end
  894.   #--------------------------------------------------------------------------
  895.   # * Restore Previous Selection Position
  896.   #--------------------------------------------------------------------------
  897.   def select_last
  898.     select_symbol(@@last_command_symbol)
  899.   end
  900. end
  901.  
  902. class Window_XRefSelection < Window_Selectable
  903.   #--------------------------------------------------------------------------
  904.   # * Object Initialization
  905.   #--------------------------------------------------------------------------
  906.   def initialize(x, y, width, height)
  907.     super
  908.     @mode = :none
  909.     @data = []
  910.     self.contents.font.size = 20
  911.   end
  912.   #--------------------------------------------------------------------------
  913.   # * Set Mode
  914.   #--------------------------------------------------------------------------
  915.   def mode=(mode)
  916.     return if @mode == mode
  917.     @mode = mode
  918.   end
  919.   #--------------------------------------------------------------------------
  920.   # * Get Digit Count
  921.   #--------------------------------------------------------------------------
  922.   def col_max
  923.     return 2
  924.   end
  925.   #--------------------------------------------------------------------------
  926.   # * Get Number of Items
  927.   #--------------------------------------------------------------------------
  928.   def item_max
  929.     @data ? @data.size : 0
  930.   end
  931.   #--------------------------------------------------------------------------
  932.   # * Get Item
  933.   #--------------------------------------------------------------------------
  934.   def item
  935.     @data && index >= 0 ? @data[index] : nil
  936.   end
  937.   #--------------------------------------------------------------------------
  938.   # * Create Item List
  939.   #--------------------------------------------------------------------------
  940.   def make_item_list
  941.     @data = Array.new(SHAZ::XRef::data_sources(@mode).size - 1) {|id| id + 1}
  942.   end
  943.   #--------------------------------------------------------------------------
  944.   # * Draw Item
  945.   #--------------------------------------------------------------------------
  946.   def draw_item(index)
  947.     item = @data[index]
  948.     return if item.nil?
  949.     rect = item_rect(index)
  950.     rect.width -= 4
  951.    
  952.     id_text = sprintf('%04d: ', item)
  953.     id_width = text_size(id_text).width
  954.    
  955.     src = SHAZ::XRef::data_sources(@mode)
  956.     case @mode
  957.     when :switches, :variables
  958.       name = src[item]
  959.     else
  960.       name = src[item] ? src[item].name : ''
  961.     end
  962.    
  963.     change_color(normal_color)
  964.     rect.x += 4
  965.     draw_text(rect, id_text)
  966.     rect.x += id_width
  967.     rect.width -= id_width + 20
  968.     draw_text(rect, name)
  969.   end
  970.   #--------------------------------------------------------------------------
  971.   # * Help Text
  972.   #--------------------------------------------------------------------------
  973.   def help_text
  974.     src = SHAZ::XRef::data_sources(@mode)
  975.     case @mode
  976.     when :switches, :variables
  977.       name = src[item]
  978.     else
  979.       name = src[item] ? src[item].name : ''
  980.     end
  981.    
  982.     txt = sprintf('%s %4d: %s', SHAZ::XRef::data_title(@mode), item, name)
  983.     return txt
  984.   end
  985.   #--------------------------------------------------------------------------
  986.   # * Set Command Window
  987.   #--------------------------------------------------------------------------
  988.   def command_window=(command_window)
  989.     @command_window = command_window
  990.     update
  991.   end
  992.   #--------------------------------------------------------------------------
  993.   # * Refresh
  994.   #--------------------------------------------------------------------------
  995.   def refresh
  996.     make_item_list
  997.     create_contents
  998.     self.contents.font.size = 20
  999.     draw_all_items
  1000.   end
  1001. end
  1002.  
  1003. class Window_XRefResults < Window_Selectable
  1004.   #--------------------------------------------------------------------------
  1005.   # * Object Initialization
  1006.   #--------------------------------------------------------------------------
  1007.   def initialize(x, y, width, height)
  1008.     super(x, y, width, height)
  1009.     @mode = :none
  1010.     @selection = nil
  1011.     @data = []
  1012.     self.contents.font.size = 20
  1013.   end
  1014.   #--------------------------------------------------------------------------
  1015.   # * Set Mode
  1016.   #--------------------------------------------------------------------------
  1017.   def mode=(mode)
  1018.     @mode = mode
  1019.   end
  1020.   #--------------------------------------------------------------------------
  1021.   # * Set Selection
  1022.   #--------------------------------------------------------------------------
  1023.   def selection=(selection)
  1024.     @selection = selection if !selection.nil?
  1025.   end
  1026.   #--------------------------------------------------------------------------
  1027.   # * Get Number of Items
  1028.   #--------------------------------------------------------------------------
  1029.   def item_max
  1030.     @data ? @data.size : 0
  1031.   end
  1032.   #--------------------------------------------------------------------------
  1033.   # * Create Item List
  1034.   #--------------------------------------------------------------------------
  1035.   def make_item_list
  1036.     if $data_xrefs.nil? || $data_xrefs[@mode].nil? || $data_xrefs[@mode][@selection].nil?
  1037.       @data = [nil]
  1038.     else
  1039.       @data = $data_xrefs[@mode][@selection]
  1040.     end
  1041.   end
  1042.   #--------------------------------------------------------------------------
  1043.   # * Draw Item
  1044.   #--------------------------------------------------------------------------
  1045.   def draw_item(index)
  1046.     item = @data[index]
  1047.     rect = item_rect_for_text(index)
  1048.     if item.nil?
  1049.       draw_text(rect, 'No References Found', 1)
  1050.     else
  1051.       y = rect.y
  1052.       draw_text(4, y, 190, line_height, item.source)
  1053.       draw_text(198, y, 160, line_height, item.location) if !item.location.nil?
  1054.       if item.page && item.line
  1055.         draw_text(362, y, 70, line_height, sprintf('%3d:%d', item.page, item.line))
  1056.       elsif item.page
  1057.         draw_text(362, y, 70, line_height, sprintf('%3d:', item.page))
  1058.       elsif item.line
  1059.         draw_text(362, y, 70, line_height, sprintf('   :%d', item.line))
  1060.       end
  1061.       draw_text(436, y, 200, line_height, item.reference)
  1062.     end
  1063.   end
  1064.   #--------------------------------------------------------------------------
  1065.   # * Refresh
  1066.   #--------------------------------------------------------------------------
  1067.   def refresh
  1068.     make_item_list
  1069.     create_contents
  1070.     self.contents.font.size = 20
  1071.     draw_all_items
  1072.   end
  1073. end
  1074.  
  1075. class Scene_XRef < Scene_Base
  1076.   #--------------------------------------------------------------------------
  1077.   # * Start Processing
  1078.   #--------------------------------------------------------------------------
  1079.   def start
  1080.     super
  1081.     create_command_window
  1082.     create_selection_window
  1083.     create_help_window
  1084.     create_result_window
  1085.   end
  1086.   #--------------------------------------------------------------------------
  1087.   # * Create Command Window
  1088.   #--------------------------------------------------------------------------
  1089.   def create_command_window
  1090.     @command_window = Window_XRefCommand.new
  1091.     @command_window.set_handler(:switches,      method(:command_choice))
  1092.     @command_window.set_handler(:variables,     method(:command_choice))
  1093.     @command_window.set_handler(:common_events, method(:command_choice))
  1094.     @command_window.set_handler(:actors,        method(:command_choice))
  1095.     @command_window.set_handler(:classes,       method(:command_choice))
  1096.     @command_window.set_handler(:skills,        method(:command_choice))
  1097.     @command_window.set_handler(:items,         method(:command_choice))
  1098.     @command_window.set_handler(:weapons,       method(:command_choice))
  1099.     @command_window.set_handler(:armors,        method(:command_choice))
  1100.     @command_window.set_handler(:enemies,       method(:command_choice))
  1101.     @command_window.set_handler(:troops,        method(:command_choice))
  1102.     @command_window.set_handler(:states,        method(:command_choice))
  1103.     @command_window.set_handler(:animations,    method(:command_choice))
  1104.     @command_window.set_handler(:cancel,        method(:return_scene))
  1105.   end
  1106.   #--------------------------------------------------------------------------
  1107.   # * Create Selection Window
  1108.   #--------------------------------------------------------------------------
  1109.   def create_selection_window
  1110.     wx = @command_window.x + @command_window.width
  1111.     ww = Graphics.width - wx
  1112.     @selection_window = Window_XRefSelection.new(wx, 0, ww, Graphics.height)
  1113.     @selection_window.set_handler(:ok,     method(:on_selection_ok))
  1114.     @selection_window.set_handler(:cancel, method(:on_selection_cancel))
  1115.     @command_window.selection_window = @selection_window
  1116.     @selection_window.command_window = @command_window
  1117.   end
  1118.   #--------------------------------------------------------------------------
  1119.   # * Create Help Window
  1120.   #--------------------------------------------------------------------------
  1121.   def create_help_window
  1122.     @help_window = Window_Help.new(1)
  1123.     @help_window.create_contents
  1124.     @help_window.visible = false
  1125.   end
  1126.   #--------------------------------------------------------------------------
  1127.   # * Create Result Window
  1128.   #--------------------------------------------------------------------------
  1129.   def create_result_window
  1130.     wy = @help_window.y + @help_window.height
  1131.     wh = Graphics.height - wy
  1132.     @result_window = Window_XRefResults.new(0, wy, Graphics.width, wh)
  1133.     @result_window.viewport = @viewport
  1134.     @result_window.set_handler(:cancel, method(:on_result_cancel))
  1135.     @result_window.hide
  1136.   end
  1137.   #--------------------------------------------------------------------------
  1138.   # * On Choice
  1139.   #--------------------------------------------------------------------------
  1140.   def command_choice
  1141.     @selection_window.refresh
  1142.     @selection_window.activate
  1143.     @selection_window.select(0)
  1144.   end
  1145.   #--------------------------------------------------------------------------
  1146.   # * Selection [OK]
  1147.   #--------------------------------------------------------------------------
  1148.   def on_selection_ok
  1149.     @result_window.mode = @command_window.current_symbol
  1150.     @last_selection = @selection_window.index
  1151.     @result_window.selection = @selection_window.item
  1152.     @result_window.refresh
  1153.     @help_window.show
  1154.     @help_window.set_text(@selection_window.help_text)
  1155.     @selection_window.hide.unselect
  1156.     @command_window.hide
  1157.     @result_window.show.activate
  1158.   end
  1159.   #--------------------------------------------------------------------------
  1160.   # * Selection [Cancel]
  1161.   #--------------------------------------------------------------------------
  1162.   def on_selection_cancel
  1163.     @selection_window.unselect
  1164.     @command_window.activate
  1165.   end
  1166.   #--------------------------------------------------------------------------
  1167.   # * Result [Cancel]
  1168.   #--------------------------------------------------------------------------
  1169.   def on_result_cancel
  1170.     @result_window.hide.unselect
  1171.     @help_window.hide
  1172.     @selection_window.show.activate
  1173.     @selection_window.select(@last_selection)
  1174.     @command_window.show
  1175.   end
  1176. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement