Deleted data blob in item_instance

Fixed issues with displaying sockets/enchants/durability on heroic items

--HG--
branch : trunk
This commit is contained in:
Shauren
2010-07-30 13:15:31 +02:00
parent c227065fc0
commit 77fc91bde8
13 changed files with 243 additions and 111 deletions
@@ -108,9 +108,9 @@ void Bag::SaveToDB()
Item::SaveToDB();
}
bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result)
bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result, uint32 entry)
{
if (!Item::LoadFromDB(guid, owner_guid, result))
if (!Item::LoadFromDB(guid, owner_guid, result, entry))
return false;
// cleanup bag content related item value fields (its will be filled correctly from `character_inventory`)
@@ -55,7 +55,7 @@ class Bag : public Item
// overwrite virtual Item::SaveToDB
void SaveToDB();
// overwrite virtual Item::LoadFromDB
bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result);
bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result, uint32 entry);
// overwrite virtual Item::DeleteFromDB
void DeleteFromDB();
+96 -61
View File
@@ -314,10 +314,29 @@ void Item::SaveToDB()
std::string text = m_text;
CharacterDatabase.escape_string(text);
std::ostringstream ss;
ss << "REPLACE INTO item_instance (guid, owner_guid, data, text) VALUES (" << guid << "," << GUID_LOPART(GetOwnerGUID()) << ",'";
for (uint16 i = 0; i < m_valuesCount; ++i)
ss << GetUInt32Value(i) << " ";
ss << "', '" << text << "')";
ss << "REPLACE INTO item_instance (guid,owner_guid,creatorGuid,giftCreatorGuid,count,duration,charges,flags,enchantments,randomPropertyId,durability,playedTime,text) VALUES (";
ss << guid << ",";
ss << GUID_LOPART(GetOwnerGUID()) << ",";
ss << GUID_LOPART(GetUInt64Value(ITEM_FIELD_CREATOR)) << ",";
ss << GUID_LOPART(GetUInt64Value(ITEM_FIELD_GIFTCREATOR)) << ",";
ss << GetCount() << ",";
ss << GetUInt32Value(ITEM_FIELD_DURATION) << ",'";
for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
ss << GetSpellCharges(i) << " ";
ss << "'," << GetUInt32Value(ITEM_FIELD_FLAGS) << ",'";
for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i)
{
ss << GetEnchantmentId(EnchantmentSlot(i)) << " ";
ss << GetEnchantmentDuration(EnchantmentSlot(i)) << " ";
ss << GetEnchantmentCharges(EnchantmentSlot(i)) << " ";
}
ss << "'," << GetItemRandomPropertyId() << ",";
ss << GetUInt32Value(ITEM_FIELD_DURABILITY) << ",";
ss << GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME) << ",";
ss << ",'" << text << "')";
CharacterDatabase.Execute(ss.str().c_str());
}break;
case ITEM_CHANGED:
@@ -325,11 +344,28 @@ void Item::SaveToDB()
std::string text = m_text;
CharacterDatabase.escape_string(text);
std::ostringstream ss;
ss << "UPDATE item_instance SET data = '";
for (uint16 i = 0; i < m_valuesCount; ++i)
ss << GetUInt32Value(i) << " ";
ss << "', owner_guid = '" << GUID_LOPART(GetOwnerGUID());
ss << "', text = '" << text << "' WHERE guid = '" << guid << "'";
ss << "UPDATE item_instance SET owner_guid = " << GUID_LOPART(GetOwnerGUID());
ss << ", creatorGuid = " << GUID_LOPART(GetUInt64Value(ITEM_FIELD_CREATOR));
ss << ", giftCreatorGuid = " << GUID_LOPART(GetUInt64Value(ITEM_FIELD_GIFTCREATOR));
ss << ", count = " << GetCount();
ss << ", duration = " << GetUInt32Value(ITEM_FIELD_DURATION);
ss << ", charges = '";
for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
ss << GetSpellCharges(i) << " ";
ss << "', flags = " << GetUInt32Value(ITEM_FIELD_FLAGS);
ss << ", enchantments = '";
for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i)
{
ss << GetEnchantmentId(EnchantmentSlot(i)) << " ";
ss << GetEnchantmentDuration(EnchantmentSlot(i)) << " ";
ss << GetEnchantmentCharges(EnchantmentSlot(i)) << " ";
}
ss << "', randomPropertyId = " << GetItemRandomPropertyId();
ss << ", durability = " << GetUInt32Value(ITEM_FIELD_DURABILITY);
ss << ", playedTime = " << GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME);
ss << ", text = '" << text << "' WHERE guid = " << guid;
CharacterDatabase.Execute(ss.str().c_str());
@@ -350,74 +386,73 @@ void Item::SaveToDB()
SetState(ITEM_UNCHANGED);
}
bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result)
bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result, uint32 entry)
{
// 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);
if (!result)
result = CharacterDatabase.PQuery("SELECT data FROM item_instance WHERE guid = '%u'", guid);
if (!result)
{
sLog.outError("Item (GUID: %u owner: %u) not found in table `item_instance`, can't load. ",guid,GUID_LOPART(owner_guid));
return false;
}
Field *fields = result->Fetch();
if (!LoadValues(fields[0].GetString()))
{
sLog.outError("Item #%d have broken data in `data` field. Can't be loaded.",guid);
return false;
}
bool need_save = false; // need explicit save data at load fixes
// overwrite possible wrong/corrupted guid
uint64 new_item_guid = MAKE_NEW_GUID(guid,0, HIGHGUID_ITEM);
if (GetUInt64Value(OBJECT_FIELD_GUID) != new_item_guid)
{
SetUInt64Value(OBJECT_FIELD_GUID, MAKE_NEW_GUID(guid,0, HIGHGUID_ITEM));
need_save = true;
}
SetEntry(entry);
ItemPrototype const* proto = GetProto();
if (!proto)
return false;
// update max durability (and durability) if need
if (proto->MaxDurability!= GetUInt32Value(ITEM_FIELD_MAXDURABILITY))
{
SetUInt32Value(ITEM_FIELD_MAXDURABILITY,proto->MaxDurability);
if (GetUInt32Value(ITEM_FIELD_DURABILITY) > proto->MaxDurability)
SetUInt32Value(ITEM_FIELD_DURABILITY,proto->MaxDurability);
//if (!result) // 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);
if (!result)
{
sLog.outError("Item (GUID: %u owner: %u) not found in table `item_instance`, can't load. ", guid, GUID_LOPART(owner_guid));
return false;
}
Field *fields = result->Fetch();
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));
SetCount(fields[2].GetUInt32());
uint32 duration = fields[3].GetUInt32();
SetUInt32Value(ITEM_FIELD_DURATION, duration);
// update duration if need, and remove if not need
if ((proto->Duration == 0) != (duration == 0))
{
SetUInt32Value(ITEM_FIELD_DURATION, abs(proto->Duration));
need_save = true;
}
// recalculate suffix factor
if (GetItemRandomPropertyId() < 0)
{
if (UpdateItemSuffixFactor())
need_save = true;
}
Tokens tokens = StrSplit(fields[4].GetCppString(), " ");
if (tokens.size() == MAX_ITEM_PROTO_SPELLS)
for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
SetSpellCharges(i, atoi(tokens[i].c_str()));
SetUInt32Value(ITEM_FIELD_FLAGS, fields[5].GetUInt32());
// Remove bind flag for items vs NO_BIND set
if (IsSoulBound() && proto->Bonding == NO_BIND)
{
ApplyModFlag(ITEM_FIELD_FLAGS,ITEM_FLAGS_BINDED, false);
ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_BINDED, false);
need_save = true;
}
// update duration if need, and remove if not need
if ((proto->Duration == 0) != (GetUInt32Value(ITEM_FIELD_DURATION) == 0))
_LoadIntoDataField(fields[6].GetString(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET);
SetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID, fields[7].GetInt32());
// recalculate suffix factor
if (GetItemRandomPropertyId() < 0)
UpdateItemSuffixFactor();
uint32 durability = fields[8].GetUInt32();
SetUInt32Value(ITEM_FIELD_DURABILITY, durability);
// update max durability (and durability) if need
SetUInt32Value(ITEM_FIELD_MAXDURABILITY, proto->MaxDurability);
if (durability > proto->MaxDurability)
{
SetUInt32Value(ITEM_FIELD_DURATION,abs(proto->Duration));
SetUInt32Value(ITEM_FIELD_DURABILITY, proto->MaxDurability);
need_save = true;
}
SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, fields[9].GetUInt32());
SetText(fields[10].GetCppString());
// set correct owner
if (owner_guid != 0 && GetOwnerGUID() != owner_guid)
{
@@ -428,10 +463,11 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result
if (need_save) // normal item changed state set not work at loading
{
std::ostringstream ss;
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 = '" << guid << "'";
ss << "UPDATE item_instance SET duration = " << GetUInt32Value(ITEM_FIELD_DURABILITY)
<< ", flags = " << GetUInt32Value(ITEM_FIELD_FLAGS)
<< ", durability = " << GetUInt32Value(ITEM_FIELD_DURABILITY)
<< ", owner_guid = " << GUID_LOPART(GetOwnerGUID())
<< " WHERE guid = " << guid;
CharacterDatabase.Execute(ss.str().c_str());
}
@@ -620,13 +656,12 @@ void Item::SetItemRandomProperties(int32 randomPropId)
}
}
bool Item::UpdateItemSuffixFactor()
void Item::UpdateItemSuffixFactor()
{
uint32 suffixFactor = GenerateEnchSuffixFactor(GetEntry());
if (GetItemSuffixFactor() == suffixFactor)
return false;
SetUInt32Value(ITEM_FIELD_PROPERTY_SEED,suffixFactor);
return true;
return;
SetUInt32Value(ITEM_FIELD_PROPERTY_SEED, suffixFactor);
}
void Item::SetState(ItemUpdateState state, Player *forplayer)
+2 -2
View File
@@ -240,7 +240,7 @@ class Item : public Object
bool IsBindedNotWith(Player const* player) const;
bool IsBoundByEnchant() const;
virtual void SaveToDB();
virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result);
virtual bool LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result, uint32 entry);
virtual void DeleteFromDB();
void DeleteFromInventoryDB();
void SaveRefundDataToDB();
@@ -284,7 +284,7 @@ class Item : public Object
int32 GetItemRandomPropertyId() const { return GetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID); }
uint32 GetItemSuffixFactor() const { return GetUInt32Value(ITEM_FIELD_PROPERTY_SEED); }
void SetItemRandomProperties(int32 randomPropId);
bool UpdateItemSuffixFactor();
void UpdateItemSuffixFactor();
static int32 GenerateItemRandomPropertyId(uint32 item_id);
void SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges);
void SetEnchantmentDuration(EnchantmentSlot slot, uint32 duration, Player* owner);
@@ -769,6 +769,24 @@ bool Object::LoadValues(const char* data)
return true;
}
void Object::_LoadIntoDataField(const char* data, uint32 startOffset, uint32 count)
{
if (!data)
return;
Tokens tokens = StrSplit(data, " ");
if (tokens.size() != count)
return;
Tokens::iterator iter;
uint32 index;
for (iter = tokens.begin(), index = 0; index < count; ++iter, ++index)
{
m_uint32Values[startOffset + index] = atol((*iter).c_str());
}
}
void Object::_SetUpdateBits(UpdateMask *updateMask, Player* /*target*/) const
{
uint32 *value = m_uint32Values;
+1
View File
@@ -329,6 +329,7 @@ class Object
void _InitValues();
void _Create (uint32 guidlow, uint32 entry, HighGuid guidhigh);
void _LoadIntoDataField(const char* data, uint32 startOffset, uint32 count);
virtual void _SetUpdateBits(UpdateMask *updateMask, Player *target) const;
+13 -31
View File
@@ -4434,15 +4434,15 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
if (has_items)
{
// Data needs to be at first place for Item::LoadFromDB
QueryResult_AutoPtr resultItems = CharacterDatabase.PQuery("SELECT data,text,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id);
QueryResult_AutoPtr resultItems = CharacterDatabase.PQuery("SELECT creatorGuid,giftCreatorGuid,count,duration,charges,flags,enchantments,randomPropertyId,durability,playedTime,text,item_guid,item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id);
if (resultItems)
{
do
{
Field *fields2 = resultItems->Fetch();
uint32 item_guidlow = fields2[2].GetUInt32();
uint32 item_template = fields2[3].GetUInt32();
uint32 item_guidlow = fields2[11].GetUInt32();
uint32 item_template = fields2[12].GetUInt32();
ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_template);
if (!itemProto)
@@ -4452,7 +4452,7 @@ void Player::DeleteFromDB(uint64 playerguid, uint32 accountId, bool updateRealmC
}
Item *pItem = NewItemOrBag(itemProto);
if (!pItem->LoadFromDB(item_guidlow, MAKE_NEW_GUID(guid, 0, HIGHGUID_PLAYER),resultItems))
if (!pItem->LoadFromDB(item_guidlow, MAKE_NEW_GUID(guid, 0, HIGHGUID_PLAYER), resultItems, item_template))
{
pItem->FSetState(ITEM_REMOVED);
pItem->SaveToDB(); // it also deletes item object!
@@ -15864,24 +15864,6 @@ float Player::GetFloatValueFromArray(Tokens const& data, uint16 index)
return result;
}
void Player::_LoadIntoDataField(const char* data, uint32 startOffset, uint32 count)
{
if (!data)
return;
Tokens tokens = StrSplit(data, " ");
if (tokens.size() != count)
return;
Tokens::iterator iter;
uint32 index;
for (iter = tokens.begin(), index = 0; index < count; ++iter, ++index)
{
m_uint32Values[startOffset + index] = atol((*iter).c_str());
}
}
bool Player::LoadFromDB(uint32 guid, SqlQueryHolder *holder)
{
//// 0 1 2 3 4 5 6 7 8 9 10 11
@@ -16733,10 +16715,10 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
do
{
Field *fields = result->Fetch();
uint32 bag_guid = fields[2].GetUInt32();
uint8 slot = fields[3].GetUInt8();
uint32 item_guid = fields[4].GetUInt32();
uint32 item_id = fields[5].GetUInt32();
uint32 bag_guid = fields[11].GetUInt32();
uint8 slot = fields[12].GetUInt8();
uint32 item_guid = fields[13].GetUInt32();
uint32 item_id = fields[14].GetUInt32();
ItemPrototype const * proto = objmgr.GetItemPrototype(item_id);
@@ -16750,7 +16732,7 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
Item *item = NewItemOrBag(proto);
if (!item->LoadFromDB(item_guid, GetGUID(), result))
if (!item->LoadFromDB(item_guid, GetGUID(), result, item_id))
{
sLog.outError("Player::_LoadInventory: Player %s has broken item (id: #%u) in inventory, deleted.", GetName(),item_id);
CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item_guid);
@@ -16909,15 +16891,15 @@ void Player::_LoadInventory(QueryResult_AutoPtr result, uint32 timediff)
void Player::_LoadMailedItems(Mail *mail)
{
// data needs to be at first place for Item::LoadFromDB
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT data, text, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID);
QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail->messageID);
if (!result)
return;
do
{
Field *fields = result->Fetch();
uint32 item_guid_low = fields[2].GetUInt32();
uint32 item_template = fields[3].GetUInt32();
uint32 item_guid_low = fields[11].GetUInt32();
uint32 item_template = fields[12].GetUInt32();
mail->AddItem(item_guid_low, item_template);
@@ -16933,7 +16915,7 @@ void Player::_LoadMailedItems(Mail *mail)
Item *item = NewItemOrBag(proto);
if (!item->LoadFromDB(item_guid_low, 0, result))
if (!item->LoadFromDB(item_guid_low, 0, result, item_template))
{
sLog.outError("Player::_LoadMailedItems - Item in mail (%u) doesn't exist !!!! - item guid: %u, deleted from mail", mail->messageID, item_guid_low);
CharacterDatabase.PExecute("DELETE FROM mail_items WHERE item_guid = '%u'", item_guid_low);
-1
View File
@@ -2410,7 +2410,6 @@ class Player : public Unit, public GridObject<Player>
void _LoadBGData(QueryResult_AutoPtr result);
void _LoadGlyphs(QueryResult_AutoPtr result);
void _LoadTalents(QueryResult_AutoPtr result);
void _LoadIntoDataField(const char* data, uint32 startOffset, uint32 count);
/*********************************************************/
/*** SAVE SYSTEM ***/