def _clone_item(s, objname, objtzid, newname=''): # first try to clone an item # look first in the room or on the player # then at existing item objects orig = s.player.itemname(objname) or \ s.player.item(objtzid) or \ s.room.itemname(objname) or \ s.room.item(objtzid) or \ items.getname(objname) or \ items.get(objtzid) # if it is not there, it might be an item class if orig is None: if objname in items.classes(): cls = getattr(items, objname) obj = cls() else: obj = None else: obj = copy.copy(orig) if obj: if newname: obj.name = newname s.message(obj, 'created.') s.player.add(obj) s.room.action(dict(act='clone_item', actor=s.player, item=obj)) return obj
def cmd_list(s, r): '''list |players|items|rooms|mobs|exits| List all objects of the given type. ''' listing = r['type'] if listing == 'players': objs = players.ls() classes = [] elif listing == 'items': objs = items.ls() classes = items.classes() elif listing == 'rooms': objs = rooms.ls() classes = rooms.classes() elif listing == 'mobs': objs = mobs.ls() classes = mobs.classes() elif listing == 'exits': objs = exits.ls() classes = exits.classes() if objs: s.message('Existing objects:') objs.sort(key=operator.attrgetter('tzid')) msgs = [] for obj in objs: tzid = '(%s)' % obj.tzid msgs.append('%s %s' % (tzid.rjust(4, ' '), obj)) s.mlmessage(msgs, indent=4) else: s.message('No', listing, 'yet.') if classes: classes = list(classes) classes.sort() if objs: s.message() s.message('Cloneable:') s.columns_v(classes, color=colors.white)