Mercurial > traipse_dev
comparison plugins/xxgvm.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | c54768cffbd4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 import os | |
2 import orpg.pluginhandler | |
3 import string | |
4 | |
5 class Plugin(orpg.pluginhandler.PluginHandler): | |
6 # Initialization subroutine. | |
7 # | |
8 # !self : instance of self | |
9 # !openrpg : instance of the the base openrpg control | |
10 def __init__(self, plugindb, parent): | |
11 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent) | |
12 | |
13 # The Following code should be edited to contain the proper information | |
14 self.name = 'Game Variable Manager' | |
15 self.author = 'mDuo13' | |
16 self.help = 'This plugin is used to manage variables in your idle status. That way,\n' | |
17 self.help += 'you can keep as many numbers as you want in your idle status, and you can update \n' | |
18 self.help += 'them without having to go to the Settings menu.\n' | |
19 self.help += '\n' | |
20 self.help += 'First you must create some variables. You can do that by typing \n' | |
21 self.help += '"/gvm set *var*=*value*" where *var* is the variables name (no $ symbol), and\n' | |
22 self.help += '*value* is the variables starting value. The variables name can be any word,\n' | |
23 self.help += 'but dont put spaces between the variables name and value.\n' | |
24 self.help += '\n' | |
25 self.help += 'You can look up the value of a variable by typing "/gvm get *var*"\n' | |
26 self.help += '\n' | |
27 self.help += 'To set your status, type "/gvm status *message*" where *message* is the message \n' | |
28 self.help += 'you want your status to have. To include variables, simply the variables name, \n' | |
29 self.help += 'STARTING WITH A $ SYMBOL. For example, you could create a status with \n' | |
30 self.help += '"/gvm status HP:$hp MP:$mp AC:$ac" which, if $hp was 20, $mp was 10, and $ac\n' | |
31 self.help += 'was 5, would make your status "HP:20 MP:10 AC:5".\n' | |
32 self.help += '\n' | |
33 self.help += 'If you later change the values of any of the variables in your status, they will \n' | |
34 self.help += 'be automatically updated; to update a value, just type\n' | |
35 self.help += '"/gvm set *var*=*variable*" the same way you used it to create the variable.\n' | |
36 self.help += '\n' | |
37 self.help += 'You can list the current variables with the "/gvm list" command. You can also\n' | |
38 self.help += 'now roll dice with curly brackets, and have filters apply to them, like this:\n' | |
39 self.help += '"{4d6.takeHighest(3)+$bonus}". Any other filters you have (i.e. the Alias \n' | |
40 self.help += 'Library) will also apply to curly bracket rolls automatically.\n' | |
41 self.help += '\n' | |
42 self.help += 'Note that the GVM plugin conflicts with the NowPlaying and GSC plugins, so if\n' | |
43 self.help += 'you have both plugin enabled at the same time, they may not work quite right.\n' | |
44 self.help += '\n' | |
45 self.help += 'You can now save a group of variables with "/gvm save *name*". You can also load\n' | |
46 self.help += 'a group of previously saved variables with "/gvm open *name*"\n' | |
47 | |
48 #You can set variables below here. Always set them to a blank value in this section. Use plugin_enabled | |
49 #to set their proper values. | |
50 self.vars = {} | |
51 self.status_scrip="" | |
52 self.status_on=0 | |
53 | |
54 | |
55 def plugin_enabled(self): | |
56 #You can add new /commands like | |
57 # self.plugin_addcommand(cmd, function, helptext) | |
58 self.plugin_addcommand('/gvm', self.on_gvm, '[set name=value | calc name=value | get name | status | list | save set_name | open set_name] - This plugin is used to manage variables that you can use in your status bar or in dice rolls') | |
59 self.plugin_addcommand('/gvmq', self.on_gvmq, '[set name=value | calc name=value | get name | status | list | save set_name | open set_name] - This plugin is used to manage variables that you can use in your status bar or in dice rolls', False) | |
60 self.plugin_addcommand('/=', self.on_comment, '', False) | |
61 | |
62 def plugin_disabled(self): | |
63 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin | |
64 #such as closing windows created by the plugin | |
65 self.plugin_removecmd('/gvm') | |
66 self.plugin_removecmd('/gvmq') | |
67 self.plugin_removecmd('/=') | |
68 | |
69 def on_comment(self, cmdargs): | |
70 pass | |
71 | |
72 def on_gvm(self, cmdargs): | |
73 for key in self.vars.keys(): | |
74 cmdargs = cmdargs.replace("$" + key, self.vars[key]) | |
75 | |
76 args = cmdargs.split(None,-1) | |
77 if len(args) == 0: | |
78 args = [' '] | |
79 if args[0]=="set": | |
80 cmd = cmdargs[len(args[0])+1:].strip().split("=") | |
81 self.vars[cmd[0]] = cmd[1] | |
82 self.chat.InfoPost("GVM: Set variable $" + cmd[0] + " to be: " + cmd[1]) | |
83 if self.status_on: | |
84 self.gvm_status(self.status_scrip) | |
85 | |
86 elif args[0]=="calc": | |
87 cmd = cmdargs[len(args[0])+1:].strip().split("=") | |
88 val = str(eval(cmd[1])) | |
89 self.vars[cmd[0]] = val | |
90 self.chat.InfoPost("GVM: Set variable $" + cmd[0] + " to be: " + val) | |
91 if self.status_on: | |
92 self.gvm_status(self.status_scrip) | |
93 | |
94 elif args[0]=="get": | |
95 if args[1] in self.vars.keys(): | |
96 self.chat.InfoPost("GVM: Variable $" + args[1] + " is: " + self.vars[args[1]]) | |
97 else: | |
98 self.chat.InfoPost("GVM: Variable $" + args[1] + " does not exist!") | |
99 | |
100 elif args[0]=="status": | |
101 self.status_scrip = cmdargs[len(args[0])+1:] | |
102 status_on = 1 | |
103 self.gvm_status(self.status_scrip) | |
104 | |
105 elif args[0]=="save": | |
106 fname = cmdargs[len(args[0])+1:] | |
107 self.plugindb.SetDict("xxgvm", fname, self.vars) | |
108 self.chat.InfoPost("GVM: Successfully saved variable set " + fname + "!") | |
109 | |
110 elif args[0]=="open": | |
111 fname = cmdargs[len(args[0])+1:] | |
112 self.vars = self.plugindb.GetDict("xxgvm", fname, {}) | |
113 self.chat.InfoPost("GVM: Loaded the file " + fname + ". Variables contained are:<br />" + self.make_list()) | |
114 | |
115 elif args[0] == "list": | |
116 self.chat.Post(self.make_list()) | |
117 | |
118 else: | |
119 self.chat.InfoPost("GVM: SYNTAX ERROR. <br />USEAGE: /gvm [set name=value | get name | status | list | save set_name | open set_name]") | |
120 | |
121 def on_gvmq(self, cmdargs): | |
122 for key in self.vars.keys(): | |
123 cmdargs = cmdargs.replace("$" + key, self.vars[key]) | |
124 args = cmdargs.split(None,-1) | |
125 if len(args) == 0: | |
126 args = [' '] | |
127 if args[0]=="set": | |
128 cmd = cmdargs[len(args[0])+1:].strip().split("=") | |
129 self.vars[cmd[0]] = cmd[1] | |
130 if self.status_on: | |
131 self.gvm_status(self.status_scrip) | |
132 | |
133 elif args[0]=="calc": | |
134 cmd = cmdargs[len(args[0])+1:].strip().split("=") | |
135 self.vars[cmd[0]] = str(eval(cmd[1])) | |
136 if self.status_on: | |
137 self.gvm_status(self.status_scrip) | |
138 | |
139 elif args[0]=="get": | |
140 if args[1] in self.vars.keys(): | |
141 self.chat.InfoPost("GVM: Variable $" + args[1] + " is: " + self.vars[args[1]]) | |
142 else: | |
143 self.chat.InfoPost("GVM: Variable $" + args[1] + " does not exist!") | |
144 | |
145 elif args[0]=="status": | |
146 self.status_scrip = cmdargs[len(args[0])+1:] | |
147 status_on = 1 | |
148 self.gvm_status(self.status_scrip) | |
149 | |
150 elif args[0]=="save": | |
151 fname = cmdargs[len(args[0])+1:] | |
152 self.plugindb.SetDict("xxgvm", fname, self.vars) | |
153 | |
154 elif args[0]=="open": | |
155 fname = cmdargs[len(args[0])+1:] | |
156 self.vars = self.plugindb.GetDict("xxgvm", fname, {}) | |
157 | |
158 elif args[0] == "list": | |
159 self.chat.Post(self.make_list()) | |
160 | |
161 else: | |
162 self.chat.InfoPost("GVM: SYNTAX ERROR. <br />USEAGE: /gvmq [set name=value | get name | status | list | save set_name | open set_name]") | |
163 | |
164 | |
165 def pre_parse(self, text): | |
166 try: | |
167 for key in self.vars.keys(): | |
168 text = text.replace("$" + key, self.vars[key]) | |
169 except Exception, e: | |
170 print e | |
171 print key | |
172 self.vars[key] | |
173 | |
174 return text | |
175 | |
176 def gvm_status(self, cmd): | |
177 keychain = self.vars.keys() | |
178 keychain.sort() | |
179 newchain = [] | |
180 for key in keychain: | |
181 newchain = [key] + newchain | |
182 for key in keychain: | |
183 cmd = cmd.replace("$" + key, self.vars[key]) | |
184 self.settings.set_setting("IdleStatusAlias", cmd) | |
185 self.session.set_text_status(cmd) | |
186 | |
187 def make_list(self): | |
188 keychain = self.vars.keys() | |
189 lister = "" | |
190 for key in keychain: | |
191 lister += "$" + key + "\t::\t" + self.vars[key] + "<br />" | |
192 if len(keychain)==0: | |
193 return "No variables!" | |
194 else: | |
195 return lister |