Mercurial > traipse_dev
comparison orpg/dieroller/wodex.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 |
---|---|
34 from die import * | 34 from die import * |
35 | 35 |
36 __version__ = "$Id: wodex.py,v 1.9 2007/05/06 16:42:55 digitalxero Exp $" | 36 __version__ = "$Id: wodex.py,v 1.9 2007/05/06 16:42:55 digitalxero Exp $" |
37 | 37 |
38 class wodex(std): | 38 class wodex(std): |
39 | |
39 def __init__(self,source=[]): | 40 def __init__(self,source=[]): |
40 std.__init__(self,source) | 41 std.__init__(self,source) |
41 | 42 |
43 | |
42 def vs(self,actualtarget=6): | 44 def vs(self,actualtarget=6): |
43 return oldwodVs(self,actualtarget,(6)) | 45 return oldwodVs(self,actualtarget,(6)) |
44 | 46 |
47 | |
45 def wod(self,actualtarget=8): | 48 def wod(self,actualtarget=8): |
46 return newwodVs(self,actualtarget,(8)) | 49 return newwodVs(self,actualtarget,(8)) |
47 | 50 |
51 | |
48 def exalt(self, actualtarget=7): | 52 def exalt(self, actualtarget=7): |
49 return exaltVs(self, actualtarget) | 53 return exaltVs(self, actualtarget) |
50 | 54 |
55 | |
51 def exaltDmg(self, actualtarget=7): | 56 def exaltDmg(self, actualtarget=7): |
52 return exaltDmg(self, actualtarget) | 57 return exaltDmg(self, actualtarget) |
53 | 58 |
59 | |
54 def vswide(self,actualtarget=6,maxtarget=10): #wide simply means it reports TNs from 2 to a specified max. | 60 def vswide(self,actualtarget=6,maxtarget=10): #wide simply means it reports TNs from 2 to a specified max. |
55 return oldwodVs(self,actualtarget,2,maxtarget) | 61 return oldwodVs(self,actualtarget,2,maxtarget) |
56 | 62 |
57 class oldwodVs(std): | 63 class oldwodVs(std): |
64 | |
58 def __init__(self,source=[],actualtarget=6,mintn=2,maxtn=10): | 65 def __init__(self,source=[],actualtarget=6,mintn=2,maxtn=10): |
59 std.__init__(self, source) | 66 std.__init__(self, source) |
60 if actualtarget > 10: | 67 if actualtarget > 10: |
61 actualtarget = 10 | 68 actualtarget = 10 |
62 if mintn > 10: | 69 if mintn > 10: |
82 # WoD etc uses d10 but i've left it so it can roll anything openended | 89 # WoD etc uses d10 but i've left it so it can roll anything openended |
83 # self.openended(self[0].sides) | 90 # self.openended(self[0].sides) |
84 | 91 |
85 #count successes, by looping through each die, and checking it against the currently set TN | 92 #count successes, by looping through each die, and checking it against the currently set TN |
86 #1's subtract successes. | 93 #1's subtract successes. |
94 | |
87 def __sum__(self): | 95 def __sum__(self): |
88 s = 0 | 96 s = 0 |
89 for r in self.data: | 97 for r in self.data: |
90 if r >= self.target: | 98 if r >= self.target: |
91 s += 1 | 99 s += 1 |
94 return s | 102 return s |
95 | 103 |
96 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through | 104 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through |
97 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could | 105 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could |
98 #easily be lost. 1s subtract successes from everything. | 106 #easily be lost. 1s subtract successes from everything. |
107 | |
99 def xsum(self,curtarget): | 108 def xsum(self,curtarget): |
100 s = 0 | 109 s = 0 |
101 for r in self.data: | 110 for r in self.data: |
102 if r >= curtarget: | 111 if r >= curtarget: |
103 s += 1 | 112 s += 1 |
104 elif r == 1: | 113 elif r == 1: |
105 s -= 1 | 114 s -= 1 |
106 return s | 115 return s |
107 | 116 |
108 | 117 |
118 | |
109 def __str__(self): | 119 def __str__(self): |
110 if len(self.data) > 0: | 120 if len(self.data) > 0: |
111 myStr = "[" + str(self.data[0]) | 121 myStr = "[" + str(self.data[0]) |
112 for a in self.data[1:]: | 122 for a in self.data[1:]: |
113 myStr += "," | 123 myStr += "," |
124 myStr = "[] = (0)" | 134 myStr = "[] = (0)" |
125 | 135 |
126 return myStr | 136 return myStr |
127 | 137 |
128 class newwodVs(std): | 138 class newwodVs(std): |
139 | |
129 def __init__(self,source=[],actualtarget=8,mintn=8,maxtn=8): | 140 def __init__(self,source=[],actualtarget=8,mintn=8,maxtn=8): |
130 std.__init__(self, source) | 141 std.__init__(self, source) |
131 if actualtarget > 30: | 142 if actualtarget > 30: |
132 actualtarget = 30 | 143 actualtarget = 30 |
133 if mintn > 10: | 144 if mintn > 10: |
154 # self.openended(self[0].sides) | 165 # self.openended(self[0].sides) |
155 | 166 |
156 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through | 167 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through |
157 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could | 168 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could |
158 #easily be lost. 1s subtract successes from original but not re-rolls. | 169 #easily be lost. 1s subtract successes from original but not re-rolls. |
170 | |
159 def xsum(self,curtarget,subones=1): | 171 def xsum(self,curtarget,subones=1): |
160 s = 0 | 172 s = 0 |
161 done = 1 | 173 done = 1 |
162 for r in self.data: | 174 for r in self.data: |
163 if r >= curtarget: | 175 if r >= curtarget: |
171 if done == 1: | 183 if done == 1: |
172 return s | 184 return s |
173 else: | 185 else: |
174 return self.xsum(0) | 186 return self.xsum(0) |
175 | 187 |
188 | |
176 def openended(self,num): | 189 def openended(self,num): |
177 if num <= 1: | 190 if num <= 1: |
178 self | 191 self |
179 done = 1 | 192 done = 1 |
180 for i in range(len(self.data)): | 193 for i in range(len(self.data)): |
185 return self | 198 return self |
186 else: | 199 else: |
187 return self.openended(num) | 200 return self.openended(num) |
188 | 201 |
189 | 202 |
203 | |
190 def __str__(self): | 204 def __str__(self): |
191 if len(self.data) > 0: | 205 if len(self.data) > 0: |
192 myStr = "[" + str(self.data[0]) | 206 myStr = "[" + str(self.data[0]) |
193 for a in self.data[1:]: | 207 for a in self.data[1:]: |
194 myStr += "," | 208 myStr += "," |
205 myStr = "[] = (0)" | 219 myStr = "[] = (0)" |
206 | 220 |
207 return myStr | 221 return myStr |
208 | 222 |
209 class exaltVs(std): | 223 class exaltVs(std): |
224 | |
210 def __init__(self, source=[], actualtarget=7): | 225 def __init__(self, source=[], actualtarget=7): |
211 std.__init__(self, source) | 226 std.__init__(self, source) |
212 | 227 |
213 if actualtarget > 10: | 228 if actualtarget > 10: |
214 actualtarget = 10 | 229 actualtarget = 10 |
217 self.target = 2 | 232 self.target = 2 |
218 else: | 233 else: |
219 self.target = actualtarget | 234 self.target = actualtarget |
220 | 235 |
221 | 236 |
237 | |
222 def xsum(self, target): | 238 def xsum(self, target): |
223 s = 0 | 239 s = 0 |
224 | 240 |
225 for r in self.data: | 241 for r in self.data: |
226 if r >= target: | 242 if r >= target: |
229 s += 1 | 245 s += 1 |
230 | 246 |
231 return s | 247 return s |
232 | 248 |
233 | 249 |
250 | |
234 def __str__(self): | 251 def __str__(self): |
235 if len(self.data) > 0: | 252 if len(self.data) > 0: |
236 myStr = str(self.data) | 253 myStr = str(self.data) |
237 myStr += " Results: " | 254 myStr += " Results: " |
238 | 255 |
247 myStr += str(succ) + " Successes" | 264 myStr += str(succ) + " Successes" |
248 | 265 |
249 return myStr | 266 return myStr |
250 | 267 |
251 class exaltDmg(std): | 268 class exaltDmg(std): |
269 | |
252 def __init__(self, source=[], actualtarget=7): | 270 def __init__(self, source=[], actualtarget=7): |
253 std.__init__(self, source) | 271 std.__init__(self, source) |
254 if actualtarget > 10: | 272 if actualtarget > 10: |
255 actualtarget = 10 | 273 actualtarget = 10 |
256 | 274 |
257 if actualtarget < 2: | 275 if actualtarget < 2: |
258 self.target = 2 | 276 self.target = 2 |
259 else: | 277 else: |
260 self.target = actualtarget | 278 self.target = actualtarget |
261 | 279 |
280 | |
262 def xsum(self, target): | 281 def xsum(self, target): |
263 s = 0 | 282 s = 0 |
264 | 283 |
265 for r in self.data: | 284 for r in self.data: |
266 if r >= target: | 285 if r >= target: |
267 s += 1 | 286 s += 1 |
268 return s | 287 return s |
269 | 288 |
289 | |
270 def __str__(self): | 290 def __str__(self): |
271 if len(self.data) > 0: | 291 if len(self.data) > 0: |
272 myStr = str(self.data) | 292 myStr = str(self.data) |
273 myStr += " Results: " | 293 myStr += " Results: " |
274 | 294 |