Esempio n. 1
0
def gold(rk_user, params):
    """
    消耗金币抽将
    """
    user_card_obj = UserCards.get_instance(rk_user.uid)
    #需要的金币
    cost_gacha_gold = game_config.gacha_config['cost_gacha_gold']
    if not rk_user.user_property.is_gold_enough(cost_gacha_gold):
        return 11, {'msg': utils.get_msg('user', 'not_enough_gold')}
    rate_conf = __get_rate_conf('gold', rk_user)
    cid, clv = __select_gacha_thing(rate_conf)
    #扣除抽奖的金币
    if rk_user.user_property.minus_gold(cost_gacha_gold):
        #加卡
        success_fg, p1, ucid, is_first = user_card_obj.add_card(
            cid, clv, where='gacha_gold')
        new_card = {
            'ucid': ucid,
            'is_first': is_first,
        }
        new_card.update(user_card_obj.get_card_dict(ucid))
        #写入跑马灯
        user_marquee_obj = UserMarquee.get(rk_user.subarea)
        marquee_params = {
            'type': 'gacha_gold',
            'username': rk_user.username,
            'cid': cid,
        }
        user_marquee_obj.record(marquee_params)
        return 0, {'new_card': new_card}
    else:
        #金币不够
        return 11, {'msg': utils.get_msg('user', 'not_enough_gold')}
Esempio n. 2
0
def gold(rk_user,params):
    """
    消耗金币抽将
    """
    user_card_obj = UserCards.get_instance(rk_user.uid)
    #需要的金币
    cost_gacha_gold = game_config.gacha_config['cost_gacha_gold']
    if not rk_user.user_property.is_gold_enough(cost_gacha_gold):
        return 11,{'msg':utils.get_msg('user','not_enough_gold')}
    rate_conf = __get_rate_conf('gold',rk_user)
    cid,clv = __select_gacha_thing(rate_conf)
    #扣除抽奖的金币
    if rk_user.user_property.minus_gold(cost_gacha_gold):
        #加卡
        success_fg,p1,ucid,is_first = user_card_obj.add_card(cid,clv,where='gacha_gold')
        new_card = {
            'ucid':ucid,
            'is_first':is_first,
        }
        new_card.update(user_card_obj.get_card_dict(ucid))
        #写入跑马灯
        user_marquee_obj = UserMarquee.get(rk_user.subarea)
        marquee_params = {
            'type': 'gacha_gold',
            'username': rk_user.username,
            'cid': cid,
        }
        user_marquee_obj.record(marquee_params)
        return 0,{'new_card':new_card}
    else:
        #金币不够
        return 11,{'msg':utils.get_msg('user','not_enough_gold')}
Esempio n. 3
0
 def marquee_info(self):
     """获得跑马灯的信息, 每隔10分钟返回一次"""
     if time.time() - self.baseinfo.get('marquee_rtime', 1) >= 10 * 60:
     #if time.time() - self.baseinfo.get('marquee_rtime', time.time()) >= 10:
         user_marquee_obj = UserMarquee.get(self.subarea)
         dmarquee = user_marquee_obj.marquee_info
         mlen = len(dmarquee)
         self.baseinfo['marquee_rtime'] = time.time()
         self.put()
         return {'info': dmarquee, 'mlen': mlen} 
     else:
         return {'mlen': 0}
Esempio n. 4
0
def charge(rk_user, params):
    """
    收费gacha抽将
    """
    ug = rk_user.user_gacha

    # 先尝试倒计免费时求将
    timer_rate_conf = __free_gacha(rk_user, params)
    if timer_rate_conf:
        cost_coin = 0
        rate_conf = timer_rate_conf
        # 更新免费抽的上次时间
        ug.set_last_gacha_time()
    else:
        cost_coin = game_config.gacha_config['cost_coin']
        rate_conf = __get_rate_conf('charge', rk_user)

    if not rk_user.user_property.is_coin_enough(cost_coin):
        raise GameLogicError('user', 'not_enough_coin')
    # 随机抽取, 获得武将或武将碎片
    thing_id, num = __select_gacha_thing(rate_conf)
    add_info = tools.add_things(rk_user, [{
        "_id": thing_id,
        "num": num
    }],
                                where="gacha")
    # 扣元宝
    rk_user.user_property.minus_coin(cost_coin, 'gacha')

    # user_card_obj = UserCards.get_instance(rk_user.uid)
    # # 加卡
    # success_fg,p1,ucid,is_first = user_card_obj.add_card(cid, where='gacha_charge')
    # new_card = {
    #     'ucid':ucid,
    #     'is_first':is_first,
    # }
    # new_card.update(user_card_obj.get_card_dict(ucid))

    if 'card' in add_info:
        # 保底开关
        if is_open_safty():
            for card_info in add_info['card']:
                cid = card_info['cid']
                __set_safety_coin(rk_user, cid, cost_coin)
                # 写入跑马灯
                user_marquee_obj = UserMarquee.get(rk_user.subarea)
                marquee_params = {
                    'type': 'gacha_charge',
                    'username': rk_user.username,
                    'cid': cid,
                }
                user_marquee_obj.record(marquee_params)
    # cardSoul 加传  card 的星级
    elif 'cardSoul' in add_info:
        card_config = rk_user.game_config.card_config
        for card_id in add_info['cardSoul']:
            num = add_info['cardSoul'][card_id]
            star = card_config[card_id]['star']
            add_info['cardSoul'][card_id] = {'num': num, 'star': star}

    # 抽将必送的物品.
    get_things = __gacha_must_get(rk_user)

    ug.set_gacha_cnt()

    # 判断新手引导
    newbie_step = int(params.get('newbie_step', 0))
    if newbie_step:
        rk_user.user_property.set_newbie_steps(newbie_step, "gacha")
    return {
        'add_info': add_info,
        'get_things': get_things,
        'gacha_cnt': ug.gacha_cnt,
    }
Esempio n. 5
0
def charge(rk_user,params):
    """
    收费gacha抽将
    """
    ug = rk_user.user_gacha

    # 先尝试倒计免费时求将
    timer_rate_conf = __free_gacha(rk_user,params)
    if timer_rate_conf:
        cost_coin = 0
        rate_conf = timer_rate_conf
        # 更新免费抽的上次时间
        ug.set_last_gacha_time()
    else:
        cost_coin = game_config.gacha_config['cost_coin']
        rate_conf = __get_rate_conf('charge', rk_user)

    if not rk_user.user_property.is_coin_enough(cost_coin):
        raise GameLogicError('user', 'not_enough_coin')
    # 随机抽取, 获得武将或武将碎片
    thing_id, num = __select_gacha_thing(rate_conf)
    add_info = tools.add_things(
        rk_user, 
        [{"_id": thing_id, "num": num}],
        where="gacha"
    )
    # 扣元宝
    rk_user.user_property.minus_coin(cost_coin, 'gacha')


    # user_card_obj = UserCards.get_instance(rk_user.uid)
    # # 加卡
    # success_fg,p1,ucid,is_first = user_card_obj.add_card(cid, where='gacha_charge')
    # new_card = {
    #     'ucid':ucid,
    #     'is_first':is_first,
    # }
    # new_card.update(user_card_obj.get_card_dict(ucid))
    
    if 'card' in add_info:
        # 保底开关
        if is_open_safty():
            for card_info in add_info['card']:
                cid = card_info['cid']
                __set_safety_coin(rk_user, cid, cost_coin)
                # 写入跑马灯
                user_marquee_obj = UserMarquee.get(rk_user.subarea)
                marquee_params = {
                    'type': 'gacha_charge',
                    'username': rk_user.username,
                    'cid': cid,
                }
                user_marquee_obj.record(marquee_params)
    # cardSoul 加传  card 的星级
    elif 'cardSoul' in add_info:
        card_config = rk_user.game_config.card_config
        for card_id in add_info['cardSoul']:
            num = add_info['cardSoul'][card_id]
            star = card_config[card_id]['star']
            add_info['cardSoul'][card_id] = {'num': num, 'star': star}

    # 抽将必送的物品.
    get_things = __gacha_must_get(rk_user)

    ug.set_gacha_cnt()

    # 判断新手引导
    newbie_step = int(params.get('newbie_step',0))
    if newbie_step:
        rk_user.user_property.set_newbie_steps(newbie_step, "gacha")
    return {
        'add_info': add_info,
        'get_things': get_things,
        'gacha_cnt': ug.gacha_cnt,
    }