This repository has been archived on 2026-05-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
dnd-utils/spellbook.py

60 lines
2.0 KiB
Python
Raw Normal View History

2026-05-18 12:28:52 -04:00
#!/usr/bin/python
import sys
import random
def main(argc, argv):
if ( argc < 2 ):
print "usage: spellbook <max_spell_level> <total_spells>"
print " pass =max_spell_level to generate total_spells all of"
print " level (max_spell_level). You can also pass =[x,x] to"
print " pass a list of spell levels."
return 1
minlevel = 1
tlist = None
if ( "=" in argv[1]):
if ( "," in argv[1]):
tlist = argv[1].strip("=").strip("[").strip("]").split(",")
for i in range(0, len(tlist)):
tlist[i] = int(tlist[i])
else:
tmp = argv[1].strip("=").strip()
minlevel = int(tmp)
maxlevel = int(tmp)
#print "Min level : %d Max level : %d" % (minlevel, maxlevel)
else:
maxlevel = int(argv[1])
total = int(argv[2])
PHBSpells = { 1: 30, 2: 24, 3: 34, 4: 24, 5: 24, 6: 24, 7: 16, 8: 16, 9: 12}
choices = [True, False]
spellLevels = {}
if ( tlist ) :
for i in range(0, total):
level = random.choice(tlist)
snum = random.choice(range(1, PHBSpells[level]+1))
if ( spellLevels.has_key(level)):
spellLevels[level].append(snum)
else:
spellLevels[level] = []
spellLevels[level].append(snum)
else:
for i in range(0, total):
#if ( random.choice(choices) ):
level = random.choice(range(minlevel, maxlevel+1))
snum = random.choice(range(1, PHBSpells[level]+1))
if ( spellLevels.has_key(level) ):
spellLevels[level].append(snum)
else:
spellLevels[level] = []
spellLevels[level].append(snum)
for i in range(1, 10):
if ( spellLevels.has_key(i) ):
spells = spellLevels[i]
spells.sort()
print "LEVEL %d : %s" % (i, str(spells))
if ( __name__ == "__main__" ):
main(len(sys.argv), sys.argv)