comparison orpg/dieroller/utils.py @ 184:dcae32e219f1 beta

Traipse Beta 'OpenRPG' {100117-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 (Beta) New Features: Added Bookmarks Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) Portable Mercurial Tip of the Day added, from Core and community New Reference Syntax added for custom PC sheets New Child Reference for gametree New Parent Reference for gametree New Gametree Recursion method, mapping, context sensitivity, and effeciency.. New Features node with bonus nodes and Node Referencing help added Dieroller structure from Core New DieRoller portability for odd Dice Added 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller added Added new vs. die roller method for WoD; ie [3v3] = [3d10.vs(3)]. Included for Mythos roller also New Warhammer FRPG Die Roller (Special thanks to Puu-san for the support) New EZ_Tree Reference system. Push a button, Traipse the tree, get a reference (Beta!) Fixes: Fix to Text based Server Fix to Remote Admin Commands Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Fix to Map from gametree not showing to all clients Fix to gametree about menus Fix to Password Manager check on startup Fix to PC Sheets from tool nodes. They now use the tabber_panel Fix to Whiteboard ID to prevent random line or text deleting. Fixes to Server, Remote Server, and Server GUI Fix to Update Manager; cleaner clode for saved repositories Fixes made to Settings Panel and now reactive settings when Ok is pressed Fixes to Alternity roller's attack roll. Uses a simple Tuple instead of a Splice Fix to Use panel of Forms and Tabbers. Now longer enters design mode Fix made Image Fetching. New fetching image and new failed image Modified ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Sun, 17 Jan 2010 21:37:34 -0600
parents 0d9b746b5751
children 56c1f2729413
comparison
equal deleted inserted replaced
183:0d9b746b5751 184:dcae32e219f1
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