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: srex.py
|
|
23 # Original Author: Michael Edwards (AKA akoman)
|
|
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. Thanks to the ORPG team
|
|
29 # for the original die rollers.
|
|
30 # Thanks to tdb30_ for letting me think out loud with him.
|
|
31 # I take my hint from the HERO dieroller: It creates for wildly variant options
|
|
32 # Further, .vs and .open do not work together in any logical way. One method of
|
|
33 # chaining them results in a [Bad Dice Format] and the other results in a standard
|
|
34 # output from calling .open()
|
|
35
|
|
36 # vs is a classic 'comparison' method function, with one difference. It uses a
|
|
37 # c&p'ed .open(int) from die.py but makes sure that once the target has been exceeded
|
|
38 # then it stops rerolling. The overhead from additional boolean checking is probably
|
|
39 # greater than the gains from not over-rolling. The behaviour is in-line with
|
|
40 # Shadowrun Third Edition which recommends not rolling once you've exceeded the target
|
|
41 # open is an override of .open(int) in die.py. The reason is pretty simple. In die.py open
|
|
42 # refers to 'open-ended rolling' whereas in Shadowrun it refers to an 'Open Test' where
|
|
43 # the objective is to find the highest die total out of rolled dice. This is then generally
|
|
44 # used as the target in a 'Success Test' (for which .vs functions)
|
|
45
|
|
46 # Modified by: Darloth
|
|
47 # Mod Version: 1.1
|
|
48 # Modified Desc:
|
|
49 # I've altered the vs call to make it report successes against every target number (tn)
|
|
50 # in a specified (default 3) range, with the original as median.
|
|
51 # This reduces rerolling if the TN was calculated incorrectly, and is also very useful
|
|
52 # when people are rolling against multiple TNs, which is the case with most area-effect spells.
|
|
53 # To aid in picking the specified TN out from the others, it will be in bold.
|
|
54 # vswide is a version which can be used with no arguments, or can be used to get a very wide range, by
|
|
55 # directly specifying the upper bound (Which is limited to 30)
|
|
56
|
|
57 from die import *
|
|
58
|
|
59 __version__ = "1.1"
|
|
60
|
|
61 class srex(std):
|
|
62
|
|
63 def __init__(self,source=[]):
|
|
64 std.__init__(self,source)
|
|
65
|
|
66
|
|
67 def vs(self,actualtarget=4,tnrange=3): #reports all tns around specified, max distance of range
|
|
68 return srVs(self,actualtarget,(actualtarget-tnrange),(actualtarget+tnrange))
|
|
69
|
|
70
|
|
71 def vswide(self,actualtarget=4,maxtarget=12): #wide simply means it reports TNs from 2 to a specified max.
|
|
72 return srVs(self,actualtarget,2,maxtarget)
|
|
73
|
|
74
|
|
75 def open(self): #unchanged from standard shadowrun open.
|
|
76 return srOpen(self)
|
|
77
|
|
78 class srVs(std):
|
|
79
|
|
80 def __init__(self,source=[],actualtarget=4,mintn=2,maxtn=12):
|
|
81 std.__init__(self, source)
|
|
82 if actualtarget > 30:
|
|
83 actualtarget = 30
|
|
84 if mintn > 30:
|
|
85 mintn = 30
|
|
86 if maxtn > 30:
|
|
87 maxtn = 30
|
|
88 # In Shadowrun, not target number may be below 2. Any
|
|
89 # thing lower is scaled up.
|
|
90 if actualtarget < 2:
|
|
91 self.target = 2
|
|
92 else:
|
|
93 self.target = actualtarget
|
|
94 #if the target number is higher than max (Mainly for wide rolls) then increase max to tn
|
|
95 if actualtarget > maxtn:
|
|
96 maxtn = actualtarget
|
|
97 #store minimum for later use as well, also in result printing section.
|
|
98 if mintn < 2:
|
|
99 self.mintn = 2
|
|
100 else:
|
|
101 self.mintn = mintn
|
|
102 self.maxtn = maxtn #store for later use in printing results. (Yeah, these comments are now disordered)
|
|
103
|
|
104 # Shadowrun was built to use the d6 but in the interests of experimentation I have
|
|
105 # made the dieroller generic enough to use any die type
|
|
106 self.openended(self[0].sides)
|
|
107
|
|
108
|
|
109 def openended(self,num):
|
|
110 if num <= 1:
|
|
111 self
|
|
112 done = 1
|
|
113
|
|
114 #reroll dice if they hit the highest number, until they are greater than the max TN (recursive)
|
|
115 for i in range(len(self.data)):
|
|
116 if (self.data[i].lastroll() >= num) and (self.data[i] < self.maxtn):
|
|
117 self.data[i].extraroll()
|
|
118 done = 0
|
|
119 if done:
|
|
120 return self
|
|
121 else:
|
|
122 return self.openended(num)
|
|
123
|
|
124 #count successes, by looping through each die, and checking it against the currently set TN
|
|
125
|
|
126 def __sum__(self):
|
|
127 s = 0
|
|
128 for r in self.data:
|
|
129 if r >= self.target:
|
|
130 s += 1
|
|
131 return s
|
|
132
|
|
133 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through
|
|
134 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could
|
|
135 #easily be lost.
|
|
136
|
|
137 def xsum(self,curtarget):
|
|
138 s = 0
|
|
139 for r in self.data:
|
|
140 if r >= curtarget:
|
|
141 s += 1
|
|
142 return s
|
|
143
|
|
144
|
|
145
|
|
146 def __str__(self):
|
|
147 if len(self.data) > 0:
|
|
148 myStr = "[" + str(self.data[0])
|
|
149 for a in self.data[1:]:
|
|
150 myStr += ","
|
|
151 myStr += str(a)
|
|
152 myStr += "] Results: "
|
|
153 #cycle through from mintn to maxtn, summing successes for each separate TN
|
|
154 for targ in range(self.mintn,self.maxtn+1):
|
|
155 if targ == self.target:
|
|
156 myStr += "<b>"
|
|
157 myStr += "(" + str(self.xsum(targ)) + " vs " + str(targ) + ") "
|
|
158 if targ == self.target:
|
|
159 myStr += "</b>"
|
|
160 else:
|
|
161 myStr = "[] = (0)"
|
|
162
|
|
163 return myStr
|
|
164
|
|
165 class srOpen(std):
|
|
166
|
|
167 def __init__(self,source=[]):
|
|
168 std.__init__(self,source)
|
|
169 self.openended(self[0].sides)
|
|
170
|
|
171
|
|
172 def openended(self,num):
|
|
173 if num <= 1:
|
|
174 self
|
|
175 done = 1
|
|
176 for i in range(len(self.data)):
|
|
177 if self.data[i].lastroll() == num:
|
|
178 self.data[i].extraroll()
|
|
179 done = 0
|
|
180 if done:
|
|
181 return self
|
|
182 else:
|
|
183 return self.openended(num)
|
|
184
|
|
185
|
|
186 def __sum__(self):
|
|
187 s = 0
|
|
188 for r in self.data:
|
|
189 if r > s:
|
|
190 s = r
|
|
191 return s
|
|
192
|
|
193
|
|
194 def __str__(self):
|
|
195 if len(self.data) > 0:
|
|
196 myStr = "[" + str(self.data[0])
|
|
197 for a in self.data[1:]:
|
|
198 myStr += ","
|
|
199 myStr += str(a)
|
|
200 self.takeHighest(1)
|
|
201 myStr += "] for a result of (" + str(self.__sum__().__int__()) + ")"
|
|
202 else:
|
|
203 myStr = "[] = (0)"
|
|
204
|
|
205 return myStr
|