Пример #1
0
def habitatLevelUp(playerId,infos):
    habitatId = infos['habitat_id']
    type = infos['money_type']
    
    habitatInfo = getHabitatInfo(playerId)
    levelInfo = str2dict(habitatInfo['info'])
    
    if not levelInfo.has_key(str(habitatId)):
        return {'status':0,'msg':'err habitatId'}
    
    nextLevel = levelInfo[str(habitatId)]+1
    limitInfo = HABITAT_CONFIG[habitatId][nextLevel]
    player = db_tool.__getPlayerById(playerId)
    
    #使用GB升级
    if(type==1):
        price = limitInfo['GB']
        if player['gb'] < price:
            return {'status':0,'msg':'not enough GB'}
        elif player['level'] < limitInfo['levelLimit']:
            return {'status':0,'msg':'not enough Level'}
        else :
            player['gb']-=price
            db_tool.__updatePlayer(playerId,{'gb':player['gb']})
    
    #使用KB升级
    else :
        price = limitInfo['KB']
        if player['kb'] < price:
           return {'status':0,'msg':'not enough KB'}
        else:
            player['kb']-=price
            db_tool.__updatePlayer(playerId,{'kb':player['kb']})
            
            #add cost log
            player_module.addCostLog(player['id'],price,'habitatLevelUp')
    
    levelInfo[str(habitatId)] = nextLevel
    updateInfo = {'info':dict2str(levelInfo)}
    updateHabitatInfo(playerId,updateInfo)
    
    return {'status':1,'gb':player['gb'],'kb':player['kb'],'id':habitatId,'level':nextLevel,'habitat':levelInfo}
Пример #2
0
def buildingLevelUp(playerId,type):
    
    player = db_tool.__getPlayerById(playerId)
    
    produceInfo = produce_module.getProduceById(playerId)
    nextLevel = produceInfo['level']+1
    produce_module.updateProduceLevel(playerId,nextLevel)
    
    #使用GB升级
    if(type==1):
        price = PRODUCE_COFIG[nextLevel]['GB']
        if player['gb'] < price:
            return {'status':0,'msg':'not enough GB'}
        elif player['level'] < PRODUCE_COFIG[nextLevel]['levelLimit']:
            return {'status':0,'msg':'not enough Level'}
        else :
            player['gb']-=price
            db_tool.__updatePlayer(playerId,{'gb':player['gb']})
    
    #使用KB升级
    else :
        price = PRODUCE_COFIG[nextLevel]['KB']
        if player['kb'] < price:
           return {'status':0,'msg':'not enough KB'}
        else:
            player['kb']-=price
            db_tool.__updatePlayer(playerId,{'kb':player['kb']})
            
            #add cost log
            player_module.addCostLog(player['id'],price,'buildingLevelUp')
        
    returnVal = {}
    returnVal['status'] = 1  
    returnVal['level'] = nextLevel
    returnVal['gb'] = player['gb']
    returnVal['kb'] = player['kb']
    returnVal['player'] = player
    return returnVal