Ejemplo n.º 1
0
def _default_start_battle(data, dungeon, battle_level, now):
    """默认开始战斗方法"""
    user = data.user.get(True)
    status = dungeon.status(user.level, now)
    if status != dungeon.ACTIVE:
        return dungeon_pb2.DUNGEON_NOT_OPEN
    if dungeon.get_remain_num() <= 0:
        return dungeon_pb2.DUNGEON_NO_ENTER_NUM

    node_basic_id = dungeon.node_basic_id()
    node_id = NodeInfo.generate_id(data.id, node_basic_id)
    node = data.node_list.get(node_id)
    if node is None:
        node = NodeInfo.create(data.id, node_basic_id)
        data.node_list.add(node)
    
    node.set_expand_dungeon()

    user = data.user.get(True)
    rival = data.rival_list.get(node_id)
    if rival is None:
        rival = RivalInfo.create(node_id, data.id)
        data.rival_list.add(rival)

    rival.set_expand_dungeon(dungeon.basic_id, dungeon.level(user.level), battle_level)

    return dungeon_pb2.DUNGEON_OK
Ejemplo n.º 2
0
def _post_upgrade(data, user, old_level, new_level, now):
    """用户升级后的处理
    1 可能解锁 PVP
    2 可能解锁 pvp arena
    3 升级世界地图上己方主城的等级
    4 增加政令值
    5 想邀请者转发升级通知
    """
    if not check_pvp_authority(data):
        return False
    if not check_arena_authority(data, now):
        return False
    if not check_worldboss_authority(data):
        return False

    own_basic_id = NodeInfo.get_own_node_basic_id()
    own_id = NodeInfo.generate_id(data.id, own_basic_id)
    own = data.node_list.get(own_id)
    own.update_own_city_level(user.level)

    energy = data.energy.get()
    level_diff = new_level - old_level
    diff = 1
    while diff <= level_diff:
        energy.update_energy_and_capacity(old_level + diff)
        diff += 1

    if user.is_invited():
        _forward_invitee_upgrade(data, user)

    return True
Ejemplo n.º 3
0
def start_battle(data, teams, heroes, rival_user_id, rival, now, force=False):
    """开始战斗
    """
    user = data.user.get(True)
    union = data.union.get()
    node_id = NodeInfo.generate_id(data.id,
                                   union.get_battle_mapping_node_basic_id())
    battle = data.battle_list.get(node_id)
    if battle is None:
        battle = BattleInfo.create(node_id, data.id)
        data.battle_list.add(battle)
    node = data.node_list.get(node_id)
    if node is None:
        node = NodeInfo.create(data.id,
                               union.get_battle_mapping_node_basic_id())
        data.node_list.add(node)
    r = data.rival_list.get(node_id)
    if r is None:
        r = RivalInfo.create(node_id, data.id)
        data.rival_list.add(r)

    #标记敌对玩家
    r.set_union_battle_enemy_detail(rival_user_id, rival)

    #消耗攻击次数
    union.consume_battle_attack()

    #消耗粮草
    resource = data.resource.get()
    resource.update_current_resource(now)
    need_food = battle_business._calc_food_consume(heroes)
    if not resource.cost_food(need_food):
        return False
    battle.set_food_consume(need_food)

    #消耗兵力
    if not battle_business._consume_soldier(data, battle, now, heroes, force):
        return False

    #计算战利品
    reward_money = 0
    reward_food = 0
    reward_user_exp = 0
    reward_hero_exp = data_loader.MonarchLevelBasicInfo_dict[
        user.level].heroBattleExp
    reward_items = reward_module.random_battle_gift(user.level)
    battle.set_reward(reward_money, reward_food, reward_hero_exp,
                      reward_user_exp, reward_items)

    return battle.start(None, r, None, teams, heroes, now, user.vip_level)
Ejemplo n.º 4
0
    def _calc_start_battle_result(self, union_response, data, req, timer):
        res = union_boss_pb2.StartUnionBossBattleRes()
        res.status = 0

        union_res = internal_union_pb2.InternalSyncBossRes()
        union_res.ParseFromString(union_response)
        
        if union_res.status != 0:
            raise Exception("Start union boss battle failed")

        if union_res.ret != union_pb2.UNION_OK:
            res.ret = union_res.ret
            return self._start_battle_succeed(data, req, res, timer)

        if union_res.boss_status != UserUnionBossInfo.BATTLE:
            if union_res.boss_status == UserUnionBossInfo.INACTIVE:
                res.ret = union_pb2.UNION_BOSS_INACTIVE
            else:
                res.ret = union_pb2.UNION_BOSS_KILLED
            return self._start_battle_succeed(data, req, res, timer)

        boss_id = union_res.boss_id
        array_index = req.world_boss_choose_index    #选择boss队伍的index

        #参战队伍 & 英雄
        teams = []
        heroes = []
        for team_info in req.battle.attack_teams:
            team_id = TeamInfo.generate_id(data.id, team_info.index)
            team = data.team_list.get(team_id)
            if team is None:
                continue
            teams.append(team)

            for hero_id in team.get_heroes():
                if hero_id != 0:
                    hero = data.hero_list.get(hero_id)
                    heroes.append(hero)

        (ret, battle_ret) = union_boss_business.start_battle(data, boss_id, 
                array_index, teams, heroes, timer.now, req.gold)
        if ret != union_pb2.UNION_OK or battle_ret != battle_pb2.BATTLE_OK:
            res.ret = ret
            res.battle_ret = battle_ret
            return self._start_battle_succeed(data, req, res, timer)

        node_id = NodeInfo.generate_id(data.id, UserUnionInfo.get_union_boss_node_basic_id())
        battle = data.battle_list.get(node_id, True)
        resource = data.resource.get(True)
        pack.pack_battle_reward_info(battle, res.reward)
        pack.pack_resource_info(resource, res.resource)
        conscript_list = data.conscript_list.get_all(True)
        for conscript in conscript_list:
            pack.pack_conscript_info(conscript, res.conscripts.add(), timer.now)

        res.ret = union_pb2.UNION_OK
        res.battle_ret = battle_pb2.BATTLE_OK
        defer = DataBase().commit(data)
        defer.addCallback(self._start_battle_succeed, req, res, timer)
        return defer
Ejemplo n.º 5
0
def trigger_custom_event(data, now, node_basic_id, event_type, change_nodes):
    """触发特定的事件
    可以指定发生事件的节点,事件的类型
    """
    logger.debug("Trigger custom event")
    map = data.map.get()
    node_id = NodeInfo.generate_id(data.id, node_basic_id)
    node = data.node_list.get(node_id)

    candidate = _calc_candidate_event(data, node, now)
    candidate.extend(_calc_candidate_event(data, node, now, False))
    if len(candidate) == 0:
        logger.warning("Node not prepared for event[node basic id=%d]" % node.basic_id)
        return False

    if event_type not in candidate:
        logger.warning("Node not matched event"
                "[node basic id=%d][event type=%d][available=%s]" %
                (node.basic_id, event_type, utils.join_to_string(candidate)))
        return False

    if not _node_arise_event(data, node_id, event_type, now,
            change_nodes, [], []):
        return False

    change_nodes.append(node)
    logger.debug("node trigger event[basic id=%d][event type=%d]" %
            (node.basic_id, node.event_type))

    map.update_next_luck_time(now)
    return True
Ejemplo n.º 6
0
    def _calc_abandon_node(self, data, req, timer):
        """
        """
        abandon_node_id = NodeInfo.generate_id(data.id, req.node_id)
        abandon_node = data.node_list.get(abandon_node_id)

        change_nodes = []
        if not map_business.abandon_key_node(data, abandon_node, timer.now,
                                             change_nodes):
            raise Exception("Abandon node failed")

        #为新刷出的敌方节点匹配敌人
        #不合法的敌人:自己,以及已经在地图上出现过的 PVP 敌人
        invalid_rival = [data.id]
        for node in data.node_list.get_all(True):
            if node.is_rival_pvp() and node.is_enemy_complete():
                rival_id = node.id
                rival = data.rival_list.get(rival_id, True)
                invalid_rival.append(rival.rival_id)

        user = data.user.get(True)
        matcher = RivalMatcher(user.level, invalid_rival)

        for node in change_nodes:
            if node.is_lack_enemy_detail():
                matcher.add_condition(data, node)

        defer = matcher.match(user.country)
        defer.addCallback(self._pack_abandon_node_response, data, change_nodes,
                          req, timer)
        return defer
Ejemplo n.º 7
0
    def _calc_upgrade(self, data, req, timer):
        """进行升级
        """
        #涉及到跨天的数据统计,所以此处要更新所有跨天数据
        if not account_business.update_across_day_info(data, timer.now):
            raise Exception("Update across day info failed")

        node_basic_id = req.node.basic_id
        node_id = NodeInfo.generate_id(data.id, node_basic_id)
        node = data.node_list.get(node_id)
        gold = 0
        if req.HasField("gold"):
            gold = req.gold

        if not exploitation_business.finish_upgrade_event(
                data, node, timer.now, gold):
            raise Exception("Finish upgrade event failed")

        resource = data.resource.get(True)
        res = self._pack_upgrade_response(data, resource, node, timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._upgrade_succeed, req, res, timer)
        return defer
Ejemplo n.º 8
0
def _default_finish_battle(data, dungeon, now, **kw):
    """默认结束战斗方法"""
    dungeon_level = kw['dungeon_level']     #完成的副本难度
    win = kw['win']                         #是否胜利
    if not win:
        dungeon.attack()
        return dungeon_pb2.DUNGEON_OK

    key = "%d_%d" % (dungeon.basic_id, dungeon_level)
    ratio = data_loader.ExpandDungeonLevelBasicInfo_dict[key].rewardRatio
    
    #修改battle中的奖励信息
    node_basic_id = dungeon.node_basic_id()
    node_id = NodeInfo.generate_id(data.id, node_basic_id)
    battle = data.battle_list.get(node_id)

    reward_money = battle.reward_money
    reward_food = battle.reward_food
    reward_hero_exp = battle.reward_hero_exp
    reward_user_exp = battle.reward_user_exp
    item_list = battle.get_reward_items()

    reward_money *= ratio
    reward_food *= ratio

    new_item_list = []
    for item_id, item_num in item_list:
        new_item_list.append((item_id, item_num * ratio))

    battle.set_reward(reward_money, reward_food, reward_hero_exp, reward_user_exp, new_item_list)
    dungeon.attack()

    return dungeon_pb2.DUNGEON_OK
Ejemplo n.º 9
0
    def _calc_rematch_node(self, data, req, timer):
        """
        """
        rematch_node_id = NodeInfo.generate_id(data.id, req.node.basic_id)
        rematch_node = data.node_list.get(rematch_node_id)

        rival_id = rematch_node.id
        rival = data.rival_list.get(rival_id, True)
        invalid_rival = [data.id, rival.rival_id]  #不允许出现原来的敌人

        if not map_business.rematch_key_node(data, rematch_node, timer.now):
            raise Exception("Rematch node failed")

        #为新刷出的敌方节点匹配敌人
        for node in data.node_list.get_all(True):
            if node.is_rival_pvp() and node.is_enemy_complete():
                rival_id = node.id
                rival = data.rival_list.get(rival_id, True)
                invalid_rival.append(rival.rival_id)

        user = data.user.get(True)
        matcher = RivalMatcher(user.level, invalid_rival)
        matcher.add_condition(data, rematch_node)

        defer = matcher.match(user.country)
        defer.addCallback(self._pack_rematch_node_response, data, rematch_node,
                          req, timer)
        return defer
Ejemplo n.º 10
0
    def _calc_increase(self, data, req, timer):
        """
        """
        #涉及到跨天的数据统计,所以此处要更新所有跨天数据
        if not account_business.update_across_day_info(data, timer.now):
            raise Exception("Update across day info failed")

        node_id = NodeInfo.generate_id(data.id, req.node.basic_id)
        node = data.node_list.get(node_id)

        use_gold = req.node.increase.use_gold
        rate = req.node.increase.rate
        duration = req.node.increase.total_time

        if use_gold:
            item = None
        else:
            item_id = ItemInfo.generate_id(data.id, req.item.basic_id)
            item = data.item_list.get(item_id)

        if not increase_business.increase(data, node, rate, use_gold, duration,
                                          item, timer.now):
            raise Exception("Increase failed")

        #记录次数
        trainer = data.trainer.get()
        trainer.add_daily_increase_item_num(1)

        return DataBase().commit(data)
Ejemplo n.º 11
0
def lose_battle(data, enemy_soldier_info, own_soldier_info, score, now):
    """战斗失败
    """
    user = data.user.get(True)
    union = data.union.get()
    node_id = NodeInfo.generate_id(data.id,
                                   union.get_battle_mapping_node_basic_id())
    battle = data.battle_list.get(node_id)
    rival = data.rival_list.get(node_id)

    #根据杀敌,增加战功
    _gain_union_battle_individual_score_of_battle(union, enemy_soldier_info,
                                                  score)

    #返还己方存活士兵
    if not battle_business._reclaim_soldier(data, battle, now,
                                            own_soldier_info):
        return False

    #更新统计信息
    if not battle_business._update_statistics(data, battle, False, rival, None,
                                              enemy_soldier_info,
                                              own_soldier_info):
        return False

    #清除原有的敌人信息
    rival.clear()

    return battle.finish()
Ejemplo n.º 12
0
def finish_jungle_event_fail(data, node, now, change_nodes):
    """结束野怪事件: 失败
    """
    #如果附属点所在的key node已经丢失,则野怪事件结束,附属点也消失
    parent_basic_id = MapGraph().get_parent(node.basic_id)
    parent_id = NodeInfo.generate_id(data.id, parent_basic_id)
    parent = data.node_list.get(parent_id, True)
    if not parent.is_visible() or not parent.is_own_side():
        #节点上必须有合法的野怪随机事件
        if node.event_type != NodeInfo.EVENT_TYPE_JUNGLE:
            logger.warning("Wrong event[type=%d]" % node.event_type)
            return False

        if not node.launch_event(now, overtime=True):
            return False

        if not node.finish_event(now, overtime=True):
            return False

        #节点变为不活跃
        map = data.map.get()
        node.reset_dependency(map)

        change_nodes.append(node)

    return True
Ejemplo n.º 13
0
def start_battle(data, arena, now):
    """开始战斗"""
    user = data.user.get(True)
    if not arena.is_able_to_open(user, now):
        logger.warning("arena is not open[user_id=%d]" % data.id)
        #return -1

    node_basic_id = arena.get_node_basic_id()
    node_id = NodeInfo.generate_id(data.id, node_basic_id)
    node = data.node_list.get(node_id)
    if node is None:
        node = NodeInfo.create(data.id, node_basic_id)
        data.node_list.add(node)

    node.set_arena()

    return node_id
Ejemplo n.º 14
0
def is_able_to_finish_battle(data, now):
    """是否可以结束战斗
    """
    union = data.union.get()
    node_id = NodeInfo.generate_id(data.id,
                                   union.get_battle_mapping_node_basic_id())
    battle = data.battle_list.get(node_id)

    return battle.is_able_to_finish(now)
Ejemplo n.º 15
0
    def _calc_start_exploit(self, data, req, timer):
        """开始进行开采的逻辑
        """
        user = data.user.get(True)
        resource = data.resource.get()
        resource.update_current_resource(timer.now)

        node_id = NodeInfo.generate_id(data.id, req.node.basic_id)
        node = data.node_list.get(node_id)

        work_heroes = []  #参与采集的英雄
        for basic_id in req.node.exploitation.hero_basic_ids:
            if basic_id == 0:
                work_heroes.append(None)
            else:
                hero_id = HeroInfo.generate_id(data.id, basic_id)
                hero = data.hero_list.get(hero_id)
                work_heroes.append(hero)

        #将参与研究的英雄从其他建筑物中移除,更新原有建筑的影响
        #不结算英雄经验 : 英雄经验由客户端周期性请求结算
        #WARNING : 在上一次请求到此时英雄驻守的经验不结算
        for hero in work_heroes:
            if hero is not None and hero.is_working_in_building():
                building = data.building_list.get(hero.place_id)
                defense = None
                if building.is_defense():
                    defense = data.defense_list.get(building.id)
                if not building_business.remove_garrison(
                        building, hero, resource, timer.now):
                    raise Exception("Reassign build hero error")

        #所有生效的内政科技
        interior_technologys = [
            tech for tech in data.technology_list.get_all(True)
            if tech.is_interior_technology() and not tech.is_upgrade
        ]

        #离线开采事件的开采时间单独设置
        if node.is_exploit_offline():
            if (req.node.exploitation.total_time != OFFLINE_EXPLOIT_TIME_1 and
                    req.node.exploitation.total_time != OFFLINE_EXPLOIT_TIME_2
                    and req.node.exploitation.total_time !=
                    OFFLINE_EXPLOIT_TIME_3):
                raise Exception("Exploitation total time error")
            else:
                node.set_exploit_total_time(req.node.exploitation.total_time)
                node.set_exploit_level(req.node.exploitation.level)

        if not exploitation_business.start_exploit_event(
                data, node, work_heroes, timer.now, interior_technologys):
            raise Exception("Start exploit failed")

        #compare.check_node(data, req.node, with_exploit = True)

        return DataBase().commit(data)
Ejemplo n.º 16
0
def init_legendcity(data, now):
    """初始化史实城
    """
    for city_id in data_loader.LegendCityBasicInfo_dict:
        node_id = NodeInfo.generate_id(
            data.id, data_loader.LegendCityBasicInfo_dict[city_id].nodeId)
        legendcity = LegendCityInfo.create(data.id, city_id, node_id, now)
        data.legendcity_list.add(legendcity)

    return True
Ejemplo n.º 17
0
    def _calc_start_question(self, data, req, timer):
        """开始问答逻辑
        """
        node_basic_id = req.node.basic_id
        node_id = NodeInfo.generate_id(data.id, node_basic_id)
        node = data.node_list.get(node_id)

        if not question_business.start_question_event(data, node, timer.now):
            raise Exception("Start question failed")

        return DataBase().commit(data)
Ejemplo n.º 18
0
Archivo: pack.py Proyecto: hw233/test-2
def pack_mail_info(mail, message, now):
    message.index = MailInfo.get_index(mail.id)
    message.type = mail.type
    message.state = mail.status
    message.passed_time = now - mail.time
    message.delete_after_used = mail.delete_after_used

    message.reward_resource.money = mail.reward_money
    message.reward_resource.food = mail.reward_food
    message.reward_resource.gold = mail.reward_gold

    for (basic_id, num) in mail.get_reward_items():
        item_message = message.reward_items.add()
        item_message.basic_id = basic_id
        item_message.num = num

    message.lost_resource.money = mail.lost_money
    message.lost_resource.food = mail.lost_food
    message.lost_resource.gold = mail.lost_gold
    message.lost_resource.soldier = mail.lost_soldier

    if mail.related_node_id != 0:
        message.node_id = NodeInfo.get_basic_id(mail.related_node_id)

    if mail.related_exploitation_type != 0:
        message.exploitation_type = mail.related_exploitation_type
        message.exploitation_level = mail.related_exploitation_level
        message.exploitation_progress = mail.related_exploitation_progress

    if mail.related_enemy_type != 0:
        message.enemy_type = mail.related_enemy_type
        message.enemy_name = mail.get_readable_enemy_name()
        message.battle_win = mail.related_battle_win

    message.basic_id = mail.basic_id
    #if not mail.is_content_empty():
    #    message.subject = mail.subject
    #    message.sender = mail.sender
    #    message.content = mail.content
    if mail.subject != '':
        message.subject = mail.subject
    if mail.sender != '':
        message.sender = mail.sender
    if mail.content != '':
        message.content = mail.content

    if mail.arena_title_level != 0:
        message.arena_title_level = mail.arena_title_level
    if mail.arena_coin != 0:
        message.arena_coin = mail.arena_coin

    if mail.legendcity_id != 0:
        message.legendcity_id = mail.legendcity_id
        message.legendcity_position = mail.legendcity_position
Ejemplo n.º 19
0
Archivo: map.py Proyecto: hw233/test-2
def _post_lost_key_node(data, map, node, lost_time, now, change_nodes,
                        new_items, new_mails):
    """丢失邻接节点的后续处理
    1 对附属点的影响: 清除附属点上随机事件
    2 对邻接关键点的影响: 邻接的敌方关键点,如果是孤立节点,视野消失
    """
    #对附属点的影响
    for basic_id in MapGraph().get_children(node.basic_id):
        child_id = NodeInfo.generate_id(data.id, basic_id)
        child = data.node_list.get(child_id)
        #如果附属点正在发生战斗,不处理,跳过
        if child.is_in_battle():
            continue

        #中止/清除所有附属点上的随机事件
        if child.is_event_arised():
            if not _stop_lucky_event_on_node(data, child, lost_time, now,
                                             change_nodes, new_items,
                                             new_mails):
                return False
        assert not child.is_dependency_active()

    ##对邻接关键点的影响
    #for basic_id in MapGraph().get_neighbors(node.basic_id):
    #    neighbor_id = NodeInfo.generate_id(data.id, basic_id)
    #    neighbor = data.node_list.get(neighbor_id)

    #    #如果邻接节点发生副本事件,视野不受影响
    #    if neighbor.event_type == NodeInfo.EVENT_TYPE_DUNGEON:
    #        continue
    #    #如果邻接点发生演武场事件,视野不受影响
    #    elif neighbor.event_type == NodeInfo.EVENT_TYPE_ARENA:
    #        continue

    #    #如果邻接点正发生战斗事件(委任),视野不受影响
    #    if neighbor.is_in_battle():
    #        continue

    #    #邻接敌方孤立关键点,视野消失,清除节点
    #    if neighbor.is_enemy_side() and is_key_node_isolated(data, neighbor):
    #        #清除随机事件
    #        if neighbor.is_event_arised():
    #            if not _stop_lucky_event_on_node(data, neighbor, lost_time, now,
    #                    change_nodes, new_items, new_mails):
    #                return False
    #        if not clear_key_node(data, neighbor):
    #            return False
    #        change_nodes.append(neighbor)

    #减少领地数
    map.lost_node(1)

    return True
Ejemplo n.º 20
0
def win_battle(data, enemy_soldier_info, own_soldier_info, score, now):
    """战斗胜利
    """
    user = data.user.get(True)
    union = data.union.get()
    node_id = NodeInfo.generate_id(data.id,
                                   union.get_battle_mapping_node_basic_id())
    battle = data.battle_list.get(node_id)
    rival = data.rival_list.get(node_id)

    #获得战利品
    resource = data.resource.get()
    resource.update_current_resource(now)
    resource.gain_money(battle.reward_money)
    resource.gain_food(battle.reward_food)
    if not item_business.gain_item(data, battle.get_reward_items(),
                                   "win battle", log_formater.WIN_BATTLE):
        return False

    #根据杀敌,增加战功
    _gain_union_battle_individual_score_of_battle(union, enemy_soldier_info,
                                                  score)

    #返还己方存活士兵
    if not battle_business._reclaim_soldier(data, battle, now,
                                            own_soldier_info):
        return False

    #用户获得经验
    if not user_business.level_upgrade(data, battle.reward_user_exp, now,
                                       "exp win union battle",
                                       log_formater.EXP_WIN_BATTLE):
        return False

    #参战英雄获得经验
    heroes_id = battle.get_battle_hero()
    exp = int(battle.reward_hero_exp / len(heroes_id))
    for hero_id in heroes_id:
        hero = data.hero_list.get(hero_id)
        if not hero_business.level_upgrade(data, hero, exp, now):
            return False

    #更新统计信息
    if not battle_business._update_statistics(data, battle, True, rival, None,
                                              enemy_soldier_info,
                                              own_soldier_info):
        return False

    #清除原有的敌人信息
    rival.clear()

    return battle.finish()
Ejemplo n.º 21
0
def _get_all_own_dependency_node_count(data):
    """获得己方所有附属点的个数
    """
    node_list = data.node_list.get_all(True)
    count = 0
    for node in node_list:
        if node.is_dependency():
            parent_basic_id = MapGraph().get_parent(node.basic_id)
            parent_id = NodeInfo.generate_id(data.id, parent_basic_id)
            parent = data.node_list.get(parent_id, True)
            #父节点(关键点)是己方节点
            if parent.is_own_side():
                count += 1
    return count
Ejemplo n.º 22
0
def arise_jungle_event(data, node, now, **kwargs):
    """出现野怪事件
    1 附属点变为活跃
    2 附属点出现 PVE 敌人
    """
    change_nodes = kwargs["change_nodes"]

    parent_basic_id = MapGraph().get_parent(node.basic_id)
    parent_id = NodeInfo.generate_id(data.id, parent_basic_id)
    parent = data.node_list.get(parent_id, True)

    map = data.map.get()
    user = data.user.get(True)
    node.respawn_dependency_with_enemy(map, parent, user, now)

    return node.arise_event(NodeInfo.EVENT_TYPE_JUNGLE, now)
Ejemplo n.º 23
0
def _get_all_enemy_neighbor_count(data):
    """获得我方总临近地城数目
    """
    node_list = data.node_list.get_all(True)
    count = 0
    for node in node_list:
        if node.is_own_side():
            continue
        for basic_id in MapGraph().get_neighbors(node.basic_id):
            neighbor_id = NodeInfo.generate_id(data.id, basic_id)
            neighbor = data.node_list.get(neighbor_id)
            if neighbor.is_own_side():
                count += 1
                break

    return count
Ejemplo n.º 24
0
def arise_gold_event(data, node, now, **kwargs):
    """出现金矿事件
    1 附属点变活跃
    2 附属点出现金矿资源信息
    """
    change_nodes = kwargs["change_nodes"]

    parent_basic_id = MapGraph().get_parent(node.basic_id)
    parent_id = NodeInfo.generate_id(data.id, parent_basic_id)
    parent = data.node_list.get(parent_id, True)

    map = data.map.get()
    user = data.user.get(True)
    node.respawn_dependency_with_gold(map, parent, now)

    return node.arise_event(NodeInfo.EVENT_TYPE_GOLD, now)
Ejemplo n.º 25
0
def finish_battle(data, worldboss, result, kill_soldier_num, now):
    """结束世界boss战斗
    """
    
    if worldboss.is_killed():
        ret = WorldBossInfo.BOSS_KILLED
    elif not worldboss.is_in_battle_time(now, True) and worldboss.is_attack_overtime(now):
        ret = WorldBossInfo.BOSS_OVERTIME
    else:
        ret = WorldBossInfo.BOSS_OK

    worldboss.finish_battle(result, kill_soldier_num, now)
    node_basic_id = worldboss.get_node_basic_id()
    node_id = NodeInfo.generate_id(data.id, node_basic_id)
    _update_worldboss_rival(data, worldboss, node_id)
    return ret
Ejemplo n.º 26
0
Archivo: map.py Proyecto: hw233/test-2
def is_key_node_isolated(data, node):
    """
    计算关键点是否孤立:相邻的没有己方关键点
    """
    assert node.is_key_node()

    for basic_id in MapGraph().get_neighbors(node.basic_id):
        neighbor_id = NodeInfo.generate_id(data.id, basic_id)
        neighbor = data.node_list.get(neighbor_id, True)  #readonly
        logger.debug(
            "node has neighbor[basic id=%d]"
            "[neighbor basic id=%d][neighbor own side=%r]" %
            (node.basic_id, neighbor.basic_id, neighbor.is_own_side()))
        if neighbor.is_own_side():
            return False

    return True
Ejemplo n.º 27
0
    def _calc_search_visit(self, data, req, timer):
        """查询探访逻辑
        """
        node_basic_id = req.node.basic_id
        node_id = NodeInfo.generate_id(data.id, node_basic_id)
        node = data.node_list.get(node_id)

        candidate = []
        if not visit_business.search_visit_event(data, node, candidate,
                                                 timer.now):
            raise Exception("Search visit failed")

        res = self._pack_search_visit_response(candidate)

        defer = DataBase().commit(data)
        defer.addCallback(self._search_visit_succeed, req, res, timer)
        return defer
Ejemplo n.º 28
0
    def _calc_finish_appoint(self, data, req, timer):
        node_id = NodeInfo.generate_id(data.id, req.node.basic_id)
        node = data.node_list.get(node_id)
        battle = data.battle_list.get(node_id)

        #存活兵力信息
        own_soldier_info = battle.get_own_soldier_info()
        enemy_soldier_info = battle.get_enemy_soldier_info()

        change_nodes = []
        items = []
        heroes = []
        mails = []

        ret = Ret()
        if not appoint_business.finish_appoint(
                data, node, battle, change_nodes, items, heroes, mails,
                timer.now, ret):
            if ret.get() == "FINISHED":
                res = appoint_pb2.FinishAppointRes()
                res.status = 0
                res.ret = appoint_pb2.FinishAppointRes.FINISHED
                pack.pack_node_info(data, node, res.node, timer.now)
                return self._finish_appoint_succeed(data, req, res, timer)
            else:
                raise Exception("Finish appoint failed")

        #为新刷出的敌方节点匹配敌人
        invalid_rival = [data.id]
        for node in data.node_list.get_all(True):
            if node.is_rival_pvp() and node.is_enemy_complete():
                rival_id = node.id
                rival = data.rival_list.get(rival_id, True)
                invalid_rival.append(rival.rival_id)

        user = data.user.get(True)
        matcher = RivalMatcher(user.level, invalid_rival)
        for node in change_nodes:
            if node.is_lack_enemy_detail():
                matcher.add_condition(data, node)

        defer = matcher.match(user.country)
        defer.addCallback(self._pack_finish_appoint_response, data,
                          change_nodes, items, heroes, mails, req, timer)
        return defer
Ejemplo n.º 29
0
Archivo: map.py Proyecto: hw233/test-2
def abandon_key_node(data, node, now, change_nodes):
    """主动丢弃己方关键点:键点从己方占有,变为敌方占有
       1.如果有可见附属点,不能丢弃
       2.如果node上在战斗或者有随机事件,不能丢弃
       3.变更节点状态
        a 如果是孤立节点,变为不可见
        b 否则,生成新敌方节点
       4.邻接的敌方关键点,如果是孤立节点,视野消失
    """
    if not node.is_able_to_abandon(now):
        logger.debug("node is not able to abandon[basic id=%d]" %
                     node.basic_id)
        return False

    #如果有附属点则不可丢弃
    for basic_id in MapGraph().get_children(node.basic_id):
        child_id = NodeInfo.generate_id(data.id, basic_id)
        child = data.node_list.get(child_id)

        if child.is_dependency_active():
            logger.debug("child dependency node is active[basic id=%d]" %
                         child.basic_id)
            return False

    map = data.map.get()
    user = data.user.get(True)

    #清除节点
    if not clear_key_node(data, node):
        logger.debug("clear key node failed[basic id=%d]" % node.basic_id)
        return False

    #当关键点不是孤立的时候,是可见的,生成新的敌方关键点
    #is_dungeon = False
    #if not is_key_node_isolated(data, node):
    #    if not respawn_enemy_key_node(data, node, now, is_dungeon):
    #        return False

    change_nodes.append(node)

    new_items = []
    new_mails = []

    return _post_lost_key_node(data, map, node, now, now, change_nodes,
                               new_items, new_mails)
Ejemplo n.º 30
0
    def _calc_clear_lucky_event(self, data, req, timer):
        """
        """
        node_basic_id = req.node.basic_id
        node_id = NodeInfo.generate_id(data.id, node_basic_id)
        node = data.node_list.get(node_id)

        change_nodes = []
        new_items = []
        new_mails = []

        ret = Ret()
        if not event_business.clear_lucky_event(
                data, node, timer.now, change_nodes, new_items, new_mails,
                ret):
            if ret.get() == "NO_EVENT":
                res = map_pb2.ClearLuckyEventRes()
                res.status = 0
                res.ret = map_pb2.ClearLuckyEventRes.NO_EVENT
                pack.pack_node_info(data, node, res.node, timer.now)
                return self._clear_lucky_event_succeed(data, req, res, timer)
            else:
                raise Exception("Clear lucky event failed")

        #为新刷出的敌方节点匹配敌人
        #不合法的敌人:自己,以及已经在地图上出现过的 PVP 敌人
        invalid_rival = [data.id]
        for node in data.node_list.get_all(True):
            if node.is_rival_pvp() and node.is_enemy_complete():
                rival_id = node.id
                rival = data.rival_list.get(rival_id, True)
                invalid_rival.append(rival.rival_id)

        user = data.user.get(True)
        matcher = RivalMatcher(user.level, invalid_rival)

        for node in change_nodes:
            if node.is_lack_enemy_detail():
                matcher.add_condition(data, node)

        defer = matcher.match(user.country)
        defer.addCallback(self._pack_clear_lucky_event_response, data,
                          change_nodes, new_items, new_mails, req, timer)
        return defer