queryfeats.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/usr/bin/env python3
  2. import pickle
  3. import pprint
  4. import re
  5. charsheet = {
  6. 'bab': 9,
  7. 'str': 20,
  8. 'dex': 14,
  9. 'con': 14,
  10. 'int': 14,
  11. 'wis': 10,
  12. 'cha': 10,
  13. 'level': [
  14. ('fighter', 9)
  15. ],
  16. 'feat': [
  17. 'toughness',
  18. 'armor proficiency, medium',
  19. 'power attack',
  20. 'combat stamina',
  21. 'improved unarmed strike',
  22. 'combat expertise',
  23. 'point blank shot',
  24. 'deadly aim',
  25. 'improved bull rush',
  26. 'improved overrun',
  27. 'improved trip',
  28. 'weapon focus',
  29. 'weapon focus with chosen weapon',
  30. 'weapon focus (greataxe)',
  31. 'weapon focus (glaive)',
  32. 'weapon focus with chosen melee weapon',
  33. 'weapon focus with selected weapon',
  34. 'weapon focus with the chosen weapon',
  35. 'weapon focus (any two-handed reach weapon)',
  36. 'weapon specialization',
  37. 'weapon specialization with selected weapon',
  38. 'improved critical',
  39. 'armor focus',
  40. 'proficiency with selected armor',
  41. 'medium armor proficiency',
  42. 'light armor proficiency',
  43. 'proficiency with light armor',
  44. 'proficiency with medium armor',
  45. 'armor training class feature',
  46. 'armor trainingclass feature',
  47. 'martial focus',
  48. 'weapon training class feature',
  49. 'combat reflexes',
  50. ],
  51. 'skill': [
  52. ('knowledge (arcane)', 9),
  53. ('knowledge (dungeoneering)', 9),
  54. ('knowledge (local)', 9),
  55. ('knowledge (nature)', 9),
  56. ('knowledge (planes)', 9),
  57. ('knowledge (religion)', 9),
  58. ('knowledge (engineering)', 1),
  59. ('knowledge (geography)', 2),
  60. ('knowledge (history)', 4),
  61. ('acrobatics', 9),
  62. ('climb', 3),
  63. ('atealth', 1),
  64. ('disable device', 1),
  65. ('spellcraft', 1),
  66. ('intimidate', 1),
  67. ('use magic device', 1),
  68. ('diplomacy', 1),
  69. ('perception', 1),
  70. ('linguistics', 4),
  71. ('lore (divine battles)', 4),
  72. ('art (anatomy)', 1),
  73. ('perform (oratory)', 2),
  74. ],
  75. }
  76. with open('feats.pickle', 'rb') as f:
  77. allfeats = pickle.load(f)
  78. def texify(textstr):
  79. textstr = re.sub(r'—', '\textemdash', textstr)
  80. textstr = re.sub(r'"', "''", textstr)
  81. return textstr
  82. def grabfeat(feats, featname):
  83. for f in feats:
  84. if f['name'].lower() == featname.lower():
  85. return f
  86. def fillsreqs(pr, charsheet):
  87. qual = True
  88. for attr in ['str', 'dex', 'con', 'int', 'wis', 'cha', 'bab']:
  89. if attr in pr:
  90. if int(pr[attr]) > charsheet[attr]:
  91. qual = False
  92. if 'level' in pr:
  93. for l in pr['level']:
  94. print(l)
  95. llqual = False
  96. for ll in charsheet['level']:
  97. print(ll)
  98. if l[0] == ll[0] and int(l[1]) <= ll[1]:
  99. llqual = True
  100. break
  101. if llqual == False:
  102. qual = False
  103. break
  104. if 'skill' in pr:
  105. for s in pr['skill']:
  106. squal = False
  107. for cs in charsheet['skill']:
  108. if s[0] == cs[0] and int(s[1]) <= cs[1]:
  109. csqual = True
  110. break
  111. if csqual == False:
  112. qual = False
  113. break
  114. return qual
  115. def qualfeat(feat, charsheet):
  116. if feat['prereqs']:
  117. return fillsreqs(feat['prereqs'], charsheet)
  118. else:
  119. return True
  120. def qualfeats(feats, charsheet):
  121. return [f for f in feats if qualfeat(f, charsheet)]
  122. def prefeats(feats):
  123. for f in allfeats:
  124. prefeats = {}
  125. fs = f['prereqs']['feat']
  126. if isinstance(fs, list):
  127. for pf in fs:
  128. if pf in prefeats:
  129. prefeats[pf] += 1
  130. else:
  131. prefeats[pf] = 1
  132. else:
  133. if fs in prefeats:
  134. prefeats[fs] += 1
  135. else:
  136. prefeats[fs] = 1
  137. return prefeats
  138. def asfeat(feat):
  139. featsnip = '\subsubsection*{%s}\n\n' % feat['name']
  140. featsnip += '\\textbf{Benefit:} %s\n\n' % feat['benefit']
  141. if feat['trick']:
  142. featsnip += '\\textbf{Combat Trick:} %s\n\n' % feat['trick']
  143. if feat['special']:
  144. featsnip += '\\textbf{Special:} %s\n\n' % feat['special']
  145. return featsnip
  146. def aschainfeat(feat):
  147. featsnip = '\item \\textbf{%s} %s\n\n' % (feat['name'], feat['benefit'])
  148. if feat['trick']:
  149. featsnip += '\\textbf{Combat Trick:} %s\n\n' % feat['trick']
  150. if feat['special']:
  151. featsnip += '\\textbf{Special:} %s\n\n' % feat['special']
  152. return featsnip
  153. def chainfeats(feats):
  154. chainsnip = '\begin{itemize}\n\n'
  155. for f in feats:
  156. chainsnip += aschainfeat(f)
  157. chainsnip += '\end{itemize}'
  158. return chainsnip
  159. if __name__ == '__main__':
  160. sectsnip = ''
  161. for f in sorted(charsheet['feat']):
  162. ff = grabfeat(allfeats, f)
  163. if ff:
  164. sectsnip += asfeat(ff)
  165. print(sectsnip)
  166. sectsnip = ''
  167. # for f in allfeats:
  168. # if 'skill' in f['prereqs']:
  169. # pprint.pprint(f['prereqs']['skill'])
  170. # outfeats = sorted(prefeats, key=lambda x: prefeats[x])
  171. # for of in outfeats:
  172. # print("%s, %s" % (of, prefeats[of]))