Пример #1
0
def becomeVIP(playerId,prop_id):
    player = db_tool.__getPlayerById(playerId)
    bool=1
    time_now = int(time.time())
    if(PROP_CONFIG[prop_id]['KB']>0):
        player['kb'] -= PROP_CONFIG[prop_id]['KB']
        if player['kb'] < 0:
            bool=0
        else:
            #add cost log
            player_module.addCostLog(playerId,PROP_CONFIG[prop_id]['KB'],'becomeVIP')
            
    elif (PROP_CONFIG[prop_id]['GB']>0):
        player['gb'] -= PROP_CONFIG[prop_id]['GB']
        if player['gb'] < 0:
            bool=0
    if(bool):
        if player['vip'] > time_now:
            player['vip'] += PROP_CONFIG[prop_id]['period']
        else:
            player['vip'] = time_now + PROP_CONFIG[prop_id]['period']
            
        db_tool.__updatePlayer(player['id'],{'vip':player['vip'],'kb':player['kb'],'gb':player['gb']})
        return {'status':1,'vip':player['vip'],'kb':player['kb']}
    else:
        return {'status':0,'msg':'Not enough money.'}
Пример #2
0
def decorateGroupInShop(playerId,param):
    habitatId = param['map_index']
    groupId = param['groupId']
    groupItems = param['group']
    
    item = {'definitionId':groupId}
    
    #买装饰物需要花费的钱
    cost_money=__getCostMoney(item)
    player = db_tool.__getPlayerById(playerId)
    #比较
    if (player['kb']<cost_money['kb']):
        return {'status':0,'msg':'not enough KB'}
    elif (player['gb']<cost_money['gb']):
        return {'status':0,'msg':'not enough GB'}
    #扣除
    player['gb'] -=cost_money['gb']
    player['kb'] -=cost_money['kb']
    player['exp'] += cost_money['exp']
    #添加
    addItems = db_tool.addMapItemList(playerId,habitatId,groupItems)
    db_tool.__updatePlayer(player['id'],{'gb':player['gb'],'kb':player['kb'],'exp':player['exp']})
    
    #add cost log
    if cost_money['kb']>0:
        player_module.addCostLog(player['id'],cost_money['kb'],'decorateGroupInShop')
    
    return {'status':1,'group':addItems,'player':player}
Пример #3
0
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.'}