comparison orpg/dieroller/utils.py @ 66:c54768cffbd4 ornery-dev

Traipse Dev 'OpenRPG' {090818-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: *Unstable* This is the first wave of Code Refinement updates. Includes new material from Core Beta; new debugger material (partially implemented), beginnings of switch to etree, TerminalWriter, and a little more. open_rpg has been renamed to component; functioning now as component.get(), component.add(), component.delete(). This version has known bugs, specifically with the gametree and nodes. I think the XML files where not removed during testing of Core and switching back.
author sirebral
date Tue, 18 Aug 2009 06:33:37 -0500
parents 4385a7d0efd1
children 449a8900f9ac
comparison
equal deleted inserted replaced
65:4840657c23c5 66:c54768cffbd4
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 from orpg.orpgCore import component
45 46
46 import re 47 import re
47 48
48 rollers = ['std','wod','d20','hero','shadowrun', 'sr4','hackmaster','srex','wodex', 'gurps', 'runequest', 'sw', 'trinity'] 49 rollers = ['std','wod','d20','hero','shadowrun', 'sr4','hackmaster','srex','wodex', 'gurps', 'runequest', 'sw', 'trinity']
49 50
50 class roller_manager: 51 class roller_manager:
51 def __init__(self,roller_class="d20"): 52 def __init__(self,roller_class="d20"):
52 try: 53 try: self.setRoller(roller_class)
53 self.setRoller(roller_class) 54 except: self.roller_class = "std"
54 except:
55 self.roller_class = "std"
56 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
64 def getRoller(self): 62 def getRoller(self):
65 return self.roller_class 63 return self.roller_class
66 64
67 def listRollers(self): 65 def listRollers(self):
69 67
70 def stdDieToDClass(self,match): 68 def stdDieToDClass(self,match):
71 s = match.group(0) 69 s = match.group(0)
72 (num,sides) = s.split('d') 70 (num,sides) = s.split('d')
73 71
74 if sides.strip().upper() == 'F': 72 if sides.strip().upper() == 'F': sides = "'f'"
75 sides = "'f'"
76
77 try: 73 try:
78 if int(num) > 100 or int(sides) > 10000: 74 if int(num) > 100 or int(sides) > 10000:
79 return None 75 return None
80 except: 76 except: pass
81 pass
82
83 return "(" + num.strip() + "**" + self.roller_class + "(" + sides.strip() + "))" 77 return "(" + num.strip() + "**" + self.roller_class + "(" + sides.strip() + "))"
84 78
85 # Use this to convert ndm-style (3d6) dice to d_base format 79 # Use this to convert ndm-style (3d6) dice to d_base format
86 def convertTheDieString(self,s): 80 def convertTheDieString(self,s):
87 reg = re.compile("\d+\s*[a-zA-Z]+\s*[\dFf]+") 81 reg = re.compile("\d+\s*[a-zA-Z]+\s*[\dFf]+")
89 if num_matches == 0 or result is None: 83 if num_matches == 0 or result is None:
90 try: 84 try:
91 s2 = self.roller_class + "(0)." + s 85 s2 = self.roller_class + "(0)." + s
92 test = eval(s2) 86 test = eval(s2)
93 return s2 87 return s2
94 except: 88 except: pass
95 pass
96 return result 89 return result
97
98 90
99 def proccessRoll(self,s): 91 def proccessRoll(self,s):
100 return str(eval(self.convertTheDieString(s))) 92 return str(eval(self.convertTheDieString(s)))
93 #component.add('dieroller', roller_manager())