167
|
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 #
|
|
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,
|
|
26 # unused objects have been replace with re-usable objects, and the code has been condensed.
|
|
27
|
|
28
|
|
29 import re
|
|
30
|
|
31 from std import std
|
|
32 from time import time, clock
|
|
33 from orpg.dieroller.base import di, die_base, die_rollers
|
|
34
|
|
35 __version__ = "$Id: alternity.py,v 0.1 2003/01/02 12:00:00 cchriss Exp $"
|
|
36
|
|
37 # Alternity stands for "Alternity system" 20 sided die plus mods
|
|
38
|
|
39 class alternity(std):
|
|
40 name = "alternity" # ADDED by SEG Nov 2009 ***
|
|
41
|
|
42 def __init__(self,source=[]):
|
|
43 std.__init__(self,source)
|
|
44
|
|
45 # these methods return new die objects for specific options
|
|
46 def sk(self,score,mod):
|
|
47 return sk(self,score,mod)
|
|
48
|
|
49 def at(self,score,mod,dmgo,dmgg,dmga):
|
|
50 return at(self,score,mod,dmgo,dmgg,dmga)
|
|
51
|
|
52 die_rollers.register(alternity)
|
|
53
|
|
54 class sk(std):
|
|
55 def __init__(self,source=[],sc="10/5/2",mod=0):
|
|
56 std.__init__(self,source)
|
|
57 m = re.match( r"\d+", str(sc) )
|
|
58 self.score = int( m.group(0) )
|
|
59 self.mod = mod
|
|
60
|
|
61 def getMod(self,mod=0):
|
|
62 m=0
|
|
63 mods = { -4: -di(12), -3: -di(8), -2: -di(6), -1: -di(4), 1: -di(4),
|
|
64 2: di(6), 3: di(8), 4: di(12), 5: di(20)}
|
|
65 if mod in mods.keys(): m = mods[mod].value
|
|
66 elif mod <= -5: m=-di(20).value
|
|
67 elif mod == 6: m=di(20).value + di(20).value
|
|
68 elif mod >= 7: m=di(20).value + di(20).value + di(20).value
|
|
69 return m
|
|
70
|
|
71 def getRolLStr(self):
|
|
72 myStr = "[" + str(self.data[0])
|
|
73 self.d20 = self.sum()
|
|
74 amod = self.getMod(self.mod)
|
|
75 self.dieRoll = self.d20 + amod
|
|
76 for a in self.data[1:]:
|
|
77 myStr += ","
|
|
78 myStr += str(a)
|
|
79 myStr += "," + str(amod) + "] = (" + str(self.dieRoll) + ")"
|
|
80 if ( self.d20 == 1 ): self.success = 'CS'
|
|
81 if ( self.dieRoll <= self.score / 4 ): self.success = 'A'
|
|
82 elif ( self.dieRoll <= self.score / 2 ): self.success = 'G'
|
|
83 elif ( self.dieRoll <= self.score ): self.success = 'O'
|
|
84 else: self.success = 'F'
|
|
85 if ( self.d20 == 20 ): self.success = 'CF'
|
|
86 return myStr
|
|
87
|
|
88 def __str__(self):
|
|
89 myStr = self.getRolLStr()
|
|
90 successes = {'CS': " <b><font color='#00aa00'>CRITICAL SUCCESS</font></b>",
|
|
91 'CF': " <b><font color='#ff0000'>CRITICAL FAILURE</font></b>",
|
|
92 'A': " <b>AMAZING Success</b>",
|
|
93 'G': " <b>Good Success</b>",
|
|
94 'O': " <b>Ordinary Success</b>",
|
|
95 'F': " <b>failure</b>"}
|
|
96 myStr += successes[self.success]
|
|
97 return myStr
|
|
98
|
|
99 class at(sk):
|
|
100 ## Traipse Usage: The source I received had the damage rolls like this 1d6s, with the damage type a
|
|
101 ## letter that could be sliced from the roll. However, the roll is parsed before the letter can be
|
|
102 ## sliced from it, and with the letter attached it created an error.
|
|
103 ##
|
|
104 ## The Traipse method puts the damage type and the damage roll into a Tuple, ie (1d6, 's').
|
|
105 ## When uing this method you must include single or double quoutes around the damage type or the
|
|
106 ## software will treat it as an object.
|
|
107 def __init__(self,source=[],sc=10, mod=0, dmgo="(1d6, 's')",dmgg="(1d6, 'w')",dmga="(1d6, 'm')"):
|
|
108 sk.__init__(self,source,sc,mod)
|
|
109 self.dmgo = dmgo
|
|
110 self.dmgg = dmgg
|
|
111 self.dmga = dmga
|
|
112
|
|
113 def getdmg(self,dmgroll):
|
|
114 astr = "===> Damage "
|
|
115 droll = str(dmgroll[0])
|
|
116 dtype = dmgroll[1]
|
|
117 astr += droll
|
|
118 if dtype=="s": astr += " stun"
|
|
119 elif dtype=="w": astr += " wound"
|
|
120 elif dtype=="m":astr += " mortal"
|
|
121 return astr
|
|
122
|
|
123 def __str__(self):
|
|
124 myStr = self.getRolLStr()
|
|
125 successes = {'CS': " <b><font color='#00aa00'>CRITICAL SUCCESS</font></b>",
|
|
126 'CF': " <b><font color='#ff0000'>CRITICAL FAILURE</font></b>",
|
|
127 'A': " <b><font color='#00aa00'>AMAZING HIT</font></b> ",
|
|
128 'G': " <b>Good HIT</b> ",
|
|
129 'O': " <b>Ordinary HIT</b> ",
|
|
130 'F': " <b>miss</b>"}
|
|
131 myStr += successes[self.success]
|
|
132 if self.success == 'A': myStr += self.getdmg(self.dmga)
|
|
133 elif self.success == 'G': myStr += self.getdmg(self.dmgg)
|
|
134 elif self.success == 'O': myStr += self.getdmg(self.dmgo)
|
|
135 return myStr
|
|
136
|