comparison plugins/xxheroinit.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
4 class Plugin(orpg.pluginhandler.PluginHandler):
5 # Initialization subroutine.
6 #
7 # !self : instance of self
8 # !openrpg : instance of the the base openrpg control
9 def __init__(self, plugindb, parent):
10 orpg.pluginhandler.PluginHandler.__init__(self, plugindb, parent)
11
12 # The Following code should be edited to contain the proper information
13 self.name = 'Hero Turn Tool'
14 self.author = 'Heroman, based on xxxinit.py'
15 self.help = """This is the Hero Games turn turn. It is a bit more complex than other games."""
16
17
18 def plugin_enabled(self):
19 #You can add new /commands like
20 # self.plugin_addcommand(cmd, function, helptext)
21 self.plugin_addcommand('/hinit', self.on_hinit, '- Toggle Init Recording on or off')
22 self.plugin_addcommand('/hhelp', self.on_hhelp, '- List all of the Hero Init Commands')
23 self.plugin_addcommand('/hstart', self.on_hstart, '- Start the Hero Init Tool', False)
24 self.plugin_addcommand('/hact', self.on_hact, '- Start the Hero Init Tool', False)
25 self.plugin_addcommand('/hseg', self.on_hseg, '- Start the Hero Init Tool', False)
26 self.plugin_addcommand('/hdex', self.on_hdex, '- Start the Hero Init Tool', False)
27 self.plugin_addcommand('/hclear', self.on_hclear, '- Start the Hero Init Tool', False)
28 self.plugin_addcommand('/hadd', self.on_hadd, '- Start the Hero Init Tool', False)
29 self.plugin_addcommand('/hdel', self.on_hdel, '- Start the Hero Init Tool', False)
30 self.plugin_addcommand('/hown', self.on_hown, '- Start the Hero Init Tool', False)
31 self.plugin_addcommand('/hlist', self.on_hlist, '- Start the Hero Init Tool', False)
32 self.plugin_addcommand('/hsort', self.on_hsort, '- Start the Hero Init Tool', False)
33 self.plugin_addcommand('/hrun', self.on_hrun, '- Start the Hero Init Tool', False)
34 self.plugin_addcommand('/hchange', self.on_hchange, '- Start the Hero Init Tool', False)
35 self.plugin_addcommand('/hset', self.on_hset, '- Start the Hero Init Tool', False)
36 self.plugin_addcommand('/hchange', self.on_hchange, '- Start the Hero Init Tool', False)
37
38 #If you want your plugin to have more then one way to call the same function you can
39 #use self.plugin_commandalias(alias name, command name)
40 #You can also make shortcut commands like the following
41 self.plugin_commandalias('/hlow', '/hsort low', False)
42 self.plugin_commandalias('/hsortlow', '/hsort low', False)
43 self.plugin_commandalias('/hhigh', '/hsort high', False)
44 self.plugin_commandalias('/hsorthigh', '/hsort high', False)
45 self.plugin_commandalias('/hreverse', '/hsort high', False)
46 self.plugin_commandalias('/hgo', '/hrun', False)
47
48 #This is where you set any variables that need to be initalized when your plugin starts
49 self.toggle = True
50 self.init_list = []
51 self.backup_list = []
52 self.dexterity = 99
53 self.segment = 12
54 self.state_strings = ["0 Phase","1/2 Phase","Full Phase","Stunned","Not Gone", "Held Full", "Held Half", "Abort"]
55
56 def plugin_disabled(self):
57 #Here you need to remove any commands you added, and anything else you want to happen when you disable the plugin
58 #such as closing windows created by the plugin
59 self.plugin_removecmd('/test')
60 self.plugin_removecmd('/example')
61
62 #This is the command to delete a message handler
63 self.plugin_delete_msg_handler('xxblank')
64
65 #This is how you should destroy a frame when the plugin is disabled
66 #This same method should be used in close_module as well
67 try:
68 self.frame.Destroy()
69 except:
70 pass
71
72 def plugin_incoming_msg(self, text, type, name, player):
73 #This is called whenever a message from someone else is received, no matter
74 #what type of message it is.
75 #The text variable is the text of the message. If the type is a regular
76 #message, it is already formatted. Otherwise, it's not.
77 #The type variable is an integer which tells you the type: 1=chat, 2=whisper
78 #3=emote, 4=info, and 5=system.
79 #The name variable is the name of the player who sent you the message.
80 #The player variable contains lots of info about the player sending the
81 #message, including name, ID#, and currently-set role.
82 #Uncomment the following line to see the format for the player variable.
83 #print player
84
85 if self.toggle:
86 if text.lower().find("heroinit") != -1:
87 command = text[text.rfind("(")+1:text.rfind(")")]
88 self.process_user(command, player)
89 return text, type, name
90
91 #Chat Commands
92 def on_hinit(self, cmdargs):
93 self.toggle = not self.toggle
94
95 if self.toggle:
96 self.chat.SystemPost("Init recording on. Enter your info")
97 else:
98 self.chat.SystemPost("Init recording off")
99
100 def on_hhelp(self, cmdargs):
101 self.chat.InfoPost("Commands:<br>/hclear : Clears out list<br>" +
102 "/hstart : Sets you to segment 12, highest dex<br>" +
103 "/hgo : Proceed to the next DEX/segment<br>" +
104 "/hact <i>#</i> (full|half|abort|stunned)<br>" +
105 "/hseg SEGNO : Set segment to SEGNO<br>" +
106 "/hdex DEXNO : Set dex to DEXNO<br>" +
107 "/hadd DEX SPD NAME : Adds to the list<br>" +
108 "/hdel # : Delete character #<br>" +
109 "/hown # playerid : Change ownership of PC # to playerid<br>" +
110 "/hclear : Clears out player list<br>" +
111 "/hchange # NEWDEX NEWSPD : Change PC # to have Dex NEWDEX and SPD NEWSPD<br>" +
112 "/hset list_# state : Change player's state (state:" + self.statelist() + ")")
113
114 def on_hstart(self, cmdargs):
115 self.dexterity = self.highestdex()
116 self.segment = 12
117
118 for player in self.init_list:
119 player[3] = 4
120 if player[0] == self.dexterity:
121 player[3] == 2
122
123 self.chat.Post("Combat Starting. ")
124 self.call_time()
125
126 def on_hact(self, cmdargs):
127 cmds = cmdargs.split(None)
128
129 if len(cmds) == 1:
130 msg = self.do_action(-1, -1, cmds[0])
131 elif len(cmds) == 2:
132 msg = self.do_action(-1, int(cmds[0]), cmds[1])
133 else:
134 msg = "Error in command. See format with hero init"
135
136 self.chat.InfoPost(msg)
137
138 def on_hseg(self, cmdargs):
139 cmds = cmdargs.split(None, 3)
140
141 try:
142 new_seg = int(cmds[0])
143 self.segment = new_seg
144 self.call_time()
145 except:
146 self.chat.SystemPost("Invalid format. correct command is: /hseg SEGMENT#")
147
148 def on_hdex(self, cmdargs):
149 cmds = cmdargs.split(None, 3)
150
151 try:
152 new_dex = int(cmds[0])
153 self.dexterity = new_dex
154 self.call_time()
155 except:
156 self.chat.SystemPost("Invalid format. correct command is: /hdex DEX#")
157
158 def on_hclear(self, cmdargs):
159 self.init_list = []
160 self.backup_list = []
161 self.dexterity = 99
162 self.segment = 12
163 self.chat.Post("<hr><font color='#ff0000'>New Initiative</font><br><font color='#0000ff'>Set new Initiatives</font>", True)
164
165 def on_hadd(self, cmdargs):
166 cmds = cmdargs.split(None, 3)
167 try:
168 if len(cmds) == 3:
169 new_dex = int(txt[0])
170 new_spd = int(txt[1])
171 self.init_list.append([new_dex, new_spd, cmds[2], 0, -1])
172 self.backup_list.append([new_dex, new_spd, cmds[2], 0, -1])
173 self.list_inits()
174 else:
175 self.chat.SystemPost("Invalid format. correct command is: /hadd dex spd description (" + str(len(cmds)) + " arguments give)")
176
177 except:
178 self.chat.SystemPost("Invalid format. correct command is: /hadd dex spd description")
179
180 def on_hdel(self, cmdargs):
181 try:
182 cmds = cmdargs.split(None, 1)
183 self.init_list.remove(int(cmds[0]))
184 self.backup_list.remove(int(cmds[0]))
185 self.list_inits()
186 except:
187 self.chat.SystemPost("Invalid format. correct command is: /del list_number")
188
189 def on_hown(self, cmdargs):
190 try:
191 cmds = cmdargs.split(None)
192 player = self.init_list[int(cmds[0])]
193 player[4] = int(cmds[1])
194 self.chat.InfoPost("Character " + player[2] + "(" + int(cmds[0]) + ") is now owned by ID " + int(cmds[1]))
195 except:
196 self.chat.SystemPost("Invalid format. correct command is: /hown # playerid")
197
198 def on_hlist(self, cmdargs):
199 self.list_inits()
200
201 def on_hsort(self, cmdargs):
202 self.init_list.sort()
203 self.backup_list.sort()
204
205 if cmdargs == "high":
206 self.init_list.reverse()
207 self.backup_list.reverse()
208
209 self.list_inits()
210
211 def on_hrun(self, cmdargs):
212 advance = True
213 nextlowest = 0
214 heldactions = False
215
216 for player in self.init_list:
217 if self.actson(player[1]. self.segment):
218 if player[3] == 5 or player[3] == 6:
219 heltactions = True
220 continue
221
222 if player[3] == 1 or player[3] == 2:
223 self.chat.InfoPost("Hero " + player[2] + " needs to act before we advance DEX")
224 advance = False
225
226 elif player[3] == 3 or player[3] == 4 or player[3] == 7:
227 if player[0] > nextlowest:
228 nextlowest = player[0]
229
230 elif player[3] == 5 or player[3] == 6:
231 heltactions = True
232
233 if not advance:
234 return
235
236 advanceseg = False
237
238 if nextlowest == 0 and self.dexterity != 0:
239 if heldactions or self.segment == 12:
240 msg = "End of Segment " + str(self.segment) + "."
241 if heldactions:
242 msg += " There are held actions."
243
244 msg += " Issue command again to advance to next segment."
245
246 self.chat.InfoPost(msg)
247 self.dexterity = 0
248 return
249 else:
250 advanceseg = True
251 elif nextlowest == 0 and self.dexterify == 0:
252 advanceseg = True
253
254 if advanceseg:
255 self.dexterity = nextlowest
256 for player in self.init_list:
257 if player[0] == self.dexterity:
258 if player[3] == 3 or player[3] == 7:
259 player[3] = 0
260 elif player[3] == 4:
261 player[3] = 2
262 else:
263 nextsegment = 0
264 while nextsegment == 0:
265 self.segment += 1
266 if self.segment == 13:
267 self.segment = 1
268
269 elif self.segment == 12:
270 nextsegment = 12
271 break
272
273 for player in self.init_list:
274 if self.actson(player[1], self.segment):
275 if player[3] == 0 or player[3] == 3 or player[3] == 7:
276 nextsegment = self.segment
277
278 if player[3] == 5 or player[3] == 6:
279 nextsegment = self.segment
280
281 self.dexterity = self.highestdex()
282 for player in self.init_list:
283 heldactions = False
284 if self.actson(player[1], self.segment):
285 if player[3] != 3 and player[3] != 7:
286 player[3] = 4
287
288 if player[0] == self.dexterity:
289 if player[3] == 3:
290 self.chat.InfoPost(player[2] + " unstuns.")
291 player[3] = 0
292 elif player[3] == 7:
293 self.chat.InfoPost(player[2] + " recovers from the abort")
294 player[3] = 0
295 else:
296 player[3] = 2
297
298 if player[3] == 5 or player[3] == 6 and self.dexterity == 0:
299 self.chat.InfoPost("There are held actions. Issue command again to advance to next segment.")
300 self.call_time()
301
302 def on_hchange(self, cmdargs):
303 try:
304 cmds = cmdargs.split()
305 self.init_list[int(cmds[0])][0] = cmds[1]
306 self.init_list[int(cmds[0])][1] = cmds[2]
307 self.backup_list[int(cmds[0])][0] = cmds[1]
308 self.backup_list[int(cmds[0])][1] = cmds[2]
309 self.list_inits()
310 except:
311 self.chat.SystemPost('Invalid format. correct command is: /hchange list_# new_dex new_spd (example: /hchange 1 18 4)')
312
313 def on_hset(self, cmdargs):
314 try:
315 cmds = cmdargs.split()
316 self.init_list[int(cmds[0])][3] = cmds[1]
317 self.backup_list[int(cmds[0])][3] = cmds[1]
318 self.list_inits()
319 except:
320 msg = "Invalid format. correct command is: /hset list_# state (state:" + self.statelist() + ")"
321 self.chat.InfoPost(msg)
322
323 #Other Methods
324 def statelist(self):
325 msg = ""
326 stateindex = 0
327 for state in self.state_strings:
328 if stateindex != 0:
329 msg += ", "
330 msg += str(stateindex) + "=" + state
331 stateindex += 1
332 return msg
333
334 def is_index(self, value):
335 try:
336 if value[:1] == "+":
337 offset = 1
338 return True
339 except:
340 return False
341
342 def actson(self, spd, segment):
343 speeds=[[0,0,0,0,0,0,0,0,0,0,0,1],
344 [0,0,0,0,0,1,0,0,0,0,0,1],
345 [0,0,0,1,0,0,0,1,0,0,0,1],
346 [0,0,1,0,0,1,0,0,1,0,0,1],
347 [0,0,1,0,1,0,0,1,0,1,0,1],
348 [0,1,0,1,0,1,0,1,0,1,0,1],
349 [0,1,0,1,0,1,1,0,1,0,1,1],
350 [0,1,1,0,1,1,0,1,1,0,1,1],
351 [0,1,1,1,0,1,1,1,0,1,1,1],
352 [0,1,1,1,1,1,0,1,1,1,1,1],
353 [0,1,1,1,1,1,1,1,1,1,1,1],
354 [1,1,1,1,1,1,1,1,1,1,1,1]]
355
356 if spd < 1 or spd > 12:
357 return False
358
359 if speeds[spd-1][segment-1] == 1:
360 return True
361
362 return False
363
364 def highestdex(self):
365 dex = 0
366 for player in self.init_list:
367 if self.actson(player[1], self.segment) and player[0] > dex:
368 dex = player[0]
369 return dex
370
371 def do_action(self, playerid, index, action):
372 if index == -1:
373 count = 1
374 for player in self.init_list:
375 if player[4] == playerid:
376 index = count
377 count += 1
378
379 if index == -1:
380 return "You do not have any players in the combat list"
381
382 index -= 1
383 player = self.init_list[index]
384 if playerid != -1 and playerid != player[4]:
385 return "You do not own that player."
386
387 # You can only perform a full action if you have a full or held full
388 if action == "full":
389 if player[3] != 2 and player[3] != 5:
390 msg = player[2] + " cannot perform a full action."
391 else:
392 player[3] = 0
393 msg = player[2] + " performs a full action."
394 elif action == "half":
395 if player[3] != 1 and player[3] != 2 and player[3] != 5 and player[3] != 6:
396 msg = player[2] + " cannot perform a half action."
397 else:
398 if player[3] == 1 or player[3] == 6:
399 player[3] = 0
400 msg = player[2] + " performs a half action."
401 else:
402 player[3] = 1
403 msg = player[2] + " performs a half action (half remaining)"
404 elif action == "hold":
405 if player[3] != 1 and player[3] != 2:
406 msg = player[2] + " cannot hold an action."
407 else:
408 if player[3] == 2:
409 player[3] = 5
410 msg = player[2] + " holding a full action."
411 else:
412 player[3] = 6
413 msg = player[2] + " holding a half action."
414 elif action == "stunned":
415 player[3] = 3
416 msg = player[2] + " stunned!"
417 elif action == "abort":
418 # abort if full/half/not gone/held. Those just lose this seg action
419 if player[3] == 1 or player[3] == 2 or player[3] == 4 or player[3] == 5 or player[3] == 6:
420 player[3] = 0
421 msg = player[2] + " aborts!"
422 # if you have 0 remaining and did not act this seg, regular abort
423 elif player[3] == 0 and not self.actson(player[1], self.segment):
424 player[3] = 7
425 msg = player[2] + " aborts!"
426 else:
427 msg = player[2] + " cannot abort yet."
428 else:
429 msg = "Unknown command."
430
431 return msg
432
433 def list_inits(self, player=0, send=False):
434 msg = "Combat Turn:<br>"
435 msg += "<table border=1 cellspacing=1 cellpadding=1><tr><th><th></th></th><th></th><th></th><th></th><th></th><th colspan=12>Segments</th></tr>"
436 msg += "<tr><th>#</th><th>Owner</th><th>Name</th><th>Spd</th><th>Dex</th><th>State</th>"
437 for x in xrange(1,13):
438 msg += "<th>" + str(x) + "</th>"
439 msg += "</tr>"
440 count=1
441 for m in self.init_list:
442 msg += "<tr><td align=center>"+str(count)+"</td>"
443 if m[4]==-1:
444 msg += "<td><font color=red>GM</font></td>"
445 else:
446 msg += "<td>" + m[4] + "</td>"
447 msg += "<td><font color='#0000ff'>" + m[2] + "</font></td>"
448 msg += "<td align=center><font color='#0000ff'>" + str(m[1]) + "</font></td>"
449 msg += "<td align=center><font color='#0000ff'>" + str(m[0]) + "</font></td>"
450 msg +="<td>" + self.state_strings[m[3]] + "</td>"
451
452 for segment in xrange(1,13):
453 if self.actson(m[1],segment):
454 msg += "<td align=center>" + str(m[0]) + "</td>"
455 else:
456 msg += "<td></td>"
457 msg += "</tr>"
458 count += 1
459 msg += "</table><br>"
460
461 msg += "It is currently Segment " + str(v.segment) + ", DEX " + str(v.dexterity) + "<br>"
462
463 if send and player != 0:
464 chat.whisper_to_players(msg, [player])
465 else:
466 self.chat.InfoPost(msg)
467
468 def call_time(self):
469 plist = ""
470 msg = "Segment is now " + str(self.segment) + ", DEX " + str(self.dexterity)
471 for player in self.init_list:
472 if player[3] == 1 or player[3] == 2 or player[3] == 5 or player[3] == 6:
473 if plist != "":
474 plist += ", "
475 plist += player[2] + "(" + self.state_strings[player[3]] + ")"
476 if plist != "":
477 msg += ": " + plist
478 self.chat.Post(msg, True)
479
480 def process_user(self, command, player):
481 if command == "hadd":
482 txt = command.split(None, 3)
483 try:
484 if len(txt) == 4:
485 new_dex = int(txt[1])
486 new_spd = int(txt[2])
487 self.init_list.append([new_dex, new_spd, txt[3], 0, player[2]])
488 self.backup_list.append([new_dex, new_spd, txt[3], 0, player[2]])
489 msg = "Character " + txt[3] + " added to initiative."
490 else:
491 msg = "Error in command. See format with heroinit"
492 except:
493 msg = "Error in command. See format with heroinit"
494
495 self.chat.whisper_to_players(msg, [player[2]])
496
497 elif command == "hact":
498 txt = command.split(None)
499 if len(txt) == 2:
500 index = -1
501 action = txt[1]
502 msg = self.do_action(player[2], index, action)
503 elif len(txt) == 3:
504 index = int(txt[1])
505 action = txt[2]
506 msg = self.do_action(player[2], index, action)
507 else:
508 msg = "Error in command. See format with heroinit"
509
510 self.chat.whisper_to_players(msg, [player[2]])
511
512 elif command == "hlist":
513 self.list_inits(player[2], True)
514
515 else:
516 msg = "Commands:<br>heroinit (hadd DEX SPEED CHARACTERNAME) : add character CHARACTERNAME with dex DEX and speed SPD to initiative list<br>"
517 msg += " Example: heroinit (hadd 18 4 Joey)<br>"
518 msg += "heroinit (hact # (full|half|hold|stunned|abort) : Have character # perform an action. # is the number from hlist. If ommited, uses first owned character<br>"
519 msg += " Example: heroinit (hact 1 full) : Make character index 1 perform a full action.<br>"
520 msg += " Example: heroinit (hact full) : Have your first owned character perform a full action<br>"
521
522 self.chat.whisper_to_players(msg, [player[2]])