Пример #1
0
def api_buy_discount_cards():
    """ api/arena/buy_discount_cards
    购买竞技场卡包
    """
    uarena = request.user.user_arena
    if uarena.step != 7:
        return {}
    all_price = 0
    sell_cards = []
    price_conf = uarena._cardup_config['price']
    card_conf = uarena._card_config
    discount_rate = uarena._common_config['arena_discount_rate']
    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]
        sell_cards.append(cid)
    all_price = int(all_price * discount_rate)
    tools.del_user_things(uarena, 'diamond', all_price,
                          'arena_buy_discount_cards')
    for cid in sell_cards:
        tools.add_user_things(uarena, cid, 1, 'arena_buy_discount_cards')
    uarena.reset_arena()
    return {}
Пример #2
0
def api_buy_discount_cards():
    """ api/arena/buy_discount_cards
    购买竞技场卡包
    """
    uarena = request.user.user_arena
    if uarena.step != 7:
        return {} 
    all_price = 0
    sell_cards = []
    price_conf = uarena._cardup_config['price']
    card_conf = uarena._card_config
    discount_rate = uarena._common_config['arena_discount_rate']
    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]
        sell_cards.append(cid)
    all_price = int(all_price * discount_rate)
    tools.del_user_things(uarena, 'diamond', all_price, 'arena_buy_discount_cards')
    for cid in sell_cards:
        tools.add_user_things(uarena, cid, 1, 'arena_buy_discount_cards') 
    uarena.reset_arena()
    return {}
Пример #3
0
 def inf_fight_result(self, winner, end_reason):
     """ <5>3
     """
     loser = self.uid if winner != self.uid else self.opponent.uid   
     # 玩家加星
     upvp_win = UserPvp.get(winner) 
     upvp_lose = UserPvp.get(loser) 
     full_exp = upvp_win._common_config['pvp_exp']
     upvp_win.win()
     tools.add_user_things(upvp_win, 'exp', full_exp, 'pvp_end')
     upvp_lose.lose()
     tools.add_user_things(upvp_lose, 'exp', int(full_exp / 3), 'pvp_end')
     upvp_win.do_put()
     upvp_lose.do_put()
     print "   Fight has end by reason: {}".format(end_reason)
     print "    WINNER : {}  || LOSER : {}".format(winner, loser)
     # 更新排行榜
     top_model = rank.get_pvp_rank()
     top_model.set(winner, upvp_win.all_star)
     top_model.set(loser, upvp_lose.all_star)
     pier_clear(loser, winner)
     data = {
         'end_reason': end_reason,
         'winner': winner,
         'loser': loser,
     }         
     self.broad('inf_fight_result', data)
Пример #4
0
def add_cards(player_uid):
    if not can_modify():
        raise
    ubase = UserBase.get(player_uid)
    new_cards = request.forms.getlist('new_cards')
    card_num = int(request.forms.get('card_num', 1))
    for card_id in new_cards:
        tools.add_user_things(ubase, card_id, card_num, 'admin')
    redirect("/admin/player_detail?uid=%s&category=cards" % player_uid)
Пример #5
0
def api_dismiss(dismiss_type, card_id=''):
    """ api/card/dismiss
    1) 有三种分解方式    
    2)  分解所得英魂值只与卡牌的品质有关。
         i   普通:5
         ii  精良:10
         iii 稀有:25
         iv  史诗:50
         v   传说:100
    Args:
        dismiss_type(str): 分解方式
            "dismiss_one" : 分解一张此卡
            "keep_one"    : 只保留一张此卡,其他分解
            "all_keep_one": 所有卡牌只保留一张,其余全分解,card_id 缺省
        card_id(str): 卡片id
    Returns:
        get_heroSoul: 分解后产生的英魂

    """
    print "dismiss_cards", card_id, dismiss_type 
    ubase = request.user
    ucards = ubase.user_cards
    get_heroSoul = 0
    product_conf = ubase._cardup_config['dismiss_product_heroSoul']
    card_config = ubase._card_config
    if dismiss_type == 'dismiss_one': 
        tools.del_user_things(ubase, card_id, 1, 'dismiss_card')
        card_quality = str(card_config[card_id]['quality'])
        get_heroSoul += product_conf[card_quality]
        adjust_team(ucards, card_id)
    elif dismiss_type == 'keep_one':
        now_num = ucards.cards.get(card_id, {}).get('num', 0)
        del_num = now_num - 1
        tools.del_user_things(ucards, card_id, del_num, 'dismiss_card')
        card_quality = str(card_config[card_id]['quality'])
        get_heroSoul += del_num * product_conf[card_quality]
        adjust_team(ucards, card_id)
    elif dismiss_type == 'all_keep_one':
        for cid, cinfo in ucards.cards.items():
            cnum = cinfo['num']
            if cnum <= 1:
                continue
            del_num = cnum - 1
            tools.del_user_things(ucards, cid, del_num, 'dismiss_card')
            card_quality = str(card_config[cid]['quality'])
            get_heroSoul += del_num * product_conf[card_quality]
            adjust_team(ucards, cid)
    tools.add_user_things(ubase, 'heroSoul', get_heroSoul, 'dismiss_card')
    return {'get_heroSoul': get_heroSoul}
Пример #6
0
def api_dismiss(dismiss_type, card_id=''):
    """ api/card/dismiss
    1) 有三种分解方式    
    2)  分解所得英魂值只与卡牌的品质有关。
         i   普通:5
         ii  精良:10
         iii 稀有:25
         iv  史诗:50
         v   传说:100
    Args:
        dismiss_type(str): 分解方式
            "dismiss_one" : 分解一张此卡
            "keep_one"    : 只保留一张此卡,其他分解
            "all_keep_one": 所有卡牌只保留一张,其余全分解,card_id 缺省
        card_id(str): 卡片id
    Returns:
        get_heroSoul: 分解后产生的英魂

    """
    print "dismiss_cards", card_id, dismiss_type
    ubase = request.user
    ucards = ubase.user_cards
    get_heroSoul = 0
    product_conf = ubase._cardup_config['dismiss_product_heroSoul']
    card_config = ubase._card_config
    if dismiss_type == 'dismiss_one':
        tools.del_user_things(ubase, card_id, 1, 'dismiss_card')
        card_quality = str(card_config[card_id]['quality'])
        get_heroSoul += product_conf[card_quality]
        adjust_team(ucards, card_id)
    elif dismiss_type == 'keep_one':
        now_num = ucards.cards.get(card_id, {}).get('num', 0)
        del_num = now_num - 1
        tools.del_user_things(ucards, card_id, del_num, 'dismiss_card')
        card_quality = str(card_config[card_id]['quality'])
        get_heroSoul += del_num * product_conf[card_quality]
        adjust_team(ucards, card_id)
    elif dismiss_type == 'all_keep_one':
        for cid, cinfo in ucards.cards.items():
            cnum = cinfo['num']
            if cnum <= 1:
                continue
            del_num = cnum - 1
            tools.del_user_things(ucards, cid, del_num, 'dismiss_card')
            card_quality = str(card_config[cid]['quality'])
            get_heroSoul += del_num * product_conf[card_quality]
            adjust_team(ucards, cid)
    tools.add_user_things(ubase, 'heroSoul', get_heroSoul, 'dismiss_card')
    return {'get_heroSoul': get_heroSoul}
Пример #7
0
def recover_stamina():
    """ 恢复体力 并 更新下次回复体力时间
    """
    user = request.user
    now = time.time()
    if now < user.last_recover_stamina_time:
        return
    gap_min = user._common_config["stamina_recover_gap_min"]
    gap_cnt = int((now - user.last_recover_stamina_time) / (gap_min * 60)) + 1
    user.last_recover_stamina_time += gap_min * 60 * gap_cnt

    # 体力不能超过上限
    uproperty = user.user_property
    max_stamina = user._userlv_config[str(user.user_property.lv)]["stamina"]
    if uproperty.stamina >= max_stamina:
        return
    add_stamina = min(max_stamina - uproperty.stamina, gap_cnt)

    add_user_things(uproperty, "stamina", add_stamina, "recover_stamin_by_self")
Пример #8
0
def api_allot_nature(nature_type, allot_num=1):
    """ api/charactor/allot_nature
    元素掌握度加点, 每次加一点
            蓝 "0"
            红 "1"
            绿 "2"
            褐 "3"
            黄 "4"
            紫 "5"

    Args:
        nature_type(str): 元素类型代号
        allot_num(str): 给该元素分配点数,缺省为1 
    """
    ubase = request.user
    need_remain_num = allot_num 
    tools.del_user_things(ubase, 'nature_remain', need_remain_num, 'allot_nature') 
    tools.add_user_things(ubase, "nature_" + nature_type, allot_num, 'allot_nature') 
    return {}
Пример #9
0
def api_allot_nature(nature_type, allot_num=1):
    """ api/charactor/allot_nature
    元素掌握度加点, 每次加一点
            蓝 "0"
            红 "1"
            绿 "2"
            褐 "3"
            黄 "4"
            紫 "5"

    Args:
        nature_type(str): 元素类型代号
        allot_num(str): 给该元素分配点数,缺省为1 
    """
    ubase = request.user
    need_remain_num = allot_num
    tools.del_user_things(ubase, 'nature_remain', need_remain_num,
                          'allot_nature')
    tools.add_user_things(ubase, "nature_" + nature_type, allot_num,
                          'allot_nature')
    return {}
Пример #10
0
    def add_exp(self, num):
        self.exp += num
        userlv_config = self._userlv_config
        old_lv = self.lv
        while str(self.lv + 1) in userlv_config and \
        self.exp >= userlv_config[str(self.lv + 1)]['exp']:
            self.lv += 1
            # 升级体力奖励
            add_stamina = userlv_config[str(self.lv)]['lv_add_stamina']
            add_user_things(self, 'stamina', add_stamina, 'lv_up')

        if str(self.lv + 1) not in userlv_config and \
        self.exp > userlv_config[str(self.lv)]:
            self.exp = userlv_config[str(self.lv)]
        modified = {'exp': self.exp}
        if old_lv != self.lv:
            modified['lv'] = self.lv
            # 升一级加一点剩余元素掌握度 
            modified['nature_remain'] = self.add_thing('nature_remain', 
                self.lv - old_lv)
        self.put()
        return modified            
Пример #11
0
    def add_exp(self, num):
        self.exp += num
        userlv_config = self._userlv_config
        old_lv = self.lv
        while str(self.lv + 1) in userlv_config and \
        self.exp >= userlv_config[str(self.lv + 1)]['exp']:
            self.lv += 1
            # 升级体力奖励
            add_stamina = userlv_config[str(self.lv)]['lv_add_stamina']
            add_user_things(self, 'stamina', add_stamina, 'lv_up')

        if str(self.lv + 1) not in userlv_config and \
        self.exp > userlv_config[str(self.lv)]:
            self.exp = userlv_config[str(self.lv)]
        modified = {'exp': self.exp}
        if old_lv != self.lv:
            modified['lv'] = self.lv
            # 升一级加一点剩余元素掌握度
            modified['nature_remain'] = self.add_thing('nature_remain',
                                                       self.lv - old_lv)
        self.put()
        return modified
Пример #12
0
def api_summon(card_id):
    """ api/card/summon
    召唤所需金币=品质系数+200*(当前等级-1)+800*当前好感度
    Args:
        card_id: 卡牌id

    """
    print "summon_cards", card_id
    ucards = request.user.user_cards
    summon_coe =ucards._cardup_config['summon_coe'] 
    card_quality = str(ucards._card_config[card_id]["quality"])
    card_lv = ucards.get_card_lv(card_id)
    now_favor = int(ucards.cards[card_id]['favor'])
    need_coin = summon_coe[card_quality] + 200 * (card_lv - 1) + 800 * now_favor
    tools.del_user_things(ucards, 'coin', need_coin, 'summon_card')
    new_info = tools.add_user_things(ucards, card_id, 1, 'summon_card')
    # 召唤后数量应该为 1
    if new_info['num'] != 1:
        raise LogicError("The num of this card sould be 0") 
    return {}
Пример #13
0
def api_summon(card_id):
    """ api/card/summon
    召唤所需金币=品质系数+200*(当前等级-1)+800*当前好感度
    Args:
        card_id: 卡牌id

    """
    print "summon_cards", card_id
    ucards = request.user.user_cards
    summon_coe = ucards._cardup_config['summon_coe']
    card_quality = str(ucards._card_config[card_id]["quality"])
    card_lv = ucards.get_card_lv(card_id)
    now_favor = int(ucards.cards[card_id]['favor'])
    need_coin = summon_coe[card_quality] + 200 * (card_lv -
                                                  1) + 800 * now_favor
    tools.del_user_things(ucards, 'coin', need_coin, 'summon_card')
    new_info = tools.add_user_things(ucards, card_id, 1, 'summon_card')
    # 召唤后数量应该为 1
    if new_info['num'] != 1:
        raise LogicError("The num of this card sould be 0")
    return {}
Пример #14
0
def modify_player():
    if not can_modify():
        raise
    player_uid = request.forms.get('uid')
    ubase = UserBase.get(player_uid)
    if not ubase:
        raise
    modify_type = request.forms.get('type')
    if not modify_type:
        raise
    print "modfiy_type", modify_type
    type_value = request.forms.get(modify_type)
    print "type_value", type_value
    if modify_type == 'uname':
        new_name = request.forms.get('newname')
        update_name = tools.update_user_info(ubase, 'name', new_name, 'admin')
        return update_name

    elif modify_type.endswith('_card_lv'):
        ucards = ubase.user_cards
        card_id = modify_type.rsplit('_lv', 1)[0]
        new_lv = int(request.forms.get(modify_type)) 
        ucards.cards[card_id]['lv'] = new_lv
        ucards.put()

    elif modify_type.endswith('_card_favor'):
        ucards = ubase.user_cards
        card_id = modify_type.rsplit('_favor', 1)[0]
        new_lv = int(request.forms.get(modify_type)) 
        ucards.cards[card_id]['favor'] = new_lv
        ucards.put()

    elif modify_type.endswith('_card_num'):
        ucards = ubase.user_cards
        card_id = modify_type.rsplit('_num', 1)[0]
        new_lv = int(request.forms.get(modify_type)) 
        ucards.cards[card_id]['num'] = new_lv
        ucards.put()
    
    elif modify_type.startswith('dismiss_'):
        ucards = ubase.user_cards
        card_id = modify_type.split('dismiss_', 1)[1]
        dismiss_type = request.forms.get(modify_type)
        request.user = ubase
        card_logic.api_dismiss(dismiss_type, card_id)

    elif modify_type.startswith('summon_'):
        ucards = ubase.user_cards
        card_id = modify_type.split('summon_', 1)[1]
        request.user = ubase
        card_logic.api_summon(card_id)
    elif modify_type.startswith('city_status_'):
        ucities = ubase.user_cities
        city_id = modify_type.split('city_status_', 1)[1]
        new_status = int(request.forms.get(modify_type))
        ucities.open_city(city_id)
        ucities.cities[city_id]['status'] = new_status
        if new_status > 1 and not ucities.cities[city_id]['challenge']:
            ucities.conquer_city(city_id)
    elif modify_type.startswith('conquer_'):
        ucities = ubase.user_cities
        city_id = modify_type.split('conquer_', 1)[1]
        new_stage = int(request.forms.get(modify_type))
        ucities.cities[city_id]['cur_conquer'] = new_stage
        
    elif modify_type.startswith('city_lv_'):
        ucities = ubase.user_cities
        city_id = modify_type.split('city_lv_', 1)[1]
        new = int(request.forms.get(modify_type))
        ucities.cities[city_id]['lv'] = new
    elif modify_type.startswith('city_jeton_'):
        ucities = ubase.user_cities
        city_id = modify_type.split('city_jeton_', 1)[1]
        new = int(request.forms.get(modify_type))
        ucities.cities[city_id]['jeton'] = new
    elif modify_type.startswith('city_reputationlv_'):
        ucities = ubase.user_cities
        city_id = modify_type.split('city_reputationlv_', 1)[1]
        new = int(request.forms.get(modify_type))
        ucities.cities[city_id]['reputation_lv'] = new
    elif modify_type.startswith('city_reputation_'):
        ucities = ubase.user_cities
        city_id = modify_type.split('city_reputation_', 1)[1]
        new = int(request.forms.get(modify_type))
        ucities.cities[city_id]['reputation'] = new
    else:
        thing = modify_type[1:]
        num = int(request.forms.get('add' + thing))
        return tools.add_user_things(ubase, thing, num, 'addby_admin')
Пример #15
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
Пример #16
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