def schedule_next_adventure(self): minimum = config.delay_min maximum = config.delay_max minutes = utils.randfloat(minimum, maximum) self.last_adventure = utils.now() self.scheduled_adventure = utils.get_future_timestamp(minutes=minutes)
def __init__(self, seconds): self.timeString = string.strip(str(seconds)) self.seconds = 0.0 try: self.seconds = float(self.timeString) except: if self.timeString[0] == "{" and self.timeString[len(self.timeString) - 1] == "}": timeString = self.timeString[1 : len(self.timeString) - 1] timeParts = string.split(timeString, ":") if len(timeParts) != 2: raise ValueError( 'Time must be in following format "{c|r:string} | float". ' + self.timeString + " has an incorrect format" ) if not (timeParts[0] in ["c", "r"]): raise ValueError("unknown time type: " + timeParts[0]) # extracting time if timeParts[0] == "c": self.seconds = float(timeParts[1]) if timeParts[0] == "r": timecomps = string.split(timeParts[1], ",") self.seconds = utils.randfloat(float(timecomps[0]), float(timecomps[1])) else: raise ValueError("time must defined within {} brackets or be a float value: " + self.timeString)
def reschedule_next_adventure(self): # This method reschedules the next adventure if config time changes. # You are expected to call this on all players if you want to update them. minimum = config.delay_min maximum = config.delay_max minutes = utils.randfloat(minimum, maximum) self.scheduled_adventure = self.last_adventure + utils.timedelta( minutes=minutes)
def __init__(self, redFloat_Or_colorString, greenFloat=None, blueFloat=None, address=None): if greenFloat is None or blueFloat is None: self.colorString = string.strip(redFloat_Or_colorString) self.R = 0.0 self.G = 0.0 self.B = 0.0 self.Address = 0 if self.colorString[0] != "{" or self.colorString[len(self.colorString) - 1] != "}": raise ValueError("color must defined within {} brackets" + self.colorString) colorString = self.colorString[1 : len(self.colorString) - 1] colorParts = string.split(colorString, ":") if not (colorParts[0] in ["x", "b", "f", "r", "hsv", "hsl"]): raise ValueError("unknown color type: " + colorParts[0]) # extracting Address if len(colorParts) > 2: self.Address = int(colorParts[2], 16) elif len(colorParts) <= 2: self.Address = 0xF # extracting RGB if colorParts[0] == "x": rgbcomps = utils.getIntComponents(colorParts[1]) self.R = rgbcomps[0] / 255.0 self.G = rgbcomps[1] / 255.0 self.B = rgbcomps[2] / 255.0 if colorParts[0] == "b": rgbcomps = string.split(colorParts[1], ",") self.R = int(rgbcomps[0]) / 255.0 self.G = int(rgbcomps[1]) / 255.0 self.B = int(rgbcomps[2]) / 255.0 if colorParts[0] == "f": rgbcomps = string.split(colorParts[1], ",") self.R = float(rgbcomps[0]) self.G = float(rgbcomps[1]) self.B = float(rgbcomps[2]) if colorParts[0] == "r": rndValues = string.split(colorParts[1], ",") fromRed = float(string.split(rndValues[0], "-")[0]) toRed = float(string.split(rndValues[0], "-")[1]) fromGreen = float(string.split(rndValues[1], "-")[0]) toGreen = float(string.split(rndValues[1], "-")[1]) fromBlue = float(string.split(rndValues[2], "-")[0]) toBlue = float(string.split(rndValues[2], "-")[1]) self.R = utils.randfloat(fromRed, toRed) self.G = utils.randfloat(fromGreen, toGreen) self.B = utils.randfloat(fromBlue, toBlue) if colorParts[0] == "hsv": hsvcomps = string.split(colorParts[1], ",") h = float(hsvcomps[0]) s = float(hsvcomps[1]) v = float(hsvcomps[2]) self.R, self.G, self.B = colorsys.hsv_to_rgb(h / 360.0, s / 100.0, v / 100.0) if colorParts[0] == "hsl": hslcomps = string.split(colorParts[1], ",") h = float(hslcomps[0]) s = float(hslcomps[1]) l = float(hslcomps[2]) self.R, self.G, self.B = colorsys.hls_to_rgb(h / 360.0, l / 100.0, s / 100.0) self.R = utils.clip(self.R) self.G = utils.clip(self.G) self.B = utils.clip(self.B) else: self.R = float(redFloat_Or_colorString) self.G = float(greenFloat) self.B = float(blueFloat) if address is None: self.Address = 0xF else: self.Address = address