Advertisement
Guest User

Untitled

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