def startAlchemy(db,conn,playerId,alchemyId): if not ALCHEMY_CONFIG.has_key(alchemyId): return {'status':0,'msg':'no alchemyId '+alchemyId} formulaList = ALCHEMY_CONFIG[alchemyId]['formula'] needLevel = ALCHEMY_CONFIG[alchemyId]['level'] #背包数据 prop = db_tool.getAllProp(playerId) #验证等级 player = db_tool.__getPlayerById(playerId) if player['level'] < needLevel: return {'status':0,'msg':'alchemy need level '+str(needLevel)} for formula in formulaList: neetDefinitionId = formula['definitionID'] neetDefinitionIdNum = formula['num'] #验证炼化材料 if not prop.has_key(str(neetDefinitionId)) or prop[str(neetDefinitionId)] < neetDefinitionIdNum: return {'status':0,'msg':'alchemy need more definitionId '+str(neetDefinitionId)} db_tool.__subtractPropItem(prop,neetDefinitionId,neetDefinitionIdNum) #正在或等待炼化的信息 alchemyInfoList = getAlchemyInfo(playerId) alchemyTime = getAlchemyTime(alchemyInfoList) alchemydict = {'id':alchemyId,'time':alchemyTime,'friends':''} alchemyInfoList.append(alchemydict) updateAlchemy(playerId,alchemyInfoList) db_tool.saveAllProp(playerId,prop) return {'status':1,'time':alchemyTime,'alchemyId':alchemyId,'bag':prop}
def Auction(playerId,param): player = db_tool.__getPlayerById(playerId) returnVal = {} time_now = int(time.time()) num = __countTransaction(playerId) if player['vip'] > time_now: if num >= 5: return {'status':0,'error_type':11,'msg':'拍卖行5格已满,'} else: if num >= 3: return {'status':0,'error_type':10,'msg':'拍卖行3格已满'} prop_id = param['definitionId'] price = param['price'] number = param['number'] propDict=db_tool.getAllProp(playerId) prop_count=propDict[str(prop_id)] if prop_count >= number: __addTransactionItem(playerId,prop_id,number,price) db_tool.__subtractPropItem(propDict,prop_id,number) db_tool.saveAllProp(playerId,propDict) returnVal['status'] = 1 returnVal['bag'] = propDict returnVal['transaction'] = __getTransactionList(playerId) returnVal['item'] = param return returnVal else : return {'status':0,'msg':'data error'}
def resolve(playerId,definitionId,definitionNum): returnVal = {} returnVal['items'] = [] #drawing = db_tool.__selectProp(definitionId,playerId) propDict = db_tool.getAllProp(playerId) drawing = propDict[str(definitionId)] if not drawing or drawing < definitionNum: return {'status':0,'msg':'can not find prop id: ['+str(definitionId)+'].'} resolve_prop = DRAWING_CONFIG[definitionId]['resolve'] for each in resolve_prop: prop_id,number,per = each['type'],each['value'],each['per'] randNum = random.randint(1,100) #有几率获得双倍材料 if 1 <= randNum <= per: number *= 2 totalNumber = number*definitionNum db_tool.__addPropItem(propDict,str(prop_id),totalNumber) returnVal['items'].append({'number':totalNumber,'definitionId':prop_id}) db_tool.__subtractPropItem(propDict,str(definitionId),definitionNum) db_tool.saveAllProp(playerId,propDict)#update prop db returnVal['status'] = 1 returnVal['bag'] = propDict returnVal['definitionId'] = definitionId returnVal['number'] = definitionNum return returnVal
def speedupAlchemy(playerId,param): useNum = param['use_num'] needNum = param['need_num'] player = db_tool.__getPlayerById(playerId) #验证KB costKb = 0 if needNum>0: costKb = needNum*10 player['kb'] -= costKb if player['kb'] < 0: return {'status':0,'msg':'not enough kb'} propDict = db_tool.getAllProp(playerId) prop_id='2020' #验证加速道具 if useNum > 0: if not propDict.has_key(prop_id) or propDict[prop_id]<useNum : return {'status':0,'msg':'no or not enough '+prop_id} #获取当前正在炼化的信息 active_alchemy = getActiveAlchemyInfo(playerId) if not active_alchemy: return {'status':0,'msg':'no active_alchemy '+str(playerId)} startTime = active_alchemy['time'] alchemy_circle = ALCHEMY_CONFIG[active_alchemy['id']]['time']*60 time_now = int(time.time()) remainTime = alchemy_circle - (time_now - startTime)%alchemy_circle #总使用道具数 prop_num = useNum+needNum #加速时间一小时 speedTime = PROP_CONFIG[int(prop_id)]['speed'] #炼化时间重新赋值 if remainTime > speedTime*prop_num: subtractTime = speedTime*prop_num else: subtractTime = remainTime #正在或等待炼化的信息 alchemyInfoList = getAlchemyInfo(playerId) for alchemy in alchemyInfoList: alchemy['time'] -= subtractTime updateAlchemy(playerId,alchemyInfoList) if useNum>0: db_tool.__subtractPropItem(propDict,prop_id,useNum) db_tool.saveAllProp(playerId,propDict)#update prop db if costKb > 0: db_tool.__updatePlayer(playerId,{'kb':player['kb']}) return {'status':1,'bag':propDict,'alchemy':alchemyInfoList,'kb':player['kb']}
def startLittleGame(playerId): propDict = db_tool.getAllProp(playerId) if not propDict.has_key(LITTLEGAME_NEED_PROPID) or propDict[LITTLEGAME_NEED_PROPID] < 1: return {'status':0,'msg':'need more definitionId '+str(LITTLEGAME_NEED_PROPID)} db_tool.__subtractPropItem(propDict,LITTLEGAME_NEED_PROPID,1) db_tool.saveAllProp(playerId,propDict) return {'status':1,'bag':propDict}
def speedupSearch(playerId, param): useNum = param["use_num"] needNum = param["need_num"] player = db_tool.__getPlayerById(playerId) # 验证KB costKb = 0 if needNum > 0: costKb = needNum * 10 player["kb"] -= costKb if player["kb"] < 0: return {"status": 0, "msg": "not enough kb"} propDict = db_tool.getAllProp(playerId) prop_id = "2020" # 验证加速道具 if useNum > 0: if not propDict.has_key(prop_id) or propDict[prop_id] < useNum: return {"status": 0, "msg": "no or not enough " + prop_id} searchInfo = getSearchTeamById(playerId) searchTypeId = searchInfo["type"] areaId = searchInfo["area"] searchStartTime = searchInfo["last_start_time"] needTime = SEARCH_TYPE[searchTypeId]["time"] * 3600 # 获取搜索队上次搜索时间 last_start_time = searchStartTime # 剩余时间 time_now = int(time.time()) remainTime = needTime - (time_now - searchStartTime) # 总使用道具数 prop_num = useNum + needNum # 加速时间一小时 speedTime = PROP_CONFIG[int(prop_id)]["speed"] # 搜索时间重新赋值 if remainTime > speedTime * prop_num: last_start_time -= speedTime * prop_num else: last_start_time -= remainTime # update and save db_tool.__updateSearchTeam(playerId, last_start_time) if useNum > 0: db_tool.__subtractPropItem(propDict, prop_id, useNum) db_tool.saveAllProp(playerId, propDict) # update prop db if costKb > 0: db_tool.__updatePlayer(playerId, {"kb": player["kb"]}) return {"status": 1, "last_start_time": last_start_time, "bag": propDict, "kb": player["kb"]}
def checkBag(playerId,needDefinitonList,propDict): #检查背包 for needDefiniton in needDefinitonList: definitionID = str(needDefiniton['definitionID']) num = needDefiniton['num'] if propDict.has_key(definitionID) and propDict[definitionID]>=num: pass else: return False #扣除背包相应物品 for needDefiniton in needDefinitonList: definitionID = str(needDefiniton['definitionID']) num = needDefiniton['num'] db_tool.__subtractPropItem(propDict,definitionID,num) return True
def speedupProduce(playerId,param): machineId = param['machineId'] useNum = param['use_num'] needNum = param['need_num'] player = db_tool.__getPlayerById(playerId) #验证KB costKb = 0 if needNum>0: costKb = needNum*10 player['kb'] -= costKb if player['kb'] < 0: return {'status':0,'msg':'not enough kb'} propDict = db_tool.getAllProp(playerId) prop_id='2020' #验证加速道具 if useNum > 0: if not propDict.has_key(prop_id) or propDict[prop_id]<useNum : return {'status':0,'msg':'no or not enough '+prop_id} produceList = getProduceList(playerId) produce_start_time = produceList[str(machineId)]['startTime'] #总使用道具数 prop_num = useNum+needNum #加速时间一小时 speedTime = PROP_CONFIG[int(prop_id)]['speed'] #生产时间重新赋值 produce_start_time -= speedTime*prop_num produceList[str(machineId)]['startTime'] = produce_start_time updateProduce(playerId,produceList) if useNum>0: db_tool.__subtractPropItem(propDict,prop_id,useNum) db_tool.saveAllProp(playerId,propDict)#update prop db if costKb > 0: db_tool.__updatePlayer(playerId,{'kb':player['kb']}) return {'status':1,'bag':propDict,'pid':machineId,'produce':produceList[str(machineId)],'kb':player['kb']}
def checkExchange(playerId, exchangeId, propDict): needDrawingList = EXCHANGE_CONFIG[exchangeId]["drawingDefinitonID"] needMaterailList = EXCHANGE_CONFIG[exchangeId]["materailDefinitonID"] end_time_str = EXCHANGE_CONFIG[exchangeId]["end_time"] end_time = time_tool.str2sec(end_time_str) time_now = int(time.time()) # 判断兑换活动时间 if time_now > end_time: return False # 检查背包 for needDrawing in needDrawingList: definitionID = str(needDrawing["definitionID"]) num = needDrawing["num"] if propDict.has_key(definitionID) and propDict[definitionID] >= num: pass else: return False for needMaterail in needMaterailList: definitionID = str(needMaterail["definitionID"]) num = needMaterail["num"] if propDict.has_key(definitionID) and propDict[definitionID] >= num: pass else: return False # 扣除背包相应物品 for needDrawing in needDrawingList: definitionID = str(needDrawing["definitionID"]) num = needDrawing["num"] db_tool.__subtractPropItem(propDict, definitionID, num) for needMaterail in needMaterailList: definitionID = str(needMaterail["definitionID"]) num = needMaterail["num"] db_tool.__subtractPropItem(propDict, definitionID, num) # db_tool.saveAllProp(playerId,propDict) return True
def joinTeamUp(launchInfo): playerId = launchInfo['id'] snsName = launchInfo['name'] snsPic = launchInfo['imageUrl'] leader = launchInfo['leader'] propDict = db_tool.getAllProp(playerId) if not propDict.has_key(EXPLORE_NEED_PROPID) or propDict[EXPLORE_NEED_PROPID] < 1: return {'status':0,'msg':'need more definitionId '+str(EXPLORE_NEED_PROPID)} exploreInfo = {} exploreInfo['player_id'] = playerId exploreInfo['leader'] = leader exploreInfo['score'] = 0 exploreInfo['reward'] = '' exploreInfo['sns_name'] = snsName exploreInfo['sns_pic'] = snsPic personInfo = getExploreInfo(playerId) if personInfo: return {'status':0,'msg':'can not joinTeamUp'} else: #判断成员个数 memberCounts = getMemberCounts(leader) if memberCounts >= 5: return {'status':0,'msg':'can not joinTeamUp ... has full member'} addExploreInfo(exploreInfo) db_tool.__subtractPropItem(propDict,EXPLORE_NEED_PROPID,1) db_tool.saveAllProp(playerId,propDict) #add eventlog leaderInfo = getExploreInfo(leader) eventInfo = {'snsName':snsName} eventInfo['leaderName'] = leaderInfo['sns_name'] addExploreEventLog(leader,2,eventInfo) returnVal = getTeamUpInfo(playerId) returnVal['bag'] = propDict return returnVal
def launchTeamUp(launchInfo): snsName = launchInfo['name'] snsPic = launchInfo['imageUrl'] floor = launchInfo['floor'] playerId = launchInfo['id'] propDict = db_tool.getAllProp(playerId) if not propDict.has_key(EXPLORE_NEED_PROPID) or propDict[EXPLORE_NEED_PROPID] < 1: return {'status':0,'msg':'need more definitionId '+str(EXPLORE_NEED_PROPID)} exploreInfo = {} exploreInfo['player_id'] = playerId exploreInfo['leader'] = playerId exploreInfo['score'] = 0 exploreInfo['reward'] = '' exploreInfo['sns_name'] = snsName exploreInfo['sns_pic'] = snsPic personInfo = getExploreInfo(playerId) if personInfo: return {'status':0,'msg':'can not launchTeamUp'} else: addExploreInfo(exploreInfo) teamInfo = {} teamInfo['leader_id'] = playerId teamInfo['total_score'] = 0 teamInfo['floor'] = floor teamInfo['step'] = 1 addExploreTeamInfo(teamInfo) db_tool.__subtractPropItem(propDict,EXPLORE_NEED_PROPID,1) db_tool.saveAllProp(playerId,propDict) #add eventlog eventInfo = {'snsName':snsName} addExploreEventLog(playerId,1,eventInfo) returnVal = getTeamUpInfo(playerId) returnVal['bag'] = propDict return returnVal
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 refining(playerId,definitionId,definitionNum): definitionId = str(definitionId) itemStar = definitionId[-1] #根据星级获得不同的炼化石 if itemStar == '0': refining_stone = 10060 elif itemStar == '1': refining_stone = 10061 elif itemStar == '2': refining_stone = 10062 propDict = db_tool.getAllProp(playerId) if not propDict.has_key(definitionId) or propDict[definitionId] < definitionNum: return {'status':0,'msg':'refining failed... no (or not enough) definitionId '+definitionId} db_tool.__subtractPropItem(propDict,definitionId,definitionNum) db_tool.__addPropItem(propDict,refining_stone,definitionNum) db_tool.saveAllProp(playerId,propDict) return {'status':1,'bag':propDict,'definitionId':refining_stone,'number':definitionNum}
def purchaseResponse(db,conn,buyer,seller,sellerName,purchaseId): sellerBag = db_tool.getAllProp(seller); buyerPlayer = db_tool.__getPlayerById(buyer) sellerPlayer = db_tool.__getPlayerById(seller) purchaseItem = lockPurchaseItem(db,conn,purchaseId) if not purchaseItem: return {'status':0,'error_type':1,'purchaseId':purchaseId,'msg':'purchaseResponse: no purchase'} price = purchaseItem['price'] number = purchaseItem['number'] prop_id = str(purchaseItem['prop_id']) if buyerPlayer['gb'] < price: return {'status':0,'error_type':2,'purchaseId':purchaseId,'msg':'purchaseResponse: not enouth gb'} if not sellerBag.has_key(prop_id) or sellerBag[prop_id] < number: return {'status':0,'error_type':3,'purchaseId':purchaseId,'msg':'purchaseResponse: not enouth prop'} #计算税 tax_rate=1/0.05 tax=int((price+tax_rate-1)/tax_rate) #更新卖方背包及GB db_tool.__subtractPropItem(sellerBag,prop_id,number) db_tool.saveAllProp(seller,sellerBag) sellerPlayer['gb'] += price-tax db_tool.__updatePlayer(seller,{'gb':sellerPlayer['gb']}) #更新买方背包及GB buyerBag = db_tool.getAllProp(buyer); db_tool.__addPropItem(buyerBag,prop_id,number) db_tool.saveAllProp(buyer,buyerBag) buyerPlayer['gb'] -= price db_tool.__updatePlayer(buyer,{'gb':buyerPlayer['gb']}) #删除求购单数据 delLockPurchaseItem(db,conn,purchaseId) #添加交易日志 time_now = int(time.time()) info = {} info['player_id'] = seller info['price'] = price info['number'] = number info['prop_id'] = prop_id info['buyer'] = sellerName eventLog = {} eventLog['user_id'] = buyer eventLog['type'] = 1 eventLog['info'] = dict2str(info) eventLog['create_time'] = time_now savePurchaseEvent(eventLog) return {'status':1,'purchaseId':purchaseId,'bag':sellerBag,'gb':sellerPlayer['gb']}