def populate(self): '''If the Zoo has an area for a mob, check that the mob is still there and if not, respawn it. If the Zoo does not have an area for the mob, it may be a new mob, so build a place for it. ''' key = self.itemname('key') if key is None: # Check if the room has any keys. If not make one. # If it does have at least one key, only make a # new one very rarely. _key = None if hasattr(self, '_key'): _key = getattr(self, '_key') if _key is None or random.choice(random.randrange(50)) == 0: key = items.Key() self.add(key) # make sure to always use the same key if hasattr(self, '_key'): key._key = getattr(self, '_key') self._key = key._key for mobclass in mobs.classes(): exists = False for x in self.exits(): if x.name == u'see the %s' % mobclass.lower(): exists = True self.respawn(x.destination, mobclass) if not exists: self.build(mobclass)
def mobtypes_widget(self, name, data): choices = mobs.classes() choices.sort() info = dict(name=name, choices=choices, selected=data) return self.render_form_select(info)
def _clone_mob(s, objname, objtzid, newname=''): # next, try to clone a mob # look first in the room # then at existing mobs orig = s.room.mobname(objname) or \ s.room.mob(objtzid) or \ mobs.getname(objname) or \ mobs.get(objtzid) # if it is not there, it might be a mob class if orig is None: if objname in mobs.classes(): cls = getattr(mobs, objname) obj = cls() else: obj = None else: obj = copy.copy(orig) if obj: if newname: obj.name = newname s.message(obj, 'created.') obj.move(s.room) obj.home = s.room s.room.action(dict(act='clone_mob', actor=s.player, mob=obj)) return obj
def cmd_summon(s, r): '''summon <character>|<mob class> If the name or id# given is an existing player or mob, this will act like: teleport <character> to <here>. If the name does not exist already, but is a mob class, this will be like: clone <mobclass>. ''' room = s.room objname = r.get('objname', '') objtzid = r.get('objtzid', 0) char = players.getname(objname) or players.get(objtzid) or \ mobs.getname(objname) or mobs.get(objtzid) if char is not None: char.teleport(room) s.message('You summon', char, '.') elif objname in mobs.classes(): mob = _clone_mob(s, objname, objtzid) s.message('You summon', mob, '.') else: iden = objname if objname else '#%s' % objtzid s.message('Unable to summon', iden, '.')
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)