示例#1
0
文件: actions.py 项目: NZem/webgame
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'}
示例#2
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}
示例#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, 
示例#4
0
文件: misc_game.py 项目: NZem/webgame
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,
示例#5
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}
示例#6
0
文件: actions.py 项目: NZem/webgame
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'}
示例#7
0
def initRegions(map, game):
	for region in map.regions:
		regState = RegionState(region, game)
		dbi.add(regState)
示例#8
0
文件: misc_game.py 项目: NZem/webgame
def initRegions(map, game):
    for region in map.regions:
        regState = RegionState(region, game)
        dbi.add(regState)