167
|
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 std import std
|
|
58 from orpg.dieroller.base import *
|
|
59
|
|
60 __version__ = "1.1"
|
|
61
|
|
62 class srex(std):
|
|
63 name = "srex"
|
|
64
|
|
65 def __init__(self,source=[]):
|
|
66 std.__init__(self,source)
|
|
67
|
|
68 def vs(self,actualtarget=4,tnrange=3): #reports all tns around specified, max distance of range
|
|
69 return srVs(self,actualtarget,(actualtarget-tnrange),(actualtarget+tnrange))
|
|
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 def open(self): #unchanged from standard shadowrun open.
|
|
75 return srOpen(self)
|
|
76
|
|
77 die_rollers.register(srex)
|
|
78
|
|
79 class srVs(std):
|
|
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 def openended(self,num):
|
|
109 if num <= 1:
|
|
110 self
|
|
111 done = 1
|
|
112
|
|
113 #reroll dice if they hit the highest number, until they are greater than the max TN (recursive)
|
|
114 for i in range(len(self.data)):
|
|
115 if (self.data[i].lastroll() >= num) and (self.data[i] < self.maxtn):
|
|
116 self.data[i].extraroll()
|
|
117 done = 0
|
|
118 if done:
|
|
119 return self
|
|
120 else:
|
|
121 return self.openended(num)
|
|
122
|
|
123 #count successes, by looping through each die, and checking it against the currently set TN
|
|
124 def __sum__(self):
|
|
125 s = 0
|
|
126 for r in self.data:
|
|
127 if r >= self.target:
|
|
128 s += 1
|
|
129 return s
|
|
130
|
|
131 #a modified sum, but this one takes a target argument, and is there because otherwise it is difficult to loop through
|
|
132 #tns counting successes against each one without changing target, which is rather dangerous as the original TN could
|
|
133 #easily be lost.
|
|
134 def xsum(self,curtarget):
|
|
135 s = 0
|
|
136 for r in self.data:
|
|
137 if r >= curtarget:
|
|
138 s += 1
|
|
139 return s
|
|
140
|
|
141
|
|
142 def __str__(self):
|
|
143 if len(self.data) > 0:
|
|
144 myStr = "[" + str(self.data[0])
|
|
145 for a in self.data[1:]:
|
|
146 myStr += ","
|
|
147 myStr += str(a)
|
|
148 myStr += "] Results: "
|
|
149 #cycle through from mintn to maxtn, summing successes for each separate TN
|
|
150 for targ in range(self.mintn,self.maxtn+1):
|
|
151 if targ == self.target:
|
|
152 myStr += "<b>"
|
|
153 myStr += "(" + str(self.xsum(targ)) + " vs " + str(targ) + ") "
|
|
154 if targ == self.target:
|
|
155 myStr += "</b>"
|
|
156 else:
|
|
157 myStr = "[] = (0)"
|
|
158
|
|
159 return myStr
|
|
160
|
|
161 class srOpen(std):
|
|
162 def __init__(self,source=[]):
|
|
163 std.__init__(self,source)
|
|
164 self.openended(self[0].sides)
|
|
165
|
|
166 def openended(self,num):
|
|
167 if num <= 1:
|
|
168 self
|
|
169 done = 1
|
|
170 for i in range(len(self.data)):
|
|
171 if self.data[i].lastroll() == num:
|
|
172 self.data[i].extraroll()
|
|
173 done = 0
|
|
174 if done:
|
|
175 return self
|
|
176 else:
|
|
177 return self.openended(num)
|
|
178
|
|
179 def __sum__(self):
|
|
180 s = 0
|
|
181 for r in self.data:
|
|
182 if r > s:
|
|
183 s = r
|
|
184 return s
|
|
185
|
|
186 def __str__(self):
|
|
187 if len(self.data) > 0:
|
|
188 myStr = "[" + str(self.data[0])
|
|
189 for a in self.data[1:]:
|
|
190 myStr += ","
|
|
191 myStr += str(a)
|
|
192 self.takeHighest(1)
|
|
193 myStr += "] for a result of (" + str(self.__sum__().__int__()) + ")"
|
|
194 else:
|
|
195 myStr = "[] = (0)"
|
|
196
|
|
197 return myStr
|