Exemplo n.º 1
0
    def loadPlayer(self, name):
        # get dict of settings in player's file
        settings = files.loadFromFile('players\\%s.plr' % self.name)

        # iterate through dict
        for k in settings.keys():
            if k == "Username":
                self.name = settings[k]
            elif k == "Password":
                self.password = settings[k]
            elif k == "Level":
                # store as int as required
                self.level = int(settings[k])
            elif k == "IsAdmin":
                # turns out I couldn't just go bool(settings[k]), it always
                # returned True (presumably because it contained _something_.
                if settings[k] == "True": self.isAdmin = True
                if settings[k] == "False": self.isAdmin = False
            elif k == "Room":
                # there may be a faster way to do this, rather than looping
                # through every single room until we find it.
                for r in self.server.world.rList:
                    if r.id == int(settings[k]):
                        self.room = int(settings[k])
            elif k == 'I':
                # this line creates an object and appends it to the player's
                # inventory.
                self.inventory.append(objects.Object(self, settings[k]))
        # set admin commands
        if self.isAdmin:
            self.cmds['dump'] = self.parse_dump
Exemplo n.º 2
0
    def __init__(self, owner, file):
        settings = files.loadFromFile('objects\\%s.obj'%file)
            
        # iterate through dict
        for k in settings.keys():
            if k=="Name":
                self.name = settings[k]
            if k=="Type":
                self.type = settings[k]

        self.id = int(file)
        self.owner = owner
Exemplo n.º 3
0
    def __init__(self, id):
        ''' Load a mob from a given id '''
        # initialize variables (not necessary but for my convenience)
        self.id = id
        self.room = None
        self.displayName = None
        self.shortName = None
        self.lookStr = None
        self.type = None
        self.moveRate = 0
        self.thinkAgain = 0

        settings = files.loadFromFile('world\\mobs\\%i.mob' % id)

        for k in settings.keys():
            if k == 'DisplayName':
                self.displayName = settings[k]
            elif k == 'ShortName':
                self.shortName = settings[k]
            elif k == 'MoveRate':
                self.moveRate = int(settings[k])
            elif k == 'Look':
                self.lookStr = settings[k]
            elif k == 'Type':
                self.type = settings[k]

        # load "personality"
        typeFound = False
        for k, v in mobTypes.items():
            if self.type == k:
                print 'Mob Personality = %s (%s)' % (k, v)
                self.type = v(self)
                print self.type
                typeFound = True
        if not typeFound:
            print 'Error loading mob: personality not found.'

        # just an alias for parse_look
        self.name = self.shortName
Exemplo n.º 4
0
    def __init__(self):
        """ Load world from files. """
        self.rList = []

        # open all files in directory world/rooms/
        fileList = os.listdir('world\\rooms\\')

        # find highest room number and create self.rList with that many slots
        highNum = 1
        for f in fileList:
            num = f.split('.')
            if int(num[0]) > highNum:
                highNum = int(num[0])
        self.rList = [0] * (highNum + 1)

        for f in fileList:
            settings = files.loadFromFile('world\\rooms\\%s' % f)
            id = None
            title = None
            desc = None
            exits = [None] * 10
            inventory = []
            mList = []
            for k in settings.keys():
                if k == 'ID':
                    id = int(settings[k])
                elif k == 'Title':
                    title = settings[k]
                elif k == 'Desc':
                    desc = settings[k]
                elif k == 'N':
                    exits[0] = int(settings[k])
                elif k == 'NE':
                    exits[1] = int(settings[k])
                elif k == 'E':
                    exits[2] = int(settings[k])
                elif k == 'SE':
                    exits[3] = int(settings[k])
                elif k == 'S':
                    exits[4] = int(settings[k])
                elif k == 'SW':
                    exits[5] = int(settings[k])
                elif k == 'W':
                    exits[6] = int(settings[k])
                elif k == 'NW':
                    exits[7] = int(settings[k])
                elif k == 'U':
                    exits[8] = int(settings[k])
                elif k == 'D':
                    exits[9] = int(settings[k])
                elif k == 'I':
                    inventory.append(objects.Object(None, settings[k]))
                elif k == 'M':
                    mList.append(mob.Mob(int(settings[k])))
            r = room.Room(id, title, desc, exits)
            r.inventory = inventory
            r.mList = mList
            # update mobs knowledge of their room
            for m in r.mList:
                m.room = r
            self.rList[id] = r

        # loop through rooms and turn exit ints into room links
        for r in self.rList:
            # loop through exits in room
            for e in range(len(r.exits)):
                # if room has an exit
                if r.exits[e] != None:
                    # loop through room list again
                    for t in self.rList:
                        # if current room id == exit int
                        if t.id == r.exits[e]:
                            # set exit to room object
                            r.exits[e] = t