Example #1
0
    def card_levelup(usr, tp, cardid):
        """
		用卡牌升级
		"""

        if not cardid:
            return {}

        petConf = config.getConfig('pet')
        practiceLevelConf = config.getConfig('practice_level')
        inv = usr.getInventory()

        point = 0

        for cid in cardid:
            card = inv.getCard(cid)
            if not card:
                return {'msg': 'card_not_exist'}
            quality = petConf[card['cardid']]['quality']
            point = practiceLevelConf['card_point'][quality - 1] + point
            inv.delCard(card['id'])

        res = practice.levelup(usr, tp, point, practiceLevelConf)
        if res.has_key('msg'):
            return res

        inv.save()
        usr.save()

        data = practice.practice_type(usr, tp)
        data['delete_dic'] = {}
        for cid in cardid:
            data['delete_dic'][cid] = 1
        return data
Example #2
0
	def get_prestige_award(self, roleid, rolelevel):
		"""
		得到声望奖励
		"""
		infectionPrestigePriceConf = config.getConfig('infection_prestige_price')
		gameConf = config.getConfig('game')		
		
		levelGroup = gameConf['infection_ladder_level_group'][-1]
		for lg in gameConf['infection_ladder_level_group']:
			if rolelevel < lg:
				levelGroup = lg
				break
		infectionPrestigePriceInfo = infectionPrestigePriceConf[str(levelGroup)]
		
		last_award_prestige_score = self.user[roleid]['last_award_prestige_score']
		prestige_score = self.user[roleid]['prestige_score']
		
		award = []
		next_awrd_score = last_award_prestige_score
		for key in infectionPrestigePriceInfo:
			pp = int(key)
			if pp > last_award_prestige_score and pp <= prestige_score:
				award.append(key)
				if next_awrd_score < pp:
					next_awrd_score = pp
					
		self.user[roleid]['last_award_prestige_score'] = next_awrd_score
		
		data = {}
		data['award'] = award		
		
		return data	
Example #3
0
def set_nickname(request):
	"""
	ÉèÖÃêdzÆ
	"""
	nickname = request.GET['nickname']
	gender = request.GET['gender']
	avatar = request.GET['avatar']
	gameConf = conf.getConfig('game')
	
	if gender != 'male' and gender != 'female':
		return HttpResponse(json.dumps({'msg':'gender_out_of_except'}))	
	try:
		acc = getAccount(request, account)		
		acc.gender = gender
		usr = acc.makeUserAndBind(nickname, avatar, gender)		
		loginData = onUserLogin(request, usr)
	except NotLogin:
		return HttpResponse(json.dumps({'msg':'login_not'}))
	except DuplicateNickname:
		return HttpResponse(json.dumps({'msg':'nickname_duplicate'}))
	if acc.nickname:
		return HttpResponse(json.dumps({'msg':'nickname_already_have'}))
	
	acc.nickname = nickname
	usr.last_login = currentTime()
	gameConf = conf.getConfig('game')
	data = usr.getLoginData(gameConf)
	data['login'] = loginData
	usr.notify = {}
	usr.save()	
	return HttpResponse(json.dumps(data))
Example #4
0
    def levelup(usr, destCardid, sourceCardid):
        """
		升级
		"""
        if not sourceCardid:
            return {'msg': 'card_not_exist'}
        inv = usr.getInventory()
        gameConf = config.getConfig('game')
        petLevelConf = config.getConfig('pet_level')
        petConf = config.getConfig('pet')
        destCard = inv.getCard(destCardid)
        sourceCard = []

        for cardid in sourceCardid:
            if not pet.isCardAvailable(usr, cardid):
                return {'msg': 'card_not_available'}
            card = inv.getCard(cardid)
            if not card:
                return {'msg': 'card_not_exist'}
            sourceCard.append(card)

        costMoney = len(sourceCard) * gameConf['pet_levelup_gold_cost']
        exp = 0
        for card in sourceCard:
            tExp = pet.totalExp(card, petConf, petLevelConf, gameConf)
            exp = tExp + exp
            inv.delCard(card['id'])

        pet.gainExp(usr, destCard, exp, petConf, petLevelConf, gameConf)
        inv.save()
        return {
            'update_card': inv.getClientCard(destCard),
            'delete_card': sourceCardid
        }
Example #5
0
	def skill_levelup(usr, tp, skillid):
		"""
		用技能升级
		"""
		if not skillid:
			return {}
		
		skillConf = config.getConfig('skill')
		practiceLevelConf = config.getConfig('practice_level')
		inv = usr.getInventory()
		
		point = 0
		
		for sid in skillid:
			sk = inv.getSkill(sid)
			if not sk:
				return {'msg': 'skill_not_exist'}
			quality = skillConf[sk['skillid']]['quality']
			point = practiceLevelConf['skill_point'][quality - 1] + point
			inv.delSkill(sk['id'])
			
		res = practice.levelup(usr, tp, point, practiceLevelConf)
		if res.has_key('msg'):
			return res
		
		inv.save()
		usr.save()
		
		data = practice.practice_type(usr, tp)
		data['delete_dic'] = {}
		for sid in skillid:
			data['delete_dic'][sid] = 1
			
		
		return data
Example #6
0
	def card_chip_levelup(usr, tp, chipDic):
		"""
		用卡牌碎片升级
		"""
		if not chipDic:
			return {}
		
		petConf = config.getConfig('pet')
		practiceLevelConf = config.getConfig('practice_level')
		inv = usr.getInventory()
		
		point = 0
		
		for chipid in chipDic:
			if not inv.card_chip.has_key(chipid):
				return {'msg':'chip_not_exist'}
			inv.card_chip[chipid] = inv.card_chip[chipid] - chipDic[chipid]
			if inv.card_chip[chipid] < 0:
				return {'msg': 'chip_not_enough'}
			if inv.card_chip[chipid] == 0:
				del inv.card_chip[chipid]
			quality = petConf[chipid]['quality']
			point = int(practiceLevelConf['card_point'][quality - 1] / petConf[chipid]['chip']) * chipDic[chipid] + point
		
		res = practice.levelup(usr, tp, point, practiceLevelConf)
		if res.has_key('msg'):
			return res	
		inv.save()
		usr.save()
		
		data = practice.practice_type(usr, tp)
		data['delete_dic'] = chipDic
		return data
Example #7
0
	def install(usr, teamPosition, ownerTeamPosition, slotpos, stoneid):
		"""
		安装宝石
		"""
		inv = usr.getInventory()
		
		if not inv.team[teamPosition]:
			return {'msg':'team_position_not_have_member'}				
		card = inv.getCard(inv.team[teamPosition])
		if not card:
			return {'msg': 'card_not_exist'}		
		gameConf = config.getConfig('game')		
		if gameConf['stone_slot_level'][slotpos] > usr.level:
			return {'msg': 'level_required'}
		
		if not card.has_key('st_slot'):
			card['st_slot'] = stone.make_st_solt()
	
		stoneConf = config.getConfig('stone')		
		st = None
		owner = None
		if ownerTeamPosition < 0:		
			st = inv.withdrawStone(stoneid)
		else:
			ownerid = inv.team[ownerTeamPosition]
			if not ownerid:
				return {'msg':'team_position_not_have_member'}
			owner = inv.getCard(ownerid)
			if not owner:
				return {'msg': 'card_not_exist'}
			for i, s in enumerate(owner['st_slot']):
				if s and s['id'] == stoneid:
					st = s
					owner['st_slot'][i] = {}
					break			
		
		if not st:
			return {'msg':'stone_not_exist'}
				
		oldst = card['st_slot'][slotpos]
		if (not oldst) and (not stoneid):
			return {'msg':'stone_not_exist'}
			
		sttype = stoneConf[st['stoneid']][st['level'] - 1]['type']
		for st1 in card['st_slot']:
			if st1 and stoneConf[st1['stoneid']][st['level'] - 1]['type'] == sttype:
				return {'msg':'stone_same_type_installed'}				
		
		card['st_slot'][slotpos] = st		
		if oldst:
			inv.depositStone(oldst)		
		inv.save()			
		data = {}		
		data['st_slot'] = inv.getStSlots()
		if oldst:
			data['add_stone'] = oldst			
		if st:
			data['delete_stone'] = st
			
		return data		
Example #8
0
	def card_levelup(usr, tp, cardid):
		"""
		用卡牌升级
		"""
				
		if not cardid:
			return {}
		
		petConf = config.getConfig('pet')
		practiceLevelConf = config.getConfig('practice_level')
		inv = usr.getInventory()
		
		point = 0
		
		for cid in cardid:
			card = inv.getCard(cid)
			if not card:
				return {'msg':'card_not_exist'}
			quality = petConf[card['cardid']]['quality']
			point = practiceLevelConf['card_point'][quality - 1] + point
			inv.delCard(card['id'])
			
		res = practice.levelup(usr, tp, point, practiceLevelConf)
		if res.has_key('msg'):
			return res
		
		inv.save()
		usr.save()
		
		data = practice.practice_type(usr, tp)
		data['delete_dic'] = {}
		for cid in cardid:
			data['delete_dic'][cid] = 1		
		return data
Example #9
0
	def update_exp(usr, gameConf):		
		
		petConf = config.getConfig('pet')
		petLevelConf = config.getConfig('pet_level')		
		inv = usr.getInventory()
				
		now = currentTime()
		eduCard = []
		for edu_slot in usr.educate['edu_slot']:
			if edu_slot and edu_slot.has_key('start_time'):
				educateDuration = now - edu_slot['last_update_time']
				if educateDuration > gameConf['educate_duration']:
					educateDuration = gameConf['educate_duration']
					del edu_slot['start_time']
					del edu_slot['last_update_time']
				else: 
					exp = edu_slot['expptm'] * (now - edu_slot['last_update_time']) / 600 * edu_slot['rate'] + edu_slot['fraction']
				edu_slot['fraction'] = exp - int(exp)
				exp = int(exp)
				if exp:
					card = inv.getCard(edu_slot['card_id'])
					pet.gainExp(card, int(exp), petConf, petLevelConf, gameConf)
					edu_slot['last_update_time'] = now
					eduCard.append(card)		
		inv.save()		
Example #10
0
    def skill_levelup(usr, tp, skillid):
        """
		用技能升级
		"""
        if not skillid:
            return {}

        skillConf = config.getConfig('skill')
        practiceLevelConf = config.getConfig('practice_level')
        inv = usr.getInventory()

        point = 0

        for sid in skillid:
            sk = inv.getSkill(sid)
            if not sk:
                return {'msg': 'skill_not_exist'}
            quality = skillConf[sk['skillid']]['quality']
            point = practiceLevelConf['skill_point'][quality - 1] + point
            inv.delSkill(sk['id'])

        res = practice.levelup(usr, tp, point, practiceLevelConf)
        if res.has_key('msg'):
            return res

        inv.save()
        usr.save()

        data = practice.practice_type(usr, tp)
        data['delete_dic'] = {}
        for sid in skillid:
            data['delete_dic'][sid] = 1

        return data
Example #11
0
File: pet.py Project: gittme/cggame
	def levelup(usr, destCardid, sourceCardid):
		if not sourceCardid:
			return {'msg':'card_not_exist'}
		inv = usr.getInventory()
		gameConf = config.getConfig('game')
		petLevelConf = config.getConfig('pet_level')
		petConf = config.getConfig('pet')
		destCard = inv.getCard(destCardid)
		sourceCard = []
		
		for cardid in sourceCardid:
			if not pet.isCardAvailable(usr, cardid):
				return {'msg':'card_not_available'}
			card = inv.getCard(cardid)			
			sourceCard.append(card)		
		
		costMoney = len(sourceCard) * gameConf['pet_levelup_gold_cost']		
		exp = 0
		for card in sourceCard:
			exp = pet.totalExp(card, petConf, petLevelConf, gameConf) + exp
			inv.delCard(card['id'])
		
		exp = int(exp * 0.5)
		pet.gainExp(destCard, exp, petConf, petLevelConf, gameConf)
		inv.save()
		return {'update_card':destCard, 'delete_card':sourceCardid}
Example #12
0
File: pet.py Project: gittme/cggame
	def training(usr, cardid, trainlevel):
		inv = usr.getInventory()
		
		card = inv.getCard(cardid)
		if not card:
			return {'msg':'card_not_exist'}
			
		cost = {}	
		gameConf = config.getConfig('game')
		if trainlevel == '0':
			trpPriceConfig = config.getConfig('trp_price')
			cost = {'trp':trpPriceConfig[usr.level - 1], 'gold':0, 'gem':0}
		elif trainlevel == '1':
			cost = gameConf['training_price1']
		elif trainlevel == '2':
			cost = gameConf['training_price2']
		elif trainlevel == '3':
			cost = gameConf['training_price3']
		else:
			return {'msg':'parameter_bad'}
	
		if cost['gold'] > usr.gold:
			return {'msg':'gold_not_enough'}
		if cost['gem'] > usr.gem:
			return {'msg': 'gem_not_enough'}
		if cost['trp'] > usr.trp:
			return {'msg': 'trp_not_enough'}
				
		strrev = 0
		itlrev = 0
		artrev = 0
		if trainlevel == '0':
			strrev = random.randint(-10, int(card['level']))
			itlrev = random.randint(-10, int(card['level'] * 1.5 - strrev))
			artrev = random.randint(-10, int(card['level'] * 1.5 - strrev - itlrev))
		elif trainlevel == '1':
			strrev = random.randint(-10, int(card['level']))
			itlrev = random.randint(-10, int(card['level'] * 2 - strrev))
			artrev = random.randint(-10, int(card['level'] * 2 - strrev - itlrev))
		elif trainlevel == '2':
			strrev = random.randint(-10, int(card['level']))
			itlrev = random.randint(-10, int(card['level'] * 2.5 - strrev))
			artrev = random.randint(-10, int(card['level'] * 2.5 - strrev - itlrev))
		elif trainlevel == '3':
			strrev = random.randint(-10, int(card['level']))
			itlrev = random.randint(-10, int(card['level'] * 3 - strrev))
			artrev = random.randint(-10, int(card['level'] * 3 - strrev - itlrev))
				
		usr.train_prd['cardid'] = cardid
		usr.train_prd['strength_revision'] = strrev
		usr.train_prd['intelligence_revision'] = itlrev
		usr.train_prd['artifice_revision'] = artrev
		
		usr.gold = usr.gold - cost['gold']
		usr.gem = usr.gem - cost['gem']
		usr.trp = usr.trp - cost['trp']
		
		usr.save()
		
		return {'train_prd': usr.train_prd, 'gold':usr.gold, 'gem':usr.gem, 'trp':usr.trp}	
Example #13
0
	def update_exp(usr, gameConf):		
		"""
		更新经验
		"""
		petConf = config.getConfig('pet')
		petLevelConf = config.getConfig('pet_level')		
		inv = usr.getInventory()
				
		now = currentTime()
		eduCard = []
		for edu_slot in usr.educate['edu_slot']:
			if edu_slot and edu_slot.has_key('start_time'):
				educateGradeConf = config.getConfig('educate_grade')		
				educateEndTime = edu_slot['start_time'] + gameConf['educate_duration']
				educateDuration = now - edu_slot['last_update_time']				
				if now > educateEndTime:
					educateDuration = educateEndTime - edu_slot['last_update_time']
					del edu_slot['start_time']
					del edu_slot['last_update_time']
				else:
					edu_slot['last_update_time'] = now
				rate = educateGradeConf[edu_slot['edt']]['rate']
				exp = edu_slot['expptm'] * educateDuration / 3600 * rate + edu_slot['fraction']
				edu_slot['fraction'] = exp - int(exp)
				exp = int(exp)
				if exp:
					card = inv.getCard(edu_slot['card_id'])
					pet.gainExp(usr, card, int(exp), petConf, petLevelConf, gameConf)					
					eduCard.append(card)		
		inv.save()
		usr.save()	
Example #14
0
	def beckon(usr, useGem):
		"""
		招财
		"""
		if not usr.luckycat:
			return {'msg':'luckycat_not_available'}
		luckycatProfitConf = config.getConfig('luckycat_profit')
		gameConf = config.getConfig('game')
		luckycat.updateBeckon(usr)
		
		gameConf = config.getConfig('game')		 
		
		if usr.luckycat['beckon_count'] >= gameConf['luckycat_beckon_count_base']	and (not useGem):
			return {'msg':'luckycat_beckon_max_free_count'}
				
		if usr.luckycat['beckon_count'] >= gameConf['luckycat_beckon_count_base'] + vip.value(usr, 'gem_beckon'):
			return {'msg':'luckycat_beckon_max_count'}
				
		if usr.luckycat['beckon_cooldown'] > gameConf['luckycat_cooldown_max'] and (not useGem):
			return {'msg':'luckycat_beckon_in_cooldown'}
			
		costGem = 0	
		if useGem:
			costGem = gameConf['luckycat_beckon_gem_base'] + gameConf['luckycat_beckon_gem_delta'] * usr.luckycat['beckon_gem_count']
			if usr.gem < costGem:
				return {'msg':'gem_not_enough'}
		
		luckycatBlessConf = config.getConfig('luckycat_bless')
		
		beckonGold = luckycatProfitConf[usr.level - 1]['beckonProfit']
		
		beckonCritical, blessid = luckycat.beckon_once(usr, useGem, beckonGold,  luckycatBlessConf, gameConf)
		
		usr.save()
		return {'gold':usr.gold, 'luckycat_beckon_count':usr.luckycat['beckon_count'], 'luckycat_beckon_cooldown':usr.luckycat['beckon_cooldown'], 'beckon_critical':beckonCritical, 'gem':usr.gem, 'bless':blessid}	
Example #15
0
	def visit(usr, level):
		"""
		访问
		"""
		inv = usr.getInventory()
		gameConf = config.getConfig('game')
		stoneProbabilityConf = config.getConfig('stone_probability')
		
		if level > len(usr.stv):
			return {'msg':'svt_too_hight'}
		
		if not usr.stv[level - 1]:
			return {'msg':'svt_not_available'}			
	
		result = []	
		msg = stone.do_visit(usr, level, result, gameConf,stoneProbabilityConf)		
		usr.save()
		inv.save()
		
		if msg:
			return msg		
		data = result[0]
		data['gold'] = usr.gold	
		data['gem'] = usr.gem
		return data
Example #16
0
    def card_chip_levelup(usr, tp, chipDic):
        """
		用卡牌碎片升级
		"""
        if not chipDic:
            return {}

        petConf = config.getConfig('pet')
        practiceLevelConf = config.getConfig('practice_level')
        inv = usr.getInventory()

        point = 0

        for chipid in chipDic:
            if not inv.card_chip.has_key(chipid):
                return {'msg': 'chip_not_exist'}
            inv.card_chip[chipid] = inv.card_chip[chipid] - chipDic[chipid]
            if inv.card_chip[chipid] < 0:
                return {'msg': 'chip_not_enough'}
            if inv.card_chip[chipid] == 0:
                del inv.card_chip[chipid]
            quality = petConf[chipid]['quality']
            point = int(practiceLevelConf['card_point'][quality - 1] /
                        petConf[chipid]['chip']) * chipDic[chipid] + point

        res = practice.levelup(usr, tp, point, practiceLevelConf)
        if res.has_key('msg'):
            return res
        inv.save()
        usr.save()

        data = practice.practice_type(usr, tp)
        data['delete_dic'] = chipDic
        return data
Example #17
0
	def degradation(usr, equipmentid):
		"""
		降级
		"""
		inv = usr.getInventory()
		equipment = inv.getEquipment(equipmentid)
		
		if not equipment:
			return {'msg':'equipment_not_exist'}
		
		if not equipment.has_key('strengthLevel'):
			return {'msg':'strength_level_required'}
				
		gameConf = config.getConfig('game')
		strengthenPriceConf = config.getConfig('strength_price')
		equipmentConf = config.getConfig('equipment')
		equipmentInfo = equipmentConf[equipment['equipmentid']]
		equipmentQuality = equipmentInfo['quality']		
		goldGain = int(strengthenPriceConf[str(equipmentQuality)][equipment['strengthLevel']] * gameConf['equipment_degradation_price_rate'])
		
		equipment['strengthLevel'] = equipment['strengthLevel'] - 1
		if equipment['strengthLevel'] <= 0:
			del equipment['strengthLevel']
		
		usr.gold = usr.gold + goldGain
		
		inv.save()
		usr.save()
		
		return {'gold':usr.gold, 'equipment_degradation':equipment}
Example #18
0
	def encounter(self, roleid, name):		
		"""
		遇敌
		"""
		gameConf = config.getConfig('game')
		now = currentTime()		
		self.update_battle(now, gameConf)
		if self.battle.has_key(roleid):
			battle = self.battle[roleid][-1]
			if battle and (not infection_arena.battle_is_finish(battle, now, gameConf)):
				return {'msg': 'infection_battle_not_finish'}
			
		rd = randint()
		quality = -1
		for (i, qualityInfo) in enumerate(gameConf['infection_quality']):
			if rd > qualityInfo['probability']:
				rd = rd - qualityInfo['probability']
			else:
				quality = i
				
		if quality < 0:
			return {'msg':'infection_bad_quality'}
		
		if not self.user.has_key(roleid):
			self.user[roleid] = infection_arena.make_user(name)		
				
		level = self.user[roleid]['level']		
		self.update_prestige(roleid, now)
				
		infectionBattleConf = config.getConfig('infection_battle')
		infectionBattleInfo = infectionBattleConf[str(quality)][level - 1]
		if not infectionBattleInfo:
			return {'msg':'infection_battle_not_exist'}
		
		battle = {}
		battle['monster'] = []
		
		totalhp = 0
		monsterConf = config.getConfig('monster')		
		for monsterid in infectionBattleInfo['monster']:
			monsterInfo = monsterConf[monsterid]			
			monster = {}
			monster['monsterid'] = monsterid
			monster['hp'] = monsterInfo['hp']
			totalhp = totalhp + monsterInfo['hp']
			battle['monster'].append(monster)
		battle['monster_total_hp'] = totalhp
		battle['quality'] = quality
		battle['level'] = level
		battle['roleid'] = roleid
		battle['create_time'] = now
		battle['user'] = {}
		battle['rolename'] = name
		self.battle[roleid] = []
		self.battle[roleid].append(battle)
		
		self.user[roleid]['infection_list'].append(infection_arena.make_relief(battle))
		self.save()
		return {'battle':self.battle[roleid]}
Example #19
0
	def onEveryLeveup(usr):
		gameConf = config.getConfig('game')
		luckycatLevelConf = config.getConfig('luckycat_level')
		if gameConf['luckycat_level_critical_itme'].count(usr.luckycat['level']):
			usr.luckycat['critical_point_list'].append(hit(gameConf['luckycat_critical_point_probability']))		
		awardGold = luckycatLevelConf[usr.luckycat['level']]['levelupGold']		
		awardGem = 0
		return awardGold, awardGem	
Example #20
0
    def defeate(usr):
        """
		击败
		"""
        res = None
        if usr.arena.has_key('challenge_roleid'):

            if SIGLE_SERVER:
                from arenarank.routine.arena import arena as arenaR
                return arenaR.defeat(str(usr.roleid),
                                     str(usr.arena['challenge_roleid']))
            else:
                res = json.loads(
                    curl.url(
                        ARENE_SERVER + '/arena/defeat/', None, {
                            'offence_roleid': usr.roleid,
                            'defence_roleid': usr.arena['challenge_roleid']
                        }))

            arenaLootConf = config.getConfig('arena_loot')
            gameConf = config.getConfig('game')

            if res.has_key('msg'):
                return res

            alreadyReach = False
            for item in gameConf['arena_rank_award']:
                if item['rank'] >= res['position'] and (
                        not usr.arena['rank_award'].has_key(item['rank'])):
                    usr.arena['rank_award'][item['rank']] = True

            arenaLootInfo = arenaLootConf[usr.level - 1]
            challengeRole = usr.__class__.get(usr.arena['challenge_roleid'])
            challengeRole.gold = challengeRole.gold - arenaLootInfo['gold']
            if challengeRole.gold < 0:
                challengeRole.gold = 0
            challengeRole.notify_gold()
            challengeRole.save()
            del usr.arena['challenge_roleid']
            card = None
            gold = 0
            skl = None
            data = {}
            if usr.arena.has_key('loot'):
                data = drop.do_award(usr, usr.arena['loot'], data)
                data = drop.makeData(data, res, 'award')

            usr.gainExp(arenaLootInfo['exp'])
            usr.gold = usr.gold + arenaLootInfo['gold']
            data['exp'] = usr.exp
            data['level'] = usr.level
            data['gold'] = usr.gold
            usr.save()
            return data
        return {'msg': 'arena_ladder_have_not_chellenge'}
Example #21
0
	def send_gift(usr, item, friendid):
		"""
		送礼
		"""
		giftConf = config.getConfig('gift')
		if not giftConf.has_key(item):
			return {'msg':'gift_not_exist'}
		
		giftInfo = giftConf[item]
		
		usrNw = usr.getNetwork()
		goldCost = giftInfo['gold']
		if usr.gold < goldCost:
			return {'msg': 'gold_not_enough'}
		gemCost = giftInfo['gem']
		if usr.gem < gemCost:
			return {'msg': 'gem_not_enough'}
				
		usr.gold = usr.gold - goldCost
		usr.gem = usr.gem - gemCost
		
		friend = usr.__class__.get(friendid)
		if not friend:
			return {'msg':'usr_not_exist'}
		
		friendNw = friend.getNetwork()

		if not usrNw.gift.has_key(item):
			usrNw.gift[item] = {'receive_count':0, 'send_count':0}
		
		if not friendNw.gift.has_key(item):
			friendNw.gift[item] = {'receive_count':0, 'send_count':0}
		
		friendNw.gift[item]['receive_count'] = friendNw.gift[item]['receive_count'] + 1
		usrNw.gift[item]['send_count'] = usrNw.gift[item]['send_count'] + 1
		friendNw.charm = friendNw.charm + giftInfo['charm']				
		usrNw.tuhao = usrNw.tuhao + giftInfo['tuhao']
		gift.notify_new_gift(friend, item)
		
		usrNw.send_gift_record.append({'roleid':friendid, 'send_time':currentTime(), 'item':item})
		friendNw.receive_gift_record.append({'roleid':usr.roleid, 'receive_time':currentTime(), 'item':item})
	
		
		gameConf = config.getConfig('game')
		gift.update_send_gift_list(usr, gameConf)
		gift.update_receive_gift_list(friend, gameConf)
		
		usr.save()
		usrNw.save()
		friend.save()
		friendNw.save()
		gift.send_gift_recored(usrNw.roleid, friend.roleid)
		return {'tuhao':usrNw.tuhao, 'gold':usr.gold, 'gem': usr.gem}
Example #22
0
    def explore(usr):
        """
		探险
		"""
        explore.update_explore(usr)

        exploreConf = config.getConfig('explore_award')
        exploreInfo = exploreConf[str(usr.level)]
        gameConf = config.getConfig('game')
        usr.explore['times'] = usr.explore['times'] + 1
        if usr.explore['times'] >= gameConf['explore_max_times']:
            return {'msg': 'explore_max_times'}
        usr.explore['last_update_times_time'] = currentTime()
        awd = {}
        awd = drop.roll(exploreInfo[0], awd)
        rv = random.uniform(gameConf['explore_gold_and_exp_revision'][0],
                            gameConf['explore_gold_and_exp_revision'][1])
        if awd.has_key('gold'):
            awd['gold'] = awd['gold'] * rv
        if awd.has_key('exp'):
            awd['exp'] = awd['exp'] * rv
        rd = randint()
        if rd < gameConf['explore_critical_probability'] + usr.explore[
                'critical_count'] * gameConf[
                    'explore_critical_probability_growth']:
            for key in awd:
                awd[key] = awd[key] * gameConf['explore_critical_income_rate']

        awd = drop.roll(exploreInfo[1], awd)
        awd = drop.do_award(usr, awd, {})
        data = drop.makeData(awd, {})

        rd = randint()
        if rd < gameConf['explore_extra_times_probability']:
            usr.explore['times'] = usr.explore['times'] - 1
            if usr.explore['times'] < 0:
                usr.explore['times'] = 0
            data['explore_times'] = usr.explore['times']

        rd = randint()
        if rd < gameConf['explore_friend_probability']:
            friendData = explore.recommend_friend(usr)
            if friendData:
                data['friend_data'] = friendData

        rd = randint()
        if rd < gameConf['infection_explore_probability']:
            infaction_battle = infection.explore_encounter(usr, gameConf)
            if infaction_battle:
                data['infaction_battle'] = infaction_battle

        usr.save()
        return data
Example #23
0
    def onEveryLeveup(usr):
        """
		每次升级
		"""
        gameConf = config.getConfig('game')
        luckycatLevelConf = config.getConfig('luckycat_level')
        if gameConf['luckycat_level_critical_itme'].count(
                usr.luckycat['level']):
            usr.luckycat['critical_point_list'].append(
                hit(gameConf['luckycat_critical_point_probability']))
        awardGold = luckycatLevelConf[usr.luckycat['level']]['levelupGold']
        awardGem = 0
        return awardGold, awardGem
Example #24
0
def end(request):
    """
	结束地下城
	"""
    battleId = request.GET['battle_id']
    fieldId = request.GET['field_id']
    star = request.GET['star']
    star = int(star)
    usr = request.user
    dun = usr.getDungeon()
    dunConf = config.getConfig('dungeon')

    if dun.curren_field['battleid'] != battleId or fieldId != dun.curren_field[
            'fieldid']:
        return {'msg': 'dungeon_finished'}

    for battleConf in dunConf:
        if battleConf['battleId'] == battleId:
            for fieldConf in battleConf['field']:
                if fieldConf['fieldId'] == fieldId:
                    gameConf = config.getConfig('game')
                    exp = fieldConf['exp']
                    if dun.daily_recored[battleId][fieldId]['vip_reset']:
                        exp = int(exp * gameConf['dungeon_reset_benefit'])
                    usr.gainExp(exp)
                    data = {}
                    if fieldConf['dropid']:
                        awd = {}
                        awd = drop.open(usr, fieldConf['dropid'], awd)
                        data = dun.award()
                        data = drop.makeData(awd, data)

                    data['exp'] = usr.exp
                    data['level'] = usr.level
                    data['gold'] = usr.gold

                    infectionBattle = infection.dungeon_encounter(usr)
                    if infectionBattle:
                        if not infectionBattle.has_key('msg'):
                            data['infection_battle'] = infectionBattle
                    #if dun.curren_field['battleid'] == dun.last_dungeon['battleid'] and dun.curren_field['fieldid'] == dun.last_dungeon['fieldid']:
                    #	dun.nextField()
                    dun.curren_field = {'battleid': '', 'fieldid': ''}
                    dun.normalRecordEnd(battleId, fieldId, star)
                    #data['last_dungeon'] = dun.last_dungeon
                    qt = usr.getQuest()
                    qt.updateDungeonCountQuest()
                    qt.updateFinishDungeonQuest(battleId, fieldId)
                    dun.save()
                    return data
    return {'msg': 'field_not_exist'}
Example #25
0
    def reborn(usr, id):
        """
		转生
		"""

        gameConf = config.getConfig('game')
        rebornConf = config.getConfig('reborn')

        costGold = gameConf['pet_reborn_price']['gold']
        costGem = gameConf['pet_reborn_price']['gem']

        if usr.gold < costGold:
            return {'msg': 'gold_not_enough'}
        if usr.gem < costGem:
            return {'msg': 'gem_not_enough'}

        inv = usr.getInventory()
        card = inv.getCard(id)
        if not card:
            return {'msg': 'card_not_exist'}

        rebornInfo = None
        for r in rebornConf:
            if r['star_max'] > card['init_star']:
                rebornInfo = r
                break
            if not card.has_key('reborn_level'):
                card['reborn_level'] = 0
            if r['level'] > card['reborn_level']:
                rebornInfo = r
                break

        if not rebornInfo:
            return {'msg': 'reborn_can_not'}

        if rebornInfo['level'] > card['level']:
            return {'msg': 'reborn_level_required'}

        if not card.has_key('reborn_level'):
            card['reborn_level'] = 0
        if not card.has_key('reborn_count'):
            card['reborn_count'] = 0

        card['init_star'] = card['init_star'] = pet.reborn_inc_star(rebornInfo)
        card['reborn_level'] = rebornInfo['level']
        card['reborn_count'] = card['reborn_count'] + 1
        usr.gold = usr.gold - costGold
        inv.save()
        usr.save()

        return {'update_card': inv.getClientCard(card), 'gold': usr.gold}
Example #26
0
	def play(usr):
		"""
		玩老虎机
		"""
		now = currentTime()
		
		gameConf = config.getConfig('game')
		
		isAvailable = True
		
		for ts in gameConf['slot_machine_open_time']:
			t = str_to_date_time(ts)
			if is_same_day(now, t):
				isAvailable = True
				break
				
		if not isAvailable:
			return {'msg':'slotmachine_not_available'}
						
		slotmachineConf = config.getConfig('slotmachine')
				
		times = len(usr.slotmachine['play_time'])
		
		if len(slotmachineConf['price']) <= times:		
			return {'msg':'slotmachine_max_time'}
				
		gemCost = slotmachineConf['price'][times]
				
		if usr.gem < gemCost:
			return {'msg':'gem_not_enough'}
		
		usr.gem = usr.gem - gemCost
		
		rd = randint()
				
		benefit = 1
		for bf in slotmachineConf['rate']:
			if rd > bf['probability']:
				rd = rd - bf['probability']
			else:
				benefit = bf['benefit']
				
		gem = int(gemCost * benefit)
		
		usr.gem = usr.gem + gem
		
		usr.slotmachine['play_time'].append(now)
		usr.save()
		
		
		return {'benefit':gem, 'gem':usr.gem}
Example #27
0
	def updateSp(self):
		"""
		更新sp
		"""
		levelConf = config.getConfig('level')
		gameConf = config.getConfig('game')
		maxSp = levelConf[self.level - 1]['sp']
		sp_recover_before = currentTime() - self.sp_last_recover
		if sp_recover_before > gameConf['sp_recover_interval']:
			point = sp_recover_before // gameConf['sp_recover_interval']
			self.sp_last_recover = self.sp_last_recover + (point * gameConf['sp_recover_interval'])
			self.sp = self.sp + point
			if self.sp > maxSp:
				self.sp = maxSp	
Example #28
0
    def beckon_clickonce(usr):
        """
		一键招财
		"""
        if not usr.luckycat:
            return {'msg': 'luckycat_not_available'}

        if not vip.value(usr, 'beckon_clickonce'):
            return {'msg': 'vip_required'}

        luckycatProfitConf = config.getConfig('luckycat_profit')
        gameConf = config.getConfig('game')
        luckycat.updateBeckon(usr)

        gameConf = config.getConfig('game')

        if usr.luckycat['beckon_count'] >= gameConf[
                'luckycat_beckon_count_base'] and (not useGem):
            return {'msg': 'luckycat_beckon_max_free_count'}

        if usr.luckycat['beckon_count'] >= gameConf[
                'luckycat_beckon_count_base'] + vip.value(usr, 'gem_beckon'):
            return {'msg': 'luckycat_beckon_max_count'}

        if usr.luckycat['beckon_cooldown'] > gameConf[
                'luckycat_cooldown_max'] and (not useGem):
            return {'msg': 'luckycat_beckon_in_cooldown'}

        costGem = gameConf['luckycat_beckon_gem_base'] + gameConf[
            'luckycat_beckon_gem_delta'] * usr.luckycat['beckon_gem_count']
        if usr.gem < costGem:
            return {'msg': 'gem_not_enough'}

        luckycatBlessConf = config.getConfig('luckycat_bless')

        beckonGold = luckycatProfitConf[usr.level - 1]['beckonProfit']

        for i in range(10):
            if usr.gem < costGem:
                break
            beckonCritical, blessid = luckycat.beckon_once(
                usr, costGem, beckonGold, luckycatBlessConf, gameConf)

        usr.save()
        return {
            'gold': usr.gold,
            'luckycat_beckon_count': usr.luckycat['beckon_count'],
            'luckycat_beckon_cooldown': usr.luckycat['beckon_cooldown'],
            'gem': usr.gem
        }
Example #29
0
def end(request):
	"""
	结束地下城
	"""
	battleId = request.GET['battle_id']
	fieldId = request.GET['field_id']
	star = request.GET['star']
	star = int(star)
	usr = request.user
	dun = usr.getDungeon()	
	dunConf = config.getConfig('dungeon')
	
	if dun.curren_field['battleid'] != battleId or fieldId != dun.curren_field['fieldid']:
		return {'msg':'dungeon_finished'}
	
	for battleConf in dunConf:
		if battleConf['battleId'] == battleId:
			for fieldConf in battleConf['field']:
				if fieldConf['fieldId'] == fieldId:
					gameConf = config.getConfig('game')
					exp = fieldConf['exp']
					if dun.daily_recored[battleId][fieldId]['vip_reset']:
						exp = int(exp * gameConf['dungeon_reset_benefit'])
					usr.gainExp(exp)
					data = {}
					if fieldConf['dropid']:
						awd = {}					
						awd = drop.open(usr, fieldConf['dropid'], awd)					
						data = dun.award()
						data = drop.makeData(awd, data)
						
					data['exp'] = usr.exp
					data['level'] = usr.level
					data['gold'] = usr.gold	
					
					infectionBattle = infection.dungeon_encounter(usr)
					if infectionBattle:
						if not infectionBattle.has_key('msg'):
							data['infection_battle'] = infectionBattle
					#if dun.curren_field['battleid'] == dun.last_dungeon['battleid'] and dun.curren_field['fieldid'] == dun.last_dungeon['fieldid']:
					#	dun.nextField()
					dun.curren_field = {'battleid':'', 'fieldid':''}
					dun.normalRecordEnd(battleId, fieldId, star)
					#data['last_dungeon'] = dun.last_dungeon
					qt = usr.getQuest()
					qt.updateDungeonCountQuest()
					qt.updateFinishDungeonQuest(battleId, fieldId)
					dun.save()
					return data					
	return {'msg':'field_not_exist'}
Example #30
0
File: gm.py Project: gittme/cggame
def gain_card_exp(request):
	cardid = request.GET['card']
	exp = int(request.GET['exp'])	
	usr = request.user
	inv = usr.getInventory()
	gameConf = config.getConfig('game')
	petLevelConf = config.getConfig('pet_level')
	petConf = config.getConfig('pet')
	card = inv.getCard(cardid)
	if not card:
		return {'msg':'card_not_exist'}
	pet.gainExp(card, exp, petConf, petLevelConf, gameConf)				
	inv.save()
	return {'update_card':card}
Example #31
0
	def defeate(usr):
		"""
		击败
		"""
		res = None
		if usr.arena.has_key('challenge_roleid'):
			
			if SIGLE_SERVER:
				from arenarank.routine.arena import arena as arenaR
				return arenaR.defeat(str(usr.roleid), str(usr.arena['challenge_roleid']))
			else:
				res = json.loads(curl.url(ARENE_SERVER +  '/arena/defeat/', None, {'offence_roleid':usr.roleid, 'defence_roleid':usr.arena['challenge_roleid']}))
			
			arenaLootConf = config.getConfig('arena_loot')
			gameConf = config.getConfig('game')
						
			if res.has_key('msg'):
				return res
				
			alreadyReach = False
			for item in gameConf['arena_rank_award']:
				if item['rank'] >= res['position'] and (not usr.arena['rank_award'].has_key(item['rank'])):
					usr.arena['rank_award'][item['rank']] = True
					
				
			arenaLootInfo = arenaLootConf[usr.level - 1]
			challengeRole = usr.__class__.get(usr.arena['challenge_roleid'])
			challengeRole.gold = challengeRole.gold - arenaLootInfo['gold']
			if challengeRole.gold < 0:
				challengeRole.gold = 0
			challengeRole.notify_gold()
			challengeRole.save()
			del usr.arena['challenge_roleid']
			card = None
			gold = 0
			skl = None			
			data = {}
			if usr.arena.has_key('loot'):
				data = drop.do_award(usr, usr.arena['loot'], data)
				data = drop.makeData(data, res, 'award')
				
			usr.gainExp(arenaLootInfo['exp'])
			usr.gold = usr.gold + arenaLootInfo['gold']
			data['exp'] = usr.exp
			data['level'] = usr.level
			data['gold'] = usr.gold
			usr.save()
			return data			
		return {'msg':'arena_ladder_have_not_chellenge'}
Example #32
0
    def garcha_skill(usr, nature):
        """
		求技能
		"""
        gameConf = config.getConfig('game')

        if (nature > len(gameConf['garcha_skill_dropid'])) or (nature < 0):
            return {'msg': 'parameter_bad'}

        goldCost = gameConf['garcha_skill_price'][nature - 1]['gold']
        gemCost = gameConf['garcha_skill_price'][nature - 1]['gem']

        if int(goldCost) == 0 and int(gemCost) == 0:
            return {'msg': 'parameter_bad'}

        if usr.gold < goldCost:
            return {'msg': 'gold_not_enough'}
        if usr.gem < gemCost:
            return {'msg': 'gem_not_enough'}

        awd = {}
        awd = drop.open(usr, gameConf['garcha_skill_dropid'][nature - 1], awd)

        data = drop.makeData(awd, {})

        usr.gold = usr.gold - goldCost
        usr.gem = usr.gem - gemCost

        data['gold'] = usr.gold
        data['gem'] = usr.gem
        return data
Example #33
0
    def update(self, position, roleid, now):
        """
		更新
		"""

        ladderScoreConf = config.getConfig('ladder_score')
        item = self.item[roleid]
        duration = now - item['last_update']
        if duration < 60:
            return item
        score = 0
        ladderScoreInfo = {}
        infoPosition = -1

        for p in ladderScoreConf:
            p = int(p)
            if p <= (position + 1) and p > (infoPosition):
                infoPosition = p

        ladderScoreInfo = ladderScoreConf[str(infoPosition)]
        score = ladderScoreInfo['efficiency'] - (float(
            (position + 1) - infoPosition) * ladderScoreInfo['score'] / 100)
        score = int(score * duration / 600)
        item['last_update'] = now
        item['score'] = item['score'] + score
        return item
Example #34
0
	def emailOpen(self, id):
		"""
		打开邮件
		"""
		
		if not self.email.has_key(id):
			return {'msg':'email_not_exist'}
		
		if self.email[id]['open']:
			return {'msg':'email_already_open'}
		
		usr = self.user
		emailConf = config.getConfig('email')
		emailInfo = emailConf[self.email[id]['emailid']]
		if emailInfo:
			awd = {}
			awd = drop.open(usr, emailInfo['dropid'], awd)
			awd = drop.makeData(awd, {})
		self.email[id]['open'] = True
		
		self.save()
		
		data = awd
		data['email_update'] = self.email[id]
		return data
Example #35
0
	def update(self, position, roleid, now):
		"""
		更新
		"""
		
		ladderScoreConf = config.getConfig('ladder_score')				
		item = self.item[roleid]		
		duration = now - item['last_update']		
		if duration < 60:
			return item
		score = 0
		ladderScoreInfo = {}
		infoPosition = -1
				
		for p in ladderScoreConf:
			p = int(p)
			if p <= (position + 1) and p > (infoPosition):
				infoPosition = p
				
		ladderScoreInfo = ladderScoreConf[str(infoPosition)]			
		score = ladderScoreInfo['efficiency'] - (float((position + 1) - infoPosition) * ladderScoreInfo['score'] / 100)
		score = int(score * duration / 600)
		item['last_update'] = now
		item['score'] = item['score'] + score
		return item
Example #36
0
    def beckon_reset(usr):
        """
		重置招财
		"""
        if not usr.luckycat:
            return {'msg': 'luckycat_not_available'}

        gameConf = config.getConfig('game')
        costGem = gameConf['luckycat_beckon_reset_price']['gem']
        costGold = gameConf['luckycat_beckon_reset_price']['gold']

        if usr.gem < costGem:
            return {'msg': 'gem_not_enough'}
        if usr.gold < costGold:
            return {'msg': 'gold_not_enough'}

        usr.gem = usr.gem - costGem
        usr.gold = usr.gold - costGold

        usr.luckycat['beckon_cooldown'] = 0
        usr.luckycat['beckon_last_update_time'] = currentTime()

        usr.save()
        return {
            'gold': usr.gold,
            'gem': usr.gem,
            'luckycat_beckon_cooldown': luckycat.beckon_cooldown(usr)
        }
Example #37
0
    def emailOpen(self, id):
        """
		打开邮件
		"""

        if not self.email.has_key(id):
            return {'msg': 'email_not_exist'}

        if self.email[id]['open']:
            return {'msg': 'email_already_open'}

        usr = self.user
        emailConf = config.getConfig('email')
        emailInfo = emailConf[self.email[id]['emailid']]
        if emailInfo:
            awd = {}
            awd = drop.open(usr, emailInfo['dropid'], awd)
            awd = drop.makeData(awd, {})
        self.email[id]['open'] = True

        self.save()

        data = awd
        data['email_update'] = self.email[id]
        return data
Example #38
0
    def assembly(usr, skillid):
        """
		安装技能
		"""
        inv = usr.getInventory()

        if not inv.skill_chip.has_key(skillid):
            return {'msg': 'skill_chip_not_enough'}

        skillConf = config.getConfig('skill')

        if not skillConf.has_key(skillid):
            return {'msg': 'skill_chip_not_exist'}

        skillInfo = skillConf[skillid]

        if inv.skill_chip[skillid] < skillInfo['chip']:
            return {'msg': 'skill_chip_not_enough'}

        inv.skill_chip[skillid] = inv.skill_chip[skillid] - skillInfo['chip']
        if inv.skill_chip[skillid] == 0:
            del inv.skill_chip[skillid]
        skill = inv.addSkill(skillid)
        inv.save()

        if inv.skill_chip.has_key(skillid):
            return {
                'skill_chip': {
                    skillid: inv.skill_chip[skillid]
                },
                'add_skill': skill
            }
        else:
            return {'skill_chip': {skillid: 0}, 'add_skill': skill}
Example #39
0
	def draw_award(usr, position):
		"""
		开服奖励
		"""
		openAwardConf = config.getConfig('open_award')
		drawidx = []
		
		for t in usr.signin['draw_award_time']:
			if is_same_day(t, currentTime()):
				return {'msg':'open_award_already_get'}
		
		for idx, ad in enumerate(openAwardConf['draw_award']):
			 if len(usr.signin['draw_award_time']) > idx and not usr.signin['draw_award_time'][idx]:
			 	continue
			 if ad['day'] > len(usr.signin['draw_award_time']):
			 	continue			 	
			 drawidx.append(idx)
			 
		if not drawidx:
			return {'msg':'open_award_already_get'}
			
		adidx = random.sample(drawidx, 1)[0]
		ad = openAwardConf['draw_award'][adidx]
		awd = {}
		awd = drop.open(usr, ad['dropid'], awd)
		while len(usr.signin['draw_award_time']) <= adidx:
			usr.signin['draw_award_time'].append({})
		usr.signin['draw_award_time'][adidx] = {'time':currentTime(), 'position': position}
		usr.save()
		data = drop.makeData(awd, {})
		
		return data	
Example #40
0
	def continue_award(usr):
		"""
		连续登陆
		"""
		openAwardConf = config.getConfig('open_award')
		if not signin.is_continue_award_available(openAwardConf):
			return {'msg':'open_award_not_available'}
							
		if signin.is_continue_award_already_get(usr):
			return {'msg':'open_award_already_get'}
		
		now = currentTime()
		if not usr.signin['continue_award_time']:
			if day_diff(now, usr.signin['continue_award_time'][-1]) != 1:
				usr.signin['continue_award_time'] = []
				
		usr.signin['continue_award_time'].append(now)
		
		
		cardid = openAwardConf['continue_award'][len(usr.signin['continue_award_time']) - 1]
		
		inv = usr.getInventory()
		c = inv.addCard(cardid)
		inv.save()
		usr.save()
		data = {}
		data['add_card'] = c
		return data
Example #41
0
	def assembly(usr, equipmentid):
		"""
		装配
		"""
		inv = usr.getInventory()
		
		if not inv.equipment_chip.has_key(equipmentid):
			return {'msg':'equipment_chip_not_enough'}
		
		equipmentConf = config.getConfig('equipment')
		
		if not equipmentConf.has_key(equipmentid):
			return {'msg':'equipment_chip_not_exist'}
		
		equipmentInfo = equipmentConf[equipmentid]
		
		if inv.equipment_chip[equipmentid] < equipmentInfo['chip']:
			return {'msg':'equipment_chip_not_enough'}
				
		inv.equipment_chip[equipmentid] = inv.equipment_chip[equipmentid] - equipmentInfo['chip']
		if inv.equipment_chip[equipmentid] == 0:
			del inv.equipment_chip[equipmentid]
		equipment = inv.addEquipment(equipmentid)
		inv.save()
		
		if inv.equipment_chip.has_key(equipmentid):
			return {'equipment_chip':{equipmentid: inv.equipment_chip[equipmentid]}, 'add_equipment':equipment}
		else:
			return {'equipment_chip':{equipmentid: 0}, 'add_equipment':equipmentid}
			
Example #42
0
    def assembly(usr, cardid):
        """
		组装
		"""

        inv = usr.getInventory()

        if not inv.card_chip.has_key(cardid):
            return {'msg': 'card_chip_not_enough'}

        petConf = config.getConfig('pet')

        if not petConf.has_key(cardid):
            return {'msg': 'card_chip_not_exist'}

        petInfo = petConf[cardid]

        if inv.card_chip[cardid] < petInfo['chip']:
            return {'msg': 'card_chip_not_enough'}

        inv.card_chip[cardid] = inv.card_chip[cardid] - petInfo['chip']
        if inv.card_chip[cardid] == 0:
            del inv.card_chip[cardid]
        card = inv.addCard(cardid)
        inv.save()

        if inv.card_chip.has_key(cardid):
            return {
                'card_chip': {
                    cardid: inv.card_chip[cardid]
                },
                'add_card': card
            }
        else:
            return {'card_chip': {cardid: 0}, 'add_card': card}
Example #43
0
	def sell(usr, equipmentid):
		"""
		卖出装备
		"""
		inv = usr.getInventory()		
		
		sellequipment = []
		
		for equipid in equipmentid:
			equipment = inv.getEquipment(equipid)
					
			if not equipment:
				return {'msg':'equipment_not_exist'}
		
			equipmentConf = config.getConfig('equipment')
			equipmentInfo = equipmentConf[equipment['equipmentid']]
		
			sellGold = equipmentInfo['price']		
			usr.gold = usr.gold + sellGold		
			inv.delEquipment(equipid)
			sellequipment.append(equipid)
		inv.save()
		usr.save()
		
		return {'gold':usr.gold, 'delete_equipment_array':sellequipment}		
Example #44
0
	def acceptQuest(self, questid, isNotify=True):
		"""
		接受任务
		"""
		questConf = config.getConfig('quest')
		questInfo = questConf[questid]
		if not self.canAccept(questid, questInfo, questConf):
			return None
		
		q = None
		if self.finish.has_key(questid):
			q = self.finish[questid]
			del self.finish[questid]
		else:
			q = quest.makeQuest(questid)			
		
		usr = self.user
		if questInfo['finishType'] == 'dungeon_id':
			dun = usr.getDungeon()			
			dun.setLastDungeon(questInfo['finishValue'][0], questInfo['finishValue'][1])
			dun.notify_allow_dungeon(questInfo['finishValue'][0], questInfo['finishValue'][1])
			dun.save()
		self.current[questid] = q
		if isNotify:
			quest.notify_add_quest(usr, questid, q)
		if quest.isFinish(questid, q):
			quest.notify_finish_quest(usr, questid)
			
		self.save()
		return q
Example #45
0
    def garcha_skill10(usr):
        """
		求技能10次
		"""

        gameConf = config.getConfig('game')

        goldCost = gameConf['garcha_skill_10_price']['gold']
        gemCost = gameConf['garcha_skill_10_price']['gem']

        if usr.gold < goldCost:
            return {'msg': 'gold_not_enough'}
        if usr.gem < gemCost:
            return {'msg': 'gem_not_enough'}

        awd = {}
        awd = drop.open(usr, gameConf['garcha_skill_10_dropid1'], awd)

        for i in range(9):
            awd = drop.open(usr, gameConf['garcha_skill_10_dropid2'], awd)

        data = drop.makeData(awd, {})

        usr.gold = usr.gold - goldCost
        usr.gem = usr.gem - gemCost

        usr.save()

        data['gold'] = usr.gold
        data['gem'] = usr.gem
        return data
Example #46
0
	def call(usr):
		educateGradeConf = config.getConfig('educate_grade')
		
		edt = usr.educate['edt']		
		goldCost = educateGradeConf[edt]['price']['gold']
		gemCost = educateGradeConf[edt]['price']['gem']
		
		if goldCost > usr.gold:
			return {'msg': 'gold_not_enough'}
		if gemCost > usr.gem:
			return {'msg': 'gem_not_enough'}
				
		usr.gold = usr.gold - goldCost
		usr.gem = usr.gem - gemCost
				
		probability = educateGradeConf[edt]['probability']
		rate = educateGradeConf[edt]['rate']
		
		if drop(probability):
			edt = edt + 1
			if edt > (len(educateGradeConf) - 1):
				edt = len(educateGradeConf) - 1
		else:
			edt = 0
		usr.educate['edt'] = edt			
		
		return {'gold':usr.gold, 'gem':usr.gem, 'edu_edt':edt}				
Example #47
0
	def start(usr, markup):
		"""
		开始
		"""
		if usr.tower['current']:
			return {'msg':'tower_not_finished'}
				
		gameConf = config.getConfig('game')
		
		if gameConf['tower_times'] - len(usr.tower['record']) <= 0:
			return {'msg':'tower_max_times'}
		
		usr.tower['current'] = tower.make_data()
		markup = int(markup)
		
		tower.do_markup(usr, markup)		
		usr.save()
		
		data = {}
		data['tower_point'] = usr.tower['current']['point']
		data['tower_energy'] = usr.tower['current']['energy']
		data['tower_strength'] = usr.tower['current']['strength']
		data['tower_intelligence'] = usr.tower['current']['intelligence']
		data['tower_artifice'] = usr.tower['current']['artifice']
		data['tower_times'] = tower.times(usr, gameConf)
		data['tower_floor'] = 0

			
		return data
Example #48
0
    def continue_award(usr):
        """
		连续登陆
		"""
        openAwardConf = config.getConfig('open_award')
        if not signin.is_continue_award_available(openAwardConf):
            return {'msg': 'open_award_not_available'}

        if signin.is_continue_award_already_get(usr):
            return {'msg': 'open_award_already_get'}

        now = currentTime()
        if not usr.signin['continue_award_time']:
            if day_diff(now, usr.signin['continue_award_time'][-1]) != 1:
                usr.signin['continue_award_time'] = []

        usr.signin['continue_award_time'].append(now)

        cardid = openAwardConf['continue_award'][
            len(usr.signin['continue_award_time']) - 1]

        inv = usr.getInventory()
        c = inv.addCard(cardid)
        inv.save()
        usr.save()
        data = {}
        data['add_card'] = c
        return data
Example #49
0
	def rollBless(usr):
		if not usr.luckycat:
			return {'msg':'luckycat_not_available'}
		luckycat.updateBless(usr)
		luckycatBlessConf = config.getConfig('luckycat_bless')
		now = currentTime()		
		if is_same_day(now, usr.luckycat['bless_roll_last_time']):
			return {'msg':'roll_bless_already_today'}
		
		roll = randint()
		blessConf = {}
		for blessid in luckycatBlessConf:
			b = luckycatBlessConf[blessid] 
			if b['probability'] < roll:
				roll = roll - b['probability']
			else:
				blessConf = b		
		
		blessid = blessConf['blessid']
		if not usr.luckycat['bless'].has_key(blessid):
			usr.luckycat['bless'][blessid] = {}
			usr.luckycat['bless'][blessid]['blessid'] = blessid
			if luckycat.isCycleDay(usr):
				usr.luckycat['bless'][blessid]['spread'] = True				
		return {'luckycat_roll_bless':blessid, 'luckycat_roll_bless_spread':usr.luckycat['bless'][blessid].has_key('spread')}
Example #50
0
    def init(self):
        """
		初始化
		"""
        conf = config.getConfig('dungeon')
        self.last_dungeon['battleid'] = ''
        self.last_dungeon['fieldid'] = ''
Example #51
0
	def inviteAward(usr, inviteCount):
		"""
		邀请领奖
		"""
		
		if inviteCount > len(usr.invite['invite']):
			return {'msg':'invite_count_not_enough'}
							
		while len(usr.invite['invite_award']) < (inviteCount + 1):
			usr.invite['invite_award'].append('')
		
		if usr.invite['invite_award'][inviteCount]:
			return {'msg':'invite_award_already_have'}
				
		inviteConf = config.getConfig('invite')
		
		dropid = inviteConf['invite_award'][inviteCount - 1]
		if not dropid:
			return {'msg': 'invite_not_have_award'}
					
		usr.invite['invite_award'][inviteCount] = dropid
		awd = {}
		awd = drop.open(usr, dropid, awd)		
		data = drop.makeData(awd, {})				
		#data.update(invite.getClientData(usr))
		usr.save()
		
		data['invite_award'] = []
		for (i, di) in enumerate(usr.invite['invite_award']):
			if di:
				data['invite_award'].append(i + 1)			
		
		return data
Example #52
0
	def finishQuest(self, questid):
		"""
		完成任务
		"""
		if not self.current.has_key(questid):
			return {'msg':'quest_not_exist'}
		q = self.current[questid]
		usr = self.user				
		questConf = config.getConfig('quest')
		questInfo = questConf[questid]		
		
		if (not quest.isFinish(questid, q)) and (questInfo['finishType'] != 'talk_npc_id'):
			return {'msg':'quest_not_finish'}
		q['count'] = q['count'] + 1
		
		del self.current[questid]
		self.finish[questid] = q		

		newQuest = self.acceptNextQuest(questid, questInfo, questConf)	
		
		data = {}
		data['finish_quest'] = questid
		if newQuest:
			data['accept_quest'] = newQuest
		if questInfo['dropid']:
			data = drop.open(usr, questInfo['dropid'], data)		
		self.save()
		return data
Example #53
0
	def equip(usr, teamPosition, equipmentid):
		inv = usr.getInventory()
		
		cardid = inv.team[teamPosition]
		
		if not cardid:
			return {'msg': 'team_position_not_have_member'}
		
		equipment = inv.getEquipment(equipmentid)
		if not equipment:
			return {'msg':'equipment_not_exist'}
				
		
		
		equipmentConf = config.getConfig('equipment')
		equipmentInfo = equipmentConf[equipment['equipmentid']]
		
		
		card = inv.getCard(cardid)
		if not card:
			return {'msg':'card_not_exist'}
		
		if not card.has_key('slot'):
			card['slot'] = equipment.make_slot()
		
		oldEquipment = card['slot'][equipmentInfo['position']]
		
		if oldEquipment:
			inv.depositEquipment(oldEquipment)
		card['slot'][equipmentInfo['position']] = equipment
		inv.equipment.remove(equipment)
		inv.save()
		
		return{'solts':inv.getSlots(), 'equipment_delete':equipmentid}