Exemplo n.º 1
0
def openBox(snsid):
    user_box = getUserBox(snsid);
    if(user_box):
        if(user_box['is_open'] == 1):
            return {'status':0,'msg':'box is opened.'}
        else:
            pass
    else:
        return {'status':0,'msg':'box is null.'}
    
    helperIds = helpStr2List(userbox['helper_ids'])
    
    if(helperIds):
        if len(helperIds) >= BOX_CONFIG['need_users']:
            reward,addexp = getRewardAndExp(snsid,BOX_CONFIG)
            '''
            retval = []
            for item in reward:
                retval.append(item)
            '''
            player = db_tool.__getPlayer(snsid)
            return {'status':1,'add_exp':addexp,'reward':reward,'bag':db_tool.getAllProp(player['id'])}
        else:
            return {'status':0,'msg':'Less users.'}
    else:
        return {'status':0,'msg':'openbox --> No helperIds.'}
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def initPlayer(sns_id):
    time_now = time.time()
    player = db_tool.__getPlayer(sns_id)
    if not player:
        #初始化玩家信息+搜索队+道具+地图+session对应表
        playerId = db_tool.__insertNewPlayer(sns_id)
        db_tool.__insertPlayerSeacher(playerId)
        db_tool.__insertItem(playerId)
        db_tool.__insertProp(playerId)
        session.setSession(sns_id)
    else:
        return 0
Exemplo n.º 4
0
def updateInviteReward(db,conn,snsId,alreadyRewardTimes,curRewardTimes):
    player = db_tool.__getPlayer(snsId)
    playerId = player['id']
    system_reward = player['system_reward']
    system_reward_list = system_reward_module.str2list(system_reward)

    #更新系统奖励
    all_sys = system_reward_list+getSysRewardBoxs(alreadyRewardTimes,curRewardTimes)
    system_reward = system_reward_module.list2str(all_sys)
    
    db_tool.__updatePlayer(playerId,{'system_reward':system_reward})
    
    totalRewardTimes = alreadyRewardTimes+curRewardTimes
        
    db.execute("update invite set sys_reward_times=%s where invite_id=%s",(totalRewardTimes,snsId))
    conn.commit()
    
    return totalRewardTimes
Exemplo n.º 5
0
def init(serverInfo,is_fan):
    playerId = serverInfo['playerId']
    sig = serverInfo['sig']
    session_key = serverInfo['session_key']
    sns_id = serverInfo['sns_id']

    #add daily reward
    dailyReward = daily_reward.getDailyReward(playerId,is_fan);
    
    #get player info
    player = db_tool.__getPlayerById(playerId)
    if not player:
        db_tool.__insertNewPlayer(sns_id)
        player = db_tool.__getPlayer(sns_id)
    
    time_now = int(time.time())

    db_tool.__updateEnergy(player)
    #snsObj = getSnsObj(sig,session_key,sns_id)
    #snsInfo = snsObj.getUserInfo()
    #player['name']=snsInfo['name']
    #player['tinyurl']=snsInfo['tinyurl']
    
    returnVal = {'status':1}
    
    returnVal['player'] = player
    #friends = db_tool.__getFriends(snsObj)
    #returnVal['friends'] = friends
    returnVal['map'] = db_tool.getMapsbyPlayerId(playerId)
    returnVal['searcher'] = search_team.getSearchTeamInfo(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['daily_task']=daily_task.getTaskInfo(playerId)
    returnVal['level_task']=level_task.getLevelTaskInfo(playerId)
    returnVal['produce']=produce.getProduceList(playerId)
    returnVal['invite_info']=invite.getInviteInfo(sns_id)
    returnVal['system_reward']=system_reward.getSystemRewardInfo(playerId)
    returnVal['alchemy']=alchemy.getAlchemyInfo(playerId)
    return returnVal