feat(Core/Misc): implement ObjectGuid class (port from TC) (#4885)

This commit is contained in:
UltraNix
2021-04-25 22:18:03 +02:00
committed by GitHub
parent 91081f4ad8
commit f4c226423d
568 changed files with 10655 additions and 11019 deletions

View File

@@ -247,15 +247,15 @@ Item::Item()
m_paidExtendedCost = 0;
}
bool Item::Create(uint32 guidlow, uint32 itemid, Player const* owner)
bool Item::Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const* owner)
{
Object::_Create(guidlow, 0, HIGHGUID_ITEM);
Object::_Create(guidlow, 0, HighGuid::Item);
SetEntry(itemid);
SetObjectScale(1.0f);
SetUInt64Value(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : 0);
SetUInt64Value(ITEM_FIELD_CONTAINED, owner ? owner->GetGUID() : 0);
SetGuidValue(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : ObjectGuid::Empty);
SetGuidValue(ITEM_FIELD_CONTAINED, owner ? owner->GetGUID() : ObjectGuid::Empty);
ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(itemid);
if (!itemProto)
@@ -309,7 +309,7 @@ void Item::SaveToDB(SQLTransaction& trans)
if (!isInTransaction)
trans = CharacterDatabase.BeginTransaction();
uint32 guid = GetGUIDLow();
ObjectGuid::LowType guid = GetGUID().GetCounter();
switch (uState)
{
case ITEM_NEW:
@@ -318,9 +318,9 @@ void Item::SaveToDB(SQLTransaction& trans)
uint8 index = 0;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(uState == ITEM_NEW ? CHAR_REP_ITEM_INSTANCE : CHAR_UPD_ITEM_INSTANCE);
stmt->setUInt32( index, GetEntry());
stmt->setUInt32(++index, GUID_LOPART(GetOwnerGUID()));
stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_CREATOR)));
stmt->setUInt32(++index, GUID_LOPART(GetUInt64Value(ITEM_FIELD_GIFTCREATOR)));
stmt->setUInt32(++index, GetOwnerGUID().GetCounter());
stmt->setUInt32(++index, GetGuidValue(ITEM_FIELD_CREATOR).GetCounter());
stmt->setUInt32(++index, GetGuidValue(ITEM_FIELD_GIFTCREATOR).GetCounter());
stmt->setUInt32(++index, GetCount());
stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURATION));
@@ -351,7 +351,7 @@ void Item::SaveToDB(SQLTransaction& trans)
if ((uState == ITEM_CHANGED) && HasFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_WRAPPED))
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GIFT_OWNER);
stmt->setUInt32(0, GUID_LOPART(GetOwnerGUID()));
stmt->setUInt32(0, GetOwnerGUID().GetCounter());
stmt->setUInt32(1, guid);
trans->Append(stmt);
}
@@ -386,14 +386,14 @@ void Item::SaveToDB(SQLTransaction& trans)
CharacterDatabase.CommitTransaction(trans);
}
bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, Field* fields, uint32 entry)
bool Item::LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fields, uint32 entry)
{
// 0 1 2 3 4 5 6 7 8 9 10
//result = CharacterDatabase.PQuery("SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text FROM item_instance WHERE guid = '%u'", guid);
// create item before any checks for store correct guid
// and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB
Object::_Create(guid, 0, HIGHGUID_ITEM);
Object::_Create(guid, 0, HighGuid::Item);
// Set entry, MUST be before proto check
SetEntry(entry);
@@ -404,12 +404,12 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, Field* fields, uint32 entr
return false;
// set owner (not if item is only loaded for gbank/auction/mail
if (owner_guid != 0)
if (owner_guid)
SetOwnerGUID(owner_guid);
bool need_save = false; // need explicit save data at load fixes
SetUInt64Value(ITEM_FIELD_CREATOR, MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER));
SetUInt64Value(ITEM_FIELD_GIFTCREATOR, MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER));
SetGuidValue(ITEM_FIELD_CREATOR, ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt32()));
SetGuidValue(ITEM_FIELD_GIFTCREATOR, ObjectGuid::Create<HighGuid::Player>(fields[1].GetUInt32()));
SetCount(fields[2].GetUInt32());
uint32 duration = fields[3].GetUInt32();
@@ -470,7 +470,7 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, Field* fields, uint32 entr
}
/*static*/
void Item::DeleteFromDB(SQLTransaction& trans, uint32 itemGuid)
void Item::DeleteFromDB(SQLTransaction& trans, ObjectGuid::LowType itemGuid)
{
sScriptMgr->OnGlobalItemDelFromDB(trans, itemGuid);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE);
@@ -480,11 +480,11 @@ void Item::DeleteFromDB(SQLTransaction& trans, uint32 itemGuid)
void Item::DeleteFromDB(SQLTransaction& trans)
{
DeleteFromDB(trans, GetGUIDLow());
DeleteFromDB(trans, GetGUID().GetCounter());
}
/*static*/
void Item::DeleteFromInventoryDB(SQLTransaction& trans, uint32 itemGuid)
void Item::DeleteFromInventoryDB(SQLTransaction& trans, ObjectGuid::LowType itemGuid)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_INVENTORY_BY_ITEM);
stmt->setUInt32(0, itemGuid);
@@ -493,7 +493,7 @@ void Item::DeleteFromInventoryDB(SQLTransaction& trans, uint32 itemGuid)
void Item::DeleteFromInventoryDB(SQLTransaction& trans)
{
DeleteFromInventoryDB(trans, GetGUIDLow());
DeleteFromInventoryDB(trans, GetGUID().GetCounter());
}
ItemTemplate const* Item::GetTemplate() const
@@ -674,7 +674,7 @@ void Item::SetState(ItemUpdateState state, Player* forplayer)
if (forplayer)
{
RemoveFromUpdateQueueOf(forplayer);
forplayer->DeleteRefundReference(GetGUIDLow());
forplayer->DeleteRefundReference(GetGUID());
}
delete this;
return;
@@ -706,7 +706,7 @@ void Item::AddToUpdateQueueOf(Player* player)
if (player->GetGUID() != GetOwnerGUID())
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("entities.player.items", "Item::AddToUpdateQueueOf - Owner's guid (%u) and player's guid (%u) don't match!", GUID_LOPART(GetOwnerGUID()), player->GetGUIDLow());
LOG_DEBUG("entities.player.items", "Item::AddToUpdateQueueOf - Owner's guid (%s) and player's guid (%s) don't match!", GetOwnerGUID().ToString().c_str(), player->GetGUID().ToString().c_str());
#endif
return;
}
@@ -728,7 +728,7 @@ void Item::RemoveFromUpdateQueueOf(Player* player)
if (player->GetGUID() != GetOwnerGUID())
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
LOG_DEBUG("entities.player.items", "Item::RemoveFromUpdateQueueOf - Owner's guid (%u) and player's guid (%u) don't match!", GUID_LOPART(GetOwnerGUID()), player->GetGUIDLow());
LOG_DEBUG("entities.player.items", "Item::RemoveFromUpdateQueueOf - Owner's guid (%s) and player's guid (%s) don't match!", GetOwnerGUID().ToString().c_str(), player->GetGUID().ToString().c_str());
#endif
return;
}
@@ -880,7 +880,7 @@ bool Item::IsFitToSpellRequirements(SpellInfo const* spellInfo) const
return true;
}
void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges, uint64 caster /*= 0*/)
void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges, ObjectGuid caster /*= ObjectGuid::Empty*/)
{
// Better lost small time at check in comparison lost time at item save to DB.
if ((GetEnchantmentId(slot) == id) && (GetEnchantmentDuration(slot) == duration) && (GetEnchantmentCharges(slot) == charges))
@@ -890,7 +890,7 @@ void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint
if (slot < MAX_INSPECTED_ENCHANTMENT_SLOT)
{
if (uint32 oldEnchant = GetEnchantmentId(slot))
owner->GetSession()->SendEnchantmentLog(GetOwnerGUID(), 0, GetEntry(), oldEnchant);
owner->GetSession()->SendEnchantmentLog(GetOwnerGUID(), ObjectGuid::Empty, GetEntry(), oldEnchant);
if (id)
owner->GetSession()->SendEnchantmentLog(GetOwnerGUID(), caster, GetEntry(), id);
@@ -1025,7 +1025,7 @@ bool Item::IsLimitedToAnotherMapOrZone(uint32 cur_mapId, uint32 cur_zoneId) cons
void Item::SendUpdateSockets()
{
WorldPacket data(SMSG_SOCKET_GEMS_RESULT, 8 + 4 + 4 + 4 + 4);
data << uint64(GetGUID());
data << GetGUID();
for (uint32 i = SOCK_ENCHANTMENT_SLOT; i <= BONUS_ENCHANTMENT_SLOT; ++i)
data << uint32(GetEnchantmentId(EnchantmentSlot(i)));
@@ -1042,7 +1042,7 @@ void Item::SendTimeUpdate(Player* owner)
return;
WorldPacket data(SMSG_ITEM_TIME_UPDATE, (8 + 4));
data << uint64(GetGUID());
data << GetGUID();
data << uint32(duration);
owner->GetSession()->SendPacket(&data);
}
@@ -1061,7 +1061,7 @@ Item* Item::CreateItem(uint32 item, uint32 count, Player const* player, bool clo
ASSERT(count != 0 && "pProto->Stackable == 0 but checked at loading already");
Item* pItem = NewItemOrBag(pProto);
if (pItem->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_ITEM), item, player))
if (pItem->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), item, player))
{
pItem->SetCount(count);
if (!clone)
@@ -1103,7 +1103,7 @@ bool Item::IsBindedNotWith(Player const* player) const
return false;
if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FIELD_FLAG_BOP_TRADEABLE))
if (allowedGUIDs.find(player->GetGUIDLow()) != allowedGUIDs.end())
if (allowedGUIDs.find(player->GetGUID()) != allowedGUIDs.end())
return false;
// BOA item case
@@ -1120,16 +1120,28 @@ void Item::BuildUpdate(UpdateDataMapType& data_map, UpdatePlayerSet&)
ClearUpdateMask(false);
}
void Item::AddToObjectUpdate()
{
if (Player* owner = GetOwner())
owner->GetMap()->AddUpdateObject(this);
}
void Item::RemoveFromObjectUpdate()
{
if (Player* owner = GetOwner())
owner->GetMap()->RemoveUpdateObject(this);
}
void Item::SaveRefundDataToDB()
{
SQLTransaction trans = CharacterDatabase.BeginTransaction();
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_REFUND_INSTANCE);
stmt->setUInt32(0, GetGUIDLow());
stmt->setUInt32(0, GetGUID().GetCounter());
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEM_REFUND_INSTANCE);
stmt->setUInt32(0, GetGUIDLow());
stmt->setUInt32(0, GetGUID().GetCounter());
stmt->setUInt32(1, GetRefundRecipient());
stmt->setUInt32(2, GetPaidMoney());
stmt->setUInt16(3, uint16(GetPaidExtendedCost()));
@@ -1143,7 +1155,7 @@ void Item::DeleteRefundDataFromDB(SQLTransaction* trans)
if (trans)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_REFUND_INSTANCE);
stmt->setUInt32(0, GetGUIDLow());
stmt->setUInt32(0, GetGUID().GetCounter());
(*trans)->Append(stmt);
}
}
@@ -1163,7 +1175,7 @@ void Item::SetNotRefundable(Player* owner, bool changestate /*=true*/, SQLTransa
SetPaidExtendedCost(0);
DeleteRefundDataFromDB(trans);
owner->DeleteRefundReference(GetGUIDLow());
owner->DeleteRefundReference(GetGUID());
}
void Item::UpdatePlayedTime(Player* owner)
@@ -1221,7 +1233,7 @@ void Item::ClearSoulboundTradeable(Player* currentOwner)
allowedGUIDs.clear();
SetState(ITEM_CHANGED, currentOwner);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_BOP_TRADE);
stmt->setUInt32(0, GetGUIDLow());
stmt->setUInt32(0, GetGUID().GetCounter());
CharacterDatabase.Execute(stmt);
}