Mercurial > traipse_dev
comparison orpg/dieroller/utils.py @ 195:b633f4c64aae alpha
Traipse Alpha 'OpenRPG' {100219-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 (Patch-2)
New Features:
New Namespace method with two new syntaxes
Fixes:
Fix to Server GUI startup errors
Fix to Server GUI Rooms tab updating
Fix to Chat and Settings if non existant die roller is picked
Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated
Fix to Alias Lib's Export to Tree, Open, Save features
Fix to alias node, now works properly
Fix to Splitter node, minor GUI cleanup
author | sirebral |
---|---|
date | Sat, 24 Apr 2010 08:37:20 -0500 |
parents | 5609ac142298 |
children |
comparison
equal
deleted
inserted
replaced
182:4b2884f29a72 | 195:b633f4c64aae |
---|---|
20 # | 20 # |
21 # File: dieroller/utils.py | 21 # File: dieroller/utils.py |
22 # Author: OpenRPG Team | 22 # Author: OpenRPG Team |
23 # Maintainer: | 23 # Maintainer: |
24 # Version: | 24 # Version: |
25 # $Id: utils.py,v 1.22 2007/05/05 05:30:10 digitalxero Exp $ | 25 # $Id: utils.py,v Traipse 'Ornery-Orc' prof.ebral Exp $ |
26 # | 26 # |
27 # Description: Classes to help manage the die roller | 27 # Description: Classes to help manage the die roller |
28 # | 28 # |
29 | 29 |
30 __version__ = "$Id: utils.py,v 1.22 2007/05/05 05:30:10 digitalxero Exp $" | 30 __version__ = "$Id: utils.py,v Traipse 'Ornery-Orc' prof.ebral Exp Exp $" |
31 | 31 |
32 import re | 32 import re |
33 | 33 |
34 import orpg.dieroller.rollers | 34 import orpg.dieroller.rollers |
35 from orpg.dieroller.base import die_rollers | 35 from orpg.dieroller.base import die_rollers |
54 | 54 |
55 def listRollers(self): | 55 def listRollers(self): |
56 return die_rollers.keys() | 56 return die_rollers.keys() |
57 | 57 |
58 def stdDieToDClass(self, match): | 58 def stdDieToDClass(self, match): |
59 s = match.group(0) | 59 s = match.group(0); self.eval = str(match.string) |
60 self.mod = str(match.string[len(s):]) | |
61 num_sides = s.split('d') | 60 num_sides = s.split('d') |
62 if len(num_sides) > 1: | 61 if len(num_sides) > 1: |
63 num_sides; num = num_sides[0]; sides = num_sides[1] | 62 num_sides; num = num_sides[0]; sides = num_sides[1] |
64 if sides.strip().upper() == 'F': sides = "'f'" | 63 if sides.strip().upper() == 'F': sides = "'f'" |
65 try: | 64 try: |
66 if int(num) > 100 or int(sides) > 10000: return None | 65 if int(num) > 100 or int(sides) > 10000: return None |
67 except: pass | 66 except: pass |
68 ret = ['(', num.strip(), "**die_rollers['", self.getRoller(), "'](", | 67 ret = ['(', num.strip(), "**die_rollers['", self.getRoller(), "'](", |
69 sides.strip(), '))'+self.mod] | 68 sides.strip(), '))'] |
70 s = ''.join(ret); s = str(eval(s)); return s ## Moved eval here for portability. | 69 s = ''.join(ret) |
70 self.eval = s | |
71 return s | |
72 | |
71 ## Portable Non Standard Die Characters #Prof-Ebral | 73 ## Portable Non Standard Die Characters #Prof-Ebral |
72 else: s = die_rollers._rollers[self.getRoller()]().non_stdDie(s); self.mod = ''; return s | 74 else: s = die_rollers._rollers[self.getRoller()]().non_stdDie(s); return s |
73 | 75 |
74 # Use this to convert ndm-style (3d6) dice to d_base format | 76 # Use this to convert ndm-style (3d6) dice to d_base format |
75 def convertTheDieString(self,s): | 77 def convertTheDieString(self,s): |
78 self.result = '' | |
76 reg = re.compile("(?:\d+|\([0-9\*/\-\+]+\))\s*[a-zA-Z]+\s*[\dFf]+") | 79 reg = re.compile("(?:\d+|\([0-9\*/\-\+]+\))\s*[a-zA-Z]+\s*[\dFf]+") |
77 (result, num_matches) = reg.subn(self.stdDieToDClass, s) | 80 (result, num_matches) = reg.subn(self.stdDieToDClass, s) |
78 if num_matches == 0 or result is None: | 81 if num_matches == 0 or result is None: |
79 reg = re.compile("(?:\d+|\([0-9\*/\-\+]+\))\s*[a-zA-Z]+\s*[a-zA-Z]+") ## Prof Ebral | 82 reg = re.compile("(?:\d+|\([0-9\*/\-\+]+\))\s*[a-zA-Z]+\s*[a-zA-Z]+") ## Prof Ebral |
80 (result, num_matches) = reg.subn(self.stdDieToDClass, s) ## Prof Ebral | 83 (result, num_matches) = reg.subn(self.stdDieToDClass, s) ## Prof Ebral |
81 """try: ## Kinda pointless when you can create new Regular Expressions | 84 """try: ## Kinda pointless when you can create new Regular Expressions |
82 s2 = self.roller_class + "(0)." + s ## Broken method | 85 s2 = self.roller_class + "(0)." + s ## Broken method |
83 test = eval(s2) | 86 test = eval(s2) |
84 return s2 | 87 return s2 |
85 except Exception, e: print e; pass""" | 88 except Exception, e: print e; pass""" |
89 self.result = result | |
86 try: return self.do_math(s) | 90 try: return self.do_math(s) |
87 except: pass | 91 except: pass |
88 return result | 92 return result |
89 | 93 |
90 def do_math(self, s): | 94 def do_math(self, s): |
91 self.mod = '' | |
92 return str(eval(s)) | 95 return str(eval(s)) |
93 | 96 |
94 def proccessRoll(self, s): | 97 def proccessRoll(self, s): |
95 v = str(self.convertTheDieString(s)) | 98 v = self.convertTheDieString(s) |
96 return v[:len(v)-len(self.mod)] | 99 try: b = str(eval(v)) |
100 except: | |
101 if v == self.eval: b = s | |
102 else: b = str(v) ##Fail safe for non standard dice. | |
103 return b | |
97 | 104 |