diff --git a/src/factory/PlayerbotFactory.cpp b/src/factory/PlayerbotFactory.cpp index 585f2633..7e25e285 100644 --- a/src/factory/PlayerbotFactory.cpp +++ b/src/factory/PlayerbotFactory.cpp @@ -40,6 +40,7 @@ #include "StatsWeightCalculator.h" #include "World.h" #include "AiObjectContext.h" +#include "ItemPackets.h" const uint64 diveMask = (1LL << 7) | (1LL << 44) | (1LL << 37) | (1LL << 38) | (1LL << 26) | (1LL << 30) | (1LL << 27) | (1LL << 33) | (1LL << 24) | (1LL << 34); @@ -1899,7 +1900,9 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance) WorldPacket packet(CMSG_AUTOSTORE_BAG_ITEM, 3); packet << bagIndex << slot << dstBag; - bot->GetSession()->HandleAutoStoreBagItemOpcode(packet); + WorldPackets::Item::AutoStoreBagItem nicePacket(std::move(packet)); + nicePacket.Read(); + bot->GetSession()->HandleAutoStoreBagItemOpcode(nicePacket); } oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); diff --git a/src/strategy/actions/EquipAction.cpp b/src/strategy/actions/EquipAction.cpp index 08e1d390..7ce3546b 100644 --- a/src/strategy/actions/EquipAction.cpp +++ b/src/strategy/actions/EquipAction.cpp @@ -4,6 +4,7 @@ */ #include "EquipAction.h" +#include #include "Event.h" #include "ItemCountValue.h" @@ -11,6 +12,7 @@ #include "ItemVisitors.h" #include "Playerbots.h" #include "StatsWeightCalculator.h" +#include "ItemPackets.h" bool EquipAction::Execute(Event event) { @@ -104,7 +106,10 @@ void EquipAction::EquipItem(Item* item) WorldPacket packet(CMSG_AUTOEQUIP_ITEM_SLOT, 2); ObjectGuid itemguid = item->GetGUID(); packet << itemguid << uint8(EQUIPMENT_SLOT_RANGED); - bot->GetSession()->HandleAutoEquipItemSlotOpcode(packet); + + WorldPackets::Item::AutoEquipItemSlot nicePacket(std::move(packet)); + nicePacket.Read(); + bot->GetSession()->HandleAutoEquipItemSlotOpcode(nicePacket); std::ostringstream out; out << "Equipping " << chat->FormatItem(itemProto) << " in ranged slot"; @@ -199,7 +204,9 @@ void EquipAction::EquipItem(Item* item) WorldPacket eqPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2); ObjectGuid newItemGuid = item->GetGUID(); eqPacket << newItemGuid << uint8(EQUIPMENT_SLOT_MAINHAND); - bot->GetSession()->HandleAutoEquipItemSlotOpcode(eqPacket); + WorldPackets::Item::AutoEquipItemSlot nicePacket(std::move(eqPacket)); + nicePacket.Read(); + bot->GetSession()->HandleAutoEquipItemSlotOpcode(nicePacket); } // Try moving old main hand weapon to offhand if beneficial @@ -210,7 +217,9 @@ void EquipAction::EquipItem(Item* item) WorldPacket offhandPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2); ObjectGuid oldMHGuid = mainHandItem->GetGUID(); offhandPacket << oldMHGuid << uint8(EQUIPMENT_SLOT_OFFHAND); - bot->GetSession()->HandleAutoEquipItemSlotOpcode(offhandPacket); + WorldPackets::Item::AutoEquipItemSlot nicePacket(std::move(offhandPacket)); + nicePacket.Read(); + bot->GetSession()->HandleAutoEquipItemSlotOpcode(nicePacket); std::ostringstream moveMsg; moveMsg << "Main hand upgrade found. Moving " << chat->FormatItem(oldMHProto) << " to offhand"; @@ -230,7 +239,9 @@ void EquipAction::EquipItem(Item* item) WorldPacket eqPacket(CMSG_AUTOEQUIP_ITEM_SLOT, 2); ObjectGuid newItemGuid = item->GetGUID(); eqPacket << newItemGuid << uint8(EQUIPMENT_SLOT_OFFHAND); - bot->GetSession()->HandleAutoEquipItemSlotOpcode(eqPacket); + WorldPackets::Item::AutoEquipItemSlot nicePacket(std::move(eqPacket)); + nicePacket.Read(); + bot->GetSession()->HandleAutoEquipItemSlotOpcode(nicePacket); std::ostringstream out; out << "Equipping " << chat->FormatItem(itemProto) << " in offhand"; @@ -287,7 +298,9 @@ void EquipAction::EquipItem(Item* item) WorldPacket packet(CMSG_AUTOEQUIP_ITEM_SLOT, 2); ObjectGuid itemguid = item->GetGUID(); packet << itemguid << dstSlot; - bot->GetSession()->HandleAutoEquipItemSlotOpcode(packet); + WorldPackets::Item::AutoEquipItemSlot nicePacket(std::move(packet)); + nicePacket.Read(); + bot->GetSession()->HandleAutoEquipItemSlotOpcode(nicePacket); } } diff --git a/src/strategy/actions/OutfitAction.cpp b/src/strategy/actions/OutfitAction.cpp index 32a8424e..e886a711 100644 --- a/src/strategy/actions/OutfitAction.cpp +++ b/src/strategy/actions/OutfitAction.cpp @@ -8,6 +8,7 @@ #include "Event.h" #include "ItemVisitors.h" #include "Playerbots.h" +#include "ItemPackets.h" bool OutfitAction::Execute(Event event) { @@ -70,7 +71,9 @@ bool OutfitAction::Execute(Event event) WorldPacket packet(CMSG_AUTOSTORE_BAG_ITEM, 3); packet << bagIndex << slot << dstBag; - bot->GetSession()->HandleAutoStoreBagItemOpcode(packet); + WorldPackets::Item::AutoStoreBagItem nicePacket(std::move(packet)); + nicePacket.Read(); + bot->GetSession()->HandleAutoStoreBagItemOpcode(nicePacket); } EquipItems(outfit); diff --git a/src/strategy/actions/SellAction.cpp b/src/strategy/actions/SellAction.cpp index ea8021ab..1164c01a 100644 --- a/src/strategy/actions/SellAction.cpp +++ b/src/strategy/actions/SellAction.cpp @@ -9,6 +9,7 @@ #include "ItemUsageValue.h" #include "ItemVisitors.h" #include "Playerbots.h" +#include "ItemPackets.h" class SellItemsVisitor : public IterateItemsVisitor { @@ -116,7 +117,10 @@ void SellAction::Sell(Item* item) WorldPacket p; p << vendorguid << itemguid << count; - bot->GetSession()->HandleSellItemOpcode(p); + + WorldPackets::Item::SellItem nicePacket(std::move(p)); + nicePacket.Read(); + bot->GetSession()->HandleSellItemOpcode(nicePacket); if (botAI->HasCheat(BotCheatMask::gold)) { diff --git a/src/strategy/actions/UnequipAction.cpp b/src/strategy/actions/UnequipAction.cpp index def974bb..9a32f5cc 100644 --- a/src/strategy/actions/UnequipAction.cpp +++ b/src/strategy/actions/UnequipAction.cpp @@ -8,6 +8,8 @@ #include "Event.h" #include "ItemCountValue.h" #include "Playerbots.h" +#include "WorldSession.h" +#include "ItemPackets.h" std::vector split(std::string const s, char delim); @@ -70,7 +72,9 @@ void UnequipAction::UnequipItem(Item* item) WorldPacket packet(CMSG_AUTOSTORE_BAG_ITEM, 3); packet << bagIndex << slot << dstBag; - bot->GetSession()->HandleAutoStoreBagItemOpcode(packet); + WorldPackets::Item::AutoStoreBagItem nicePacket(std::move(packet)); + nicePacket.Read(); + bot->GetSession()->HandleAutoStoreBagItemOpcode(nicePacket); std::ostringstream out; out << chat->FormatItem(item->GetTemplate()) << " unequipped"; diff --git a/src/strategy/actions/UseItemAction.cpp b/src/strategy/actions/UseItemAction.cpp index 2654c1fa..85c56c63 100644 --- a/src/strategy/actions/UseItemAction.cpp +++ b/src/strategy/actions/UseItemAction.cpp @@ -9,6 +9,7 @@ #include "Event.h" #include "ItemUsageValue.h" #include "Playerbots.h" +#include "ItemPackets.h" bool UseItemAction::Execute(Event event) { @@ -324,8 +325,8 @@ void UseItemAction::TellConsumableUse(Item* item, std::string const action, floa bool UseItemAction::SocketItem(Item* item, Item* gem, bool replace) { - WorldPacket* const packet = new WorldPacket(CMSG_SOCKET_GEMS); - *packet << item->GetGUID(); + WorldPacket packet(CMSG_SOCKET_GEMS); + packet << item->GetGUID(); bool fits = false; for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; @@ -337,14 +338,14 @@ bool UseItemAction::SocketItem(Item* item, Item* gem, bool replace) { if (fits) { - *packet << ObjectGuid::Empty; + packet << ObjectGuid::Empty; continue; } uint32 enchant_id = item->GetEnchantmentId(EnchantmentSlot(enchant_slot)); if (!enchant_id) { - *packet << gem->GetGUID(); + packet << gem->GetGUID(); fits = true; continue; } @@ -352,20 +353,20 @@ bool UseItemAction::SocketItem(Item* item, Item* gem, bool replace) SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id); if (!enchantEntry || !enchantEntry->GemID) { - *packet << gem->GetGUID(); + packet << gem->GetGUID(); fits = true; continue; } if (replace && enchantEntry->GemID != gem->GetTemplate()->ItemId) { - *packet << gem->GetGUID(); + packet << gem->GetGUID(); fits = true; continue; } } - *packet << ObjectGuid::Empty; + packet << ObjectGuid::Empty; } if (fits) @@ -375,7 +376,9 @@ bool UseItemAction::SocketItem(Item* item, Item* gem, bool replace) out << " with " << chat->FormatItem(gem->GetTemplate()); botAI->TellMaster(out); - bot->GetSession()->HandleSocketOpcode(*packet); + WorldPackets::Item::SocketGems nicePacket(std::move(packet)); + nicePacket.Read(); + bot->GetSession()->HandleSocketOpcode(nicePacket); } return fits;