def getRewardAndExp(db,conn,snsId,config): db.execute("UPDATE user_box set is_open = 1 where owner_id = %s",(snsId,)) #第一次添加经验 exp = 0 player = db_tool.__getPlayer(snsId) #get collection collectionStr = db_tool.__getPlayerCollection(player['id'])['status'] collectionList = collection.__collectionToList(collectionStr) #随机获取一个未收集到的图鉴奖励 rewards = config.get('reward') uncollectItem = getUnCollectItem(collectionList,rewards) #如果都收集过了 if(not uncollectItem): uncollectItem = rewards reward = random.choice(uncollectItem) prop = db_tool.getAllProp(player['id']) for propId in reward.keys(): #add collection if str(propId) in collectionList: exp += 0 else: exp += DRAWING_CONFIG[int('1'+propId)]['exp'] player['exp'] += exp db_tool.__updatePlayer(player['id'],{'exp':player['exp']}) collection.__updateCollection(player,propId) #add prop db_tool.__addPropItem(prop,propId,reward[propId]) db_tool.saveAllProp(player['id'],prop) conn.commit() return reward,exp
def __updateCollection(player,definitionId): collection = db_tool.__getPlayerCollection(player['id']) status = collection['status'] definitionId = str(definitionId) statusList = [] if status: statusList = status.split("|") if definitionId not in statusList: statusList.append(str(definitionId)) status = '|'.join(statusList) db_tool.updateCollection(status,player['id'])
def mix(playerId,definitionId): player = db_tool.__getPlayerById(playerId) propDict = db_tool.getAllProp(playerId) if not propDict.has_key(str(definitionId)): return {'status':0,'msg':'no definitionId'+str(definitionId)} drawing = propDict[str(definitionId)] if not drawing or drawing <= 0: return {'status':0,'type_error':13,'msg':' '} mix_prop = DRAWING_CONFIG[definitionId]['mix'] item_id = item_module.getMixIdByDrawId(definitionId) #合成新物种加经验 collectionStr = db_tool.__getPlayerCollection(player['id'])['status'] collection = __collectionToList(collectionStr) if str(item_id) in collection: exp = 0 else: exp = DRAWING_CONFIG[definitionId]['exp'] player['exp'] += exp #验证合成需要的材料 if not __checkNum(player,mix_prop,propDict): return {'status':0,'type_error':23,'msg':'材料数量不够'} for each in mix_prop: if each['type'] == 2: player['gb']-=each['value'] else: db_tool.__subtractPropItem(propDict,each['type'],each['value']) db_tool.__updatePlayer(player['id'],{'gb':player['gb'],'exp':player['exp']}) db_tool.__addPropItem(propDict,str(item_id),1) db_tool.__subtractPropItem(propDict,str(definitionId),1) db_tool.saveAllProp(player['id'],propDict)#update db __updateCollection(player,item_id) #num = db_tool.getGlobalDefinitionNum(item_id) #num=1 return {'status':1,'bag':propDict,"item_id":item_id,'add_exp':exp,'player_exp':player['exp'],'player_gb':player['gb']}
def finishCollection(playerId,definitionId): player = db_tool.__getPlayerById(playerId) # collectionListStr = db_tool.__getPlayerCollectionList(player['id'])['status'] if not collectionListStr: collectionListList = [] else: collectionListList = __collectionToList(collectionListStr) if str(definitionId) in collectionListList: return {'status':0,'msg':''} collectionStr = db_tool.__getPlayerCollection(player['id'])['status'] # if not collectionStr: collectionList = [] else: collectionList = __collectionToList(collectionStr) content = COLLECTION_CONFIG[definitionId]['content'] for each in content: if str(each) not in collectionList: return {'status':0} award = COLLECTION_CONFIG[definitionId]['award'] if award['gb']: player['gb'] += award['gb'] if award['exp']: player['exp'] += award['exp'] db_tool.__updatePlayer(player['id'],{'gb':player['gb'],'exp':player['exp']}) collectionListList.append(str(definitionId)) strCollection = __listToCollection(collectionListList) db_tool.updateCollectionList(strCollection,player['id']) prop = db_tool.getAllProp(playerId) if award['definitionId']: db_tool.__addPropItem(prop,award['definitionId'],1) db_tool.saveAllProp(playerId,prop) return {'status':1,'bag':prop,'player':player}
def getCollection(playerId): collection=db_tool.__getPlayerCollection(playerId) if not collection['status']: return [] returnVal = collection['status'].split('|') return returnVal