Mercurial > traipse
comparison orpg/dieroller/wodex.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 97265586402b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
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 def __init__(self,source=[]): | |
40 std.__init__(self,source) | |
41 | |
42 def vs(self,actualtarget=6): | |
43 return oldwodVs(self,actualtarget,(6)) | |
44 | |
45 def wod(self,actualtarget=8): | |
46 return newwodVs(self,actualtarget,(8)) | |
47 | |
48 def exalt(self, actualtarget=7): | |
49 return exaltVs(self, actualtarget) | |
50 | |
51 def exaltDmg(self, actualtarget=7): | |
52 return exaltDmg(self, actualtarget) | |
53 | |
54 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) | |
56 | |
57 class oldwodVs(std): | |
58 def __init__(self,source=[],actualtarget=6,mintn=2,maxtn=10): | |
59 std.__init__(self, source) | |
60 if actualtarget > 10: | |
61 actualtarget = 10 | |
62 if mintn > 10: | |
63 mintn = 10 | |
64 if maxtn > 10: | |
65 maxtn = 10 | |
66 if actualtarget < 2: | |
67 self.target = 2 | |
68 else: | |
69 self.target = actualtarget | |
70 #if the target number is higher than max (Mainly for wide rolls) then increase max to tn | |
71 if actualtarget > maxtn: | |
72 maxtn = actualtarget | |
73 if actualtarget < mintn: | |
74 mintn = actualtarget | |
75 #store minimum for later use as well, also in result printing section. | |
76 if mintn < 2: | |
77 self.mintn = 2 | |
78 else: | |
79 self.mintn = mintn | |
80 self.maxtn = maxtn #store for later use in printing results. (Yeah, these comments are now disordered) | |
81 | |
82 # WoD etc uses d10 but i've left it so it can roll anything openended | |
83 # self.openended(self[0].sides) | |
84 | |
85 #count successes, by looping through each die, and checking it against the currently set TN | |
86 #1's subtract successes. | |
87 def __sum__(self): | |
88 s = 0 | |
89 for r in self.data: | |
90 if r >= self.target: | |
91 s += 1 | |
92 elif r == 1: | |
93 s -= 1 | |
94 return s | |
95 | |
96 #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 | |
98 #easily be lost. 1s subtract successes from everything. | |
99 def xsum(self,curtarget): | |
100 s = 0 | |
101 for r in self.data: | |
102 if r >= curtarget: | |
103 s += 1 | |
104 elif r == 1: | |
105 s -= 1 | |
106 return s | |
107 | |
108 | |
109 def __str__(self): | |
110 if len(self.data) > 0: | |
111 myStr = "[" + str(self.data[0]) | |
112 for a in self.data[1:]: | |
113 myStr += "," | |
114 myStr += str(a) | |
115 myStr += "] Results: " | |
116 #cycle through from mintn to maxtn, summing successes for each separate TN | |
117 for targ in range(self.mintn,self.maxtn+1): | |
118 if (targ == self.target): | |
119 myStr += "<b>" | |
120 myStr += "(" + str(self.xsum(targ)) + " vs " + str(targ) + ") " | |
121 if (targ == self.target): | |
122 myStr += "</b>" | |
123 else: | |
124 myStr = "[] = (0)" | |
125 | |
126 return myStr | |
127 | |
128 class newwodVs(std): | |
129 def __init__(self,source=[],actualtarget=8,mintn=8,maxtn=8): | |
130 std.__init__(self, source) | |
131 if actualtarget > 30: | |
132 actualtarget = 30 | |
133 if mintn > 10: | |
134 mintn = 10 | |
135 if maxtn > 10: | |
136 maxtn = 10 | |
137 if actualtarget < 2: | |
138 self.target = 2 | |
139 else: | |
140 self.target = actualtarget | |
141 #if the target number is higher than max (Mainly for wide rolls) then increase max to tn | |
142 if actualtarget > maxtn: | |
143 maxtn = actualtarget | |
144 if actualtarget < mintn: | |
145 mintn = actualtarget | |
146 #store minimum for later use as well, also in result printing section. | |
147 if mintn < 2: | |
148 self.mintn = 2 | |
149 else: | |
150 self.mintn = mintn | |
151 self.maxtn = maxtn #store for later use in printing results. (Yeah, these comments are now disordered) | |
152 | |
153 # WoD etc uses d10 but i've left it so it can roll anything openended | |
154 # self.openended(self[0].sides) | |
155 | |
156 #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 | |
158 #easily be lost. 1s subtract successes from original but not re-rolls. | |
159 def xsum(self,curtarget,subones=1): | |
160 s = 0 | |
161 done = 1 | |
162 for r in self.data: | |
163 if r >= curtarget: | |
164 s += 1 | |
165 elif ((r == 1) and (subones == 1)): | |
166 s -= 1 | |
167 if r == 10: | |
168 done = 0 | |
169 subones = 0 | |
170 self.append(di(10)) | |
171 if done == 1: | |
172 return s | |
173 else: | |
174 return self.xsum(0) | |
175 | |
176 def openended(self,num): | |
177 if num <= 1: | |
178 self | |
179 done = 1 | |
180 for i in range(len(self.data)): | |
181 if self.data[i].lastroll() == num: | |
182 self.data[i].extraroll() | |
183 done = 0 | |
184 if done: | |
185 return self | |
186 else: | |
187 return self.openended(num) | |
188 | |
189 | |
190 def __str__(self): | |
191 if len(self.data) > 0: | |
192 myStr = "[" + str(self.data[0]) | |
193 for a in self.data[1:]: | |
194 myStr += "," | |
195 myStr += str(a) | |
196 myStr += "] Results: " | |
197 #cycle through from mintn to maxtn, summing successes for each separate TN | |
198 for targ in range(self.mintn,self.maxtn+1): | |
199 if (targ == self.target): | |
200 myStr += "<b>" | |
201 myStr += "(" + str(self.xsum(targ)) + " vs " + str(targ) + ") " | |
202 if (targ == self.target): | |
203 myStr += "</b>" | |
204 else: | |
205 myStr = "[] = (0)" | |
206 | |
207 return myStr | |
208 | |
209 class exaltVs(std): | |
210 def __init__(self, source=[], actualtarget=7): | |
211 std.__init__(self, source) | |
212 | |
213 if actualtarget > 10: | |
214 actualtarget = 10 | |
215 | |
216 if actualtarget < 2: | |
217 self.target = 2 | |
218 else: | |
219 self.target = actualtarget | |
220 | |
221 | |
222 def xsum(self, target): | |
223 s = 0 | |
224 | |
225 for r in self.data: | |
226 if r >= target: | |
227 s += 1 | |
228 if r == 10: | |
229 s += 1 | |
230 | |
231 return s | |
232 | |
233 | |
234 def __str__(self): | |
235 if len(self.data) > 0: | |
236 myStr = str(self.data) | |
237 myStr += " Results: " | |
238 | |
239 succ = self.xsum(self.target) | |
240 if succ == 0 and 1 in self.data: | |
241 myStr += 'BOTCH!' | |
242 elif succ == 0: | |
243 myStr += str(succ) + " Failure" | |
244 elif succ == 1: | |
245 myStr += str(succ) + " Success" | |
246 else: | |
247 myStr += str(succ) + " Successes" | |
248 | |
249 return myStr | |
250 | |
251 class exaltDmg(std): | |
252 def __init__(self, source=[], actualtarget=7): | |
253 std.__init__(self, source) | |
254 if actualtarget > 10: | |
255 actualtarget = 10 | |
256 | |
257 if actualtarget < 2: | |
258 self.target = 2 | |
259 else: | |
260 self.target = actualtarget | |
261 | |
262 def xsum(self, target): | |
263 s = 0 | |
264 | |
265 for r in self.data: | |
266 if r >= target: | |
267 s += 1 | |
268 return s | |
269 | |
270 def __str__(self): | |
271 if len(self.data) > 0: | |
272 myStr = str(self.data) | |
273 myStr += " Results: " | |
274 | |
275 succ = self.xsum(self.target) | |
276 | |
277 if succ == 0 and 1 in self.data: | |
278 myStr += 'BOTCH!' | |
279 elif succ == 0: | |
280 myStr += str(succ) + " Failure" | |
281 elif succ == 1: | |
282 myStr += str(succ) + " Success" | |
283 else: | |
284 myStr += str(succ) + " Successes" | |
285 | |
286 return myStr |