comparison plugins/xxinit.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 from string import find, replace
4 import orpg.dirpath
5
6 class Plugin(orpg.pluginhandler.PluginHandler):
7 # Initialization subroutine.
8 #
9 # !self : instance of self
10 # !chat : instance of the chat window to write to
11 def __init__(self, plugindb, parent):
12 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
13
14 # The Following code should be edited to contain the proper information
15 self.name = 'Initiative Tool'
16 self.author = 'Woody, Darloth, updated by mDuo13'
17 self.help = "This is the ever-popular init tool. To learn how to use it, type\n"
18 self.help += "'/init help'. It will load the a help node into your game tree."
19
20 self.toggle = ''
21 self.init_list = ''
22 self.backup_list = ''
23 self.tool_type = ''
24 self.wod_counter = ''
25
26 def plugin_enabled(self):
27 #This is where you set any variables that need to be initalized when your plugin starts
28
29 self.plugin_addcommand('/init', self.on_init, '[help|type|clear|new|start|add|del|list|sortlow|sorthigh|run|go|change] - Init tool. Use /init help to get details about how to use the tool')
30
31
32 self.toggle = 1
33 self.init_list = []
34 self.backup_list = []
35 self.tool_type = 'std'
36 self.wod_counter = 0
37
38 def plugin_disabled(self):
39 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
40 #such as closing windows created by the plugin
41 self.plugin_removecmd('/init')
42
43 def on_init(self, cmdargs):
44 #this is just an example function for a command you create create your own
45 args = cmdargs.split(None,-1)
46
47 if len(args) == 0:
48 if self.toggle:
49 self.toggle = 0
50 self.post_my_msg("<font color='#ff0000'>Init recording off</font>")
51 else:
52 self.post_my_msg("<font color='#ff0000'>Init recording on</font>")
53 self.toggle = 1
54 elif args[0] == 'help':
55 f = open(orpg.dirpath.dir_struct["plugins"]+ "inittool.xml","r")
56 self.gametree.insert_xml(f.read())
57 f.close()
58 elif args[0] == 'type':
59 if len(args) == 2:
60 if args[1] == 'std' or args[1] == 'wod' or args[1] == '3e' or args[1] == 'srun':
61 self.tool_type = args[1]
62 self.post_my_msg("<font color='#ff0000'>Initiative tool now set to '" + self.tool_type + "'</font>")
63 else:
64 self.post_my_msg("<font color='#ff0000'>Unknown Initiative tool type: " + args[1])
65 else:
66 self.chat.Post("<font color='#ff0000'>currently using the '" + self.tool_type + "' Initiative tool type</font>")
67 elif args[0] == 'clear' or args[0] == 'new' or args[0] == 'start':
68 self.init_list = []
69 self.backup_list = []
70 self.post_my_msg("<hr><font color='#ff0000'>New Initiative</font><br /><font color='#0000ff'>Roll new Initiatives</font>",1)
71 elif args[0] == 'add':
72 try:
73 new_init = int(args[1])
74 self.init_list += [[new_init, args[2]]]
75 self.backup_list += [[new_init, arge[2]]]
76 self.list_inits()
77 except:
78 self.post_my_msg("<font color='#ff0000'>Invalid format. correct command is: /add init_number description</font>")
79 elif args[0] == 'del':
80 try:
81 del self.init_list[int(args[1])-1]
82 del self.backup_list[int(args[1])-1]
83 self.list_inits()
84 except:
85 self.post_my_msg("<font color='#ff0000'>Invalid format. correct command is: /del list_number</font>")
86 elif args[0] == 'list':
87 self.list_inits()
88 elif args[0] == 'backuplist':
89 self.list_backups()
90 elif args[0] == 'sortlow':
91 self.init_list.sort()
92 self.backup_list.sort()
93 self.list_inits()
94 elif args[0] == 'sorthigh':
95 self.init_list.sort()
96 self.init_list.reverse()
97 self.backup_list.sort()
98 self.backup_list.reverse()
99 self.list_inits()
100 elif args[0] == 'run' or args[0] == 'go':
101 if len(self.init_list):
102 id = str(self.init_list[0][0])
103 player = str(self.init_list[0][1])
104 del self.init_list[0]
105 self.post_my_msg("<hr><font color='#ff0000'>Next init:</font><br /><font color='#0000ff'><b>("+id+")</b>: "+player+"</font>",1)
106 else:
107 if self.tool_type == 'std' or (self.tool_type == 'wod' and self.wod_counter == 1):
108 self.backup_list = []
109 self.init_list = []
110 self.wod_counter = 0
111 self.post_my_msg("<hr><font color='#ff0000'>End of Initiative Round</font>",1)
112 elif self.tool_type == '3e':
113 self.init_list += self. backup_list
114 self.post_my_msg("<hr><font color='#ff0000'>End of Initiative Round, Starting New Initiative Round</font>",1)
115 elif self.tool_type == 'wod' and self.wod_counter == 0 and len(self.backup_list) > 0:
116 self.post_my_msg("<hr><font color='#ff0000'>Starting physical initiatives:</font>",1)
117 self.wod_counter = 1
118 self.init_list = self.backup_list
119 self.init_list.sort()
120 self.init_list.reverse()
121 elif self.tool_type == 'srun':
122 for m in self.backup_list[:]:
123 m[0] -= 10
124 if m[0] <= 10:
125 self.backup_list.remove(m)
126 if len(self.backup_list):
127 self.post_my_msg("<hr><font color='#ff0000'>End of Initiative Pass, starting next Pass</font>",1)
128 self.init_list += self.backup_list
129 else:
130 self.post_my_msg("<hr><font color='#ff0000'>End of Combat Turn, roll new initiatives please</font>",1)
131 self.init_list = []
132 self.backup_list = []
133 elif args[0] == 'change':
134 try:
135 id = int(args[1])
136 new_init = int(args[2])
137 self.init_list[id][0] = new_init
138 self.backup_list[id][0] = new_init
139 self.list_inits()
140 except:
141 self.post_my_msg("<font color='#0000ff'>Invalid format. correct command is: /change list_# new_init_# (example: /change 1 4)</font>")
142 else:
143 self.post_my_msg("<font color='#0000ff'>Invalid Command, type /init help and read the manual please</font>")
144
145 def post_msg(self, text, myself):
146 if self.toggle:
147 if myself == 1:
148 if text.lower().find("init") != -1:
149 player = text[:text.find("[")]
150 init = text[text.rfind("(")+1:text.rfind(")")]
151 else:
152 if text.lower().find("init") != -1:
153 player=text[text.find("</B>")+4:text.find("[")]
154 init=text[text.rfind("(")+1:text.rfind(")")]
155 try:
156 if text.lower().find("init") != -1:
157 init = int(init)
158 self.init_list += [[init,player]]
159 self.backup_list += [[init,player]]
160 except:
161 pass
162 return text
163
164
165 def post_my_msg(self, msg, send=0):
166 tmp = self.toggle
167 self.toggle = 0
168 self.chat.Post(msg,send)
169 self.toggle = tmp
170
171
172 def list_inits(self):
173 msg = 'Initiatives:<br />'
174 for m in self.init_list:
175 msg += " <font color='#ff0000'>" + str(self.init_list.index(m) + 1) + "</font>"
176 msg += ": <font color='#0000ff'>(" + str(m[0]) + ") "
177 msg += m[1] + "</font><br />"
178 self.post_my_msg(msg)
179
180
181 def list_backups(self):
182 msg = 'backup list:<br />'
183 for m in self.backup_list:
184 msg += " <font color='#ff0000'>" + str(self.backup_list.index(m) + 1) + "</font>"
185 msg += ": <font color='#0000ff'>(" + str(m[0]) + ") "
186 msg += m[1] + "</font><br />"
187 self.post_my_msg(msg)