Beispiel #1
0
def get_invade_award(ubase, last_login_time):
    uinvade = ubase.user_invade
    td = datetime.datetime.today()
    # 平日发普通奖励,第七天发终极奖励 并重置城战
    sevent_day = ubase._common_config['invade_seventh_weekday']

    # 和上次登入是否同一周 若不是 重置
    if total_isoweek(stamp=last_login_time,
                     start=sevent_day) != (total_isoweek(start=sevent_day)):
        #if not datetime.datetime.strptime(ubase.last_login_date,
        #    "%Y-%m-%d").strftime("%W") == td.strftime("%W"):
        uinvade.reset_invade()

    is_seventh_day = td.isoweekday() == sevent_day
    invadeaward_config = ubase._invadeaward_config
    cup_rank = str(ubase.user_invade.cup_rank)
    if is_seventh_day:
        award = invadeaward_config['seventh_award'].get(cup_rank, {})
        uinvade.reset_invade()
    else:
        award = invadeaward_config['normal_award'].get(cup_rank, {})
    if not award:
        return {}
    add_user_awards(ubase, award, 'login_invade')
    language = ubase._language_config['award_msg']['invade']
    return {
        'type': 'invade',
        'award': award,
        'content1': language['content1'],
        "title": language['title'],
    }
Beispiel #2
0
def get_pvp_award(ubase, last_login_time):
    upvp = ubase.user_pvp
    td = datetime.datetime.today()
    # 每双周结算奖励
    award_day = ubase._common_config['pvp_award_weekday']
    # 和上次登入是否同一双周 若不是 重置
    last_day = datetime.date.fromtimestamp(last_login_time)
    last_week = total_isoweek(stamp=last_login_time, start=award_day)
    this_week = total_isoweek(start=award_day)
    # 此周为双周 且为发放奖励的日子
    is_award_day = this_week % 2 == 1 and td.isoweekday() == award_day
    if not is_award_day:
        return {}
    # 先发奖 再变动段位
    pvpaward_config = ubase._pvpaward_config
    pvp_grade = str(upvp.grade)
    award = pvpaward_config.get(pvp_grade, {})
    # 超过一个双周重置一次
    if (this_week / 2) - (last_week / 2) == 1:
        upvp.reset_pvp()
    # 超过二个双周重置两次成初始
    elif (this_week / 2) - (last_week / 2) >= 2:
        upvp.reset_pvp()
        upvp.reset_pvp()
    if not award:
        return {}
    add_user_awards(ubase, award, 'login_pvp')
    language = ubase._language_config['award_msg']['pvp']
    return {
        'type': 'pvp',
        'award': award,
        'content1': language['content1'],
        'content2': language['content2'] % upvp.grade,
        "title": language['title'],
    }
Beispiel #3
0
def get_pvp_award(ubase, last_login_time):
    upvp = ubase.user_pvp
    td = datetime.datetime.today()
    # 每双周结算奖励
    award_day = ubase._common_config['pvp_award_weekday']
    # 和上次登入是否同一双周 若不是 重置
    last_day = datetime.date.fromtimestamp(last_login_time)
    last_week = total_isoweek(stamp=last_login_time, start=award_day)
    this_week = total_isoweek(start=award_day)
    # 此周为双周 且为发放奖励的日子
    is_award_day = this_week % 2 == 1 and td.isoweekday() == award_day 
    if not is_award_day:
        return {}
    # 先发奖 再变动段位 
    pvpaward_config = ubase._pvpaward_config
    pvp_grade = str(upvp.grade)
    award = pvpaward_config.get(pvp_grade, {})
    # 超过一个双周重置一次
    if (this_week / 2) - (last_week / 2) == 1:
        upvp.reset_pvp()
    # 超过二个双周重置两次成初始
    elif (this_week / 2) - (last_week / 2) >= 2:
        upvp.reset_pvp()
        upvp.reset_pvp()
    if not award:
        return {}
    add_user_awards(ubase, award, 'login_pvp')
    language = ubase._language_config['award_msg']['pvp']
    return {'type': 'pvp',
            'award': award,
            'content1': language['content1'],
            'content2': language['content2'] % upvp.grade,
            "title": language['title'],
            
    }
Beispiel #4
0
def api_end_fight(win):
    """ api/arena/end_fight
    战斗胜利
    Argv:
        win(bool): 是否胜利
    """ 
    uarena = request.user.user_arena
    full_exp = uarena._common_config['arena_fight_exp']
    if win:
        umodified = uarena.user_modified
        if 'dungeon' not in umodified.temp:
            raise LogicError('Should start fight first')
        start_info = umodified.temp['dungeon']
        if start_info.get('type') != 'arena':
            raise LogicError('End the wrong fight')
        now = int(time.time())
        if now - start_info['time'] <= 1:
            raise LogicError("rush a dungeon to quick")
        uarena.inc_win()
        add_exp = full_exp
    else:
        add_exp = full_exp // 3
    award = {'exp': add_exp} 
    tools.add_user_awards(uarena, award, 'arena')
    uarena.check_over()
    return {'award': award}
Beispiel #5
0
def api_end_fight(win):
    """ api/arena/end_fight
    战斗胜利
    Argv:
        win(bool): 是否胜利
    """
    uarena = request.user.user_arena
    full_exp = uarena._common_config['arena_fight_exp']
    if win:
        umodified = uarena.user_modified
        if 'dungeon' not in umodified.temp:
            raise LogicError('Should start fight first')
        start_info = umodified.temp['dungeon']
        if start_info.get('type') != 'arena':
            raise LogicError('End the wrong fight')
        now = int(time.time())
        if now - start_info['time'] <= 1:
            raise LogicError("rush a dungeon to quick")
        uarena.inc_win()
        add_exp = full_exp
    else:
        add_exp = full_exp // 3
    award = {'exp': add_exp}
    tools.add_user_awards(uarena, award, 'arena')
    uarena.check_over()
    return {'award': award}
Beispiel #6
0
def api_get_award(task_id):
    """ api/task/get_award
    领取任务奖励
    Args:
        task_id(str): 任务代号
    """
    utask= request.user.user_task
    main_task_conf = utask._task_config['main_task']
    print "debug guochen", utask.has_task(task_id), task_id in main_task_conf
    if not utask.has_task(task_id) or task_id not in main_task_conf:
        return {}
    print "debug gucohen", utask.main_task[task_id]['completed']
    if not utask.main_task[task_id]['completed']:
        return {}
    now_step = utask.main_task[task_id]['step']
    award = main_task_conf[task_id]['award'][now_step]
    next_step = str(int(now_step) + 1)
    if next_step in main_task_conf[task_id]['value']:
        utask.set_completed(task_id, completed=False)
        utask.set_step(task_id, next_step)
        set_value(utask, task_id, utask.main_task[task_id]['now_value'])
    else:
        utask.del_main_task(task_id)
    tools.add_user_awards(utask, award, 'task')
    return api_info()
Beispiel #7
0
def get_invade_award(ubase, last_login_time):
    uinvade = ubase.user_invade
    td =  datetime.datetime.today() 
    # 平日发普通奖励,第七天发终极奖励 并重置城战
    sevent_day = ubase._common_config['invade_seventh_weekday']
    
    # 和上次登入是否同一周 若不是 重置
    if total_isoweek(stamp=last_login_time, start=sevent_day) != (
        total_isoweek(start=sevent_day)): 
    #if not datetime.datetime.strptime(ubase.last_login_date,
    #    "%Y-%m-%d").strftime("%W") == td.strftime("%W"):
        uinvade.reset_invade()
        
    is_seventh_day = td.isoweekday() == sevent_day 
    invadeaward_config = ubase._invadeaward_config
    cup_rank = str(ubase.user_invade.cup_rank)
    if is_seventh_day:
        award = invadeaward_config['seventh_award'].get(cup_rank, {})
        uinvade.reset_invade()
    else:
        award = invadeaward_config['normal_award'].get(cup_rank, {})
    if not award:
        return {} 
    add_user_awards(ubase, award, 'login_invade')
    language = ubase._language_config['award_msg']['invade']
    return {'type': 'invade',
            'award': award,
            'content1': language['content1'],
            "title": language['title'],
    }
Beispiel #8
0
def api_get_award(task_id):
    """ api/task/get_award
    领取任务奖励
    Args:
        task_id(str): 任务代号
    """
    utask = request.user.user_task
    main_task_conf = utask._task_config['main_task']
    print "debug guochen", utask.has_task(task_id), task_id in main_task_conf
    if not utask.has_task(task_id) or task_id not in main_task_conf:
        return {}
    print "debug gucohen", utask.main_task[task_id]['completed']
    if not utask.main_task[task_id]['completed']:
        return {}
    now_step = utask.main_task[task_id]['step']
    award = main_task_conf[task_id]['award'][now_step]
    next_step = str(int(now_step) + 1)
    if next_step in main_task_conf[task_id]['value']:
        utask.set_completed(task_id, completed=False)
        utask.set_step(task_id, next_step)
        set_value(utask, task_id, utask.main_task[task_id]['now_value'])
    else:
        utask.del_main_task(task_id)
    tools.add_user_awards(utask, award, 'task')
    return api_info()
Beispiel #9
0
def get_capital_award(ubase):
    """ 主城进贡金币 """
    # 没有主城没有进贡
    if not ubase.user_cities.capital_city:
        return {} 
    lv_conf = ubase._userlv_config[str(ubase.user_property.lv)]
    award = {}
    award['coin'] = lv_conf['reward_coin']
    add_user_awards(ubase, award, 'login_capital')
    language = ubase._language_config['award_msg']['capital']
    return {'type':  'captial',
            'award': award,
            'content1': language['content1'],
            "title": language['title'],
    }
Beispiel #10
0
def get_capital_award(ubase):
    """ 主城进贡金币 """
    # 没有主城没有进贡
    if not ubase.user_cities.capital_city:
        return {}
    lv_conf = ubase._userlv_config[str(ubase.user_property.lv)]
    award = {}
    award['coin'] = lv_conf['reward_coin']
    add_user_awards(ubase, award, 'login_capital')
    language = ubase._language_config['award_msg']['capital']
    return {
        'type': 'captial',
        'award': award,
        'content1': language['content1'],
        "title": language['title'],
    }
Beispiel #11
0
def api_get_city_award():
    """ api/city/get_city_award 
    领取城市进贡
    """
    ucities = request.user.user_cities
    award = ucities.city_award
    tools.add_user_awards(ucities, award, 'city_award')
    language = ubase._language_config['award_msg']['city']
    now = datetime.datetime.now()
    return {'type': 'city',
            'award': award,
            'content1': language['content1'],
            'content2': language['content2'] % (60 - now.minute),
            "title": language['title'],
            
    }
Beispiel #12
0
def api_invade_shopping(index):
    """ api/shop/invade_shopping
    购买城战商品,消耗城战代币 
    Args:
        index(str): 商品序号
    """
    uinvade = request.user.user_invade
    invadeshop_config = uinvade._invadeshop_config
    if index not in invadeshop_config:
        return {}
    shop = invadeshop_config[index]
    # 消耗城战代币
    tools.del_user_things(uinvade, 'invade_jeton', shop['cost_invade_jeton'],
                          'invade_shopping')
    # 添加奖励
    tools.add_user_awards(uinvade, shop['award'], 'invade_shopping')
    return {}
Beispiel #13
0
def api_shopping(shop_type, index):
    """ api/shop/shopping
    商城购买,消耗钻石 
    Args:
        shop_type(str): 商品类型 【item, package】
        index(str): 商品序号
    """
    umodified = request.user.user_modified
    shop_config = umodified._shop_config
    if shop_type not in shop_config or index not in shop_config[shop_type]:
        return {}
    # 判断购买次数是否超过
    conf = shop_config[shop_type][index]
    limit_type = ''
    for limit in ['daily_limit_cnt', 'forever_limit_cnt']:
        if limit in conf:
            limit_type = limit
    if limit_type:
        limit_cnt = conf.get(limit_type)
        purchased = umodified.temp.get('shop', {}).get(limit_type[:-4], {})
        if limit_cnt <= purchased.get(shop_type, {}).get(index, 0):
            return {}
        else:
            umodified.temp.setdefault('shop', {})
            umodified.temp['shop'].setdefault(limit_type[:-4], {})
            umodified.temp['shop'][limit_type[:-4]].setdefault(shop_type, {})
            umodified.temp['shop'][limit_type[:-4]][shop_type].setdefault(
                index, 0)
            umodified.temp['shop'][limit_type[:-4]][shop_type][index] += 1
    # 判断限购
    if 'start_sale_time' in conf and 'end_sale_time' in conf:
        now_str = str(datetime.datetime.now())[:-7]
        if not info['start_sale_time'] <= now_str <= info['end_sale_time']:
            return {}
    # 扣钻石
    tools.del_user_things(umodified, 'diamond', conf['cost_diamond'],
                          'shopping_for_{}'.format(shop_type))
    # 添加奖励
    tools.add_user_awards(umodified, conf['award'],
                          'shopping_for_{}'.format(shop_type))
    return {}
Beispiel #14
0
def api_get_award():
    """ api/arena/get_award
    领取竞技奖励
    Returns:
        awards: 获得奖励
        cards_price(int): 卡包价格,若达到获得折扣卡包由此字段
    """
    uarena = request.user.user_arena
    if uarena.step != 6:
        return {}
    award = uarena._arenaaward_config[str(uarena.win)]
    tools.add_user_awards(uarena, award, 'arena')
    common_config = uarena._common_config
    returns = {}
    language = uarena._language_config['award_msg']['arena']
    returns['title'] = language['title']
    returns['content1'] = language['content1']
    returns['awards'] = award
    if uarena.win >= common_config['arena_discount_win']:
        all_price = 0
        price_conf = uarena._cardup_config['price']
        card_conf = uarena._card_config
        for cid in uarena.selected_cards:
            # 拥有卡不出售
            own_cards = uarena.user_cards.cards
            if cid in own_cards and own_cards[cid]['num'] != 0:
                continue
            quality = str(card_conf[cid]['quality'])
            all_price += price_conf[quality]
        if all_price:
            discount_rate = uarena._common_config['arena_discount_rate']
            returns['cards_price'] = int(all_price * discount_rate)
            uarena.set_step(7)
        else:
            uarena.reset_arena()
    else:
        uarena.reset_arena()
    return returns
Beispiel #15
0
def api_get_award():
    """ api/arena/get_award
    领取竞技奖励
    Returns:
        awards: 获得奖励
        cards_price(int): 卡包价格,若达到获得折扣卡包由此字段
    """
    uarena = request.user.user_arena
    if uarena.step != 6:
        return {}
    award = uarena._arenaaward_config[str(uarena.win)]
    tools.add_user_awards(uarena, award, 'arena')
    common_config = uarena._common_config
    returns = {} 
    language = uarena._language_config['award_msg']['arena']
    returns['title'] = language['title']
    returns['content1'] = language['content1']
    returns['awards'] = award
    if uarena.win >= common_config['arena_discount_win']:
        all_price = 0
        price_conf = uarena._cardup_config['price']
        card_conf = uarena._card_config
        for cid in uarena.selected_cards:
            # 拥有卡不出售 
            own_cards = uarena.user_cards.cards
            if cid in own_cards and own_cards[cid]['num'] != 0:
                continue    
            quality = str(card_conf[cid]['quality'])
            all_price += price_conf[quality]
        if all_price:
            discount_rate = uarena._common_config['arena_discount_rate']
            returns['cards_price'] = int(all_price * discount_rate)
            uarena.set_step(7)
        else:
            uarena.reset_arena()
    else:
        uarena.reset_arena()
    return returns
Beispiel #16
0
def api_reputation_shopping(city_id, index):
    """ api/shop/reputation_shopping
    购买某城声望商品,消耗此城代币 
    Args:
        city_id(str): 购买那个城的商品
        index(str): 商品序号
    """
    ucities = request.user.user_cities
    reputationshop_config = ucities._reputationshop_config
    if city_id not in reputationshop_config or index not in reputationshop_config[
            city_id]:
        return {}
    shop = reputationshop_config[city_id][index]
    need_reputation_lv = shop['need_reputation_lv']
    # 城市声望必须达到指定条件
    if need_reputation_lv > ucities.cities[city_id]['reputation_lv']:
        return {}
    # 消耗城市代币
    new_info = ucities.add_city_jeton(city_id, -shop['cost_city_jeton'])
    ucities.user_modified.set_modify_info('cities', new_info)
    # 添加奖励
    tools.add_user_awards(ucities, shop['award'], 'reputation_shopping')
    return {}
Beispiel #17
0
def api_end_defense(win):
    """ api/invade/end_defense
    结束反击战斗
    Argvs:
        win(bool): 是否胜利
    
    """ 
    user = request.user
    full_exp = user._common_config['invade_defense_exp']
    if not win:
        # 反击失败只给1/3经验
        return {'award': {'exp': full_exp // 3}}
    umodified = user.user_modified
    defe_history = umodified.get_dungeon_info('invade_defense')['history']
    umodified.clear_dungeon_info('invade_defense')
    now = int(time.time())
    if now - defe_history['time'] <= 1:
        raise LogicError("rush a dungeon to quick") 

    uInvade = user.user_invade
    award = {
        'exp': full_exp,
        'invade_jeton': 1,
    } 
    # 加代币
    uInvade.add_invade_jeton(1)
    tools.add_user_awards(uInvade, award, 'invade_denfense')
    # 加日志
    defe_history['status'] = 1
    defe_history['win_invade_jeton'] = 1
    defe_history['time'] = int(time.time())
    uInvade.add_history(defe_history)
    # 防守成功加1
    uInvade.inc_total_defense_win()
    
    return award
Beispiel #18
0
def api_end_defense(win):
    """ api/invade/end_defense
    结束反击战斗
    Argvs:
        win(bool): 是否胜利
    
    """
    user = request.user
    full_exp = user._common_config['invade_defense_exp']
    if not win:
        # 反击失败只给1/3经验
        return {'award': {'exp': full_exp // 3}}
    umodified = user.user_modified
    defe_history = umodified.get_dungeon_info('invade_defense')['history']
    umodified.clear_dungeon_info('invade_defense')
    now = int(time.time())
    if now - defe_history['time'] <= 1:
        raise LogicError("rush a dungeon to quick")

    uInvade = user.user_invade
    award = {
        'exp': full_exp,
        'invade_jeton': 1,
    }
    # 加代币
    uInvade.add_invade_jeton(1)
    tools.add_user_awards(uInvade, award, 'invade_denfense')
    # 加日志
    defe_history['status'] = 1
    defe_history['win_invade_jeton'] = 1
    defe_history['time'] = int(time.time())
    uInvade.add_history(defe_history)
    # 防守成功加1
    uInvade.inc_total_defense_win()

    return award
Beispiel #19
0
def api_end_invade(win):
    """ api/invade/end_invade
    战斗胜利
    Argvs:
        win(bool): 是否胜利
    Returns:
        exp(int): 获得经验
        cup(int): 获得奖杯数,可为负数
        coin(int): 获得金币数
    """ 
    user = request.user
    common_config = user._common_config
    umodified = user.user_modified
    start_info = umodified.clear_dungeon_info('invade')

    now = int(time.time())
    if now - start_info['time'] <= 1:
        raise LogicError("rush a dungeon to quick") 

    uInvade = user.user_invade
    uProperty = uInvade.user_property
    opponent_info = start_info['opponent_info']
    opponent_uid = opponent_info['uid']
    opponent_invade_log = {
        'status': 0,
        'name': user.name,
        'uid': user.uid,
        'lv': uProperty.lv, 
        'cup': uInvade.cup,
        'time': int(time.time()),
    }
    opponent_invade_log['team_info'] = uInvade.now_team_info()
    # 胜利获得全额经验1奖杯和对手金钱;失败扣奖杯,且对手加代币
    full_exp = common_config['invade_fight_exp']
    invade_user_instance = InvadeUser.get_instance()
    if win:
        # 连胜次数加1
        uInvade.inc_consecutive_win()
        # 侵略成功加1
        uInvade.inc_total_invade_win()
        award = opponent_info['win_award']
        award['exp'] = full_exp
        opponent_invade_log['status'] = 0
        opponent_invade_log['lose_coin'] = award.get('coin', 0)
        # 每次打赢别人, 自己的保护时间取消
        uInvade.reset_shield_time()
        # 如果自己有主城,加入被搜寻中
        #if uInvade.user_cities.capital_city:
        invade_user_instance.add_user(uInvade.uid)
    else:
        # 失败清空连胜次数 
        uInvade.reset_consecutive_win()
        award = opponent_info['lose_award']
        award['exp'] = full_exp // 3
        opponent_invade_log['status'] = 1
        opponent_invade_log['win_invade_jeton'] = 1

    # 改变对手数据! 加代币 或 减钱
    if opponent_uid:
        opponentInvade = UserInvade.get(opponent_uid)
        # 日志中主城设为被打者主城
        capital_city = opponentInvade.user_cities.capital_city
        opponent_invade_log['capital_city'] = capital_city
        # 加上入侵者此城等级
        uCities = uInvade.user_cities
        city_lv = 0 if not uCities.has_show_city(capital_city) else uCities.cities[capital_city]['lv']  
        opponent_invade_log['team_info']['city_lv'] = city_lv
        # 要告诉对手他被打了
        opponentInvade.add_history(opponent_invade_log)
        if win:
            opponent_coin = opponentInvade.user_property.coin 
            award['coin'] = min(opponent_invade_log['lose_coin'], opponent_coin) 
            tools.del_user_things(opponentInvade, 'coin', award['coin'], 'beinvaded')
            # 给被打人 加护盾时间
            shield_gap = common_config['invade_keep_shield_seconds']
            shield_time = int(time.time()) + shield_gap
            invade_user_instance.add_user(opponent_uid, shield_time) 
            opponentInvade.reset_shield_time(shield_time)
        else:
            invade_user_instance.add_user(opponent_uid) 
            opponentInvade.add_invade_jeton(1)
    else:
        award['coin'] = 0
        
    # 给自己加奖励
    if 'cup' in award:
        add_cup = uInvade.add_cup(award['cup'])
        award['cup'] = add_cup
    tools.add_user_awards(user, award, 'invade')
    return award
Beispiel #20
0
def api_end_invade(win):
    """ api/invade/end_invade
    战斗胜利
    Argvs:
        win(bool): 是否胜利
    Returns:
        exp(int): 获得经验
        cup(int): 获得奖杯数,可为负数
        coin(int): 获得金币数
    """
    user = request.user
    common_config = user._common_config
    umodified = user.user_modified
    start_info = umodified.clear_dungeon_info('invade')

    now = int(time.time())
    if now - start_info['time'] <= 1:
        raise LogicError("rush a dungeon to quick")

    uInvade = user.user_invade
    uProperty = uInvade.user_property
    opponent_info = start_info['opponent_info']
    opponent_uid = opponent_info['uid']
    opponent_invade_log = {
        'status': 0,
        'name': user.name,
        'uid': user.uid,
        'lv': uProperty.lv,
        'cup': uInvade.cup,
        'time': int(time.time()),
    }
    opponent_invade_log['team_info'] = uInvade.now_team_info()
    # 胜利获得全额经验1奖杯和对手金钱;失败扣奖杯,且对手加代币
    full_exp = common_config['invade_fight_exp']
    invade_user_instance = InvadeUser.get_instance()
    if win:
        # 连胜次数加1
        uInvade.inc_consecutive_win()
        # 侵略成功加1
        uInvade.inc_total_invade_win()
        award = opponent_info['win_award']
        award['exp'] = full_exp
        opponent_invade_log['status'] = 0
        opponent_invade_log['lose_coin'] = award.get('coin', 0)
        # 每次打赢别人, 自己的保护时间取消
        uInvade.reset_shield_time()
        # 如果自己有主城,加入被搜寻中
        #if uInvade.user_cities.capital_city:
        invade_user_instance.add_user(uInvade.uid)
    else:
        # 失败清空连胜次数
        uInvade.reset_consecutive_win()
        award = opponent_info['lose_award']
        award['exp'] = full_exp // 3
        opponent_invade_log['status'] = 1
        opponent_invade_log['win_invade_jeton'] = 1

    # 改变对手数据! 加代币 或 减钱
    if opponent_uid:
        opponentInvade = UserInvade.get(opponent_uid)
        # 日志中主城设为被打者主城
        capital_city = opponentInvade.user_cities.capital_city
        opponent_invade_log['capital_city'] = capital_city
        # 加上入侵者此城等级
        uCities = uInvade.user_cities
        city_lv = 0 if not uCities.has_show_city(
            capital_city) else uCities.cities[capital_city]['lv']
        opponent_invade_log['team_info']['city_lv'] = city_lv
        # 要告诉对手他被打了
        opponentInvade.add_history(opponent_invade_log)
        if win:
            opponent_coin = opponentInvade.user_property.coin
            award['coin'] = min(opponent_invade_log['lose_coin'],
                                opponent_coin)
            tools.del_user_things(opponentInvade, 'coin', award['coin'],
                                  'beinvaded')
            # 给被打人 加护盾时间
            shield_gap = common_config['invade_keep_shield_seconds']
            shield_time = int(time.time()) + shield_gap
            invade_user_instance.add_user(opponent_uid, shield_time)
            opponentInvade.reset_shield_time(shield_time)
        else:
            invade_user_instance.add_user(opponent_uid)
            opponentInvade.add_invade_jeton(1)
    else:
        award['coin'] = 0

    # 给自己加奖励
    if 'cup' in award:
        add_cup = uInvade.add_cup(award['cup'])
        award['cup'] = add_cup
    tools.add_user_awards(user, award, 'invade')
    return award
Beispiel #21
0
def api_end(dungeon_type, city_id, win=False, has_dead_mem=True, bout=1):
    """ api/dungeon/end
    结束战斗
    Args:
        dungeon_type(str): 战斗类型 "conquer"征服模式 "challenge"挑战模式 
        city_id(str): 要打哪个城,城市id
        win(bool): 战斗胜利还是失败
        has_dead_mem(bool): 挑战模式战斗过程是否有队员死亡
        bout(bool): 挑战模式战斗使用回合数

    Returns:
        coin(int): 奖励 铜钱
        exp(int): 奖励 经验
        diamond(int): 奖励 钻石
        heroSoul(int): 奖励 英魂
        card(list): 奖励 卡牌 [card_id, num]  卡牌id, 数量
            例:
             {
                "coin":170,
                "exp":10,
                "diamond":10,
                "heroSoul":70,
                "card":[
                    [
                        "10_card",
                        1
                    ]
                ]
            },

    """
    ubase = request.user
    ucities = ubase.user_cities
    umodified = ubase.user_modified 
    if 'dungeon' not in umodified.temp:
        raise LogicError('Should start fight first')
    start_info = umodified.temp['dungeon']
    if start_info.get('type') != dungeon_type or \
       start_info.get('city_id') != city_id:
        raise LogicError('End the wrong fight')
    now = int(time.time())
    if now - start_info['time'] <= 1:
        raise LogicError("rush a dungeon to quick")
    award = {}
    if dungeon_type == 'conquer':
        conquer_config = ubase._conquer_config  
        cur_stage = ucities.cur_conquer_stage(city_id)
        stage_conf = conquer_config[city_id][cur_stage]
        award = stage_conf.get('award', {})

        full_exp = award.get('exp', 0)
        # 失败只加1/3经验 
        if not win: 
            add_exp = int(full_exp / 3)
            tools.add_user_things(ubase, 'exp', add_exp, 'conquer')
            return {'exp': add_exp}
        tools.add_user_awards(ubase, award, 'conquer')
        # 额外宝箱奖励
        if 'box_award' in stage_conf:
            tools.add_user_awards(ubase, stage_conf['box_award'], 'conquer')
        new_info = ucities.up_conquer_stage(city_id)
        # 征服玩此城市, 城市每张满级卡加一级
        if str(int(cur_stage) + 1) not in conquer_config[city_id]:
            new_info = ucities.conquer_city(city_id)
            # 城市每张满级卡加一级
            ucards = ucities.user_cards
            max_card_lv = ucards._common_config['max_card_lv']
            card_config = ucards._card_config
            for card_id, card_info in ucards.cards.items():
                if card_info['lv'] == max_card_lv and\
                   city_id == str(card_config[card_id]['camp']):
                    ucities.up_city_lv(city_id)
        umodified.set_modify_info('cities', new_info)
    elif dungeon_type == 'challenge':
        challenge_config = ubase._challenge_config
        floor = umodified.temp['dungeon']['floor']
        cur_room = str(ucities.cities[city_id]['challenge'][floor])
        room_conf = challenge_config[city_id][floor][cur_room]
        award = room_conf.get('award', {})

        full_exp = award.get('exp', 0)
        # 失败只加1/3经验 
        if not win: 
            add_exp = int(full_exp / 3)
            tools.add_user_things(ubase, 'exp', add_exp, 'challenge')
            return {'exp': add_exp}
        if can_get_ext_award(ubase, room_conf['ext_term'], has_dead_mem, bout):
            for thing, info in room_conf['ext_award'].items(): 
                if thing in award:
                    award[thing] += info
                else:
                    award[thing] = info
        # 加当前城市声望
        if 'reputation' in award:
            add_reputation = award.pop('reputation')
            new_info = ucities.add_city_reputation(city_id, add_reputation)
            umodified.set_modify_info('cities', new_info)
        tools.add_user_awards(ubase, award, 'conquer')
        new_info = ucities.up_challenge_stage(city_id, floor)
        umodified.set_modify_info('cities', new_info)
    umodified.temp.pop('dungeon')
    return award
Beispiel #22
0
def api_end(dungeon_type, city_id, win=False, has_dead_mem=True, bout=1):
    """ api/dungeon/end
    结束战斗
    Args:
        dungeon_type(str): 战斗类型 "conquer"征服模式 "challenge"挑战模式 
        city_id(str): 要打哪个城,城市id
        win(bool): 战斗胜利还是失败
        has_dead_mem(bool): 挑战模式战斗过程是否有队员死亡
        bout(bool): 挑战模式战斗使用回合数

    Returns:
        coin(int): 奖励 铜钱
        exp(int): 奖励 经验
        diamond(int): 奖励 钻石
        heroSoul(int): 奖励 英魂
        card(list): 奖励 卡牌 [card_id, num]  卡牌id, 数量
            例:
             {
                "coin":170,
                "exp":10,
                "diamond":10,
                "heroSoul":70,
                "card":[
                    [
                        "10_card",
                        1
                    ]
                ]
            },

    """
    ubase = request.user
    ucities = ubase.user_cities
    umodified = ubase.user_modified
    if 'dungeon' not in umodified.temp:
        raise LogicError('Should start fight first')
    start_info = umodified.temp['dungeon']
    if start_info.get('type') != dungeon_type or \
       start_info.get('city_id') != city_id:
        raise LogicError('End the wrong fight')
    now = int(time.time())
    if now - start_info['time'] <= 1:
        raise LogicError("rush a dungeon to quick")
    award = {}
    if dungeon_type == 'conquer':
        conquer_config = ubase._conquer_config
        cur_stage = ucities.cur_conquer_stage(city_id)
        stage_conf = conquer_config[city_id][cur_stage]
        award = stage_conf.get('award', {})

        full_exp = award.get('exp', 0)
        # 失败只加1/3经验
        if not win:
            add_exp = int(full_exp / 3)
            tools.add_user_things(ubase, 'exp', add_exp, 'conquer')
            return {'exp': add_exp}
        tools.add_user_awards(ubase, award, 'conquer')
        # 额外宝箱奖励
        if 'box_award' in stage_conf:
            tools.add_user_awards(ubase, stage_conf['box_award'], 'conquer')
        new_info = ucities.up_conquer_stage(city_id)
        # 征服玩此城市, 城市每张满级卡加一级
        if str(int(cur_stage) + 1) not in conquer_config[city_id]:
            new_info = ucities.conquer_city(city_id)
            # 城市每张满级卡加一级
            ucards = ucities.user_cards
            max_card_lv = ucards._common_config['max_card_lv']
            card_config = ucards._card_config
            for card_id, card_info in ucards.cards.items():
                if card_info['lv'] == max_card_lv and\
                   city_id == str(card_config[card_id]['camp']):
                    ucities.up_city_lv(city_id)
        umodified.set_modify_info('cities', new_info)
    elif dungeon_type == 'challenge':
        challenge_config = ubase._challenge_config
        floor = umodified.temp['dungeon']['floor']
        cur_room = str(ucities.cities[city_id]['challenge'][floor])
        room_conf = challenge_config[city_id][floor][cur_room]
        award = room_conf.get('award', {})

        full_exp = award.get('exp', 0)
        # 失败只加1/3经验
        if not win:
            add_exp = int(full_exp / 3)
            tools.add_user_things(ubase, 'exp', add_exp, 'challenge')
            return {'exp': add_exp}
        if can_get_ext_award(ubase, room_conf['ext_term'], has_dead_mem, bout):
            for thing, info in room_conf['ext_award'].items():
                if thing in award:
                    award[thing] += info
                else:
                    award[thing] = info
        # 加当前城市声望
        if 'reputation' in award:
            add_reputation = award.pop('reputation')
            new_info = ucities.add_city_reputation(city_id, add_reputation)
            umodified.set_modify_info('cities', new_info)
        tools.add_user_awards(ubase, award, 'conquer')
        new_info = ucities.up_challenge_stage(city_id, floor)
        umodified.set_modify_info('cities', new_info)
    umodified.temp.pop('dungeon')
    return award