예제 #1
0
파일: actions.py 프로젝트: NZem/webgame
def act_aiJoin(data):
    game = dbi.getXbyY('Game', 'id', data['gameId'])
    if game.state != GAME_WAITING:
        raise BadFieldException('badGameState')
    maxPlayersNum = game.map.playersNum
    if len(game.players) >= maxPlayersNum:
        raise BadFieldException('tooManyPlayers')
    maxPriority = max(game.players, key=lambda x: x.priority).priority if len(
        game.players) else 0
    aiCnt = len(filter(lambda x: x.isAI == True, game.players))
    sid = getSid()
    ai = User('AI%d' % sid, None, True)
    ai.sid = sid
    ai.gameId = game.id
    ai.isReady = True
    ai.priority = maxPriority + 1
    ai.inGame = True
    dbi.add(ai)
    dbi.flush(ai)
    game.aiRequiredNum -= 1
    readyPlayersNum = dbi.query(User).filter(User.gameId == game.id).filter(
        User.isReady == True).count()
    if maxPlayersNum == readyPlayersNum:
        misc_game.startGame(game, ai, data)
    return {'result': 'ok', 'sid': ai.sid, 'id': ai.id}
예제 #2
0
def act_setReadinessStatus(data):
    user = dbi.getXbyY('User', 'sid', data['sid'])
    game = user.game
    if not (game and user.inGame):
        raise BadFieldException('notInGame')

    if game.state != GAME_WAITING:
        raise BadFieldException('badGameState')

    user.isReady = data['isReady']
    dbi.flush(user)
    maxPlayersNum = game.map.playersNum
    readyPlayersNum = dbi.query(User).filter(User.game == game).filter(
        User.isReady == True).count()
    if maxPlayersNum == readyPlayersNum:
        misc_game.startGame(game, user, data)
    dbi.updateGameHistory(user.game, data)
    return {'result': 'ok'}
예제 #3
0
def act_setReadinessStatus(data):
	user = dbi.getXbyY('User', 'sid', data['sid'])
	game = user.game
	if not (game and user.inGame): 
		raise BadFieldException('notInGame')

	
	if game.state != GAME_WAITING:
		raise BadFieldException('badGameState')

	user.isReady = data['isReady']
	dbi.flush(user)
	maxPlayersNum = game.map.playersNum
	readyPlayersNum = dbi.query(User).filter(User.game==game).filter(User.isReady==True).count()
	if maxPlayersNum == readyPlayersNum:
		misc_game.startGame(game, user, data)
	dbi.updateGameHistory(user.game, data)
	return {'result': 'ok'}
예제 #4
0
파일: actions.py 프로젝트: NZem/webgame
def act_aiJoin(data):
	game = dbi.getXbyY('Game', 'id', data['gameId'])
	if game.state != GAME_WAITING:
		raise BadFieldException('badGameState')
	maxPlayersNum = game.map.playersNum
	if len(game.players) >= maxPlayersNum:
		raise BadFieldException('tooManyPlayers')
	maxPriority = max(game.players, key=lambda x: x.priority).priority if len(game.players) else 0
	aiCnt = len(filter(lambda x: x.isAI == True, game.players))
	sid = getSid()
	ai = User('AI%d' % sid, None, True)
	ai.sid = sid
	ai.gameId = game.id
	ai.isReady = True
	ai.priority = maxPriority + 1
	ai.inGame = True
	dbi.add(ai)
	dbi.flush(ai)
	game.aiRequiredNum -= 1
	readyPlayersNum = dbi.query(User).filter(User.gameId == game.id).filter(User.isReady==True).count()
	if maxPlayersNum == readyPlayersNum:
		misc_game.startGame(game, ai, data)
	return {'result': 'ok', 'sid' : ai.sid, 'id' : ai.id}