Пример #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
Пример #2
0
def set_explore(uid, fight_heroes):
    formation_action = FormationAction(uid)
    check_heroes = [i for i in fight_heroes if i != '']
    # 判断有没有重复英雄
    if len(check_heroes) != len(set(check_heroes)):
        print('is same')
        return False
    hero_action = HeroAction(uid)
    all_hero = hero_action.get_model_info()
    # 有没有根本不存在的英雄
    if len(set(check_heroes) - set(all_hero.keys())) > 0:
        print('is not exist')
        return False
    info = formation_action.get_model_info()
    if len(
            set(check_heroes)
            & set(info.get(formation_action.explore_formation_str))) > 0:
        print('pve hero in fight formation')
        return False
    data = {
        formation_action.explore_formation_str: fight_heroes,
    }
    print(fight_heroes)
    if formation_action.set_model_info(data):
        print(data)
        return data
    return False
Пример #3
0
def get_pve_heroes_info(uid):
    for_action = FormationAction(uid)
    hero_action = HeroAction(uid)
    all_hero = hero_action.get_model_info()
    pve_heroes = for_action.get_explore_model_info()
    return {
        hero_id: hero_info
        for hero_id, hero_info in all_hero.items() if hero_id in pve_heroes
    }
Пример #4
0
def get_inventory_info(uid):
    item_action = ItemAction(uid)
    hero_action = HeroAction(uid)
    book_action = HandBookAction(uid)

    return {
        'items': item_action.get_all(),
        'dolls': hero_action.get_model_info(),
        'book': book_action.get_model_info(),
    }
Пример #5
0
def enter_friend_home(uid, f_id):
    island_logic.refresh_income_info(f_id)
    # 需要记录谁进来了
    hero_action = HeroAction(f_id)
    f_action = FormationAction(f_id)
    res = {
        'id': f_id,
        'heroes': hero_action.get_model_info(),
        'formation': f_action.get_model_info(),
    }
    return res
Пример #6
0
def grab_egg(uid, key_id, eggs):
    mach_action = MachineAction(uid)
    egg = mach_action.get_egg_info(key_id)
    eggs = eggs.encode('utf-8')
    eggs = eval(eggs)
    if egg is False:
        print("egg  is not exits")
        return False
    item_id = egg.get('id', False)
    if item_id is False:
        return False
    '''如果是新手的话 必出娃娃'''
    hero_action = HeroAction(uid)
    cur_hero_keys = hero_action.get_doll_keys()
    if len(cur_hero_keys) == 0:
        res = dict()
        a_id = 40001
        res['doll'] = hero_action.add_model(a_id)
        record_logic.add_record(uid, 'get_hero', 1)
        return res
    '''新手判定结束'''
    config = ConfigModel('egg').get_config_by_id(item_id)
    print(config)
    # 需要一个判定 如果是新手 直接给一个固定的娃娃
    if config['lv'] < 2:
        if mach_action.delete_egg(key_id):
            res = open_egg(uid, item_id)
        else:
            return False
    else:
        print('is hatch')
        hatch_action = HatchAction(uid)
        available_hatch = hatch_action.get_hatch_available()
        if available_hatch is None:
            return False
        elif mach_action.delete_egg(key_id):
            res = {
                'hatch':
                hatch_action.add_model_index(item_id, available_hatch['pos'])
            }
        else:
            return False
    # 更新保存蛋的位置
    note_model = NoteModel(uid)
    mach_id = note_model.get_cur_machine()
    cur_eggs_keys = mach_action.get_egg_group(mach_id)
    values = {
        k: v
        for k, v in eggs.items() if k in cur_eggs_keys and k != key_id
    }
    mach_action.add_egg_list(values)
    res['update_exp'] = user_logic.add_exp(uid, 1)
    return res
Пример #7
0
def set_fight(uid, fight_heroes):
    formation_action = FormationAction(uid)
    check_heroes = [i for i in fight_heroes if i != '']
    # 判断有没有重复英雄
    if len(check_heroes) != len(set(check_heroes)):
        print('is same')
        return False
    hero_action = HeroAction(uid)
    all_hero = hero_action.get_model_info()
    # 有没有根本不存在的英雄
    if len(set(check_heroes) - set(all_hero.keys())) > 0:
        print('is not exist')
        return False
    # 读取英雄属性配置信息
    hero_config = ConfigModel('doll')
    hero_upgrade_config = ConfigModel('doll_upgrade')
    # 计算战斗力
    all_atk = 0
    all_capacity = 0
    normal_fight_per = 0.1
    fight_per = 0.9
    for hero_id, hero_info in all_hero.iteritems():
        cur_hero_config = hero_config.get_config_by_id(hero_id)
        cur_lv_config = hero_upgrade_config.get_config_by_id(
            70000 + int(hero_info['lv']))
        if int(cur_hero_config['category']
               ) != formation_action.fight_type and hero_id in check_heroes:
            print('is not fight hero', hero_id)
            return False
        base_atk = int(cur_hero_config['atk'])
        base_capacity = int(cur_hero_config['capacity'])
        atk_add_per = int(cur_lv_config['add_atk'])
        capacity_add_per = int(cur_lv_config['add_capacity'])
        hero_atk = base_atk * atk_add_per
        hero_capacity = base_capacity * capacity_add_per
        if hero_id in fight_heroes:
            all_atk += hero_atk * fight_per
        else:
            all_atk += hero_atk * normal_fight_per
            all_capacity += hero_capacity
    info = formation_action.get_model_info()
    cur_income = info.get(formation_action.income_str)
    data = {
        formation_action.fight_formation_str: fight_heroes,
        formation_action.fight_atk_str: all_atk,
        formation_action.capacity_str: all_capacity,
    }
    print(fight_heroes)
    if formation_action.set_model_info(data):
        print(data)
        return data
    return False
Пример #8
0
def eat_atk(uid, heroes_group, atk):
    hero_action = HeroAction(uid)
    heroes_info = hero_action.get_model_info()
    check_hero_group = [
        hero for hero_id, hero in heroes_info.items()
        if hero_id in heroes_group and hero.get('hp', -1) > 0
    ]
    hero_ct = len(check_hero_group)
    if hero_ct == 0:
        return False
    share_atk = math.floor(float(atk) / hero_ct)
    print hero_ct, share_atk
    for hero in check_hero_group:
        hero_action.injure_doll_hp(hero.get(hero_action.doll_id_str, 0),
                                   share_atk)
    return check_hero_group
Пример #9
0
def get_pve_atk(uid):
    for_action = FormationAction(uid)
    hero_action = HeroAction(uid)
    all_hero = hero_action.get_model_info()
    pve_heroes = for_action.get_explore_model_info()
    heroes = {
        hero_id: hero_info
        for hero_id, hero_info in all_hero.items() if hero_id in pve_heroes
    }
    hero_config = ConfigModel('doll')
    hero_upgrade_config = ConfigModel('doll_upgrade')
    all_atk = 0
    for hero_id, hero_info in heroes.iteritems():
        cur_hero_config = hero_config.get_config_by_id(hero_id)
        cur_lv_config = hero_upgrade_config.get_config_by_id(
            70000 + int(hero_info['lv']))
        base_atk = int(cur_hero_config['atk'])
        atk_add_per = float(cur_lv_config['add_atk'])
        hero_atk = base_atk * atk_add_per
        all_atk += hero_atk
    return all_atk
Пример #10
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
Пример #11
0
def refresh_lock(uid, machine_id):
    config_model = ConfigModel('machine')
    next_book_id = machine_id + 1
    book = HandBookAction(uid)
    if book.has_key(next_book_id):
        return False
    # 判定当前关卡是否完成
    front_config = config_model.get_config_by_id(machine_id)
    if front_config:
        config_doll_group = front_config.get('itemGroup', False)
        config_exp = front_config.get('exp', 0)
        cur_exp = book.get_book_exp(machine_id)
        config_doll_group = config_doll_group.split(',')
        config_dolls = [str(i) for i in config_doll_group]
        doll_model = HeroAction(uid)
        my_doll_group = doll_model.get_doll_group()
        config_doll_group = set(config_dolls)
        # my_doll_group >= config_doll_group
        if my_doll_group.issuperset(
                config_doll_group) and cur_exp > config_exp:
            if book.unlock_book(next_book_id):
                return next_book_id
    return False
Пример #12
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
Пример #13
0
def rob_doll(uid, friend_id):
    u_doll_model = HeroAction(uid)
    f_doll_model = HeroAction(friend_id)
    # 好友的娃娃列表
    doll_keys = f_doll_model.get_doll_keys()
    # 默认的打劫数量
    default_rob_ct = 1
    # 需要打劫的数量
    rob_ct = min(len(doll_keys), default_rob_ct)
    # 需要打劫的娃娃列表
    doll_part = random.sample(doll_keys, rob_ct)
    doll_award = dict()
    res_doll = dict()
    for doll_id in doll_part:
        doll = f_doll_model.get_doll_info_by_id(doll_id)
        f_doll_model.reduce_model(doll_id)
        # 如果我有这个娃娃 增加经验
        if u_doll_model.has_key(doll_id):
            doll_award[doll_id] = u_doll_model.add_doll_exp(
                doll_id, doll['exp'])
        # 如果我没有这个娃娃 增加一个
        else:
            doll_award[doll_id] = u_doll_model.add_model(doll_id)
        res_doll[doll_id] = doll
    res = {'dolls': res_doll, 'award': doll_award}
    return res
Пример #14
0
def interact_doll(uid, hero_id):
    action = HeroAction(uid)
    res = action.interact_doll(hero_id)
    return res