Example #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')}
Example #2
0
def __has_safety_card(rk_user):
    """
    是否有保底卡
    """
    safety_cards = [card_conf[0] for card_conf in game_config.gacha_config['gacha_black_conf']['safety_cards']]
    user_card_obj = UserCards.get_instance(rk_user.uid)
    return user_card_obj.has_card_in_list(safety_cards)
Example #3
0
def show_user_cards_fields():
    user_card_obj = UserCards.get_instance(uid)
    print 'user_card_obj.cards','-'*50
    pprint (user_card_obj.cards)
    print 'user_card_obj.cards_info','-'*50
    #pprint (user_card_obj.cards_info)
    print 'user_card_obj.decks','-'*50
Example #4
0
def gold_multi(rk_user,params):
    """
    金币gacha连抽
    """
    user_card_obj = UserCards.get_instance(rk_user.uid)
    #获取配置里面的多次抽将的次数
    multi_gacha_cnt = game_config.gacha_config.get('multi_gacha_cnt',10)
    cost_gacha_gold = int(game_config.gacha_config['cost_gacha_gold'])*int(multi_gacha_cnt)
    if not rk_user.user_property.is_gold_enough(cost_gacha_gold):
        return 11,{'msg':utils.get_msg('user','not_enough_gold')}
    #只可以进行配置要求的次数
    if rk_user.user_property.minus_gold(cost_gacha_gold):
        #抽卡
        rate_conf = __get_rate_conf('gold',rk_user)
        cards = __select_gacha_multi_cards(rate_conf, 10)
        #加卡
        new_cards = []
        for cid,clv in cards:
            success_fg,p1,ucid,is_first = user_card_obj.add_card(cid,clv, where = 'free_multi')
            new_card = {
                'ucid':ucid,
                'is_first':is_first,
            }
            new_card.update(user_card_obj.get_card_dict(ucid))
            new_cards.append(new_card)
        return 0,{'new_cards':new_cards}
    else:
        #金币不够
        return 11,{'msg':utils.get_msg('user','not_enough_gold')}
Example #5
0
def exchange_card(rk_user, params):
    """
    将魂卡兑换成武将
    miaoyichao
    """
    # 需要兑换的武将
    cid = params['cid']
    user_souls_obj = UserSouls.get_instance(rk_user.uid)
    user_card_obj = UserCards.get_instance(rk_user.uid)
    needed_souls = int(game_config.card_config[cid]['souls_needed'])
    #   将魂不足
    if not user_souls_obj.is_normal_soul_enough(cid,needed_souls):
        return 11, {'msg': utils.get_msg('soul','not_enough_soul')}
    #减武将碎片
    user_souls_obj.minus_card_soul(cid, needed_souls, 'soul_exchange_card')
    # 加武将
    success_fg, p1, ucid, is_first = user_card_obj.add_card(cid, where='soul_exchange_card')
    new_card = {
        'ucid':ucid,
        'is_first':is_first,
    }
    new_card.update(user_card_obj.get_card_dict(ucid))
    return 0, {
                'new_card': new_card,
    }
Example #6
0
def set_decks():
    user_card_obj = UserCards.get_instance(UID)
    old_leader_ucid = user_card_obj.leader_ucid
    decks = user_card_obj.deck
    cards = user_card_obj.cards.keys()
    cards_info = user_card_obj.cards_info
    print  'data=',json.dumps(cards,indent=1)
Example #7
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')}
Example #8
0
def gold_multi(rk_user, params):
    """
    金币gacha连抽
    """
    user_card_obj = UserCards.get_instance(rk_user.uid)
    #获取配置里面的多次抽将的次数
    multi_gacha_cnt = game_config.gacha_config.get('multi_gacha_cnt', 10)
    cost_gacha_gold = int(
        game_config.gacha_config['cost_gacha_gold']) * int(multi_gacha_cnt)
    if not rk_user.user_property.is_gold_enough(cost_gacha_gold):
        return 11, {'msg': utils.get_msg('user', 'not_enough_gold')}
    #只可以进行配置要求的次数
    if rk_user.user_property.minus_gold(cost_gacha_gold):
        #抽卡
        rate_conf = __get_rate_conf('gold', rk_user)
        cards = __select_gacha_multi_cards(rate_conf, 10)
        #加卡
        new_cards = []
        for cid, clv in cards:
            success_fg, p1, ucid, is_first = user_card_obj.add_card(
                cid, clv, where='free_multi')
            new_card = {
                'ucid': ucid,
                'is_first': is_first,
            }
            new_card.update(user_card_obj.get_card_dict(ucid))
            new_cards.append(new_card)
        return 0, {'new_cards': new_cards}
    else:
        #金币不够
        return 11, {'msg': utils.get_msg('user', 'not_enough_gold')}
Example #9
0
def exchange_card(rk_user, params):
    """
    将魂卡兑换成武将
    miaoyichao
    """
    # 需要兑换的武将
    cid = params['cid']
    user_souls_obj = UserSouls.get_instance(rk_user.uid)
    user_card_obj = UserCards.get_instance(rk_user.uid)
    needed_souls = int(game_config.card_config[cid]['souls_needed'])
    #   将魂不足
    if not user_souls_obj.is_normal_soul_enough(cid, needed_souls):
        return 11, {'msg': utils.get_msg('soul', 'not_enough_soul')}
    #减武将碎片
    user_souls_obj.minus_card_soul(cid, needed_souls, 'soul_exchange_card')
    # 加武将
    success_fg, p1, ucid, is_first = user_card_obj.add_card(
        cid, where='soul_exchange_card')
    new_card = {
        'ucid': ucid,
        'is_first': is_first,
    }
    new_card.update(user_card_obj.get_card_dict(ucid))
    return 0, {
        'new_card': new_card,
    }
Example #10
0
def get_all(rk_user, params):
    """
    * 取得用户的全部武将
    * miaoyichao
    """
    data = {}
    data['user_cards'] = UserCards.get_instance(rk_user.uid).cards
    return 0, data
Example #11
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
    }
Example #12
0
def __has_safety_card(rk_user):
    """
    是否有保底卡
    """
    safety_cards = [
        card_conf[0] for card_conf in
        game_config.gacha_config['gacha_black_conf']['safety_cards']
    ]
    user_card_obj = UserCards.get_instance(rk_user.uid)
    return user_card_obj.has_card_in_list(safety_cards)
Example #13
0
def add_card(cid):
    ucid = create_gen_id()
    #cid = '3_card'
    user_cards_obj = UserCasuser_card_obj = UserCards.get_instance(uid)
    user_cards_obj.cards[ucid] = {
                            'cid':cid,
                            'lv': 1,
                            'exp': 0,
                            'talent_lv':0,
                            'upd_time':int(time.time()),
                            }
    user_cards_obj.do_put()
Example #14
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}
Example #15
0
def show_all_cards():
    user_card_obj = UserCards.get_instance(uid)
    cards = user_card_obj.cards
    ucids = [ucid for ucid in cards]
    ucids.sort()
    for ucid in ucids:
        print ucid,cards[ucid]
	# del card
        #if cards[ucid]['upd_time'] == 1417750539:
	#    user_card_obj.cards.pop(ucid)
    user_card_obj.do_put()
    print 'cards length', len(cards)

    cards_info = user_card_obj.cards_info
    decks = cards_info['decks']
    pprint(cards) 
Example #16
0
def ttest_give_award():
    user_property = UserProperty.get_instance(uid)
    uc = UserCards.get_instance(uid) 
    ue = UserEquips.get_instance(uid) 
    up = UserPack.get_instance(uid)
    us = UserSouls.get_instance(uid) 
    #award = {'card':{'1_card':1}}
    #award = {'equip':{'13001_equip': 2}}
    #award = {'props':{'1_props':2}}
    #award = {'soul':{'card':{'1_card':1}}}
    award = {'soul':{'equip':{'13001_equip':1}}}
    print user_property.test_give_award(award)
    uc.do_put()   
    ue.do_put()
    up.do_put()
    us.do_put()
Example #17
0
def wipe_out():
    '''
    扫荡
    目前只有普通战场有扫荡
    '''
    d_type = 'normal' 
    floor_id = '1'
    room_id  = '1'
    do_times = 1   # 扫荡次数
    data = {}
    if d_type not in ['normal'] or not floor_id or not room_id or do_times not in [1, 10]:
        return 11,{'msg':utils.get_msg('dungeon', 'invalid_params')} # 
    user_dungeon = UserDungeon.get(uid)
    has_played_info = user_dungeon.has_played_info
    '''
    has_played_floor = has_played_info[d_type].get(floor_id)
    # 未达到此战场
    if not has_played_floor:
        return 11,{'msg':utils.get_msg('dungeon', 'not_arrived')} # 
    has_played_room = has_played_floor['rooms'].get(room_id)
    if not has_played_room:
        return 11,{'msg':utils.get_msg('dungeon', 'not_arrived')} # 
    # 没达到3星
    if not has_played_room['perfect']:
        return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')} # 
    '''
    try:
        has_played_info[d_type][floor_id]['rooms'][room_id]
    except:
        return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')}
    # 没达到3星(完美过关)
    if not has_played_info[d_type][floor_id]['rooms'][room_id]['perfect']:
        return 11,{'msg':utils.get_msg('dungeon', 'not_three_star')}
    # 扫荡券不够
    user_pack = UserPack.get_instance(uid)
    if not user_pack.is_props_enough('24_props', do_times):
        return 11,{'msg':utils.get_msg('dungeon', 'wipe_out_not_enough')} # 
    # 目前只有普通战场 
    dungeon_config = game_config.normal_dungeon_config
    room_config = dungeon_config[floor_id]['rooms'][room_id]

    # 计算能够扫荡次数
    can_make_copy_cnt = room_config['can_make_copy_cn']
    if d_type == 'normal':
        try:  #  判断dungeon_repeat_info中有无此关卡记录
            user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] += 0
        except :
            # 无此关卡记录时,把此关卡今日完成次数置零
            if d_type not in user_dungeon.dungeon_repeat_info:
                user_dungeon.dungeon_repeat_info[d_type]={}
            if floor_id not in user_dungeon.dungeon_repeat_info[d_type]:
                user_dungeon.dungeon_repeat_info[d_type][floor_id] = {}
            if room_id not in user_dungeon.dungeon_repeat_info[d_type][floor_id]:
                user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id] = 0
            user_dungeon.do_put()
    has_played_cnt = user_dungeon.dungeon_repeat_info[d_type][floor_id][room_id]
    can_wipe_out_cnt = can_make_copy_cnt - has_played_cnt
    print can_make_copy_cnt, has_played_cnt 
    # 进入战场次数用完,不能扫荡
    if can_wipe_out_cnt <= 0:
        return 11,{'msg':utils.get_msg('dungeon', 'invalid_limit_dungeon')}
    # 剩余战场次数不够扫荡十次
    if can_wipe_out_cnt < do_times:
        return 11,{'msg':utils.get_msg('dungeon', 'can_not_do_ten_times')}
    # 扫荡战利品
    get_goods = {
        'exp': 0,
        'exp_point': 0,
        'gold': 0,
        'card': {},
        'equip': {},
        'soul':{
            'card': {},
            'equip': {},
        },
        'mat': {},
        'props': {},
    }

    # 扫荡一次能够得到的经验,卡经验点,和钱币
    get_goods['exp'] += room_config.get('exp', 0) * do_times
    get_goods['exp_point'] += room_config.get('exp_point', 0) * do_times
    get_goods['gold'] += room_config.get('gold', 0) * do_times

    # 扫荡能够得到的物品
    drop_info = _pack_drop_info(room_config.get('drop_info', {}))
    invisible_drop = _pack_drop_info(room_config.get('invisible_drop', {}))
    drop_info.extend(invisible_drop)
    # 有掉落物品(包括可见和不可见)时计算掉落, 不用战斗所以不区分可见不可见
    if drop_info: # sample  ['12002_equip', '5_card_soul', '53001_equip_1_soul', '6_card', '23_props', '8_props']
        drop_info = list(set(drop_info))  # list去重
        drop_info_config = game_config.drop_info_config['normal_dungeon']
        # 检查战场掉落配置中是否有此物品
        for goods_id in drop_info:
            print 'goods_id------*--*-*-*-*-*--*-*-*-*-------', goods_id
            if 'soul' in goods_id:
                if goods_id[:-5] not in drop_info_config['soul']:
                    return 11,{'msg':utils.get_msg('dungeon', 'no_this_goods')}
            else:
                if goods_id not in drop_info_config:
                    return 11,{'msg':utils.get_msg('dungeon', 'no_this_goods')}
        # 计算掉落数量
        for n in range(do_times):
            for goods_id in drop_info:
                if 'soul' in goods_id:
                    goods_id = goods_id[:-5]  # 去掉'_soul'后缀
                    value_config = drop_info_config['soul'][goods_id]['visible']
                    # 根据配置概率判断是否得到
                    if utils.is_happen(value_config[1]):
                        num = random.randint(value_config[0][0], value_config[0][1])
                        soul_type = 'card' if 'card' in goods_id else 'equip'
                        if goods_id not in get_goods['soul'][soul_type]:
                            get_goods['soul'][soul_type][goods_id] = num
                        else:
                            get_goods['soul'][soul_type][goods_id] += num
                    else:
                        continue

                else:
                    value_config = drop_info_config[goods_id]['visible']
                    # 根据配置概率判断是否得到
                    if utils.is_happen(value_config[1]):
                        num = random.randint(value_config[0][0], value_config[0][1])
                        for t in ['card', 'equip', 'props', 'mat']:
                            if t in goods_id:
                                get_type = t
                        if goods_id not in get_goods[get_type]:
                            get_goods[get_type][goods_id] = num
                        else:
                            get_goods[get_type][goods_id] += num
                    else:
                        continue
    # 减扫荡券
    user_pack = UserPack.get_instance(uid)
    user_pack.minus_props('24_props', do_times, 'wipe_out')
    # 添加扫荡奖励
    user_property = UserProperty.get_instance(uid)
    tmpdata = user_property.test_give_award(get_goods, where='wipe out')
    user_property.do_put()
    uc = UserCards.get_instance(uid)
    uc.do_put()
    ue = UserEquips.get_instance(uid)
    ue.do_put()
    up = UserPack.get_instance(uid)
    up.do_put()
    us = UserSouls.get_instance(uid)
    us.do_put()
    # 记录repeat info
    user_dungeon.add_repeat_cnt(d_type, floor_id, room_id, do_times)
    user_dungeon.do_put()

    # 给前端
    data['get_exp'] = tmpdata['exp']
    data['get_exp_point'] = tmpdata['exp_point']
    data['get_gold'] = tmpdata['gold']
    data['get_card'] = tmpdata['card']
    data['get_equip'] = tmpdata['equip']
    data['get_souls'] = tmpdata['soul']
    data['get_material'] = tmpdata['mat']
    data['get_props'] = tmpdata['props']

    print data
Example #18
0
def set_decks(rk_user, params):
    """设置编队
    params:
        deck_index:当前编队编号0-9
        new_deck:  武将id:是否是主将 1是 0 否
            ucid:0,ucid:1,ucid:0,,ucid:0_ucid:0,ucid:1,ucid:0,,ucid:0
    """
    #获取参数
    #new_decks = params['new_deck']
    new_deck = params.get('new_deck')
    cur_deck_index = int(params["deck_index"])
    #判断编队是否符合要求
    if cur_deck_index < 0 or cur_deck_index > 4:
        raise GameLogicError('card', 'invalid_deck')
    if new_deck:
        new_decks = new_deck.split('_')
        user_card_obj = UserCards.get_instance(rk_user.uid)

        decks = user_card_obj.decks
        if len(decks) == 5:
            new_decks_lst = [[{}] * 5] * 5
        else:
            raise GameLogicError('card', 'invalid_deck')
        for i, new_deck in enumerate(new_decks):
            new_new_deck = new_deck.split(',')
            #检查队伍长度是否合法
            if len(new_new_deck) == 0:
                continue
            if len(new_new_deck) < game_config.system_config['deck_length']:
                new_new_deck.extend([':0'] *
                                    (game_config.system_config['deck_length'] -
                                     len(new_new_deck)))
                # return 11,{'msg':utils.get_msg('card','invalid_deck')}
            #检查这些武将是否存在
            new_deck_copy = []
            for card_info in new_new_deck:
                card_info_ls = card_info.split(':')
                if card_info_ls:
                    ucid, is_leader = card_info_ls
                else:
                    ucid = ''
                    is_leader = 0
                if ucid and not user_card_obj.has_card(ucid):
                    raise GameLogicError('card', 'no_card')
                #判断升级和强化素材不能上阵
                if ucid:
                    tmp_dict = {'ucid': ucid}
                    if int(is_leader) == 1:
                        tmp_dict['leader'] = 1
                    new_deck_copy.append(tmp_dict)
                else:
                    new_deck_copy.append({})
            #队伍中不能出现重复的ucid和重复的ueid和多个leader
            no_repeat_deck = utils.remove_null(new_deck_copy)
            ucids = [
                card['ucid'] for card in no_repeat_deck
                if card.get('ucid', '')
            ]
            leader_cnt = len([
                card['leader'] for card in no_repeat_deck
                if card.get('leader', 0)
            ])
            if len(ucids) != len(set(ucids)) or leader_cnt != 1:
                raise GameLogicError('card', 'invalid_deck')
            new_decks_lst[i] = copy.deepcopy(new_deck_copy)

        #设置最新队伍
        user_card_obj.set_decks(new_decks_lst)
        #设置当前编队索引
        user_card_obj.set_cur_deck_index(cur_deck_index)

    if params.get('yuanjun_deck'):
        set_yuanjun_decks(rk_user, params)
    return {}
Example #19
0
def advanced_talent(rk_user, params):
    '''
    miaoyichao
    *天赋进阶
    *params : ucid = ucid
    * cost_cards = ucid,ucid,ucid.ucid
    '''
    ucid = params['ucid']
    #获取用户武将对象
    user_card_obj = UserCards.get_instance(rk_user.uid)
    #检查要天赋进阶的武将是否存在
    if not user_card_obj.has_card(ucid):
        return 11, {'msg': utils.get_msg('card', 'no_card')}
    #获取武将的cid
    cid = user_card_obj.cards[ucid]['cid']
    #获取武将的star
    star = str(game_config.card_config[cid].get('star', 4))
    #获取武将的当前天赋等级和最大等级
    cur_talent_lv = user_card_obj.cards[ucid].get('talent_lv', 0)
    max_talent_lv = int(game_config.card_config[cid]['max_talent_lv'])
    #是否已经是最大进阶等级
    if cur_talent_lv >= max_talent_lv:
        return 11, {'msg': utils.get_msg('card', 'max_talent_lv')}
    #取得天赋进阶的配置信息
    advanced_talent_config = game_config.talent_skill_config[
        'advanced_talent_config']
    #获取所需要的进阶丹和card数量
    need_things = advanced_talent_config.get(star,
                                             '4').get(str(cur_talent_lv + 1))
    need_card_num = need_things.get('card', 0)
    if need_card_num:
        #需要消耗其他的武将
        cost_ucids = params['cost_cards'].split(',')
        cost_ucids = utils.remove_null(cost_ucids)
        #检查武将是否存在
        for cost_ucid in cost_ucids:
            #判断是否存在该武将
            if not user_card_obj.has_card(cost_ucid):
                return 11, {'msg': utils.get_msg('card', 'no_card')}
            #判断是否是同名卡牌
            if cid != user_card_obj.cards[cost_ucid]['cid']:
                return 11, {'msg': utils.get_msg('card', 'params_wrong')}
        #带装备武将不允许用于进阶
        if user_card_obj.is_equip_used(cost_ucids):
            return 11, {'msg': utils.get_msg('equip', 'is_used')}
        #被锁定武将不能卖出
        if user_card_obj.is_locked(cost_ucids):
            return 11, {'msg': utils.get_msg('card', 'locked')}
        #有天赋技能的不能用于天赋进阶
        if user_card_obj.has_talent(cost_ucids):
            return 11, {'msg': utils.get_msg('card', 'has_talent_card')}
        #检查武将是否在deck中
        rc, msg = check_card_in_deck(user_card_obj, cost_ucids)
        if rc:
            return rc, {'msg': msg}
        #判断消耗的武将数量是否足够
        if len(cost_ucids) < need_card_num:
            return 11, {'msg': utils.get_msg('card', 'not_enough_card')}
    #这里开始处理道具的逻辑
    props_config = game_config.props_config
    #判断道具是否足够
    user_pack_obj = UserPack.get_instance(rk_user.uid)
    need_props = need_things.get('props', ['8_props', 100])
    props_id = need_props[0]
    #检查道具的类型是否正确
    if props_config.get(props_id, {}).get('used_by', '') != 'talent':
        return 11, {'msg': utils.get_msg('pack', 'wrong_used')}
    #检查道具是否足够
    num = int(need_props[1])
    if not user_pack_obj.is_props_enough(props_id, num):
        return 11, {'msg': utils.get_msg('pack', 'not_enough_item')}
    #检查天赋进阶的金币是否足够
    cost_gold = int(need_things.get('cost_gold', 10000))
    if not rk_user.user_property.is_gold_enough(cost_gold):
        return 11, {'msg': utils.get_msg('user', 'not_enough_gold')}
    #扣用户金钱
    rk_user.user_property.minus_gold(cost_gold, 'advanced_talent')
    #删除道具
    user_pack_obj.minus_props(props_id, num, where='advanced_talent')
    #天赋进阶
    user_card_obj.advanced_talent(ucid)
    if need_card_num:
        #删除武将
        user_card_obj.del_card_info(cost_ucids, where='advanced_talent')
    data = {'new_card_info': {}}
    data['new_card_info']['ucid'] = ucid
    data['new_card_info'].update(user_card_obj.cards[ucid])
    return 0, data
Example #20
0
def stove(rk_user,params):
    """
    熔炼炉
    类似一个回收系统,消耗武将,装备等,来得到相应的资源,资源包括战魂,铜钱,素材,道具等。
    返还的范围包括物品的初始花费和后续花费,比如升级某样物品所花费的铜钱也返还
    """
    #练化类型
    category = params.get('category','')
    data = {}
    rc = 0
    user_property_obj = UserProperty.get_instance(rk_user.uid)
    user_card_obj = UserCards.get_instance(rk_user.uid)
    user_equip_obj = UserEquips.get_instance(rk_user.uid)
    user_pack_obj = UserPack.get_instance(rk_user.uid)
    user_property_obj = UserProperty.get_instance(rk_user.uid)
    #出售逻辑很炼丹炉一样,所以直接调用出售逻辑获得数据结构
    #武将
    if category == 'card':
        rc,msg = card.card_stove(rk_user,params)
        if rc:
            return rc,msg
        #获取武将计算系数                       card_update_config:武将强化
        card_stove_gold_coe = float(game_config.card_update_config['card_stove_gold_coe'])
        card_stove_props_coe = float(game_config.card_update_config['card_stove_props_coe'])
        #取得天赋进阶的配置信息                 talent_skill_config 武将天赋技能
        advanced_talent_config = game_config.talent_skill_config['advanced_talent_config']
        #总计获取的战魂
        fight_soul = 0
        #总计返回的进阶丹  
        return_props = 0
        #返回铜钱
        return_gold = 0
        for card_info in msg['cards_info']:
            cid = card_info['cid']
#           print '#### cid=', cid

            #获取武将的当前天赋等级
            cur_talent_lv = card_info['talent_lv']
#           print '#### cur_talent_lv=', cur_talent_lv

            #获取武将星级            card_config 武将设置
            star = str(game_config.card_config[cid].get('star',4))
#           print '#### card star=', star

            #读取计算战魂系统    card_update_config:武将强化
            stove_card_fight_soul = int(game_config.card_update_config['card_stove_fight_soul'].get(star,1))
            #获取当前经验
            cost_update_gold = card_info['exp']
            #武将炼化基础值
            base_gold = int(game_config.card_update_config['sell_base_gold'].get(star,3000))
            #获取当前进阶所需的配置(武将,铜钱,进阶丹)

            #铜钱计算公式 = 基础数值 + int(当前状态总共消耗铜钱 * 0.8)
            return_gold  += base_gold + int(cost_update_gold * card_stove_gold_coe)
            #战魂计算公式 =(1 + 进阶到当前状态总消耗武将个数)* 系数
            fight_soul  += stove_card_fight_soul

            for talent_lv in range(1, int(cur_talent_lv)+1):
                cur_talent = advanced_talent_config[star].get(str(talent_lv),{})
                cost_talent_gold  = int(cur_talent.get('cost_gold',0))
                cost_talent_card  = int(cur_talent.get('card',0))   #武将
                cost_talent_props = cur_talent.get('props',[]) #进阶丹

                #铜钱计算公式 = 基础数值 + int(当前状态总共消耗铜钱 * 0.8)
                return_gold  += int( cost_talent_gold * card_stove_gold_coe )
                #进阶丹 = int(当前状态总消耗 * 0.8)
                if cost_talent_props:
                    return_props += int(cost_talent_props[1] * card_stove_props_coe)
                #战魂计算公式 =(1 + 进阶到当前状态总消耗武将个数)* 系数
                fight_soul  += int(cost_talent_card * stove_card_fight_soul)

#               print '#### return_gold, return_props, fight_soul=', \
#                       return_gold, return_props, fight_soul

        #添加战魂
        user_property_obj.add_fight_soul(fight_soul, 'stove')
        #返还进阶丹
        user_pack_obj.add_props('8_props',return_props, 'stove')
        #用户删卡
        user_card_obj.del_card_info(msg['cards_ucids'], where='stove')
        #返还铜钱
        user_property_obj.add_gold(return_gold, 'stove')
        data = {'gold':return_gold,'fight_soul':fight_soul,'props':{'8_props':return_props}}

    #普通装备(1:武器(攻击),2:护甲(防御),3:头盔(血量),4:饰品(回复)
    elif category == 'common_equip':
        rc,msg = equip.equip_stove(rk_user,params)
        if rc:
            return rc,msg
        # category check,防止category和装备eid不匹配
        for equip_info in msg['equips_info']:
            eid = equip_info['eid']
            eqtype = game_config.equip_config[eid]['eqtype']
            if eqtype not in [1, 2, 3, 4]:
                return 11,{'msg':utils.get_msg('mystery_store','category_not_match')}
        #获取普通装备计算系数                      equip_exp_conf:装备等级配置
        common_stove_gold_coe = float(game_config.equip_exp_config['common_stove_gold_coe'])
        #返回铜钱
        return_gold = 0
        for equip_info in msg['equips_info']:
            # equip_info 是 UserEquips实例的equips[ueid]字段
            eid = equip_info['eid'] 
            uetype = int(game_config.equip_config[eid]['eqtype'])
            #获取当前等级
            cur_equip_lv = equip_info['cur_lv']
            #获取当前经验(升级到该经验所需铜钱)
            cost_update_gold = equip_info['cur_experience']

            #获取装备的星级
            star = str(game_config.equip_config[eid].get('star',1))
            #普通装备炼化基础值            equip_exp_config:装备等级配置

            base_gold = int(game_config.equip_exp_config['common_base_gold'].get(star,500))
            return_gold += int((base_gold + cost_update_gold) * common_stove_gold_coe)


        #用户删除装备
        user_equip_obj.delete_equip(msg['equips_ueids'], where='stove')
        #返还铜钱
        user_property_obj.add_gold(return_gold, 'stove')

        data = {'gold':return_gold}

    #宝物(5:兵法,6:坐骑)
    elif category == 'treasure_equip':
        rc,msg = equip.equip_stove(rk_user,params)
        if rc:
            return rc,msg
        # category check,防止category和装备eid不匹配
        for equip_info in msg['equips_info']:
            eid = equip_info['eid']
            eqtype = game_config.equip_config[eid]['eqtype']
            if eqtype not in [5, 6]:
                return 11,{'msg':utils.get_msg('mystery_store','category_not_match')}

        #获取宝物计算系数                             装备等级配置
        treasure_stove_gold_coe = float(game_config.equip_exp_config['treasure_stove_gold_coe'])
        #返回铜钱
        return_gold = 0
        #返回道具
        return_props = {}
        #返还的 不同等级的经验马/经验书数量
        num_book4=num_book3=num_book2=num_book1=num_horse4=num_horse3=num_horse2=num_horse1 = 0
        # 不同等级的经验马/经验书提供的经验
        props_conf = game_config.props_config
        equip5_prop_list = []
        equip6_prop_list = []
        for prop_id in props_conf:
            if props_conf[prop_id].get('used_by') == 'equip5':
                equip5_prop_list.append((prop_id, props_conf[prop_id]['exp']))
            elif props_conf[prop_id].get('used_by') == 'equip6':
                equip6_prop_list.append((prop_id, props_conf[prop_id]['exp']))
        equip5_prop_list.sort(reverse=True)
        equip6_prop_list.sort(reverse=True)

        def calculate_rebate(prop_exp_list, all_exp):
            rebate_props = {}
            left_exp = all_exp
            for prop, exp in prop_exp_list:
                rebate_props[prop] = left_exp // exp
                left_exp = left_exp % exp
                if not left_exp:
                    break
            return rebate_props

        for equip_info in msg['equips_info']:
            eid = equip_info['eid']
            #宝物装备升级所消耗铜钱
            cost_update_gold = equip_info['cur_experience'] * treasure_stove_gold_coe
            #获取装备的星级
            star = str(game_config.equip_config[eid].get('star',1))
            #宝物装备炼化基础值
            base_gold = game_config.equip_exp_config['treasure_sell_gold'].get(star,500)
            eqtype = game_config.equip_config[eid]['eqtype']
            #计算返还经验书的数量。经验书有不同等级,分别计算个数。5000 3000 1000 500为相应等级的经验书所提供的经验
            if eqtype == 5:
                return_props.update(calculate_rebate(equip5_prop_list, cost_update_gold))
            #计算返还经验马  逻辑同经验书
            elif eqtype == 6:
                return_props.update(calculate_rebate(equip6_prop_list, cost_update_gold))
            return_gold += int(base_gold + (cost_update_gold * treasure_stove_gold_coe))
        #返还道具
        for props_id in return_props:
            user_pack_obj.add_props(props_id,return_props[props_id], 'stove')
        #用户删除装备
        user_equip_obj.delete_equip(msg['equips_ueids'], where='stove')
        #返还铜钱
        user_property_obj.add_gold(return_gold, where='stove')
        data = {'gold':return_gold,'props':return_props}
    else:
        return 11,{'msg':utils.get_msg('mystery_store','no_stove_category')}

#   print '#### stove_info:', data

    return rc,{'stove_info':data}