comparison orpg/dieroller/srex.py @ 71:449a8900f9ac ornery-dev

Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author sirebral
date Thu, 20 Aug 2009 03:00:39 -0500
parents 4385a7d0efd1
children bf799efe7a8a
comparison
equal deleted inserted replaced
70:52a5fa913008 71:449a8900f9ac
57 from die import * 57 from die import *
58 58
59 __version__ = "1.1" 59 __version__ = "1.1"
60 60
61 class srex(std): 61 class srex(std):
62
62 def __init__(self,source=[]): 63 def __init__(self,source=[]):
63 std.__init__(self,source) 64 std.__init__(self,source)
64 65
66
65 def vs(self,actualtarget=4,tnrange=3): #reports all tns around specified, max distance of range 67 def vs(self,actualtarget=4,tnrange=3): #reports all tns around specified, max distance of range
66 return srVs(self,actualtarget,(actualtarget-tnrange),(actualtarget+tnrange)) 68 return srVs(self,actualtarget,(actualtarget-tnrange),(actualtarget+tnrange))
67 69
70
68 def vswide(self,actualtarget=4,maxtarget=12): #wide simply means it reports TNs from 2 to a specified max. 71 def vswide(self,actualtarget=4,maxtarget=12): #wide simply means it reports TNs from 2 to a specified max.
69 return srVs(self,actualtarget,2,maxtarget) 72 return srVs(self,actualtarget,2,maxtarget)
70 73
74
71 def open(self): #unchanged from standard shadowrun open. 75 def open(self): #unchanged from standard shadowrun open.
72 return srOpen(self) 76 return srOpen(self)
73 77
74 class srVs(std): 78 class srVs(std):
79
75 def __init__(self,source=[],actualtarget=4,mintn=2,maxtn=12): 80 def __init__(self,source=[],actualtarget=4,mintn=2,maxtn=12):
76 std.__init__(self, source) 81 std.__init__(self, source)
77 if actualtarget > 30: 82 if actualtarget > 30:
78 actualtarget = 30 83 actualtarget = 30
79 if mintn > 30: 84 if mintn > 30:
98 103
99 # Shadowrun was built to use the d6 but in the interests of experimentation I have 104 # Shadowrun was built to use the d6 but in the interests of experimentation I have
100 # made the dieroller generic enough to use any die type 105 # made the dieroller generic enough to use any die type
101 self.openended(self[0].sides) 106 self.openended(self[0].sides)
102 107
108
103 def openended(self,num): 109 def openended(self,num):
104 if num <= 1: 110 if num <= 1:
105 self 111 self
106 done = 1 112 done = 1
107 113
114 return self 120 return self
115 else: 121 else:
116 return self.openended(num) 122 return self.openended(num)
117 123
118 #count successes, by looping through each die, and checking it against the currently set TN 124 #count successes, by looping through each die, and checking it against the currently set TN
125
119 def __sum__(self): 126 def __sum__(self):
120 s = 0 127 s = 0
121 for r in self.data: 128 for r in self.data:
122 if r >= self.target: 129 if r >= self.target:
123 s += 1 130 s += 1
124 return s 131 return s
125 132
126 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through 133 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through
127 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could 134 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could
128 #easily be lost. 135 #easily be lost.
136
129 def xsum(self,curtarget): 137 def xsum(self,curtarget):
130 s = 0 138 s = 0
131 for r in self.data: 139 for r in self.data:
132 if r >= curtarget: 140 if r >= curtarget:
133 s += 1 141 s += 1
134 return s 142 return s
135 143
136 144
145
137 def __str__(self): 146 def __str__(self):
138 if len(self.data) > 0: 147 if len(self.data) > 0:
139 myStr = "[" + str(self.data[0]) 148 myStr = "[" + str(self.data[0])
140 for a in self.data[1:]: 149 for a in self.data[1:]:
141 myStr += "," 150 myStr += ","
152 myStr = "[] = (0)" 161 myStr = "[] = (0)"
153 162
154 return myStr 163 return myStr
155 164
156 class srOpen(std): 165 class srOpen(std):
166
157 def __init__(self,source=[]): 167 def __init__(self,source=[]):
158 std.__init__(self,source) 168 std.__init__(self,source)
159 self.openended(self[0].sides) 169 self.openended(self[0].sides)
160 170
171
161 def openended(self,num): 172 def openended(self,num):
162 if num <= 1: 173 if num <= 1:
163 self 174 self
164 done = 1 175 done = 1
165 for i in range(len(self.data)): 176 for i in range(len(self.data)):
169 if done: 180 if done:
170 return self 181 return self
171 else: 182 else:
172 return self.openended(num) 183 return self.openended(num)
173 184
185
174 def __sum__(self): 186 def __sum__(self):
175 s = 0 187 s = 0
176 for r in self.data: 188 for r in self.data:
177 if r > s: 189 if r > s:
178 s = r 190 s = r
179 return s 191 return s
180 192
193
181 def __str__(self): 194 def __str__(self):
182 if len(self.data) > 0: 195 if len(self.data) > 0:
183 myStr = "[" + str(self.data[0]) 196 myStr = "[" + str(self.data[0])
184 for a in self.data[1:]: 197 for a in self.data[1:]:
185 myStr += "," 198 myStr += ","