Exemple #1
0
def guild_catch(uid):
    award = dict()
    res = dict()
    gold = 100
    user_action = UserAction(uid)
    user_action.add_gold(gold)
    award['gold'] = gold
    res['award'] = award
    res['result'] = True
    record_logic.add_record(uid, 'rob', 1)
    return res
Exemple #2
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
Exemple #3
0
def get_list_info(data):
    res = list()
    for f_id in data:
        p_model = PlatformAction(f_id)
        u_model = UserAction(f_id)
        f_action = FormationAction(f_id)
        item = {
            'id': f_id,
            'platform': p_model.get_private_info(),
            'userInfo': u_model.get_private_info(),
            'formation': f_action.get_private_info(),
        }
        res.append(item)
    # res = sorted(res, key=lambda x: x['gold'], reverse=True)
    return res
Exemple #4
0
def award_income(uid):
    f_action = FormationAction(uid)
    u_action = UserAction(uid)
    income = f_action.get_income()
    res = dict()
    award = {}
    if f_action.set_income(0):
        if u_action.add_gold(income):
            award['gold'] = income
        else:
            print('is db error')
    else:
        award['gold'] = 0
    res['award'] = award
    return res
Exemple #5
0
def try_five_times(uid):
    gold_cost = 500
    u_action = UserAction(uid)
    if u_action.reduce_gold(gold_cost) is False:
        return False
    turntable_config_model = ConfigModel('turntable')
    turntable_config_info = turntable_config_model.get_model_info()
    random_list = []
    for key, value in turntable_config_info.items():
        random_list.extend([key] * value['chance'])
    selected_keys = random.sample(random_list, 5)
    awards = [{turntable_config_info[selected_key]['item_id']: int(turntable_config_info[selected_key]['ct'])} for selected_key in selected_keys]
    all_awards = union_dict(awards)
    res = {
        'selected': selected_keys,
        'award': inventory_logic.add_awards(uid, all_awards),
    }
    return res
Exemple #6
0
def try_once(uid):
    gold_cost = 100
    u_action = UserAction(uid)
    if u_action.reduce_gold(gold_cost) is False:
        return False
    turntable_config_model = ConfigModel('turntable')
    turntable_config_info = turntable_config_model.get_model_info()
    random_list = []
    for key, value in turntable_config_info.items():
        random_list.extend([key] * value['chance'])
    selected_key = random.choice(random_list)
    selected_info = turntable_config_info[selected_key]
    print(selected_info)
    award = {selected_info['item_id']: int(selected_info['ct'])}
    res = {
        'selected': [selected_info['config_id']],
        'award': inventory_logic.add_awards(uid, award),
    }
    return res
Exemple #7
0
def get_my_friend_info(uid):
    action = FriendAction(uid)
    data = action.get_model_info()
    res = list()
    for f_id in data:
        p_model = PlatformAction(f_id)
        u_model = UserAction(f_id)
        f_action = FormationAction(f_id)
        p_model_info = p_model.get_private_info()
        item = {
            'id': f_id,
            'name': p_model_info['nickname'],
            'figureurl': p_model_info['figureurl'],
            'lv': u_model.get_value('lv'),
            'gold': u_model.get_gold(),
            'income': f_action.get_income(),
        }
        res.append(item)
    res = sorted(res, key=lambda x: x['gold'], reverse=True)
    return res
Exemple #8
0
def start_grab(uid, key_id):
    mach_action = MachineAction(uid)
    egg = mach_action.get_egg_info(key_id)
    if egg is False:
        print("egg  is not exits")
        return False
    item_id = egg.get('id', False)
    if item_id is False:
        return False
    user_action = UserAction(uid)
    vit = user_action.get_vit()
    vit_cost = 1
    if vit < vit_cost or user_action.reduce_vit(vit_cost) is False:
        return False
    config = ConfigModel('egg').get_config_by_id(item_id)
    probability = int(config['lv']) / 100
    rand = random.random()
    res = dict()
    res['res'] = True if rand <= probability else False
    note_model = NoteModel(uid)
    note_model.set_value(key_id, res['res'])
    return res
Exemple #9
0
def open_egg_by_cost(uid, index):
    action = HatchAction(uid)
    data = action.get_model_info_by_index(index)
    egg_id = data['key_id']
    egg_config_model = ConfigModel('egg')
    cur_egg_config = egg_config_model.get_config_by_id(egg_id)
    if cur_egg_config is False:
        return False
    open_type = cur_egg_config.get('open_type')
    open_cost = cur_egg_config.get('open_cost')
    print(open_type, open_cost)
    user_action = UserAction(uid)
    if open_type == 'gold':
        check_cost = user_action.reduce_gold(open_cost)
    else:
        check_cost = user_action.reduce_diamond(open_cost)
    if check_cost is False:
        return False
    action = HatchAction(uid)
    if action.remove_model(index):
        return machine_logic.open_egg(uid, egg_id)
    else:
        return False
Exemple #10
0
def buy_vit(uid):
    add_ct = 10
    u = UserAction(uid)
    user_info = u.get_model_info()
    re_action = RecordAction(uid)
    record_info = re_action.get_model_info()
    cur_buy_ct = record_info.get(re_action.buy_vit_str, 0)
    price = 10
    cost = 2**cur_buy_ct * price
    cur_diamond = user_info.get(u.diamond_str, 0)
    if cur_diamond < cost:
        print (uid, u.diamond_str, 'not enough', cur_diamond, cost, cur_buy_ct)
        return False
    data = {
        u.diamond_str: cur_diamond - cost,
        u.vit_str: user_info.get(u.vit_str, 0) + add_ct
    }
    # 记录次数
    re_action.update_model_info({re_action.buy_vit_str: cur_buy_ct+1})
    res = {}
    if u.set_values(data):
        res['award'] = {'vit': add_ct}
    return res
Exemple #11
0
def catch(uid, opponent):
    if opponent == 'VIP':
        return guild_catch(uid)
    award = dict()
    res = dict()
    opponent_formation = FormationAction(opponent)
    user_action = UserAction(uid)
    opponent_formation_info = opponent_formation.get_model_info()
    cur_income = opponent_formation_info.get(opponent_formation.income_str, 0)
    catch_ct = opponent_formation_info.get(opponent_formation.catch_ct_str, 0)
    catch_refresh_time = opponent_formation_info.get(
        opponent_formation.catch_refresh_time_str, 0)
    cur_time = int(time.time())
    catch_cd = 600
    if cur_time < catch_refresh_time + catch_cd:
        # 时间不到需要等待
        return False
    update_data = dict()
    update_data[opponent_formation.catch_refresh_time_str] = cur_time
    update_data[opponent_formation.catch_ct_str] = catch_ct + 1
    gold = int(cur_income / 10)
    update_data[opponent_formation.income_str] = cur_income - gold
    if opponent_formation.set_model_info(update_data):
        user_action.add_gold(gold)
        print('gold', gold)
        award['gold'] = gold
        res['update'] = update_data
        result = True
        record_logic.add_record(uid, 'rob', 1)
        mail_action = MailAction(opponent)
        mail_action.add_fight_message(uid)
    else:
        result = False
    res['award'] = award
    res['result'] = result
    return res
Exemple #12
0
def buy(uid, shop_id):
    print('buy', uid, shop_id)
    user_action = UserAction(uid)
    item_action = ItemAction(uid)
    shop_config_model = ConfigModel('shop')
    shop_info = shop_config_model.get_config_by_id(shop_id)
    item_config_model = ConfigModel('item')
    item_info = item_config_model.get_config_by_id(shop_info.get('item_id'))
    print shop_info
    price = shop_info.get('price', 10000)
    if shop_info.get(
            'method',
            'gold') == 'gold' and price >= user_action.get_value('gold', 0):
        return False
    else:
        user_action.reduce_gold(price)
    if shop_info.get('method') == 'diamond' and price >= user_action.get_value(
            'diamond', 0):
        return False
    else:
        user_action.reduce_diamond(price)
    print(item_info)
    item_action.add_model(item_info.get('config_id'), 1)
    return True
Exemple #13
0
def set_userinfo(uid, data):
    u = UserAction(uid)
    u.set_values(data)
    return u
Exemple #14
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
Exemple #15
0
def add_awards(uid, data):
    u = UserAction(uid)
    for item, ct in data:
        u.incr(item, ct)
    return True
Exemple #16
0
def get_user_info(uid):
    u = UserAction(uid)
    return u.get_model_info()
Exemple #17
0
def fight_against(uid, opponent):
    if opponent == 'VIP':
        return guild_attack(uid)
    res = dict()
    r_action = RecordAction(uid)
    r_data = r_action.get_model_info()
    fight_data = r_data.get(r_action.fight_group_str, [])
    if fight_data is None:
        fight_data = []
    if opponent in fight_data:
        res['isCD'] = True
        return res
    my_formation = FormationAction(uid)
    my_formation_info = my_formation.get_model_info()
    opponent_formation = FormationAction(opponent)
    opponent_info = opponent_formation.get_model_info()
    my_atk = my_formation_info.get(opponent_formation.fight_atk_str, 0)
    opponent_atk = opponent_info.get(opponent_formation.fight_atk_str, 10000)
    my_art_info = artifact_logic.get_artifact_akt(uid)
    opponent_art_info = artifact_logic.get_artifact_akt(opponent)
    res['my_atk'] = my_atk + my_art_info.get('atk', 0)
    res['opponent_atk'] = opponent_atk + opponent_art_info.get('atk', 0)
    my_fight_heroes = my_formation_info.get(my_formation.fight_formation_str)
    my_fight_heroes_group = [i for i in my_fight_heroes if i != '']

    eat_hero_update = eat_atk(uid, my_fight_heroes_group, res['opponent_atk'])
    if eat_hero_update is False:
        # 我受伤了已经
        res['error'] = True
        res['update'] = my_formation_info
    else:
        user_action = UserAction(uid)
        # 体力的扣除
        cur_vit = user_action.get_vit()
        cost_vit = 1
        if cur_vit < cost_vit:
            return False
        if user_action.reduce_vit(cost_vit) is False:
            return False
        award_success_gold = 10
        award_fail_gold = 2
        award = dict()
        award_success_items = [
            20010, 20011, 20012, 20013, 20014, 20015, 20016, 20017, 20018,
            20019
        ]
        item_action = ItemAction(uid)
        if my_atk > opponent_atk:
            result = True
            opponent_formation.set_injured()
            award_item = random.choice(award_success_items)
            award_item_ct = 1
            if item_action.add_model(award_item, award_item_ct):
                award[award_item] = award_item_ct
            if user_action.add_gold(award_success_gold):
                award['gold'] = award_success_gold
        else:
            result = False
            my_formation.set_injured()
            if user_action.add_gold(award_fail_gold):
                award['gold'] = award_fail_gold
        res['award'] = award
        res['result'] = result
        res['update'] = eat_hero_update
        update_data = {
            r_action.fight_group_str: fight_data,
            r_action.fight_str: r_data.get(r_action.fight_str, 0) + 1
        }
        record_logic.add_fight_record(uid, update_data)
    return res
Exemple #18
0
def refresh_vit(uid):
    u = UserAction(uid)
    if u.get_vit() < u.max_vit_value:
        u.reset_vit()