Commit code, circa 2010
This commit is contained in:
59
spellbook.py
Executable file
59
spellbook.py
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/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)
|
||||
Reference in New Issue
Block a user