Mercurial > traipse_dev
comparison orpg/dieroller/trinity.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 | 35 |
36 __version__ = "$Id: trinity.py,v 1.2 2007/05/05 05:30:10 digitalxero Exp $" | 36 __version__ = "$Id: trinity.py,v 1.2 2007/05/05 05:30:10 digitalxero Exp $" |
37 | 37 |
38 | 38 |
39 class trinity(std): | 39 class trinity(std): |
40 def __init__(self,source=[],target=7,targetthr=0): | 40 |
41 std.__init__(self,source) | 41 def __init__(self,source=[],target=7,targetthr=0): |
42 self.target = target | 42 std.__init__(self,source) |
43 self.targetthr = targetthr | 43 self.target = target |
44 self.targetthr = targetthr | |
44 | 45 |
45 def vs(self,target): | 46 |
46 self.target = target | 47 def vs(self,target): |
47 return self | 48 self.target = target |
49 return self | |
48 | 50 |
49 def thr(self,targetthr): | 51 |
50 self.targetthr = targetthr | 52 def thr(self,targetthr): |
51 return self | 53 self.targetthr = targetthr |
54 return self | |
52 | 55 |
53 def sum(self): | 56 |
54 rolls = [] | 57 def sum(self): |
55 s = 0 | 58 rolls = [] |
56 b = 0 | 59 s = 0 |
57 for a in self.data: | 60 b = 0 |
58 rolls.extend(a.gethistory()) | 61 for a in self.data: |
59 for r in rolls: | 62 rolls.extend(a.gethistory()) |
60 if r >= self.target: | 63 for r in rolls: |
61 s += 1 | 64 if r >= self.target: |
62 elif r == 1: | 65 s += 1 |
63 b -= 1 | 66 elif r == 1: |
64 if s == 0: | 67 b -= 1 |
65 return b | 68 if s == 0: |
66 else: | 69 return b |
67 return s | 70 else: |
71 return s | |
68 | 72 |
69 def __str__(self): | 73 |
70 if len(self.data) > 0: | 74 def __str__(self): |
71 myStr = "[" + str(self.data[0]) | 75 if len(self.data) > 0: |
72 for a in self.data[1:]: | 76 myStr = "[" + str(self.data[0]) |
73 myStr += "," | 77 for a in self.data[1:]: |
74 myStr += str(a) | 78 myStr += "," |
75 if self.sum() < 0: | 79 myStr += str(a) |
76 myStr += "] result of a (" + str(self.sum()) + ") botch" | 80 if self.sum() < 0: |
77 elif self.sum() == 0: | 81 myStr += "] result of a (" + str(self.sum()) + ") botch" |
78 myStr += "] result of a failure" | 82 elif self.sum() == 0: |
79 else: | 83 myStr += "] result of a failure" |
80 myStr += "] result of (" + str(self.sum()) + ") success" | 84 else: |
85 myStr += "] result of (" + str(self.sum()) + ") success" | |
81 | 86 |
82 | 87 |
83 return myStr | 88 return myStr |