Esempio n. 1
0
    def handle(world_session, socket, reader):
        if len(
                reader.data
        ) >= 12:  # Avoid handling empty quest giver complete quest packet.
            guid, quest_id = unpack('<QI', reader.data[:12])
            high_guid = ObjectManager.extract_high_guid(guid)

            quest_giver = None
            if high_guid == HighGuid.HIGHGUID_UNIT:
                quest_giver = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, guid)
            elif high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
                quest_giver = MapManager.get_surrounding_gameobject_by_guid(
                    world_session.player_mgr, guid)

            if not quest_giver:
                Logger.error(
                    f'Error in CMSG_QUESTGIVER_COMPLETE_QUEST, could not find quest giver with guid of: {guid}'
                )
                return 0
            if world_session.player_mgr.is_enemy_to(quest_giver):
                return 0

            world_session.player_mgr.quest_manager.handle_complete_quest(
                quest_id, guid)
        return 0
    def handle(world_session, socket, reader):
        if len(
                reader.data
        ) >= 12:  # Avoid handling empty quest giver request reward packet.
            guid, quest_id = unpack('<QI', reader.data[:12])
            high_guid = ObjectManager.extract_high_guid(guid)
            is_item = False

            quest_giver = None
            if high_guid == HighGuid.HIGHGUID_UNIT:
                quest_giver = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, guid)
            elif high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
                quest_giver = MapManager.get_surrounding_gameobject_by_guid(
                    world_session.player_mgr, guid)
            elif high_guid == HighGuid.HIGHGUID_ITEM:
                is_item = True
                quest_giver = world_session.player_mgr.inventory.get_item_by_guid(
                    guid)

            if not quest_giver:
                Logger.error(
                    f'Error in CMSG_QUESTGIVER_REQUEST_REWARD, could not find quest giver with guid: {guid}'
                )
                return 0

            if not is_item and world_session.player_mgr.is_enemy_to(
                    quest_giver):
                return 0

            world_session.player_mgr.quest_manager.handle_request_reward(
                guid, quest_id)
        return 0
    def handle(world_session, socket, reader):
        if len(
                reader.data
        ) >= 12:  # Avoid handling empty quest giver accept quest packet.
            guid, quest_id = unpack('<QI', reader.data[:12])
            high_guid = ObjectManager.extract_high_guid(guid)
            is_item = False

            quest_giver = None
            if high_guid == HighGuid.HIGHGUID_UNIT:
                quest_giver = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, guid)
            elif high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
                quest_giver = MapManager.get_surrounding_gameobject_by_guid(
                    world_session.player_mgr, guid)
            elif high_guid == HighGuid.HIGHGUID_ITEM:
                is_item = True
                quest_giver = world_session.player_mgr.inventory.get_item_by_guid(
                    guid)

            if not quest_giver:
                Logger.error(
                    f'Error in CMSG_QUESTGIVER_ACCEPT_QUEST, could not find quest giver with guid of: {guid}'
                )
                return 0
            elif not is_item and world_session.player_mgr.is_enemy_to(
                    quest_giver):
                return 0
            elif world_session.player_mgr.quest_manager.is_quest_log_full():
                world_session.enqueue_packet(
                    PacketWriter.get_packet(OpCode.SMSG_QUESTLOG_FULL))
            else:
                world_session.player_mgr.quest_manager.handle_accept_quest(
                    quest_id, guid, shared=False)
        return 0
    def handle(world_session, socket, reader: PacketReader) -> int:
        if len(reader.data
               ) >= 8:  # Avoid handling empty debug AI state packet.
            guid = unpack('<Q', reader.data[:8])[0]

            high_guid: HighGuid = ObjectManager.extract_high_guid(guid)
            if high_guid == HighGuid.HIGHGUID_UNIT or high_guid == HighGuid.HIGHGUID_PLAYER:
                world_object = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, guid, include_players=True)
            else:
                world_object = MapManager.get_surrounding_gameobject_by_guid(
                    world_session.player_mgr, guid)

            # No object with that Guid? Return.
            if not world_object:
                return 0

            messages: list[str] = world_object.get_debug_messages()
            data = pack('<QI', guid, len(messages))

            for message in messages:
                message_bytes = PacketWriter.string_to_bytes(
                    message[:127])  # Max length is 128 (127 + null byte).
                data += pack(f'<{len(message_bytes)}s', message_bytes)

            world_session.enqueue_packet(
                PacketWriter.get_packet(OpCode.SMSG_DEBUG_AISTATE, data))

        return 0
Esempio n. 5
0
    def is_quest_complete(self, quest_giver_guid):
        quest_giver = None
        high_guid = ObjectManager.extract_high_guid(quest_giver_guid)

        if high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
            quest_giver = MapManager.get_surrounding_gameobject_by_guid(self.owner, quest_giver_guid)
        elif high_guid == HighGuid.HIGHGUID_UNIT:
            quest_giver = MapManager.get_surrounding_unit_by_guid(self.owner, quest_giver_guid)

        if not quest_giver:
            return False

        if QuestHelpers.is_instant_complete_quest(self.quest):
            return True

        if self.db_state.state != QuestState.QUEST_REWARD:
            return False

        if quest_giver.get_type_id() == ObjectTypeIds.ID_UNIT and quest_giver.get_type_id() != ObjectTypeIds.ID_PLAYER:
            involved_relations_list = WorldDatabaseManager.QuestRelationHolder.creature_quest_finisher_get_by_entry(quest_giver.entry)
        elif quest_giver.get_type_id() == ObjectTypeIds.ID_GAMEOBJECT:
            involved_relations_list = WorldDatabaseManager.QuestRelationHolder.gameobject_quest_finisher_get_by_entry(quest_giver.entry)
        else:
            return False

        # Return if this quest is finished by this quest giver.
        return self.quest.entry in {quest_entry[1] for quest_entry in involved_relations_list}
    def handle(world_session, socket, reader):
        if len(reader.data
               ) >= 8:  # Avoid handling empty quest giver status packet.
            guid = unpack('<Q', reader.data[:8])[0]
            high_guid = ObjectManager.extract_high_guid(guid)

            quest_giver = None
            if high_guid == HighGuid.HIGHGUID_UNIT:
                quest_giver = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, guid)
            elif high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
                quest_giver = MapManager.get_surrounding_gameobject_by_guid(
                    world_session.player_mgr, guid)

            if not quest_giver:
                Logger.error(
                    f'Error in CMSG_QUESTGIVER_STATUS_QUERY, could not find quest giver with guid of: {guid}'
                )
                return 0

            # Only units are able to provide quest status.
            if world_session.player_mgr and quest_giver.get_type_id(
            ) == ObjectTypeIds.ID_UNIT:
                quest_giver_status = world_session.player_mgr.quest_manager.get_dialog_status(
                    quest_giver)
                world_session.player_mgr.quest_manager.send_quest_giver_status(
                    guid, quest_giver_status)

        return 0
    def handle(world_session, socket, reader):
        if len(reader.data
               ) >= 8:  # Avoid handling empty quest giver hello packet.
            guid = unpack('<Q', reader.data[:8])[0]
            high_guid = ObjectManager.extract_high_guid(guid)

            quest_giver = None
            if high_guid == HighGuid.HIGHGUID_UNIT:
                quest_giver = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, guid)
            elif high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
                quest_giver = MapManager.get_surrounding_gameobject_by_guid(
                    world_session.player_mgr, guid)

            if not quest_giver:
                Logger.error(
                    f'Error in CMSG_QUESTGIVER_HELLO, could not find quest giver with guid of: {guid}'
                )
                return 0
            if world_session.player_mgr.is_enemy_to(quest_giver):
                return 0

            # TODO: Stop the npc if it's moving
            # TODO: Remove feign death from player (if it even exists in 0.5.3)
            # TODO: If the gossip menu is already open, do nothing
            if quest_giver.is_within_interactable_distance(
                    world_session.player_mgr):
                world_session.player_mgr.quest_manager.handle_quest_giver_hello(
                    quest_giver, guid)

        return 0
Esempio n. 8
0
    def handle_accept_quest(self, quest_id, quest_giver_guid, shared=False):
        if quest_id in self.active_quests:
            self.send_cant_take_quest_response(QuestFailedReasons.QUEST_ALREADY_ON)
            return

        if quest_id in self.completed_quests:
            self.send_cant_take_quest_response(QuestFailedReasons.QUEST_ONLY_ONE_TIMED)
            return

        quest_item_starter = None
        if quest_giver_guid:
            quest_giver = None
            high_guid = ObjectManager.extract_high_guid(quest_giver_guid)

            if high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
                quest_giver = MapManager.get_surrounding_gameobject_by_guid(self.player_mgr, quest_giver_guid)
            elif high_guid == HighGuid.HIGHGUID_UNIT:
                quest_giver = MapManager.get_surrounding_unit_by_guid(self.player_mgr, quest_giver_guid)
            elif high_guid == HighGuid.HIGHGUID_ITEM:
                quest_giver = self.player_mgr.inventory.get_item_by_guid(quest_giver_guid)
                quest_item_starter = quest_giver

            if not quest_giver:
                return

        quest = WorldDatabaseManager.QuestTemplateHolder.quest_get_by_entry(quest_id)
        if not quest:
            return

        req_src_item = quest.SrcItemId
        req_src_item_count = quest.SrcItemCount
        if req_src_item != 0:
            # Check if the required source item is the item quest starter, else check if we can add it to the inventory.
            if not quest_item_starter or quest_item_starter.entry != req_src_item:
                if not self.player_mgr.inventory.add_item(req_src_item, count=req_src_item_count):
                    return

        active_quest = self._create_db_quest_status(quest)
        active_quest.save(is_new=True)
        self.add_to_quest_log(quest_id, active_quest)
        self.send_quest_query_response(quest)

        # If player is in a group and quest has QUEST_FLAGS_PARTY_ACCEPT flag, let other members accept it too.
        if self.player_mgr.group_manager and not shared:
            quest_template = WorldDatabaseManager.QuestTemplateHolder.quest_get_by_entry(quest_id)
            if quest_template and quest_template.QuestFlags & QuestFlags.QUEST_FLAGS_PARTY_ACCEPT:
                self.share_quest_event(active_quest)

        # Check if the player already has related items.
        active_quest.update_required_items_from_inventory()
        if active_quest.can_complete_quest():
            self.complete_quest(active_quest, update_surrounding=False)

        self.update_surrounding_quest_status()
Esempio n. 9
0
    def handle(world_session, socket, reader):
        if len(reader.data
               ) >= 8:  # Avoid handling empty quest giver query quest packet.
            guid, quest_entry = unpack('<QL', reader.data[:12])
            high_guid = ObjectManager.extract_high_guid(guid)

            # NPC
            if high_guid == HighGuid.HIGHGUID_UNIT:
                quest_giver = MapManager.get_surrounding_unit_by_guid(
                    world_session.player_mgr, guid)
                if not quest_giver:
                    return 0

                quest_giver_is_related = world_session.player_mgr.quest_manager.check_quest_giver_npc_is_related(
                    quest_giver.entry, quest_entry)
                if not quest_giver_is_related:
                    return 0
            # Gameobject
            elif high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
                quest_giver = MapManager.get_surrounding_gameobject_by_guid(
                    world_session, guid)
                if not quest_giver:
                    return 0
            # Item
            elif high_guid == HighGuid.HIGHGUID_ITEM:
                item_info = world_session.player_mgr.inventory.get_item_info_by_guid(
                    guid)
                if not item_info[3]:
                    return 0

                quest_giver = item_info[3].item_template
                quest_giver_is_related = quest_giver.start_quest == quest_entry
                if not quest_giver_is_related:
                    return 0
            else:
                Logger.error(
                    f'Error in CMSG_QUESTGIVER_QUERY_QUEST, unknown quest giver type.'
                )
                return 0

            quest = WorldDatabaseManager.QuestTemplateHolder.quest_get_by_entry(
                quest_entry)
            if not quest:
                Logger.error(
                    f'Error in CMSG_QUESTGIVER_QUERY_QUEST, could not find quest with an entry of: {quest_entry}'
                )
                return 0

            world_session.player_mgr.quest_manager.send_quest_giver_quest_details(
                quest, guid, True)

        return 0
    def handle(world_session, socket, reader):
        # CGPlayer_C::GetQuestReward
        if len(reader.data) >= 16:  # Avoid handling empty quest fiver choose reward packet.
            guid, quest_id, item_choice = unpack('<Q2I', reader.data[:16])
            high_guid = ObjectManager.extract_high_guid(guid)

            quest_giver = None
            if high_guid == HighGuid.HIGHGUID_UNIT:
                quest_giver = MapManager.get_surrounding_unit_by_guid(world_session.player_mgr, guid)
            elif high_guid == HighGuid.HIGHGUID_GAMEOBJECT:
                quest_giver = MapManager.get_surrounding_gameobject_by_guid(world_session.player_mgr, guid)

            if not quest_giver:
                Logger.error(f'Error in CMSG_QUESTGIVER_COMPLETE_QUEST, could not find quest giver with guid of: {guid}')
                return 0

            if world_session.player_mgr.is_enemy_to(quest_giver):
                return 0

            world_session.player_mgr.quest_manager.handle_choose_reward(guid, quest_id, item_choice)
        return 0