155
|
1 ## a vs die roller as used by WOD games
|
|
2 #!/usr/bin/env python
|
|
3 # Copyright (C) 2000-2001 The OpenRPG Project
|
|
4 #
|
|
5 # openrpg-dev@lists.sourceforge.net
|
|
6 #
|
|
7 # This program is free software; you can redistribute it and/or modify
|
|
8 # it under the terms of the GNU General Public License as published by
|
|
9 # the Free Software Foundation; either version 2 of the License, or
|
|
10 # (at your option) any later version.
|
|
11 #
|
|
12 # This program is distributed in the hope that it will be useful,
|
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 # GNU General Public License for more details.
|
|
16 #
|
|
17 # You should have received a copy of the GNU General Public License
|
|
18 # along with this program; if not, write to the Free Software
|
|
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
20 # --
|
|
21 #
|
|
22 # File: wodex.py
|
|
23 # Original Author: Darloth
|
|
24 # Maintainer:
|
|
25 # Original Version: 1.0
|
|
26 #
|
|
27 # Description: A modified form of the World of Darkness die roller to
|
|
28 # conform to ShadowRun rules-sets, then modified back to the WoD for
|
|
29 # the new WoD system. Thanks to the ORPG team
|
|
30 # for the original die rollers.
|
|
31 # Much thanks to whoever wrote the original shadowrun roller (akoman I believe)
|
|
32
|
|
33
|
|
34 from die import *
|
|
35
|
|
36 __version__ = "$Id: wodex.py,v 1.9 2007/05/06 16:42:55 digitalxero Exp $"
|
|
37
|
|
38 class wodex(std):
|
|
39
|
|
40 def __init__(self,source=[]):
|
|
41 std.__init__(self,source)
|
|
42
|
|
43
|
|
44 def vs(self,actualtarget=6):
|
|
45 return oldwodVs(self,actualtarget,(6))
|
|
46
|
|
47
|
|
48 def wod(self,actualtarget=8):
|
|
49 return newwodVs(self,actualtarget,(8))
|
|
50
|
|
51
|
|
52 def exalt(self, actualtarget=7):
|
|
53 return exaltVs(self, actualtarget)
|
|
54
|
|
55
|
|
56 def exaltDmg(self, actualtarget=7):
|
|
57 return exaltDmg(self, actualtarget)
|
|
58
|
|
59
|
|
60 def vswide(self,actualtarget=6,maxtarget=10): #wide simply means it reports TNs from 2 to a specified max.
|
|
61 return oldwodVs(self,actualtarget,2,maxtarget)
|
|
62
|
|
63 class oldwodVs(std):
|
|
64
|
|
65 def __init__(self,source=[],actualtarget=6,mintn=2,maxtn=10):
|
|
66 std.__init__(self, source)
|
|
67 if actualtarget > 10:
|
|
68 actualtarget = 10
|
|
69 if mintn > 10:
|
|
70 mintn = 10
|
|
71 if maxtn > 10:
|
|
72 maxtn = 10
|
|
73 if actualtarget < 2:
|
|
74 self.target = 2
|
|
75 else:
|
|
76 self.target = actualtarget
|
|
77 #if the target number is higher than max (Mainly for wide rolls) then increase max to tn
|
|
78 if actualtarget > maxtn:
|
|
79 maxtn = actualtarget
|
|
80 if actualtarget < mintn:
|
|
81 mintn = actualtarget
|
|
82 #store minimum for later use as well, also in result printing section.
|
|
83 if mintn < 2:
|
|
84 self.mintn = 2
|
|
85 else:
|
|
86 self.mintn = mintn
|
|
87 self.maxtn = maxtn #store for later use in printing results. (Yeah, these comments are now disordered)
|
|
88
|
|
89 # WoD etc uses d10 but i've left it so it can roll anything openended
|
|
90 # self.openended(self[0].sides)
|
|
91
|
|
92 #count successes, by looping through each die, and checking it against the currently set TN
|
|
93 #1's subtract successes.
|
|
94
|
|
95 def __sum__(self):
|
|
96 s = 0
|
|
97 for r in self.data:
|
|
98 if r >= self.target:
|
|
99 s += 1
|
|
100 elif r == 1:
|
|
101 s -= 1
|
|
102 return s
|
|
103
|
|
104 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through
|
|
105 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could
|
|
106 #easily be lost. 1s subtract successes from everything.
|
|
107
|
|
108 def xsum(self,curtarget):
|
|
109 s = 0
|
|
110 for r in self.data:
|
|
111 if r >= curtarget:
|
|
112 s += 1
|
|
113 elif r == 1:
|
|
114 s -= 1
|
|
115 return s
|
|
116
|
|
117
|
|
118
|
|
119 def __str__(self):
|
|
120 if len(self.data) > 0:
|
|
121 myStr = "[" + str(self.data[0])
|
|
122 for a in self.data[1:]:
|
|
123 myStr += ","
|
|
124 myStr += str(a)
|
|
125 myStr += "] Results: "
|
|
126 #cycle through from mintn to maxtn, summing successes for each separate TN
|
|
127 for targ in range(self.mintn,self.maxtn+1):
|
|
128 if (targ == self.target):
|
|
129 myStr += "<b>"
|
|
130 myStr += "(" + str(self.xsum(targ)) + " vs " + str(targ) + ") "
|
|
131 if (targ == self.target):
|
|
132 myStr += "</b>"
|
|
133 else:
|
|
134 myStr = "[] = (0)"
|
|
135
|
|
136 return myStr
|
|
137
|
|
138 class newwodVs(std):
|
|
139
|
|
140 def __init__(self,source=[],actualtarget=8,mintn=8,maxtn=8):
|
|
141 std.__init__(self, source)
|
|
142 if actualtarget > 30:
|
|
143 actualtarget = 30
|
|
144 if mintn > 10:
|
|
145 mintn = 10
|
|
146 if maxtn > 10:
|
|
147 maxtn = 10
|
|
148 if actualtarget < 2:
|
|
149 self.target = 2
|
|
150 else:
|
|
151 self.target = actualtarget
|
|
152 #if the target number is higher than max (Mainly for wide rolls) then increase max to tn
|
|
153 if actualtarget > maxtn:
|
|
154 maxtn = actualtarget
|
|
155 if actualtarget < mintn:
|
|
156 mintn = actualtarget
|
|
157 #store minimum for later use as well, also in result printing section.
|
|
158 if mintn < 2:
|
|
159 self.mintn = 2
|
|
160 else:
|
|
161 self.mintn = mintn
|
|
162 self.maxtn = maxtn #store for later use in printing results. (Yeah, these comments are now disordered)
|
|
163
|
|
164 # WoD etc uses d10 but i've left it so it can roll anything openended
|
|
165 # self.openended(self[0].sides)
|
|
166
|
|
167 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through
|
|
168 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could
|
|
169 #easily be lost. 1s subtract successes from original but not re-rolls.
|
|
170
|
|
171 def xsum(self,curtarget,subones=1):
|
|
172 s = 0
|
|
173 done = 1
|
|
174 for r in self.data:
|
|
175 if r >= curtarget:
|
|
176 s += 1
|
|
177 elif ((r == 1) and (subones == 1)):
|
|
178 s -= 1
|
|
179 if r == 10:
|
|
180 done = 0
|
|
181 subones = 0
|
|
182 self.append(di(10))
|
|
183 if done == 1:
|
|
184 return s
|
|
185 else:
|
|
186 return self.xsum(0)
|
|
187
|
|
188
|
|
189 def openended(self,num):
|
|
190 if num <= 1:
|
|
191 self
|
|
192 done = 1
|
|
193 for i in range(len(self.data)):
|
|
194 if self.data[i].lastroll() == num:
|
|
195 self.data[i].extraroll()
|
|
196 done = 0
|
|
197 if done:
|
|
198 return self
|
|
199 else:
|
|
200 return self.openended(num)
|
|
201
|
|
202
|
|
203
|
|
204 def __str__(self):
|
|
205 if len(self.data) > 0:
|
|
206 myStr = "[" + str(self.data[0])
|
|
207 for a in self.data[1:]:
|
|
208 myStr += ","
|
|
209 myStr += str(a)
|
|
210 myStr += "] Results: "
|
|
211 #cycle through from mintn to maxtn, summing successes for each separate TN
|
|
212 for targ in range(self.mintn,self.maxtn+1):
|
|
213 if (targ == self.target):
|
|
214 myStr += "<b>"
|
|
215 myStr += "(" + str(self.xsum(targ)) + " vs " + str(targ) + ") "
|
|
216 if (targ == self.target):
|
|
217 myStr += "</b>"
|
|
218 else:
|
|
219 myStr = "[] = (0)"
|
|
220
|
|
221 return myStr
|
|
222
|
|
223 class exaltVs(std):
|
|
224
|
|
225 def __init__(self, source=[], actualtarget=7):
|
|
226 std.__init__(self, source)
|
|
227
|
|
228 if actualtarget > 10:
|
|
229 actualtarget = 10
|
|
230
|
|
231 if actualtarget < 2:
|
|
232 self.target = 2
|
|
233 else:
|
|
234 self.target = actualtarget
|
|
235
|
|
236
|
|
237
|
|
238 def xsum(self, target):
|
|
239 s = 0
|
|
240
|
|
241 for r in self.data:
|
|
242 if r >= target:
|
|
243 s += 1
|
|
244 if r == 10:
|
|
245 s += 1
|
|
246
|
|
247 return s
|
|
248
|
|
249
|
|
250
|
|
251 def __str__(self):
|
|
252 if len(self.data) > 0:
|
|
253 myStr = str(self.data)
|
|
254 myStr += " Results: "
|
|
255
|
|
256 succ = self.xsum(self.target)
|
|
257 if succ == 0 and 1 in self.data:
|
|
258 myStr += 'BOTCH!'
|
|
259 elif succ == 0:
|
|
260 myStr += str(succ) + " Failure"
|
|
261 elif succ == 1:
|
|
262 myStr += str(succ) + " Success"
|
|
263 else:
|
|
264 myStr += str(succ) + " Successes"
|
|
265
|
|
266 return myStr
|
|
267
|
|
268 class exaltDmg(std):
|
|
269
|
|
270 def __init__(self, source=[], actualtarget=7):
|
|
271 std.__init__(self, source)
|
|
272 if actualtarget > 10:
|
|
273 actualtarget = 10
|
|
274
|
|
275 if actualtarget < 2:
|
|
276 self.target = 2
|
|
277 else:
|
|
278 self.target = actualtarget
|
|
279
|
|
280
|
|
281 def xsum(self, target):
|
|
282 s = 0
|
|
283
|
|
284 for r in self.data:
|
|
285 if r >= target:
|
|
286 s += 1
|
|
287 return s
|
|
288
|
|
289
|
|
290 def __str__(self):
|
|
291 if len(self.data) > 0:
|
|
292 myStr = str(self.data)
|
|
293 myStr += " Results: "
|
|
294
|
|
295 succ = self.xsum(self.target)
|
|
296
|
|
297 if succ == 0 and 1 in self.data:
|
|
298 myStr += 'BOTCH!'
|
|
299 elif succ == 0:
|
|
300 myStr += str(succ) + " Failure"
|
|
301 elif succ == 1:
|
|
302 myStr += str(succ) + " Success"
|
|
303 else:
|
|
304 myStr += str(succ) + " Successes"
|
|
305
|
|
306 return myStr
|