uint8 Item::GetGemCountWithLimitCategory(uint32 limitCategory) const { uint8 count = 0; for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT+MAX_GEM_SOCKETS; ++enchant_slot) { uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)); if (!enchant_id) continue; SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id); if (!enchantEntry) continue; ItemTemplate const* gemProto = sObjectMgr->GetItemTemplate(enchantEntry->GemID); if (!gemProto) continue; if (gemProto->ItemLimitCategory == limitCategory) ++count; } return count; }
bool Item::GemsFitSockets() const { bool fits = true; for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT+MAX_GEM_SOCKETS; ++enchant_slot) { uint8 SocketColor = GetTemplate()->Socket[enchant_slot-SOCK_ENCHANTMENT_SLOT].Color; uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)); if (!enchant_id) { if (SocketColor) fits &= false; continue; } SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id); if (!enchantEntry) { if (SocketColor) fits &= false; continue; } uint8 GemColor = 0; uint32 gemid = enchantEntry->GemID; if (gemid) { ItemTemplate const* gemProto = sObjectMgr->GetItemTemplate(gemid); if (gemProto) { GemPropertiesEntry const* gemProperty = sGemPropertiesStore.LookupEntry(gemProto->GemProperties); if (gemProperty) GemColor = gemProperty->color; } } fits &= (GemColor & SocketColor) ? true : false; } return fits; }
uint8 Item::GetJewelcraftingGemCount() const { uint8 count = 0; for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS; ++enchant_slot) { uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)); if (!enchant_id) continue; SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id); if (!enchantEntry) continue; ItemPrototype const* gemProto = ObjectMgr::GetItemPrototype(enchantEntry->GemID); if (!gemProto) continue; if (gemProto->RequiredSkill == SKILL_JEWELCRAFTING) ++count; } return count; }
bool Item::GemsFitSockets() const { for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT+MAX_GEM_SOCKETS; ++enchant_slot) { uint8 SocketColor = GetTemplate()->Socket[enchant_slot-SOCK_ENCHANTMENT_SLOT].Color; if (!SocketColor) // no socket slot continue; uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)); if (!enchant_id) // no gems on this socket return false; SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id); if (!enchantEntry) // invalid gem id on this socket return false; uint8 GemColor = 0; uint32 gemid = enchantEntry->GemID; if (gemid) { ItemTemplate const* gemProto = sObjectMgr->GetItemTemplate(gemid); if (gemProto) { GemPropertiesEntry const* gemProperty = sGemPropertiesStore.LookupEntry(gemProto->GemProperties); if (gemProperty) GemColor = gemProperty->color; } } if (!(GemColor & SocketColor)) // bad gem color on this socket return false; } return true; }
bool Item::IsBoundByEnchant() const { // Check all enchants for soulbound for (uint32 enchant_slot = PERM_ENCHANTMENT_SLOT; enchant_slot < MAX_ENCHANTMENT_SLOT; ++enchant_slot) { uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot)); if (!enchant_id) continue; if (enchant_slot == TRANSMOGRIFY_ENCHANTMENT_SLOT) return true; if (enchant_slot > PRISMATIC_ENCHANTMENT_SLOT && enchant_slot < PROP_ENCHANTMENT_SLOT_0) continue; SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id); if (!enchantEntry) continue; if (enchantEntry->slot & ENCHANTMENT_CAN_SOULBOUND) return true; } return false; }
void Item::SaveToDB(SQLTransaction& trans) { bool isInTransaction = !(trans.null()); if (!isInTransaction) trans = CharacterDatabase.BeginTransaction(); uint32 guid = GetGUIDLow(); switch (uState) { case ITEM_NEW: case ITEM_CHANGED: { 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, GetCount()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_DURATION)); std::ostringstream ssSpells; for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) ssSpells << GetSpellCharges(i) << ' '; stmt->setString(++index, ssSpells.str()); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_FLAGS)); std::ostringstream ssEnchants; for (uint8 i = 0; i < MAX_ENCHANTMENT_SLOT; ++i) { ssEnchants << GetEnchantmentId(EnchantmentSlot(i)) << ' '; ssEnchants << GetEnchantmentDuration(EnchantmentSlot(i)) << ' '; ssEnchants << GetEnchantmentCharges(EnchantmentSlot(i)) << ' '; } stmt->setString(++index, ssEnchants.str()); stmt->setInt16 (++index, GetItemRandomPropertyId()); stmt->setUInt16(++index, GetUInt32Value(ITEM_FIELD_DURABILITY)); stmt->setUInt32(++index, GetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME)); stmt->setString(++index, m_text); stmt->setUInt32(++index, guid); trans->Append(stmt); if ((uState == ITEM_CHANGED) && HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GIFT_OWNER); stmt->setUInt32(0, GUID_LOPART(GetOwnerGUID())); stmt->setUInt32(1, guid); trans->Append(stmt); } break; } case ITEM_REMOVED: { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_INSTANCE); stmt->setUInt32(0, guid); trans->Append(stmt); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_WRAPPED)) { stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GIFT); stmt->setUInt32(0, guid); trans->Append(stmt); } if (!isInTransaction) CharacterDatabase.CommitTransaction(trans); delete this; return; } case ITEM_UNCHANGED: break; } SetState(ITEM_UNCHANGED); if (!isInTransaction) CharacterDatabase.CommitTransaction(trans); }
int32 Item::GetReforgableStat(ItemModType statType) const { ItemTemplate const* proto = GetTemplate(); for (uint32 i = 0; i < MAX_ITEM_PROTO_STATS; ++i) if (proto->ItemStat[i].ItemStatType == statType) return proto->ItemStat[i].ItemStatValue; int32 randomPropId = GetItemRandomPropertyId(); if (!randomPropId) return 0; if (randomPropId < 0) { ItemRandomSuffixEntry const* randomSuffix = sItemRandomSuffixStore.LookupEntry(-randomPropId); if (!randomSuffix) return 0; for (uint32 e = PROP_ENCHANTMENT_SLOT_0; e <= PROP_ENCHANTMENT_SLOT_4; ++e) if (SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(GetEnchantmentId(EnchantmentSlot(e)))) for (uint32 f = 0; f < MAX_ITEM_ENCHANTMENT_EFFECTS; ++f) if (enchant->type[f] == ITEM_ENCHANTMENT_TYPE_STAT && enchant->spellid[f] == statType) for (int k = 0; k < 5; ++k) if (randomSuffix->enchant_id[k] == enchant->ID) return int32((randomSuffix->prefix[k] * GetItemSuffixFactor()) / 10000); } else { ItemRandomPropertiesEntry const* randomProp = sItemRandomPropertiesStore.LookupEntry(randomPropId); if (!randomProp) return 0; for (uint32 e = PROP_ENCHANTMENT_SLOT_0; e <= PROP_ENCHANTMENT_SLOT_4; ++e) if (SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(GetEnchantmentId(EnchantmentSlot(e)))) for (uint32 f = 0; f < MAX_ITEM_ENCHANTMENT_EFFECTS; ++f) if (enchant->type[f] == ITEM_ENCHANTMENT_TYPE_STAT && enchant->spellid[f] == statType) for (int k = 0; k < MAX_ITEM_ENCHANTMENT_EFFECTS; ++k) if (randomProp->enchant_id[k] == enchant->ID) return int32(enchant->amount[k]); } return 0; }
void Item::SaveToDB() { uint32 guid = GetGUIDLow(); switch (uState) { case ITEM_NEW: { std::string text = m_text; CharacterDatabase.escape_string(text); std::ostringstream ss; 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: { std::string text = m_text; CharacterDatabase.escape_string(text); std::ostringstream ss; 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()); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED)) CharacterDatabase.PExecute("UPDATE character_gifts SET guid = '%u' WHERE item_guid = '%u'", GUID_LOPART(GetOwnerGUID()),GetGUIDLow()); }break; case ITEM_REMOVED: { CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'", guid); if (HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED)) CharacterDatabase.PExecute("DELETE FROM character_gifts WHERE item_guid = '%u'", GetGUIDLow()); delete this; return; } case ITEM_UNCHANGED: break; } SetState(ITEM_UNCHANGED); }