Mercurial > traipse_dev
comparison orpg/dieroller/d20.py @ 71:449a8900f9ac ornery-dev
Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author | sirebral |
---|---|
date | Thu, 20 Aug 2009 03:00:39 -0500 |
parents | 4385a7d0efd1 |
children | bf799efe7a8a |
comparison
equal
deleted
inserted
replaced
70:52a5fa913008 | 71:449a8900f9ac |
---|---|
23 __version__ = "$Id: d20.py,v 1.9 2006/11/04 21:24:19 digitalxero Exp $" | 23 __version__ = "$Id: d20.py,v 1.9 2006/11/04 21:24:19 digitalxero Exp $" |
24 | 24 |
25 # d20 stands for "d20 system" not 20 sided die :) | 25 # d20 stands for "d20 system" not 20 sided die :) |
26 | 26 |
27 class d20(std): | 27 class d20(std): |
28 | |
28 def __init__(self,source=[]): | 29 def __init__(self,source=[]): |
29 std.__init__(self,source) | 30 std.__init__(self,source) |
30 | 31 |
31 # these methods return new die objects for specific options | 32 # these methods return new die objects for specific options |
32 | 33 |
34 | |
33 def attack(self,AC,mod,critical): | 35 def attack(self,AC,mod,critical): |
34 return d20attack(self,AC,mod,critical) | 36 return d20attack(self,AC,mod,critical) |
35 | 37 |
38 | |
36 def dc(self,DC,mod): | 39 def dc(self,DC,mod): |
37 return d20dc(self,DC,mod) | 40 return d20dc(self,DC,mod) |
38 | 41 |
39 class d20dc(std): | 42 class d20dc(std): |
43 | |
40 def __init__(self,source=[],DC=10,mod=0): | 44 def __init__(self,source=[],DC=10,mod=0): |
41 std.__init__(self,source) | 45 std.__init__(self,source) |
42 self.DC = DC | 46 self.DC = DC |
43 self.mod = mod | 47 self.mod = mod |
44 self.append(static_di(mod)) | 48 self.append(static_di(mod)) |
45 | 49 |
50 | |
46 def is_success(self): | 51 def is_success(self): |
47 return ((self.sum() >= self.DC or self.data[0] == 20) and self.data[0] != 1) | 52 return ((self.sum() >= self.DC or self.data[0] == 20) and self.data[0] != 1) |
48 | 53 |
54 | |
49 def __str__(self): | 55 def __str__(self): |
50 myStr = "[" + str(self.data[0]) | 56 myStr = "[" + str(self.data[0]) |
51 for a in self.data[1:]: | 57 for a in self.data[1:]: |
52 myStr += "," | 58 myStr += "," |
53 myStr += str(a) | 59 myStr += str(a) |
62 | 68 |
63 return myStr | 69 return myStr |
64 | 70 |
65 | 71 |
66 class d20attack(std): | 72 class d20attack(std): |
73 | |
67 def __init__(self,source=[],AC=10,mod=0,critical=20): | 74 def __init__(self,source=[],AC=10,mod=0,critical=20): |
68 std.__init__(self,source) | 75 std.__init__(self,source) |
69 self.mod = mod | 76 self.mod = mod |
70 self.critical = critical | 77 self.critical = critical |
71 self.AC = AC | 78 self.AC = AC |
72 self.append(static_di(mod)) | 79 self.append(static_di(mod)) |
73 self.critical_check() | 80 self.critical_check() |
74 | 81 |
82 | |
75 def attack(AC=10,mod=0,critical=20): | 83 def attack(AC=10,mod=0,critical=20): |
76 self.mod = mod | 84 self.mod = mod |
77 self.critical = critical | 85 self.critical = critical |
78 self.AC = AC | 86 self.AC = AC |
79 | 87 |
88 | |
80 def critical_check(self): | 89 def critical_check(self): |
81 self.critical_result = 0 | 90 self.critical_result = 0 |
82 self.critical_roll = 0 | 91 self.critical_roll = 0 |
83 if self.data[0] >= self.critical and self.is_hit(): | 92 if self.data[0] >= self.critical and self.is_hit(): |
84 self.critical_roll = die_base(20) + self.mod | 93 self.critical_roll = die_base(20) + self.mod |
85 if self.critical_roll.sum() >= self.AC: | 94 if self.critical_roll.sum() >= self.AC: |
86 self.critical_result = 1 | 95 self.critical_result = 1 |
87 | 96 |
97 | |
88 def is_critical(self): | 98 def is_critical(self): |
89 return self.critical_result | 99 return self.critical_result |
90 | 100 |
101 | |
91 def is_hit(self): | 102 def is_hit(self): |
92 return ((self.sum() >= self.AC or self.data[0] == 20) and self.data[0] != 1) | 103 return ((self.sum() >= self.AC or self.data[0] == 20) and self.data[0] != 1) |
93 | 104 |
105 | |
94 def __str__(self): | 106 def __str__(self): |
95 myStr = "[" + str(self.data[0]) | 107 myStr = "[" + str(self.data[0]) |
96 for a in self.data[1:]: | 108 for a in self.data[1:]: |
97 myStr += "," | 109 myStr += "," |
98 myStr += str(a) | 110 myStr += str(a) |