Ejemplo n.º 1
0
    def send_inventory_list(self, world_session):
        vendor_data, session = WorldDatabaseManager.creature_get_vendor_data(self.entry)
        item_count = len(vendor_data) if vendor_data else 0

        data = pack(
            '<QB',
            self.guid,
            item_count
        )

        if item_count == 0:
            data += pack('<B', 0)
        else:
            for vendor_data_entry in vendor_data:
                data += pack(
                    '<7I',
                    1,  # mui
                    vendor_data_entry.item,
                    vendor_data_entry.item_template.display_id,
                    0xFFFFFFFF if vendor_data_entry.maxcount <= 0 else vendor_data_entry.maxcount,
                    vendor_data_entry.item_template.buy_price,
                    0,  # durability
                    0,  # stack count
                )
                world_session.enqueue_packet(ItemManager(item_template=vendor_data_entry.item_template).query_details())

        session.close()
        world_session.enqueue_packet(PacketWriter.get_packet(OpCode.SMSG_LIST_INVENTORY, data))
Ejemplo n.º 2
0
    def load_items(self):
        # Add backpack
        self.containers[InventorySlots.SLOT_INBACKPACK] = ContainerManager(
            is_backpack=True, owner=self.owner.guid)

        character_inventory = RealmDatabaseManager.character_get_inventory(
            self.owner.guid)

        # First load bags
        for item_instance in character_inventory:
            item_template = WorldDatabaseManager.item_template_get_by_entry(
                item_instance.item_template)
            if item_template and item_template.inventory_type == InventoryTypes.BAG:
                container_mgr = ContainerManager(owner=self.owner.guid,
                                                 item_template=item_template,
                                                 item_instance=item_instance)
                if self.is_bag_pos(container_mgr.current_slot):
                    self.containers[item_instance.bag].sorted_slots[
                        container_mgr.current_slot] = container_mgr
                    self.containers[container_mgr.current_slot] = container_mgr

        # Then load items
        for item_instance in character_inventory:
            item_template = WorldDatabaseManager.item_template_get_by_entry(
                item_instance.item_template)
            if item_template:
                item_mgr = ItemManager(item_template=item_template,
                                       item_instance=item_instance)
                if item_mgr.is_container() and self.is_bag_pos(
                        item_mgr.current_slot):
                    continue
                if item_instance.bag in self.containers:
                    self.containers[item_instance.bag].sorted_slots[
                        item_mgr.current_slot] = item_mgr
Ejemplo n.º 3
0
    def send_inventory_list(self, world_session):
        vendor_data, session = WorldDatabaseManager.creature_get_vendor_data(self.entry)
        item_count = len(vendor_data) if vendor_data else 0

        data = pack(
            '<QB',
            self.guid,
            item_count
        )

        if item_count == 0:
            data += pack('<B', 0)
        else:
            for count, vendor_data_entry in enumerate(vendor_data):
                data += pack(
                    '<7I',
                    count + 1,  # m_muid, acts as slot counter.
                    vendor_data_entry.item,
                    vendor_data_entry.item_template.display_id,
                    0xFFFFFFFF if vendor_data_entry.maxcount <= 0 else vendor_data_entry.maxcount,
                    vendor_data_entry.item_template.buy_price,
                    vendor_data_entry.item_template.max_durability,  # Max durability (not implemented in 0.5.3).
                    vendor_data_entry.item_template.buy_count  # Stack count.
                )
                world_session.enqueue_packet(ItemManager(item_template=vendor_data_entry.item_template).query_details())

        session.close()
        world_session.enqueue_packet(PacketWriter.get_packet(OpCode.SMSG_LIST_INVENTORY, data))
Ejemplo n.º 4
0
    def handle(world_session, socket, reader):
        if len(reader.data) >= 4:  # Avoid handling empty item query packet.
            entry = unpack('<I', reader.data[:4])[0]
            if entry > 0:
                item_template = WorldDatabaseManager.ItemTemplateHolder.item_template_get_by_entry(
                    entry)
                if item_template:
                    item_mgr = ItemManager(item_template=item_template)
                    world_session.enqueue_packet(item_mgr.query_details())

        return 0
Ejemplo n.º 5
0
    def _gen_item_struct(self, item_entry, count):
        item_template = WorldDatabaseManager.ItemTemplateHolder.item_template_get_by_entry(
            item_entry)
        display_id = 0
        if item_template:
            item_mgr = ItemManager(item_template=item_template)
            self.player_mgr.enqueue_packet(item_mgr.query_details())
            display_id = item_template.display_id

        item_data = pack('<3I', item_entry, count, display_id)

        return item_data
Ejemplo n.º 6
0
    def load_items(self):
        character_inventory = RealmDatabaseManager.character_get_inventory(
            self.owner.guid)

        # First load bags
        for item_instance in character_inventory:
            item_template = WorldDatabaseManager.ItemTemplateHolder.item_template_get_by_entry(
                item_instance.item_template)
            if item_template and item_template.inventory_type == InventoryTypes.BAG:
                container_mgr = ContainerManager(owner=self.owner.guid,
                                                 item_template=item_template,
                                                 item_instance=item_instance)
                if self.is_bag_pos(container_mgr.current_slot):
                    if item_instance.bag > 23:
                        low_guid = container_mgr.guid & ~HighGuid.HIGHGUID_CONTAINER
                        Logger.warning(
                            f'Invalid bag slot {item_instance.bag} for guid {low_guid} owner {self.owner.guid}'
                        )
                        continue
                    self.containers[item_instance.bag].sorted_slots[
                        container_mgr.current_slot] = container_mgr
                    self.containers[container_mgr.current_slot] = container_mgr

        # Then load items
        for item_instance in character_inventory:
            item_template = WorldDatabaseManager.ItemTemplateHolder.item_template_get_by_entry(
                item_instance.item_template)
            if item_template:
                if item_template.display_id > MAX_3368_ITEM_DISPLAY_ID and \
                        self.is_equipment_pos(item_instance.bag, item_instance.slot):
                    Logger.error(
                        f'Character {self.owner.player.name} has an equipped item ({item_template.entry} - {item_template.name}) '
                        f'with out of bounds display_id ({item_template.display_id}), '
                        f'deleting in order to prevent crashes.')
                    RealmDatabaseManager.character_inventory_delete(
                        item_instance)
                    continue

                if item_template.inventory_type == InventoryTypes.BAG:
                    if self.is_bag_pos(item_instance.slot):
                        continue

                    item_mgr = ContainerManager(owner=self.owner.guid,
                                                item_template=item_template,
                                                item_instance=item_instance)
                else:
                    item_mgr = ItemManager(item_template=item_template,
                                           item_instance=item_instance)

                if item_instance.bag in self.containers and self.containers[
                        item_instance.bag]:
                    self.containers[item_instance.bag].sorted_slots[
                        item_mgr.current_slot] = item_mgr
Ejemplo n.º 7
0
    def load_items(self):
        # Add backpack
        self.containers[InventorySlots.SLOT_INBACKPACK] = ContainerManager(
            is_backpack=True, owner=self.owner.guid)

        character_inventory = RealmDatabaseManager.character_get_inventory(
            self.owner.guid)

        # First load bags
        for item_instance in character_inventory:
            item_template = WorldDatabaseManager.item_template_get_by_entry(
                item_instance.item_template)
            if item_template and item_template.inventory_type == InventoryTypes.BAG:
                container_mgr = ContainerManager(owner=self.owner.guid,
                                                 item_template=item_template,
                                                 item_instance=item_instance)
                if self.is_bag_pos(container_mgr.current_slot):
                    self.containers[item_instance.bag].sorted_slots[
                        container_mgr.current_slot] = container_mgr
                    self.containers[container_mgr.current_slot] = container_mgr

        # Then load items
        for item_instance in character_inventory:
            item_template = WorldDatabaseManager.item_template_get_by_entry(
                item_instance.item_template)
            if item_template:
                if item_template.display_id > MAX_3368_ITEM_DISPLAY_ID and \
                        self.is_equipment_pos(item_instance.bag, item_instance.slot):
                    Logger.error(
                        'Character %s has an equipped item (%u - %s) with out of bounds display_id (%u), '
                        'deleting in order to prevent crashes.' %
                        (self.owner.player.name, item_template.entry,
                         item_template.name, item_template.display_id))
                    RealmDatabaseManager.character_inventory_delete(
                        item_instance)
                    continue

                if item_template.inventory_type == InventoryTypes.BAG:
                    if self.is_bag_pos(item_instance.slot):
                        continue

                    item_mgr = ContainerManager(owner=self.owner.guid,
                                                item_template=item_template,
                                                item_instance=item_instance)
                else:
                    item_mgr = ItemManager(item_template=item_template,
                                           item_instance=item_instance)
                if item_instance.bag in self.containers:
                    self.containers[item_instance.bag].sorted_slots[
                        item_mgr.current_slot] = item_mgr

        self.set_base_attack_time()