Advertisement
Krazplay

FFBE WotV parsing skills Ruby

Apr 26th, 2020
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.32 KB | None | 0 0
  1. require "json"
  2.  
  3. # Getting skill names
  4. file = open("SkillName.json")
  5. json = file.read
  6. skillNames = JSON.parse(json)
  7. tabSkillNames = {}
  8. skillNames["infos"].each do |info|
  9.     tabSkillNames[info["key"]] = info["value"]
  10. end
  11.  
  12. # Getting skill descriptions
  13. file = open("SkillExpr.json")
  14. json = file.read
  15. skiExpr = JSON.parse(json)
  16. tabExpr = {}
  17. skiExpr["infos"].each do |info|
  18.     tabExpr[info["key"]] = info["value"]
  19. end
  20.  
  21. # Getting skills data
  22. file = open("Skill.json")
  23. json = file.read
  24. skills = JSON.parse(json)
  25. hash_skills = {}
  26. skills["items"].each do |item|
  27.     hash_skills["#{item["iname"]}"] = item
  28. end
  29.  
  30. # USELESS, no skill buff has a name
  31. # Getting buff names
  32. file = open("BuffName.json")
  33. json = file.read
  34. buffNames = JSON.parse(json)
  35. tabBuffNames = {}
  36. buffNames["infos"].each do |info|
  37.     tabBuffNames[info["key"]] = info["value"]
  38. end
  39.  
  40. # Getting buffs data
  41. file = open("Buff.json")
  42. json = file.read
  43. buffs = JSON.parse(json)
  44. hash_buffs = {}
  45. buffs["items"].each do |item|
  46.     hash_buffs["#{item["iname"]}"] = item
  47. end
  48.  
  49. # Getting unit names
  50. file = open("UnitName.json")
  51. json = file.read
  52. unitNames = JSON.parse(json)
  53. tabUnitNames = {}
  54. unitNames["infos"].each do |info|
  55.     tabUnitNames[info["key"]] = info["value"]
  56. end
  57.  
  58. # Buffs use a type and not a direct stat, this is annoying
  59. typebuff = []
  60. typebuff[1] = "Max HP"
  61. typebuff[21] = "ATK"
  62. typebuff[22] = "DEF"
  63. typebuff[23] = "MAG"
  64. typebuff[24] = "SPR"
  65. typebuff[25] = "DEX?"
  66. typebuff[26] = "AGI"
  67. typebuff[28] = "Move"
  68. typebuff[29] = "Jump"
  69. typebuff[88] = "Paralysis"
  70. typebuff[89] = "Confusion"
  71. typebuff[90] = "Charm"
  72. typebuff[92] = "Toad"
  73. typebuff[95] = "Haste"
  74. typebuff[96] = "Slow"
  75. typebuff[97] = "Stop"
  76. typebuff[98] = "Stun"
  77. typebuff[99] = "Immobilize"
  78. typebuff[100] = "Disable"
  79. typebuff[101] = "Berserk"
  80. typebuff[102] = "Doom"
  81. typebuff[105] = "Protect"
  82. typebuff[106] = "Shell"
  83. typebuff[112] = "Quicken"
  84. typebuff[156] = "Eva"
  85. typebuff[158] = "CRIT"
  86. typebuff[180] = "Hate"
  87. typebuff[181] = "Brave"
  88. typebuff[182] = "Faith (perma)"
  89. typebuff[193] = "Faith (temp)"
  90.  
  91. descr= {"eff_val"=>" (L1)", "eff_val1" => " (L20)", "val1"=>" (L1)", "val11"=>" (L20)",
  92. "val2"=>" (L1)", "val21"=>" (L20)", "type1" => " (type)", "type2" => " (type2)", "eff_rate" => "% (L1)",
  93. "eff_rate1" => "% (L20)", "turn" => " turns", "ct_spd"=>" (CastSpd)", "ct_spd1"=>" (CSpdL20)", "rate"=>"%"}
  94.  
  95. # Opening main files
  96. file = open("UnitAbilityBoard.json")
  97. json = file.read
  98. uab_json = JSON.parse(json)
  99.  
  100. # Main loop: looping on all items (characters) in the json
  101. uab_json["items"].each do |item|
  102.     # Name + iname
  103.     puts ""
  104.     puts ""
  105.     puts "#{tabUnitNames[item["iname"]]};;;;#{item["iname"]}"
  106.     # We may want to sort the skills before printing
  107.     sk_char= []
  108.    
  109.     # Now looping on all the panels in the board
  110.     item["panels"].each do |panel|
  111.         # We're looking only for skill panels
  112.         if panel["panel_effect_type"] == 1
  113.             # I'm linking the panel to the skill, it may have useful info
  114.             hash_skills["#{panel["value"]}"]["panel"] = panel
  115.             # Pushing to array with every skills we want to print:
  116.             sk_char.push(hash_skills["#{panel["value"]}"])
  117.         end
  118.     end
  119.    
  120.     # Sorting by job
  121.     sk_char.sort_by! { |hash| [hash["panel"]["applicable_job"], hash["panel"]["panel_id"]]  }
  122.    
  123.     # Now the printing part
  124.     sk_char.each do |skill|
  125.         # Skill job
  126.         string = ";#{skill["panel"]["applicable_job"]};"
  127.         # Skill name
  128.         string += "#{tabSkillNames[skill["iname"]]};"
  129.         # Well, I think it's more understandable with the base 100%
  130.         for imp in ["eff_val","eff_val1"]
  131.             val = 100 + skill[imp] if skill[imp] != nil
  132.             string += "#{val}#{descr[imp]}" if skill[imp] != nil
  133.             string += ";"
  134.         end
  135.         # important values, have their own private cell
  136.         for imp in ["eff_rate","eff_rate1", "ct_spd", "ct_spd1"]
  137.             string += "#{skill[imp]}#{descr[imp]}" if skill[imp] != nil
  138.             string += ";"
  139.         end
  140.         # skill description + raw panel data
  141.         string += ";#{tabExpr[skill["iname"]]};;;;#{skill["panel"]};"
  142.         # A cell with all the raw skill data (removed panel for readability)
  143.         skill["panel"] = nil
  144.         string += "#{skill};"
  145.         puts string
  146.        
  147.        
  148.         # The skill may have BUFFs
  149.         if skill["s_buffs"] != nil or skill["t_buffs"] != nil
  150.             # concatenate 2 arrays (both can contain buffs), need to be sure not to have nil first
  151.             skill["s_buffs"] = [] if skill["s_buffs"] == nil
  152.             skill["t_buffs"] = [] if skill["t_buffs"] == nil
  153.             buffs = skill["s_buffs"] | skill["t_buffs"]
  154.             # Loop on all the buffs (iterate on both arrays)
  155.             buffs.each do |buff_id|
  156.                 bstring = ";;;;"
  157.                 # Name of the buff, if available -there is never a buff name for skills-
  158.                 bstring += tabBuffNames[buff_id] != "" ? "#{tabBuffNames[buff_id]};" : "Buff;"
  159.                 # important values, have their own private cell
  160.                 for imp in ["rate", "turn","type1","val1","val11","type2","val2","val21"]
  161.                     value = hash_buffs[buff_id][imp]
  162.                     # If the buff use this parameter, print value
  163.                     if value != nil
  164.                         # Must do a special case for those
  165.                         if ["type1", "type2"].include?(imp) and typebuff[value] != nil
  166.                                 value = typebuff[value] if value != nil and typebuff[value] != nil
  167.                                 bstring += "#{value}"
  168.                         else
  169.                             # value + description
  170.                             bstring += "#{value}#{descr[imp]}"
  171.                         end
  172.                     end
  173.                     bstring += ";"
  174.                 end
  175.                 # raw data of the buff
  176.                 bstring += ";#{hash_buffs[buff_id]};"
  177.                 puts bstring
  178.             end
  179.         end
  180.     end
  181. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement