comparison orpg/dieroller/die.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
35 import copy 35 import copy
36 #import string 36 #import string
37 37
38 class die_base(UserList.UserList): 38 class die_base(UserList.UserList):
39 39
40
40 def __init__(self,source = []): 41 def __init__(self,source = []):
41 if isinstance(source, (int, float, basestring)): 42 if isinstance(source, (int, float, basestring)):
42 s = [] 43 s = []
43 s.append(di(source)) 44 s.append(di(source))
44 else: 45 else:
45 s = source 46 s = source
46 UserList.UserList.__init__(self,s) 47 UserList.UserList.__init__(self,s)
47 48
48 49
50
49 def sum(self): 51 def sum(self):
50 s = 0 52 s = 0
51 for a in self.data: 53 for a in self.data:
52 s += int(a) 54 s += int(a)
53 return s 55 return s
54 56
57
55 def __lshift__(self,other): 58 def __lshift__(self,other):
56 if type(other) == type(3) or type(other) == type(3.0): 59 if type(other) == type(3) or type(other) == type(3.0):
57 o = other 60 o = other
58 elif hasattr(other,"sum"): 61 elif hasattr(other,"sum"):
59 o = other.sum() 62 o = other.sum()
64 for die in self: 67 for die in self:
65 if die < o: 68 if die < o:
66 result.append(die) 69 result.append(die)
67 return self.__class__(result) 70 return self.__class__(result)
68 71
72
69 def __rshift__(self,other): 73 def __rshift__(self,other):
70 74
71 if type(other) == type(3) or type(other) == type(3.0): 75 if type(other) == type(3) or type(other) == type(3.0):
72 o = other 76 o = other
73 elif hasattr(other,"sum"): 77 elif hasattr(other,"sum"):
79 for die in self: 83 for die in self:
80 if die > o: 84 if die > o:
81 result.append(die) 85 result.append(die)
82 return self.__class__(result) 86 return self.__class__(result)
83 87
88
84 def __rlshift__(self,other): 89 def __rlshift__(self,other):
85 return self.__rshift__(other) 90 return self.__rshift__(other)
86 91
92
87 def __rrshift__(self,other): 93 def __rrshift__(self,other):
88 return self.__lshift__(other) 94 return self.__lshift__(other)
89 95
90 96
97
91 def __str__(self): 98 def __str__(self):
92 if len(self.data) > 0: 99 if len(self.data) > 0:
93 myStr = "[" + str(self.data[0]) 100 myStr = "[" + str(self.data[0])
94 for a in self.data[1:]: 101 for a in self.data[1:]:
95 myStr += "," 102 myStr += ","
97 myStr += "] = (" + str(self.sum()) + ")" 104 myStr += "] = (" + str(self.sum()) + ")"
98 else: 105 else:
99 myStr = "[] = (0)" 106 myStr = "[] = (0)"
100 return myStr 107 return myStr
101 108
109
102 def __lt__(self,other): 110 def __lt__(self,other):
103 if type(other) == type(3) or type(other) == type(3.0): 111 if type(other) == type(3) or type(other) == type(3.0):
104 return (self.sum() < other) 112 return (self.sum() < other)
105 elif hasattr(other,"sum"): 113 elif hasattr(other,"sum"):
106 return (self.sum() < other.sum()) 114 return (self.sum() < other.sum())
107 else: 115 else:
108 return UserList.UserList.__lt__(self,other) 116 return UserList.UserList.__lt__(self,other)
109 117
118
110 def __le__(self,other): 119 def __le__(self,other):
111 if type(other) == type(3) or type(other) == type(3.0): 120 if type(other) == type(3) or type(other) == type(3.0):
112 return (self.sum() <= other) 121 return (self.sum() <= other)
113 elif hasattr(other,"sum"): 122 elif hasattr(other,"sum"):
114 return (self.sum() <= other.sum()) 123 return (self.sum() <= other.sum())
115 else: 124 else:
116 return UserList.UserList.__le__(self,other) 125 return UserList.UserList.__le__(self,other)
117 126
127
118 def __eq__(self,other): 128 def __eq__(self,other):
119 if type(other) == type(3) or type(other) == type(3.0): 129 if type(other) == type(3) or type(other) == type(3.0):
120 return (self.sum() == other) 130 return (self.sum() == other)
121 elif hasattr(other,"sum"): 131 elif hasattr(other,"sum"):
122 return (self.sum() == other.sum()) 132 return (self.sum() == other.sum())
123 else: 133 else:
124 return UserList.UserList.__eq__(self,other) 134 return UserList.UserList.__eq__(self,other)
125 135
136
126 def __ne__(self,other): 137 def __ne__(self,other):
127 if type(other) == type(3) or type(other) == type(3.0): 138 if type(other) == type(3) or type(other) == type(3.0):
128 return (self.sum() != other) 139 return (self.sum() != other)
129 elif hasattr(other,"sum"): 140 elif hasattr(other,"sum"):
130 return (self.sum() != other.sum()) 141 return (self.sum() != other.sum())
131 else: 142 else:
132 return UserList.UserList.__ne__(self,other) 143 return UserList.UserList.__ne__(self,other)
133 144
145
134 def __gt__(self,other): 146 def __gt__(self,other):
135 if type(other) == type(3) or type(other) == type(3.0): 147 if type(other) == type(3) or type(other) == type(3.0):
136 return (self.sum() > other) 148 return (self.sum() > other)
137 elif hasattr(other,"sum"): 149 elif hasattr(other,"sum"):
138 return (self.sum() > other.sum()) 150 return (self.sum() > other.sum())
139 else: 151 else:
140 return UserList.UserList.__gt__(self,other) 152 return UserList.UserList.__gt__(self,other)
141 153
154
142 def __ge__(self,other): 155 def __ge__(self,other):
143 if type(other) == type(3) or type(other) == type(3.0): 156 if type(other) == type(3) or type(other) == type(3.0):
144 return (self.sum() >= other) 157 return (self.sum() >= other)
145 elif hasattr(other,"sum"): 158 elif hasattr(other,"sum"):
146 return (self.sum() >= other.sum()) 159 return (self.sum() >= other.sum())
147 else: 160 else:
148 return UserList.UserList.__ge__(self,other) 161 return UserList.UserList.__ge__(self,other)
149 162
163
150 def __cmp__(self,other): 164 def __cmp__(self,other):
151 # this function included for backwards compatibility 165 # this function included for backwards compatibility
152 # As of 2.1, lists implement the "rich comparison" 166 # As of 2.1, lists implement the "rich comparison"
153 # methods overloaded above. 167 # methods overloaded above.
154 if type(other) == type(3) or type(other) == type(3.0): 168 if type(other) == type(3) or type(other) == type(3.0):
157 return cmp(self.sum(), other.sum()) 171 return cmp(self.sum(), other.sum())
158 else: 172 else:
159 return UserList.UserList.__cmp__(self,other) 173 return UserList.UserList.__cmp__(self,other)
160 174
161 175
176
162 def __rcmp__(self,other): 177 def __rcmp__(self,other):
163 return self.__cmp__(other) 178 return self.__cmp__(other)
164 179
180
165 def __add__(self,other): 181 def __add__(self,other):
166 mycopy = copy.deepcopy(self) 182 mycopy = copy.deepcopy(self)
167 if type(other) == type(3) or type(other) == type(3.0): 183 if type(other) == type(3) or type(other) == type(3.0):
168 #if other < 0: 184 #if other < 0:
169 # return self.__sub__(-other) 185 # return self.__sub__(-other)
175 return self 191 return self
176 mycopy.extend(other) 192 mycopy.extend(other)
177 #result = UserList.UserList.__add__(mycopy,other) 193 #result = UserList.UserList.__add__(mycopy,other)
178 return mycopy 194 return mycopy
179 195
196
180 def __iadd__(self,other): 197 def __iadd__(self,other):
181 return self.__add__(other) 198 return self.__add__(other)
182 199
200
183 def __radd__(self,other): 201 def __radd__(self,other):
184 mycopy = copy.deepcopy(self) 202 mycopy = copy.deepcopy(self)
185 if type(other) == type(3) or type(other) == type(3.0): 203 if type(other) == type(3) or type(other) == type(3.0):
186 new_die = di(0) 204 new_die = di(0)
187 new_die.set_value(other) 205 new_die.set_value(other)
188 other = new_die 206 other = new_die
189 mycopy.insert(0,other) 207 mycopy.insert(0,other)
190 return mycopy 208 return mycopy
191 209
210
192 def __int__(self): 211 def __int__(self):
193 return self.sum() 212 return self.sum()
194 213
214
195 def __sub__(self,other): 215 def __sub__(self,other):
196 mycopy = copy.deepcopy(self) 216 mycopy = copy.deepcopy(self)
197 if type(other) == type(3) or type(other) == type(3.0): 217 if type(other) == type(3) or type(other) == type(3.0):
198 neg_die = static_di(-other) 218 neg_die = static_di(-other)
199 #neg_die.set_value(-other) 219 #neg_die.set_value(-other)
202 else: 222 else:
203 other = -other 223 other = -other
204 mycopy.extend(other) 224 mycopy.extend(other)
205 return mycopy 225 return mycopy
206 226
227
207 def __rsub__(self,other): 228 def __rsub__(self,other):
208 mycopy = -copy.deepcopy(self) 229 mycopy = -copy.deepcopy(self)
209 #print type(other) 230 #print type(other)
210 if type(other) == type(3) or type(other) == type(3.0): 231 if type(other) == type(3) or type(other) == type(3.0):
211 new_die = di(0) 232 new_die = di(0)
212 new_die.set_value(other) 233 new_die.set_value(other)
213 other = new_die 234 other = new_die
214 mycopy.insert(0,other) 235 mycopy.insert(0,other)
215 return mycopy 236 return mycopy
216 237
238
217 def __isub__(self,other): 239 def __isub__(self,other):
218 return self.__sub__(other) 240 return self.__sub__(other)
219 241
242
220 def __mul__(self,other): 243 def __mul__(self,other):
221 if type(other) == type(3) or type(other) == type(3.0): 244 if type(other) == type(3) or type(other) == type(3.0):
222 return self.sum() * other 245 return self.sum() * other
223 elif hasattr(other,"sum"): 246 elif hasattr(other,"sum"):
224 return other.sum() * self.sum() 247 return other.sum() * self.sum()
225 else: 248 else:
226 return UserList.UserList.__mul__(self,other) 249 return UserList.UserList.__mul__(self,other)
227 250
251
228 def __rmul__(self,other): 252 def __rmul__(self,other):
229 return self.__mul__(other) 253 return self.__mul__(other)
230 254
255
231 def __div__(self,other): 256 def __div__(self,other):
232 if type(other) == type(3) or type(other) == type(3.0): 257 if type(other) == type(3) or type(other) == type(3.0):
233 return float(self.sum()) / other 258 return float(self.sum()) / other
234 elif hasattr(other,"sum"): 259 elif hasattr(other,"sum"):
235 return float(self.sum()) / other.sum() 260 return float(self.sum()) / other.sum()
236 else: 261 else:
237 return UserList.UserList.__div__(self,other) 262 return UserList.UserList.__div__(self,other)
238 263
264
239 def __rdiv__(self,other): 265 def __rdiv__(self,other):
240 if type(other) == type(3) or type(other) == type(3.0): 266 if type(other) == type(3) or type(other) == type(3.0):
241 return other / float(self.sum()) 267 return other / float(self.sum())
242 elif hasattr(other,"sum"): 268 elif hasattr(other,"sum"):
243 return other.sum() / float(self.sum()) 269 return other.sum() / float(self.sum())
244 else: 270 else:
245 return UserList.UserList.__rdiv__(self,other) 271 return UserList.UserList.__rdiv__(self,other)
246 272
273
247 def __mod__(self,other): 274 def __mod__(self,other):
248 if type(other) == type(3) or type(other) == type(3.0): 275 if type(other) == type(3) or type(other) == type(3.0):
249 return self.sum()%other 276 return self.sum()%other
250 elif hasattr(other,"sum"): 277 elif hasattr(other,"sum"):
251 return self.sum() % other.sum() 278 return self.sum() % other.sum()
252 else: 279 else:
253 return UserList.UserList.__mod__(self,other) 280 return UserList.UserList.__mod__(self,other)
254 281
282
255 def __rmod__(self,other): 283 def __rmod__(self,other):
256 if type(other) == type(3) or type(other) == type(3.0): 284 if type(other) == type(3) or type(other) == type(3.0):
257 return other % self.sum() 285 return other % self.sum()
258 elif hasattr(other,"sum"): 286 elif hasattr(other,"sum"):
259 return other.sum() % self.sum() 287 return other.sum() % self.sum()
260 else: 288 else:
261 return UserList.UserList.__rmod__(self,other) 289 return UserList.UserList.__rmod__(self,other)
262 290
291
263 def __neg__(self): 292 def __neg__(self):
264 for i in range(len(self.data)): 293 for i in range(len(self.data)):
265 self.data[i] = -self.data[i] 294 self.data[i] = -self.data[i]
266 return self 295 return self
267 296
297
268 def __pos__(self): 298 def __pos__(self):
269 for i in range(len(self.data)): 299 for i in range(len(self.data)):
270 self.data[i] = +self.data[i] 300 self.data[i] = +self.data[i]
271 return self 301 return self
272 302
303
273 def __abs__(self): 304 def __abs__(self):
274 for i in range(len(self.data)): 305 for i in range(len(self.data)):
275 self.data[i] = abs(self.data[i]) 306 self.data[i] = abs(self.data[i])
276 return self 307 return self
277 #return abs(self.sum()) 308 #return abs(self.sum())
278 309
310
279 def __pow__(self,other): 311 def __pow__(self,other):
280 if type(other) == type(3) or type(other) == type(3.0): 312 if type(other) == type(3) or type(other) == type(3.0):
281 return self.sum() ** other 313 return self.sum() ** other
282 elif hasattr(other,"sum"): 314 elif hasattr(other,"sum"):
283 return self.sum() ** other.sum() 315 return self.sum() ** other.sum()
284 else: 316 else:
285 return UserList.UserList.__pow__(self,other) 317 return UserList.UserList.__pow__(self,other)
286 318
287 319
320
288 def __rpow__(self,other): 321 def __rpow__(self,other):
289 # We're overloading exponentiation of ints to create "other" number of dice 322 # We're overloading exponentiation of ints to create "other" number of dice
290 323
291 if other >= 1: 324 if other >= 1:
292 result = self.__class__(self[0].sides) 325 result = self.__class__(self[0].sides)
298 return result 331 return result
299 332
300 ### di class to handle actual dice 333 ### di class to handle actual dice
301 334
302 class di: 335 class di:
336
303 def __init__(self,sides,min=1): 337 def __init__(self,sides,min=1):
304 self.sides = sides 338 self.sides = sides
305 self.history = None 339 self.history = None
306 self.value = None 340 self.value = None
307 self.target = None 341 self.target = None
308 self.roll(min) 342 self.roll(min)
309 343
344
310 def __str__(self): 345 def __str__(self):
311 if len(self.history) > 1: 346 if len(self.history) > 1:
312 return str(self.history) 347 return str(self.history)
313 else: 348 else:
314 return str(self.value) 349 return str(self.value)
315 350
351
316 def __neg__(self): 352 def __neg__(self):
317 self.value = -self.value 353 self.value = -self.value
318 for i in range(len(self.history)): 354 for i in range(len(self.history)):
319 self.history[i] = -self.history[i] 355 self.history[i] = -self.history[i]
320 return self 356 return self
321 357
358
322 def __pos__(self): 359 def __pos__(self):
323 self.value = +self.value 360 self.value = +self.value
324 for i in range(len(self.history)): 361 for i in range(len(self.history)):
325 self.history[i] = +self.history[i] 362 self.history[i] = +self.history[i]
326 return self 363 return self
327 364
365
328 def __abs__(self): 366 def __abs__(self):
329 self.value = abs(self.value) 367 self.value = abs(self.value)
330 for i in range(len(self.history)): 368 for i in range(len(self.history)):
331 self.history[i] = abs(self.history[i]) 369 self.history[i] = abs(self.history[i])
332 return self 370 return self
333 371
372
334 def __repr__(self): 373 def __repr__(self):
335 if len(self.history) > 1: 374 if len(self.history) > 1:
336 return str(self.history) 375 return str(self.history)
337 else: 376 else:
338 return str(self.value) 377 return str(self.value)
339 378
379
340 def __int__(self): 380 def __int__(self):
341 return self.value 381 return self.value
342 382
343 383
384
344 def __lt__(self,other): 385 def __lt__(self,other):
345 if type(other) == type(3) or type(other) == type(3.0): 386 if type(other) == type(3) or type(other) == type(3.0):
346 return self.value < other 387 return self.value < other
347 elif hasattr(other,"value"): 388 elif hasattr(other,"value"):
348 return self.value < other.value 389 return self.value < other.value
349 else: 390 else:
350 return self < other 391 return self < other
351 392
393
352 def __le__(self,other): 394 def __le__(self,other):
353 if type(other) == type(3) or type(other) == type(3.0): 395 if type(other) == type(3) or type(other) == type(3.0):
354 return self.value <= other 396 return self.value <= other
355 elif hasattr(other,"value"): 397 elif hasattr(other,"value"):
356 return self.value <= other.value 398 return self.value <= other.value
357 else: 399 else:
358 return self <= other 400 return self <= other
359 401
402
360 def __eq__(self,other): 403 def __eq__(self,other):
361 if type(other) == type(3) or type(other) == type(3.0): 404 if type(other) == type(3) or type(other) == type(3.0):
362 return self.value == other 405 return self.value == other
363 elif hasattr(other,"value"): 406 elif hasattr(other,"value"):
364 return self.value == other.value 407 return self.value == other.value
365 else: 408 else:
366 return self == other 409 return self == other
367 410
411
368 def __ne__(self,other): 412 def __ne__(self,other):
369 if type(other) == type(3) or type(other) == type(3.0): 413 if type(other) == type(3) or type(other) == type(3.0):
370 return self.value != other 414 return self.value != other
371 elif hasattr(other,"value"): 415 elif hasattr(other,"value"):
372 return self.value != other.value 416 return self.value != other.value
373 else: 417 else:
374 return self != other 418 return self != other
375 419
420
376 def __gt__(self,other): 421 def __gt__(self,other):
377 if type(other) == type(3) or type(other) == type(3.0): 422 if type(other) == type(3) or type(other) == type(3.0):
378 return self.value > other 423 return self.value > other
379 elif hasattr(other,"value"): 424 elif hasattr(other,"value"):
380 return self.value > other.value 425 return self.value > other.value
381 else: 426 else:
382 return self > other 427 return self > other
383 428
429
384 def __ge__(self,other): 430 def __ge__(self,other):
385 if type(other) == type(3) or type(other) == type(3.0): 431 if type(other) == type(3) or type(other) == type(3.0):
386 return self.value >= other 432 return self.value >= other
387 elif hasattr(other,"value"): 433 elif hasattr(other,"value"):
388 return self.value >= other.value 434 return self.value >= other.value
389 else: 435 else:
390 return self >= other 436 return self >= other
391 437
438
392 def __cmp__(self,other): 439 def __cmp__(self,other):
393 # this function included for backwards compatibility 440 # this function included for backwards compatibility
394 # As of 2.1, lists implement the "rich comparison" 441 # As of 2.1, lists implement the "rich comparison"
395 # methods overloaded above. 442 # methods overloaded above.
396 if type(other) == type(3) or type(other) == type(3.0): 443 if type(other) == type(3) or type(other) == type(3.0):
397 return cmp(self.value, other) 444 return cmp(self.value, other)
398 elif hasattr(other,"value"): 445 elif hasattr(other,"value"):
399 return cmp(self.value, other.value) 446 return cmp(self.value, other.value)
400 else: 447 else:
401 return cmp(self,other) 448 return cmp(self,other)
402 449
450
403 def roll(self,min=1): 451 def roll(self,min=1):
404 if isinstance(self.sides, basestring) and self.sides.lower() == 'f': 452 if isinstance(self.sides, basestring) and self.sides.lower() == 'f':
405 self.value = random.randint(-1, 1) 453 self.value = random.randint(-1, 1)
406 else: 454 else:
407 #self.value = random.randint(min, self.sides) 455 #self.value = random.randint(min, self.sides)
408 self.value = int(random.uniform(min, self.sides+1)) 456 self.value = int(random.uniform(min, self.sides+1))
409 self.history = [] 457 self.history = []
410 self.history.append(self.value) 458 self.history.append(self.value)
411 459
460
412 def extraroll(self): 461 def extraroll(self):
413 if isinstance(self.sides, basestring) and self.sides.lower() == 'f': 462 if isinstance(self.sides, basestring) and self.sides.lower() == 'f':
414 result = random.randint(-1, 1) 463 result = random.randint(-1, 1)
415 else: 464 else:
416 #result = random.randint(1, self.sides) 465 #result = random.randint(1, self.sides)
417 result = int(random.uniform(1,self.sides+1)) 466 result = int(random.uniform(1,self.sides+1))
418 467
419 self.value += result 468 self.value += result
420 self.history.append(result) 469 self.history.append(result)
421 470
471
422 def lastroll(self): 472 def lastroll(self):
423 return self.history[len(self.history)-1] 473 return self.history[len(self.history)-1]
424 474
475
425 def set_value(self,value): 476 def set_value(self,value):
426 self.value = value 477 self.value = value
427 self.history = [] 478 self.history = []
428 self.history.append(self.value) 479 self.history.append(self.value)
429 480
481
430 def modify(self,mod): 482 def modify(self,mod):
431 self.value += mod 483 self.value += mod
432 self.history.append(mod) 484 self.history.append(mod)
433 485
486
434 def gethistory(self): 487 def gethistory(self):
435 return self.history[:] 488 return self.history[:]
436 489
437 class static_di(di): 490 class static_di(di):
491
438 def __init__(self,value): 492 def __init__(self,value):
439 di.__init__(self,value,value) 493 di.__init__(self,value,value)
440 self.set_value(value) 494 self.set_value(value)
441 495
442 496
443 class std(die_base): 497 class std(die_base):
498
444 def __init__(self,source=[]): 499 def __init__(self,source=[]):
445 die_base.__init__(self,source) 500 die_base.__init__(self,source)
446 501
447 # Examples of adding member functions through inheritance. 502 # Examples of adding member functions through inheritance.
448 503
504
449 def ascending(self): 505 def ascending(self):
450 result = self[:] 506 result = self[:]
451 result.sort() 507 result.sort()
452 return result 508 return result
453 509
510
454 def descending(self): 511 def descending(self):
455 result = self[:] 512 result = self[:]
456 result.sort() 513 result.sort()
457 result.reverse() 514 result.reverse()
458 return result 515 return result
459 516
517
460 def takeHighest(self,num_dice): 518 def takeHighest(self,num_dice):
461 return self.descending()[:num_dice] 519 return self.descending()[:num_dice]
462 520
521
463 def takeLowest(self,num_dice): 522 def takeLowest(self,num_dice):
464 return self.ascending()[:num_dice] 523 return self.ascending()[:num_dice]
465 524
525
466 def extra(self,num): 526 def extra(self,num):
467 for i in range(len(self.data)): 527 for i in range(len(self.data)):
468 if self.data[i].lastroll() >= num: 528 if self.data[i].lastroll() >= num:
469 self.data[i].extraroll() 529 self.data[i].extraroll()
470 return self 530 return self
471 531
532
472 def open(self,num): 533 def open(self,num):
473 if num <= 1: 534 if num <= 1:
474 self 535 self
475 done = 1 536 done = 1
476 for i in range(len(self.data)): 537 for i in range(len(self.data)):
480 if done: 541 if done:
481 return self 542 return self
482 else: 543 else:
483 return self.open(num) 544 return self.open(num)
484 545
546
485 def minroll(self,min): 547 def minroll(self,min):
486 for i in range(len(self.data)): 548 for i in range(len(self.data)):
487 if self.data[i].lastroll() < min: 549 if self.data[i].lastroll() < min:
488 self.data[i].roll(min) 550 self.data[i].roll(min)
489 return self 551 return self
490 552
553
491 def each(self,mod): 554 def each(self,mod):
492 mod = int(mod) 555 mod = int(mod)
493 for i in range(len(self.data)): 556 for i in range(len(self.data)):
494 self.data[i].modify(mod) 557 self.data[i].modify(mod)
495 return self 558 return self
496 559
497 560
561
498 def vs(self, target): 562 def vs(self, target):
499 for dn in self.data: 563 for dn in self.data:
500 dn.target = target 564 dn.target = target
501 return self 565 return self
502 566
503 567
504 ## If we are testing against a saving throw, we check for 568 ## If we are testing against a saving throw, we check for
505 ## greater than or equal to against the target value and 569 ## greater than or equal to against the target value and
506 ## we only return the number of successful saves. A negative 570 ## we only return the number of successful saves. A negative
507 ## value will never be generated. 571 ## value will never be generated.
572
508 def sum(self): 573 def sum(self):
509 retValue = 0 574 retValue = 0
510 for dn in self.data: 575 for dn in self.data:
511 setValue = reduce( lambda x, y : int(x)+int(y), dn.history ) 576 setValue = reduce( lambda x, y : int(x)+int(y), dn.history )
512 if dn.target: 577 if dn.target: