bool Item::LoadRefundDataFromDB(Player* owner) { bool failed = true; if (!IsRefundOrSoulboundTradeExpired(owner)) { QueryResult* result = CharacterDatabase.PQuery("SELECT paidMoney, paidExtendedCost FROM item_refund_instance WHERE itemGuid = %u AND playerGuid = %u", GetGUIDLow(), owner->GetGUIDLow()); if (result) { Field* fields = result->Fetch(); SetRefundable(owner, fields[0].GetUInt32(), fields[1].GetUInt16(), true); delete result; failed = false; } } else DeleteRefundDataFromDB(); if (failed) { RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE); SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, 0); return false; } return true; }
void Item::SetNotRefundable(Player *owner, bool changestate) { if (!HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE)) return; RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE); // Following is not applicable in the trading procedure if (changestate) SetState(ITEM_CHANGED, owner); SetRefundRecipient(0); SetPaidMoney(0); SetPaidExtendedCost(0); DeleteRefundDataFromDB(); owner->DeleteRefundReference(GetGUIDLow()); }
void Item::SetNotRefundable(Player* owner, bool changeState/*=true*/) { if (!HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE)) return; RemoveFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE); SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, 0); if (changeState) SetState(ITEM_CHANGED, owner); m_paidCost = 0; m_paidExtCost = 0; DeleteRefundDataFromDB(); owner->RemoveItemWithTimeCheck(GetGUIDLow()); }
void Item::SaveToDB() { uint32 guid = GetGUIDLow(); switch(m_state) { case ITEM_NEW: { DeleteFromDB(guid); std::ostringstream ss; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; static SqlStatementID insItem; SqlStatement stmt = CharacterDatabase.CreateStatement(insItem, "INSERT INTO item_instance (guid, owner_guid, data, text) VALUES (?, ?, ?, ?)"); stmt.PExecute(guid, GetOwnerGuid().GetCounter(), ss.str().c_str(), m_text.c_str()); break; } case ITEM_CHANGED: { std::ostringstream ss; for (uint16 i = 0; i < m_valuesCount; ++i) ss << GetUInt32Value(i) << " "; static SqlStatementID updInstance; SqlStatement stmt = CharacterDatabase.CreateStatement(updInstance, "UPDATE item_instance SET data = ?, owner_guid = ?, text = ? WHERE guid = ?"); stmt.PExecute(ss.str().c_str(), GetOwnerGuid().GetCounter(), m_text.c_str(), guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) { static SqlStatementID updGifts; stmt = CharacterDatabase.CreateStatement(updGifts, "UPDATE character_gifts SET guid = ? WHERE item_guid = ?"); stmt.PExecute(GetOwnerGuid().GetCounter(), GetGUIDLow()); } break; } case ITEM_REMOVED: { DeleteFromDB(guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_WRAPPED)) DeleteGiftsFromDB(); if (HasSavedLoot()) DeleteLootFromDB(); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_REFUNDABLE)) DeleteRefundDataFromDB(); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_BOP_TRADEABLE)) DeleteSoulboundTradeableFromDB(); delete this; return; } case ITEM_UNCHANGED: return; } if (m_lootState == ITEM_LOOT_CHANGED || m_lootState == ITEM_LOOT_REMOVED) DeleteLootFromDB(); if (m_lootState == ITEM_LOOT_NEW || m_lootState == ITEM_LOOT_CHANGED) { if (Player* owner = GetOwner()) { // save money as 0 itemid data if (loot.gold) { static SqlStatementID saveGold; SqlStatement stmt = CharacterDatabase.CreateStatement(saveGold, "INSERT INTO item_loot (guid, owner_guid, itemid, amount, suffix, property) VALUES (?, ?, 0, ?, 0, 0)"); stmt.PExecute(GetGUIDLow(), owner->GetGUIDLow(), loot.gold); } static SqlStatementID saveLoot; SqlStatement stmt = CharacterDatabase.CreateStatement(saveLoot, "INSERT INTO item_loot (guid, owner_guid, itemid, amount, suffix, property) VALUES (?, ?, ?, ?, ?, ?)"); // save items and quest items (at load its all will added as normal, but this not important for item loot case) for (size_t i = 0; i < loot.GetMaxSlotInLootFor(owner); ++i) { QuestItem* qitem = NULL; LootItem* item = loot.LootItemInSlot(i, owner, &qitem); if (!item) continue; // questitems use the blocked field for other purposes if (!qitem && item->is_blocked) continue; stmt.addUInt32(GetGUIDLow()); stmt.addUInt32(owner->GetGUIDLow()); stmt.addUInt32(item->itemid); stmt.addUInt8(item->count); stmt.addUInt32(item->randomSuffix); stmt.addInt32(item->randomPropertyId); stmt.Execute(); } } } if (m_lootState != ITEM_LOOT_NONE && m_lootState != ITEM_LOOT_TEMPORARY) SetLootState(ITEM_LOOT_UNCHANGED); SetState(ITEM_UNCHANGED); }