コード例 #1
0
ファイル: festival_gift.py プロジェクト: flycare/kaka_world
def presentGift(playerId,playerName,friendId,giftId):
    giftId = str(giftId)
    festivalInfo = getFestivalGift(playerId)
    
    presentedFriendsList = str2list(festivalInfo['presented_friends'])
    if friendId in presentedFriendsList:
        return {'status':0,'msg':'Only allow presentGift for once a day '}
    else:
        giftDict = str2dict(festivalInfo['gifts'])
        
        if giftDict[giftId] < 1:
            return {'status':0,'msg':'not enough gifts to present'}
        
        giftDict[giftId] -= 1
        presentedFriendsList.append(friendId)
        
        updateInfo = {}
        updateInfo['gifts'] = dict2str(giftDict)
        updateInfo['presented_friends'] = list2str(presentedFriendsList)
        updateFestivalGift(playerId,updateInfo)
        
        #给好友背包添加礼物
        propDict = db_tool.getAllProp(friendId)
        db_tool.__addPropItem(propDict,giftId,1)
        db_tool.saveAllProp(friendId,propDict)
        
        log_info = {}
        log_info['player_id'] = playerId
        log_info['player_name'] = playerName
        log_info['number'] = 1
        log_info['prop_id'] = giftId
        #添加赠送记录
        writeGiftEventLog(log_info,friendId)
        
        return {'status':1,'gifts':giftDict,'friends':updateInfo['presented_friends']}
コード例 #2
0
ファイル: search_team.py プロジェクト: flycare/kaka_world
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}
コード例 #3
0
ファイル: auction.py プロジェクト: flycare/kaka_world
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'}
コード例 #4
0
ファイル: collection.py プロジェクト: flycare/kaka_world
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
コード例 #5
0
ファイル: daily_reward.py プロジェクト: flycare/kaka_world
def getWeeklyReward(playerId):
    todayTime = int(time.time())
    addReward = False
    
    rewardInfo = explore_reward.getExploreRewardInfo(playerId)

    if not rewardInfo:
        rewardInfo = {}
        rewardInfo['player_id'] = playerId
        rewardInfo['create_time'] = todayTime
        explore_reward.saveExploreRewardInfo(rewardInfo)
        
        addReward = True
    else:
        #if time_tool.getIntervalDays(rewardInfo['create_time']) >= 3:
        if time_tool.getWeekNum(rewardInfo['create_time']) != time_tool.getWeekNum(todayTime):
            
            updRewardInfo = {}
            updRewardInfo['create_time'] = todayTime
            explore_reward.updateExploreRewardInfo(playerId,updRewardInfo)
            
            addReward = True
    
    #每周赠送两个(每人最多两个)
    if addReward:
        propDict = db_tool.getAllProp(playerId)
        #db_tool.__addPropItem(propDict,EXPLORE_NEED_PROPID,2)
        propDict[EXPLORE_NEED_PROPID] = 2
        db_tool.saveAllProp(playerId,propDict)
コード例 #6
0
ファイル: daily_reward.py プロジェクト: flycare/kaka_world
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}
コード例 #7
0
ファイル: user_box.py プロジェクト: flycare/kaka_world
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
コード例 #8
0
ファイル: level_task.py プロジェクト: flycare/kaka_world
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':'没有相应的等级任务'}
コード例 #9
0
ファイル: alchemy.py プロジェクト: flycare/kaka_world
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}
コード例 #10
0
ファイル: prop.py プロジェクト: flycare/kaka_world
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'}
コード例 #11
0
ファイル: player.py プロジェクト: flycare/kaka_world
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}
コード例 #12
0
ファイル: alchemy.py プロジェクト: flycare/kaka_world
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}
コード例 #13
0
ファイル: alchemy.py プロジェクト: flycare/kaka_world
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']}
コード例 #14
0
ファイル: explore_team.py プロジェクト: flycare/kaka_world
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
コード例 #15
0
ファイル: explore_team.py プロジェクト: flycare/kaka_world
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}
コード例 #16
0
ファイル: exchange_task.py プロジェクト: flycare/kaka_world
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}
コード例 #17
0
ファイル: prop.py プロジェクト: flycare/kaka_world
def decorateInBag(playerId,param):
    habitatId = param['map_index']
    definitionId = str(param['definitionId'])
    propDict= db_tool.getAllProp(playerId)
    if propDict.has_key(definitionId) and propDict[definitionId]>0:
        propDict[definitionId]=propDict[definitionId]-1
        addItems = db_tool.addMapItem(playerId,habitatId,param)
        db_tool.saveAllProp(playerId,propDict)
        return {'status':1,'add':addItems}
    else:
        return {'status':0,'msg':'no definitionId in bag'}
コード例 #18
0
ファイル: search_team.py プロジェクト: flycare/kaka_world
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"]}
コード例 #19
0
ファイル: item.py プロジェクト: flycare/kaka_world
def updateMapItems(playerId,habitatId,param,propDict):
    #删除界面上的Item
    moveItems = db_tool.updateMapItemsXY(playerId,habitatId,param['move'])
    sellItems = db_tool.delMapItems(playerId,habitatId,param['sell'])
    backItems = db_tool.delMapItems(playerId,habitatId,param['back'])
    
    #更新背包
    for item in backItems:
        db_tool.__addPropItem(propDict,item['definitionId'],1)
    db_tool.saveAllProp(playerId,propDict)
        
    return moveItems,sellItems,backItems,propDict
コード例 #20
0
ファイル: explore_team.py プロジェクト: flycare/kaka_world
def getStepReward(playerId,step):
    personInfo = getExploreInfo(playerId)
    
    teamInfo,membersInfo = getExploreMembers(playerId)
    floor = teamInfo['floor']
    rewardId = (floor-1)*3+step
    
    rewardList = rewardstr2list(personInfo['reward'])
    rewardId = str(rewardId)
    if rewardId not in rewardList:
        return {'status':0,'msg':'has no step reward '+rewardId}
    
    rewardList.remove(rewardId)
    
    exploreInfo = {}
    exploreInfo['reward'] = list2rewardstr(rewardList)
    updateExploreInfo(playerId,exploreInfo)
    
    #随机获得奖励
    rewardProp = random.choice(EXPLORE_REWARD_CONFIG[int(rewardId)])
    
    propDict = db_tool.getAllProp(playerId)
    db_tool.__addPropItem(propDict,rewardProp,1)
    db_tool.saveAllProp(playerId,propDict)
    
    returnVal = getTeamUpInfo(playerId)
    #前台展现使用
    returnVal['definitionId'] = rewardProp
    returnVal['num'] = 1
    returnVal['bag'] = propDict
    #任务判断使用
    returnVal['floor'] = returnVal['teamInfo']['floor']
    returnVal['reward_step'] = step
    
    #add eventlog
    eventInfo = {'snsName':personInfo['sns_name']}
    eventInfo['definitionId'] = rewardProp
    eventInfo['num'] = 1
    eventInfo['step'] = step
    addExploreEventLog(personInfo['leader'],5,eventInfo)
    
    #完成所有阶段游戏并领取奖励后,退出游戏
    if not rewardList and returnVal['teamInfo']['step'] == 4:
        quitTeamUp(playerId)
        returnVal['teamInfo'] = None
        
        #add eventlog
        eventInfo = {'snsName':personInfo['sns_name']}
        addExploreEventLog(personInfo['leader'],6,eventInfo)
    
    
    return returnVal
コード例 #21
0
ファイル: auction.py プロジェクト: flycare/kaka_world
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)}
コード例 #22
0
ファイル: prop.py プロジェクト: flycare/kaka_world
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.'}
コード例 #23
0
ファイル: exchange.py プロジェクト: flycare/kaka_world
def startExchange(playerId, exchangeData):
    exchangeId = exchangeData["index"]
    # 检查兑换需要的物品并扣除物品
    propDict = db_tool.getAllProp(playerId)
    if not checkExchange(playerId, exchangeId, propDict):
        return {"status": 0, "msg": "不满足兑换条件 or 活动结束 " + str(exchangeId)}
    # 给玩家奖励
    propId = EXCHANGE_CONFIG[exchangeId]["goalDefinitionID"]
    propNum = 1
    db_tool.__addPropItem(propDict, propId, propNum)
    db_tool.saveAllProp(playerId, propDict)
    return {
        "status": 1,
        "exchangeId": exchangeId,
        "exchangeData": exchangeData,
        "num": propNum,
        "definitionId": propId,
        "bag": propDict,
    }
コード例 #24
0
ファイル: produce.py プロジェクト: flycare/kaka_world
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']}
コード例 #25
0
ファイル: collection.py プロジェクト: flycare/kaka_world
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']}
コード例 #26
0
ファイル: explore_team.py プロジェクト: flycare/kaka_world
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
コード例 #27
0
ファイル: explore_team.py プロジェクト: flycare/kaka_world
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
コード例 #28
0
ファイル: prop.py プロジェクト: flycare/kaka_world
def buyPropInShop(playerId,params):
    player = db_tool.__getPlayerById(playerId)
    bool = True 
    for each in params :
        prop_id = each['definitionId']
        number = each['number']
        #
        if str(prop_id) == '2':
            pass
        elif PROP_CONFIG[prop_id]['KB']>0 :
            #logging.debug(each)
            money=PROP_CONFIG[prop_id]['KB']*number
            player['kb']-=money
            if player['kb'] < 0:
                bool=False
            else:
                #add cost log
                player_module.addCostLog(playerId,money,'buyPropInShop')
                
        elif PROP_CONFIG[prop_id]['GB']>0:
            money=PROP_CONFIG[prop_id]['GB']*number
            player['gb']-=money
            if player['gb'] < 0:
                bool=False
        else:
            return {'status':0,'msg':'There is a error in PROP_CONFIG'}
    
    if bool:
        db_tool.__updatePlayer(player['id'],{'gb':player['gb'],'kb':player['kb']})
        propDict = db_tool.getAllProp(playerId)
        for each in params :
            db_tool.__addPropItem(propDict,each['definitionId'],each['number'])#Not update db
        db_tool.saveAllProp(player['id'],propDict)#update db
        returnVal = {}
        returnVal['status'] = 1
        returnVal['player'] = player
        returnVal['bag'] = propDict
        returnVal['items'] = params
        return returnVal
    else :
        return {'status':0,'msg':'Not enough money.'}
コード例 #29
0
ファイル: produce.py プロジェクト: flycare/kaka_world
def finishProduce(playerId,machineId):
    #get from db
    produceInfo = getProduceList(playerId)
    produceId = produceInfo[str(machineId)]['produceId']
    startProduceTime = produceInfo[str(machineId)]['startTime']
    #search from config
    definitionId = PRODUCE_CONFIG[produceId]['definitionID']
    definitionNum = PRODUCE_CONFIG[produceId]['num']
    needProduceTime = PRODUCE_CONFIG[produceId]['time']*60
    time_now = int(time.time())
    if((time_now - startProduceTime) >= needProduceTime):
        #add bag
        prop = db_tool.getAllProp(playerId)
        db_tool.__addPropItem(prop,definitionId,definitionNum)
        db_tool.saveAllProp(playerId,prop)
        #remove produce
        produceInfo.pop(str(machineId))
        updateProduce(playerId,produceInfo)
        return {'status':1,'machineId':machineId,'produceId':produceId,'bag':prop}
    else:
        return {'status':0,'msg':'need more time to produce '}
コード例 #30
0
ファイル: auction.py プロジェクト: flycare/kaka_world
def cancelAuction(db,conn,playerId,transaction_id):
    returnVal = {}
    transaction=__lockTransactionById(db,conn,transaction_id)
    if transaction:
        number = transaction['number']
        prop_id = transaction['prop_id']
        
        #放回背包
        propDict=db_tool.getAllProp(playerId)
        db_tool.__addPropItem(propDict,prop_id,number)
        db_tool.saveAllProp(playerId,propDict)
        #删除记录
        __delLockTransactionItem(db,conn,transaction_id)
        
        returnVal['status'] = 1
        returnVal['transaction'] = __getTransactionList(playerId)
        returnVal['bag'] = propDict
        returnVal['auctionId'] = transaction_id
        return returnVal
    else:
        return {'status':0,'error_type':13,'msg':'Can not find the Transaction by id '+str(transaction_id) }