Ejemplo n.º 1
0
def act_sendMessage(data):
    userId = dbi.getXbyY('User', 'sid', data['sid']).id
    msgTime = misc.generateTimeForTest() if misc.TEST_MODE else math.trunc(
        time.time())
    text = data['text']
    dbi.add(Message(userId, text, msgTime))
    return {'result': 'ok'}
Ejemplo n.º 2
0
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}
Ejemplo n.º 3
0
def showNextRace(game, lastIndex, vRace = None, vSpecialPower = None):
	raceId, specPowerId = getNextRaceAndPowerFromStack(game, vRace, vSpecialPower)
	tokenBadges = dbi.query(TokenBadge).filter(TokenBadge.gameId == game.id).all()
	tokenBadgesInStack = filter(lambda x: not x.Owner() and not x.inDecline and x.pos > lastIndex, tokenBadges) 
	for tokenBadge in tokenBadgesInStack: 
		tokenBadge.pos -= 1
		dbi.flush(tokenBadge)
	tokBadge = TokenBadge(raceId, specPowerId, game.id)
	dbi.add(tokBadge)
	dbi.flush(tokBadge)
	return races.racesList[raceId].name, races.specialPowerList[specPowerId].name, 
Ejemplo n.º 4
0
def showNextRace(game, lastIndex, vRace=None, vSpecialPower=None):
    raceId, specPowerId = getNextRaceAndPowerFromStack(game, vRace,
                                                       vSpecialPower)
    tokenBadges = dbi.query(TokenBadge).filter(
        TokenBadge.gameId == game.id).all()
    tokenBadgesInStack = filter(
        lambda x: not x.Owner() and not x.inDecline and x.pos > lastIndex,
        tokenBadges)
    for tokenBadge in tokenBadgesInStack:
        tokenBadge.pos -= 1
        dbi.flush(tokenBadge)
    tokBadge = TokenBadge(raceId, specPowerId, game.id)
    dbi.add(tokBadge)
    dbi.flush(tokBadge)
    return races.racesList[raceId].name, races.specialPowerList[
        specPowerId].name,
Ejemplo n.º 5
0
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}
Ejemplo n.º 6
0
def act_sendMessage(data):
	userId = dbi.getXbyY('User', 'sid', data['sid']).id
	msgTime = misc.generateTimeForTest() if misc.TEST_MODE else math.trunc(time.time())
	text = data['text']
	dbi.add(Message(userId, text, msgTime))
	return {'result': 'ok'}
Ejemplo n.º 7
0
def initRegions(map, game):
	for region in map.regions:
		regState = RegionState(region, game)
		dbi.add(regState)
Ejemplo n.º 8
0
def initRegions(map, game):
    for region in map.regions:
        regState = RegionState(region, game)
        dbi.add(regState)