def locateChild(self, ctx, segments): '''for pages that need to find which object they should operate on from the URL. For instance /edit/102 should act on the object with tzid = 102. This method will set some convenience variables so that they will be available later: self.obj --> the actual object self.tzid --> the tzid of the object self.cls --> name of the object's class (a string) self.base --> the most important base class of the object one of ... rooms.Room exits.Exit items.Item mobs.Mob players.Player self.bse --> name of the object's base class (a string) ''' tzid = int(segments[0]) self.tzid = tzid obj = tzindex.get(tzid) self.obj = obj bases = [Room, Exit, Item, Mob, Player] found = False for base in bases: if issubclass(obj.__class__, base): found = True self.base = base break if not found: # Module was probably rebuilt elsewhere (from the MUD). # Try rebuilding then finding the base class again. self.child_rebuild(ctx) return self.locateChild(ctx, segments) else: self.bse = class_as_string(base, instance=False) self.cls = class_as_string(obj) return self, ()
def upgrade(from_version, to_version): from share import upgrade if from_version==1 and to_version==2: import rooms for room in rooms.ls(): cls = class_as_string(room) if cls == 'TeleTrap': print 'upgrading', room, cls updated = upgrade(room) commit()
def action_spawn(self): room = self.room mobtype = self.setting('mobtype') ms = room.mobs() for mob in ms: mobcls = class_as_string(mob) if mobcls == mobtype: return import mobs spawncls = getattr(mobs, mobtype) mob = spawncls() mob.home = room mob.move(room) self.room.action(dict(act='arrive', actor=mob, fromx=None))
def near_destroy_mob(self, info): 'Someone has "destroy"ed some mob near this player.' destroyer = info['actor'] mob = info['mob'] name = mob.name try: clsname = class_as_string(mob) except TypeError: clsname = mob.name if destroyer is not self and self.can_see(mob): if name.lower() != clsname.lower(): self.message(clsname, mob, 'is destroyed.') else: self.message(mob, 'is destroyed.')
def near_destroy_item(self, info): 'Someone has "destroy"ed some item near this player.' destroyer = info['actor'] item = info['item'] name = item.name try: clsname = class_as_string(item) except TypeError: clsname = item.name if destroyer is not self and self.can_see(item): if name.lower() != clsname.lower(): self.message(clsname, item, 'is destroyed.') else: self.message(item, 'is destroyed.')
def cmd_study(s, r): '''study <object>|<object type> Learn more information about an object, or one of the different types of clonable objects that are available. See the lists of cloneables using the @list command. ''' objname = r.get('objname', '') objtzid = r.get('objtzid', 0) if not objname and not objtzid: s.message('Try: @study <object>') raise SyntaxError obj = find(r, s.room, s.player, s.room) if obj is not None: doc = obj.__doc__ name = class_as_string(obj) found = obj else: found = False for mod in items, mobs, rooms: for name in mod.classes(): if objname == name: found = name cls = getattr(mod, name) doc = cls.__doc__ if not found: s.message('No such thing to study.') return if doc is None: doc = '... but it is still a mystery' name = colors.white(name) s.message('You study the', found) msgs = doc.split('\n') s.mlmessage(msgs, indent=4)
def respawn(self, outside, mc): 'Check to see if the mob is in its cage. If not then make a new one.' # lock the doors key = self.itemname('key') door = outside.exitname('door') door.lock(key) # check if the mob is still at home cage = door.destination found = False for mob in cage.mobs(): mobclass = class_as_string(mob) if mobclass == mc: found = True if not found: cls = getattr(mobs, mc) mob = cls() mob.home = cage mob.move(cage)