Beispiel #1
0
def defender():
    for grid in Grid.all():
        dbid = "g:%s:def" % grid['id']
        # Get the most recently placed infector
        try:
            latest = db.zrange(dbid, 0, 1)[0]
        except IndexError:
            continue
        l_time = db.zscore(dbid, latest)
        if int(time()) - int(l_time) < 3:
            return

        defenders = db.zrange(dbid, 0, -1)
        for defender in defenders:
            c = grid.get(defender)
            if int(time()) - int(db.zscore(dbid, defender)) < 3:
                break
            TileDest[8](grid, c, grid.getPlayer(c['player']))
            db.zrem(dbid, str(defender))
Beispiel #2
0
def infector():
    for grid in Grid.all():
        dbid = "g:%s:inf" % grid['id']
        # Get the most recently placed infector
        try:
            latest = db.zrange(dbid, 0, 1)[0]
        except IndexError:
            continue

        l_time = db.zrank(dbid, latest)
        if (int(time()) - int(l_time)) < 3:
            # The most recent has been sittig for under 3 seconds, 
            # so we're done here
            continue
        # Looks like we can't take that shortcut. Let's loop.
        coords = db.zrange(dbid, 0, -1)
        for infector in coords:
            c = grid.get(infector)
            if int(time()) - int(db.zscore(dbid, infector)) < 3:
                break

            around = grid.around(c, [1,4], 1, True)
            for coord in around:
                if coord['player'] == c['player']:
                    continue
                if coord['type'] == "4":
                    TileDest[4](grid, coord, grid.getPlayer(coord['player']))
                    coords.remove(str(coord))
                else:
                    TileDest[1](grid, coord, grid.getPlayer(coord['player']))
                coord['type'] = 1
                coord['player'] = c['player']
                UpdateManager.sendCoord(grid, coord)

            # Delete the infector
            db.zrem(dbid, str(c))
            c['type'] = 1
            c['health'] = 25
            UpdateManager.sendCoord(grid, c)
Beispiel #3
0
def dest_defender(grid, coord, player):
    db.zrem(grid.dbid + ":def", str(coord))
    db.delete(coord.dbid)
    db.rename("def:" + coord.dbid, coord.dbid)
    UpdateManager.sendCoord(grid, coord)
Beispiel #4
0
def dest_inf(grid, coord, player):
    db.zrem(grid.dbid + ":inf", str(coord))