annotate orpg/tools/InterParse.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
children 0bc44a57ae6c
rev   line source
195
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
1 #!/usr/bin/env python
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
2 # Copyright (C) 2000-2010 The OpenRPG Project
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
3 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
4 # openrpg-dev@lists.sourceforge.net
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
5 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
6 # This program is free software; you can redistribute it and/or modify
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
7 # it under the terms of the GNU General Public License as published by
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
8 # the Free Software Foundation; either version 2 of the License, or
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
9 # (at your option) any later version.
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
10 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
14 # GNU General Public License for more details.
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
15 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
16 # You should have received a copy of the GNU General Public License
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
17 # along with this program; if not, write to the Free Software
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
19 # --
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
20 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
21 # File: InterParse.py
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
22 # Author:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
23 # Maintainer: Tyler Starke (Traipse)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
24 # Version:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
25 # $Id: InterParse.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
26 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
27 # Description: InterParse = Interpretor Parser. This class parses all of the node referencing.
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
28 #
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
29
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
30 from orpg.orpgCore import component
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
31 import re
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
32 from orpg.tools.orpg_log import logger
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
33 from wx import TextEntryDialog, ID_OK
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
34
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
35 class InterParse():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
36
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
37 def __init__(self):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
38 pass
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
39
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
40 def Post(self, s, send=False, myself=False):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
41 s = self.Normalize(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
42 component.get('chat').set_colors()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
43 component.get('chat').Post(s, send, myself)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
44
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
45 def ParseLogic(self, s, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
46 'Nodes now parse through ParsLogic. Easily add new parse rules right here!!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
47 s = self.NameSpaceE(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
48 s = self.NameSpaceI(s, node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
49 s = self.NodeMap(s, node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
50 s = self.NodeParent(s, node.get('map'))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
51 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
52
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
53 def Normalize(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
54 for plugin_fname in component.get('chat').activeplugins.keys():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
55 plugin = component.get('chat').activeplugins[plugin_fname]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
56 try: s = plugin.pre_parse(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
57 except Exception, e:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
58 if str(e) != "'module' object has no attribute 'post_msg'":
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
59 logger.general(traceback.format_exc())
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
60 logger.general("EXCEPTION: " + str(e))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
61 if component.get('chat').parsed == 0:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
62 s = self.NameSpaceE(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
63 s = self.Node(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
64 s = self.Dice(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
65 s = self.Filter(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
66 component.get('chat').parsed = 1
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
67 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
68
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
69 def Filter(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
70 s = component.get('chat').GetFilteredText(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
71 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
72
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
73 def Node(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
74 """Parses player input for embedded nodes rolls"""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
75 cur_loc = 0
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
76 #[a-zA-Z0-9 _\-\.]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
77 reg = re.compile("(!@(.*?)@!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
78 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
79 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
80 newstr = self.Node(self.resolve_nodes(matches[i][1]))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
81 s = s.replace(matches[i][0], newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
82 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
83
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
84 def Dice(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
85 """Parses player input for embedded dice rolls"""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
86 reg = re.compile("\[([^]]*?)\]")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
87 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
88 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
89 newstr = self.Unknown(matches[i])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
90 qmode = 0
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
91 newstr1 = newstr
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
92 if newstr[0].lower() == 'q':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
93 newstr = newstr[1:]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
94 qmode = 1
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
95 if newstr[0].lower() == '#':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
96 newstr = newstr[1:]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
97 qmode = 2
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
98 try: newstr = component.get('DiceManager').proccessRoll(newstr)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
99 except: pass
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
100 if qmode == 1:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
101 s = s.replace("[" + matches[i] + "]",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
102 "<!-- Official Roll [" + newstr1 + "] => " + newstr + "-->" + newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
103 elif qmode == 2:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
104 s = s.replace("[" + matches[i] + "]", newstr[len(newstr)-2:-1], 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
105 else: s = s.replace("[" + matches[i] + "]",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
106 "[" + newstr1 + "<!-- Official Roll -->] => " + newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
107 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
108
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
109 def Unknown(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
110 # Uses a tuple. Usage: ?Label}dY. If no Label is assigned then use ?}DY
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
111 newstr = "0"
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
112 reg = re.compile("(\?\{*)([a-zA-Z ]*)(\}*)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
113 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
114 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
115 lb = "Replace '?' with: "
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
116 if len(matches[i][0]):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
117 lb = matches[i][1] + "?: "
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
118 dlg = TextEntryDialog(component.get('chat'), lb, "Missing Value?")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
119 dlg.SetValue('')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
120 if matches[i][0] != '':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
121 dlg.SetTitle("Enter Value for " + matches[i][1])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
122 if dlg.ShowModal() == ID_OK: newstr = dlg.GetValue()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
123 if newstr == '': newstr = '0'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
124 s = s.replace(matches[i][0], newstr, 1).replace(matches[i][1], '', 1).replace(matches[i][2], '', 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
125 dlg.Destroy()
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
126 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
127
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
128 def NameSpaceI(self, s, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
129 reg = re.compile("(!=(.*?)=!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
130 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
131 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
132 tree_map = node.get('map').split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
133 root = self.get_node(tree_map[0])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
134 find = matches[i][1].split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
135 names = root.getiterator('nodehandler')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
136 for name in names:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
137 if find[0] == name.get('name'):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
138 if name.get('class') == 'rpg_grid_handler':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
139 newstr = self.NameSpaceGrid(find, name); break
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
140 else: newstr = str(name.find('text').text); break
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
141 else: newstr = 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
142 s = s.replace(matches[i][0], newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
143 s = self.ParseLogic(s, name)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
144 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
145
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
146 def NameSpaceE(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
147 reg = re.compile("(!&(.*?)&!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
148 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
149 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
150 find = matches[i][1].split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
151 root = find[0]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
152 root = self.get_node(root)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
153 names = root.getiterator('nodehandler')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
154 for name in names:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
155 if find[1] == name.get('name'):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
156 if name.get('class') == 'rpg_grid_handler':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
157 newstr = self.NameSpaceGrid([find[1], find[2]], name); break
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
158 else: newstr = str(name.find('text').text); break
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
159 else: newstr = 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
160 s = s.replace(matches[i][0], newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
161 s = self.ParseLogic(s, name)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
162 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
163
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
164 def NameSpaceGrid(self, s, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
165 cell = tuple(s[1].strip('(').strip(')').split(','))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
166 grid = node.find('grid')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
167 rows = grid.findall('row')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
168 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
169 try: s = self.ParseLogic(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
170 except: s = 'Invalid Grid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
171 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
172
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
173 def NodeMap(self, s, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
174 """Parses player input for embedded nodes rolls"""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
175 cur_loc = 0
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
176 reg = re.compile("(!!(.*?)!!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
177 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
178 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
179 tree_map = node.get('map')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
180 tree_map = tree_map + '::' + matches[i][1]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
181 newstr = '!@'+ tree_map +'@!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
182 s = s.replace(matches[i][0], newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
183 s = self.Node(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
184 s = self.NodeParent(s, tree_map)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
185 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
186
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
187 def NodeParent(self, s, tree_map):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
188 """Parses player input for embedded nodes rolls"""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
189 cur_loc = 0
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
190 reg = re.compile("(!#(.*?)#!)")
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
191 matches = reg.findall(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
192 for i in xrange(0,len(matches)):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
193 ## Build the new tree_map
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
194 new_map = tree_map.split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
195 del new_map[len(new_map)-1]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
196 parent_map = matches[i][1].split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
197 ## Backwards Reference the Parent Children
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
198 child_node = self.get_node('::'.join(new_map))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
199 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
200 s = s.replace(matches[i][0], newstr, 1)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
201 s = self.Node(s)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
202 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
203
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
204 def get_root(self, child_node, tree_map, new_map, parent_map):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
205 if child_node == 'Invalid Reference!': return child_node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
206 roots = child_node.getchildren(); tr = tree_map.split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
207 newstr = ''
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
208 for root in roots:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
209 try: t = new_map.index(root.get('name'))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
210 except: t = 1
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
211 if parent_map[0] == root.get('name'):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
212 newstr = '!@' + '::'.join(new_map[:len(tr)-t]) + '::' + '::'.join(parent_map) + '@!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
213 if newstr != '': return newstr
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
214 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
215 del new_map[len(new_map)-1]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
216 child_node = self.get_node('::'.join(new_map))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
217 newstr = self.get_root(child_node, tree_map, new_map, parent_map)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
218 return newstr
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
219
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
220 def get_node(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
221 return_node = 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
222 value = ""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
223 path = s.split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
224 depth = len(path)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
225 try: node = component.get('tree').tree_map[path[0]]['node']
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
226 except Exception, e: return return_node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
227 return_node = self.resolve_get_loop(node, path, 1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
228 return return_node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
229
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
230 def resolve_get_loop(self, node, path, step, depth):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
231 if step == depth: return node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
232 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
233 child_list = node.findall('nodehandler')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
234 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
235 if step == depth: break
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
236 if child.get('name') == path[step]:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
237 node = self.resolve_get_loop(child, path, step+1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
238 return node
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
239
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
240 def resolve_nodes(self, s):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
241 self.passed = False
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
242 string = 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
243 value = ""
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
244 path = s.split('::')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
245 depth = len(path)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
246 try: node = component.get('tree').tree_map[path[0]]['node']
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
247 except Exception, e: return string
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
248 if node.get('class') in ('dnd35char_handler',
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
249 "SWd20char_handler",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
250 "d20char_handler",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
251 "dnd3echar_handler"): string = self.resolve_cust_loop(node, path, 1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
252 elif node.get('class') == 'rpg_grid_handler': self.resolve_grid(node, path, 1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
253 else: string = self.resolve_loop(node, path, 1, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
254 return string
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
255
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
256 def resolve_loop(self, node, path, step, depth):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
257 if step == depth: return self.resolution(node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
258 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
259 child_list = node.findall('nodehandler')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
260 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
261 if step == depth: break
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
262 if child.get('name') == path[step]:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
263 node = child
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
264 step += 1
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
265 if node.get('class') in ('dnd35char_handler',
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
266 "SWd20char_handler",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
267 "d20char_handler",
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
268 "dnd3echar_handler"):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
269 string = self.resolve_cust_loop(node, path, step, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
270 elif node.get('class') == 'rpg_grid_handler':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
271 string = self.resolve_grid(node, path, step, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
272 else: string = self.resolve_loop(node, path, step, depth)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
273 return string
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
274
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
275 def resolution(self, node):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
276 if self.passed == False:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
277 self.passed = True
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
278 if node.get('class') == 'textctrl_handler':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
279 s = str(node.find('text').text)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
280 else: s = 'Nodehandler for '+ node.get('class') + ' not done!' or 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
281 else: s = ''
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
282 s = self.ParseLogic(s, node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
283 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
284
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
285 def resolve_grid(self, node, path, step, depth):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
286 if step == depth:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
287 return 'Invalid Grid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
288 cell = tuple(path[step].strip('(').strip(')').split(','))
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
289 grid = node.find('grid')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
290 rows = grid.findall('row')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
291 col = rows[int(self.Dice(cell[0]))-1].findall('cell')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
292 try: s = self.ParseLogic(col[int(self.Dice(cell[1]))-1].text, node) or 'No Cell Data'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
293 except: s = 'Invalid Grid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
294 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
295
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
296 def resolve_cust_loop(self, node, path, step, depth):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
297 s = 'Invalid Reference!'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
298 node_class = node.get('class')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
299 ## Code needs clean up. Either choose .lower() or .title(), then reset the path list's content ##
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
300 if step == depth: self.resolution(node)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
301 ##Build Abilities dictionary##
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
302 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('abilities')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
303 else: ab = node.find('abilities')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
304 ab_list = ab.findall('stat'); pc_stats = {}
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
305
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
306 for ability in ab_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
307 pc_stats[ability.get('name')] = (
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
308 str(ability.get('base')),
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
309 str((int(ability.get('base'))-10)/2) )
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
310 pc_stats[ability.get('abbr')] = (
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
311 str(ability.get('base')),
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
312 str((int(ability.get('base'))-10)/2) )
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
313
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
314 if node_class not in ('d20char_handler', "SWd20char_handler"): ab = node.find('character').find('saves')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
315 else: ab = node.find('saves')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
316 ab_list = ab.findall('save')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
317 for save in ab_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
318 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]) ) )
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
319 if save.get('name') == 'Fortitude': abbr = 'Fort'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
320 if save.get('name') == 'Reflex': abbr = 'Ref'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
321 if save.get('name') == 'Will': abbr = 'Will'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
322 pc_stats[abbr] = ( str(save.get('base')), str(int(save.get('magmod')) + int(save.get('miscmod')) + int(pc_stats[save.get('stat')][1]) ) )
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
323
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
324 if path[step].lower() == 'skill':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
325 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
326 node = node.find('skills')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
327 child_list = node.findall('skill')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
328 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
329 if path[step+1].lower() == child.get('name').lower():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
330 if step+2 == depth: s = child.get('rank')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
331 elif path[step+2].lower() == 'check':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
332 s = '<b>Skill Check:</b> ' + child.get('name') + ' [1d20+'+str( int(child.get('rank')) + int(pc_stats[child.get('stat')][1]) )+']'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
333 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
334
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
335 if path[step].lower() == 'feat':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
336 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snf')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
337 node = node.find('feats')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
338 child_list = node.findall('feat')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
339 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
340 if path[step+1].lower() == child.get('name').lower():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
341 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
342 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
343 if path[step].lower() == 'cast':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
344 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('snp')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
345 node = node.find('spells')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
346 child_list = node.findall('spell')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
347 for child in child_list:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
348 if path[step+1].lower() == child.get('name').lower():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
349 if step+2 == depth: s = '<b>'+child.get('name')+'</b>'+': '+child.get('desc')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
350 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
351 if path[step].lower() == 'attack':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
352 if node_class not in ('d20char_handler', "SWd20char_handler"): node = node.find('combat')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
353 if path[step+1].lower() == 'melee' or path[step+1].lower() == 'm':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
354 bonus_text = '(Melee)'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
355 bonus = node.find('attacks')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
356 bonus = bonus.find('melee')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
357 bonus = bonus.attrib; d = int(pc_stats['Str'][1])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
358 elif path[step+1].lower() == 'ranged' or path[step+1].lower() == 'r':
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
359 bonus_text = '(Ranged)'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
360 bonus = node.find('attacks')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
361 bonus = bonus.find('ranged')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
362 bonus = bonus.attrib; d = int(pc_stats['Dex'][1])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
363 for b in bonus:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
364 d += int(bonus[b])
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
365 bonus = str(d)
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
366 if path[step+2] == None: s= bonus
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
367 else:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
368 weapons = node.find('attacks')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
369 weapons = weapons.findall('weapon')
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
370 for child in weapons:
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
371 if path[step+2].lower() == child.get('name').lower():
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
372 s = '<b>Attack: '+bonus_text+'</b> '+child.get('name')+' [1d20+'+bonus+'] ' + 'Damage: ['+child.get('damage')+']'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
373 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
374 elif pc_stats.has_key(path[step].title()):
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
375 if step+1 == depth: s = pc_stats[path[step].title()][0] + ' +('+pc_stats[path[step].title()][1]+')'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
376 elif path[step+1].title() == 'Mod': s = pc_stats[path[step].title()][1]
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
377 elif path[step+1].title() == 'Check': s = '<b>'+path[step].title()+' Check:</b> [1d20+'+str(pc_stats[path[step].title()][1])+']'
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
378 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
379 return s
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
380
b633f4c64aae Traipse Alpha 'OpenRPG' {100219-00}
sirebral
parents:
diff changeset
381 Parse = InterParse()