コード例 #1
0
ファイル: daily_reward.py プロジェクト: flycare/kaka_world
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}
コード例 #2
0
ファイル: exchange_task.py プロジェクト: flycare/kaka_world
def getExchangeTaskInfo(playerId):
    taskInfo = getExchangeTask(playerId)
    
    #返回的任务ID
    retTaskId = 0
    
    taskIds = getExchangeLevelTaskIds(playerId)
    
    #没有相应的兑换任务
    if not taskIds:
        return retTaskId
    
    if not taskInfo:
        time_now = int(time.time())
        taskId = random.choice(taskIds)
        
        taskInfo = {}
        taskInfo['player_id'] = playerId
        taskInfo['create_time'] = time_now
        taskInfo['task_id'] = taskId
        taskInfo['status'] = 0
        
        saveExchangeTask(taskInfo)
        
        retTaskId = taskId
    else:
        if time_tool.isToday(taskInfo['create_time']):
            
            #今天是否已经兑换
            if taskInfo['status'] == 0:
                retTaskId = taskInfo['task_id']
            else:
                pass
        else:
            time_now = int(time.time())
            taskId = random.choice(taskIds)
            
            updTaskInfo = {}
            updTaskInfo['create_time'] = time_now
            updTaskInfo['task_id'] = taskId
            updTaskInfo['status'] = 0
            updateExchangeTask(playerId,updTaskInfo)
            
            retTaskId = taskId
    
    return retTaskId
コード例 #3
0
ファイル: festival_gift.py プロジェクト: flycare/kaka_world
def receiveGift(playerId,giftId,giftNum):
    giftId = str(giftId)
    time_now = int(time.time())
    festivalInfo = getFestivalGift(playerId)
    
    #今日送过礼物的好友
    friends = ''
    #剩余礼物个数
    total_gifts = 0

    if not festivalInfo:
        giftDict = {giftId:giftNum}
        
        festivalInfo = {}
        festivalInfo['player_id'] = playerId
        festivalInfo['gifts'] = dict2str(giftDict)
        festivalInfo['presented_friends'] = ''
        festivalInfo['start_time'] = time_now
        
        saveFestivalGift(festivalInfo)
    else:
        giftDict = str2dict(festivalInfo['gifts'])
        
        if not time_tool.isToday(festivalInfo['start_time']):
            
            if giftDict.has_key(giftId):
                giftDict[giftId] += giftNum
            else:
                giftDict[giftId] = giftNum
            
            updateInfo = {}
            updateInfo['gifts'] = dict2str(giftDict)
            updateInfo['presented_friends'] = ''
            updateInfo['start_time'] = time_now
            updateFestivalGift(playerId,updateInfo)

        else:
            friends = festivalInfo['presented_friends']
    
    if giftDict.has_key(giftId):
        total_gifts = giftDict[giftId]
    
    return {'giftId':giftId,'giftNum':total_gifts,'friends':friends}
コード例 #4
0
ファイル: friend.py プロジェクト: flycare/kaka_world
def getVisitFriends(db,conn,player_id):
    returnVal = {}
    db.execute("SELECT * FROM visit_friend WHERE player_id = %s",(player_id,))
    visitInfo = db.fetchone()
    if(not visitInfo):
        time_now = int(time.time())
        db.execute("INSERT INTO visit_friend(player_id,first_visit,daily_visit,visit_time) VALUES(%s,%s,%s,%s)",
                    (player_id,'','',time_now))
        conn.commit()
        returnVal['first_visit']=''
        returnVal['daily_visit']=''
    else:
        returnVal['first_visit']=visitInfo['first_visit']
        returnVal['daily_visit']=visitInfo['daily_visit']
        if not time_tool.isToday(visitInfo['visit_time']):
            daily_visit = ''
            todayTime = int(time.time())
            db.execute("UPDATE visit_friend set daily_visit = %s,visit_time = %s WHERE player_id = %s",(daily_visit,todayTime,player_id))
            conn.commit()
            returnVal['daily_visit']=[]
    return returnVal