comparison orpg/tools/InterParse.py @ 191:a3d7e05085da beta

Traipse Beta 'OpenRPG' {100201-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: New Bookmarks Feature New 'boot' command to remote admin New confirmation window for sent nodes Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG New Zoom Mouse plugin added New Images added to Plugin UI Switching to Element Tree New Map efficiency, from FlexiRPG New Status Bar to Update Manager New TrueDebug Class in orpg_log (See documentation for usage) New Portable Mercurial New Tip of the Day, 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 New Dieroller structure from Core New DieRoller portability for odd Dice New 7th Sea die roller; ie [7k3] = [7d10.takeHighest(3).open(10)] New 'Mythos' System die roller 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!) New Grids act more like Spreadsheets in Use mode, with Auto Calc Fixes: Fix to allow for portability to an OpenSUSE linux OS Fix to mplay_client for Fedora and OpenSUSE 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 Fix to whiteboard ID's to prevent non updated clients from ruining the fix. default_manifest.xml renamed to default_upmana.xml
author sirebral
date Mon, 01 Feb 2010 09:57:07 -0600
parents
children fb08f5731b5e
comparison
equal deleted inserted replaced
190:15488fe94f52 191:a3d7e05085da
1 from orpg.orpgCore import component
2 import re
3 from orpg.tools.orpg_log import logger
4
5 class InterParse():
6
7 def __init__(self):
8 pass
9
10 def Post(self, s, send=False, myself=False):
11 s = self.Normalize(s)
12 component.get('chat').set_colors()
13 component.get('chat').Post(s,send,myself)
14
15 def Normalize(self, s):
16 for plugin_fname in component.get('chat').activeplugins.keys():
17 plugin = component.get('chat').activeplugins[plugin_fname]
18 try: s = plugin.pre_parse(s)
19 except Exception, e:
20 if str(e) != "'module' object has no attribute 'post_msg'":
21 logger.general(traceback.format_exc())
22 logger.general("EXCEPTION: " + str(e))
23 if component.get('chat').parsed == 0:
24 s = self.Node(s)
25 s = self.Dice(s)
26 s = self.Filter(s)
27 component.get('chat').parsed = 1
28 return s
29
30 def Filter(self, s):
31 s = component.get('chat').GetFilteredText(s)
32 return s
33
34 def Node(self, s):
35 """Parses player input for embedded nodes rolls"""
36 cur_loc = 0
37 #[a-zA-Z0-9 _\-\.]
38 reg = re.compile("(!@(.*?)@!)")
39 matches = reg.findall(s)
40 for i in xrange(0,len(matches)):
41 newstr = self.Node(self.resolve_nodes(matches[i][1]))
42 s = s.replace(matches[i][0], newstr, 1)
43 return s
44
45 def Dice(self, s):
46 """Parses player input for embedded dice rolls"""
47 reg = re.compile("\[([^]]*?)\]")
48 matches = reg.findall(s)
49 for i in xrange(0,len(matches)):
50 newstr = self.Unknown(matches[i])
51 qmode = 0
52 newstr1 = newstr
53 if newstr[0].lower() == 'q':
54 newstr = newstr[1:]
55 qmode = 1
56 if newstr[0].lower() == '#':
57 newstr = newstr[1:]
58 qmode = 2
59 try: newstr = component.get('DiceManager').proccessRoll(newstr)
60 except: pass
61 if qmode == 1:
62 s = s.replace("[" + matches[i] + "]",
63 "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1)
64 elif qmode == 2:
65 s = s.replace("[" + matches[i] + "]", newstr[len(newstr)-2:-1], 1)
66 else: s = s.replace("[" + matches[i] + "]",
67 "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1)
68 return s
69
70 def Unknown(self, s):
71 # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY
72 newstr = "0"
73 reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)")
74 matches = reg.findall(s)
75 for i in xrange(0,len(matches)):
76 lb = "Replace '?' with: "
77 if len(matches[i][0]):
78 lb = matches[i][1] + "?: "
79 dlg = wx.TextEntryDialog(self, lb, "Missing Value?")
80 dlg.SetValue('')
81 if matches[i][0] != '':
82 dlg.SetTitle("Enter Value for " + matches[i][1])
83 if dlg.ShowModal() == wx.ID_OK: newstr = dlg.GetValue()
84 if newstr == '': newstr = '0'
85 s = s.replace(matches[i][0], newstr, 1).replace(matches[i][1], '', 1).replace(matches[i][2], '', 1)
86 dlg.Destroy()
87 return s
88
89 def NodeMap(self, s, node):
90 """Parses player input for embedded nodes rolls"""
91 cur_loc = 0
92 reg = re.compile("(!!(.*?)!!)")
93 matches = reg.findall(s)
94 for i in xrange(0,len(matches)):
95 tree_map = node.get('map')
96 tree_map = tree_map + '::' + matches[i][1]
97 newstr = '!@'+ tree_map +'@!'
98 s = s.replace(matches[i][0], newstr, 1)
99 s = self.Node(s)
100 s = self.NodeParent(s, tree_map)
101 return s
102
103 def NodeParent(self, s, tree_map):
104 """Parses player input for embedded nodes rolls"""
105 cur_loc = 0
106 reg = re.compile("(!#(.*?)#!)")
107 matches = reg.findall(s)
108 for i in xrange(0,len(matches)):
109 ## Build the new tree_map
110 new_map = tree_map.split('::')
111 del new_map[len(new_map)-1]
112 parent_map = matches[i][1].split('::')
113 ## Backwards Reference the Parent Children
114 child_node = self.get_node('::'.join(new_map))
115 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
116 s = s.replace(matches[i][0], newstr, 1)
117 s = self.Node(s)
118 return s
119
120 def get_root(self, child_node, tree_map, new_map, parent_map):
121 if child_node == 'Invalid Reference!': return child_node
122 roots = child_node.getchildren(); tr = tree_map.split('::')
123 newstr = ''
124 for root in roots:
125 try: t = new_map.index(root.get('name'))
126 except: t = 1
127 if parent_map[0] == root.get('name'):
128 newstr = '!@' + '::'.join(new_map[:len(tr)-t]) + '::' + '::'.join(parent_map) + '@!'
129 if newstr != '': return newstr
130 else:
131 del new_map[len(new_map)-1]
132 child_node = self.get_node('::'.join(new_map))
133 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
134 return newstr
135
136 def get_node(self, s):
137 return_node = 'Invalid Reference!'
138 value = ""
139 path = s.split('::')
140 depth = len(path)
141 try: node = component.get('tree').tree_map[path[0]]['node']
142 except Exception, e: return return_node
143 return_node = self.resolve_get_loop(node, path, 1, depth)
144 return return_node
145
146 def resolve_get_loop(self, node, path, step, depth):
147 if step == depth: return node
148 else:
149 child_list = node.findall('nodehandler')
150 for child in child_list:
151 if step == depth: break
152 if child.get('name') == path[step]:
153 node = self.resolve_get_loop(child, path, step+1, depth)
154 return node
155
156 def resolve_nodes(self, s):
157 self.passed = False
158 string = 'Invalid Reference!'
159 value = ""
160 path = s.split('::')
161 depth = len(path)
162 try: node = component.get('tree').tree_map[path[0]]['node']
163 except Exception, e: return string
164 if node.get('class') in ('dnd35char_handler',
165 "SWd20char_handler",
166 "d20char_handler",
167 "dnd3echar_handler"): string = self.resolve_cust_loop(node, path, 1, depth)
168 elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, 1, depth)
169 else: string = self.resolve_loop(node, path, 1, depth)
170 return string
171
172 def resolve_loop(self, node, path, step, depth):
173 if step == depth: return self.resolution(node)
174 else:
175 child_list = node.findall('nodehandler')
176 for child in child_list:
177 if step == depth: break
178 if child.get('name') == path[step]:
179 node = child
180 step += 1
181 if node.get('class') in ('dnd35char_handler',
182 "SWd20char_handler",
183 "d20char_handler",
184 "dnd3echar_handler"):
185 string = self.resolve_cust_loop(node, path, step, depth)
186 elif node.get('class') == 'rpg_grid_handler':
187 string = self.resolve_grid(node, path, step, depth)
188 else: string = self.resolve_loop(node, path, step, depth)
189 return string
190
191 def resolution(self, node):
192 if self.passed == False:
193 self.passed = True
194 if node.get('class') == 'textctrl_handler':
195 s = str(node.find('text').text)
196 else: s = 'Nodehandler for '+ node.get('class') + ' not done!' or 'Invalid Reference!'
197 else:
198 s = ''
199 s = self.NodeMap(s, node)
200 s = self.NodeParent(s, node.get('map'))
201 return s
202
203 def resolve_grid(self, node, path, step, depth):
204 if step == depth:
205 return 'Invalid Grid Reference!'
206 cell = tuple(path[step].strip('(').strip(')').split(','))
207 grid = node.find('grid')
208 rows = grid.findall('row')
209 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
210 try: s = self.NodeMap(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
211 except: s = 'Invalid Grid Reference!'
212 return s
213
214 def resolve_cust_loop(self, node, path, step, depth):
215 s = 'Invalid Reference!'
216 node_class = node.get('class')
217 ## Code needs clean up. Either choose .lower() or .title(), then reset the path list's content ##
218 if step == depth: self.resolution(node)
219 ##Build Abilities dictionary##
220 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('abilities')
221 else: ab = node.find('abilities')
222 ab_list = ab.findall('stat'); pc_stats = {}
223
224 for ability in ab_list:
225 pc_stats[ability.get('name')] = (
226 str(ability.get('base')),
227 str((int(ability.get('base'))-10)/2) )
228 pc_stats[ability.get('abbr')] = (
229 str(ability.get('base')),
230 str((int(ability.get('base'))-10)/2) )
231
232 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('saves')
233 else: ab = node.find('saves')
234 ab_list = ab.findall('save')
235 for save in ab_list:
236 pc_stats[save.get('name')] = (str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) )
237 if save.get('name') == 'Fortitude': abbr = 'Fort'
238 if save.get('name') == 'Reflex': abbr = 'Ref'
239 if save.get('name') == 'Will': abbr = 'Will'
240 pc_stats[abbr] = ( str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) )
241
242 if path[step].lower() == 'skill':
243 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
244 node = node.find('skills')
245 child_list = node.findall('skill')
246 for child in child_list:
247 if path[step+1].lower() == child.get('name').lower():
248 if step+2 == depth: s = child.get('rank')
249 elif path[step+2].lower() == 'check':
250 s = '<b>Skill Check:</b> ' + child.get('name') + ' [1d20+'+str( int(child.get('rank')) + int(pc_stats[child.get('stat')][1]) )+']'
251 print s
252 return s
253
254 if path[step].lower() == 'feat':
255 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
256 node = node.find('feats')
257 child_list = node.findall('feat')
258 for child in child_list:
259 if path[step+1].lower() == child.get('name').lower():
260 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
261 return s
262 if path[step].lower() == 'cast':
263 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snp')
264 node = node.find('spells')
265 child_list = node.findall('spell')
266 for child in child_list:
267 if path[step+1].lower() == child.get('name').lower():
268 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
269 return s
270 if path[step].lower() == 'attack':
271 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('combat')
272 if path[step+1].lower() == 'melee' or path[step+1].lower() == 'm':
273 bonus_text = '(Melee)'
274 bonus = node.find('attacks')
275 bonus = bonus.find('melee')
276 bonus = bonus.attrib; d = int(pc_stats['Str'][1])
277 elif path[step+1].lower() == 'ranged' or path[step+1].lower() == 'r':
278 bonus_text = '(Ranged)'
279 bonus = node.find('attacks')
280 bonus = bonus.find('ranged')
281 bonus = bonus.attrib; d = int(pc_stats['Dex'][1])
282 for b in bonus:
283 d += int(bonus[b])
284 bonus = str(d)
285 if path[step+2] == None: s= bonus
286 else:
287 weapons = node.find('attacks')
288 weapons = weapons.findall('weapon')
289 for child in weapons:
290 if path[step+2].lower() == child.get('name').lower():
291 s = '<b>Attack: '+bonus_text+'</b> '+child.get('name')+' [1d20+'+bonus+'] ' + 'Damage: ['+child.get('damage')+']'
292 return s
293 elif pc_stats.has_key(path[step].title()):
294 if step+1 == depth: s = pc_stats[path[step].title()][0] + ' +('+pc_stats[path[step].title()][1]+')'
295 elif path[step+1].title() == 'Mod': s = pc_stats[path[step].title()][1]
296 elif path[step+1].title() == 'Check': s = '<b>'+path[step].title()+' Check:</b> [1d20+'+str(pc_stats[path[step].title()][1])+']'
297 return s
298 return s
299
300 Parse = InterParse()