def change_hp(self, side, val): if not 0 <= val <= 10: raise AreaError("Invalid penalty value.") if not 1 <= side <= 2: raise AreaError("Invalid penalty side.") if side == 1: self.set_attr("health.defense", val) elif side == 2: self.set_attr("health.prosecution", val) self.send_command("HP", side, val)
def change_status(self, value): allowed_values = ( "idle", "building", "casing", "recess", ) if value.lower() not in allowed_values: raise AreaError( f"Invalid status. Possible values: {', '.join(allowed_values)}" ) if value == self.get_attr("status"): raise AreaError("This status is already set.") self.set_attr("status", value.upper()) self.server.send_arup_status()
def ooc_cmd_bg(client, arg): if len(arg) == 0: raise ArgumentError("You must specify a name. Use /bg <background>.") if not client.is_mod and client.area.bg_lock: raise AreaError("This area's background is locked") try: client.area.change_background(arg) except AreaError: raise client.area.send_host_message( "{} changed the background to {}.".format(client.get_char_name(), arg) ) logger.log_server( "[{}][{}]Changed background to {}".format( client.area.id, client.get_char_name(), arg ), client, )
def wrapper(*args, **kwargs): client = args[0] if not client.area.get_attr("is_casing"): raise AreaError("This area is not intended for casing.") return f(*args, **kwargs)
def get_area_by_id(self, num): for area in self.areas: if area.id == num: return area raise AreaError("Area not found.")
def get_area_by_name(self, name): for area in self.areas: if area.name == name: return area raise AreaError("Area not found.")
def get_rand_avail_char_id(self): avail_set = set(range(len(self.server.char_list))) - set( [x.char_id for x in self.clients]) if len(avail_set) == 0: raise AreaError("No available characters.") return random.choice(tuple(avail_set))
def change_background(self, bg): if bg not in self.server.backgrounds: raise AreaError("Invalid background name.") self.set_attr("background.name", bg) self.send_command("BN", bg)