"""The big hazard helper for the system."""# -*- coding: utf-8 -*-from __future__ import absolute_importimport xchatimport randomimport osfrom botvgh import bigdatafrom botvgh.hazards import callscript, haz_list, hazard_helper__module_name__ = "BOTVGH Arena Hazard Helper"__module_version__ = "1.2"__module_description__ = "The scripts that make hazards go off."class HazardHelper(object): """The various methods for calling Hazards are done here.""" CopyBO = botvgh_battlehelper.BattleHelper().BOrd haz_spaceballs = hazard_spaceballs.Hazards_Spaceballs() haz_simpsons = hazard_simpsons.Hazards_Simpsons() haz_masterlist = hazard_masterlist.Hazards_MasterList() haz_callscript = callscript.CallScript() def __init__(self): self.rebuildLists() def rebuildLists(self): """ Run this to rebuild both the list of hazard sets and hazard call bits. """ self.hazIntr = list() self.hazName = list() self.hazDesc = list() self.hazSets = list() swapper = 1 baseDir = bigdata.txtHazards for line in file(os.path.join(baseDir, 'haztime.txt')): if not line.startswith("COMMENT "): if swapper == 1: self.hazName.append(line[:-1]) else: self.hazDesc.append(line[:-1]) swapper = -swapper for line in file(os.path.join(baseDir, 'hazintro.txt')): if not line.startswith("COMMENT "): self.hazIntr.append(line[:-1]) for line in file(os.path.join(baseDir, 'hazsets.txt')): if not line.startswith("COMMENT "): self.hazSets.append(line[:-1]) return None def HazardSpecificGetter(self, con, set, seed = -1): delay = xchat.hook_timer(50, self.HazardSpecificGetDelay, (con, set, seed)) def HazardSpecificGetDelay(self, userdata): """ This gets the specific hazard in question. """ context = userdata[0] set = userdata[1].lower() # Confirming that it's lower. seed = userdata[2] if set == "ref": context.command("say It's Ref's Choice! Do whatever!") elif set == "spaceballs": context.command("say %s" % self.haz_spaceballs.getHazard(seed)) elif set == "simpsons": context.command("say %s" % self.haz_simpsons.getHazard(seed)) elif set == "callscript": cs = self.haz_callscript if seed == -1: seed = random.randint(0, len(cs.callList)) context.command(cs.getCallScript(seed)) line = cs.callList[seed][14:-9].replace(' ','_') self.CopyBO.insert(line,"average man", "call scripters") elif set == "master" or set == "masterlist": context.command("say %s" % self.haz_masterlist.getHazard(seed)) else: context.command("say %s %s isn't a valid hazard set!" \ % (bigdata.errMsg1, set)) return 0 def HazardSetGetter(self, con, seed = -1): delay = xchat.hook_timer(50, self.HazardSetGetDelay, (con, seed)) def HazardSetGetDelay(self, userdata): """ This returns the set that is called upon through the commands. """ context = userdata[0] seed = userdata[1] temptro = self.hazIntr tempers = self.hazName tempesc = self.hazDesc userlst = xchat.get_list("users") usernum = random.randrange(0, len(userlst)) if seed == -1: seed = random.randrange(0, len(tempers)) Part1 = eval(temptro[random.randrange(0, len(temptro))]) Part2 = eval(tempesc[seed]) context.command("say %s %s" % (Part1, Part2)) return 0 def HazRoll(self, word, word_eol, userdata): """ HazRoll is called every time a random (or rigged) hazard is required. Follow the commands as listed. """ context = xchat.get_context() # /haz getset [<setNumber>] SetSpeak = "say The hazard set of the day is: " if word[1].lower() == "getSet".lower(): seed = -1 if len(word) == 3: seed = int(word[2]) self.HazardSetGetter(context, seed) # /haz rebuild <set> elif word[1].lower() == "rebuild".lower(): toSay = "The master list set is rebuilt, with %d hazards now." \ % len(self.haz_masterlist.quotes) if len(word) == 3: if any(word[2].lower() == s.lower() for s in self.hazSets): Part1 = "The %s and the master list sets are rebuilt. " \ % word[2] Part2 = "The master list now has %d hazards." \ % len(self.haz_masterlist.quotes) toSay = "%s%s" % (Part1, Part2) context.command("say \x02\x03,14%s\x03\x02" % toSay) # /haz <HazSet> [<number>] elif any(word[1].lower() == s.lower() for s in self.hazSets): seed = -1 if len(word) == 3: seed = int(word[2]) self.HazardSpecificGetter(context, word[1], seed) # Umm...you goofed. else: xchat.command("say \x02ERROR!\x02 Check your roll commands.") return xchat.EAT_ALL