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 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}