コード例 #1
0
ファイル: races.py プロジェクト: elvslv/web_game
	def dragonAttack(self, tokenBadge, regState):
		regState.checkIfImmune()
		if not(racesList[tokenBadge.raceId].canConquer(regState.region, tokenBadge) 
			and self.canConquer(regState.region, tokenBadge)):
			raise BadFieldException('badRegion')
			
		attackedTokenBadge = regState.tokenBadge
		attackedTokensNum = regState.tokensNum
		if attackedTokenBadge and attackedTokenBadge.id == tokenBadge.id:
			raise BadFieldException('badRegion')
			
		misc_game.clearFromRace(regState)
		if attackedTokenBadge:
			racesList[attackedTokenBadge.raceId].sufferCasualties(attackedTokenBadge)
		else:
			attackedTokensNum = 0
		##check anything else?
		for region in tokenBadge.regions: 
			region.dragon = False
		regState.tokenBadge = tokenBadge
		regState.dragon = True
		regState.tokensNum = 1
		regState.owner = tokenBadge.Owner()
		regState.inDecline = False
		tokenBadge.Owner().tokensInHand -= 1
		if attackedTokenBadge:
			racesList[attackedTokenBadge.raceId].sufferCasualties(attackedTokenBadge)
			attackedTokenBadge.Owner().tokensInHand += attackedTokensNum - racesList[attackedTokenBadge.raceId].getCasualties()
		dbi.updateWarHistory(tokenBadge.Owner(), attackedTokenBadge.id if 
			attackedTokenBadge else None, tokenBadge.id, None, regState.regionId,
			attackedTokensNum, ATTACK_DRAGON)
コード例 #2
0
ファイル: actions_game.py プロジェクト: NZem/webgame
def act_enchant(data):
    user = dbi.getXbyY('User', 'sid', data['sid'])
    if not (user.game and user.inGame):
        raise BadFieldException('notInGame')
    if not user.currentTokenBadge or user.currentTokenBadge.raceId != 9:
        raise BadFieldException('badStage')
    checkStage(GAME_CONQUER, user, ATTACK_ENCHANT)
    reg = user.game.map.getRegion(data['regionId']).getState(user.game.id)
    #print 'fff', reg.id, reg.tokenBadgeId
    if not reg.tokenBadge:
        raise BadFieldException('nothingToEnchant')
    victimBadgeId = reg.tokenBadge.id
    callRaceMethod(user.currentTokenBadge.raceId, 'enchant',
                   user.currentTokenBadge, reg)
    #clearFromRace(reg)
    dbi.updateWarHistory(user, victimBadgeId, user.currentTokenBadge.id, None,
                         reg.region.id, 1, ATTACK_ENCHANT)
    dbi.updateGameHistory(user.game, data)
    return {'result': 'ok'}
コード例 #3
0
ファイル: actions_game.py プロジェクト: NZem/webgame
def act_enchant(data):
	user = dbi.getXbyY('User', 'sid', data['sid'])
	if not (user.game and user.inGame): 
		raise BadFieldException('notInGame')
	if not user.currentTokenBadge or user.currentTokenBadge.raceId != 9: 
		raise BadFieldException('badStage')
	checkStage(GAME_CONQUER, user, ATTACK_ENCHANT)
	reg = user.game.map.getRegion(data['regionId']).getState(user.game.id)
	#print 'fff', reg.id, reg.tokenBadgeId
	if not reg.tokenBadge:
		raise BadFieldException('nothingToEnchant')
	victimBadgeId = reg.tokenBadge.id
	callRaceMethod(user.currentTokenBadge.raceId, 'enchant', user.currentTokenBadge,
		reg)
	#clearFromRace(reg)
	dbi.updateWarHistory(user, victimBadgeId, user.currentTokenBadge.id, None, 
			reg.region.id, 1, ATTACK_ENCHANT)
	dbi.updateGameHistory(user.game, data)
	return {'result': 'ok'}	
コード例 #4
0
ファイル: races.py プロジェクト: NZem/webgame
	def dragonAttack(self, tokenBadge, regState):
		regState.checkIfImmune()
		if not(racesList[tokenBadge.raceId].canConquer(regState.region, tokenBadge) 
			and self.canConquer(regState.region, tokenBadge)):
			raise BadFieldException('badRegion')
			
		attackedTokenBadge = regState.tokenBadge
		attackedTokensNum = regState.tokensNum
		if attackedTokenBadge and attackedTokenBadge.id == tokenBadge.id:
			raise BadFieldException('badRegion')
			
		#misc_game.clearFromRace(regState)
                if regState.tokenBadge:
                        race = racesList[regState.tokenBadge.raceId]
                        race.clearRegion(regState.tokenBadge, regState)
                        specialPower = specialPowerList[regState.tokenBadge.specialPowerId]
                        specialPower.clearRegion(regState.tokenBadge, regState)
		
		if attackedTokenBadge:
			racesList[attackedTokenBadge.raceId].sufferCasualties(attackedTokenBadge)
		else:
			attackedTokensNum = 0
		##check anything else?
		for region in tokenBadge.regions: 
			region.dragon = False
		regState.tokenBadge = tokenBadge
		regState.dragon = True
		regState.tokensNum = 1
		regState.owner = tokenBadge.Owner()
		regState.inDecline = False
		tokenBadge.Owner().tokensInHand -= 1
		if attackedTokenBadge:
			racesList[attackedTokenBadge.raceId].sufferCasualties(attackedTokenBadge)
			attackedTokenBadge.Owner().tokensInHand += attackedTokensNum - racesList[attackedTokenBadge.raceId].getCasualties()
		dbi.updateWarHistory(tokenBadge.Owner(), attackedTokenBadge.id if 
			attackedTokenBadge else None, tokenBadge.id, None, regState.regionId,
			attackedTokensNum, ATTACK_DRAGON)
コード例 #5
0
ファイル: actions_game.py プロジェクト: NZem/webgame
def act_conquer(data):
    user = dbi.getXbyY('User', 'sid', data['sid'])
    game = user.game
    if not (game and user.inGame):
        raise BadFieldException('notInGame')
    if not user.currentTokenBadge or not user.tokensInHand:
        raise BadFieldException('badStage')
    checkStage(GAME_CONQUER, user)
    region = game.map.getRegion(data['regionId'])
    regState = region.getState(game.id)
    victimTokenBadge = regState.tokenBadge
    owner = regState.owner
    if owner == user and not regState.inDecline:
        raise BadFieldException('badRegion')
    tokenBadge = user.currentTokenBadge
    raceId, specialPowerId = tokenBadge.raceId, tokenBadge.specPowId
    if not regState.inDecline:
        user.checkForFriends(owner)
    f1 = callRaceMethod(raceId, 'canConquer', region, tokenBadge)
    f2 = callSpecialPowerMethod(specialPowerId, 'canConquer', region,
                                tokenBadge)
    if not (f1 and f2):
        raise BadFieldException('badRegion')
    regState.checkIfImmune()
    attackedRace = None
    attackedSpecialPower = None
    if regState.tokenBadge:
        attackedRace = regState.tokenBadge.raceId
        attackedSpecialPower = regState.tokenBadge.specPowId
    enemyDefenseBonus = 0
    if attackedRace:
        enemyDefenseBonus = callRaceMethod(attackedRace, 'defenseBonus')
    defense = regState.tokensNum
    unitPrice = max(
        misc.BASIC_CONQUER_COST + defense + region.mountain +
        regState.encampment + regState.fortified + enemyDefenseBonus +
        callRaceMethod(raceId, 'attackBonus', region, tokenBadge) +
        callSpecialPowerMethod(specialPowerId, 'attackBonus', region,
                               tokenBadge), 1)
    unitsNum = user.tokensInHand
    if unitsNum + 3 < unitPrice:
        raise BadFieldException('badTokensNum')
    t = user.game.getLastState() == misc.GAME_THROW_DICE
    dice = t and user.game.history[-1].dice
    if not dice and unitsNum < unitPrice:
        dice = misc_game.throwDice(game)
    unitPrice -= (dice or 0)
    unitPrice = max(unitPrice, 1)
    if unitsNum < unitPrice:
        dbi.updateHistory(user, GAME_UNSUCCESSFULL_CONQUER,
                          user.currentTokenBadge.id)
        tokenBadge.totalTokensNum += callRaceMethod(tokenBadge.raceId,
                                                    'turnEndReinforcements',
                                                    user)
        return {'result': 'badTokensNum', 'dice': dice}
    clearFromRace(regState)  # Not sure if it's necessary
    victimBadgeId = regState.tokenBadgeId
    regState.owner = user
    regState.tokenBadge = user.currentTokenBadge
    regState.inDecline = False
    regState.tokensNum = unitPrice
    if victimTokenBadge:
        callRaceMethod(victimTokenBadge.raceId, 'sufferCasualties',
                       victimTokenBadge)
        owner.tokensInHand += defense - callRaceMethod(victimTokenBadge.raceId,
                                                       'getCasualties')
    callRaceMethod(raceId, 'conquered', regState, tokenBadge)
    dbi.updateWarHistory(user, victimBadgeId, tokenBadge.id, dice, region.id,
                         defense, ATTACK_CONQUER)
    user.tokensInHand -= unitPrice
    dbi.updateGameHistory(game, data)
    return {
        'result': 'ok',
        'dice': dice
    } if (dice and not t) else {
        'result': 'ok'
    }
コード例 #6
0
ファイル: actions_game.py プロジェクト: NZem/webgame
def act_conquer(data):
	user = dbi.getXbyY('User', 'sid', data['sid'])
	game = user.game
	if not (game and user.inGame): 
		raise BadFieldException('notInGame')
	if not user.currentTokenBadge or  not user.tokensInHand:
		raise BadFieldException('badStage') 
	checkStage(GAME_CONQUER, user)
	region = game.map.getRegion(data['regionId'])
	regState = region.getState(game.id)
	victimTokenBadge = regState.tokenBadge
	owner = regState.owner
	if owner == user and not regState.inDecline: 
		raise BadFieldException('badRegion')
	tokenBadge = user.currentTokenBadge
	raceId, specialPowerId = tokenBadge.raceId, tokenBadge.specPowId
	if not regState.inDecline:
		user.checkForFriends(owner)
	f1 = callRaceMethod(raceId, 'canConquer', region, tokenBadge)
	f2 = callSpecialPowerMethod(specialPowerId, 'canConquer',  region,  tokenBadge)
	if not (f1 and f2):
		raise BadFieldException('badRegion')
	regState.checkIfImmune()
	attackedRace = None
	attackedSpecialPower = None
	if regState.tokenBadge:
		attackedRace = regState.tokenBadge.raceId
		attackedSpecialPower = regState.tokenBadge.specPowId
	enemyDefenseBonus = 0
	if attackedRace:
		enemyDefenseBonus = callRaceMethod(attackedRace, 'defenseBonus')
	defense = regState.tokensNum
	unitPrice = max(misc.BASIC_CONQUER_COST + defense + region.mountain + 
		regState.encampment + regState.fortified +  enemyDefenseBonus +
		callRaceMethod(raceId, 'attackBonus', region, tokenBadge) + 
		callSpecialPowerMethod(specialPowerId, 'attackBonus', region, tokenBadge)
			, 1)
	unitsNum = user.tokensInHand
	if unitsNum + 3 < unitPrice:
		raise BadFieldException('badTokensNum') 
	t = user.game.getLastState() == misc.GAME_THROW_DICE
	dice = t and user.game.history[-1].dice
	if not dice and unitsNum < unitPrice : 
		dice = misc_game.throwDice(game)
	unitPrice -= (dice or 0)
	unitPrice = max(unitPrice, 1)
	if unitsNum < unitPrice:
		dbi.updateHistory(user, GAME_UNSUCCESSFULL_CONQUER, user.currentTokenBadge.id)
		tokenBadge.totalTokensNum += callRaceMethod(tokenBadge.raceId, 'turnEndReinforcements', user)
		return {'result': 'badTokensNum', 'dice': dice}
	clearFromRace(regState)					# Not sure if it's necessary
	victimBadgeId = regState.tokenBadgeId
	regState.owner = user
	regState.tokenBadge = user.currentTokenBadge
	regState.inDecline = False
	regState.tokensNum = unitPrice
	if victimTokenBadge:
		callRaceMethod(victimTokenBadge.raceId, 'sufferCasualties', victimTokenBadge)
		owner.tokensInHand += defense - callRaceMethod(victimTokenBadge.raceId, 'getCasualties')
	callRaceMethod(raceId, 'conquered', regState, tokenBadge)
	dbi.updateWarHistory(user, victimBadgeId, tokenBadge.id, dice, 
		region.id, defense, ATTACK_CONQUER)
	user.tokensInHand -= unitPrice
	dbi.updateGameHistory(game, data)
	return {'result': 'ok', 'dice': dice} if (dice and not t) else {'result': 'ok'}