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 use_normal(uid, config_info=None):
    res = {}
    user = UserAction(uid)
    ct = 1
    user.add_gold(ct)
    res['gold'] = ct
    return res
Esempio n. 3
0
def rob_money(uid, friend_id):
    u_model = UserAction(uid)
    f_doll_model = HeroAction(friend_id)
    # 好友的娃娃列表
    doll_keys = f_doll_model.get_doll_keys()
    # 默认的打劫数量
    default_rob_ct = 3
    # 需要打劫的数量
    rob_ct = min(len(doll_keys), default_rob_ct)
    # 需要打劫的娃娃列表
    doll_part = random.sample(doll_keys, rob_ct)
    gold_award = 0
    res_doll = {}
    for doll_id in doll_part:
        doll = f_doll_model.get_doll_info_by_id(doll_id)
        doll_gold = doll.get('gold', 0)
        gold_award += doll_gold / 5
        doll['gold'] = int(doll_gold * (1 - 1.0 / 5))
        f_doll_model.update_doll_info(doll_id, doll)
        res_doll[doll_id] = doll
    print res_doll
    print type(doll_keys)
    u_model.add_gold(gold_award)

    res = {'gold': gold_award, 'dolls': res_doll}
    return res
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
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
Esempio n. 8
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