SHARE
TWEET

updated puppet page script

Dabomstew Dec 5th, 2015 (edited) 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3.4
  2. import re
  3. from operator import itemgetter
  4.  
  5. dataFile = open("DollData.dbs", "rb")
  6. nameFile = open("DollName.csv", "r")
  7. captionFile = open("DollCaption.csv", "r")
  8. skillFile = open("SkillData.csv", "r")
  9. abilityFile = open("AbilityData.csv", "r")
  10. skillDataFile = open("SkillData.sbs", "rb")
  11. itemFile = open("ItemData.csv", "r")
  12.  
  13. offsetTable = [0x5d, 0xc2, 0x127]
  14.  
  15. typeNames = ['None', 'Void', 'Fire', 'Water', 'Nature', 'Earth', 'Steel', 'Wind', 'Electric', 'Light', 'Dark', 'Nether', 'Poison', 'Fighting', 'Illusion', 'Sound', 'Dream']
  16.  
  17. # Each row represents the defender, and each column represents the attacker
  18. typeTable = [
  19. [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
  20. [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0],
  21. [1.0, 1.0, 0.5, 2.0, 0.5, 2.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
  22. [1.0, 1.0, 0.5, 0.5, 2.0, 1.0, 0.5, 1.0, 2.0, 0.5, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0],
  23. [1.0, 1.0, 2.0, 0.5, 0.5, 0.5, 2.0, 1.0, 0.5, 0.5, 1.0, 1.0, 2.0, 1.0, 1.0, 1.0, 1.0],
  24. [1.0, 1.0, 0.5, 2.0, 2.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.5, 2.0, 1.0, 1.0, 1.0],
  25. [1.0, 1.0, 2.0, 1.0, 1.0, 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]
  40.  
  41. expTable = ['700,000', '850,000', '1,000,000', '1,150,000', '1,300,000']
  42.  
  43. tmSkillIds = [
  44. 0, 106, 155, 206, 353, 403, 454, 603, 20, 22,
  45. 24, 107, 104, 152, 204, 201, 253, 254, 257, 303,
  46. 301, 351, 354, 355, 404, 455, 452, 504, 507, 506,
  47. 605, 553, 655, 656, 664, 666, 706, 707, 753, 34,
  48. 37, 38, 116, 111, 162, 165, 212, 213, 264, 313,
  49. 363, 405, 410, 407, 460, 511, 610, 611, 555, 670,
  50. 716, 712, 756, 41, 42, 47, 54, 121, 173, 366,
  51. 461, 462, 463, 468, 513, 518, 618, 561, 718, 762,
  52. 776, 127, 179, 233, 273, 327, 375, 421, 474, 524,
  53. 623, 566, 680, 741, 782]
  54.  
  55. baseSkillLevelOffset = [(0, 0x6e), (0, 0x70), (0, 0x72), (0, 0x74), (7, 0x21), (10, 0x23), (14, 0x25), (19, 0x27), (24, 0x29)]
  56. evolvedSkillLevelOffset = [(0, 0x11), (0, 0x13), (0, 0x15), (0, 0x17), (30, 0x19), (36, 0x1b), (42, 0x1d), (49, 0x1f), (56, 0x21), (63, 0x23), (70, 0x25)]
  57.  
  58. puppetNames = nameFile.readlines()
  59. for i in range(len(puppetNames)):
  60.     puppetNames[i] = str.strip(puppetNames[i])
  61.  
  62. puppetCaptions = captionFile.readlines()
  63. for i in range(len(puppetCaptions)):
  64.     puppetCaptions[i] = re.sub(r'\s+', ' ', ','.join(puppetCaptions[i].split(',')[2:]))
  65.    
  66. abilityNames = abilityFile.readlines()
  67. for i in range(len(abilityNames)):
  68.     abilityNames[i] = abilityNames[i].split(',')[1]
  69.    
  70. itemNames = itemFile.readlines()[1:]
  71. for i in range(len(itemNames)):
  72.     itemNames[i] = itemNames[i].split(',')[1]
  73.    
  74. #skillNames = skillFile.readlines()
  75. #for i in range(len(skillNames)):
  76. #    skillNames[i] = skillNames[i].split(',')[0]
  77.  
  78. skillSps = []
  79. skillNames = []
  80. while True:
  81.     skillData = skillDataFile.read(0x77)
  82.     if len(skillData) < 0x77:
  83.         break
  84.     skillNames.append(bytes(skillData[0:0x20])[0:bytes(skillData[0:0x20]).find(b"\x00")].decode('shift_jis').rstrip(' \t\r\n\0'))
  85.     skillSps.append(skillData[0x23])
  86.    
  87. skillNames[680] = "12th Sign - Warrior"
  88.  
  89. def getAbilityLink(ability):
  90.     #return '[[Abilities#' + ability + '|' + ability + ']]'
  91.     return '[[' + ability + ']]'
  92.    
  93. def immunityOverride(abilityName, type, typeEffectiveness, typeFootnote, typeFootnoteText, abilityn, footnoteCount):
  94.     old = typeEffectiveness[type]
  95.     typeEffectiveness[type] *= 0
  96.     typeFootnote[type] = getFootnoteTag(footnoteCount)
  97.     if abilityn == 1:
  98.         typeFootnoteText.append(typeFootnote[type] + 'Immunity due to ' + abilityName + '.')
  99.     else:
  100.         typeFootnoteText.append(typeFootnote[type] + 'Immunity only when using ' + abilityName + ". Otherwise, the modifier is '''" + '{:g}x'.format(old) + ".'''")
  101.        
  102. def getFootnoteTag(count):
  103.     if count == 0:
  104.         return '<nowiki>*</nowiki>'
  105.     return '*' * (count + 1)
  106.    
  107. def addDrop(drops, drop, value):
  108.     if drop in drops:
  109.         drops[drop] += value
  110.     else:
  111.         drops[drop] = value
  112.        
  113. def readWord(data, offset):
  114.     return (data[offset+1] << 8) + data[offset]
  115.    
  116. def makeDropsString(drops):
  117.     dropsList = [[drop, drops[drop]] for drop in drops]
  118.     dropsList = sorted(dropsList, key=itemgetter(1), reverse=True)
  119.     return ", ".join("%d%% %s" % (drop[1], drop[0]) for drop in dropsList)
  120.    
  121. speciesIndex = 0
  122. i = 0
  123. while True:
  124.     puppetData = dataFile.read(0x1F1)
  125.     if len(puppetData) < 0x1F1:
  126.         break
  127.     jpName = bytes(puppetData[0:0x20]).decode('shift_jis').rstrip(' \t\r\n\0')
  128.     cost = str(costTable[puppetData[0x20]])
  129.    
  130.     if speciesIndex > 125:
  131.         break
  132.    
  133.     for j in range(3):
  134.         offset = offsetTable[j]
  135.        
  136.         # id = str(puppetData[0x2a] << 8 + puppetData[0x29])
  137.         id = str(i)
  138.         style = styleNames[puppetData[offset]]
  139.         if style == 'None':
  140.             continue
  141.         type1 = typeNames[puppetData[offset+1]]
  142.         type2 = typeNames[puppetData[offset+2]]
  143.         typen = 2
  144.         if type2 == 'None':
  145.             typen = 1
  146.         hp = str(puppetData[offset+3])
  147.         foatk = str(puppetData[offset+4])
  148.         fodef = str(puppetData[offset+5])
  149.         spatk = str(puppetData[offset+6])
  150.         spdef = str(puppetData[offset+7])
  151.         spd = str(puppetData[offset+8])
  152.         bst = str(puppetData[offset+3] + puppetData[offset+4] + puppetData[offset+5] + puppetData[offset+6] + puppetData[offset+7] + puppetData[offset+8])
  153.         ability1Id = readWord(puppetData, offset+9)
  154.         ability2Id = readWord(puppetData, offset+11)
  155.         ability1 = abilityNames[ability1Id]
  156.         ability2 = abilityNames[ability2Id]
  157.         abilityn = 2
  158.         if ability2Id == 0:
  159.             abilityn = 1
  160.             ability2 = 'None'
  161.            
  162.         # Drop Table
  163.         drops = {}
  164.         addDrop(drops, itemNames[readWord(puppetData, 0x2B)], 80)
  165.         addDrop(drops, itemNames[readWord(puppetData, 0x2D)], 20)
  166.         dropslow = makeDropsString(drops)
  167.         for drop in drops:
  168.             drops[drop] //= 2
  169.         addDrop(drops, itemNames[readWord(puppetData, 0x2F)], 40)
  170.         addDrop(drops, itemNames[readWord(puppetData, 0x31)], 10)
  171.         dropshigh = makeDropsString(drops)
  172.        
  173.         # Style Changes
  174.         styleChanges = []
  175.         for k in range(3):
  176.             if k != j:
  177.                 styleChanges.append('[[' + styleNames[puppetData[offsetTable[k]]] + ' ' + puppetNames[speciesIndex] + ']]')
  178.                
  179.        
  180.        
  181.         outputFile = open('dollPages\\' + style + ' ' + puppetNames[speciesIndex] + '.txt', 'w')
  182.        
  183.         # InfoBox
  184.         outputFile.write('\n'.join([
  185.         '{{InfoBox', '|name=' + style + ' ' + puppetNames[speciesIndex],
  186.         '|jname=' + jpName,
  187.         '|imagename=' + puppetNames[speciesIndex],
  188.         '|typen=' + str(typen),
  189.         '|type1=' + type1,
  190.         '']))
  191.         if typen == 2:
  192.             outputFile.write('|type2=' + type2 + '\n')
  193.         outputFile.write('\n'.join([
  194.         '|dexnum=' + str(i),
  195.         '|cost=' + cost,
  196.         '|abilityn=' + str(abilityn),
  197.         '|ability1=' + getAbilityLink(ability1),
  198.         '']))
  199.         if abilityn == 2:
  200.             outputFile.write('|ability2=' + getAbilityLink(ability2) + '\n')
  201.         outputFile.write('\n'.join([
  202.         '|lv100exp=' + expTable[puppetData[0x20]],
  203.         '|style1=' + styleChanges[0],
  204.         '|style2=' + styleChanges[1],
  205.         '|lowdrops=' + dropslow,
  206.         '|highdrops=' + dropshigh,
  207.         '}}\n']))
  208.        
  209.         # Dex Entry and Base Stats
  210.         outputFile.write('\n'.join([
  211.         '{| border="0"',
  212.         '|-', '| colspan="2" |',
  213.         '{| class="wikitable" border="1" cellpadding="2" style="border-collapse: collapse; width: 556px;"',
  214.         '|-',
  215.         '! scope="row" style="width: 54px;" | Dex Entry',
  216.         '| ' + puppetCaptions[speciesIndex],
  217.         '|}',
  218.         '|-',
  219.         '| colspan="2" |',
  220.         '{| class="wikitable" border="1" cellpadding="2" style="border-collapse: collapse; width: 556px;"',
  221.         '|-',
  222.         '! scope="col" style="width: 79px;" | HP',
  223.         '! scope="col" style="width: 79px;" | Fo.Att.',
  224.         '! scope="col" style="width: 79px;" | Fo.Def.',
  225.         '! scope="col" style="width: 79px;" | Sp.Att.',
  226.         '! scope="col" style="width: 79px;" | Sp.Def.',
  227.         '! scope="col" style="width: 79px;" | Speed',
  228.         '! scope="col" style="width: 82px;" | Total',
  229.         '|-',
  230.         '| style="text-align: center;" | ' + hp,
  231.         '| style="text-align: center;" | ' + foatk,
  232.         '| style="text-align: center;" | ' + fodef,
  233.         '| style="text-align: center;" | ' + spatk,
  234.         '| style="text-align: center;" | ' + spdef,
  235.         '| style="text-align: center;" | ' + spd,
  236.         '| style="text-align: center;" | ' + bst,
  237.         '|}\n']))
  238.        
  239.         # Type Effectiveness
  240.         outputFile.write('{{TypeEffectiveness\n')
  241.         if typen == 1:
  242.             typeEffectiveness = list(typeTable[puppetData[offset+1]])
  243.         else:
  244.             typeEffectiveness = []
  245.             for k in range(17):
  246.                 typeEffectiveness.append(typeTable[puppetData[offset+1]][k] * typeTable[puppetData[offset+2]][k])
  247.         typeFootnote = [''] * 17
  248.         typeFootnoteText = []
  249.         footnoteCount = 0
  250.         if ability1Id == 120 or ability2Id == 120:
  251.             oldLight = typeEffectiveness[9]
  252.             oldDark = typeEffectiveness[10]
  253.             typeEffectiveness[9] *= 1.25
  254.             typeEffectiveness[10] *= 0
  255.             typeFootnote[9] = getFootnoteTag(footnoteCount)
  256.             typeFootnote[10] = getFootnoteTag(footnoteCount)
  257.             footnoteCount += 1
  258.             if typeEffectiveness[9] >= 2.01:
  259.                 word = 'Stronger weakness'
  260.             elif typeEffectiveness[9] >= 1.01:
  261.                 word = 'Weakness'
  262.             else:
  263.                 word = 'Reduced resistance'
  264.             if abilityn == 1:
  265.                 typeFootnoteText.append(typeFootnote[9] + word + ' and immunity due to ' + getAbilityLink(abilityNames[120]) + '.')
  266.             else:
  267.                 typeFootnoteText.append(typeFootnote[10] + word + ' and immunity only when using ' + getAbilityLink(abilityNames[120]) + ". Otherwise, the modifiers are '''" + '{:g}x'.format(oldLight) + "''' (Light) and '''" + '{:g}x'.format(oldDark) + "''' (Dark).")
  268.         for k in range(138, 152):
  269.             if ability1Id == k or ability2Id == k:
  270.                 immunityOverride(abilityNames[k], k - 136, typeEffectiveness, typeFootnote, typeFootnoteText, abilityn, footnoteCount)
  271.                 footnoteCount += 1
  272.         if ability1Id == 155 or ability2Id == 155:
  273.             oldLight = typeEffectiveness[9]
  274.             oldDark = typeEffectiveness[10]
  275.             typeEffectiveness[9] /= 2
  276.             typeEffectiveness[10] /= 2
  277.             typeFootnote[9] = getFootnoteTag(footnoteCount)
  278.             typeFootnote[10] = getFootnoteTag(footnoteCount)
  279.             footnoteCount += 1
  280.             if typeEffectiveness[9] >= 0.99 and typeEffectiveness[9] <= 1.01:
  281.                 if typeEffectiveness[10] >= 0.99 and typeEffectiveness[10] <= 1.01:
  282.                     prefix = "Neutralities"
  283.                 else:
  284.                     prefix = "Neutrality and resistance"
  285.             elif typeEffectiveness[10] >= 0.99 and typeEffectiveness[10] <= 1.01:
  286.                 prefix = "Resistance and neutrality"
  287.             else:
  288.                 prefix = "Resistances"
  289.             if abilityn == 1:
  290.                 typeFootnoteText.append(typeFootnote[9] + prefix + ' due to ' + getAbilityLink(abilityNames[155]) + '.')
  291.             else:
  292.                 typeFootnoteText.append(typeFootnote[10] + prefix + ' only when using ' + getAbilityLink(abilityNames[155]) + ". Otherwise, the modifiers are '''" + '{:g}x'.format(oldLight) + "''' (Light) and '''" + '{:g}x'.format(oldDark) + "''' (Dark).")
  293.         if ability1Id == 313 or ability2Id == 313:
  294.             footnote = getFootnoteTag(footnoteCount)
  295.             footnoteCount += 1
  296.             for k in range(1, 17):
  297.                 if typeEffectiveness[k] > 0.24 and typeEffectiveness[k] < 1.01:
  298.                     typeEffectiveness[k] = 0
  299.                     typeFootnote[k] = footnote
  300.             if abilityn == 1:
  301.                 typeFootnoteText.append(footnote + 'Immunities due to ' + getAbilityLink(abilityNames[313]) + '.')
  302.             else:
  303.                 typeFootnoteText.append(footnote + 'Immunities only when using ' + getAbilityLink(abilityNames[313]) + '.')
  304.        
  305.         for k in range(1, 17):
  306.             if typeEffectiveness[k] < 0.99 or typeEffectiveness[k] > 1.01 or typeFootnote[k] != '':
  307.                 outputFile.write('|' + typeNames[k].lower() + '=' + '{:g}x'.format(typeEffectiveness[k]) + typeFootnote[k] + '\n')
  308.        
  309.         outputFile.write('}}\n')
  310.        
  311.         for k in range(len(typeFootnoteText)):
  312.             outputFile.write('<small>' + typeFootnoteText[k] + '</small><br/>\n')
  313.        
  314.         # Level up moves
  315.         outputFile.write('\n'.join([
  316.         '|-',
  317.         '| style="vertical-align: top;" |',
  318.         '{| class="wikitable" border="1" cellpadding="2" style="border-collapse: collapse;"',
  319.         '|+ Level Up Moves',
  320.         '|-',
  321.         '! scope="col" style="width: 48px;" | Lv',
  322.         '! scope="col" style="width: 164px;" | Move',
  323.         '! scope="col" style="width: 48px;" | PP',
  324.         '|-\n']))
  325.        
  326.         for k in range(4):
  327.             skillId = readWord(puppetData, baseSkillLevelOffset[k][1])
  328.             pp = min(int((baseSkillLevelOffset[k][0] / 2 + 50) * 2 / skillSps[skillId]), 99)
  329.             if skillId != 0:
  330.                 outputFile.write('\n'.join([
  331.                 '| style="text-align:center" | -',
  332.                 '| [[' + skillNames[skillId] + ']]',
  333.                 '| style="text-align:center" | ' + str(pp),
  334.                 '|-\n']))
  335.        
  336.         if style != 'Normal':
  337.             for k in range(4):
  338.                 skillId = readWord(puppetData, evolvedSkillLevelOffset[k][1] + offset)
  339.                 pp = min(int((evolvedSkillLevelOffset[k][0] / 2 + 50) * 2 / skillSps[skillId]), 99)
  340.                 if skillId != 0:
  341.                     outputFile.write('\n'.join([
  342.                     '| style="text-align:center" | -',
  343.                     '| [[' + skillNames[skillId] + ']]',
  344.                     '| style="text-align:center" | ' + str(pp),
  345.                     '|-\n']))
  346.        
  347.         for k in range(4, len(baseSkillLevelOffset)):
  348.             skillId = readWord(puppetData, baseSkillLevelOffset[k][1])
  349.             pp = min(int((baseSkillLevelOffset[k][0] / 2 + 50) * 2 / skillSps[skillId]), 99)
  350.             if skillId != 0:
  351.                 outputFile.write('\n'.join([
  352.                 '| style="text-align:center" | ' + str(baseSkillLevelOffset[k][0]),
  353.                 '| [[' + skillNames[skillId] + ']]',
  354.                 '| style="text-align:center" | ' + str(pp),
  355.                 '|-\n']))
  356.        
  357.         if style != 'Normal':
  358.             for k in range(4, len(evolvedSkillLevelOffset)):
  359.                 skillId = readWord(puppetData, evolvedSkillLevelOffset[k][1] + offset)
  360.                 pp = min(int((evolvedSkillLevelOffset[k][0] / 2 + 50) * 2 / skillSps[skillId]), 99)
  361.                 if skillId != 0:
  362.                     outputFile.write('\n'.join([
  363.                     '| style="text-align:center" | ' + str(evolvedSkillLevelOffset[k][0]),
  364.                     '| [[' + skillNames[skillId] + ']]',
  365.                     '| style="text-align:center" | ' + str(pp),
  366.                     '|-\n']))
  367.                    
  368.         outputFile.write('|}\n')
  369.        
  370.         # Skillcard moves
  371.         outputFile.write('\n'.join([
  372.         '| style="vertical-align: top;" |',
  373.         '{| class="wikitable" border="1" cellpadding="2" style="border-collapse: collapse;"',
  374.         '|+ Skill Cards',
  375.         '|-',
  376.         '! scope="col" style="width: 48px;" | SC',
  377.         '! scope="col" style="width: 208px;" | Skill',
  378.         '|-\n']))
  379.        
  380.         for k in range(1, 95):
  381.             byteIndex = int((k - 1) / 8) + 0x31 + offset
  382.             bitIndex = (k - 1) % 8
  383.             if (puppetData[byteIndex] >> bitIndex) & 1 == 1:
  384.                 outputFile.write('\n'.join([
  385.                 '| style="text-align:center;" | #' + str(k),
  386.                 '| [[' + skillNames[tmSkillIds[k]] + ']]',
  387.                 '|-\n']))
  388.            
  389.         # Page footer
  390.         outputFile.write('\n'.join([
  391.         '|}',
  392.         '|-',
  393.         '|}',
  394.         '']))
  395.        
  396.         outputFile.close()
  397.        
  398.         i += 1
  399.    
  400.     speciesIndex += 1
  401.  
  402. dataFile.close()
  403. nameFile.close()
  404. abilityFile.close()
  405. captionFile.close()
  406. skillFile.close()
  407. skillDataFile.close()
  408. itemFile.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top