171
|
1 # (at your option) any later version.
|
|
2 #
|
|
3 # This program is distributed in the hope that it will be useful,
|
|
4 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
5 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
6 # GNU General Public License for more details.
|
|
7 #
|
|
8 # You should have received a copy of the GNU General Public License
|
|
9 # along with this program; if not, write to the Free Software
|
|
10 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
11 # --
|
|
12 #
|
|
13 # File: Alternity.py
|
|
14 # Version:
|
|
15 # $Id: Alternity.py,v .1 JEC (cchriss@thecastle.com)
|
|
16 #
|
|
17 # Description: Alternity die roller based on Posterboy's D20 Dieroller
|
|
18 #
|
|
19 # Changelog:
|
|
20 #
|
187
|
21 # v.1 original release JEC
|
|
22 #
|
|
23 # Traipse Release:
|
|
24 # The changes made in the Traipe release are intended to create a more direct connection
|
|
25 # between the source and the intrepretor. IF, ELIF statements have been replaced with dictionaries,
|
171
|
26 # unused objects have been replace with re-usable objects, and the code has been condensed.
|
187
|
27 #
|
189
|
28 # SEG: JAN 24 2010 - v.1.4 O'Flux Release:
|
187
|
29 # Edits & Additions: fixed a few minor bugs; Damage roll & Display Issues.
|
|
30 # Added Secondary Damage Calculation and Display. Fix all errors.
|
189
|
31 # Added proper results for Critcal Successes with failure ==> final Result Ordinary Success
|
|
32 # Removed reduntent Method to make parent class true with all others working as child.
|
|
33 # Made all special output same colour codes font size. Cleaned out old commented lines.
|
187
|
34 # Tested for Traipse on Win 7
|
|
35 #
|
|
36 # Skill Check Example:
|
|
37 # [1d20.sk(12,-2)]
|
|
38 # OUTPUT Example:
|
|
39 # => [6,-3] = (3) AMAZING Success
|
|
40 #
|
|
41 # Pistol, Laser; 0 step -- Attack Example:
|
|
42 # [1d20.at(12,0,(1d4+1,"w"),(1d6+1,"w"),(1d4,"m"))]
|
|
43 # OUTPUT Example:
|
|
44 # => [1,0] = (1) CRITICAL SUCCESS AMAZING HIT
|
|
45 # ===> Damage [4] = (4) mortal ======> Secondary Damage (2) stun / (2) wound
|
|
46 #
|
|
47 # Action Check Example:
|
|
48 # [1d20.ac(14,-1)]
|
|
49 # OUTPUT Example:
|
|
50 # => ACTION CHECK : [18,-3] = (15) Marginal failure
|
|
51 # -1 Step make up bonus next Action Check
|
|
52 #
|
|
53 #
|
171
|
54
|
|
55 import re
|
187
|
56
|
171
|
57 from std import std
|
|
58 from time import time, clock
|
|
59 from orpg.dieroller.base import di, die_base, die_rollers
|
|
60
|
189
|
61 ##from orpg.tools.orpg_log import debug
|
187
|
62
|
|
63
|
|
64 __version__ = "$Id: alternity.py,v 0.1 2003/01/02 12:00:00 cchriss Exp $"
|
171
|
65
|
|
66 # Alternity stands for "Alternity system" 20 sided die plus mods
|
|
67
|
|
68 class alternity(std):
|
|
69 name = "alternity" # ADDED by SEG Nov 2009 ***
|
|
70
|
|
71 def __init__(self,source=[]):
|
|
72 std.__init__(self,source)
|
|
73
|
187
|
74 # these methods return new die objects for specific options
|
171
|
75 def sk(self,score,mod):
|
|
76 return sk(self,score,mod)
|
|
77
|
|
78 def at(self,score,mod,dmgo,dmgg,dmga):
|
|
79 return at(self,score,mod,dmgo,dmgg,dmga)
|
|
80
|
187
|
81 def ac(self,score,mod):
|
|
82 return ac(self,score,mod)
|
|
83
|
171
|
84 die_rollers.register(alternity)
|
|
85
|
|
86 class sk(std):
|
|
87 def __init__(self,source=[],sc="10/5/2",mod=0):
|
|
88 std.__init__(self,source)
|
|
89 m = re.match( r"\d+", str(sc) )
|
|
90 self.score = int( m.group(0) )
|
|
91 self.mod = mod
|
|
92
|
|
93 def getMod(self,mod=0):
|
187
|
94 m=0
|
|
95 mods = { -4: -di(12), -3: -di(8), -2: -di(6), -1: -di(4), 1: di(4),
|
|
96 2: di(6), 3: di(8), 4: di(12), 5: di(20)} # SEG fix 1: di(4) #
|
|
97 if mod in mods.keys(): m = mods[mod].value
|
171
|
98 elif mod <= -5: m=-di(20).value
|
|
99 elif mod == 6: m=di(20).value + di(20).value
|
|
100 elif mod >= 7: m=di(20).value + di(20).value + di(20).value
|
|
101 return m
|
|
102
|
|
103 def getRolLStr(self):
|
187
|
104 myStr = "[" + str(self.data[0])
|
171
|
105 self.d20 = self.sum()
|
189
|
106 self.amod = self.getMod(self.mod)
|
|
107
|
|
108 ## varN = "self.amod"
|
|
109 ## debug(varN)
|
|
110 ## debug(self.amod) ## seg added debug output
|
|
111
|
|
112 self.dieRoll = self.d20 + self.amod
|
171
|
113 for a in self.data[1:]:
|
|
114 myStr += ","
|
|
115 myStr += str(a)
|
189
|
116 myStr += "," + str(self.amod) + "] = (" + str(self.dieRoll) + ")"
|
171
|
117 if ( self.dieRoll <= self.score / 4 ): self.success = 'A'
|
|
118 elif ( self.dieRoll <= self.score / 2 ): self.success = 'G'
|
|
119 elif ( self.dieRoll <= self.score ): self.success = 'O'
|
|
120 else: self.success = 'F'
|
|
121 if ( self.d20 == 20 ): self.success = 'CF'
|
|
122 return myStr
|
|
123
|
|
124 def __str__(self):
|
187
|
125 myStr = self.getRolLStr()
|
189
|
126
|
|
127 ## varN = "myStr"
|
|
128 ## debug(varN)
|
|
129 ## debug(myStr) ## seg added debug output
|
|
130
|
|
131 successes = {'CS': " <b><font size=2 color='#8D38C9'>CRITICAL SUCCESS</font></b>",
|
|
132 'CF': " <b><font size=2 color='#151B54'>CRITICAL FAILURE</font></b>",
|
|
133 'A': " <b><font size=2 color='#E42217'>AMAZING Success</font></b>",
|
|
134 'G': " <b><font size=2 color='#306EFF'>Good Success</font></b>",
|
|
135 'O': " <b><font size=2 color='#52D017'>Ordinary Success</font></b>",
|
|
136 'F': " <b><font size=2 color='#41627E'>failure</font></b>"}
|
|
137
|
187
|
138 if ( self.d20 == 1 ): myStr += successes['CS'] # SEG Dec 19 2009
|
171
|
139 myStr += successes[self.success]
|
189
|
140 if ( self.d20 == 1 ) and (self.success == 'F') :
|
|
141 myStr += " final result ==> "
|
|
142 myStr += successes['O'] # SEG JAN 23 2010
|
171
|
143 return myStr
|
|
144
|
187
|
145 class at(sk):
|
|
146 ## Traipse Usage: The source I received had the damage rolls like this 1d6s, with the damage type a
|
|
147 ## letter that could be sliced from the roll. However, the roll is parsed before the letter can be
|
|
148 ## sliced from it, and with the letter attached it created an error.
|
|
149 ##
|
|
150 ## The Traipse method puts the damage type and the damage roll into a Tuple, ie (1d6, 's').
|
|
151 ## When using this method you must include single or double quoutes around the damage type or the
|
171
|
152 ## software will treat it as an object.
|
187
|
153
|
171
|
154 def __init__(self,source=[],sc=10, mod=0, dmgo="(1d6, 's')",dmgg="(1d6, 'w')",dmga="(1d6, 'm')"):
|
|
155 sk.__init__(self,source,sc,mod)
|
|
156 self.dmgo = dmgo
|
|
157 self.dmgg = dmgg
|
|
158 self.dmga = dmga
|
|
159
|
187
|
160 def getdmg(self,dmgroll):
|
|
161 astr = "<b>===></b> Damage "
|
171
|
162 droll = str(dmgroll[0])
|
187
|
163 xyz = droll.split('(')
|
|
164 secD = (int(xyz[1][:-1])/2) ## SEG* Calculate Secondary Damage
|
189
|
165
|
|
166 ## varN = "secD"
|
|
167 ## debug(varN)
|
|
168 ## debug(secD) ## seg added debug output
|
|
169
|
171
|
170 dtype = dmgroll[1]
|
|
171 astr += droll
|
187
|
172 if dtype=="s": astr += " <b><font size=2 color='#52D017'>stun</font></b><BR>"
|
|
173 elif dtype=="w":
|
|
174 astr += " <b><font size=2 color='#C11B17'>wound</font></b>"+" <b>======></b> Secondary Damage ("+str(secD) \
|
|
175 +") <b><font size=2 color='#52D017'>stun</font></b><BR>" # SEG* Display Secondary Damage
|
|
176 elif dtype=="m":
|
|
177 astr += " <b><font size=2 color='#FF0000'>mortal</font></b>"+" <b>======></b> Secondary Damage ("+str(secD) \
|
|
178 +") <b><font size=2 color='#52D017'>stun</font></b>"+" <b>/</b> ("+str(secD)+") <b><font size=2 color='#C11B17'>wound</font></b><BR>" # SEG* Display Secondary Damage
|
171
|
179 return astr
|
|
180
|
|
181 def __str__(self):
|
187
|
182 myStr = self.getRolLStr()
|
189
|
183
|
|
184 ## varN = "myStr"
|
|
185 ## debug(varN)
|
|
186 ## debug(myStr) ## seg added debug output
|
|
187
|
187
|
188 successes = {'CS': " <b><font size=2 color='#8D38C9'>CRITICAL SUCCESS</font></b>",
|
|
189 'CF': " <b><font size=2 color='#151B54'>CRITICAL FAILURE</font></b>",
|
|
190 'A': " <b><font size=2 color='#E42217'>AMAZING HIT</font></b><BR> ",
|
|
191 'G': " <b><font size=2 color='#306EFF'>Good HIT</font></b><BR> ",
|
|
192 'O': " <b><font size=2 color='#52D017'>Ordinary HIT</font></b><BR> ",
|
|
193 'F': " <b><font size=2 color='#41627E'>miss</font></b>"}
|
189
|
194 if ( self.d20 == 1 ):
|
|
195 myStr += successes['CS'] # SEG Dec 19 2009
|
|
196
|
|
197 if ( self.d20 == 1 ) and (self.success == 'F') :
|
|
198 myStr += successes['F'] # SEG JAN 23 2010
|
|
199 myStr += " final result ==> "
|
|
200 self.success = 'O'
|
|
201
|
187
|
202 myStr += successes[self.success]
|
|
203 if self.success == 'A': myStr += self.getdmg(self.dmga)
|
|
204 elif self.success == 'G': myStr += self.getdmg(self.dmgg)
|
|
205 elif self.success == 'O': myStr += self.getdmg(self.dmgo)
|
171
|
206 return myStr
|
187
|
207
|
|
208 class ac(sk):
|
|
209 def __init__(self,source=[],sc=10,mod=0):
|
|
210 sk.__init__(self,source,sc,mod)
|
|
211
|
189
|
212 def __str__(self):
|
|
213 myStr = self.getRolLStr()
|
187
|
214
|
189
|
215 ## varN = "myStr"
|
|
216 ## debug(varN)
|
|
217 ## debug(myStr) ## seg added debug output
|
|
218
|
187
|
219 myStr = " <b><font color='#E42217'>ACTION CHECK : </font></b>"+myStr
|
189
|
220 successes = {'CS': " <b><font size=2 color='#8D38C9'>CRITICAL SUCCESS</font></b>",
|
|
221 'CF': " <b><font size=2 color='#151B54'>CRITICAL FAILURE</font></b><BR> -2 Step make up bonus next Action Check",
|
|
222 'A': " <b><font size=2 color='#E42217'>AMAZING Success</font></b>",
|
|
223 'G': " <b><font size=2 color='#306EFF'>Good Success</font></b>",
|
|
224 'O': " <b><font size=2 color='#52D017'>Ordinary Success</font></b>",
|
|
225 'F': " <b><font size=2 color='#41627E'>Marginal failure</font></b>"}
|
187
|
226 if ( self.d20 == 1 ): myStr += successes['CS'] # SEG Dec 19 2009
|
|
227 myStr += successes[self.success]
|
189
|
228 if ( self.d20 == 1 ) and (self.success == 'F') :
|
|
229 myStr += " final result ==> "
|
|
230 myStr += successes['O'] # SEG JAN 23 2010
|
|
231 if ( self.d20 != 1 ) and (self.success == 'F') :
|
|
232 myStr += "<BR> -1 Step make up bonus next Action Check"
|
|
233
|
187
|
234 return myStr
|
|
235
|
|
236
|
|
237
|
|
238
|
|
239
|
|
240
|
|
241
|
|
242
|
|
243
|
|
244
|
|
245
|
|
246
|
|
247
|
|
248
|