コード例 #1
0
    def prepare_game(self, ttoa, storage_ready):
        if not storage_ready:
            exit()

        #initialize player for current user and log into Midgard
        username = getpass.getuser()
        me = adventurer.adventurer(username, True)
        #players location
        me.get_location()
        #initialize game controller
        self.blyton = enid.enid()

        if int(me.location.lat) == 0 and int(me.location.lon) == 0:
            # We didn't get location yet, register adventure list to be refreshed after first location change
            print "No initial location, postponing adventure list generation until location changes"
            self.location_listener = me.connect('location-changed', self.show_game)
        else:
            self.show_game(me, me.location, '', '', False)
コード例 #2
0
ファイル: enid.py プロジェクト: cannonerd/adventure_tablet
    def adventure_from_mission(self, mission, player):
        target = point.point(mission.latitude, mission.longitude)
        mission_adventure = adventure.adventure(target, mission.text, mission)

        # Check for adventurers
        adventurers = []
        qb = midgard.query_builder('ttoa_log')
        qb.add_constraint('mission', '=', mission.id)
        logs = qb.execute()
        for log in logs:
            if log.author not in adventurers:
                adventurers.append(log.author)
        for participant in adventurers:
            user = midgard.mgdschema.ttoa_user()
            user.get_by_id(participant)
            if user.username == player.nick:
                # We don't add the current player to adventures, they do so manually
                continue
            else:
                mission_adventure.add_adventurer(adventurer.adventurer(user.username), True)

        return mission_adventure
コード例 #3
0
ファイル: enid.py プロジェクト: cannonerd/adventure_tablet
        else:
            south = 1
        if args[1] < 0:
            west = -1
        else:
            west = 1
        try:
            djia = urllib.urlopen((date - datetime.timedelta(td30)).strftime("http://irc.peeron.com/xkcd/map/data/%Y/%m/%d")).read()
        except IOError, e:
            print "geohash: DJIA connection failed"
            return None
        if '404 Not Found' in djia:
            # FIXME: Throw an exception here instead
            print("Dow Jones not available yet.")
            return None
        sum = hashlib.md5("%s-%s" % (date, djia)).digest()
        n, w = [str(d*(abs(a)+f)) for d, f, a in zip((south, west),
            [x/2.**64 for x in struct.unpack_from(">QQ", sum)], args[0:])]
        geohash = point.point(n, w)
        return geohash

if __name__ == '__main__':
    import adventurer
    suski = adventurer.adventurer('suski')
    location = suski.location()
    blyton = enid()
    date = datetime.date.today()
    mission = blyton.adventure_from_geohash(location, date)
    print("%s, your mission, if you choose to accept it, is:") % (suski.nick)
    print("  %s is in %s (%s, %s), some %s km away from you") % (mission.name, mission.destination.describe(), mission.destination.lat, mission.destination.lon, int(location.distance_to(mission.destination)))
コード例 #4
0
                qaikudata = message['data'].split(',')
                if len(qaikudata) == 3:
                    #print "Overriding comment location with QaikuData %s" % (message['data'])
                    message['geo']['coordinates'][1] = float(qaikudata[0])
                    message['geo']['coordinates'][0] = float(qaikudata[1])
                    colour = qaikudata[2]

            # Check if the adventure already has this player
            nick = message['user']['screen_name']
            message_adventurer = None
            for player in self.adventurers:
                if player.nick == nick:
                    message_adventurer = player
                    break
            if message_adventurer is None:
                message_adventurer = adventurer.adventurer(nick)
                if colour is not None:
                    if message_adventurer.colour != colour:
                        message_adventurer.set_colour(colour)
                message_adventurer.location = point.point(message['geo']['coordinates'][1], message['geo']['coordinates'][0])
                self.add_adventurer(message_adventurer, True)

            message_adventurer.location_changed_qaiku(message)

        if latest_update > 0:
            self.logs_last_updated = datetime.datetime.fromtimestamp(latest_update)
        return True

    def log_to_qaiku(self, log, adventurer):
        if self.qaikuid is None:
            #print "No QaikuID for adventure %s" % (self.name)