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: d20.py
|
|
14 # Author: OpenRPG Dev Team
|
|
15 # Maintainer:
|
|
16 # Version:
|
|
17 # $Id: d20.py,v 1.9 2006/11/04 21:24:19 digitalxero Exp $
|
|
18 #
|
|
19 # Description: d20 die roller
|
|
20 __version__ = "$Id: d20.py,v 1.9 2006/11/04 21:24:19 digitalxero Exp $"
|
|
21
|
|
22 # d20 stands for "d20 system" not 20 sided die :)
|
|
23
|
|
24 from std import std
|
|
25 from orpg.dieroller.base import *
|
|
26
|
|
27 class d20(std):
|
|
28 name = "d20"
|
|
29
|
|
30 def __init__(self,source=[]):
|
|
31 std.__init__(self,source)
|
|
32
|
|
33 # these methods return new die objects for specific options
|
|
34
|
|
35 def attack(self,AC,mod,critical):
|
|
36 return d20attack(self,AC,mod,critical)
|
|
37
|
|
38 def dc(self,DC,mod):
|
|
39 return d20dc(self,DC,mod)
|
|
40
|
|
41 die_rollers.register(d20)
|
|
42
|
|
43 class d20dc(std):
|
|
44 def __init__(self,source=[],DC=10,mod=0):
|
|
45 std.__init__(self,source)
|
|
46 self.DC = DC
|
|
47 self.mod = mod
|
|
48 self.append(static_di(mod))
|
|
49
|
|
50 def is_success(self):
|
|
51 return ((self.sum() >= self.DC or self.data[0] == 20) and self.data[0] != 1)
|
|
52
|
|
53 def __str__(self):
|
|
54 myStr = "[" + str(self.data[0])
|
|
55 for a in self.data[1:]:
|
|
56 myStr += ","
|
|
57 myStr += str(a)
|
|
58 myStr += "] = (" + str(self.sum()) + ")"
|
|
59
|
|
60 myStr += " vs DC " + str(self.DC)
|
|
61
|
|
62 if self.is_success():
|
|
63 myStr += " Success!"
|
|
64 else:
|
|
65 myStr += " Failure!"
|
|
66
|
|
67 return myStr
|
|
68
|
|
69
|
|
70 class d20attack(std):
|
|
71 def __init__(self,source=[],AC=10,mod=0,critical=20):
|
|
72 std.__init__(self,source)
|
|
73 self.mod = mod
|
|
74 self.critical = critical
|
|
75 self.AC = AC
|
|
76 self.append(static_di(mod))
|
|
77 self.critical_check()
|
|
78
|
|
79 def attack(AC=10,mod=0,critical=20):
|
|
80 self.mod = mod
|
|
81 self.critical = critical
|
|
82 self.AC = AC
|
|
83
|
|
84 def critical_check(self):
|
|
85 self.critical_result = 0
|
|
86 self.critical_roll = 0
|
|
87 if self.data[0] >= self.critical and self.is_hit():
|
|
88 self.critical_roll = die_base(20) + self.mod
|
|
89 if self.critical_roll.sum() >= self.AC:
|
|
90 self.critical_result = 1
|
|
91
|
|
92 def is_critical(self):
|
|
93 return self.critical_result
|
|
94
|
|
95 def is_hit(self):
|
|
96 return ((self.sum() >= self.AC or self.data[0] == 20) and self.data[0] != 1)
|
|
97
|
|
98 def __str__(self):
|
|
99 myStr = "[" + str(self.data[0])
|
|
100 for a in self.data[1:]:
|
|
101 myStr += ","
|
|
102 myStr += str(a)
|
|
103 myStr += "] = (" + str(self.sum()) + ")"
|
|
104
|
|
105 myStr += " vs AC " + str(self.AC)
|
|
106
|
|
107 if self.is_critical():
|
|
108 myStr += " Critical"
|
|
109
|
|
110 if self.is_hit():
|
|
111 myStr += " Hit!"
|
|
112 else:
|
|
113 myStr += " Miss!"
|
|
114
|
|
115 return myStr
|