mirror of
https://github.com/mangosfour/server.git
synced 2025-12-26 07:37:02 +00:00
[10751] Use objectguids in item code.
Also * Fixed unexpected container updated state after inventory load * Make .debug getitemstate command more friendly by args.
This commit is contained in:
parent
bbd34562a8
commit
2601022b9f
14 changed files with 173 additions and 110 deletions
|
|
@ -247,13 +247,13 @@ Item::Item( )
|
|||
|
||||
bool Item::Create( uint32 guidlow, uint32 itemid, Player const* owner)
|
||||
{
|
||||
Object::_Create( guidlow, 0, HIGHGUID_ITEM );
|
||||
Object::_Create(guidlow, 0, HIGHGUID_ITEM);
|
||||
|
||||
SetEntry(itemid);
|
||||
SetObjectScale(DEFAULT_OBJECT_SCALE);
|
||||
|
||||
SetUInt64Value(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : 0);
|
||||
SetUInt64Value(ITEM_FIELD_CONTAINED, owner ? owner->GetGUID() : 0);
|
||||
SetGuidValue(ITEM_FIELD_OWNER, owner ? owner->GetObjectGuid() : ObjectGuid());
|
||||
SetGuidValue(ITEM_FIELD_CONTAINED, owner ? owner->GetObjectGuid() : ObjectGuid());
|
||||
|
||||
ItemPrototype const *itemProto = ObjectMgr::GetItemPrototype(itemid);
|
||||
if(!itemProto)
|
||||
|
|
@ -299,7 +299,7 @@ void Item::SaveToDB()
|
|||
CharacterDatabase.escape_string(text);
|
||||
CharacterDatabase.PExecute( "DELETE FROM item_instance WHERE guid = '%u'", guid );
|
||||
std::ostringstream ss;
|
||||
ss << "INSERT INTO item_instance (guid,owner_guid,data,text) VALUES (" << guid << "," << GUID_LOPART(GetOwnerGUID()) << ",'";
|
||||
ss << "INSERT INTO item_instance (guid,owner_guid,data,text) VALUES (" << guid << "," << GetOwnerGuid().GetCounter() << ",'";
|
||||
for(uint16 i = 0; i < m_valuesCount; ++i )
|
||||
ss << GetUInt32Value(i) << " ";
|
||||
ss << "', '" << text << "')";
|
||||
|
|
@ -313,13 +313,13 @@ void Item::SaveToDB()
|
|||
ss << "UPDATE item_instance SET data = '";
|
||||
for(uint16 i = 0; i < m_valuesCount; ++i )
|
||||
ss << GetUInt32Value(i) << " ";
|
||||
ss << "', owner_guid = '" << GUID_LOPART(GetOwnerGUID());
|
||||
ss << "', owner_guid = '" << GetOwnerGuid().GetCounter();
|
||||
ss << "', text = '" << text << "' WHERE guid = '" << guid << "'";
|
||||
|
||||
CharacterDatabase.Execute( ss.str().c_str() );
|
||||
|
||||
if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED))
|
||||
CharacterDatabase.PExecute("UPDATE character_gifts SET guid = '%u' WHERE item_guid = '%u'", GUID_LOPART(GetOwnerGUID()),GetGUIDLow());
|
||||
CharacterDatabase.PExecute("UPDATE character_gifts SET guid = '%u' WHERE item_guid = '%u'", GetOwnerGuid().GetCounter(), GetGUIDLow());
|
||||
} break;
|
||||
case ITEM_REMOVED:
|
||||
{
|
||||
|
|
@ -377,7 +377,7 @@ void Item::SaveToDB()
|
|||
SetState(ITEM_UNCHANGED);
|
||||
}
|
||||
|
||||
bool Item::LoadFromDB(uint32 guidLow, uint64 owner_guid, Field *fields)
|
||||
bool Item::LoadFromDB(uint32 guidLow, Field *fields, ObjectGuid ownerGuid)
|
||||
{
|
||||
// create item before any checks for store correct guid
|
||||
// and allow use "FSetState(ITEM_REMOVED); SaveToDB();" for deleting item from DB
|
||||
|
|
@ -435,9 +435,9 @@ bool Item::LoadFromDB(uint32 guidLow, uint64 owner_guid, Field *fields)
|
|||
}
|
||||
|
||||
// set correct owner
|
||||
if (owner_guid != 0 && GetOwnerGUID() != owner_guid)
|
||||
if (!ownerGuid.IsEmpty() && GetOwnerGuid() != ownerGuid)
|
||||
{
|
||||
SetOwnerGUID(owner_guid);
|
||||
SetOwnerGuid(ownerGuid);
|
||||
need_save = true;
|
||||
}
|
||||
|
||||
|
|
@ -461,7 +461,7 @@ bool Item::LoadFromDB(uint32 guidLow, uint64 owner_guid, Field *fields)
|
|||
ss << "UPDATE item_instance SET data = '";
|
||||
for(uint16 i = 0; i < m_valuesCount; ++i )
|
||||
ss << GetUInt32Value(i) << " ";
|
||||
ss << "', owner_guid = '" << GUID_LOPART(GetOwnerGUID()) << "' WHERE guid = '" << guidLow << "'";
|
||||
ss << "', owner_guid = '" << GetOwnerGuid().GetCounter() << "' WHERE guid = '" << guidLow << "'";
|
||||
|
||||
CharacterDatabase.Execute( ss.str().c_str() );
|
||||
}
|
||||
|
|
@ -490,7 +490,7 @@ void Item::LoadLootFromDB(Field *fields)
|
|||
if(!proto)
|
||||
{
|
||||
CharacterDatabase.PExecute("DELETE FROM item_loot WHERE guid = '%u' AND itemid = '%u'", GetGUIDLow(), item_id);
|
||||
sLog.outError("Item::LoadLootFromDB: %s has an unknown item (id: #%u) in item_loot, deleted.", ObjectGuid(GetOwnerGUID()).GetString().c_str(), item_id);
|
||||
sLog.outError("Item::LoadLootFromDB: %s has an unknown item (id: #%u) in item_loot, deleted.", GetOwnerGuid().GetString().c_str(), item_id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -517,7 +517,7 @@ ItemPrototype const *Item::GetProto() const
|
|||
|
||||
Player* Item::GetOwner()const
|
||||
{
|
||||
return sObjectMgr.GetPlayer(GetOwnerGUID());
|
||||
return sObjectMgr.GetPlayer(GetOwnerGuid());
|
||||
}
|
||||
|
||||
uint32 Item::GetSkill()
|
||||
|
|
@ -717,25 +717,29 @@ void Item::SetState(ItemUpdateState state, Player *forplayer)
|
|||
|
||||
void Item::AddToUpdateQueueOf(Player *player)
|
||||
{
|
||||
if (IsInUpdateQueue()) return;
|
||||
if (IsInUpdateQueue())
|
||||
return;
|
||||
|
||||
if (!player)
|
||||
{
|
||||
player = GetOwner();
|
||||
if (!player)
|
||||
{
|
||||
sLog.outError("Item::AddToUpdateQueueOf - GetPlayer didn't find a player matching owner's guid (%u)!", GUID_LOPART(GetOwnerGUID()));
|
||||
sLog.outError("Item::AddToUpdateQueueOf - %s current owner (%s) not in world!",
|
||||
GetObjectGuid().GetString().c_str(), GetOwnerGuid().GetString().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (player->GetGUID() != GetOwnerGUID())
|
||||
if (player->GetObjectGuid() != GetOwnerGuid())
|
||||
{
|
||||
sLog.outError("Item::AddToUpdateQueueOf - Owner's guid (%u) and player's guid (%u) don't match!", GUID_LOPART(GetOwnerGUID()), player->GetGUIDLow());
|
||||
sLog.outError("Item::AddToUpdateQueueOf - %s current owner (%s) and inventory owner (%s) don't match!",
|
||||
GetObjectGuid().GetString().c_str(), GetOwnerGuid().GetString().c_str(), player->GetObjectGuid().GetString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (player->m_itemUpdateQueueBlocked) return;
|
||||
if (player->m_itemUpdateQueueBlocked)
|
||||
return;
|
||||
|
||||
player->m_itemUpdateQueue.push_back(this);
|
||||
uQueuePos = player->m_itemUpdateQueue.size()-1;
|
||||
|
|
@ -743,25 +747,29 @@ void Item::AddToUpdateQueueOf(Player *player)
|
|||
|
||||
void Item::RemoveFromUpdateQueueOf(Player *player)
|
||||
{
|
||||
if (!IsInUpdateQueue()) return;
|
||||
if (!IsInUpdateQueue())
|
||||
return;
|
||||
|
||||
if (!player)
|
||||
{
|
||||
player = GetOwner();
|
||||
if (!player)
|
||||
{
|
||||
sLog.outError("Item::RemoveFromUpdateQueueOf - GetPlayer didn't find a player matching owner's guid (%u)!", GUID_LOPART(GetOwnerGUID()));
|
||||
sLog.outError("Item::RemoveFromUpdateQueueOf - %s current owner (%s) not in world!",
|
||||
GetObjectGuid().GetString().c_str(), GetOwnerGuid().GetString().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (player->GetGUID() != GetOwnerGUID())
|
||||
if (player->GetObjectGuid() != GetOwnerGuid())
|
||||
{
|
||||
sLog.outError("Item::RemoveFromUpdateQueueOf - Owner's guid (%u) and player's guid (%u) don't match!", GUID_LOPART(GetOwnerGUID()), player->GetGUIDLow());
|
||||
sLog.outError("Item::RemoveFromUpdateQueueOf - %s current owner (%s) and inventory owner (%s) don't match!",
|
||||
GetObjectGuid().GetString().c_str(), GetOwnerGuid().GetString().c_str(), player->GetObjectGuid().GetString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (player->m_itemUpdateQueueBlocked) return;
|
||||
if (player->m_itemUpdateQueueBlocked)
|
||||
return;
|
||||
|
||||
player->m_itemUpdateQueue[uQueuePos] = NULL;
|
||||
uQueuePos = -1;
|
||||
|
|
@ -1051,11 +1059,11 @@ Item* Item::CloneItem( uint32 count, Player const* player ) const
|
|||
bool Item::IsBindedNotWith( Player const* player ) const
|
||||
{
|
||||
// not binded item
|
||||
if(!IsSoulBound())
|
||||
if (!IsSoulBound())
|
||||
return false;
|
||||
|
||||
// own item
|
||||
if(GetOwnerGUID()== player->GetGUID())
|
||||
if (GetOwnerGuid() == player->GetObjectGuid())
|
||||
return false;
|
||||
|
||||
// has loot with diff owner
|
||||
|
|
@ -1063,18 +1071,18 @@ bool Item::IsBindedNotWith( Player const* player ) const
|
|||
return true;
|
||||
|
||||
// not BOA item case
|
||||
if(!IsBoundAccountWide())
|
||||
if (!IsBoundAccountWide())
|
||||
return true;
|
||||
|
||||
// online
|
||||
if(Player* owner = sObjectMgr.GetPlayer(GetOwnerGUID()))
|
||||
if (Player* owner = GetOwner())
|
||||
{
|
||||
return owner->GetSession()->GetAccountId() != player->GetSession()->GetAccountId();
|
||||
}
|
||||
// offline slow case
|
||||
else
|
||||
{
|
||||
return sObjectMgr.GetPlayerAccountIdByGUID(GetOwnerGUID()) != player->GetSession()->GetAccountId();
|
||||
return sObjectMgr.GetPlayerAccountIdByGUID(GetOwnerGuid()) != player->GetSession()->GetAccountId();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue