Mercurial > traipse_dev
comparison orpg/dieroller/hackmaster.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 #!/usr/bin/env python | |
2 # Copyright Not Yet, see how much I trust you | |
3 # | |
4 # openrpg-dev@lists.sourceforge.net | |
5 # | |
6 # This program is free software; you can redistribute it and/or modify | |
7 # it under the terms of the GNU General Public License as published by | |
8 # the Free Software Foundation; either version 2 of the License, or | |
9 # (at your option) any later version. | |
10 # | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU General Public License for more details. | |
15 # | |
16 # You should have received a copy of the GNU General Public License | |
17 # along with this program; if not, write to the Free Software | |
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 # -- | |
20 # | |
21 # File: hackmaster.py | |
22 # Author: Ric Soard | |
23 # Maintainer: | |
24 # Version: | |
25 # $Id: hackmaster.py,v 0.4 2003/08/12 | |
26 # | |
27 # Description: special die roller for HackMaster(C)(TM) RPG | |
28 # has penetration damage - .damage(bonus,honor) | |
29 # has attack - .attack(bonus, honor) | |
30 # has severity .severity(honor) | |
31 # has help - .help() | |
32 # | |
33 # | |
34 import random | |
35 from die import * | |
36 | |
37 __version__ = "$Id: hackmaster.py,v 1.8 2006/11/15 12:11:22 digitalxero Exp $" | |
38 | |
39 #hackmaster Class basically passes into functional classes | |
40 class hackmaster(std): | |
41 def __init__(self,source=[]): | |
42 std.__init__(self,source) | |
43 | |
44 def damage(self, mod, hon): | |
45 return HMdamage(self, mod, hon) | |
46 | |
47 def attack(self, mod, hon): | |
48 return HMattack(self, mod, hon) | |
49 | |
50 def help(self): | |
51 return HMhelp(self) | |
52 | |
53 def severity(self, honor): | |
54 return HMSeverity(self, honor) | |
55 | |
56 | |
57 # HM Damage roller - rolles penetration as per the PHB - re-rolles on max die - 1, adds honor to the penetration rolls | |
58 # and this appears to be invisible to the user ( if a 4 on a d4 is rolled a 3 will appear and be followed by another | |
59 # die. if High honor then a 4 will appear followed by a another die. | |
60 class HMdamage(std): | |
61 def __init__(self,source=[], mod = 0, hon = 0): | |
62 std.__init__(self,source) | |
63 self.mod = mod | |
64 self.hon = hon | |
65 self.check_pen() | |
66 #here we roll the mod die | |
67 self.append(static_di(self.mod)) | |
68 #here we roll the honor die | |
69 self.append(static_di(self.hon)) | |
70 | |
71 def damage(mod = 0, hon = 0): | |
72 self.mod = mod | |
73 self.hon = hon | |
74 | |
75 # This function is called by default to display the die string to the chat window. | |
76 # Our die string attempts to explain the results | |
77 def __str__(self): | |
78 myStr = "Damage " | |
79 myStr += "[Damage Roll, Modifiers, Honor]: " + " [" + str(self.data[0]) | |
80 for a in self.data[1:]: | |
81 myStr += "," | |
82 myStr += str(a) | |
83 myStr += "] = (" + str(self.sum()) + ")" | |
84 | |
85 return myStr | |
86 | |
87 # This function checks to see if we need to reroll for penetration | |
88 def check_pen(self): | |
89 for i in range(len(self.data)): | |
90 if self.data[i].lastroll() >= self.data[i].sides: | |
91 self.pen_roll(i) | |
92 | |
93 #this function rolls the penetration die, and checks to see if it needs to be re-rolled again. | |
94 def pen_roll(self,num): | |
95 result = int(random.uniform(1,self.data[num].sides+1)) | |
96 self.data[num].value += (result - 1 + self.hon) | |
97 self.data[num].history.append(result - 1 + self.hon) | |
98 if result >= self.data[num].sides: | |
99 self.pen_roll(num) | |
100 | |
101 # this function rolls for the HM Attack. the function checks for a 20 and displays critical, and a 1 | |
102 # and displays fumble | |
103 class HMattack(std): | |
104 def __init__(self, source=[], mod = 0, base_severity = 0, hon = 0, size = 0): | |
105 std.__init__(self,source) | |
106 self.size = size | |
107 self.mod = mod | |
108 self.base_severity = base_severity | |
109 self.hon = hon | |
110 self.fumble = 0 | |
111 self.crit = 0 | |
112 self.check_crit() | |
113 #this is a static die that adds the modifier | |
114 self.append(static_di(self.mod)) | |
115 #this is a static die that adds honor, we want high rolls so it's +1 | |
116 self.append(static_di(self.hon)) | |
117 | |
118 | |
119 def check_crit(self): | |
120 if self.data[0] == self.data[0].sides: | |
121 self.crit = 1 | |
122 if self.data[0] == 1: | |
123 self.fumble = 1 | |
124 | |
125 | |
126 #this function is the out put to the chat window, it basicaly just displays the roll unless | |
127 #it's a natural 20, or a natural 1 | |
128 def __str__(self): | |
129 if self.crit > 0: | |
130 myStr = "Critical Hit!!: " | |
131 elif self.fumble > 0: | |
132 myStr = "FUMBLE!!" | |
133 else: | |
134 myStr = "To Hit:" | |
135 myStr += "[To Hit Roll, Modifiers, Honor]" + " [" + str(self.data[0]) | |
136 for a in self.data[1:]: | |
137 myStr += "," | |
138 myStr += str(a) | |
139 myStr += "] = (" + str(self.sum()) + ")" | |
140 return myStr | |
141 | |
142 class HMhelp(std): | |
143 def __init__(self,source=[]): | |
144 std.__init__(self,source) | |
145 self.source = source | |
146 | |
147 def __str__(self): | |
148 myStr = " <br /> .attack(Bonus, Honor): <br />" | |
149 myStr += " The attack roll rolles the dice and adds your bonus <br />" | |
150 myStr += " and honor modifier and returns you final roll. <br />" | |
151 myStr += " On a natural 20 the dieroller displays Critical Hit!! <br />" | |
152 myStr += " On a natural 1 the dieroller displays FUMBLE!! <br />" | |
153 myStr += " Example A 1st level fighter with +1 to hit and a +2 sword and High Honor <br />" | |
154 myStr += " would roll [1d20.attack(3,1)] <br />" | |
155 myStr += " .damage(Bonus, Honor): <br />" | |
156 myStr += " The damage roll rolls the dice and rerolls on a max roll for <br />" | |
157 myStr += " penetration damage, the penetration die is -1 and is rerolled on a max roll <br />" | |
158 myStr += " The roller returns the damage dice, monidifiers, and honor <br />" | |
159 myStr += " Example A magic-user uses a quaterstaff +1 with high honor, he would roll <br />" | |
160 myStr += " [1d6.damage(1,1)] <br />" | |
161 myStr += " .severity(honor): <br />" | |
162 myStr += " the severity is for critical hit resolution - the character rolls <br />" | |
163 myStr += " a d8 and adds honor bonus. the die is rerolled on natural 8 and natural 1 with a -1 modifier <br />" | |
164 myStr += " on an 8 the reroll is added on a 1 the reroll is subtracted <br />" | |
165 myStr += " Example [1d8.severity(1)] <br />" | |
166 myStr += " .help() : <br />" | |
167 myStr += " displays this message <br />" | |
168 | |
169 return myStr | |
170 | |
171 # the severity roll is for critical resolution. The die is rerolled and added | |
172 #on a natural 8 and rerolled and subtracted on a 1 | |
173 class HMSeverity(std): | |
174 def __init__(self, source =[], honor=0): | |
175 std.__init__(self,source) | |
176 self.source = source | |
177 self.hon = honor | |
178 self.data = [] | |
179 self.append(di(8)) | |
180 self.CheckReroll() | |
181 self.append(static_di(self.hon)) | |
182 | |
183 | |
184 def __str__(self): | |
185 myStr = "[Severity Dice, Honor]" + " [" + str(self.data[0]) | |
186 for a in self.data[1:]: | |
187 myStr += "," | |
188 myStr += str(a) | |
189 myStr += "] = (" + str(self.sum()) + ")" | |
190 return myStr | |
191 | |
192 def CheckReroll(self): | |
193 if self.data[0] == self.data[0].sides: | |
194 self.crit_chain(0,1) | |
195 if self.data[0] == 1: | |
196 self.crit_chain(0,-1) | |
197 | |
198 #this function needes moved for severity | |
199 def crit_chain(self,num,neg): | |
200 result = int(random.uniform(1,self.data[num].sides+1)) | |
201 self.data[num].value += (((result - 1) * neg) + self.hon) | |
202 self.data[num].history.append(((result - 1) * neg) + self.hon) | |
203 if result >= self.data[num].sides: | |
204 self.crit_chain(num,1) | |
205 if result == 1: | |
206 self.crit_chain(num,-1) |