Advertisement
ezmash

VX Ace to MV Converter 2.0 (VX Ace)

Jan 19th, 2018 (edited)
12,404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 50.67 KB | None | 0 0
  1. #=begin
  2. #***********************************************************************
  3. # Version 2.1
  4. # 2020.08.24
  5. #***********************************************************************
  6.  
  7. module DEGICA
  8.   module CONVERT
  9.     FOLDER = 'mv-data/'
  10.    
  11.     LOGGING = true # only useful for debugging this script
  12.     LOGSCRIPTS = true # lists any damage formulae and event commands using scripts - you'll need to convert these manually
  13.     LOGCOMMENTS = true # only turn this on if you have scripts that look for certain comments and want to re-implement them
  14.    
  15.     def self.run
  16.       DataManager.load_normal_database
  17.       Dir.mkdir "mv-data" unless File.exists?("mv-data")
  18.      
  19.       #*************************************************************************
  20.       @log = File.open(FOLDER + "_log.txt", "w") if LOGGING
  21.       @scriptlog = File.open(FOLDER + "_scripts.txt", "w") if LOGSCRIPTS
  22.       @commentlog = File.open(FOLDER + "_comments.txt", "w") if LOGCOMMENTS
  23.       #*************************************************************************
  24.      
  25.       convert_actors
  26.       convert_classes
  27.       convert_skills
  28.       convert_items
  29.       convert_weapons
  30.       convert_armors
  31.       convert_enemies
  32.       convert_troops
  33.       convert_states
  34.       convert_animations
  35.       convert_tilesets
  36.       convert_common_events
  37.       convert_system
  38.       convert_mapinfos
  39.      
  40.       Dir.glob('Data/Map???.rvdata2').each {|filename| convert_map(filename)}
  41.      
  42.       #*************************************************************************
  43.       @log.close if LOGGING
  44.       @scriptlog.close if LOGSCRIPTS
  45.       @commentlog.close if LOGCOMMENTS
  46.       #*************************************************************************
  47.     end
  48.    
  49.     #===========================================================================
  50.     #
  51.     # DATABASE CONVERSION
  52.     #
  53.     #===========================================================================
  54.    
  55.     #===========================================================================
  56.     # ACTORS
  57.     #===========================================================================
  58.     def self.convert_actors
  59.       f = File.open(FOLDER + "Actors.json", "w")
  60.       f.puts('[')
  61.       f.puts('null,')
  62.       for x in 1 ... $data_actors.size
  63.         actor = $data_actors[x]
  64.         actor = RPG::Actor.new if !actor
  65.         actor_data = '{'
  66.        
  67.         actor_data += '"id":' + x.to_s + ','
  68.         actor_data += '"battlerName":"",'
  69.         actor_data += '"characterIndex":' + actor.character_index.to_s + ','
  70.         actor_data += '"characterName":"' + actor.character_name + '",'
  71.         actor_data += '"classId":' + actor.class_id.to_s + ','
  72.         actor_data += '"equips":' + actor.equips.to_s.gsub(/ /){''} + ','
  73.         actor_data += '"faceIndex":' + actor.face_index.to_s + ','
  74.         actor_data += '"faceName":"' + actor.face_name + '",'
  75.         actor_data += '"traits":' + get_traits(actor) + ','
  76.         actor_data += '"initialLevel":' + actor.initial_level.to_s + ','
  77.         actor_data += '"maxLevel":' + actor.max_level.to_s + ','
  78.         actor_data += '"name":' + get_text(actor.name) + ','
  79.         actor_data += '"nickname":' + get_text(actor.nickname) + ','
  80.         actor_data += '"note":' + get_text(actor.note) + ','
  81.         actor_data += '"profile":' + get_text(actor.description)
  82.        
  83.         actor_data += '}'
  84.         actor_data += ',' if x < $data_actors.size - 1
  85.         f.puts(actor_data)
  86.       end
  87.       f.puts(']')
  88.       f.close
  89.     end
  90.    
  91.     #===========================================================================
  92.     # CLASSES
  93.     #===========================================================================
  94.     def self.convert_classes
  95.       f = File.open(FOLDER + "Classes.json", "w")
  96.       f.puts('[')
  97.       f.puts('null,')
  98.       for x in 1 ... $data_classes.size
  99.         cls = $data_classes[x]
  100.         cls = RPG::Class.new if !cls
  101.         cls_data = '{'
  102.        
  103.         cls_data += '"id":' + x.to_s + ','
  104.         cls_data += '"expParams":' + cls.exp_params.to_s.gsub(/ /){''} + ','
  105.         cls_data += '"traits":' + get_traits(cls) + ','
  106.         cls_data += '"learnings":' + get_learnings(cls) + ','
  107.         cls_data += '"name":' + get_text(cls.name) + ','
  108.         cls_data += '"note":' + get_text(cls.note) + ','
  109.         cls_data += '"params":' + get_params(cls)
  110.        
  111.         cls_data += '}'
  112.         cls_data += ',' if x < $data_classes.size - 1
  113.         f.puts(cls_data)
  114.       end
  115.       f.puts(']')
  116.       f.close
  117.     end
  118.  
  119.     def self.get_learnings(obj)
  120.       res = '['
  121.       count = 1
  122.       max_count = obj.learnings.size
  123.       obj.learnings.each do |lrn|
  124.         res += '{"level":' + lrn.level.to_s + ','
  125.         res += '"note":' + get_text(lrn.note) + ','
  126.         res += '"skillId":' + lrn.skill_id.to_s + '}'
  127.         res += ',' if count < max_count
  128.         count += 1
  129.       end      
  130.       res += ']'
  131.       res
  132.     end
  133.    
  134.     def self.get_params(cls)
  135.       res = '['
  136.       for p in 0..7
  137.         res += '['
  138.         for l in 0..99
  139.           res += cls.params[p,l].to_s
  140.           res += ',' if l < 99
  141.         end
  142.         res += ']'
  143.         res += ',' if p < 7
  144.       end
  145.       res += ']'
  146.       res
  147.     end
  148.    
  149.     #===========================================================================
  150.     # SKILLS
  151.     #===========================================================================
  152.     def self.convert_skills
  153.       f = File.open(FOLDER + "Skills.json", "w")
  154.       f.puts('[')
  155.       f.puts('null,')
  156.       for x in 1 ... $data_skills.size
  157.         skill = $data_skills[x]
  158.         skill = RPG::Skill.new if !skill
  159.         skl_data = '{'
  160.        
  161.         skl_data += '"id":' + x.to_s + ','
  162.         skl_data += '"animationId":' + skill.animation_id.to_s + ','
  163.         skl_data += '"damage":' + get_damage(skill) + ','
  164.         skl_data += '"description":' + get_text(skill.description) + ','
  165.         skl_data += '"effects":' + get_effects(skill) + ','
  166.         skl_data += '"hitType":' + skill.hit_type.to_s + ','
  167.         skl_data += '"iconIndex":' + skill.icon_index.to_s + ','
  168.         skl_data += '"message1":' + get_text(skill.message1) + ','
  169.         skl_data += '"message2":' + get_text(skill.message2) + ','
  170.         skl_data += '"mpCost":' + skill.mp_cost.to_s + ','
  171.         skl_data += '"name":' + get_text(skill.name) + ','
  172.         skl_data += '"note":' + get_text(skill.note) + ','
  173.         skl_data += '"occasion":' + skill.occasion.to_s + ','
  174.         skl_data += '"repeats":' + skill.repeats.to_s + ','
  175.         skl_data += '"requiredWtypeId1":' + skill.required_wtype_id1.to_s + ','
  176.         skl_data += '"requiredWtypeId2":' + skill.required_wtype_id2.to_s + ','
  177.         skl_data += '"scope":' + skill.scope.to_s + ','
  178.         skl_data += '"speed":' + skill.speed.to_s + ','
  179.         skl_data += '"stypeId":' + skill.stype_id.to_s + ','
  180.         skl_data += '"successRate":' + skill.success_rate.to_s + ','
  181.         skl_data += '"tpCost":' + skill.tp_cost.to_s + ','
  182.         skl_data += '"tpGain":' + skill.tp_gain.to_s
  183.        
  184.         skl_data += '}'
  185.         skl_data += ',' if x < $data_skills.size - 1
  186.         f.puts(skl_data)
  187.       end
  188.       f.puts(']')
  189.       f.close
  190.     end
  191.    
  192.     #===========================================================================
  193.     # ITEMS
  194.     #===========================================================================
  195.     def self.convert_items
  196.       f = File.open(FOLDER + "Items.json", "w")
  197.       f.puts('[')
  198.       f.puts('null,')
  199.       for x in 1 ... $data_items.size
  200.         item = $data_items[x]
  201.         item = RPG::Item.new if !item
  202.         itm_data = '{'
  203.        
  204.         itm_data += '"id":' + x.to_s + ','
  205.         itm_data += '"animationId":' + item.animation_id.to_s + ','
  206.         itm_data += '"consumable":' + item.consumable.to_s + ','
  207.         itm_data += '"damage":' + get_damage(item) + ','
  208.         itm_data += '"description":' + get_text(item.description) + ','
  209.         itm_data += '"effects":' + get_effects(item) + ','
  210.         itm_data += '"hitType":' + item.hit_type.to_s + ','
  211.         itm_data += '"iconIndex":' + item.icon_index.to_s + ','
  212.         itm_data += '"itypeId":' + item.itype_id.to_s + ','
  213.         itm_data += '"name":' + get_text(item.name) + ','
  214.         itm_data += '"note":' + get_text(item.note) + ','
  215.         itm_data += '"occasion":' + item.occasion.to_s + ','
  216.         itm_data += '"price":' + item.price.to_s + ','
  217.         itm_data += '"repeats":' + item.repeats.to_s + ','
  218.         itm_data += '"scope":' + item.scope.to_s + ','
  219.         itm_data += '"speed":' + item.speed.to_s + ','
  220.         itm_data += '"successRate":' + item.success_rate.to_s + ','
  221.         itm_data += '"tpGain":' + item.tp_gain.to_s
  222.        
  223.         itm_data += '}'
  224.         itm_data += ',' if x < $data_items.size - 1
  225.         f.puts(itm_data)
  226.       end
  227.       f.puts(']')
  228.       f.close
  229.     end
  230.    
  231.     #===========================================================================
  232.     # WEAPONS
  233.     #===========================================================================
  234.     def self.convert_weapons
  235.       f = File.open(FOLDER + "Weapons.json", "w")
  236.       f.puts('[')
  237.       f.puts('null,')
  238.       for x in 1 ... $data_weapons.size
  239.         wpn = $data_weapons[x]
  240.         wpn = RPG::Weapon.new if !wpn
  241.         wpn_data = '{'
  242.        
  243.         wpn_data += '"id":' + x.to_s + ','
  244.         wpn_data += '"animationId":' + wpn.animation_id.to_s + ','
  245.         wpn_data += '"description":' + get_text(wpn.description) + ','
  246.         wpn_data += '"etypeId":1,' # weapons are 0 in Ace, but 1 in MV
  247.         wpn_data += '"traits":' + get_traits(wpn) + ','
  248.         wpn_data += '"iconIndex":' + wpn.icon_index.to_s + ','
  249.         wpn_data += '"name":' + get_text(wpn.name) + ','
  250.         wpn_data += '"note":' + get_text(wpn.note) + ','
  251.         wpn_data += '"params":' + wpn.params.to_s.gsub(/ /){''} + ','
  252.         wpn_data += '"price":' + wpn.price.to_s + ','
  253.         wpn_data += '"wtypeId":' + wpn.wtype_id.to_s
  254.        
  255.         wpn_data += '}'
  256.         wpn_data += ',' if x < $data_weapons.size - 1
  257.         f.puts(wpn_data)
  258.       end
  259.       f.puts(']')
  260.       f.close
  261.     end
  262.    
  263.     #===========================================================================
  264.     # ARMORS
  265.     #===========================================================================
  266.     def self.convert_armors
  267.       f = File.open(FOLDER + "Armors.json", "w")
  268.       f.puts('[')
  269.       f.puts('null,')
  270.       for x in 1 ... $data_armors.size
  271.         amr = $data_armors[x]
  272.         amr = RPG::Armor.new if !amr
  273.         amr_data = '{'
  274.        
  275.         amr_data += '"id":' + x.to_s + ','
  276.         amr_data += '"atypeId":' + amr.atype_id.to_s + ','
  277.         amr_data += '"description":' + get_text(amr.description) + ','
  278.         amr_data += '"etypeId":' + amr.etype_id.to_s + ','
  279.         amr_data += '"traits":' + get_traits(amr) + ','
  280.         amr_data += '"iconIndex":' + amr.icon_index.to_s + ','
  281.         amr_data += '"name":' + get_text(amr.name) + ','
  282.         amr_data += '"note":' + get_text(amr.note) + ','
  283.         amr_data += '"params":' + amr.params.to_s.gsub(/ /){''} + ','
  284.         amr_data += '"price":' + amr.price.to_s
  285.        
  286.         amr_data += '}'
  287.         amr_data += ',' if x < $data_armors.size - 1
  288.         f.puts(amr_data)
  289.       end
  290.       f.puts(']')
  291.       f.close
  292.     end
  293.    
  294.     #===========================================================================
  295.     # ENEMIES
  296.     #===========================================================================
  297.     def self.convert_enemies
  298.       f = File.open(FOLDER + "Enemies.json", "w")
  299.       f.puts('[')
  300.       f.puts('null,')
  301.       for x in 1 ... $data_enemies.size
  302.         foe = $data_enemies[x]
  303.         foe = RPG::Enemy.new if !foe
  304.         foe_data = '{'
  305.        
  306.         foe_data += '"id":' + x.to_s + ','
  307.         foe_data += '"actions":' + get_actions(foe) + ','
  308.         foe_data += '"battlerHue":' + foe.battler_hue.to_s + ','
  309.         foe_data += '"battlerName":"' + foe.battler_name + '",'
  310.         foe_data += '"dropItems":' + get_drop_items(foe) + ','
  311.         foe_data += '"exp":' + foe.exp.to_s + ','
  312.         foe_data += '"traits":' + get_traits(foe) + ','
  313.         foe_data += '"gold":' + foe.gold.to_s + ','
  314.         foe_data += '"name":' + get_text(foe.name) + ','
  315.         foe_data += '"note":' + get_text(foe.note) + ','
  316.         foe_data += '"params":' + foe.params.to_s.gsub(/ /){''}
  317.        
  318.         foe_data += '}'
  319.         foe_data += ',' if x < $data_enemies.size - 1
  320.         f.puts(foe_data)
  321.       end
  322.       f.puts(']')
  323.       f.close
  324.     end
  325.    
  326.     def self.get_actions(foe)
  327.       res = '['
  328.       count = 1
  329.       max_count = foe.actions.size
  330.       foe.actions.each do |action|
  331.         res += '{"conditionParam1":' + action.condition_param1.to_s + ','
  332.         res += '"conditionParam2":' + action.condition_param2.to_s + ','
  333.         res += '"conditionType":' + action.condition_type.to_s + ','
  334.         res += '"rating":' + action.rating.to_s + ','
  335.         res += '"skillId":' + action.skill_id.to_s + '}'
  336.         res += ',' if count < max_count
  337.         count += 1
  338.       end
  339.       res += ']'
  340.       res
  341.     end
  342.    
  343.     def self.get_drop_items(foe)
  344.       res = '['
  345.       count = 1
  346.       max_count = foe.drop_items.size
  347.       foe.drop_items.each do |item|
  348.         res += '{"dataId":' + item.data_id.to_s + ','
  349.         res += '"denominator":' + item.denominator.to_s + ','
  350.         res += '"kind":' + item.kind.to_s + '}'
  351.         res += ',' if count < max_count
  352.         count += 1
  353.       end
  354.       res += ']'
  355.       res
  356.     end
  357.    
  358.     #===========================================================================
  359.     # TROOPS
  360.     #===========================================================================
  361.     def self.convert_troops
  362.       f = File.open(FOLDER + "Troops.json", "w")
  363.       f.puts('[')
  364.       f.puts('null,')
  365.       for x in 1 ... $data_troops.size
  366.         troop = $data_troops[x]
  367.         troop = RPG::Troop.new if !troop
  368.         troop_data = '{'
  369.        
  370.         #***********************************************************************
  371.         log("Troop " + x.to_s + " (" + get_text(troop.name) + ")")
  372.         @logtroop = sprintf('Troop %d %s ', x, troop.name)
  373.         #***********************************************************************
  374.      
  375.         troop_data += '"id":' + x.to_s + ','
  376.         troop_data += '"members":' + get_troop_members(troop) + ','
  377.         troop_data += '"name":' + get_text(troop.name) + ','
  378.         troop_data += '"pages":' + get_troop_pages(troop)
  379.        
  380.         troop_data += '}'
  381.         troop_data += ',' if x < $data_troops.size - 1
  382.         f.puts(troop_data)
  383.       end
  384.       f.puts(']')
  385.       f.close
  386.     end
  387.    
  388.     def self.get_troop_members(troop)
  389.       res = '['
  390.       count = 1
  391.       max_count = troop.members.size
  392.       troop.members.each do |enemy|
  393.         res += '{"enemyId":' + enemy.enemy_id.to_s + ','
  394.         res += '"x":' + enemy.x.to_s + ','
  395.         res += '"y":' + enemy.y.to_s + ','
  396.         res += '"hidden":' + enemy.hidden.to_s + '}'
  397.         res += ',' if count < max_count
  398.         count += 1
  399.       end
  400.       res += ']'
  401.       res
  402.     end
  403.    
  404.     def self.get_troop_pages(troop)
  405.       res = '['
  406.       count = 1
  407.       max_count = troop.pages.size
  408.       troop.pages.each do |page|
  409.         #***********************************************************************
  410.         log("  Page " + count.to_s)
  411.         @logkey = sprintf('%s Page %d', @logtroop, count)
  412.         #***********************************************************************
  413.         cond = page.condition
  414.         res += '{"conditions":{"actorHp":' + cond.actor_hp.to_s + ','
  415.         res += '"actorId":' + cond.actor_id.to_s + ','
  416.         res += '"actorValid":' + cond.actor_valid.to_s + ','
  417.         res += '"enemyHp":' + cond.enemy_hp.to_s + ','
  418.         res += '"enemyIndex":' + cond.enemy_index.to_s + ','
  419.         res += '"enemyValid":' + cond.enemy_valid.to_s + ','
  420.         res += '"switchId":' + cond.switch_id.to_s + ','
  421.         res += '"switchValid":' + cond.switch_valid.to_s + ','
  422.         res += '"turnA":' + cond.turn_a.to_s + ','
  423.         res += '"turnB":' + cond.turn_b.to_s + ','
  424.         res += '"turnEnding":' + cond.turn_ending.to_s + ','
  425.         res += '"turnValid":' + cond.turn_valid.to_s + '},'
  426.        
  427.         res += '"list":' + get_command_list(page.list) + ','
  428.         res += '"span":' + page.span.to_s + '}'
  429.        
  430.         res += ',' if count < max_count
  431.         count += 1
  432.       end
  433.       res += ']'
  434.       res
  435.     end
  436.    
  437.     #===========================================================================
  438.     # STATES
  439.     #===========================================================================
  440.     def self.convert_states
  441.       f = File.open(FOLDER + "States.json", "w")
  442.       f.puts('[')
  443.       f.puts('null,')
  444.       for x in 1 ... $data_states.size
  445.         state = $data_states[x]
  446.         state = RPG::State.new if !state
  447.         state_data = '{'
  448.        
  449.         state_data += '"id":' + x.to_s + ','
  450.         state_data += '"autoRemovalTiming":' + state.auto_removal_timing.to_s + ','
  451.         state_data += '"chanceByDamage":' + state.chance_by_damage.to_s + ','
  452.         state_data += '"iconIndex":' + state.icon_index.to_s + ','
  453.         state_data += '"maxTurns":' + state.max_turns.to_s + ','
  454.         state_data += '"message1":' + get_text(state.message1) + ','
  455.         state_data += '"message2":' + get_text(state.message2) + ','
  456.         state_data += '"message3":' + get_text(state.message3) + ','
  457.         state_data += '"message4":' + get_text(state.message4) + ','
  458.         state_data += '"minTurns":' + state.min_turns.to_s + ','
  459.         state_data += '"motion":0,'
  460.         state_data += '"overlay":0,'
  461.         state_data += '"name":' + get_text(state.name) + ','
  462.         state_data += '"note":' + get_text(state.note) + ','
  463.         state_data += '"priority":' + state.priority.to_s + ','
  464.         state_data += '"removeAtBattleEnd":' + state.remove_at_battle_end.to_s + ','
  465.         state_data += '"removeByDamage":' + state.remove_by_damage.to_s + ','
  466.         state_data += '"removeByRestriction":' + state.remove_by_restriction.to_s + ','
  467.         state_data += '"removeByWalking":' + state.remove_by_walking.to_s + ','
  468.         state_data += '"restriction":' + state.restriction.to_s + ','
  469.         state_data += '"stepsToRemove":' + state.steps_to_remove.to_s + ','
  470.         state_data += '"traits":' + get_traits(state)        
  471.        
  472.         state_data += '}'
  473.         state_data += ',' if x < $data_states.size - 1
  474.         f.puts(state_data)
  475.       end
  476.       f.puts(']')
  477.       f.close
  478.     end
  479.    
  480.     #===========================================================================
  481.     # ANIMATIONS
  482.     #===========================================================================
  483.     def self.convert_animations
  484.       f = File.open(FOLDER + "Animations.json", "w")
  485.       f.puts('[')
  486.       f.puts('null,')
  487.       for x in 1 ... $data_animations.size
  488.         anim = $data_animations[x]
  489.         anim = RPG::Animation.new if !anim
  490.         anim_data = '{'
  491.        
  492.         anim_data += '"id":' + x.to_s + ','
  493.         anim_data += '"animation1Hue":' + anim.animation1_hue.to_s + ','
  494.         anim_data += '"animation1Name":"' + anim.animation1_name + '",'
  495.         anim_data += '"animation2Hue":' + anim.animation2_hue.to_s + ','
  496.         anim_data += '"animation2Name":"' + anim.animation2_name + '",'
  497.         anim_data += '"frames":' + get_anim_frames(anim) + ','
  498.         anim_data += '"name":' + get_text(anim.name) + ','
  499.         anim_data += '"position":' + anim.position.to_s + ','
  500.         anim_data += '"timings":' + get_anim_timings(anim)
  501.        
  502.         anim_data += '}'
  503.         anim_data += ',' if x < $data_animations.size - 1
  504.         f.puts(anim_data)
  505.       end
  506.       f.puts(']')
  507.       f.close
  508.     end
  509.    
  510.     def self.get_anim_frames(anim)
  511.       res = '['
  512.       for f in 0 ... anim.frame_max
  513.         res += '['
  514.         frame = anim.frames[f]
  515.         if frame
  516.           for c in 0 ... frame.cell_max
  517.             res += '['
  518.             for i in 0..7
  519.               res += frame.cell_data[c,i].to_s
  520.               res += ',' if i < 7
  521.             end
  522.             res += ']'
  523.             res += ',' if c < frame.cell_max - 1
  524.           end
  525.         else
  526.           res += '[]'
  527.         end
  528.         res += ']'
  529.         res += ',' if f < anim.frame_max - 1
  530.       end
  531.       res += ']'
  532.       res
  533.     end
  534.    
  535.     def self.get_anim_timings(anim)
  536.       res = '['
  537.       for t in 0 ... anim.timings.size
  538.         timing = anim.timings[t]
  539.         res += '{"flashColor":' + get_color(timing.flash_color) + ','
  540.         res += '"flashDuration":' + timing.flash_duration.to_s + ','
  541.         res += '"flashScope":' + timing.flash_scope.to_s + ','
  542.         res += '"frame":' + timing.frame.to_s + ','
  543.         res += '"se":'
  544.         if timing.se.name == ''
  545.           res += 'null'
  546.         else
  547.           res += get_audio(timing.se)
  548.         end
  549.         res += '}'
  550.         res += ',' if t < anim.timings.size - 1
  551.       end
  552.       res += ']'
  553.       res
  554.     end
  555.    
  556.     #===========================================================================
  557.     # TILESETS
  558.     #===========================================================================
  559.     def self.convert_tilesets
  560.       f = File.open(FOLDER + "Tilesets.json", "w")
  561.       f.puts('[')
  562.       f.puts('null,')
  563.       for x in 1 ... $data_tilesets.size
  564.         tileset = $data_tilesets[x]
  565.         tileset = RPG::Tileset.new if !tileset
  566.         ts_data = '{'
  567.        
  568.         ts_data += '"id":' + x.to_s + ','
  569.         ts_data += '"flags":'
  570.         flags = []
  571.         for t in 0 .. 8191
  572.           flags[t] = tileset.flags[t]
  573.         end
  574.         ts_data += flags.to_s.gsub(/ /){''} + ','
  575.         ts_data += '"mode":' + tileset.mode.to_s + ','
  576.         ts_data += '"name":' + get_text(tileset.name) + ','
  577.         ts_data += '"note":' + get_text(tileset.note) + ','
  578.         ts_data += '"tilesetNames":' + tileset.tileset_names.to_s.gsub(/, /){','}
  579.        
  580.         ts_data += '}'
  581.         ts_data += ',' if x < $data_tilesets.size - 1
  582.         f.puts(ts_data)
  583.       end
  584.       f.puts(']')
  585.       f.close
  586.     end
  587.    
  588.     #===========================================================================
  589.     # COMMON EVENTS
  590.     #===========================================================================
  591.     def self.convert_common_events
  592.       f = File.open(FOLDER + "CommonEvents.json", "w")
  593.       f.puts('[')
  594.       f.puts('null,')
  595.       for x in 1 ... $data_common_events.size
  596.         event = $data_common_events[x]
  597.         event = RPG::CommonEvent.new if !event
  598.        
  599.         #***********************************************************************
  600.         log("Common Event " + x.to_s + " (" + get_text(event.name) + ")")
  601.         @logkey = sprintf('Common Event %d %s', x, event.name)
  602.         #***********************************************************************
  603.        
  604.         ev_data = '{'
  605.        
  606.         ev_data += '"id":' + x.to_s + ','
  607.         ev_data += '"list":' + get_command_list(event.list) + ','
  608.         ev_data += '"name":' + get_text(event.name) + ','
  609.         ev_data += '"switchId":' + event.switch_id.to_s + ','
  610.         ev_data += '"trigger":' + event.trigger.to_s
  611.        
  612.         ev_data += '}'
  613.         ev_data += ',' if x < $data_common_events.size - 1
  614.         f.puts(ev_data)
  615.       end
  616.       f.puts(']')
  617.       f.close
  618.     end
  619.    
  620.     #===========================================================================
  621.     # SYSTEM
  622.     #===========================================================================
  623.     def self.convert_system
  624.       f = File.open(FOLDER + "System.json", "w")
  625.       system = $data_system
  626.       sys_data = '{'
  627.      
  628.       sys_data += '"airship":' + get_vehicle(system.airship) + ','
  629.       sys_data += '"armorTypes":' + system.armor_types.to_s.gsub(/, /){','} + ','
  630.       sys_data += '"attackMotions":' + get_attack_motions + ','
  631.       sys_data += '"battleBgm":' + get_audio(system.battle_bgm) + ','
  632.       sys_data += '"battleBack1Name":"' + system.battleback1_name + '",'
  633.       sys_data += '"battleBack2Name":"' + system.battleback2_name + '",'
  634.       sys_data += '"battlerHue":' + system.battler_hue.to_s + ','
  635.       sys_data += '"battlerName":"' + system.battler_name + '",'
  636.       sys_data += '"boat":' + get_vehicle(system.boat) + ','
  637.       sys_data += '"currencyUnit":"' + system.currency_unit + '",'
  638.       sys_data += '"defeatMe":{"name":"Defeat1","pan":0,"pitch":100,"volume":90},'
  639.       sys_data += '"editMapId":' + system.edit_map_id.to_s + ','
  640.       sys_data += '"elements":' + system.elements.to_s.gsub(/, /){','} + ','
  641.       sys_data += '"equipTypes":' + system.terms.etypes.unshift('').to_s.gsub(/, /){','} + ','
  642.       sys_data += '"gameTitle":' + get_text(system.game_title) + ','
  643.       sys_data += '"gameoverMe":' + get_audio(system.gameover_me) + ','
  644.       sys_data += '"locale":"en_US",'
  645.       sys_data += '"magicSkills":[1],'
  646.       sys_data += '"menuCommands":[true,true,true,true,true,true],'
  647.       sys_data += '"optDisplayTp":' + system.opt_display_tp.to_s + ','
  648.       sys_data += '"optDrawTitle":' + system.opt_draw_title.to_s + ','
  649.       sys_data += '"optExtraExp":' + system.opt_extra_exp.to_s + ','
  650.       sys_data += '"optFloorDeath":' + system.opt_floor_death.to_s + ','
  651.       sys_data += '"optFollowers":' + system.opt_followers.to_s + ','
  652.       sys_data += '"optSideView":false,'
  653.       sys_data += '"optSlipDeath":' + system.opt_slip_death.to_s + ','
  654.       sys_data += '"optTransparent":' + system.opt_transparent.to_s + ','
  655.       sys_data += '"partyMembers":' + system.party_members.to_s.gsub(/ /){''} + ','
  656.       sys_data += '"ship":' + get_vehicle(system.ship) + ','
  657.       sys_data += '"skillTypes":' + system.skill_types.to_s.gsub(/, /){','} + ','
  658.       sys_data += '"sounds":' + get_system_sounds(system) + ','
  659.       sys_data += '"startMapId":' + system.start_map_id.to_s + ','
  660.       sys_data += '"startX":' + system.start_x.to_s + ','
  661.       sys_data += '"startY":' + system.start_y.to_s + ','
  662.       system.switches[0] = ''
  663.       sys_data += '"switches":' + system.switches.to_s.gsub(/, /){','} + ','
  664.       sys_data += '"terms":{"basic":' + (system.terms.basic + ['EXP','EXP']).to_s.gsub(/, /){','} + ','
  665.       sys_data += '"commands":' + (system.terms.commands + ['','Buy','Sell']).to_s.gsub(/, /){','} + ','
  666.       sys_data += '"params":' + (system.terms.params + ['Hit','Evasion']).to_s.gsub(/, /){','} + ','
  667.       sys_data += '"messages":' + get_system_messages + '},'
  668.       sys_data += '"testBattlers":' + get_test_battlers(system.test_battlers) + ','
  669.       sys_data += '"testTroopId":' + system.test_troop_id.to_s + ','
  670.       sys_data += '"title1Name":"' + system.title1_name + '",'
  671.       sys_data += '"title2Name":"' + system.title2_name + '",'
  672.       sys_data += '"titleBgm":' + get_audio(system.title_bgm) + ','
  673.       system.variables[0] = ''
  674.       sys_data += '"variables":' + system.variables.to_s.gsub(/, /){','} + ','
  675.       sys_data += '"versionId":' + system.version_id.to_s + ','
  676.       sys_data += '"victoryMe":' + get_audio(system.battle_end_me) + ','
  677.       sys_data += '"weaponTypes":' + system.weapon_types.to_s.gsub(/, /){','} + ','
  678.       sys_data += '"windowTone":' + get_tone(system.window_tone)
  679.      
  680.       sys_data += '}'
  681.       f.puts(sys_data)
  682.       f.close
  683.     end
  684.    
  685.     def self.get_attack_motions
  686.       res = '['
  687.       res += '{"type":0,"weaponImageId":0},'
  688.       res += '{"type":1,"weaponImageId":1},'
  689.       res += '{"type":1,"weaponImageId":2},'
  690.       res += '{"type":1,"weaponImageId":3},'
  691.       res += '{"type":1,"weaponImageId":4},'
  692.       res += '{"type":1,"weaponImageId":5},'
  693.       res += '{"type":1,"weaponImageId":6},'
  694.       res += '{"type":2,"weaponImageId":7},'
  695.       res += '{"type":2,"weaponImageId":8},'
  696.       res += '{"type":2,"weaponImageId":9},'
  697.       res += '{"type":0,"weaponImageId":10},'
  698.       res += '{"type":0,"weaponImageId":11},'
  699.       res += '{"type":0,"weaponImageId":12}'
  700.       res += ']'
  701.       res
  702.     end
  703.      
  704.     def self.get_vehicle(vehicle)
  705.       res = '{"bgm":' + get_audio(vehicle.bgm) + ','
  706.       res += '"characterIndex":' + vehicle.character_index.to_s + ','
  707.       res += '"characterName":"' + vehicle.character_name + '",'
  708.       res += '"startMapId":' + vehicle.start_map_id.to_s + ','
  709.       res += '"startX":' + vehicle.start_x.to_s + ','
  710.       res += '"startY":' + vehicle.start_y.to_s + '}'
  711.       res
  712.     end
  713.    
  714.     def self.get_system_sounds(system)
  715.       res = '['
  716.       for x in 0 ... system.sounds.size
  717.         res += get_audio(system.sounds[x])
  718.         res += ',' if x < system.sounds.size - 1
  719.       end
  720.      
  721.       res += ']'
  722.       res
  723.     end
  724.    
  725.     def self.get_system_messages
  726.       res = '{'
  727.       res += '"actionFailure":"There was no effect on %1!",'
  728.       res += '"actorDamage":"%1 took %2 damage!",'
  729.       res += '"actorDrain":"%1 was drained of %2 %3!",'
  730.       res += '"actorGain":"%1 gained %2 %3!",'
  731.       res += '"actorLoss":"%1 lost %2 %3!",'
  732.       res += '"actorNoDamage":"%1 took no damage!",'
  733.       res += '"actorNoHit":"Miss! %1 took no damage!",'
  734.       res += '"actorRecovery":"%1 recovered %2 %3!",'
  735.       res += '"alwaysDash":"Always Dash",'
  736.       res += '"bgmVolume":"BGM Volume",'
  737.       res += '"bgsVolume":"BGS Volume",'
  738.       res += '"buffAdd":"%1\'s %2 went up!",'
  739.       res += '"buffRemove":"%1''s %2 returned to normal!",'
  740.       res += '"commandRemember":"Command Remember",'
  741.       res += '"counterAttack":"%1 counterattacked!",'
  742.       res += '"criticalToActor":"A painful blow!!",'
  743.       res += '"criticalToEnemy":"An excellent hit!!",'
  744.       res += '"debuffAdd":"%1\'s %2 went down!",'
  745.       res += '"defeat":"%1 was defeated.",'
  746.       res += '"emerge":"%1 emerged!",'
  747.       res += '"enemyDamage":"%1 took %2 damage!",'
  748.       res += '"enemyDrain":"%1 was drained of %2 %3!",'
  749.       res += '"enemyGain":"%1 gained %2 %3!",'
  750.       res += '"enemyLoss":"%1 lost %2 %3!",'
  751.       res += '"enemyNoDamage":"%1 took no damage!",'
  752.       res += '"enemyNoHit":"Miss! %1 took no damage!",'
  753.       res += '"enemyRecovery":"%1 recovered %2 %3!",'
  754.       res += '"escapeFailure":"However, it was unable to escape!",'
  755.       res += '"escapeStart":"%1 has started to escape!",'
  756.       res += '"evasion":"%1 evaded the attack!",'
  757.       res += '"expNext":"To Next %1",'
  758.       res += '"expTotal":"Current %1",'
  759.       res += '"file":"File",'
  760.       res += '"levelUp":"%1 is now %2 %3!",'
  761.       res += '"loadMessage":"Load which file?",'
  762.       res += '"magicEvasion":"%1 nullified the magic!",'
  763.       res += '"magicReflection":"%1 reflected the magic!",'
  764.       res += '"meVolume":"ME Volume",'
  765.       res += '"obtainExp":"%1 %2 received!",'
  766.       res += '"obtainGold":"%1\\\\G found!",'
  767.       res += '"obtainItem":"%1 found!",'
  768.       res += '"obtainSkill":"%1 learned!",'
  769.       res += '"partyName":"%1\'s Party",'
  770.       res += '"possession":"Possession",'
  771.       res += '"preemptive":"%1 got the upper hand!",'
  772.       res += '"saveMessage":"Save to which file?",'
  773.       res += '"seVolume":"SE Volume",'
  774.       res += '"substitute":"%1 protected %2!",'
  775.       res += '"surprise":"%1 was surprised!",'
  776.       res += '"useItem":"%1 uses %2!",'
  777.       res += '"victory":"%1 was victorious!"'
  778.       res += '}'
  779.       res
  780.     end
  781.    
  782.     def self.get_test_battlers(battlers)
  783.       res = '['
  784.       for x in 0 ... battlers.size
  785.         battler = battlers[x]
  786.         res += '{'
  787.         res += '"actorId":' + battler.actor_id.to_s + ','
  788.         res += '"equips":' + battler.equips.to_s.gsub(/ /){''} + ','
  789.         res += '"level":' + battler.level.to_s
  790.         res += '}'
  791.         res += ',' if x < battlers.size - 1
  792.       end
  793.       res += ']'
  794.       res
  795.     end
  796.    
  797.     #===========================================================================
  798.     # MAPINFOS
  799.     #===========================================================================
  800.     def self.convert_mapinfos
  801.       f = File.open(FOLDER + "MapInfos.json", "w")
  802.       f.puts('[')
  803.       f.puts('null,')
  804.       for x in 1 .. $data_mapinfos.size
  805.         map = $data_mapinfos[x]
  806.         map = RPG::MapInfo.new if !map
  807.         map_data = '{'
  808.         map_data += '"id":' + x.to_s + ','
  809.         map_data += '"expanded":' + map.expanded.to_s + ','
  810.         map_data += '"name":' + get_text(map.name) + ','
  811.         map_data += '"order":' + map.order.to_s + ','
  812.         map_data += '"parentId":' + map.parent_id.to_s + ','
  813.         map_data += '"scrollX":' + map.scroll_x.to_s + ','
  814.         map_data += '"scrollY":' + map.scroll_y.to_s
  815.        
  816.         map_data += '}'
  817.         map_data += ',' if x < $data_mapinfos.size
  818.         f.puts(map_data)
  819.       end      
  820.       f.puts(']')
  821.       f.close
  822.     end
  823.    
  824.     #===========================================================================
  825.     # MAPS
  826.     #===========================================================================
  827.     def self.convert_map(filename)
  828.       map = load_data(filename)
  829.       f = File.open(FOLDER + filename.gsub(/Data\//){''}.gsub(/rvdata2/){'json'}, "w")
  830.       f.puts('{')
  831.       mapid = 0
  832.      
  833.       #*************************************************************************
  834.       log("Map " + filename + " (" + map.display_name + ")")
  835.       filename.gsub!(/Map(\d+)\.rvdata2/) do
  836.         mapid = $1.to_i
  837.         @logmap = sprintf('Map %d %s', $1.to_i, $data_mapinfos[$1.to_i].name)
  838.       end
  839.       #*************************************************************************
  840.      
  841.       map_data = '"autoplayBgm":' + map.autoplay_bgm.to_s + ','
  842.       map_data += '"autoplayBgs":' + map.autoplay_bgs.to_s + ','
  843.       map_data += '"battleback1Name":"' + map.battleback1_name + '",'
  844.       map_data += '"battleback2Name":"' + map.battleback2_name + '",'
  845.       map_data += '"bgm":' + get_audio(map.bgm) + ','
  846.       map_data += '"bgs":' + get_audio(map.bgs) + ','
  847.       map_data += '"disableDashing":' + map.disable_dashing.to_s + ','
  848.       map_data += '"displayName":' + get_text(map.display_name) + ','
  849.       map_data += '"encounterList":' + get_encounter_list(map.encounter_list) + ','
  850.       map_data += '"encounterStep":' + map.encounter_step.to_s + ','
  851.       map_data += '"height":' + map.height.to_s + ','
  852.       map_data += '"note":' + get_text(map.note) + ','
  853.       map_data += '"parallaxLoopX":' + map.parallax_loop_x.to_s + ','
  854.       map_data += '"parallaxLoopY":' + map.parallax_loop_y.to_s + ','
  855.       map_data += '"parallaxName":"' + map.parallax_name + '",'
  856.       map_data += '"parallaxShow":' + map.parallax_show.to_s + ','
  857.       map_data += '"parallaxSx":' + map.parallax_sx.to_s + ','
  858.       map_data += '"parallaxSy":' + map.parallax_sy.to_s + ','
  859.       map_data += '"scrollType":' + map.scroll_type.to_s + ','
  860.       map_data += '"specifyBattleback":' + map.specify_battleback.to_s + ','
  861.       map_data += '"tilesetId":' + map.tileset_id.to_s + ','
  862.       map_data += '"width":' + map.width.to_s + ','
  863.       map_data += '"data":' + get_map_data(map.data, map.events).to_s.gsub(/ /){''} + ','
  864.       map_data += '"events":' + get_map_events(map.events)
  865.      
  866.       p sprintf('Map %d (%s) is %d x %d', mapid, $data_mapinfos[mapid].name, map.width, map.height) if map.width < 25 or map.height < 19
  867.      
  868.       f.puts(map_data)
  869.      
  870.       f.puts('}')
  871.       f.close
  872.     end
  873.    
  874.     def self.get_encounter_list(list)
  875.       res = '['
  876.       for x in 0 ... list.size
  877.         encounter = list[x]
  878.         encounter = RPG::Map::Encounter.new if !encounter
  879.         res += '{"regionSet":' + encounter.region_set.to_s.gsub(/ /){''} + ','
  880.         res += '"troopId":' + encounter.troop_id.to_s + ','
  881.         res += '"weight":' + encounter.weight.to_s
  882.         res += '}'
  883.         res += ',' if x < list.size - 1
  884.       end
  885.       res += ']'
  886.       res
  887.     end
  888.    
  889.     def self.get_map_data(data, events)
  890.       res = []
  891.       for z in 0 .. 1 # first 2 map layers
  892.         for y in 0 ... data.ysize
  893.           for x in 0 ... data.xsize
  894.             res.push(data[x,y,z])
  895.           end
  896.         end
  897.       end
  898.       z = 2
  899.       upper1 = []
  900.       upper2 = []
  901.       for y in 0 ... data.ysize # 3rd & new 4th map layer
  902.         for x in 0 ... data.xsize
  903.           tile_event = events.select{|id, evt| evt && evt.x == x && evt.y == y && is_tile_event?(evt) }
  904.           if tile_event.size > 0
  905.             key = tile_event.keys[0]
  906.             upper1.push(data[x,y,z])
  907.             upper2.push(events[key].pages[0].graphic.tile_id)
  908.           else
  909.             upper1.push(0)
  910.             upper2.push(data[x,y,z])
  911.           end
  912.         end
  913.       end
  914.       res += upper1 + upper2
  915.       z = data.zsize - 1 # shadow layer
  916.       for y in 0 ... data.ysize
  917.         for x in 0 ... data.xsize
  918.           res.push(data[x,y,z])
  919.         end
  920.       end
  921.       for y in 0 ... data.ysize # region layer
  922.         for x in 0 ... data.xsize
  923.           res.push(data[x,y,3] >> 8)
  924.         end
  925.       end
  926.       res
  927.     end
  928.    
  929.     def self.is_tile_event?(evt)
  930.       return false if evt.pages.size > 1
  931.       return false if evt.pages[0].list.size > 1
  932.       return false if evt.pages[0].graphic.tile_id == 0
  933.       c = evt.pages[0].condition
  934.       return !(c.switch1_valid || c.switch2_valid || c.variable_valid ||
  935.         c.self_switch_valid || c.item_valid || c.actor_valid)
  936.     end
  937.    
  938.     def self.get_map_events(events)
  939.       res = '['
  940.       max_key = events.keys.max
  941.       if max_key
  942.         for x in 0 .. max_key
  943.           if events.has_key?(x)
  944.             event = events[x]
  945.             if is_tile_event?(event)
  946.               res += 'null'
  947.             else
  948.               res += get_event(event)
  949.             end
  950.           else
  951.             res += 'null'
  952.           end
  953.           res += ',' if x < max_key
  954.         end
  955.       end
  956.       res += ']'
  957.       res
  958.     end
  959.  
  960.     def self.get_event(event)
  961.       #*************************************************************************
  962.       log("  Event " + event.id.to_s + " (" + get_text(event.name) + " @ " + event.x.to_s + "," + event.y.to_s + ")")
  963.       @logevent = sprintf('%s - Event %d %s (%d,%d)', @logmap, event.id, event.name, event.x, event.y)
  964.       #*************************************************************************
  965.       res = '{"id":' + event.id.to_s + ','
  966.       res += '"name":' + get_text(event.name) + ','
  967.       res += '"note":"",'
  968.       res += '"pages":' + get_event_pages(event.pages) + ','
  969.       res += '"x":' + event.x.to_s + ','
  970.       res += '"y":' + event.y.to_s      
  971.       res += '}'
  972.       res
  973.     end
  974.    
  975.     def self.get_event_pages(pages)
  976.       res = '['
  977.       for x in 0 ... pages.size
  978.         #***********************************************************************
  979.         log("    Page " + (x+1).to_s)
  980.         @logkey = sprintf('%s - Page %d', @logevent, x+1)
  981.         #***********************************************************************
  982.         page = pages[x]
  983.         page = RPG::Event::Page.new if !page
  984.         res += get_page(page)
  985.         res += ',' if x < pages.size - 1
  986.       end
  987.       res += ']'
  988.       res
  989.     end
  990.        
  991.     def self.get_page(page)
  992.       condition = page.condition
  993.       res = '{"conditions":'
  994.       res += '{"actorId":' + condition.actor_id.to_s + ','
  995.       res += '"actorValid":' + condition.actor_valid.to_s + ','
  996.       res += '"itemId":' + condition.item_id.to_s + ','
  997.       res += '"itemValid":' + condition.item_valid.to_s + ','
  998.       res += '"selfSwitchCh":"' + condition.self_switch_ch + '",'
  999.       res += '"selfSwitchValid":' + condition.self_switch_valid.to_s + ','
  1000.       res += '"switch1Id":' + condition.switch1_id.to_s + ','
  1001.       res += '"switch1Valid":' + condition.switch1_valid.to_s + ','
  1002.       res += '"switch2Id":' + condition.switch2_id.to_s + ','
  1003.       res += '"switch2Valid":' + condition.switch2_valid.to_s + ','
  1004.       res += '"variableId":' + condition.variable_id.to_s + ','
  1005.       res += '"variableValid":' + condition.variable_valid.to_s + ','
  1006.       res += '"variableValue":' + condition.variable_value.to_s + '},'
  1007.      
  1008.       res += '"directionFix":' + page.direction_fix.to_s + ','
  1009.      
  1010.       graphic = page.graphic
  1011.       res += '"image":'
  1012.       res += '{"tileId":' + graphic.tile_id.to_s + ','
  1013.       res += '"characterName":"' + graphic.character_name + '",'
  1014.       res += '"direction":' + graphic.direction.to_s + ','
  1015.       res += '"pattern":' + graphic.pattern.to_s + ','
  1016.       res += '"characterIndex":' + graphic.character_index.to_s + '},'
  1017.      
  1018.       res += '"moveFrequency":' + page.move_frequency.to_s + ','
  1019.       res += '"moveRoute":' + get_move_route(page.move_route) + ','
  1020.       res += '"moveSpeed":' + page.move_speed.to_s + ','
  1021.       res += '"moveType":' + page.move_type.to_s + ','
  1022.       res += '"priorityType":' + page.priority_type.to_s + ','
  1023.       res += '"stepAnime":' + page.step_anime.to_s + ','
  1024.       res += '"through":' + page.through.to_s + ','
  1025.       res += '"trigger":' + page.trigger.to_s + ','
  1026.       res += '"walkAnime":' + page.walk_anime.to_s + ','
  1027.       res += '"list":' + get_command_list(page.list) + '}'
  1028.      
  1029.       res
  1030.     end
  1031.    
  1032.     #===========================================================================
  1033.     # SUPPORT OBJECTS FOR DATABASE
  1034.     #===========================================================================
  1035.    
  1036.     def self.get_traits(obj)
  1037.       res = '['
  1038.       count = 1
  1039.       max_count = obj.features.size
  1040.       obj.features.each do |feat|
  1041.         res += '{"code":' + feat.code.to_s + ','
  1042.         res += '"dataId":' + feat.data_id.to_s + ','
  1043.         res += '"value":' + feat.value.to_s + '}'
  1044.         res += ',' if count < max_count
  1045.         count += 1
  1046.       end      
  1047.       res += ']'
  1048.       res
  1049.     end
  1050.    
  1051.     def self.get_effects(obj)
  1052.       res = '['
  1053.       count = 1
  1054.       max_count = obj.effects.size
  1055.       obj.effects.each do |effct|
  1056.         res += '{"code":' + effct.code.to_s + ','
  1057.         res += '"dataId":' + effct.data_id.to_s + ','
  1058.         res += '"value1":' + effct.value1.to_s + ','
  1059.         res += '"value2":' + effct.value2.to_s + '}'
  1060.         res += ',' if count < max_count
  1061.         count += 1
  1062.       end      
  1063.       res += ']'
  1064.       res
  1065.     end
  1066.    
  1067.     def self.get_damage(obj)
  1068.       dmg = obj.damage
  1069.      
  1070.       if LOGSCRIPTS && obj.damage.formula.to_i.to_s != obj.damage.formula
  1071.         sl_data = sprintf('%s %d %s: Damage Formula: %s',
  1072.           (obj.is_a?(RPG::Skill) ? 'Skill' : 'Item'), obj.id, obj.name, dmg.formula)
  1073.         @scriptlog.puts(sl_data)
  1074.       end
  1075.      
  1076.       res = '{"critical":' + dmg.critical.to_s + ','
  1077.       res += '"elementId":' + dmg.element_id.to_s + ','
  1078.       res += '"formula":"' + dmg.formula + '",'
  1079.       res += '"type":' + dmg.type.to_s + ','
  1080.       res += '"variance":' + dmg.variance.to_s + '}'
  1081.       res
  1082.     end
  1083.    
  1084.    
  1085.     #===========================================================================
  1086.     #
  1087.     # EVENT COMMANDS
  1088.     #
  1089.     #===========================================================================
  1090.    
  1091.     #===========================================================================
  1092.     # COMMAND LISTS
  1093.     #===========================================================================
  1094.    
  1095.     def self.get_command_list(list)
  1096.       res = '['
  1097.       count = 1
  1098.       max_count = list.size
  1099.       list.each do |cmd|
  1100.         @loginfo = sprintf('%s Line %d: ', @logkey, count)
  1101.        
  1102.         case cmd.code
  1103.         when 102 # show choices
  1104.           cmd.parameters[1] -= 1 # disallow cancel
  1105.           cmd.parameters[1] = -2 if cmd.parameters[1] == 4 # branch on cancel
  1106.           cmd.parameters[2] = 0 # default
  1107.           cmd.parameters[3] = 2 # window position
  1108.           cmd.parameters[4] = 0 # window background
  1109.         when 104
  1110.           cmd.parameters[1] = 2 # key item
  1111.         when 108, 408 # comment
  1112.           log_comment(cmd.parameters[0])
  1113.         when 111
  1114.           if cmd.parameters[0] == 11 # Key Pressed
  1115.             # ASD buttons are not catered for in MV.  To use these, you will
  1116.             # have to add 41 (A), 43 (S) and 44 (D) to the Input.keyMapper hash
  1117.             # in rpg_core.js:
  1118.             # Input.keyMapper[41] = 'A'
  1119.             # Input.keyMapper[53] = 'S'
  1120.             # Input.keyMapper[44] = 'D'
  1121.             case cmd.parameters[1]
  1122.             when 14
  1123.               cmd.parameters = [12, "Input.isTriggered('A')"]
  1124.             when 15
  1125.               cmd.parameters = [12, "Input.isTriggered('S')"]
  1126.             when 16
  1127.               cmd.parameters = [12, "Input.isTriggered('D')"]
  1128.             else
  1129.               cmd.parameters[1] = ['', '', 'down', '', 'left', '', 'right', '', 'up',
  1130.                 '', '', 'shift', 'cancel', 'ok', '', '', '', 'pageup', 'pagedown'][
  1131.                 cmd.parameters[1]]
  1132.             end
  1133.           elsif cmd.parameters[0] == 12 # Script
  1134.             log_script('Conditional Branch script call', cmd.parameters[1])
  1135.           end
  1136.         when 122 # Control Variables
  1137.           if cmd.parameters[3] == 4 # Script
  1138.             log_script('Control Variables script call', cmd.parameters[4])
  1139.           end
  1140.         when 231 # show picture
  1141.           if cmd.parameters[9] == 2 # subtract
  1142.             params = cmd.parameters
  1143.             cmd.code = 355
  1144.             cmd.parameters = [sprintf('$gameScreen.showPicture(%d, "%s", %d, %s, %s, %d, %d, %d, %d)',
  1145.               params[0], params[1], params[2], (params[3] == 0 ? params[4].to_s : '$gameVariables.value(' + params[4].to_s + ')'),
  1146.               (params[3] == 0 ? params[5].to_s : '$gameVariables.value(' + params[5].to_s + ')'),
  1147.               params[6], params[7], params[8], params[9])]
  1148.           end
  1149.         when 232 # move picture
  1150.           cmd.parameters[1] = 0 # not used, but can't be blank in MV
  1151.           if cmd.parameters[9] == 2 # subtract
  1152.             params = cmd.parameters
  1153.             cmd.code = 355
  1154.             cmd.parameters = [sprintf('$gameScreen.movePicture(%d, %d, %s, %s, %d, %d, %d, %d, %d)%s',
  1155.               params[0], params[2], (params[3] == 0 ? params[4].to_s : '$gameVariables.value(' + params[4].to_s + ')'),
  1156.               (params[3] == 0 ? params[5].to_s : '$gameVariables.value(' + params[5].to_s + ')'),
  1157.               params[6], params[7], params[8], params[9], params[10], params[11] ? '; this.wait(' + params[10].to_s + ')' : '')]
  1158.           end
  1159.         when 285 # get location info
  1160.           cmd.parameters[1] = 6 if cmd.parameters[1] == 5 # region id now +1
  1161.         when 319 # change equipment
  1162.           cmd.parameters[1] += 1
  1163.         when 302 # shop processing
  1164.           cmd.parameters[3] = 0 if cmd.parameters[3].nil?
  1165.         when 322 # change actor graphic
  1166.           cmd.parameters[4] = 0 # SV graphic
  1167.           cmd.parameters[5] = ''
  1168.         when 355, 655 # Script call
  1169.           log_script('Script call', cmd.parameters[0])
  1170.         when 505 # Move route
  1171.           mvrcmd = cmd.parameters[0]
  1172.           if mvrcmd.code == 45 # script
  1173.             log_script('Move Route Script call', mvrcmd.parameters[0])
  1174.           end
  1175.         end
  1176.        
  1177.         evt_cmd = '{"code":' + cmd.code.to_s + ','
  1178.         evt_cmd += '"indent":' + cmd.indent.to_s + ','
  1179.         evt_cmd += '"parameters":' + convert_parameters(cmd.parameters) + '}'
  1180.        
  1181.         #***********************************************************************
  1182.         log("      " + evt_cmd)
  1183.         #***********************************************************************
  1184.        
  1185.         res += evt_cmd
  1186.         res += ',' if count < max_count
  1187.         count += 1
  1188.       end
  1189.       res += ']'
  1190.       res
  1191.     end
  1192.    
  1193.     def self.get_move_route(mr)
  1194.       res = '{"list":['
  1195.       list = mr.list
  1196.       for x in 0 ... list.size
  1197.         cmd = list[x]
  1198.        
  1199.         case cmd.code
  1200.         when 43
  1201.           if cmd.parameters[0] == 2 then
  1202.             cmd.code = 45
  1203.             cmd.parameters = ["this.setBlendMode(2);"]
  1204.           end
  1205.         end
  1206.        
  1207.         mvr = '{"code":' + cmd.code.to_s + ','
  1208.         mvr += '"indent":null,'
  1209.         mvr += '"parameters":' + convert_parameters(cmd.parameters) + '}'
  1210.        
  1211.         #***********************************************************************
  1212.         log("        " + mvr)
  1213.         #***********************************************************************
  1214.        
  1215.         res += mvr
  1216.         res += ',' if x < list.size - 1
  1217.       end
  1218.       res += '],"repeat":' + mr.repeat.to_s + ','
  1219.       res += '"skippable":' + mr.skippable.to_s + ','
  1220.       res += '"wait":' + mr.wait.to_s + '}'
  1221.       res
  1222.     end
  1223.    
  1224.     def self.convert_parameters(params)
  1225.       res = '['
  1226.       for x in 0 ... params.size
  1227.         param = params[x]
  1228.         case param
  1229.         when RPG::MoveRoute
  1230.           param = get_move_route(param)
  1231.         when RPG::MoveCommand
  1232.           param = get_move_command(param)
  1233.         when RPG::AudioFile
  1234.           param = get_audio(param)
  1235.         when String
  1236.           param = get_text(param)
  1237.         when Symbol
  1238.           param = get_text(param.to_s)
  1239.         when Tone
  1240.           param = get_tone(param)
  1241.         when Color
  1242.           param = get_color(param)
  1243.         end
  1244.        
  1245.         res += param.to_s
  1246.         res += ',' if x < params.size - 1
  1247.       end
  1248.       res += ']'
  1249.       res
  1250.     end
  1251.          
  1252.    
  1253.     #===========================================================================
  1254.     # COMMANDS
  1255.     #===========================================================================
  1256.    
  1257.     def self.get_move_command(param)
  1258.       res = '{"code":' + param.code.to_s + ','
  1259.       res += '"indent":null,'
  1260.       res += '"parameters":' + convert_parameters(param.parameters).to_s + '}'
  1261.       res
  1262.     end
  1263.    
  1264.     #===========================================================================
  1265.     # COMMON OBJECTS
  1266.     #===========================================================================
  1267.    
  1268.     def self.get_text(text)
  1269.       if text
  1270.         '"' + text.gsub(/\\/){'\\\\'}.gsub(/[\r\n]+/){'\\n'}.gsub(/"/){'\\"'} + '"'
  1271.      else
  1272.        '""'
  1273.      end
  1274.    end
  1275.    
  1276.    def self.get_audio(a)
  1277.      a = RPG::AudioFile.new if !a
  1278.      res = '{"name":"' + a.name + '",'
  1279.      res += '"pan":0,'
  1280.      res += '"pitch":' + a.pitch.to_s + ','
  1281.      res += '"volume":' + a.volume.to_s + '}'
  1282.      res
  1283.    end      
  1284.    
  1285.    def self.get_color(color)
  1286.      res = '['
  1287.      res += color.red.to_s + ','
  1288.      res += color.green.to_s + ','
  1289.      res += color.blue.to_s + ','
  1290.      res += color.alpha.to_s
  1291.      res += ']'
  1292.      res
  1293.    end
  1294.    
  1295.    def self.get_tone(tone)
  1296.      res = '['
  1297.      res += tone.red.to_s + ','
  1298.      res += tone.green.to_s + ','
  1299.      res += tone.blue.to_s + ','
  1300.      res += tone.gray.to_s
  1301.      res += ']'
  1302.      res
  1303.    end
  1304.    
  1305.    def self.log(details)
  1306.      @log.puts(details) if LOGGING
  1307.    end
  1308.    
  1309.    def self.log_script(title, cmd)
  1310.      @scriptlog.puts(sprintf('%s - %s: %s', @loginfo, title, cmd))
  1311.    end
  1312.    
  1313.    def self.log_comment(comment)
  1314.      @commentlog.puts(sprintf('%s - Comment: %s', @loginfo, comment))
  1315.    end
  1316.  end
  1317. end
  1318.  
  1319. DEGICA::CONVERT::run
  1320. #=end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement