예제 #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
예제 #2
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
예제 #3
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