-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlibspellbook.py
More file actions
executable file
·72 lines (64 loc) · 1.74 KB
/
libspellbook.py
File metadata and controls
executable file
·72 lines (64 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
import random
random.seed()
# zero-level caster gets no spells, and cheap indexing
spellsbylevel=[\
[0, 0, 0, 0, 0, 0],\
[1, 0, 0, 0, 0, 0],\
[2, 0, 0, 0, 0, 0],\
[2, 1, 0, 0, 0, 0],\
[2, 2, 0, 0, 0, 0],\
[2, 2, 1, 0, 0, 0],\
[2, 2, 2, 0, 0, 0],\
[3, 2, 2, 1, 0, 0],\
[3, 3, 2, 2, 0, 0],\
[3, 3, 3, 2, 1, 0],\
[3, 3, 3, 3, 2, 0],\
[4, 3, 3, 3, 2, 1],\
[4, 4, 3, 3, 3, 2],\
[4, 4, 4, 3, 3, 2],\
[4, 4, 4, 4, 3, 3] ]
def selRandFromList(num, seq):
if num <= 0:
return []
if (num >= len(seq)):
return seq
alreadygot = []
# this implementation is awful for speed. Whooo python
for i in range(0,num):
ind = random.randint(0,len(seq)-1)
while ind in alreadygot:
ind = random.randint(0,len(seq)-1)
alreadygot.append(ind)
return map(lambda l: seq[l], alreadygot)
def parseSpells(infile):
sfdesc = open(infile, 'r')
spelllist = sfdesc.readlines()
sfdesc.close()
spelllist = filter(lambda s: not s.startswith('#'), spelllist)
spelllist = map(lambda k: k.lstrip().rstrip(), spelllist)
outlist = []
while spelllist != []:
tmp = []
spellname = spelllist.pop(0)
while spellname != "" and spelllist != []:
tmp.append(spellname)
if spelllist != []:
spellname = spelllist.pop(0)
outlist.append(tmp)
return outlist
def genSpells(slist, level, intel, excess):
out = []
for i in range(0,len(slist)):
numspells = spellsbylevel[level][i]
if numspells > 0:
numspells += intel
if excess:
numspells += random.randint(0,2)
tmp = selRandFromList(numspells,slist[i])
if tmp != []:
out.append(tmp)
return out
def printSpells(known):
for j in range(0,len(known)):
print "" + str(j+1) + ": " + ', '.join(known[j])