def acceptSystemReward(playerId,sysRewardId): if not str(sysRewardId): return {'status':0,'msg':'no sysRewardId'} player = db_tool.__getPlayerById(playerId) system_reward = player['system_reward'] system_reward_list = str2list(system_reward) if str(sysRewardId) in system_reward_list: #更新领取状态 system_reward_list.remove(str(sysRewardId)) db_tool.__updatePlayer(playerId,{'system_reward':list2str(system_reward_list)}) #给与奖励 for systemReward in SYSTEM_REWARD_CONFIG[sysRewardId]: system_reward_type = systemReward['type'] system_reward_num = systemReward['num'] db_tool.addPropAndMoney(playerId,system_reward_type,system_reward_num) propDict = db_tool.getAllProp(playerId) player = db_tool.__getPlayerById(playerId) return {'status':1,'sysRewardId':sysRewardId,'player':player,'bag':propDict} else: return {'status':0,'msg':'no sysRewardId '+str(sysRewardId)}
def buyAuction(db,conn,playerId,transaction_id,buyer_name): player = db_tool.__getPlayerById(playerId) playerId = player['id'] returnVal = {} transaction= __lockTransactionById(db,conn,transaction_id) if transaction: number = transaction['number'] price = transaction['price'] seller_id = transaction['user_id'] seller = db_tool.__getPlayerById(seller_id) player['gb']-=price if(player['gb']>=0): tax_rate=1/0.05 tax=int((price+tax_rate-1)/tax_rate) seller_income=price-tax; #修改卖家gb db_tool.__updatePlayer(seller_id,{'gb':seller['gb']+seller_income}) #修改买家gb及背包 db_tool.__updatePlayer(playerId,{'gb':player['gb']}) props = db_tool.getAllProp(playerId) db_tool.__addPropItem(props,transaction['prop_id'],number) db_tool.saveAllProp(playerId,props) #删除记录 __delLockTransactionItem(db,conn,transaction_id) log_info = {} log_info['player_id'] = playerId log_info['price'] = price log_info['buyer'] = buyer_name log_info['number'] = number log_info['prop_id'] = transaction['prop_id'] auctionEvent(log_info,seller_id) returnVal['status'] = 1 returnVal['bag'] = db_tool.getAllProp(playerId) returnVal['player'] = player returnVal['cost']=price returnVal['auctionId'] = transaction_id returnVal['auctionStatus'] = player_module.getAuctionStatus(seller_id) return returnVal else: return {'status':0,'error_type':100,'msg':'Not enough money'} else: return {'status':0,'error_type':1,'auctionId':transaction_id,'msg':'Can not find the Transaction by id '+str(transaction_id)}
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 finishTreasure(playerId,info): player = db_tool.__getPlayerById(playerId) if not player: return {'status':0,'msg':'can not find player by player id :'+str(playerId)} energyCost = 10 player=__updateEnergy(player) player['gb']+=info['gb'] player['energy']+=info['energy'] player['exp']+=info['exp'] if(info['continue']): if(player['free_times'] > 0): player['free_times'] -= 1 elif(player['energy']<energyCost): return {'status':0,'msg':'not enough energy.'} else: player['energy']-= energyCost #重置confirmCode treasureInfo = getTreasureInfo(playerId) info['confirmCode'] = treasureInfo['start_time'] else: #验证是否可以挖宝 if not checkTreasure(playerId,info['confirmCode']): return {'status':0,'msg':'confirmCode error, player id :'+str(playerId)} bool= db_tool.__updatePlayer(playerId,{'gb':player['gb'],'exp':player['exp'],'energy':player['energy'],'last_energy_time':player['last_energy_time'],'free_times':player['free_times']}) if(bool): return {'status':1,'player':player,'info':info} else: return {'status':0,'player':player,'info':info}
def stealSearchTeam(db, conn, param): playerId = param["player_id"] playerName = param["player_name"] playerPic = param["player_pic"] friendId = param["friend_id"] friendPlayer = db_tool.__getPlayerById(friendId) if not friendPlayer or player_module.isVIP(friendPlayer): return {"status": 0, "error_type": 2, "msg": "friend is null or is vip"} searchInfo = lockSearchTeamById(db, conn, friendId) if not searchInfo or searchInfo["blue_box"] != 1: searchInfo = getSearchTeamDetail(friendId) return { "status": 0, "error_type": 1, "searcher": searchInfo, "msg": "searchInfo is done or stealed by other friend", } number = searchInfo["number"] searchTypeId = searchInfo["type"] areaId = searchInfo["area"] searchStartTime = searchInfo["last_start_time"] needTime = SEARCH_TYPE[searchTypeId]["time"] * 3600 time_now = int(time.time()) if (searchStartTime + needTime) > time_now: return {"status": 0, "msg": "need more time for searchInfo"} # 记录好友信息 friendsInfo = {} friendsInfo["id"] = playerId friendsInfo["name"] = playerName friendsInfo["pic"] = playerPic updateInfo = {} updateInfo["friends"] = db_tool.__dictToString(friendsInfo) updateInfo["number"] = number - 1 updateInfo["blue_box"] = 2 updateSearchTeamInfoForLock(db, conn, friendId, updateInfo) # 更新背包信息 propDict = db_tool.getAllProp(playerId) prop_id, num = odds.getItemByArea(areaId) db_tool.__addPropItem(propDict, prop_id, num) db_tool.saveAllProp(playerId, propDict) searchInfo = getSearchTeamDetail(friendId) # 添加交互日志 log_info = {} log_info["player_id"] = playerId log_info["player_name"] = playerName log_info["prop_id"] = prop_id interaction_event.writeInteractionEventLog(log_info, friendId, 1) return {"status": 1, "definitionId": prop_id, "bag": propDict, "searcher": searchInfo}
def addLotteryReward(playerId): player = db_tool.__getPlayerById(playerId) lottery_num = player['lottery_num'] if lottery_num == 0: return {'status':0,'msg':'lottery_num == 0'} else: lottery_num -= 1 db_tool.__updatePlayer(player['id'],{'lottery_num':lottery_num}) rewardList = DAILY_REWARD_CONF['common'] todayTime = int(time.time()) if player['vip']>todayTime: rewardList = rewardList + DAILY_REWARD_CONF['vip'] rewardInfo = random.choice(rewardList) rewardType = rewardInfo['definitionID'] rewardNum = rewardInfo['num'] prop = db_tool.getAllProp(playerId) db_tool.__addPropItem(prop,rewardType,rewardNum) db_tool.saveAllProp(playerId,prop) return {'status':1,'bag':prop,'definitionID':rewardType,'num':rewardNum}
def getTreasure(db,conn,playerId,info): import random area=info['map_id'] player = db_tool.__getPlayerById(playerId) if player['level'] < SEARCH_AREA[area]: return {'status':0,'msg':'等级不足,不能到该区域挖宝'} #验证并设置获得宝藏状态status=1 db.execute("SELECT * FROM treasure WHERE player_id =%s ",(playerId,)) treasureInfo = db.fetchone() if (treasureInfo['status'] == 0): #设置status=1 db.execute("UPDATE treasure set status=1 where player_id=%s",(playerId,)) definitionId,num=odds.getItemByAreaForTreasure(area) propDict = db_tool.getAllProp(playerId) db_tool.__addPropItem(propDict,definitionId,num) db_tool.saveAllProp(playerId,propDict) conn.commit() else: return {'status':0,'msg':'已挖到宝藏'} return {'status':1,'definitionId':definitionId,'num':num,'bag':propDict}
def decorateGroupInShop(playerId,param): habitatId = param['map_index'] groupId = param['groupId'] groupItems = param['group'] item = {'definitionId':groupId} #买装饰物需要花费的钱 cost_money=__getCostMoney(item) player = db_tool.__getPlayerById(playerId) #比较 if (player['kb']<cost_money['kb']): return {'status':0,'msg':'not enough KB'} elif (player['gb']<cost_money['gb']): return {'status':0,'msg':'not enough GB'} #扣除 player['gb'] -=cost_money['gb'] player['kb'] -=cost_money['kb'] player['exp'] += cost_money['exp'] #添加 addItems = db_tool.addMapItemList(playerId,habitatId,groupItems) db_tool.__updatePlayer(player['id'],{'gb':player['gb'],'kb':player['kb'],'exp':player['exp']}) #add cost log if cost_money['kb']>0: player_module.addCostLog(player['id'],cost_money['kb'],'decorateGroupInShop') return {'status':1,'group':addItems,'player':player}
def startTreasure(playerId,info): player = db_tool.__getPlayerById(playerId) if not player: return {'status':0,'msg':'can not find player by player id :'+str(playerId)} player=__updateEnergy(player) #挖宝消耗的能量 energyCost = 10 #操作状态 bool = False #免费挖宝次数['free_times'] if(player['free_times'] > 0): player['free_times'] -= 1 bool = db_tool.__updatePlayer(player['id'],{'free_times':player['free_times']}) elif player['energy'] >= energyCost : player['energy'] -= energyCost bool = db_tool.__updatePlayer(player['id'],{'energy':player['energy'],'last_energy_time':player['last_energy_time']}) else: return {'status':0,'msg':'not enough energy.','energy':player['energy'],'last_energy_time':player['last_energy_time']} treasureInfo = getTreasureInfo(playerId) if(bool): return {'status':1,'player':player,'confirmCode':treasureInfo['start_time']} else: return {'status':0,'msg':'update player info error.'}
def finishLevelTask(db,conn,playerId,taskId): taskinfo = getLevelTaskById(db,conn,playerId) taskdict = __stringToDict(taskinfo['task_info']) taskId = int(taskId) if(taskdict.has_key(taskId)): taskdict.pop(taskId) propDict = db_tool.getAllProp(playerId) #任务奖励 taskReward = TASK_AWARD_CONFIG[taskId] if taskReward.has_key('gb'): db_tool.addPropAndMoney(playerId,'2',taskReward['gb']) if taskReward.has_key('exp'): db_tool.addPropAndMoney(playerId,'3',taskReward['exp']) if taskReward.has_key('item'): for item in taskReward['item']: db_tool.__addPropItem(propDict,item['definitionID'],item['num']) db_tool.saveAllProp(playerId,propDict) #更新任务状态 taskstr = __dictToString(taskdict) updateLevelTaskById(db,conn,playerId,taskstr) player = db_tool.__getPlayerById(playerId) #触发的新任务 triggerTasks = addTriggerTask(playerId,taskId) return{'status':1,'player':player,'bag':propDict,'task_id':taskId,'new_task':triggerTasks} else: return {'status':0,'msg':'没有相应的等级任务'}
def becomeVIP(playerId,prop_id): player = db_tool.__getPlayerById(playerId) bool=1 time_now = int(time.time()) if(PROP_CONFIG[prop_id]['KB']>0): player['kb'] -= PROP_CONFIG[prop_id]['KB'] if player['kb'] < 0: bool=0 else: #add cost log player_module.addCostLog(playerId,PROP_CONFIG[prop_id]['KB'],'becomeVIP') elif (PROP_CONFIG[prop_id]['GB']>0): player['gb'] -= PROP_CONFIG[prop_id]['GB'] if player['gb'] < 0: bool=0 if(bool): if player['vip'] > time_now: player['vip'] += PROP_CONFIG[prop_id]['period'] else: player['vip'] = time_now + PROP_CONFIG[prop_id]['period'] db_tool.__updatePlayer(player['id'],{'vip':player['vip'],'kb':player['kb'],'gb':player['gb']}) return {'status':1,'vip':player['vip'],'kb':player['kb']} else: return {'status':0,'msg':'Not enough money.'}
def updateGuide(id,guide_id): bool= db_tool.__updatePlayer(id,{"guide":guide_id}); if(bool): #做完新手导读 if(guide_id == GUIDE_STEP['totalsteps']): reward = [] for rewardType in GUIDE_CONFIG.keys(): db_tool.addPropAndMoney(id,rewardType,GUIDE_CONFIG[rewardType]) #format retval = {} retval['definationID'] = rewardType retval['num'] = GUIDE_CONFIG[rewardType] reward.append(retval) #增加3点经验使玩家升级 player = db_tool.__getPlayerById(id) player['exp'] = player['exp']+3 db_tool.__updatePlayer(id,{'exp':player['exp']}); return {'status':1,'player':player,'guide':guide_id,'reward':reward,'bag':db_tool.getAllProp(id)} else: return {'status':1,'guide':guide_id} else: return {'status':0,'guide':guide_id}
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 sellProps(playerId,param): player = db_tool.__getPlayerById(playerId) prop_id = str(param['definitionId']) prop_num= param['number'] propDict = db_tool.getAllProp(playerId) if propDict.has_key(prop_id) and propDict[prop_id] >= prop_num: propDict[prop_id]-=prop_num itemType = prop_id[0] itemStar = prop_id[-1] #是否是残片 if (itemType != '1'): return {'status':0,'msg':'err definitionIds'} #卖出的金额 gold = SELL_UNMIX_CONFIG[int(itemStar)+1]*prop_num player['gb'] += gold db_tool.__updatePlayer(player['id'],{'gb':player['gb']}) db_tool.saveAllProp(player['id'],propDict) return {'status':1,'player':player,'sell_info':param} else: return {'status':0,'msg':'not enough definitionIds'}
def sendSearchTeam(playerId, param): areaId = param["map_id"] searchTypeId = param["index"] player = db_tool.__getPlayerById(playerId) if player["level"] < SEARCH_AREA[areaId]: return {"status": 0, "msg": "you can not search this area in level [" + str(areaId) + "]"} time_now = int(time.time()) searchInfo = getSearchTeamById(playerId) if not searchInfo: searchInfo = {} searchInfo["user_id"] = playerId searchInfo["last_start_time"] = time_now searchInfo["area"] = areaId searchInfo["type"] = searchTypeId searchInfo["number"] = SEARCH_TYPE[searchTypeId]["rewards"] searchInfo["blue_box"] = 0 saveSearchTeamInfo(searchInfo) else: """ updateInfo = {} updateInfo['last_start_time'] = time_now updateInfo['area'] = areaId updateInfo['type'] = searchTypeId updateInfo['number'] = 0 updateInfo['blue_box'] = 0 updateSearchTeamInfo(playerId,updateInfo) """ return {"status": 0, "msg": "can not send search_team for twice"} return {"status": 1, "map_id": areaId, "index": searchTypeId, "start_time": time_now}
def decorativeScene(serverInfo,param): playerId = serverInfo['playerId'] habitatId = param['map_index'] player = db_tool.__getPlayerById(playerId) maps=db_tool.getMapsbyPlayerId(playerId,habitatId) propDict= db_tool.getAllProp(playerId) if not __checkItems(param['sell'],maps): return {'status':0,'msg':'sell item is not in map'} if not __checkItems(param['move'],maps): return {'status':0,'msg':'move item is not in map'} if not __checkItems(param['back'],maps): return {'status':0,'msg':'back item is not in map'} moveItems,sellItems,backItems,propDict=updateMapItems(playerId,habitatId,param,propDict) #卖出获得的钱 income_money = __getSellMoney(param['sell']) player['gb']=income_money+player['gb'] db_tool.__updatePlayer(playerId,{'gb':player['gb']}) returnVal = {'status':1} returnVal['move']=moveItems returnVal['back']=backItems returnVal['sell']=sellItems returnVal['playerBag'] = propDict returnVal['player']=player return returnVal
def finishAlchemy(db,conn,playerId,alchemyId): #正在或等待炼化的信息 alchemyInfoList = getAlchemyInfo(playerId) for alchemy in alchemyInfoList: if(alchemy['id'] == alchemyId): finishAlchemy = alchemy break; if not finishAlchemy: return {'status':0,'msg':'err alchemyId for finishAlchemy'} needTime = ALCHEMY_CONFIG[alchemyId]['time'] alchemyTime = finishAlchemy['time'] helpFriends = finishAlchemy['friends'] successRate = getRateOfFriends(helpFriends)+ALCHEMY_CONFIG[alchemyId]['percent'] totalCostTime = alchemyTime+needTime time_now = int(time.time()) if time_now < totalCostTime: return {'status':0,'msg':'not enough time to finishAlchemy'} #炼化成功率 randNum = random.randint(1,100) if 1 <= randNum <= successRate: success = True else: success = False #玩家+背包信息 player = db_tool.__getPlayerById(playerId) prop = db_tool.getAllProp(playerId) #炼化失败 if not success: alchemyInfoList.remove(finishAlchemy) formulaList = ALCHEMY_CONFIG[alchemyId]['formula'] for formula in formulaList: neetDefinitionId = formula['definitionID'] neetDefinitionIdNum = formula['num'] db_tool.__addPropItem(prop,neetDefinitionId,neetDefinitionIdNum) updateAlchemy(playerId,alchemyInfoList) db_tool.saveAllProp(playerId,prop) #return {'status':0,'msg':'Alchemy failed ...'} else: rewardDefinitionID = ALCHEMY_CONFIG[finishAlchemy['id']]['award']['definitionID'] rewardExp = ALCHEMY_CONFIG[finishAlchemy['id']]['award']['exp'] player['exp']+=rewardExp db_tool.__updatePlayer(playerId,{'exp':player['exp']}) db_tool.__addPropItem(prop,rewardDefinitionID,1) db_tool.saveAllProp(playerId,prop) #更新炼化信息 alchemyInfoList.remove(finishAlchemy) updateAlchemy(playerId,alchemyInfoList) return {'status':1,'flag':success,'alchemyId':alchemyId,'player':player,'bag':prop}
def getDigItemReward(playerId): #奖励 rewardGb = 0 rewardEnergy = 0 rewardDefinitionId = 0 #消耗能量 costEnergy = 1 player = db_tool.__getPlayerById(playerId) #更新能量 player = player_module.__updateEnergy(player) if player['energy'] < costEnergy: return {'status':0,'msg':'not enough energy.'} #扣除能量 player['energy'] -= costEnergy #获取背包信息 propDict = db_tool.getAllProp(playerId) oddsInfo = EXPLORE_DIG_REWARD_CONFIG[1] random_table_key = 'explore_dig_random_table_1' rewardItems = random_tool.getRandomItemList(random_table_key,oddsInfo) for odds in rewardItems: rewardType = odds['type'] rewardNum = odds['num'] #金币 if rewardType == 2: rewardGb = rewardNum player['gb'] += rewardNum #能量 elif rewardType == 4: rewardEnergy = rewardNum player['energy'] += rewardNum #钥匙 else: rewardDefinitionId = rewardType db_tool.__addPropItem(propDict,rewardType,rewardNum) db_tool.saveAllProp(playerId,propDict) #更新player db_tool.__updatePlayer(playerId,{'gb':player['gb'],'energy':player['energy'],'last_energy_time':player['last_energy_time']}) returnVal = { 'status':1, 'gb':rewardGb, 'energy':rewardEnergy, 'definitionId':rewardDefinitionId, 'player':player, 'bag':propDict } 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 startExchangeTask(playerId): propDict = db_tool.getAllProp(playerId) player = db_tool.__getPlayerById(playerId) player = player_module.__updateEnergy(player) taskInfo = getExchangeTask(playerId) taskId = taskInfo['task_id'] if not EXCHANGE_TASK_CONFIG.has_key(taskId): return {'status':0,'msg':'没有相应的兑换任务 '+str(taskId)} needDefinitonList = EXCHANGE_TASK_CONFIG[taskId]['needDefinitonID'] if not checkBag(playerId,needDefinitonList,propDict): return {'status':0,'msg':'不满足兑换条件 '+str(taskId)} rewardList = EXCHANGE_TASK_CONFIG[taskId]['reward'] rewardGb = 0 rewardExp = 0 rewardEnergy = 0 rewardDefinitionId = 0 for reward in rewardList: rewardType = reward['type'] rewardNum = reward['num'] #金币 if rewardType == 2: rewardGb = rewardNum player['gb'] += rewardNum #经验 if rewardType == 3: rewardExp = rewardNum player['exp'] += rewardNum #能量 elif rewardType == 4: rewardEnergy = rewardNum player['energy'] += rewardNum #物品 else: rewardDefinitionId = rewardType db_tool.__addPropItem(propDict,rewardType,rewardNum) #更新player db_tool.__updatePlayer(playerId,{'gb':player['gb'],'exp':player['exp'],'energy':player['energy'],'last_energy_time':player['last_energy_time']}) db_tool.saveAllProp(playerId,propDict) #更新兑换状态 updTaskInfo = {} updTaskInfo['status'] = 1 updateExchangeTask(playerId,updTaskInfo) return {'status':1,'reward':rewardList,'player':player,'bag':propDict}
def getDailyReward(playerId,isfan): #get player player = db_tool.__getPlayerById(playerId) #if(not player): # return {'status':0,'msg':'player not exist'} #compare login time todayTime = int(time.time()) lastLoginTime = player['last_login_time'] #get login times login_times = player['login_times'] lottery_num = player['lottery_num'] #计算连续登录天数 if(time_tool.isToday(lastLoginTime)): return {'lottery_num':lottery_num,'login_times':login_times} elif(time_tool.isYesterday(lastLoginTime)): login_times+=1 else: login_times = 1 #根据登录天数赠送金币+抽奖次数 rewardDays = login_times if rewardDays>5: rewardDays = 5 rewardGg = DAILY_CONFIG[rewardDays]['gb'] rewardLotteryNum = DAILY_CONFIG[rewardDays]['lotteryNum'] player['gb'] += rewardGg player['lottery_num'] = rewardLotteryNum #vip多一次抽奖机会 #if player['vip']>todayTime: # player['lottery_num'] += 1 #赠送免费挖宝次数 if(isfan): free_treasure_times = 4 else: free_treasure_times = 3 free_times = player['free_times']+free_treasure_times #每日送免费能量 player['help_energy'] = 50 db_tool.__updatePlayer(player['id'],{'free_times':free_times, 'gb':player['gb'], 'lottery_num':player['lottery_num'], 'last_login_time':todayTime, 'login_times':login_times, 'help_energy':player['help_energy']}) return {'lottery_num':player['lottery_num'],'login_times':login_times}
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 harvest(db,conn,playerId,itemId): mapItem = db_tool.lockItem(db,conn,playerId,itemId) if not mapItem: return {'status':0,'msg':'no such item'} definitionId = item_module.getDrawIdByMixId(mapItem['definitionId']) startTime = mapItem['created_time'] friends = mapItem['friends'] #收获消耗的能量,时间,获得的GB costEnergy = 1 addGb = DRAWING_CONFIG[definitionId]['harvest']['income'] costTime = DRAWING_CONFIG[definitionId]['harvest']['duration'] time_now = int(time.time()) if (startTime+costTime) > time_now: return {'status':0,'msg':'need more time for growth'} player = db_tool.__getPlayerById(playerId) player=__updateEnergy(player) #是否被好友收过 if friends: addGb = addGb*3/4 else: player['energy'] -= costEnergy if player['energy'] < 0: return {'status':0,'msg':'not enough energy.'} player['gb'] += addGb db_tool.__updatePlayer(player['id'],{'energy':player['energy'],'gb':player['gb'],'last_energy_time':player['last_energy_time']}) #生长时间置0 updateInfo = {} updateInfo['created_time'] = 0 updateInfo['friends'] = '' db_tool.updateItemById(db,conn,playerId,itemId,updateInfo) ''' #掉落动力石 stone=0 randNum = random.randint(1,100) if 1 <= randNum <= 5: stone=1 else: stone=0 if stone>0: propDict = db_tool.getAllProp(playerId) db_tool.__addPropItem(propDict,10050,stone) db_tool.saveAllProp(playerId,propDict) ''' return {'status':1,'gb':addGb,'playerInfo':player,'id':itemId}
def cancelPurchase(playerId,purchaseId): purchaseItem = getPurchaseItem(purchaseId) if not purchaseItem or purchaseItem['user_id'] != playerId: bag = db_tool.getAllProp(playerId); player = db_tool.__getPlayerById(playerId) return {'status':0,'bag':bag,'gb':player['gb'],'error_type':1,'purchaseId':purchaseId,'msg':'cancelPurchase error by purchaseId'+str(purchaseId)} delPurchaseItem(purchaseId) purchaseList = getPurchaseList(playerId) return {'status':1,'purchaseId':purchaseId,'purchase_transaction':purchaseList}
def helpAlchemy(db,conn,playerId,snsName,snsPic,friendId): player = db_tool.__getPlayerById(playerId) sns_id = player['sns_id'] #正在或等待炼化的信息 alchemyInfoList = getAlchemyInfo(friendId) #正在炼化的信息 active_alchemy = {} time_now = int(time.time()) for alchemy in alchemyInfoList: #分钟转换成秒 needTime = ALCHEMY_CONFIG[alchemy['id']]['time']*60 alchemyTime = alchemy['time'] totalCostTime = alchemyTime+needTime #正在炼化的信息 if time_now < totalCostTime: active_alchemy = alchemy break if not active_alchemy: return {'status':0,'msg':'no active_alchemy info'} helpUserInfo = str(playerId)+'#'+snsName+'#'+snsPic friends = active_alchemy['friends'] #默认空 if friends == '': friendsList = [] else: friendsList = friends.split('@') if helpUserInfo not in friendsList: friendsList.append(helpUserInfo) active_alchemy['friends'] = '@'.join(friendsList) updateAlchemy(friendId,alchemyInfoList) #添加交互日志 log_info = {} log_info['player_id'] = playerId log_info['player_name'] = snsName interaction_event.writeInteractionEventLog(log_info,friendId,2) return {'status':1,'alchemyInfo':alchemyInfoList}
def getExchangeLevelTaskIds(playerId): player = db_tool.__getPlayerById(playerId) level = player['level'] ids = [] if level <= 5: ids = EXCHANGE_LEVEL_TASK_CONFIG[5] elif level <= 10: ids = EXCHANGE_LEVEL_TASK_CONFIG[10] elif level <= 15: ids = EXCHANGE_LEVEL_TASK_CONFIG[15] elif level <= 20: ids = EXCHANGE_LEVEL_TASK_CONFIG[20] elif level <= 25: ids = EXCHANGE_LEVEL_TASK_CONFIG[25] return ids
def usePropInBag(playerId,prop_id): propDict = db_tool.getAllProp(playerId) prop_id=str(prop_id) if propDict.has_key(prop_id) and propDict[prop_id] >0 : player = db_tool.__getPlayerById(playerId) player = player_module.__updateEnergy(player) boxItem = {} #能量道具 if prop_id == '2010' or prop_id == '2011' or prop_id == '2012': player['energy'] += PROP_CONFIG[int(prop_id)]['num'] db_tool.__updatePlayer(player['id'],{'energy':player['energy'],'last_energy_time':player['last_energy_time']}) #VIP道具 elif prop_id == '2001' or prop_id == '2002' or prop_id == '2003': time_now = int(time.time()) if player['vip'] > time_now: player['vip'] += PROP_CONFIG[int(prop_id)]['period'] else: player['vip'] = time_now + PROP_CONFIG[int(prop_id)]['period'] db_tool.__updatePlayer(player['id'],{'vip':player['vip']}) #材料包 elif prop_id == '3001' or prop_id == '3002' or prop_id == '3003': props = PROP_CONFIG[int(prop_id)]['items'] for item in props: db_tool.__addPropItem(propDict,item['type'],item['num']) #神秘箱子 elif prop_id == '4000' or prop_id == '4010': random_table_key = 'magic_box_random_table_'+prop_id boxItem = random_tool.getRandomItem(random_table_key,MAGIC_BOX[int(prop_id)]) db_tool.__addPropItem(propDict,boxItem['type'],boxItem['num']) else: return {'status':0,'msg':'未配置效果物品 ['+str(prop_id)+'].'} propDict[prop_id]-=1 db_tool.saveAllProp(player['id'],propDict) #有箱子信息 if boxItem: return {'status':1,'player':player,'bag':propDict,'time_now':int(time.time()),'prop_id':prop_id,'box_item_type':boxItem['type'],'box_item_num':boxItem['num']} else: return {'status':1,'player':player,'bag':propDict,'time_now':int(time.time()),'prop_id':prop_id} else: return {'status':0,'msg':'Can not find ['+str(prop_id)+'] in bag.'}
def init(serverInfo,is_fan): playerId = serverInfo['playerId'] sns_id = serverInfo['sns_id'] #add weekly reward daily_reward.getWeeklyReward(playerId) #add daily reward (notice: update last_login_time) dailyReward = daily_reward.getDailyReward(playerId,is_fan); #add festival reward festivalDailyReward = daily_reward.getFestivalDailyReward(playerId) #get player info player = db_tool.__getPlayerById(playerId) if not player: return {'status':0,'msg':'player not exist'} time_now = int(time.time()) player_module.__updateEnergy(player) returnVal = {'status':1} returnVal['player'] = player #returnVal['map'] = db_tool.getMapsbyPlayerId(playerId) returnVal['map_level'] = item.getHabitatInfo(playerId) returnVal['searcher'] = search_team.getSearchTeamDetail(playerId) returnVal['bag'] = db_tool.getAllProp(playerId) returnVal['bagMax'] = prop.getBagCapacity(playerId) returnVal['collection'] = collection.getCollection(playerId) returnVal['time_now']=time_now returnVal['box_status']=user_box.getUserBoxStatus(sns_id) returnVal['daily_reward']=dailyReward returnVal['festival_daily_reward']=festivalDailyReward returnVal['daily_task']=daily_task.getTaskInfo(playerId) returnVal['level_task']=level_task.getLevelTaskInfo(playerId) returnVal['produce']=produce.getProduceInfo(playerId) returnVal['invite_info']=invite.getInviteInfo(sns_id) returnVal['system_reward']=system_reward.getSystemRewardInfo(playerId) returnVal['auctionStatus'] = player_module.getAuctionStatus(playerId) returnVal['alchemy']=alchemy.getAlchemyInfo(playerId) returnVal['event_num']=interaction_event.getEventCount(playerId) returnVal['exchange_task']=exchange_task.getExchangeTaskInfo(playerId) returnVal['explore_start']=explore_team.isExploreStart(playerId) returnVal['life_tree'] = life_tree.getLifeTreeInfo(playerId) returnVal['interval_box'] = interval_box.getIntervalBoxInfo(playerId) return returnVal
def helpHarvest(db,conn,playerId,param): playerId = param['player_id'] playerName = param['player_name'] playerPic = param['player_pic'] friendId = param['friend_id'] itemId = param['id'] mapItem = db_tool.lockItem(db,conn,friendId,itemId) if not mapItem: return {'status':0,'msg':'no such item'} definitionId = item_module.getDrawIdByMixId(mapItem['definitionId']) friends = mapItem['friends'] if friends: return {'status':0,'msg':'has helped by others'} player = db_tool.__getPlayerById(playerId) #消耗免费能量 player['help_energy'] -= 1 if player['help_energy'] < 0: return {'status':0,'msg':'not enough helpEnergy'} #获得的GB addGb = DRAWING_CONFIG[definitionId]['harvest']['income']/4 player['gb'] += addGb #获得奖励 db_tool.__updatePlayer(player['id'],{'gb':player['gb'],'help_energy':player['help_energy']}) #记录好友信息 friendsInfo = {} friendsInfo['id'] = playerId friendsInfo['name'] = playerName friendsInfo['pic'] = playerPic updateInfo = {'friends':db_tool.__dictToString(friendsInfo)} db_tool.updateItemById(db,conn,friendId,itemId,updateInfo) #添加交互日志 log_info = {} log_info['player_id'] = playerId log_info['player_name'] = playerName interaction_event.writeInteractionEventLog(log_info,friendId,4) return {'status':1,'gb':addGb,'playerInfo':player,'id':itemId}
def getAuction(playerId): time_now = int(time.time()) player = db_tool.__getPlayerById(playerId) if not player: return {'status':0,'msg':'用户不存在'} returnVal = {} returnVal['status'] = 1 returnVal['vip'] = 1 if time_now < player['vip'] else 0 returnVal['uid'] = playerId returnVal['transaction'] = __getTransactionList(playerId) returnVal['player'] = player returnVal['events'] = getAuctionEvent(playerId) returnVal['purchase_transaction'] = purchase.getPurchaseList(playerId) returnVal['purchase_events'] = purchase.getPurchaseEvent(playerId) return returnVal