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