示例#1
0
def get_fudai_things(rk_user, params):
    """开启福袋获得物品

    Args:
        fudai_id   开启的福袋id 
        times      开启次数
    """
    fudai_id = params.get('fudai_id', '')
    open_times = int(params.get('times', 0))
    # 判断是否是福袋
    if not game_config.props_config.get(fudai_id, {}).get('used_by',
                                                          '') == 'fudai':
        raise GameLogicError('pack', 'wrong_used')
        # 判断用户是否有该道具
    user_pack_obj = rk_user.user_pack
    if not user_pack_obj.is_props_enough(fudai_id, open_times):
        raise GameLogicError('pack', 'not_enough_props')
    fudai_conf = game_config.operat_config.get('fudai_conf',
                                               {}).get(fudai_id, {})
    get_things_conf = fudai_conf.get('get_things', {})
    get_things_list = []
    for cnt in range(open_times):
        get_things_dict = utils.get_items_by_weight_dict(get_things_conf, 1)[0]
        things_id = get_things_dict['id']
        things_num = get_things_dict['num']
        get_things_list.append({'_id': things_id, 'num': things_num})
    all_get_things = tools.add_things(rk_user,
                                      get_things_list,
                                      where=u"open_fudai_%s" % fudai_id)
    # 减素材
    user_pack_obj.minus_props(fudai_id, open_times, where="open_fudai")
    return {'get_info': all_get_things}
示例#2
0
文件: gift.py 项目: wzgdavid/myCoding
def get_sign_in_gift(rk_user, params):
    '''
    领取签到奖励
    params['day'] 当月日期,作为id使用
    '''
    day = '5' 
    ug = rk_user.user_gift
    now = datetime.datetime.now()
    month = str(now.month)
    today = str(now.day)
    print ' _get_total_sign_in_days(ug)',  _get_total_sign_in_days(ug)
    if day != str(_get_total_sign_in_days(ug) + 1):
        return 11, {'msg': utils.get_msg('gift', 'signin_in_turn')}
    if ug.sign_in_record[day]['has_got']:
        return 11, {'msg': utils.get_msg('gift', 'gift_has_got')}

    if ug.sign_in_record[today].get('today_has_signed_in', False):
        return 11, {'msg': utils.get_msg('gift', 'today_has_signed_in')} 
    # 添加奖励
    awards = game_config.loginbonus_config['sign_in_bonus'].get(month, {}).get(day, {})
    data = tools.add_things(
        rk_user, 
        [{"_id": goods, "num": awards[goods]} for goods in awards if goods],
        where="open_server_gift"
    )
    ug.sign_in_record[day]['has_got'] = True
    #  每天只能签到一次,此字段用来后端判断当天是否已签到过
    ug.sign_in_record[today]['today_has_signed_in'] = True
    ug.do_put()    
    rk_user.user_property.do_put()
    rk_user.user_pack.do_put()
    rk_user.user_cards.do_put()
    rk_user.user_equips.do_put()    
    return 0, data
示例#3
0
文件: gift.py 项目: wzgdavid/myCoding
def get_open_server_gift(rk_user, params):
    '''
    领取开服礼包中的奖励
    参数
        params['day'] 第几次领
    '''
    #day = params['day']
    day = '5'
    ug = rk_user.user_gift
    ul = rk_user.user_login
    awards = game_config.loginbonus_config['open_server_gift'].get('awards', {})
    if day not in awards.keys():
        return 11, {'msg': utils.get_msg('gift', 'gift_not_exist')}
    the_gift = ug.open_server_record['gifts'][day]
    if the_gift['has_got']:
        return 11, {'msg': utils.get_msg('gift', 'gift_has_got')}
    today = utils.get_today_str()
    if ug.open_server_record['date_info'].get(today, False):
        return 11, {'msg': utils.get_msg('gift', 'today_has_signed_in')}
    # 按顺序领取
    if int(day) != _got_days(ug)+1:
        return 11, {'msg': utils.get_msg('gift', 'signin_in_turn')}
    data = tools.add_things(
        rk_user, 
        [{"_id": goods, "num": awards[goods]} for goods in awards if goods],
        where="open_server_gift"
    )
    the_gift['has_got'] = True
    # 因为每天只能领取一次,'date_info'用来按日期记录哪天是否已领过一次
    ug.open_server_record['date_info'][today] = True 
    ug.do_put()
    return 0, data
示例#4
0
def get_fudai_things(rk_user, params):
    """开启福袋获得物品

    Args:
        fudai_id   开启的福袋id 
        times      开启次数
    """
    fudai_id = params.get('fudai_id', '')
    open_times = int(params.get('times', 0))
    # 判断是否是福袋
    if not game_config.props_config.get(fudai_id, {}).get('used_by','') == 'fudai':
        raise GameLogicError('pack', 'wrong_used')
        # 判断用户是否有该道具
    user_pack_obj = rk_user.user_pack
    if not user_pack_obj.is_props_enough(fudai_id, open_times):
        raise GameLogicError('pack', 'not_enough_props')
    fudai_conf = game_config.operat_config.get('fudai_conf', {}).get(fudai_id, {})
    get_things_conf = fudai_conf.get('get_things', {})
    get_things_list = []
    for cnt in range(open_times):
        get_things_dict = utils.get_items_by_weight_dict(get_things_conf, 1)[0]
        things_id = get_things_dict['id']
        things_num = get_things_dict['num']
        get_things_list.append({'_id': things_id, 'num': things_num})
    all_get_things = tools.add_things(rk_user, get_things_list, where=u"open_fudai_%s" %fudai_id)
    # 减素材
    user_pack_obj.minus_props(fudai_id, open_times, where="open_fudai")
    return {'get_info': all_get_things}
示例#5
0
def get_growup_awards(rk_user, params):
    """ 领取等级成长奖励

    Args:
        award_lv:  领取是第几等级的奖励
    """
    award_lv = params.get('award_lv', '0')
    ua = rk_user.user_activity
    ua_growup_info = ua.growup_info
    all_growup_awards = game_config.operat_config.get('growup_award', {})

    # 没有购买成长计划
    if not ua_growup_info.get('has_bought', False):
        raise GameLogicError('has not bought')
    # 不存在该等级奖励
    if award_lv not in all_growup_awards:
        raise GameLogicError('lv award no exist')
    # 等级未到达
    user_property_obj = rk_user.user_property
    if int(user_property_obj.lv) < int(award_lv):
        raise GameLogicError('lv not reached')
    # 已领取的等级奖励 不能再领
    has_got_award_lvs = ua_growup_info.get('has_got_lvs', [])
    if award_lv in has_got_award_lvs:
        raise GameLogicError('has got this award')
    has_got_award_lvs.append(award_lv)
    ua_growup_info['has_got_lvs'] = has_got_award_lvs
    ua.put()
    # 加物品
    get_things = [{'_id': thing_id, 'num': num}  for thing_id, num in 
            all_growup_awards[award_lv].get('awards', {}).items()]
    all_get_goods = tools.add_things(rk_user, get_things, where='get_growup_awards_%s' %award_lv)
    return {"get_info": all_get_goods}
示例#6
0
def get_sign_in_gift(rk_user, params):
    '''
    领取签到奖励
    params['day'] 代表第几次签到,如果当月已签到3次则day应该是4
    '''
    day = params['day']
    ug = rk_user.user_gift
    now = datetime.datetime.now()
    month = str(now.month)
    today = str(now.day)
    
    if ug.sign_in_record[day]['has_got']:
        return 11, {'msg': utils.get_msg('gift', 'gift_has_got')}
    # 一天只能领一次
    if ug.sign_in_record[today].get('today_has_signed_in', False):
        return 11, {'msg': utils.get_msg('gift', 'today_has_signed_in')}
    # 不能跳领,必须一天一个按顺序领
    if day != str(ug.total_sign_days + 1):
        return 11, {'msg': utils.get_msg('gift', 'signin_in_turn')}
    # 添加奖励
    conf = game_config.loginbonus_config['sign_in_bonus']
    award = conf.get(month, conf[conf.keys()[0]]).get(day, {})  # 容错处理,没配置当月的话取配置里的第一个

    data = tools.add_things(
        rk_user, 
        [{"_id": goods, "num": award[goods]} for goods in award if goods],
        where="sign_in_gift"
    )
    #  用来给前端显示是否已领取,这时sign_in_record的下一层字段代表签到天数
    ug.sign_in_record[day]['has_got'] = True
    #  每天只能签到一次,此字段用来后端判断当天是否已签到过,这时sign_in_record的下一层字段代表日期
    ug.sign_in_record[today]['today_has_signed_in'] = True
    ug.put()

    return 0, data
示例#7
0
def receive(rk_user, params):
    '''
    领取邮件中的内容
    '''
    mails_id = str(params['mails_id'])
    all_info = UserMail.hgetall(rk_user.uid)
    return_info = {}
    for m in all_info:
        mid = all_info[m]['mail_info']['mid']
        if mid == mails_id:
            can_get = all_info[m]['mail_info'].get('can_get', False)
            if can_get is False:
                break
            awards = all_info[m]['mail_info']['awards']
            where = 'mail_' + all_info[m]['mail_info']['title']
            return_info = tools.add_things(rk_user, [{
                "_id": goods,
                "num": awards[goods]
            } for goods in awards if goods], where)

            umobj = UserMail.hget(rk_user.uid, m)
            umobj.mail_info['can_get'] = False
            umobj.mail_info['open_time'] = utils.datetime_toString(
                datetime.datetime.now())
            umobj.hput()
            break

    return 0, {'receive': return_info}
示例#8
0
def get_open_server_gift(rk_user, params):
    '''
    领取开服礼包中的奖励
    参数
        params['day'] 第几次领
    '''
    day = params['day']
    ug = rk_user.user_gift
    ul = rk_user.user_login
    awards = game_config.loginbonus_config['open_server_gift'].get('awards', {})
    if day not in awards.keys():
        return 11, {'msg': utils.get_msg('gift', 'gift_not_exist')}
    the_gift = ug.open_server_record['gifts'][day]
    if the_gift['has_got']:
        return 11, {'msg': utils.get_msg('gift', 'gift_has_got')}
    # 一天只能领一次
    today = utils.get_today_str()
    if ug.open_server_record['date_info'].get(today, False):
        return 11, {'msg': utils.get_msg('gift', 'today_has_signed_in')}
    # 按顺序领取
    if int(day) != ug.total_open_days+1:
        return 11, {'msg': utils.get_msg('gift', 'signin_in_turn')}
    this_award = awards[day]
    data = tools.add_things(
        rk_user, 
        [{"_id": goods, "num": this_award[goods]} for goods in this_award if goods],
        where="open_server_gift"
    )
    
    the_gift['has_got'] = True
    # 因为每天只能领取一次,'date_info'用来按日期记录哪天是否已领过一次
    ug.open_server_record['date_info'][today] = True 
    ug.put()
    return 0, data
示例#9
0
def charge_multi(rk_user,params):
    """
    收费gacha多连抽
    """
    user_gacha_obj = rk_user.user_gacha
    user_card_obj = UserCards.get_instance(rk_user.uid)
    #元宝是否足够连抽
    multi_gacha_cnt = game_config.gacha_config.get('multi_gacha_cnt',10)
    cost_coin = game_config.gacha_config['cost_coin']

    
    total_cost_coin = cost_coin * multi_gacha_cnt * game_config.gacha_config['multi_discount'] # 10连抽打折(9折)
    if not rk_user.user_property.is_coin_enough(total_cost_coin):
        raise GameLogicError('user', 'not_enough_coin')
    cids = []

    get_list = []
    for cnt in range(multi_gacha_cnt):
        if cnt == 9:
            rate_conf = __multi_tenth_charge_rate(rk_user, cids) or __get_rate_conf('charge', rk_user)
        else:
            rate_conf = __get_rate_conf('charge', rk_user)
        thing_id, num = __select_gacha_thing(rate_conf)
        get_list.append({'_id': thing_id, 'num': num})
        user_gacha_obj.set_gacha_cnt()


        # success_fg, p1, ucid, is_first = user_card_obj.add_card(cid, clv, where='gacha_multi')
        # new_card = {
        #     'ucid':ucid,
        #     'is_first':is_first,
        # }
        # if is_open_safty():
        #     __set_safety_coin(rk_user, cid, cost_coin)

        # cids.append(cid)
        # new_card.update(user_card_obj.get_card_dict(ucid))
        # new_cards.append(new_card)

    add_info = tools.add_things(
        rk_user, 
        get_list,
        where="gacha_multi"
    )

    # cardSoul 加传  card 的星级
    if '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}
    rk_user.user_property.minus_coin(total_cost_coin, 'gacha_multi')
    get_things = __gacha_must_get(rk_user, multi_gacha_cnt)
    return {
        'add_info': add_info,
        'get_things': get_things
    }
示例#10
0
def __gacha_must_get(rk_user, gacha_times=1):
    # 抽将必送的物品.
    gacha_things = game_config.gacha_config['gacha_things']
    rtn_data = {}
    data = tools.add_things(
        rk_user, 
        [{"_id": goods, "num": gacha_things[goods] * gacha_times} for goods in gacha_things if goods],
        where="gacha_must_get_things"
    )
    for v in data.values():
        rtn_data.update(v)
    return rtn_data
示例#11
0
def __gacha_must_get(rk_user, gacha_times=1):
    # 抽将必送的物品.
    gacha_things = game_config.gacha_config['gacha_things']
    rtn_data = {}
    data = tools.add_things(rk_user, [{
        "_id": goods,
        "num": gacha_things[goods] * gacha_times
    } for goods in gacha_things if goods],
                            where="gacha_must_get_things")
    for v in data.values():
        rtn_data.update(v)
    return rtn_data
示例#12
0
def charge_multi(rk_user, params):
    """
    收费gacha多连抽
    """
    user_gacha_obj = rk_user.user_gacha
    user_card_obj = UserCards.get_instance(rk_user.uid)
    #元宝是否足够连抽
    multi_gacha_cnt = game_config.gacha_config.get('multi_gacha_cnt', 10)
    cost_coin = game_config.gacha_config['cost_coin']

    total_cost_coin = cost_coin * multi_gacha_cnt * game_config.gacha_config[
        'multi_discount']  # 10连抽打折(9折)
    if not rk_user.user_property.is_coin_enough(total_cost_coin):
        raise GameLogicError('user', 'not_enough_coin')
    cids = []

    get_list = []
    for cnt in range(multi_gacha_cnt):
        if cnt == 9:
            rate_conf = __multi_tenth_charge_rate(
                rk_user, cids) or __get_rate_conf('charge', rk_user)
        else:
            rate_conf = __get_rate_conf('charge', rk_user)
        thing_id, num = __select_gacha_thing(rate_conf)
        get_list.append({'_id': thing_id, 'num': num})
        user_gacha_obj.set_gacha_cnt()

        # success_fg, p1, ucid, is_first = user_card_obj.add_card(cid, clv, where='gacha_multi')
        # new_card = {
        #     'ucid':ucid,
        #     'is_first':is_first,
        # }
        # if is_open_safty():
        #     __set_safety_coin(rk_user, cid, cost_coin)

        # cids.append(cid)
        # new_card.update(user_card_obj.get_card_dict(ucid))
        # new_cards.append(new_card)

    add_info = tools.add_things(rk_user, get_list, where="gacha_multi")

    # cardSoul 加传  card 的星级
    if '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}
    rk_user.user_property.minus_coin(total_cost_coin, 'gacha_multi')
    get_things = __gacha_must_get(rk_user, multi_gacha_cnt)
    return {'add_info': add_info, 'get_things': get_things}
示例#13
0
def buy_store_goods(rk_user, params):
    """
    用功勋兑换 Pk 商店物品
    params  参数需包含 
        goods_index:   所兑换的物品index
    返回 data 包括所兑换物品和商店信息
    """

    goods_index = int(params['goods_index'])
    user_pk_store = rk_user.user_pk_store
    user_pk_goods = user_pk_store.goods
    
    
    # pk商店无此物品
    if not (0 <= goods_index < len(user_pk_goods)):
        return 11, {'msg': utils.get_msg('pk_store', 'no_this_goods')}
    
    goods_info = user_pk_goods[goods_index]
    
    # 已兑换过
    if not user_pk_store.can_buy_this_goods(goods_index):
        raise GameLogicError('pk_store', 'can_not_buy_again')
    need_honor = goods_info['need_honor']
    # 兑换所需功勋点不够
    user_real_pvp = rk_user.user_real_pvp
    if not user_real_pvp.is_honor_enough(need_honor):
        raise GameLogicError('pk_store', 'not_enough_honor')
    # 扣除功勋
    user_real_pvp.minus_honor(need_honor, where='buy_PkStore_goods')
    # 兑换物品
    user_pk_store.goods_has_bought(goods_index)

    # 发放兑换物品
    all_get_goods = tools.add_things(rk_user,
                             [goods_info['goods']],
                             where="buy_pk_store_goods")


    # 记录log
    log_data = {"cost_honor": need_honor, "goods": all_get_goods}
    data_log_mod.set_log("PkStore", rk_user, **log_data)

    data = {'get_info': all_get_goods}
    data.update(_pack_store_info(user_pk_store.store_info()))
    return data
示例#14
0
def buy_store_goods(rk_user, params):
    """
    用功勋兑换 Pk 商店物品
    params  参数需包含 
        goods_index:   所兑换的物品index
    返回 data 包括所兑换物品和商店信息
    """

    goods_index = int(params['goods_index'])
    user_pk_store = rk_user.user_pk_store
    user_pk_goods = user_pk_store.goods

    # pk商店无此物品
    if not (0 <= goods_index < len(user_pk_goods)):
        return 11, {'msg': utils.get_msg('pk_store', 'no_this_goods')}

    goods_info = user_pk_goods[goods_index]

    # 已兑换过
    if not user_pk_store.can_buy_this_goods(goods_index):
        raise GameLogicError('pk_store', 'can_not_buy_again')
    need_honor = goods_info['need_honor']
    # 兑换所需功勋点不够
    user_real_pvp = rk_user.user_real_pvp
    if not user_real_pvp.is_honor_enough(need_honor):
        raise GameLogicError('pk_store', 'not_enough_honor')
    # 扣除功勋
    user_real_pvp.minus_honor(need_honor, where='buy_PkStore_goods')
    # 兑换物品
    user_pk_store.goods_has_bought(goods_index)

    # 发放兑换物品
    all_get_goods = tools.add_things(rk_user, [goods_info['goods']],
                                     where="buy_pk_store_goods")

    # 记录log
    log_data = {"cost_honor": need_honor, "goods": all_get_goods}
    data_log_mod.set_log("PkStore", rk_user, **log_data)

    data = {'get_info': all_get_goods}
    data.update(_pack_store_info(user_pk_store.store_info()))
    return data
示例#15
0
def get_award(rk_user, params):
    '''领取主线任务奖励'''
    task_set = params['task']
    award_result = rk_user.user_task.get_award(task_set)  # 已做领奖次数+1的处理
    print 'award_result', award_result
    if award_result != 0 :
        raise GameLogicError('task','cant_get_award')
    conf = game_config.task_config['main_task']
    current_award = str(rk_user.user_task.main_task[task_set]['got_award'])
    print 'current_award',current_award
    award = conf[task_set]['award'][current_award]
    print 'awardinfo', [{"_id": goods, "num": award[goods]} for goods in award if goods]
    data = {}
    data['get_things'] = tools.add_things(
        rk_user,
        [{"_id": goods, "num": award[goods]} for goods in award if goods],
        where="main_task_award"
    )
    data.update(show_main_task(rk_user, params)[1])
    return 0, data
示例#16
0
def buy_vip_gift(rk_user, params):
    "购买vip礼品包"
    vip_gift_id = params.get('vip_gift_id', '')
    vip_gift_sale_config = game_config.vip_store_config.get('vip_sale', {})

    user_property_obj = rk_user.user_property
    vip_cur_level = user_property_obj.vip_cur_level

    # 已购买的vip礼包id list
    has_bought_ids = user_property_obj.property_info['has_bought_vip_package']

    # 判断vip礼包id是否有效
    if not vip_gift_id:
        raise GameLogicError('gift', 'gift_code_error')
    # 判断是否存在该vip礼包
    if vip_gift_id not in vip_gift_sale_config:
        raise GameLogicError('gift', 'gift_code_not_exist')
    # 判断玩家的vip等级是否达到
    if int(vip_gift_id) > int(vip_cur_level):
        raise GameLogicError('gift', 'level_not_enough')
    # 判断玩家是否已经购买相应的vip礼包
    if vip_gift_id in has_bought_ids:
        raise GameLogicError('gift', 'gift_already_buy')

    need_coin = vip_gift_sale_config[vip_gift_id]['coin']
    # 判断玩家的元宝是否达到
    if not user_property_obj.is_coin_enough(need_coin):
        raise GameLogicError('user', 'not_enough_coin')

    goods_list = vip_gift_sale_config[vip_gift_id]['goods_list']
    all_get_goods = tools.add_things(rk_user, [{
        "_id": good_id,
        "num": num
    } for good_id, num in goods_list.items()],
                                     where='buy_vip_gift')
    # 扣除元宝
    user_property_obj.minus_coin(need_coin, where="buy_vip_gift")

    user_property_obj.add_bought_vip_package(vip_gift_id)
    return {'get_info': all_get_goods}
示例#17
0
def get_growup_awards(rk_user, params):
    """ 领取等级成长奖励

    Args:
        award_lv:  领取是第几等级的奖励
    """
    award_lv = params.get('award_lv', '0')
    ua = rk_user.user_activity
    ua_growup_info = ua.growup_info
    all_growup_awards = game_config.operat_config.get('growup_award', {})

    # 没有购买成长计划
    if not ua_growup_info.get('has_bought', False):
        raise GameLogicError('has not bought')
    # 不存在该等级奖励
    if award_lv not in all_growup_awards:
        raise GameLogicError('lv award no exist')
    # 等级未到达
    user_property_obj = rk_user.user_property
    if int(user_property_obj.lv) < int(award_lv):
        raise GameLogicError('lv not reached')
    # 已领取的等级奖励 不能再领
    has_got_award_lvs = ua_growup_info.get('has_got_lvs', [])
    if award_lv in has_got_award_lvs:
        raise GameLogicError('has got this award')
    has_got_award_lvs.append(award_lv)
    ua_growup_info['has_got_lvs'] = has_got_award_lvs
    ua.put()
    # 加物品
    get_things = [{
        '_id': thing_id,
        'num': num
    }
                  for thing_id, num in all_growup_awards[award_lv].get(
                      'awards', {}).items()]
    all_get_goods = tools.add_things(rk_user,
                                     get_things,
                                     where='get_growup_awards_%s' % award_lv)
    return {"get_info": all_get_goods}
示例#18
0
def get_box(rk_user, params):
    '''
    领取每日任务的宝箱
    '''
    box_type = params['box_type']
    ut = rk_user.user_task

    points = ut.daily_info['points']
    box_conf = game_config.task_config['daily_task_box'][box_type]
    if points < box_conf['need_point']:
        raise GameLogicError('task','not_enough_points')
    if ut.daily_info['has_got'][box_type] == True:
        raise GameLogicError('task','box_has_got')
    award = box_conf['award']
    data = tools.add_things(
        rk_user,
        [{"_id": goods, "num": award[goods]} for goods in award if goods],
        where="daily_task_award"
    )
    ut.daily_info['has_got'][box_type] = True
    ut.put()
    return 0, data
示例#19
0
def buy_store_goods(rk_user, params):
    """
    玩家购买指定商品时逻辑
    params  参数需包含 store_type: 可选  "packages"   "gold_store"  or  "coin_store" 
                     goods_index:  int  为所买商品在所属类型的index   
    """
    #store_type = params['store_type']
    goods_index = int(params['goods_index'])

    buy_goods_info = {}
    goods_list = []
    user_mystery_store_obj = rk_user.user_mystery_store

    buy_goods_info = user_mystery_store_obj.store_info()['store'][goods_index]
    goods_list.append(buy_goods_info['goods'])
    need = "need_coin" if buy_goods_info.get("need_coin", 0) else "need_fight_soul"
    needed_cost = buy_goods_info.get(need, 0)
    fight_or_coin = need.replace("need_", "")
   

    #  根据store_type  决定是 消耗元宝还是战魂
    minus_func = getattr(rk_user.user_property, "minus_" + fight_or_coin)

    if not minus_func(needed_cost, 'buy_mystery_store_goods'):
        raise GameLogicError('user', 'not_enough_' + fight_or_coin)

    # 发商品    
    # 前端通过rc 是否等于 0 判断是否购买成功
    if not user_mystery_store_obj.update_goods_info_by_index(goods_index):
        raise GameLogicError('has bought this item')
    all_get_goods = tools.add_things(rk_user, goods_list, where=u"buy_from_mystery_store")

    # 记录log
    log_data = {"cost": fight_or_coin, "cost_num": needed_cost, "goods": goods_list}
    data_log_mod.set_log("MysteryStore", rk_user, **log_data)

    return {'get_info': all_get_goods}
示例#20
0
def buy_vip_gift(rk_user, params):
    "购买vip礼品包"
    vip_gift_id = params.get('vip_gift_id', '')
    vip_gift_sale_config = game_config.vip_store_config.get('vip_sale',{})

    user_property_obj = rk_user.user_property
    vip_cur_level = user_property_obj.vip_cur_level

    # 已购买的vip礼包id list
    has_bought_ids = user_property_obj.property_info['has_bought_vip_package']

    # 判断vip礼包id是否有效
    if not vip_gift_id:
        raise GameLogicError('gift', 'gift_code_error')
    # 判断是否存在该vip礼包
    if vip_gift_id not in vip_gift_sale_config:
        raise GameLogicError('gift','gift_code_not_exist')
    # 判断玩家的vip等级是否达到
    if int(vip_gift_id) > int(vip_cur_level):
        raise GameLogicError('gift','level_not_enough')
    # 判断玩家是否已经购买相应的vip礼包
    if vip_gift_id in has_bought_ids:
        raise GameLogicError('gift','gift_already_buy')

    need_coin = vip_gift_sale_config[vip_gift_id]['coin']
    # 判断玩家的元宝是否达到
    if not user_property_obj.is_coin_enough(need_coin):
        raise GameLogicError('user', 'not_enough_coin')

    goods_list = vip_gift_sale_config[vip_gift_id]['goods_list']
    all_get_goods = tools.add_things(rk_user, [{"_id": good_id, "num": num} 
        for good_id, num in goods_list.items()], where='buy_vip_gift')
    # 扣除元宝
    user_property_obj.minus_coin(need_coin, where="buy_vip_gift")

    user_property_obj.add_bought_vip_package(vip_gift_id)
    return {'get_info': all_get_goods}
示例#21
0
def receive(rk_user, params):
    '''
    领取邮件中的内容
    '''
    mails_id = str(params['mails_id'])
    all_info = UserMail.hgetall(rk_user.uid)
    return_info = {}
    for m in all_info:
        mid = all_info[m]['mail_info']['mid']
        if mid == mails_id:
            can_get = all_info[m]['mail_info'].get('can_get', False)
            if can_get is False:
                break
            awards = all_info[m]['mail_info']['awards']
            where = 'mail_' + all_info[m]['mail_info']['title']
            return_info = tools.add_things(rk_user, [{"_id": goods, "num": awards[goods]} for goods in awards if goods], where)

            umobj = UserMail.hget(rk_user.uid, m)
            umobj.mail_info['can_get'] = False
            umobj.mail_info['open_time'] = utils.datetime_toString(datetime.datetime.now())
            umobj.hput()
            break

    return 0, {'receive': return_info}
示例#22
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,
    }
示例#23
0
def get_giftCode_gift(rk_user, params):
    """兑换礼品码

    Args:
        gift_code:   礼品码
    """
    gift_keys = game_config.gift_config.get("gift_config", {})
    if rk_user.client_type in settings.ANDROID_CLIENT_TYPE and "is_open" in game_config.android_config:
        is_open = game_config.android_config.get("is_open", True)
    else:
        is_open = game_config.gift_config.get("is_open", True)
    if not is_open:
        msg = utils.get_msg("gift", "gift_not_open")
        return 11, {"msg": msg}
    # 校验礼品码
    gift_code = params["gift_code"]
    gift_code = gift_code.strip()
    gift_id = gift_code[:-5]
    if gift_id not in gift_keys:
        msg = utils.get_msg("gift", "gift_code_not_exist")
        return 11, {"msg": msg}
    gift_conf = game_config.gift_config["gift_config"][gift_id]
    start_time = utils.string_toDatetime(gift_conf.get("start_time", "2013-05-29 00:00:00"))
    end_time = utils.string_toDatetime(gift_conf.get("end_time", "2020-05-29 00:00:00"))
    now_time = datetime.datetime.now()
    if now_time < start_time or now_time > end_time:
        return 11, {"msg": utils.get_msg("gift", "gift_not_in_right_time")}

    gift_code_obj = GiftCode.get(gift_id)
    user_gift_obj = UserGift.get_instance(rk_user.uid)

    # 平台限制判断
    gift_platform_list = gift_conf.get("platform_list", [])
    if gift_platform_list and rk_user.platform not in gift_platform_list:
        return 11, {"msg": utils.get_msg("gift", "platform_not_allowed")}
    # 分区限制判断
    gift_subarea_list = gift_conf.get("subarea_list", [])
    if gift_subarea_list and rk_user.subarea not in gift_subarea_list:
        return 11, {"msg": utils.get_msg("gift", "subarea_not_allowed")}

    if gift_id in user_gift_obj.gift_code_type:
        return 11, {"msg": utils.get_msg("gift", "this_type_already_get")}
    if not gift_code_obj or gift_code not in gift_code_obj.codes:
        return 11, {"msg": utils.get_msg("gift", "gift_code_not_exist")}
    # 是否允许不同uid领取相同礼品码
    recycling = gift_conf.get("recycling", False)
    if not recycling:
        if gift_code_obj.codes[gift_code]:
            return 11, {"msg": utils.get_msg("gift", "gift_code_gived")}
    # 玩家是否已经领取了此礼品码
    if not user_gift_obj.add_has_got_gift_code(gift_code):
        return 11, {"msg": utils.get_msg("gift", "gift_code_gived")}

    # 记录该礼品码被最后一次领取的uid
    gift_code_obj.codes[gift_code] = rk_user.uid
    gift_code_obj.put()
    # 记录玩家已领的礼品码
    user_gift_obj.gift_code_type.append(gift_id)
    # 发礼品
    all_get_things = tools.add_things(
        rk_user,
        [{"_id": thing_id, "num": num} for thing_id, num in gift_conf.get("gift", {}).items()],
        where=u"giftCode_award",
    )
    # 对于可以升级获得的奖励
    # if gift.get('lv_up_gift',{}):
    #     user_gift_obj.add_lv_up_giftcode(gift_id)
    #     user_gift_obj.get_giftcode_lv_up_award(gift_id)
    user_gift_obj.put()
    return {"get_info": all_get_things}
示例#24
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,
    }
示例#25
0
def get_giftCode_gift(rk_user, params):
    """兑换礼品码

    Args:
        gift_code:   礼品码
    """
    gift_keys = game_config.gift_config.get('gift_config', {})
    if rk_user.client_type in settings.ANDROID_CLIENT_TYPE and 'is_open' in game_config.android_config:
        is_open = game_config.android_config.get('is_open', True)
    else:
        is_open = game_config.gift_config.get('is_open', True)
    if not is_open:
        msg = utils.get_msg('gift', 'gift_not_open')
        return 11, {'msg': msg}
    # 校验礼品码
    gift_code = params['gift_code']
    gift_code = gift_code.strip()
    gift_id = gift_code[:-5]
    if gift_id not in gift_keys:
        msg = utils.get_msg('gift', 'gift_code_not_exist')
        return 11, {'msg': msg}
    gift_conf = game_config.gift_config['gift_config'][gift_id]
    start_time = utils.string_toDatetime(
        gift_conf.get('start_time', '2013-05-29 00:00:00'))
    end_time = utils.string_toDatetime(
        gift_conf.get('end_time', '2020-05-29 00:00:00'))
    now_time = datetime.datetime.now()
    if now_time < start_time or now_time > end_time:
        return 11, {'msg': utils.get_msg('gift', 'gift_not_in_right_time')}

    gift_code_obj = GiftCode.get(gift_id)
    user_gift_obj = UserGift.get_instance(rk_user.uid)

    # 平台限制判断
    gift_platform_list = gift_conf.get('platform_list', [])
    if gift_platform_list and rk_user.platform not in gift_platform_list:
        return 11, {'msg': utils.get_msg('gift', 'platform_not_allowed')}
    # 分区限制判断
    gift_subarea_list = gift_conf.get('subarea_list', [])
    if gift_subarea_list and rk_user.subarea not in gift_subarea_list:
        return 11, {'msg': utils.get_msg('gift', 'subarea_not_allowed')}

    if gift_id in user_gift_obj.gift_code_type:
        return 11, {'msg': utils.get_msg('gift', 'this_type_already_get')}
    if not gift_code_obj or gift_code not in gift_code_obj.codes:
        return 11, {'msg': utils.get_msg('gift', 'gift_code_not_exist')}
    # 是否允许不同uid领取相同礼品码
    recycling = gift_conf.get('recycling', False)
    if not recycling:
        if gift_code_obj.codes[gift_code]:
            return 11, {'msg': utils.get_msg('gift', 'gift_code_gived')}
    # 玩家是否已经领取了此礼品码
    if not user_gift_obj.add_has_got_gift_code(gift_code):
        return 11, {'msg': utils.get_msg('gift', 'gift_code_gived')}

    # 记录该礼品码被最后一次领取的uid
    gift_code_obj.codes[gift_code] = rk_user.uid
    gift_code_obj.put()
    # 记录玩家已领的礼品码
    user_gift_obj.gift_code_type.append(gift_id)
    # 发礼品
    all_get_things = tools.add_things(rk_user, [{
        '_id': thing_id,
        'num': num
    } for thing_id, num in gift_conf.get('gift', {}).items()],
                                      where=u"giftCode_award")
    #对于可以升级获得的奖励
    # if gift.get('lv_up_gift',{}):
    #     user_gift_obj.add_lv_up_giftcode(gift_id)
    #     user_gift_obj.get_giftcode_lv_up_award(gift_id)
    user_gift_obj.put()
    return {'get_info': all_get_things}
示例#26
0
def __give_first_charge_award(rk_user):
    """首次充值奖励
    """
    first_charge_award = rk_user.game_config.operat_config.get('first_charge_award', {})
    tools.add_things(rk_user, [{'_id': thing_id, 'num': num}
                     for thing_id, num in first_charge_award.items()], where='first_charge_award')