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: d20.py
|
|
14 # Author: OpenRPG Dev Team
|
|
15 # Maintainer:
|
|
16 # Version:
|
195
|
17 # $Id: d20.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
|
167
|
18 #
|
|
19 # Description: d20 die roller
|
195
|
20 __version__ = "$Id: d20.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
|
167
|
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 def attack(self,AC,mod,critical):
|
|
34 return d20attack(self,AC,mod,critical)
|
|
35
|
|
36 def dc(self,DC,mod):
|
|
37 return d20dc(self,DC,mod)
|
|
38
|
|
39 die_rollers.register(d20)
|
|
40
|
|
41 class d20dc(std):
|
|
42 def __init__(self,source=[],DC=10,mod=0):
|
|
43 std.__init__(self,source)
|
|
44 self.DC = DC
|
|
45 self.mod = mod
|
|
46 self.append(static_di(mod))
|
|
47
|
|
48 def is_success(self):
|
|
49 return ((self.sum() >= self.DC or self.data[0] == 20) and self.data[0] != 1)
|
|
50
|
|
51 def __str__(self):
|
|
52 myStr = "[" + str(self.data[0])
|
|
53 for a in self.data[1:]:
|
|
54 myStr += ","
|
|
55 myStr += str(a)
|
|
56 myStr += "] = (" + str(self.sum()) + ")"
|
|
57 myStr += " vs DC " + str(self.DC)
|
195
|
58 if self.is_success(): myStr += " Success!"
|
|
59 else: myStr += " Failure!"
|
167
|
60 return myStr
|
|
61
|
|
62
|
|
63 class d20attack(std):
|
|
64 def __init__(self,source=[],AC=10,mod=0,critical=20):
|
|
65 std.__init__(self,source)
|
|
66 self.mod = mod
|
|
67 self.critical = critical
|
|
68 self.AC = AC
|
|
69 self.append(static_di(mod))
|
|
70 self.critical_check()
|
|
71
|
|
72 def attack(AC=10,mod=0,critical=20):
|
|
73 self.mod = mod
|
|
74 self.critical = critical
|
|
75 self.AC = AC
|
|
76
|
|
77 def critical_check(self):
|
|
78 self.critical_result = 0
|
|
79 self.critical_roll = 0
|
|
80 if self.data[0] >= self.critical and self.is_hit():
|
|
81 self.critical_roll = die_base(20) + self.mod
|
195
|
82 if self.critical_roll.sum() >= self.AC: self.critical_result = 1
|
167
|
83
|
|
84 def is_critical(self):
|
|
85 return self.critical_result
|
|
86
|
|
87 def is_hit(self):
|
|
88 return ((self.sum() >= self.AC or self.data[0] == 20) and self.data[0] != 1)
|
|
89
|
|
90 def __str__(self):
|
|
91 myStr = "[" + str(self.data[0])
|
|
92 for a in self.data[1:]:
|
|
93 myStr += ","
|
|
94 myStr += str(a)
|
|
95 myStr += "] = (" + str(self.sum()) + ")"
|
|
96 myStr += " vs AC " + str(self.AC)
|
195
|
97 if self.is_critical(): myStr += " Critical"
|
|
98 if self.is_hit(): myStr += " Hit!"
|
|
99 else: myStr += " Miss!"
|
|
100 return myStr
|
167
|
101
|