171
|
1 from orpg.dieroller.base import die_base, die_rollers
|
|
2
|
|
3 class std(die_base):
|
|
4 name = "std"
|
|
5
|
212
|
6 def __init__(self, source=[]):
|
|
7 die_base.__init__(self, source)
|
171
|
8
|
|
9 # Examples of adding member functions through inheritance.
|
|
10
|
|
11 def ascending(self):
|
|
12 result = self[:]
|
|
13 result.sort()
|
|
14 return result
|
|
15
|
|
16 def descending(self):
|
|
17 result = self[:]
|
|
18 result.sort()
|
|
19 result.reverse()
|
|
20 return result
|
|
21
|
212
|
22 def takeHighest(self, num_dice):
|
171
|
23 return self.descending()[:num_dice]
|
|
24
|
|
25 def takeLowest(self,num_dice):
|
|
26 return self.ascending()[:num_dice]
|
|
27
|
212
|
28 def extra(self, num):
|
171
|
29 for i in range(len(self.data)):
|
|
30 if self.data[i].lastroll() >= num:
|
|
31 self.data[i].extraroll()
|
|
32 return self
|
|
33
|
212
|
34 def open(self, num):
|
|
35 if num <= 1: self
|
171
|
36 done = 1
|
|
37 for i in range(len(self.data)):
|
|
38 if self.data[i].lastroll() >= num:
|
|
39 self.data[i].extraroll()
|
|
40 done = 0
|
236
|
41 if done: print self; return self
|
212
|
42 else: return self.open(num)
|
171
|
43
|
|
44 def minroll(self,min):
|
|
45 for i in range(len(self.data)):
|
|
46 if self.data[i].lastroll() < min:
|
|
47 self.data[i].roll(min)
|
|
48 return self
|
|
49
|
212
|
50 def each(self, mod):
|
171
|
51 mod = int(mod)
|
|
52 for i in range(len(self.data)):
|
|
53 self.data[i].modify(mod)
|
|
54 return self
|
|
55
|
|
56 def vs(self, target):
|
|
57 for dn in self.data:
|
|
58 dn.target = target
|
|
59 return self
|
|
60
|
|
61
|
|
62 ## If we are testing against a saving throw, we check for
|
|
63 ## greater than or equal to against the target value and
|
|
64 ## we only return the number of successful saves. A negative
|
|
65 ## value will never be generated.
|
|
66 def sum(self):
|
|
67 retValue = 0
|
|
68 for dn in self.data:
|
|
69 setValue = reduce( lambda x, y : int(x)+int(y), dn.history )
|
|
70 if dn.target:
|
212
|
71 for dv in dn.history:
|
|
72 if int(dv) >= dn.target: retValue += 1
|
171
|
73 else:
|
|
74 retValue += setValue
|
|
75 return retValue
|
|
76
|
184
|
77 die_rollers.register(std)
|