Esempio n. 1
0
def use_box(uid, config_info):
    # 奖励
    awards = get_award(config_info)
    item_model = ItemAction(uid)
    doll_model = HeroAction(uid)
    hatch_action = HatchAction(uid)
    user = UserAction(uid)
    res = dict()
    for a_id, ct in awards.iteritems():
        # 如果是金币添加金币
        if a_id == "gold":
            user.add_gold(ct)
            res[a_id] = ct
        # 如果是钻石添加钻石
        elif a_id == "diamond":
            user.add_diamond(ct)
            res[a_id] = ct
        # 经验
        elif a_id == "exp":
            user.add_gold(ct)
            res[a_id] = ct
        # 如果是道具添加道具
        elif int(a_id) / 10000 == 2:
            if item_model.add_model(a_id, ct):
                res[a_id] = ct
        elif int(a_id) / 10000 == 3:
            hatch_action.add_model(a_id)
        elif int(a_id) / 10000 == 4:
            res['doll'] = doll_model.add_model(a_id)
        else:
            pass
    return res
Esempio n. 2
0
def open_egg(uid, egg_id):
    print('open_egg', egg_id)
    # 奖励
    awards = get_award(egg_id)
    item_action = ItemAction(uid)
    hero_action = HeroAction(uid)
    book_action = HandBookAction(uid)
    user_action = UserAction(uid)
    res = dict()
    for a_id, ct in awards.iteritems():
        # 如果是金币添加金币
        if a_id == "gold":
            user_action.add_gold(ct)
            res[a_id] = ct
        # 如果是钻石添加钻石
        elif a_id == "diamond":
            user_action.add_diamond(ct)
            res[a_id] = ct
        # 经验
        elif a_id == "exp":
            user_action.add_gold(ct)
            res[a_id] = ct
        # 如果是道具添加道具
        elif int(a_id) / 10000 == 2:
            item_action.add_model(a_id, ct)
        elif int(a_id) / 10000 == 4:
            if hero_action.get_doll_exist(a_id) is False:
                res['doll'] = hero_action.add_model(a_id)
                record_logic.add_record(uid, 'get_hero', 1)
            else:
                cur_hero = hero_action.get_doll_info_by_id(a_id)
                hero_config_model = ConfigModel('doll_upgrade')
                cur_lv_config = hero_config_model.get_config_by_id(
                    70000 + cur_hero['lv'])
                max_exp = cur_lv_config['exp']
                max_lv = 5
                add_exp = 1
                # 新的经验值
                exp = cur_hero['exp'] + add_exp
                if exp >= max_exp:
                    if cur_hero['lv'] < max_lv:
                        cur_hero['lv'] += 1
                        cur_hero['exp'] = exp - max_exp
                        hero_action.set_value(a_id, cur_hero)
                        res['hero_lv_up'] = True
                    else:
                        res['hero_lv_up'] = False
                        # 满级了
                        if cur_hero['exp'] < max_exp:
                            cur_hero['exp'] = max_exp
                            hero_action.set_value(a_id, cur_hero)
                        else:
                            # 经验槽也满了已经
                            add_exp = 0
                else:
                    cur_hero['exp'] = exp
                    hero_action.set_value(a_id, cur_hero)
                    res['hero_lv_up'] = False
                # 如果已经有这个英雄了 就发金币吧
                # user_action.add_gold(10)
                # res['gold'] = 10
                cur_hero['add_exp'] = add_exp
                res['doll'] = cur_hero
                res['hero_exist'] = a_id
        else:
            pass
    # 图鉴加经验
    note_model = NoteModel(uid)
    res['book_exp'] = book_action.add_book_exp(note_model.get_cur_machine(), 1)
    unlock_next_book = book_logic.refresh_lock(uid,
                                               note_model.get_cur_machine())
    if unlock_next_book:
        res['egg'] = reset_machine_egg_info(uid, unlock_next_book)
    return res