comparison orpg/dieroller/hackmaster.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
36 36
37 __version__ = "$Id: hackmaster.py,v 1.8 2006/11/15 12:11:22 digitalxero Exp $" 37 __version__ = "$Id: hackmaster.py,v 1.8 2006/11/15 12:11:22 digitalxero Exp $"
38 38
39 #hackmaster Class basically passes into functional classes 39 #hackmaster Class basically passes into functional classes
40 class hackmaster(std): 40 class hackmaster(std):
41
41 def __init__(self,source=[]): 42 def __init__(self,source=[]):
42 std.__init__(self,source) 43 std.__init__(self,source)
43 44
45
44 def damage(self, mod, hon): 46 def damage(self, mod, hon):
45 return HMdamage(self, mod, hon) 47 return HMdamage(self, mod, hon)
46 48
49
47 def attack(self, mod, hon): 50 def attack(self, mod, hon):
48 return HMattack(self, mod, hon) 51 return HMattack(self, mod, hon)
49 52
53
50 def help(self): 54 def help(self):
51 return HMhelp(self) 55 return HMhelp(self)
52 56
57
53 def severity(self, honor): 58 def severity(self, honor):
54 return HMSeverity(self, honor) 59 return HMSeverity(self, honor)
55 60
56 61
57 # HM Damage roller - rolles penetration as per the PHB - re-rolles on max die - 1, adds honor to the penetration rolls 62 # HM Damage roller - rolles penetration as per the PHB - re-rolles on max die - 1, adds honor to the penetration rolls
58 # and this appears to be invisible to the user ( if a 4 on a d4 is rolled a 3 will appear and be followed by another 63 # and this appears to be invisible to the user ( if a 4 on a d4 is rolled a 3 will appear and be followed by another
59 # die. if High honor then a 4 will appear followed by a another die. 64 # die. if High honor then a 4 will appear followed by a another die.
60 class HMdamage(std): 65 class HMdamage(std):
66
61 def __init__(self,source=[], mod = 0, hon = 0): 67 def __init__(self,source=[], mod = 0, hon = 0):
62 std.__init__(self,source) 68 std.__init__(self,source)
63 self.mod = mod 69 self.mod = mod
64 self.hon = hon 70 self.hon = hon
65 self.check_pen() 71 self.check_pen()
66 #here we roll the mod die 72 #here we roll the mod die
67 self.append(static_di(self.mod)) 73 self.append(static_di(self.mod))
68 #here we roll the honor die 74 #here we roll the honor die
69 self.append(static_di(self.hon)) 75 self.append(static_di(self.hon))
70 76
77
71 def damage(mod = 0, hon = 0): 78 def damage(mod = 0, hon = 0):
72 self.mod = mod 79 self.mod = mod
73 self.hon = hon 80 self.hon = hon
74 81
75 # This function is called by default to display the die string to the chat window. 82 # This function is called by default to display the die string to the chat window.
76 # Our die string attempts to explain the results 83 # Our die string attempts to explain the results
84
77 def __str__(self): 85 def __str__(self):
78 myStr = "Damage " 86 myStr = "Damage "
79 myStr += "[Damage Roll, Modifiers, Honor]: " + " [" + str(self.data[0]) 87 myStr += "[Damage Roll, Modifiers, Honor]: " + " [" + str(self.data[0])
80 for a in self.data[1:]: 88 for a in self.data[1:]:
81 myStr += "," 89 myStr += ","
83 myStr += "] = (" + str(self.sum()) + ")" 91 myStr += "] = (" + str(self.sum()) + ")"
84 92
85 return myStr 93 return myStr
86 94
87 # This function checks to see if we need to reroll for penetration 95 # This function checks to see if we need to reroll for penetration
96
88 def check_pen(self): 97 def check_pen(self):
89 for i in range(len(self.data)): 98 for i in range(len(self.data)):
90 if self.data[i].lastroll() >= self.data[i].sides: 99 if self.data[i].lastroll() >= self.data[i].sides:
91 self.pen_roll(i) 100 self.pen_roll(i)
92 101
93 #this function rolls the penetration die, and checks to see if it needs to be re-rolled again. 102 #this function rolls the penetration die, and checks to see if it needs to be re-rolled again.
103
94 def pen_roll(self,num): 104 def pen_roll(self,num):
95 result = int(random.uniform(1,self.data[num].sides+1)) 105 result = int(random.uniform(1,self.data[num].sides+1))
96 self.data[num].value += (result - 1 + self.hon) 106 self.data[num].value += (result - 1 + self.hon)
97 self.data[num].history.append(result - 1 + self.hon) 107 self.data[num].history.append(result - 1 + self.hon)
98 if result >= self.data[num].sides: 108 if result >= self.data[num].sides:
99 self.pen_roll(num) 109 self.pen_roll(num)
100 110
101 # this function rolls for the HM Attack. the function checks for a 20 and displays critical, and a 1 111 # this function rolls for the HM Attack. the function checks for a 20 and displays critical, and a 1
102 # and displays fumble 112 # and displays fumble
103 class HMattack(std): 113 class HMattack(std):
114
104 def __init__(self, source=[], mod = 0, base_severity = 0, hon = 0, size = 0): 115 def __init__(self, source=[], mod = 0, base_severity = 0, hon = 0, size = 0):
105 std.__init__(self,source) 116 std.__init__(self,source)
106 self.size = size 117 self.size = size
107 self.mod = mod 118 self.mod = mod
108 self.base_severity = base_severity 119 self.base_severity = base_severity
114 self.append(static_di(self.mod)) 125 self.append(static_di(self.mod))
115 #this is a static die that adds honor, we want high rolls so it's +1 126 #this is a static die that adds honor, we want high rolls so it's +1
116 self.append(static_di(self.hon)) 127 self.append(static_di(self.hon))
117 128
118 129
130
119 def check_crit(self): 131 def check_crit(self):
120 if self.data[0] == self.data[0].sides: 132 if self.data[0] == self.data[0].sides:
121 self.crit = 1 133 self.crit = 1
122 if self.data[0] == 1: 134 if self.data[0] == 1:
123 self.fumble = 1 135 self.fumble = 1
124 136
125 137
126 #this function is the out put to the chat window, it basicaly just displays the roll unless 138 #this function is the out put to the chat window, it basicaly just displays the roll unless
127 #it's a natural 20, or a natural 1 139 #it's a natural 20, or a natural 1
140
128 def __str__(self): 141 def __str__(self):
129 if self.crit > 0: 142 if self.crit > 0:
130 myStr = "Critical Hit!!: " 143 myStr = "Critical Hit!!: "
131 elif self.fumble > 0: 144 elif self.fumble > 0:
132 myStr = "FUMBLE!!" 145 myStr = "FUMBLE!!"
138 myStr += str(a) 151 myStr += str(a)
139 myStr += "] = (" + str(self.sum()) + ")" 152 myStr += "] = (" + str(self.sum()) + ")"
140 return myStr 153 return myStr
141 154
142 class HMhelp(std): 155 class HMhelp(std):
156
143 def __init__(self,source=[]): 157 def __init__(self,source=[]):
144 std.__init__(self,source) 158 std.__init__(self,source)
145 self.source = source 159 self.source = source
146 160
161
147 def __str__(self): 162 def __str__(self):
148 myStr = " <br /> .attack(Bonus, Honor): <br />" 163 myStr = " <br /> .attack(Bonus, Honor): <br />"
149 myStr += " The attack roll rolles the dice and adds your bonus <br />" 164 myStr += " The attack roll rolles the dice and adds your bonus <br />"
150 myStr += " and honor modifier and returns you final roll. <br />" 165 myStr += " and honor modifier and returns you final roll. <br />"
151 myStr += " On a natural 20 the dieroller displays Critical Hit!! <br />" 166 myStr += " On a natural 20 the dieroller displays Critical Hit!! <br />"
169 return myStr 184 return myStr
170 185
171 # the severity roll is for critical resolution. The die is rerolled and added 186 # the severity roll is for critical resolution. The die is rerolled and added
172 #on a natural 8 and rerolled and subtracted on a 1 187 #on a natural 8 and rerolled and subtracted on a 1
173 class HMSeverity(std): 188 class HMSeverity(std):
189
174 def __init__(self, source =[], honor=0): 190 def __init__(self, source =[], honor=0):
175 std.__init__(self,source) 191 std.__init__(self,source)
176 self.source = source 192 self.source = source
177 self.hon = honor 193 self.hon = honor
178 self.data = [] 194 self.data = []
179 self.append(di(8)) 195 self.append(di(8))
180 self.CheckReroll() 196 self.CheckReroll()
181 self.append(static_di(self.hon)) 197 self.append(static_di(self.hon))
182 198
183 199
200
184 def __str__(self): 201 def __str__(self):
185 myStr = "[Severity Dice, Honor]" + " [" + str(self.data[0]) 202 myStr = "[Severity Dice, Honor]" + " [" + str(self.data[0])
186 for a in self.data[1:]: 203 for a in self.data[1:]:
187 myStr += "," 204 myStr += ","
188 myStr += str(a) 205 myStr += str(a)
189 myStr += "] = (" + str(self.sum()) + ")" 206 myStr += "] = (" + str(self.sum()) + ")"
190 return myStr 207 return myStr
191 208
209
192 def CheckReroll(self): 210 def CheckReroll(self):
193 if self.data[0] == self.data[0].sides: 211 if self.data[0] == self.data[0].sides:
194 self.crit_chain(0,1) 212 self.crit_chain(0,1)
195 if self.data[0] == 1: 213 if self.data[0] == 1:
196 self.crit_chain(0,-1) 214 self.crit_chain(0,-1)
197 215
198 #this function needes moved for severity 216 #this function needes moved for severity
217
199 def crit_chain(self,num,neg): 218 def crit_chain(self,num,neg):
200 result = int(random.uniform(1,self.data[num].sides+1)) 219 result = int(random.uniform(1,self.data[num].sides+1))
201 self.data[num].value += (((result - 1) * neg) + self.hon) 220 self.data[num].value += (((result - 1) * neg) + self.hon)
202 self.data[num].history.append(((result - 1) * neg) + self.hon) 221 self.data[num].history.append(((result - 1) * neg) + self.hon)
203 if result >= self.data[num].sides: 222 if result >= self.data[num].sides: