Skip to content

Commit

Permalink
Core/PacketIO: Refactor LootPackets to use new Bits<> writing utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Dec 27, 2024
1 parent aefcd2f commit 28d3c1b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/server/game/Loot/Loot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,7 @@ void Loot::BuildLootResponse(WorldPackets::Loot::LootResponse& packet, Player co
{
WorldPackets::Loot::LootItemData& lootItem = packet.Items.emplace_back();
lootItem.LootListID = item.LootListId;
lootItem.Type = item.type;
lootItem.UIType = *uiType;
lootItem.Quantity = item.count;
lootItem.Loot.Initialize(item);
Expand Down
85 changes: 46 additions & 39 deletions src/server/game/Server/Packets/LootPackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

#include "LootPackets.h"

ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Loot::LootItemData const& lootItem)
namespace WorldPackets::Loot
{
data.WriteBits(lootItem.Type, 2);
data.WriteBits(lootItem.UIType, 3);
data.WriteBit(lootItem.CanTradeToTapList);
static ByteBuffer& operator<<(ByteBuffer& data, LootItemData const& lootItem)
{
data << Bits<2>(lootItem.Type);
data << Bits<3>(lootItem.UIType);
data << Bits<1>(lootItem.CanTradeToTapList);
data.FlushBits();
data << lootItem.Loot; // WorldPackets::Item::ItemInstance
data << uint32(lootItem.Quantity);
Expand All @@ -30,12 +32,22 @@ ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Loot::LootItemData const&
return data;
}

void WorldPackets::Loot::LootUnit::Read()
static ByteBuffer& operator<<(ByteBuffer& data, LootCurrency const& lootCurrency)
{
data << uint32(lootCurrency.CurrencyID);
data << uint32(lootCurrency.Quantity);
data << uint8(lootCurrency.LootListID);
data << Bits<3>(lootCurrency.UIType);
data.FlushBits();
return data;
}

void LootUnit::Read()
{
_worldPacket >> Unit;
}

WorldPacket const* WorldPackets::Loot::LootResponse::Write()
WorldPacket const* LootResponse::Write()
{
_worldPacket << Owner;
_worldPacket << LootObj;
Expand All @@ -55,18 +67,12 @@ WorldPacket const* WorldPackets::Loot::LootResponse::Write()
_worldPacket << item;

for (LootCurrency const& currency : Currencies)
{
_worldPacket << uint32(currency.CurrencyID);
_worldPacket << uint32(currency.Quantity);
_worldPacket << uint8(currency.LootListID);
_worldPacket.WriteBits(currency.UIType, 3);
_worldPacket.FlushBits();
}
_worldPacket << currency;

return &_worldPacket;
}

void WorldPackets::Loot::LootItem::Read()
void LootItem::Read()
{
uint32 Count;
_worldPacket >> Count;
Expand All @@ -78,10 +84,10 @@ void WorldPackets::Loot::LootItem::Read()
_worldPacket >> Loot[i].LootListID;
}

IsSoftInteract = _worldPacket.ReadBit();
_worldPacket >> Bits<1>(IsSoftInteract);
}

void WorldPackets::Loot::MasterLootItem::Read()
void MasterLootItem::Read()
{
uint32 Count;
_worldPacket >> Count;
Expand All @@ -95,7 +101,7 @@ void WorldPackets::Loot::MasterLootItem::Read()
}
}

WorldPacket const* WorldPackets::Loot::LootRemoved::Write()
WorldPacket const* LootRemoved::Write()
{
_worldPacket << Owner;
_worldPacket << LootObj;
Expand All @@ -104,55 +110,55 @@ WorldPacket const* WorldPackets::Loot::LootRemoved::Write()
return &_worldPacket;
}

void WorldPackets::Loot::LootRelease::Read()
void LootRelease::Read()
{
_worldPacket >> Unit;
}

void WorldPackets::Loot::LootMoney::Read()
void LootMoney::Read()
{
IsSoftInteract = _worldPacket.ReadBit();
_worldPacket >> Bits<1>(IsSoftInteract);
}

WorldPacket const* WorldPackets::Loot::LootMoneyNotify::Write()
WorldPacket const* LootMoneyNotify::Write()
{
_worldPacket << uint64(Money);
_worldPacket << uint64(MoneyMod);
_worldPacket.WriteBit(SoleLooter);
_worldPacket << Bits<1>(SoleLooter);
_worldPacket.FlushBits();

return &_worldPacket;
}

WorldPacket const* WorldPackets::Loot::CoinRemoved::Write()
WorldPacket const* CoinRemoved::Write()
{
_worldPacket << LootObj;

return &_worldPacket;
}

void WorldPackets::Loot::LootRoll::Read()
void LootRoll::Read()
{
_worldPacket >> LootObj;
_worldPacket >> LootListID;
_worldPacket >> RollType;
}

WorldPacket const* WorldPackets::Loot::LootReleaseResponse::Write()
WorldPacket const* LootReleaseResponse::Write()
{
_worldPacket << LootObj;
_worldPacket << Owner;

return &_worldPacket;
}

WorldPacket const* WorldPackets::Loot::LootList::Write()
WorldPacket const* LootList::Write()
{
_worldPacket << Owner;
_worldPacket << LootObj;

_worldPacket.WriteBit(Master.has_value());
_worldPacket.WriteBit(RoundRobinWinner.has_value());
_worldPacket << OptionalInit(Master);
_worldPacket << OptionalInit(RoundRobinWinner);

_worldPacket.FlushBits();

Expand All @@ -165,12 +171,12 @@ WorldPacket const* WorldPackets::Loot::LootList::Write()
return &_worldPacket;
}

void WorldPackets::Loot::SetLootSpecialization::Read()
void SetLootSpecialization::Read()
{
_worldPacket >> SpecID;
}

WorldPacket const* WorldPackets::Loot::StartLootRoll::Write()
WorldPacket const* StartLootRoll::Write()
{
_worldPacket << LootObj;
_worldPacket << int32(MapID);
Expand All @@ -184,36 +190,36 @@ WorldPacket const* WorldPackets::Loot::StartLootRoll::Write()
return &_worldPacket;
}

WorldPacket const* WorldPackets::Loot::LootRollBroadcast::Write()
WorldPacket const* LootRollBroadcast::Write()
{
_worldPacket << LootObj;
_worldPacket << Player;
_worldPacket << int32(Roll);
_worldPacket << uint8(RollType);
_worldPacket << int32(DungeonEncounterID);
_worldPacket << Item;
_worldPacket.WriteBit(Autopassed);
_worldPacket.WriteBit(OffSpec);
_worldPacket << Bits<1>(Autopassed);
_worldPacket << Bits<1>(OffSpec);
_worldPacket.FlushBits();

return &_worldPacket;
}

WorldPacket const* WorldPackets::Loot::LootRollWon::Write()
WorldPacket const* LootRollWon::Write()
{
_worldPacket << LootObj;
_worldPacket << Winner;
_worldPacket << int32(Roll);
_worldPacket << uint8(RollType);
_worldPacket << int32(DungeonEncounterID);
_worldPacket << Item;
_worldPacket.WriteBit(MainSpec);
_worldPacket << Bits<1>(MainSpec);
_worldPacket.FlushBits();

return &_worldPacket;
}

WorldPacket const* WorldPackets::Loot::LootAllPassed::Write()
WorldPacket const* LootAllPassed::Write()
{
_worldPacket << LootObj;
_worldPacket << int32(DungeonEncounterID);
Expand All @@ -222,7 +228,7 @@ WorldPacket const* WorldPackets::Loot::LootAllPassed::Write()
return &_worldPacket;
}

WorldPacket const* WorldPackets::Loot::LootRollsComplete::Write()
WorldPacket const* LootRollsComplete::Write()
{
_worldPacket << LootObj;
_worldPacket << uint8(LootListID);
Expand All @@ -231,7 +237,7 @@ WorldPacket const* WorldPackets::Loot::LootRollsComplete::Write()
return &_worldPacket;
}

WorldPacket const* WorldPackets::Loot::MasterLootCandidateList::Write()
WorldPacket const* MasterLootCandidateList::Write()
{
_worldPacket << LootObj;
_worldPacket << uint32(Players.size());
Expand All @@ -241,9 +247,10 @@ WorldPacket const* WorldPackets::Loot::MasterLootCandidateList::Write()
return &_worldPacket;
}

WorldPacket const* WorldPackets::Loot::AELootTargets::Write()
WorldPacket const* AELootTargets::Write()
{
_worldPacket << uint32(Count);

return &_worldPacket;
}
}
7 changes: 4 additions & 3 deletions src/server/game/Server/Packets/LootPackets.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#ifndef LootPackets_h__
#define LootPackets_h__

#include "Packet.h"
#include "ObjectGuid.h"
#include "ItemPacketsCommon.h"
#include "LootItemType.h"
#include "ObjectGuid.h"
#include "Packet.h"

enum class LootRollIneligibilityReason : uint32;

Expand All @@ -40,7 +41,7 @@ namespace WorldPackets

struct LootItemData
{
uint8 Type = 0;
::LootItemType Type = LootItemType::Item;
uint8 UIType = 0;
uint32 Quantity = 0;
uint8 LootItemType = 0;
Expand Down

0 comments on commit 28d3c1b

Please sign in to comment.