Mercurial > traipse
comparison orpg/dieroller/utils.py @ 18:97265586402b ornery-orc
Traipse 'OpenRPG' {090827-00}
Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc''s main goal is to offer more advanced features and enhance the productivity of the user.
Update Summary:
Update Manager is now in version 0.8. While not every button works, users can now browse the different revisions and their different changesets. The code has been refined some with feature from Core added to it. A Crash report is now created if the users software crashes. Update Manager has been moved to the Traipse Suite menu item, and a Debug Console as been added as well.
author | sirebral |
---|---|
date | Thu, 27 Aug 2009 01:04:43 -0500 |
parents | 4385a7d0efd1 |
children | 51428d30c59e |
comparison
equal
deleted
inserted
replaced
17:265b987cce4f | 18:97265586402b |
---|---|
40 from srex import * | 40 from srex import * |
41 from gurps import * | 41 from gurps import * |
42 from runequest import * | 42 from runequest import * |
43 from savage import * | 43 from savage import * |
44 from trinity import * | 44 from trinity import * |
45 | |
46 import re | 45 import re |
47 | 46 |
48 rollers = ['std','wod','d20','hero','shadowrun', 'sr4','hackmaster','srex','wodex', 'gurps', 'runequest', 'sw', 'trinity'] | 47 rollers = ['std','wod','d20','hero','shadowrun', 'sr4','hackmaster','srex','wodex', 'gurps', 'runequest', 'sw', 'trinity'] |
49 | 48 |
50 class roller_manager: | 49 class roller_manager: |
50 | |
51 def __init__(self,roller_class="d20"): | 51 def __init__(self,roller_class="d20"): |
52 try: | 52 try: self.setRoller(roller_class) |
53 self.setRoller(roller_class) | 53 except: self.roller_class = "std" |
54 except: | |
55 self.roller_class = "std" | |
56 | 54 |
55 | |
57 def setRoller(self,roller_class): | 56 def setRoller(self,roller_class): |
58 try: | 57 try: |
59 rollers.index(roller_class) | 58 rollers.index(roller_class) |
60 self.roller_class = roller_class | 59 self.roller_class = roller_class |
61 except: | 60 except: raise Exception, "Invalid die roller!" |
62 raise Exception, "Invalid die roller!" | |
63 | 61 |
62 | |
64 def getRoller(self): | 63 def getRoller(self): |
65 return self.roller_class | 64 return self.roller_class |
66 | 65 |
66 | |
67 def listRollers(self): | 67 def listRollers(self): |
68 return rollers | 68 return rollers |
69 | 69 |
70 | |
70 def stdDieToDClass(self,match): | 71 def stdDieToDClass(self,match): |
71 s = match.group(0) | 72 s = match.group(0) |
72 (num,sides) = s.split('d') | 73 (num,sides) = s.split('d') |
73 | 74 |
74 if sides.strip().upper() == 'F': | 75 if sides.strip().upper() == 'F': sides = "'f'" |
75 sides = "'f'" | |
76 | |
77 try: | 76 try: |
78 if int(num) > 100 or int(sides) > 10000: | 77 if int(num) > 100 or int(sides) > 10000: |
79 return None | 78 return None |
80 except: | 79 except: pass |
81 pass | |
82 | |
83 return "(" + num.strip() + "**" + self.roller_class + "(" + sides.strip() + "))" | 80 return "(" + num.strip() + "**" + self.roller_class + "(" + sides.strip() + "))" |
84 | 81 |
85 # Use this to convert ndm-style (3d6) dice to d_base format | 82 # Use this to convert ndm-style (3d6) dice to d_base format |
83 | |
86 def convertTheDieString(self,s): | 84 def convertTheDieString(self,s): |
87 reg = re.compile("\d+\s*[a-zA-Z]+\s*[\dFf]+") | 85 reg = re.compile("\d+\s*[a-zA-Z]+\s*[\dFf]+") |
88 (result, num_matches) = reg.subn(self.stdDieToDClass, s) | 86 (result, num_matches) = reg.subn(self.stdDieToDClass, s) |
89 if num_matches == 0 or result is None: | 87 if num_matches == 0 or result is None: |
90 try: | 88 try: |
91 s2 = self.roller_class + "(0)." + s | 89 s2 = self.roller_class + "(0)." + s |
92 test = eval(s2) | 90 test = eval(s2) |
93 return s2 | 91 return s2 |
94 except: | 92 except: pass |
95 pass | |
96 return result | 93 return result |
97 | 94 |
98 | 95 |
99 def proccessRoll(self,s): | 96 def proccessRoll(self,s): |
100 return str(eval(self.convertTheDieString(s))) | 97 return str(eval(self.convertTheDieString(s))) |
98 | |
99 DiceManager = roller_manager |