comparison orpg/dieroller/sr4.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: sr4.py
23 # Author: Veggiesama, ripped straight from Michael Edwards (AKA akoman)
24 # Maintainer:
25 # Version: 1.1
26 #
27 # 1.1: Now with glitch and critical glitch detection!
28 # 1.1: Cleaned up some of the output to make it simpler.
29 #
30 # Description: Modified from the original Shadowrun dieroller by akoman,
31 # but altered to follow the new Shadowrun 4th Ed dice system.
32 #
33 # SR4 VS
34 # Typing [Xd6.vs(Y)] will roll X dice, checking each die
35 # roll against the MIN_TARGET_NUMBER (default: 5). If it
36 # meets or beats it, it counts as a hit. If the total hits
37 # meet or beat the Y value (threshold), there's a success.
38 #
39 # SR4 EDGE VS
40 # Identical to the above function, except it looks like
41 # [Xd6.edge(Y)] and follows the "Rule of Six". That rule
42 # states any roll of 6 is counted as a hit and rerolled
43 # with a potential to score more hits. The "Edge" bonus
44 # dice must be included into X.
45 #
46 # SR4 INIT
47 # Typing [Xd6.init(Y)] will roll X dice, checking each
48 # die for a hit. All hits are added to Y (the init attrib
49 # of the player), to give an Init Score for the combat.
50 #
51 # SR4 EDGE INIT
52 # Typing [Xd6.initedge(Y)] or [Xd6.edgeinit(Y)] will do
53 # as above, except adding the possibility of Edge dice.
54 #
55 # Note about non-traditional uses:
56 # - D6's are not required. This script will work with any
57 # die possible, and the "Rule of Six" will only trigger
58 # on the highest die roll possible. Not throughly tested.
59 # - If you want to alter the minimum target number (ex.
60 # score a hit on a 4, 5, or 6), scroll down and change
61 # the global value MIN_TARGET_NUMBER to your liking.
62
63 from die import *
64
65 __version__ = "1.1"
66
67 MIN_TARGET_NUMBER = 5
68 GLITCH_NUMBER = 1
69
70 class sr4(std):
71 def __init__(self,source=[]):
72 std.__init__(self,source)
73 self.threshold = None
74 self.init_attrib = None
75
76 def vs(self,threshold=0):
77 return sr4vs(self, threshold)
78
79 def edge(self,threshold=0):
80 return sr4vs(self, threshold, 1)
81
82 def init(self,init_attrib=0):
83 return sr4init(self, init_attrib)
84
85 def initedge(self,init_attrib=0):
86 return sr4init(self, init_attrib, 1)
87 def edgeinit(self,init_attrib=0):
88 return sr4init(self, init_attrib, 1)
89
90 def countEdge(self,num):
91 if num <= 1:
92 self
93 done = 1
94 for i in range(len(self.data)):
95 if (self.data[i].lastroll() >= num):
96 # counts every rerolled 6 as a hit
97 self.hits += 1
98 self.data[i].extraroll()
99 self.total += 1
100 done = 0
101 elif (self.data[i].lastroll() <= GLITCH_NUMBER):
102 self.ones += 1
103 self.total += 1
104 if done:
105 return self
106 else:
107 return self.countEdge(num)
108
109 def countHits(self,num):
110 for i in range(len(self.data)):
111 if (self.data[i].lastroll() >= MIN_TARGET_NUMBER):
112 # (Rule of Six taken into account in countEdge(), not here)
113 self.hits += 1
114 elif (self.data[i].lastroll() <= GLITCH_NUMBER):
115 self.ones += 1
116 self.total += 1
117
118 def __str__(self):
119 if len(self.data) > 0:
120 self.hits = 0
121 self.ones = 0
122 self.total = 0
123 for i in range(len(self.data)):
124 if (self.data[i].lastroll() >= MIN_TARGET_NUMBER):
125 self.hits += 1
126 elif (self.data[i].lastroll() <= GLITCH_NUMBER):
127 self.ones += 1
128 self.total += 1
129 firstpass = 0
130 myStr = "["
131 for a in self.data[0:]:
132 if firstpass != 0:
133 myStr += ","
134 firstpass = 1
135 if a >= MIN_TARGET_NUMBER:
136 myStr += "<B>" + str(a) + "</B>"
137 elif a <= GLITCH_NUMBER:
138 myStr += "<i>" + str(a) + "</i>"
139 else:
140 myStr += str(a)
141 myStr += "] " + CheckIfGlitch(self.ones, self.hits, self.total)
142 myStr += "Hits: (" + str(self.hits) + ")"
143 else:
144 myStr = "[] = (0)"
145 return myStr
146
147 class sr4init(sr4):
148 def __init__(self,source=[],init_attrib=1,edge=0):
149 std.__init__(self,source)
150 if init_attrib < 2:
151 self.init_attrib = 2
152 else:
153 self.init_attrib = init_attrib
154 self.dicesides = self[0].sides
155 self.hits = 0
156 self.ones = 0
157 self.total = 0
158 if edge:
159 self.countEdge(self.dicesides)
160 self.countHits(self.dicesides)
161
162 def __str__(self):
163 if len(self.data) > 0:
164 firstpass = 0
165 myStr = "["
166 for a in self.data[0:]:
167 if firstpass != 0:
168 myStr += ","
169 firstpass = 1
170 if a >= MIN_TARGET_NUMBER:
171 myStr += "<B>" + str(a) + "</B>"
172 elif a <= GLITCH_NUMBER:
173 myStr += "<i>" + str(a) + "</i>"
174 else:
175 myStr += str(a)
176 myStr += "] " + CheckIfGlitch(self.ones, self.hits, self.total)
177 init_score = str(self.init_attrib + self.hits)
178 myStr += "InitScore: " + str(self.init_attrib) + "+"
179 myStr += str(self.hits) + " = (" + init_score + ")"
180 else:
181 myStr = "[] = (0)"
182 return myStr
183
184 class sr4vs(sr4):
185 def __init__(self,source=[], threshold=1, edge=0):
186 std.__init__(self, source)
187 if threshold < 0:
188 self.threshold = 0
189 else:
190 self.threshold = threshold
191 self.dicesides = self[0].sides
192 self.hits = 0
193 self.ones = 0
194 self.total = 0
195 if edge:
196 self.countEdge(self.dicesides)
197 self.countHits(self.dicesides)
198
199 def __str__(self):
200 if len(self.data) > 0:
201 firstpass = 0
202 myStr = "["
203 for a in self.data[0:]:
204 if firstpass != 0:
205 myStr += ","
206 firstpass = 1
207 if a >= MIN_TARGET_NUMBER:
208 myStr += "<B>" + str(a) + "</B>"
209 elif a <= GLITCH_NUMBER:
210 myStr += "<i>" + str(a) + "</i>"
211 else:
212 myStr += str(a)
213 #myStr += "] Threshold=" + str(self.threshold)
214 myStr += "] vs " + str(self.threshold) + " "
215 myStr += CheckIfGlitch(self.ones, self.hits, self.total)
216 if self.hits >= self.threshold:
217 myStr += "*SUCCESS* "
218 else:
219 myStr += "*FAILURE* "
220 myStr += "Hits: (" + str(self.hits) + ")"
221 else:
222 myStr = "[] = (0)"
223 return myStr
224
225 def CheckIfGlitch(ones, hits, total_dice):
226 if (ones * 2) >= total_dice:
227 if hits >= 1:
228 return "*GLITCH* "
229 else:
230 return "*CRITICAL GLITCH* "
231 else:
232 return ""