Exemplo n.º 1
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
Exemplo n.º 2
0
def refresh_income_info(uid):
    action = FormationAction(uid)
    info = action.get_model_info()
    print(info)
    capacity = info.get(action.capacity_str, 0)
    capacity_update_at = info.get(action.capacity_update_at_str, 0)
    '''
    if info.get(action.fight_state_str) == action.state_injured:
        print('state_injured')
        return False
    '''
    cur_income = info.get(action.income_str, 0)
    cur_time = int(time.time())
    # 每个小时的获取的金币
    per_hour_capacity = capacity / 10.0
    income = int((cur_time - capacity_update_at) / 3600.0 * per_hour_capacity) + cur_income
    # print(capacity, cur_income, per_hour_capacity, income)
    if income == cur_income:
        return False
    res = {
        'income': income,
        'capacity_update_at': cur_time,
    }
    if action.set_values(res):
        print(res)
        return res
    return False
Exemplo n.º 3
0
def get_my_friend_platform_info(uid, fir_list):
    p_action = PlatformAction(uid)
    u_action = UserAction(uid)
    f_action = FormationAction(uid)
    p_info_data = p_action.get_all_by_userlist(fir_list)
    u_info_data = u_action.get_all_by_userlist(fir_list)
    r_info_data = f_action.get_all_by_userlist(fir_list)

    p_dict_info = {}
    for data in p_info_data:
        p_dict_info[data['u_id']] = data
    u_dict_info = {}
    for data in u_info_data:
        u_dict_info[data['u_id']] = data
    r_dict_info = {}
    for data in r_info_data:
        r_dict_info[data['u_id']] = data
    res = dict()
    for f_id in fir_list:
        item = {
            'id': f_id,
            'platform': p_dict_info.get(f_id, False),
            'userInfo': u_dict_info.get(f_id, False),
            'formation': r_dict_info.get(f_id, False),
        }
        if item.get('platform') is False or item.get('userInfo') is False:
            continue
        res[f_id] = item
    return res
Exemplo n.º 4
0
def use_heal(uid, config_info=None):
    formation_action = FormationAction(uid)
    formation_info = formation_action.get_model_info()
    if formation_info.get(formation_action.fight_state_str
                          ) != formation_action.state_injured:
        return False
    res = formation_action.set_normal()
    return {'heal': res}
Exemplo n.º 5
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
    }
Exemplo n.º 6
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
Exemplo n.º 7
0
def check_income(uid):
    action = FormationAction(uid)
    info = action.get_model_info()
    capacity = info.get('capacity', 0)
    capacity_update_at = info.get('capacity_update_at', 0)
    cur_income = info.get('income', 0)
    cur_time = int(time.time())
    # 每个小时的获取的金币
    per_hour_capacity = capacity / 10.0
    income = int((cur_time - capacity_update_at) / 3600.0 * per_hour_capacity) + cur_income
    print (cur_time - capacity_update_at)
    print(capacity, cur_income, per_hour_capacity, income)
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
0
def get_formation_info(uid):
    action = FormationAction(uid)
    return action.get_model_info()
Exemplo n.º 15
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