def route(game_id,data,userid,username): command = None params = [] if data: command = COMMAND_MAPPINGS.get(data[0].lower()) if len(data) > 1: params = data[1:] if command: game_state = GameState() game_state.load(game_id) try: return command(commands.Game(game_state), params,userid,username).to_json() finally: game_state.save(game_id) return {'text': u"""Usage: /slack command, where commands are: reset [confirm]: reset the game if "confirm" is passed as the parameter setup [add|remove]: display the current setup. If add is the parameter, add rest of text as setup text. If remove, remove the nth item. pool [reroll|setup]: show the current dice pool. if setup passed as a parameter, setup the initial pool. if reroll passed in, reroll all dice in the pool. register [name]: register your player name with the game unregister [name]: unregister yourself or the specified user status: output current status to channel take [color number]: take a die from the pool give [color number] [user]: give a die to another player. use "pool" as player name to return to the pool. roll: roll all your dice and give the aggregate score spend: spend one your dice (so you no longer have it)"""}
def route(game_id, data, userid, username): command = None params = [] if data: command = COMMAND_MAPPINGS.get(data[0].lower()) if len(data) > 1: params = data[1:] if command: game_state = GameState() game_state.load(game_id) try: return command(commands.Game(game_state), params, userid, username).to_json() finally: game_state.save(game_id) return { "text": u"""Usage: /slack command, where commands are: reset [confirm]: reset the game if "confirm" is passed as the parameter setup [add|remove]: display the current setup. If add is the parameter, add rest of text as setup text. If remove, remove the nth item. pool [reroll|setup]: show the current dice pool. if setup passed as a parameter, setup the initial pool. if reroll passed in, reroll all dice in the pool. register [name]: register your player name with the game unregister [name]: unregister yourself or the specified user status: output current status to channel take [color number]: take a die from the pool give [color number] [user]: give a die to another player. use "pool" as player name to return to the pool. roll: roll all your dice and give the aggregate score spend: spend one your dice (so you no longer have it)""" }
def unlock(): data = request.json # data={slug,x,y,password} game_state = GameState.load(data['slug'], data['password']) message = game_state.unlock(data['x'], data['y']) game_state.check_cash() db.save(data['slug'], game_state.data) return make_response(game_state, message)
def sell(): data = request.json # data={slug,seed,password} game_state = GameState.load(data['slug'], data['password']) message = game_state.sell(data['seed']) game_state.check_cash() db.save(data['slug'], game_state.data) return make_response(game_state, message)
def harvest(): data = request.json # data={slug,x,y,password} game_state = GameState.load(data['slug'], data['password']) message = game_state.harvest(data['x'], data['y']) game_state.add_recipes() db.save(data['slug'], game_state.data) return make_response(game_state, message)
def recipe(): data = request.json # data={slug,password} game_state = GameState.load(data['slug'], data['password']) known_recipes = {} for recipe_id in CONFIG.recipes: if game_state.is_known_recipe(recipe_id): known_recipes[recipe_id] = CONFIG.recipes[recipe_id] return make_response(game_state, recipes=known_recipes)
def state(slug): valid_chars(slug) body = request.json if body['newOrLoad'] == 'new': game_state = GameState.new(slug, body['password']) if body['newOrLoad'] == 'load': game_state = GameState.load(slug, body['password']) if game_state is None: raise NotFound("Game %s does not exist" % slug) db.save(slug, game_state.data) return make_response(game_state)
def buy(): data = request.json # data={slug,recipe_id,password} game_state = GameState.load(data['slug'], data['password']) message = game_state.buy(data['recipe_id']) db.save(data['slug'], game_state.data) return make_response(game_state, message)
def sow(): data = request.json # data={slug,seed,x,y,password} game_state = GameState.load(data['slug'], data['password']) message = game_state.sow(data['seed'], data['x'], data['y']) db.save(data['slug'], game_state.data) return make_response(game_state, message)