def sendMessage(handler, **args): UpdateManager.sendGrid(Grid(handler.user['grid']), "newMessage", handler.user, pid = handler.user['pid'], text = args['text'] ) return { "status": 200 }
def joinGrid(handler, **args): try: #TODO: Sanity checks gid = args['gid'] except KeyError: return {"status": 406, "error": "no gid"} pid = None if "pid" in args: pid = args['pid'] g = Grid(gid) if g.exists() is False: return {"status":404, "error":"Grid not found."} # Add the user to the grid/UpdateManager pid = g.addUser(handler.user, pid) if pid is False: return { "status":406, "error": "Grid is full" } handler.user['pid'] = pid handler.user['grid'] = gid handler.user['active'] = True player = handler.user.getPlayer() # Looks like it's a new player, go ahead and init them if g.playerExists(pid) is False: player['cash'] = g['init_cash'] # Starting cash value player['inc'] = 0 player['lastInc'] = int(time()) player['tused'] = g['init_tused'] player['tlim'] = g['init_tlim'] updated = g.loadEvent("join_%s" % pid) # Add their new coords for coord in updated: UpdateManager.sendCoord(g, coord, handler.user) # Announce our color to all other clients UpdateManager.sendGrid(g, "addPlayer", handler.user) return { "status":200, "uid": handler.user['id'], "pid": pid, "cash": player['cash'], "inc": player['inc'], "tused": player['tused'], "tlim": player['tlim'], "colors": g.getColors(), "color": player['color'], "coords": g.dump() }
def damager(): for grid in Grid.all(): length = db.llen(grid.dbid + ":dam") # List of tiles that can be damaged takes_damage = [2, 3, 4, 5, 6, 7] for i in range(0, length): c = grid.get(db.lindex(grid.dbid + ":dam", i)) around = grid.around(c, 0, 1) for coord in around: # Make sure we can damage it if (int(coord['type']) not in takes_damage) or (c['player'] == coord['player']): continue before = coord['type'] coord.damage(10) if coord['type'] == before: UpdateManager.sendGrid(grid, "setHealth", coord=str(coord), health=coord['health']) else: UpdateManager.sendGrid(grid, "set", coord=str(coord), tile = 1, player = coord['player'], health=25) # Damage/delete the damager c.damage(10) if int(c['type']) == 6: UpdateManager.sendGrid(grid, "setHealth", coord=str(c), health=c['health']) else: db.lrem(grid.dbid + ":dam", str(c), 0) UpdateManager.sendCoord(grid, c)