class Property(PersistentSlots): """ Represents object-specific setting. """ __slots__ = ('name', 'data_type', 'value', '_obj_setting') _transient_vars = ('_obj_setting', ) __type_parsers = { str: None, int: p.IntStaticParser, float: p.FloatStaticParser, BaseObject: p.MatchObject(cls=BaseObject, show=True, context=False) } def __init__(self, name, data_type=str, value=None): self.name = name self.data_type = data_type self.value = value @property def obj_setting(self): try: return self._obj_setting except AttributeError: self._obj_setting = self.generate_obj_setting() return self._obj_setting def generate_obj_setting(self): parser = self.__type_parsers.get(self.data_type, None) return PropertyObjSetting(self, parser=parser)
class LocationsCmd(Command): """ @locations [<object>] Print out the nested location tree of the object specified. Defaults to self. """ aliases = ('@locations', '@locs') syntax = '[<obj>]' arg_parsers = { 'obj': parsers.MatchObject(cls=LocatedObject, show=True, search_for='object', context=False) } lock = locks.all_pass def run(self, actor, obj): """ :type actor: mudslingcore.objects.Player :type obj: mudsling.objects.Object """ if (obj is None and actor.is_possessing and actor.possessing.isa(LocatedObject)): #: :type: mudsling.objects.Object obj = actor.possessing if not obj.allows(actor, 'locate'): raise self._err('{rYou are not permitted to locate that.') locs = ['{g%s' % actor.name_for(obj)] locs.extend('{y%s' % actor.name_for(l) for l in obj.locations()) actor.msg(' {m/ '.join(locs))
class ChangeClassCmd(Command): """ @chclass <object> to <class> """ aliases = ('@chclass', '@change-class', '@chparent') syntax = '<object> to <class>' arg_parsers = { 'object': parsers.MatchObject(show=True, context=False), 'class': parsers.ObjClassStaticParser } lock = 'perm(create objects)' def run(self, this, actor, args): """ :type this: mudslingcore.objects.Player :type actor: mudslingcore.objects.Player :type args: dict """ cls = args['class'] clsName = registry.classes.get_class_name(cls) if not actor.superuser and not (issubclass(cls, LockableObject) and cls.createLock.eval(cls, actor)): msg = "{yYou do not have permission to create {c%s{y objects." raise self._err(msg % clsName) obj = args['object'] if obj._real_object().__class__ == cls: raise self._err("%s is already a %s." % (obj, clsName)) try: self.game.db.change_class(args['object'], cls) except Exception as e: raise self._err(e.message) else: actor.tell('{c', args['object'], '{g is now a {c', clsName, '{g.')
class DescribeCmd(EditCmd): """ @describe[/paste] <object> [as <description>] Describe a describable object. """ aliases = ('@describe', '@desc') syntax = '<obj> [as <text>]' arg_parsers = { 'obj': parsers.MatchObject(cls=DescribableObject, search_for='describable object', show=True, context=False) } switch_defaults = {'paste': False} # noinspection PyMethodOverriding def run(self, actor, obj, switches, text=None): """ :type actor: mudslingcore.objects.Player :type obj: mudslingcore.objects.DescribableObject :type switches: dict of (str, bool) :type text: str """ if switches['paste']: self._paste(actor, obj, 'desc') elif text is not None: obj.set_obj_setting('desc', text) self._notify_set(actor, obj, 'desc') else: self._edit(actor, obj, 'desc') def _notify_set(self, actor, obj, setting): actor.tell(obj, ' description set.')
def execute(self): # Just to avoid circular imports! self.arg_parsers = { 'obj': parsers.MatchObject(cls=InspectableObject, search_for='inspectable object', show=True, context=False) } super(ShowCmd, self).execute()
class MoveCmd(Command): """ @move <object> to <location> Moves the specified object to the specified location. """ aliases = ('@move', '@tel', '@teleport') syntax = "<what> to <where>" lock = "perm(teleport)" arg_parsers = { 'what': parsers.MatchObject(cls=LocatedObject, context=False, search_for='locatable object', show=True), 'where': parsers.MatchObject(cls=LocatedObject, context=False, search_for='location', show=True), } def run(self, this, actor, args): """ :type this: mudslingcore.objects.Player :type actor: mudslingcore.objects.Player :type args: dict """ obj, where = (args['what'], args['where']) if not obj.allows(actor, 'move'): actor.tell("{yYou are not allowed to move {c", obj, "{y.") return misc.teleport_object(obj, where) msg_key = 'teleport' if obj.location == where else 'teleport_failed' actor.direct_message(msg_key, recipients=(actor, obj), actor=actor, obj=obj, where=where)
class LookCmd(Command): """ look [[at] <something>] Look at the room or specified object, seeing the description thereof. """ aliases = ('look', 'l') syntax = "[[at] <something>]" arg_parsers = { 'something': parsers.MatchObject(search_for='thing to look at', show=True) } lock = locks.all_pass # Everyone can have a look. def _is_lookable(self, obj): return hasattr(obj, 'seen_by') and callable(obj.seen_by) def run(self, this, actor, args): """ :type this: mudslingcore.objects.Character :type actor: mudslingcore.objects.Character :type args: dict """ if not this.can_see: actor.msg("{yYou are unable to see.") return if 'something' not in args or args['something'] is None: # Naked look. if self._is_lookable(actor.location): #noinspection PyUnresolvedReferences actor.msg(actor.location.seen_by(actor)) return actor.msg("You don't seem to see anything...") return #: :type: Object target = args['something'] if target in actor.primary_context() or actor.has_perm('remote look'): if self._is_lookable(target): actor.msg(target.seen_by(actor)) else: actor.msg(actor.name_for(target) + "\nYou see nothing of note.") else: actor.msg("You don't see any '%s' here." % self.args['something'])
class GoCmd(Command): """ @go <location> Teleport one's self to the indicated location. """ aliases = ('@go', ) syntax = "[<where>]" lock = 'perm(teleport)' arg_parsers = { 'where': parsers.MatchObject(cls=LocatedObject, context=False, search_for='location', show=True) } def run(self, actor, where): """ :type actor: mudslingcore.objects.Player :type where: mudsling.objects.Object """ if actor.is_possessing and actor.possessing.is_valid(LocatedObject): #: :type: mudsling.objects.Object obj = actor.possessing plugins = self.game.plugins.enabled_plugins() if where is None and 'myobjs' in plugins: from myobjs import MyObjCharacter #: :type: MyObjCharacter char = obj if char.isa(MyObjCharacter) and char.has_myobj('place'): place = char.get_myobj('place') if self.game.db.is_valid(place, LocatedObject): where = place if where is None: actor.msg(self.syntax_help()) return if not obj.allows(actor, 'move'): actor.tell("{yYou are not allowed to move {c", obj, "{y.") return misc.teleport_object(obj, where) else: m = "You are not attached to a valid object with location." raise self._err(m)
class FindPlaceCmd(mudsling.commands.Command): """ @find-place <name> in <group> Find a room within the hierarchy of a room group tree. If you have @myobjs, a single result will be saved to your %place myobj variable. """ aliases = ('@find-place', '@findplace') syntax = '<search> {{in|on}} <group>' arg_parsers = { 'group': parsers.MatchObject(cls=RoomGroup, search_for='room group', show=True, context=False) } lock = 'perm(teleport)' def run(self, actor, search, group): """ :type actor: mudslingcore.objects.Player :type search: str :type group: mudslingcore.rooms.RoomGroup """ matches = actor._match(search, list(group.all_rooms)) if not matches: p = self.args['optset1'].lower() actor.tell('{yNo places found matching "{m', search, '{y" ', p, ' {c', group, '{y.') return plugins = self.game.plugins.enabled_plugins() if len(matches) == 1 and 'myobjs' in plugins: from myobjs import MyObjCharacter #: :type: myobjs.MyObjCharacter char = actor.possessing if char.isa(MyObjCharacter): char.set_myobj('place', matches[0]) actor.tell('{mSaved {c', matches[0], '{m to {y%place {mmyobj.') out = '{cFound Places{y:\n' out += '\n'.join(' {y* {g%s' % actor.name_for(m) for m in matches) actor.msg(out)
class RenameCmd(Command): """ @rename <object> to <new-names> Renames an object to the new name. """ aliases = ('@rename', ) syntax = "<obj> {to|as} <names>" arg_parsers = { 'obj': parsers.MatchObject(NamedObject, search_for='named object', show=True, context=False), 'names': parsers.StringListStaticParser, } lock = locks.all_pass # Everyone can use @rename -- access check within. def run(self, actor, obj, names): """ :type actor: mudslingcore.objects.Player :type obj: NamedObject :type names: list of str """ if not obj.allows(actor, 'rename'): actor.tell("{yYou are not allowed to rename {c", obj, "{y.") return oldNames = obj.set_names(names) msg = "{{gName of {{c#{id}{{g changed to '{{m{name}{{g'" keys = {'id': obj.obj_id, 'name': obj.name} if len(names) > 1: msg += " with aliases: {aliases}" aliases = ["{y%s{g" % a for a in obj.aliases] keys['aliases'] = utils.string.english_list(aliases) actor.msg(str(msg.format(**keys))) actor.msg("(previous names: {M%s{n)" % ', '.join(oldNames))
def execute(self): switches = self.parse_args(self.parse_switches(self.switchstr), self.switch_parsers) if 'obj' in switches: self.arg_parsers = {'value': parsers.MatchObject(context=False)} return super(SetGlobalCmd, self).execute()
""" obj, where = (args['what'], args['where']) if not obj.allows(actor, 'move'): actor.tell("{yYou are not allowed to move {c", obj, "{y.") return misc.teleport_object(obj, where) msg_key = 'teleport' if obj.location == where else 'teleport_failed' actor.direct_message(msg_key, recipients=(actor, obj), actor=actor, obj=obj, where=where) match_configurable_obj = parsers.MatchObject(cls=ConfigurableObject, search_for='configurable object', show=True, context=False) class SettingsCommand(Command): """ Special command type which checks access after instantiation based on a specially-named parameter. Actor must be able to configure the 'obj' parameter. """ __metaclass__ = abc.ABCMeta lock = locks.all_pass def before_run(self): obj = self.parsed_args['obj'] if not lock_can_configure(obj, self.actor):