Пример #1
0
    def set_loaded(self):
        from sys import maxint

        obj = Object()
        obj.name = "Loading Complete."
        far = maxint*-1
        obj.loc = IntVector(x=far, y=far, z=far)
        obj.states.extend(['hidden'])
        obj.save()
        print obj.name
Пример #2
0
    def insert_objects(self):
        '''Insert any objects you want to be present in the zone into the
        database in this call.

        This gets called exactly once per database. If you change something here
        and want it to appear in the zone's database, you will need to clear the
        database first.

        Deleting the "Loading Complete" object will only cause duplicates.
        Do not do this.
        '''

        # Place 10 chickens randomly:
        for i in xrange(10):
            obj = ScriptedObject()
            obj.name = "Chicken #%d" % i
            obj.resource = 'chicken'
            obj.loc = IntVector(x=randloc(), y=randloc(), z=randloc())
            obj.rot = FloatVector(x=randrot(), y=randrot(), z=randrot())
            obj.scale = FloatVector(x=randscale(), y=randscale(), z=randscale())
            obj.vel = FloatVector(x=0, y=0, z=0)
            obj.states.extend(['alive', 'whole', 'clickable'])
            obj.scripts = ['games.objects.chicken']
            obj.save()

        print [o.name for o in Object.objects()]
Пример #3
0
 def update_scene(self):
     '''Update the internal scene with any changes to the zone's objects.
     This is like get_objects() from the client, only directly grabbing from the server.'''
     # Get all the objects since our last update.
     for o in Object.objects(last_modified__gte=self.last_update, physical=True):
         if o.id in self.objects:
             # This object is already in our scene, let's update its position
             # with what the database says its position is.
             self.objects[o.id]['me_obj'] = o
             self.objects[o.id]['body'].position = o.loc.x, o.loc.y
         else:
             # This object is not in our physics scene yet
             self.insert_space_object(o)
     self.last_update = datetime.datetime.now()
Пример #4
0
    def move(self, xmod, ymod, zmod):
        self.me_obj.loc['x'] += xmod
        self.me_obj.loc['y'] += ymod
        self.me_obj.loc['z'] += zmod
        self.me_obj.last_modified = datetime.datetime.now()

        from helpers import manhattan
        ourx, oury = self.me_obj.loc['x'], self.me_obj.loc['y']
        for o in Object.objects(physical=True):
            # Is the distance between that object and the character less than 3?
            if o.loc and manhattan(o.loc['x'], o.loc['y'], ourx, oury) < 1:
                # We collided against something, so return now and don't
                # save the location changes into the database.
                return False
        else:
            # We didn't collide with any objects.
            self.me_obj.save()
            return True
Пример #5
0
    def __init__(self, zoneid):
        super(ZoneScriptRunner, self).__init__()

        # Make sure mongodb is up
        while True:
            try:
                me.connect(zoneid)
                break
            except(me.connection.ConnectionError):
                # Mongo's not up yet. Give it time.
                time.sleep(.1)

        # While the zone is not loaded, wait.
        while not Object.objects(name="Loading Complete."):
            time.sleep(.1)

        # Watch the script path for any changes, and reboot the scriptserver if they do.
        self.observer = Observer()
        self.observer.schedule(ScriptEventHandler(), path=settings.SCRIPT_PATH, recursive=True)
        self.observer.start()

        self.load_scripts()
        logger.info("Started with data for zone: %s" % zoneid)
Пример #6
0
    def set_movement(self, character, xmod, ymod, zmod, user=None):
        charobj = self.create_character(character, owner=user)

#         try:
#             charobj.loc
#         except(AttributeError):
#             # Character doesn't exist, create a new one.
#             self.set_status(500)
#             self.write('Character "%s" was not set to online, and didn\'t exist in the database.' % character)
#             return

        # Set the character's new position based on the x, y and z modifiers.
        if hasattr(charobj, 'loc') and charobj.loc is not None:
            charobj.loc['x'] += xmod*charobj.speed
            charobj.loc['y'] += ymod*charobj.speed
            charobj.loc['z'] += zmod*charobj.speed
            charobj.last_modified = datetime.datetime.now()
        else:
            charobj.loc = IntVector(x=0, y=0, z=0)

        # Do simple physics here.
        # TODO: Split this into its own method.
        def manhattan(x1, y1, x2, y2):
            return abs(x1-x2) + abs(y1-y2)

        charx, chary = charobj.loc['x'], charobj.loc['y']
        for o in Object.objects(physical=True):
            # Is the distance between that object and the character less than 3?
            if o.loc and manhattan(o.loc['x'], o.loc['y'], charx, chary) < 3:
                # We collided against something, so return now and don't
                # save the location changes into the database.
                return False

        # We didn't collide, hooray!
        # So we'll save to the database and return it.
        charobj.save()
        return charobj
Пример #7
0
 def is_loaded(self):
     return True if Object.objects(name="Loading Complete.") else False