void Item::SaveToDB( int8 containerslot, int8 slot, bool firstsave, QueryBuffer* buf ) { if( !m_isDirty && !firstsave ) return; std::stringstream ss; ss << "REPLACE INTO playeritems VALUES("; ss << m_uint32Values[ITEM_FIELD_OWNER] << ","; ss << m_uint32Values[OBJECT_FIELD_GUID] << ","; ss << m_uint32Values[OBJECT_FIELD_ENTRY] << ","; ss << wrapped_item_id << ","; ss << m_uint32Values[ITEM_FIELD_GIFTCREATOR] << ","; ss << m_uint32Values[ITEM_FIELD_CREATOR] << ","; ss << GetUInt32Value(ITEM_FIELD_STACK_COUNT) << ","; ss << GetChargesLeft() << ","; ss << GetUInt32Value(ITEM_FIELD_FLAGS) << ","; ss << random_prop << ", " << random_suffix << ", "; ss << GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID) << ","; ss << GetUInt32Value(ITEM_FIELD_DURABILITY) << ","; ss << static_cast<int>(containerslot) << ","; ss << static_cast<int>(slot) << ",'"; // Pack together enchantment fields if( Enchantments.size() > 0 ) { EnchantmentMap::iterator itr = Enchantments.begin(); for(; itr != Enchantments.end(); ++itr) { if( itr->second.RemoveAtLogout ) continue; uint32 elapsed_duration = uint32( UNIXTIME - itr->second.ApplyTime ); int32 remaining_duration = itr->second.Duration - elapsed_duration; if( remaining_duration < 0 ) remaining_duration = 0; /* if( !itr->second.RemoveAtLogout && (remaining_duration > 5 && itr->second.Slot != 2) || itr->second.Slot == 2) // no point saving stuff with < 5 seconds... unless is perm enchant { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } */ if( itr->second.Enchantment && ( remaining_duration && remaining_duration > 5 ) || ( itr->second.Duration == 0 ) ) { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } } } ss << "')"; if( firstsave ) CharacterDatabase.WaitExecute( ss.str().c_str() ); else { if( buf == NULL ) CharacterDatabase.Execute( ss.str().c_str() ); else buf->AddQueryStr( ss.str() ); } m_isDirty = false; }
void Item::SaveToDB( int8 containerslot, int8 slot, bool firstsave, QueryBuffer* buf ) { if( !m_isDirty && !firstsave ) return; std::stringstream ss; ss << "REPLACE INTO playeritems VALUES("; ss << m_uint32Values[ITEM_FIELD_OWNER] << ","; ss << m_uint32Values[OBJECT_FIELD_GUID] << ","; ss << m_uint32Values[OBJECT_FIELD_ENTRY] << ","; ss << wrapped_item_id << ","; ss << m_uint32Values[ITEM_FIELD_GIFTCREATOR] << ","; ss << m_uint32Values[ITEM_FIELD_CREATOR] << ","; ss << GetUInt32Value(ITEM_FIELD_STACK_COUNT) << ","; ss << GetChargesLeft() << ","; ss << GetUInt32Value(ITEM_FIELD_FLAGS) << ","; ss << random_prop << ", " << random_suffix << ", "; ss << GetUInt32Value(ITEM_FIELD_ITEM_TEXT_ID) << ","; ss << GetUInt32Value(ITEM_FIELD_DURABILITY) << ","; ss << static_cast<int>(containerslot) << ","; ss << static_cast<int>(slot) << ",'"; // Pack together enchantment fields if( Enchantments.size() > 0 ) { EnchantmentMap::iterator itr = Enchantments.begin(); for(; itr != Enchantments.end(); ++itr) { if( itr->second.RemoveAtLogout ) continue; uint32 elapsed_duration = uint32( UNIXTIME - itr->second.ApplyTime ); int32 remaining_duration = itr->second.Duration - elapsed_duration; if( remaining_duration < 0 ) remaining_duration = 0; /* if( !itr->second.RemoveAtLogout && (remaining_duration > 5 && itr->second.Slot != 2) || itr->second.Slot == 2) // no point saving stuff with < 5 seconds... unless is perm enchant { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } */ if( itr->second.Enchantment && ( remaining_duration && remaining_duration > 5 || itr->second.Duration == 0 ) ) { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } } } ss << "','"; ss << ItemExpiresOn << "','"; ////////////////////////////////////////////////// Refund stuff ///////////////////////////////// // Check if the owner is instantiated. When sending mail he/she obviously will not be :P if( this->GetOwner() != NULL ){ std::pair< time_t, uint32 > refundentry; refundentry.first = 0; refundentry.second = 0; refundentry = this->GetOwner()->GetItemInterface()->LookupRefundable( this->GetGUID() ); ss << uint32( refundentry.first ) << "','"; ss << uint32( refundentry.second ); }else{ ss << uint32( 0 ) << "','"; ss << uint32( 0 ); } ///////////////////////////////////////////////////////////////////////////////////////////////// ss << "')"; if( firstsave ) CharacterDatabase.WaitExecute( ss.str().c_str() ); else { if( buf == NULL ) CharacterDatabase.Execute( ss.str().c_str() ); else buf->AddQueryStr( ss.str() ); } m_isDirty = false; }
void Item::SaveToDB( int16 containerslot, int16 slot, bool firstsave, QueryBuffer* buf ) { if( !m_isDirty && !firstsave ) return; std::stringstream ss; ss << "REPLACE INTO playeritems VALUES("; ss << m_uint32Values[ITEM_FIELD_OWNER] << ","; ss << m_uint32Values[OBJECT_FIELD_GUID] << ","; ss << m_uint32Values[OBJECT_FIELD_ENTRY] << ","; ss << wrapped_item_id << ","; ss << m_uint32Values[ITEM_FIELD_GIFTCREATOR] << ","; ss << m_uint32Values[ITEM_FIELD_CREATOR] << ","; ss << GetUInt32Value(ITEM_FIELD_STACK_COUNT) << ","; ss << (int32)GetChargesLeft() << ","; ss << GetUInt32Value(ITEM_FIELD_FLAGS) << ","; ss << random_prop << "," << random_suffix << ","; ss << GetTextID() << ","; ss << GetUInt32Value(ITEM_FIELD_DURABILITY) << ","; ss << static_cast<int>(containerslot) << ","; ss << static_cast<int>(slot) << ",'"; // Pack together enchantment fields if( Enchantments.size() > 0 ) { EnchantmentMap::iterator itr = Enchantments.begin(); for(; itr != Enchantments.end(); itr++) { if( itr->second.RemoveAtLogout ) continue; uint32 elapsed_duration = uint32( UNIXTIME - itr->second.ApplyTime ); int32 remaining_duration = itr->second.Duration - elapsed_duration; if( remaining_duration < 0 ) remaining_duration = 0; if( itr->second.Enchantment && ( remaining_duration && remaining_duration > 5 ) || ( itr->second.Duration == 0 ) ) { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ","; ss << uint32(itr->second.Dummy ? 1 : 0) << ";"; } } } ss << "','"; if(Gems[0] || Gems[1] || Gems[2]) { // We get socket. for(uint32 g = 0; g < 3; g++) { // Socket screen turn on. if(Gems[g]) { ss << g; // All your gem are belong to us. ss << ":" << Gems[g] << ";"; } } } ss << "')"; if( firstsave ) CharacterDatabase.WaitExecute( ss.str().c_str() ); else { if( buf == NULL ) CharacterDatabase.Execute( ss.str().c_str() ); else buf->AddQueryStr( ss.str() ); } m_isDirty = false; }
void Item::SaveToDB(int8 containerslot, int8 slot, bool firstsave, QueryBuffer* buf) { if (!m_isDirty && !firstsave) return; uint64 GiftCreatorGUID = GetGiftCreatorGUID(); uint64 CreatorGUID = GetCreatorGUID(); std::stringstream ss; ss << "DELETE FROM playeritems WHERE guid = " << GetLowGUID() << ";"; if (firstsave) CharacterDatabase.WaitExecute(ss.str().c_str()); else { if (buf == NULL) CharacterDatabase.Execute(ss.str().c_str()); else buf->AddQueryNA(ss.str().c_str()); } ss.rdbuf()->str(""); uint64 ownerGUID = GetOwnerGUID(); ss << "INSERT INTO playeritems VALUES("; ss << (Arcemu::Util::GUID_LOPART(ownerGUID)) << ","; ss << GetLowGUID() << ","; ss << GetEntry() << ","; ss << wrapped_item_id << ","; ss << (Arcemu::Util::GUID_LOPART(GiftCreatorGUID)) << ","; ss << (Arcemu::Util::GUID_LOPART(CreatorGUID)) << ","; ss << GetStackCount() << ","; ss << int32(GetChargesLeft()) << ","; ss << uint32(m_uint32Values[ITEM_FIELD_FLAGS]) << ","; ss << random_prop << ", " << random_suffix << ", "; ss << 0 << ","; ss << GetDurability() << ","; ss << static_cast<int>(containerslot) << ","; ss << static_cast<int>(slot) << ",'"; // Pack together enchantment fields if (Enchantments.size() > 0) { EnchantmentMap::iterator itr = Enchantments.begin(); for (; itr != Enchantments.end(); ++itr) { if (itr->second.RemoveAtLogout) continue; uint32 elapsed_duration = uint32(UNIXTIME - itr->second.ApplyTime); int32 remaining_duration = itr->second.Duration - elapsed_duration; if (remaining_duration < 0) remaining_duration = 0; if (itr->second.Enchantment && (remaining_duration > 5 || itr->second.Duration == 0)) { ss << itr->second.Enchantment->Id << ","; ss << remaining_duration << ","; ss << itr->second.Slot << ";"; } } } ss << "','"; ss << ItemExpiresOn << "','"; ////////////////////////////////////////////////// Refund stuff ///////////////////////////////// // Check if the owner is instantiated. When sending mail he/she obviously will not be :P if (this->GetOwner() != NULL) { std::pair< time_t, uint32 > refundentry; refundentry.first = 0; refundentry.second = 0; refundentry = this->GetOwner()->GetItemInterface()->LookupRefundable(this->GetGUID()); ss << uint32(refundentry.first) << "','"; ss << uint32(refundentry.second); } else { ss << uint32(0) << "','"; ss << uint32(0); } ///////////////////////////////////////////////////////////////////////////////////////////////// ss << "','"; ss << text; ss << "')"; if (firstsave) CharacterDatabase.WaitExecute(ss.str().c_str()); else { if (buf == NULL) CharacterDatabase.Execute(ss.str().c_str()); else buf->AddQueryNA(ss.str().c_str()); } m_isDirty = false; }