def list_attribute(self, crop, attr, value): """ Formats a single attribute line. """ if crop and isinstance(value, basestring): value = utils.crop(value) value = utils.to_unicode(value) string = "\n %s = %s" % (attr, value) string = raw(string) return string
def func(self): "implements the functionality." caller = self.caller if not self.args: caller.msg("Usage: @code <obj>[/<type> [= <codestring>]]") return codetype = None objname = self.lhs if '/' in self.lhs: objname, codetype = [part.strip() for part in self.lhs.rsplit("/", 1)] obj = self.caller.search(objname) if not obj: return # get the dicts from db storage for easy referencing evlang_scripts = obj.db.evlang_scripts evlang_locks = obj.db.evlang_locks if not (evlang_scripts != None and evlang_locks and obj.ndb.evlang): caller.msg("Object %s can not be scripted." % obj.key) return if 'delete' in self.switches: # clearing a code snippet if not codetype: caller.msg("You must specify a code type.") return if not codetype in evlang_scripts: caller.msg("Code type '%s' not found on %s." % (codetype, obj.key)) return # this will also update the database obj.ndb.evlang.delete(codetype) caller.msg("Code for type '%s' cleared on %s." % (codetype, obj.key)) return if not self.rhs: if codetype: scripts = [(name, tup[1], utils.crop(tup[0])) for name, tup in evlang_scripts.items() if name==codetype] scripts.extend([(name, "--", "--") for name in evlang_locks if name not in evlang_scripts if name==codetype]) else: # no type specified. List all scripts/slots on object print evlang_scripts scripts = [(name, tup[1], utils.crop(tup[0])) for name, tup in evlang_scripts.items()] scripts.extend([(name, "--", "--") for name in evlang_locks if name not in evlang_scripts]) scripts = sorted(scripts, key=lambda p: p[0]) table = [["type"] + [tup[0] for tup in scripts], ["creator"] + [tup[1] for tup in scripts], ["code"] + [tup[2] for tup in scripts]] ftable = utils.format_table(table, extra_space=5) string = "{wEvlang scripts on %s:{n" % obj.key for irow, row in enumerate(ftable): if irow == 0: string += "\n" + "".join("{w%s{n" % col for col in row) else: string += "\n" + "".join(col for col in row) caller.msg(string) return # we have rhs codestring = self.rhs if not codetype in evlang_locks: caller.msg("Code type '%s' cannot be coded on %s." % (codetype, obj.key)) return # check access with the locktype "code" if not obj.ndb.evlang.lockhandler.check(caller, "code"): caller.msg("You are not permitted to add code of type %s." % codetype) return # we have code access to this type. oldcode = None if codetype in evlang_scripts: oldcode = str(evlang_scripts[codetype][0]) # this updates the database right away too obj.ndb.evlang.add(codetype, codestring, scripter=caller) if oldcode: caller.msg("{wReplaced{n\n %s\n{wWith{n\n %s" % (oldcode, codestring)) else: caller.msg("Code added in '%s':\n %s" % (codetype, codestring)) if "debug" in self.switches: # debug mode caller.msg("{wDebug: running script (look out for errors below) ...{n\n" + "-"*68) obj.ndb.evlang.run_by_name(codetype, caller, quiet=False)
def func(self): "Define extended command" caller = self.caller location = caller.location if self.cmdstring == '@detail': # switch to detailing mode. This operates only on current location if not location: caller.msg("No location to detail!") return if not self.rhs: # no '=' used - list content of given detail if self.args in location.db.details: string = "{wDetail '%s' on %s:\n{n" % (self.args, location) string += location.db.details[self.args] caller.msg(string) return if not self.args: # No args given. Return all details on location string = "{wDetails on %s{n:\n" % location string += "\n".join(" {w%s{n: %s" % (key, utils.crop(text)) for key, text in location.db.details.items()) caller.msg(string) return if self.switches and self.switches[0] in 'del': # removing a detail. if self.lhs in location.db.details: del location.db.detail caller.msg("Detail %s deleted, if it existed." % self.lhs) self.reset_times(location) return # setting a detail location.db.details[self.lhs] = self.rhs caller.msg("Set Detail %s to '%s'." % (self.lhs, self.rhs)) self.reset_times(location) return else: # we are doing a @desc call if not self.args: if location: string = "{wDescriptions on %s{n:\n" % location.key string += " {wspring:{n %s\n" % location.db.spring_desc string += " {wsummer:{n %s\n" % location.db.summer_desc string += " {wautumn:{n %s\n" % location.db.autumn_desc string += " {wwinter:{n %s\n" % location.db.winter_desc string += " {wgeneral:{n %s" % location.db.general_desc caller.msg(string) return if self.switches and self.switches[0] in ("spring", "summer", "autumn", "winter"): # a seasonal switch was given if self.rhs: caller.msg("Seasonal descs only works with rooms, not objects.") return switch = self.switches[0] if not location: caller.msg("No location was found!") return if switch == 'spring': location.db.spring_desc = self.args elif switch == 'summer': location.db.summer_desc = self.args elif switch == 'autumn': location.db.autumn_desc = self.args elif switch == 'winter': location.db.winter_desc = self.args # clear flag to force an update self.reset_times(location) caller.msg("Seasonal description was set on %s." % location.key) else: # Not seasonal desc set, maybe this is not an extended room if self.rhs: text = self.rhs obj = caller.search(self.lhs) if not obj: return else: text = self.args obj = location obj.db.desc = self.rhs # this is set as a compatability fallback if utils.inherits_from(obj, ExtendedRoom): # this is an extendedroom, we need to reset times and set general_desc obj.db.general_desc = text self.reset_times(obj) caller.msg("General description was set on %s." % obj.key) else: caller.msg("The description was set on %s." % obj.key)
def func(self): "Define extended command" caller = self.caller location = caller.location if self.cmdstring == '@detail': # switch to detailing mode. This operates only on current location if not location: caller.msg("No location to detail!") return if not self.rhs: # no '=' used - list content of given detail if self.args in location.db.details: string = "{wDetail '%s' on %s:\n{n" % (self.args, location) string += location.db.details[self.args] caller.msg(string) return if not self.args: # No args given. Return all details on location string = "{wDetails on %s{n:\n" % location string += "\n".join(" {w%s{n: %s" % (key, utils.crop(text)) for key, text in location.db.details.items()) caller.msg(string) return if self.switches and self.switches[0] in 'del': # removing a detail. if self.lhs in location.db.details: del location.db.detail caller.msg("Detail %s deleted, if it existed." % self.lhs) self.reset_times(location) return # setting a detail location.db.details[self.lhs] = self.rhs caller.msg("Set Detail %s to '%s'." % (self.lhs, self.rhs)) self.reset_times(location) return else: # we are doing a @desc call if not self.args: if location: string = "{wDescriptions on %s{n:\n" % location.key string += " {wspring:{n %s\n" % location.db.spring_desc string += " {wsummer:{n %s\n" % location.db.summer_desc string += " {wautumn:{n %s\n" % location.db.autumn_desc string += " {wwinter:{n %s\n" % location.db.winter_desc string += " {wgeneral:{n %s" % location.db.general_desc caller.msg(string) return if self.switches and self.switches[0] in ("spring", "summer", "autumn", "winter"): # a seasonal switch was given if self.rhs: caller.msg("Seasonal descs only works with rooms, not objects.") return switch = self.switches[0] if not location: caller.msg("No location was found!") return if switch == 'spring': location.db.spring_desc = self.args elif switch == 'summer': location.db.summer_desc = self.args elif switch == 'autumn': location.db.autumn_desc = self.args elif switch == 'winter': location.db.winter_desc = self.args # clear flag to force an update self.reset_times(location) caller.msg("Seasonal description was set on %s." % location.key) else: # Not seasonal desc set, maybe this is not an extended room if self.rhs: text = self.rhs obj = caller.search(self.lhs) if not obj: return else: text = self.args obj = location obj.db.desc = self.rhs # a compatability fallback if utils.inherits_from(obj, ExtendedRoom): # this is an extendedroom, we need to reset # times and set general_desc obj.db.general_desc = text self.reset_times(obj) caller.msg("General description was set on %s." % obj.key) else: caller.msg("The description was set on %s." % obj.key)