aboutsummaryrefslogtreecommitdiff
path: root/src/game/Item.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Item.cpp')
-rw-r--r--src/game/Item.cpp159
1 files changed, 158 insertions, 1 deletions
diff --git a/src/game/Item.cpp b/src/game/Item.cpp
index ed91c888451..2d39b016623 100644
--- a/src/game/Item.cpp
+++ b/src/game/Item.cpp
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
#include "Common.h"
#include "Item.h"
#include "ObjectMgr.h"
@@ -25,19 +26,25 @@
#include "ItemEnchantmentMgr.h"
#include "SpellMgr.h"
#include "ScriptCalls.h"
+
void AddItemsSetItem(Player*player,Item *item)
{
ItemPrototype const *proto = item->GetProto();
uint32 setid = proto->ItemSet;
+
ItemSetEntry const *set = sItemSetStore.LookupEntry(setid);
+
if(!set)
{
sLog.outErrorDb("Item set %u for item (id %u) not found, mods not applied.",setid,proto->ItemId);
return;
}
+
if( set->required_skill_id && player->GetSkillValue(set->required_skill_id) < set->required_skill_value )
return;
+
ItemSetEffect *eff = NULL;
+
for(size_t x = 0; x < player->ItemSetEff.size(); ++x)
{
if(player->ItemSetEff[x] && player->ItemSetEff[x]->setid == setid)
@@ -46,21 +53,26 @@ void AddItemsSetItem(Player*player,Item *item)
break;
}
}
+
if(!eff)
{
eff = new ItemSetEffect;
memset(eff,0,sizeof(ItemSetEffect));
eff->setid = setid;
+
size_t x = 0;
for(; x < player->ItemSetEff.size(); x++)
if(!player->ItemSetEff[x])
break;
+
if(x < player->ItemSetEff.size())
player->ItemSetEff[x]=eff;
else
player->ItemSetEff.push_back(eff);
}
+
++eff->item_count;
+
for(uint32 x=0;x<8;x++)
{
if(!set->spells [x])
@@ -68,12 +80,15 @@ void AddItemsSetItem(Player*player,Item *item)
//not enough for spell
if(set->items_to_triggerspell[x] > eff->item_count)
continue;
+
uint32 z=0;
for(;z<8;z++)
if(eff->spells[z] && eff->spells[z]->Id==set->spells[x])
break;
+
if(z < 8)
continue;
+
//new spell
for(uint32 y=0;y<8;y++)
{
@@ -85,6 +100,7 @@ void AddItemsSetItem(Player*player,Item *item)
sLog.outError("WORLD: unknown spell id %u in items set %u effects", set->spells[x],setid);
break;
}
+
// spell casted only if fit form requirement, in other case will casted at form change
player->ApplyEquipSpell(spellInfo,NULL,true);
eff->spells[y] = spellInfo;
@@ -93,15 +109,19 @@ void AddItemsSetItem(Player*player,Item *item)
}
}
}
+
void RemoveItemsSetItem(Player*player,ItemPrototype const *proto)
{
uint32 setid = proto->ItemSet;
+
ItemSetEntry const *set = sItemSetStore.LookupEntry(setid);
+
if(!set)
{
sLog.outErrorDb("Item set #%u for item #%u not found, mods not removed.",setid,proto->ItemId);
return;
}
+
ItemSetEffect *eff = NULL;
size_t setindex = 0;
for(;setindex < player->ItemSetEff.size(); setindex++)
@@ -112,17 +132,22 @@ void RemoveItemsSetItem(Player*player,ItemPrototype const *proto)
break;
}
}
+
// can be in case now enough skill requirement for set appling but set has been appliend when skill requirement not enough
if(!eff)
return;
+
--eff->item_count;
+
for(uint32 x=0;x<8;x++)
{
if(!set->spells[x])
continue;
+
// enough for spell
if(set->items_to_triggerspell[x] <= eff->item_count)
continue;
+
for(uint32 z=0;z<8;z++)
{
if(eff->spells[z] && eff->spells[z]->Id==set->spells[x])
@@ -134,6 +159,7 @@ void RemoveItemsSetItem(Player*player,ItemPrototype const *proto)
}
}
}
+
if(!eff->item_count) //all items of a set were removed
{
assert(eff == player->ItemSetEff[setindex]);
@@ -141,10 +167,12 @@ void RemoveItemsSetItem(Player*player,ItemPrototype const *proto)
player->ItemSetEff[setindex] = NULL;
}
}
+
bool ItemCanGoIntoBag(ItemPrototype const *pProto, ItemPrototype const *pBagProto)
{
if(!pProto || !pBagProto)
return false;
+
switch(pBagProto->Class)
{
case ITEM_CLASS_CONTAINER:
@@ -204,11 +232,14 @@ bool ItemCanGoIntoBag(ItemPrototype const *pProto, ItemPrototype const *pBagProt
}
return false;
}
+
Item::Item( )
{
m_objectType |= TYPEMASK_ITEM;
m_objectTypeId = TYPEID_ITEM;
+
m_updateFlag = UPDATEFLAG_HIGHGUID;
+
m_valuesCount = ITEM_END;
m_slot = 0;
uState = ITEM_NEW;
@@ -217,39 +248,52 @@ Item::Item( )
m_lootGenerated = false;
mb_in_trade = false;
}
+
bool Item::Create( uint32 guidlow, uint32 itemid, Player const* owner)
{
Object::_Create( guidlow, 0, HIGHGUID_ITEM );
+
SetEntry(itemid);
SetFloatValue(OBJECT_FIELD_SCALE_X, 1.0f);
+
SetUInt64Value(ITEM_FIELD_OWNER, owner ? owner->GetGUID() : 0);
SetUInt64Value(ITEM_FIELD_CONTAINED, owner ? owner->GetGUID() : 0);
+
ItemPrototype const *itemProto = objmgr.GetItemPrototype(itemid);
if(!itemProto)
return false;
+
SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);
SetUInt32Value(ITEM_FIELD_MAXDURABILITY, itemProto->MaxDurability);
SetUInt32Value(ITEM_FIELD_DURABILITY, itemProto->MaxDurability);
+
for(uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
SetSpellCharges(i,itemProto->Spells[i].SpellCharges);
+
SetUInt32Value(ITEM_FIELD_FLAGS, itemProto->Flags);
SetUInt32Value(ITEM_FIELD_DURATION, abs(itemProto->Duration));
+
return true;
}
+
void Item::UpdateDuration(Player* owner, uint32 diff)
{
if (!GetUInt32Value(ITEM_FIELD_DURATION))
return;
+
sLog.outDebug("Item::UpdateDuration Item (Entry: %u Duration %u Diff %u)",GetEntry(),GetUInt32Value(ITEM_FIELD_DURATION),diff);
+
if (GetUInt32Value(ITEM_FIELD_DURATION)<=diff)
{
Script->ItemExpire(owner, GetProto());
- owner->DestroyItem(GetBagSlot(), GetSlot(), true);
+ owner->DestroyItem(GetBagSlot(), GetSlot(), true);
return;
}
+
SetUInt32Value(ITEM_FIELD_DURATION, GetUInt32Value(ITEM_FIELD_DURATION) - diff);
SetState(ITEM_CHANGED, owner); // save new time in database
}
+
void Item::SaveToDB()
{
uint32 guid = GetGUIDLow();
@@ -272,7 +316,9 @@ void Item::SaveToDB()
for(uint16 i = 0; i < m_valuesCount; ++i )
ss << GetUInt32Value(i) << " ";
ss << "', owner_guid = '" << GUID_LOPART(GetOwnerGUID()) << "' 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;
@@ -291,30 +337,37 @@ void Item::SaveToDB()
}
SetState(ITEM_UNCHANGED);
}
+
bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
{
// 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);
+
bool delete_result = false;
if(!result)
{
result = CharacterDatabase.PQuery("SELECT data FROM item_instance WHERE guid = '%u'", guid);
delete_result = true;
}
+
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);
if (delete_result) delete result;
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)
@@ -322,42 +375,51 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
SetUInt64Value(OBJECT_FIELD_GUID, MAKE_NEW_GUID(guid,0, HIGHGUID_ITEM));
need_save = true;
}
+
if (delete_result) delete result;
+
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);
+
need_save = true;
}
+
// recalculate suffix factor
if(GetItemRandomPropertyId() < 0)
{
if(UpdateItemSuffixFactor())
need_save = true;
}
+
// Remove bind flag for items vs NO_BIND set
if (IsSoulBound() && proto->Bonding == NO_BIND)
{
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))
{
SetUInt32Value(ITEM_FIELD_DURATION,abs(proto->Duration));
need_save = true;
}
+
// set correct owner
if(owner_guid != 0 && GetOwnerGUID() != owner_guid)
{
SetOwnerGUID(owner_guid);
need_save = true;
}
+
if(need_save) // normal item changed state set not work at loading
{
std::ostringstream ss;
@@ -365,26 +427,33 @@ bool Item::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult *result)
for(uint16 i = 0; i < m_valuesCount; ++i )
ss << GetUInt32Value(i) << " ";
ss << "', owner_guid = '" << GUID_LOPART(GetOwnerGUID()) << "' WHERE guid = '" << guid << "'";
+
CharacterDatabase.Execute( ss.str().c_str() );
}
+
return true;
}
+
void Item::DeleteFromDB()
{
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'",GetGUIDLow());
}
+
void Item::DeleteFromInventoryDB()
{
CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item = '%u'",GetGUIDLow());
}
+
ItemPrototype const *Item::GetProto() const
{
return objmgr.GetItemPrototype(GetEntry());
}
+
Player* Item::GetOwner()const
{
return objmgr.GetPlayer(GetOwnerGUID());
}
+
uint32 Item::GetSkill()
{
const static uint32 item_weapon_skills[MAX_ITEM_SUBCLASS_WEAPON] =
@@ -395,11 +464,14 @@ uint32 Item::GetSkill()
SKILL_DAGGERS, SKILL_THROWN, SKILL_ASSASSINATION, SKILL_CROSSBOWS, SKILL_WANDS,
SKILL_FISHING
};
+
const static uint32 item_armor_skills[MAX_ITEM_SUBCLASS_ARMOR] =
{
0,SKILL_CLOTH,SKILL_LEATHER,SKILL_MAIL,SKILL_PLATE_MAIL,0,SKILL_SHIELD,0,0,0,0
};
+
ItemPrototype const* proto = GetProto();
+
switch (proto->Class)
{
case ITEM_CLASS_WEAPON:
@@ -407,18 +479,22 @@ uint32 Item::GetSkill()
return 0;
else
return item_weapon_skills[proto->SubClass];
+
case ITEM_CLASS_ARMOR:
if( proto->SubClass >= MAX_ITEM_SUBCLASS_ARMOR )
return 0;
else
return item_armor_skills[proto->SubClass];
+
default:
return 0;
}
}
+
uint32 Item::GetSpell()
{
ItemPrototype const* proto = GetProto();
+
switch (proto->Class)
{
case ITEM_CLASS_WEAPON:
@@ -454,20 +530,25 @@ uint32 Item::GetSpell()
}
return 0;
}
+
int32 Item::GenerateItemRandomPropertyId(uint32 item_id)
{
ItemPrototype const *itemProto = sItemStorage.LookupEntry<ItemPrototype>(item_id);
+
if(!itemProto)
return 0;
+
// item must have one from this field values not null if it can have random enchantments
if((!itemProto->RandomProperty) && (!itemProto->RandomSuffix))
return 0;
+
// item can have not null only one from field values
if((itemProto->RandomProperty) && (itemProto->RandomSuffix))
{
sLog.outErrorDb("Item template %u have RandomProperty==%u and RandomSuffix==%u, but must have one from field =0",itemProto->ItemId,itemProto->RandomProperty,itemProto->RandomSuffix);
return 0;
}
+
// RandomProperty case
if(itemProto->RandomProperty)
{
@@ -478,6 +559,7 @@ int32 Item::GenerateItemRandomPropertyId(uint32 item_id)
sLog.outErrorDb("Enchantment id #%u used but it doesn't have records in 'ItemRandomProperties.dbc'",randomPropId);
return 0;
}
+
return random_id->ID;
}
// RandomSuffix case
@@ -490,13 +572,16 @@ int32 Item::GenerateItemRandomPropertyId(uint32 item_id)
sLog.outErrorDb("Enchantment id #%u used but it doesn't have records in sItemRandomSuffixStore.",randomPropId);
return 0;
}
+
return -int32(random_id->ID);
}
}
+
void Item::SetItemRandomProperties(int32 randomPropId)
{
if(!randomPropId)
return;
+
if(randomPropId > 0)
{
ItemRandomPropertiesEntry const *item_rand = sItemRandomPropertiesStore.LookupEntry(randomPropId);
@@ -523,11 +608,13 @@ void Item::SetItemRandomProperties(int32 randomPropId)
UpdateItemSuffixFactor();
SetState(ITEM_CHANGED);
}
+
for(uint32 i = PROP_ENCHANTMENT_SLOT_0; i < PROP_ENCHANTMENT_SLOT_0 + 3; ++i)
SetEnchantment(EnchantmentSlot(i),item_rand->enchant_id[i - PROP_ENCHANTMENT_SLOT_0],0,0);
}
}
}
+
bool Item::UpdateItemSuffixFactor()
{
uint32 suffixFactor = GenerateEnchSuffixFactor(GetEntry());
@@ -536,6 +623,7 @@ bool Item::UpdateItemSuffixFactor()
SetUInt32Value(ITEM_FIELD_PROPERTY_SEED,suffixFactor);
return true;
}
+
void Item::SetState(ItemUpdateState state, Player *forplayer)
{
if (uState == ITEM_NEW && state == ITEM_REMOVED)
@@ -545,6 +633,7 @@ void Item::SetState(ItemUpdateState state, Player *forplayer)
delete this;
return;
}
+
if (state != ITEM_UNCHANGED)
{
// new items must stay in new state until saved
@@ -559,9 +648,11 @@ void Item::SetState(ItemUpdateState state, Player *forplayer)
uState = ITEM_UNCHANGED;
}
}
+
void Item::AddToUpdateQueueOf(Player *player)
{
if (IsInUpdateQueue()) return;
+
if (!player)
{
player = GetOwner();
@@ -571,18 +662,23 @@ void Item::AddToUpdateQueueOf(Player *player)
return;
}
}
+
if (player->GetGUID() != GetOwnerGUID())
{
sLog.outDebug("Item::AddToUpdateQueueOf - Owner's guid (%u) and player's guid (%u) don't match!", GUID_LOPART(GetOwnerGUID()), player->GetGUIDLow());
return;
}
+
if (player->m_itemUpdateQueueBlocked) return;
+
player->m_itemUpdateQueue.push_back(this);
uQueuePos = player->m_itemUpdateQueue.size()-1;
}
+
void Item::RemoveFromUpdateQueueOf(Player *player)
{
if (!IsInUpdateQueue()) return;
+
if (!player)
{
player = GetOwner();
@@ -592,29 +688,37 @@ void Item::RemoveFromUpdateQueueOf(Player *player)
return;
}
}
+
if (player->GetGUID() != GetOwnerGUID())
{
sLog.outDebug("Item::RemoveFromUpdateQueueOf - Owner's guid (%u) and player's guid (%u) don't match!", GUID_LOPART(GetOwnerGUID()), player->GetGUIDLow());
return;
}
+
if (player->m_itemUpdateQueueBlocked) return;
+
player->m_itemUpdateQueue[uQueuePos] = NULL;
uQueuePos = -1;
}
+
uint8 Item::GetBagSlot() const
{
return m_container ? m_container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
}
+
bool Item::IsEquipped() const
{
return !IsInBag() && m_slot < EQUIPMENT_SLOT_END;
}
+
bool Item::CanBeTraded(bool mail) const
{
if ((!mail || !IsBoundAccountWide()) && IsSoulBound())
return false;
+
if (IsBag() && (Player::IsBagPos(GetPos()) || !((Bag const*)this)->IsEmpty()) )
return false;
+
if (Player* owner = GetOwner())
{
if (owner->CanUnequipItem(GetPos(),false) != EQUIP_ERR_OK )
@@ -622,10 +726,13 @@ bool Item::CanBeTraded(bool mail) const
if (owner->GetLootGUID()==GetGUID())
return false;
}
+
if (IsBoundByEnchant())
return false;
+
return true;
}
+
bool Item::IsBoundByEnchant() const
{
// Check all enchants for soulbound
@@ -634,17 +741,21 @@ bool Item::IsBoundByEnchant() const
uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot));
if(!enchant_id)
continue;
+
SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
if(!enchantEntry)
continue;
+
if(enchantEntry->slot & ENCHANTMENT_CAN_SOULBOUND)
return true;
}
return false;
}
+
bool Item::IsFitToSpellRequirements(SpellEntry const* spellInfo) const
{
ItemPrototype const* proto = GetProto();
+
if (spellInfo->EquippedItemClass != -1) // -1 == any item class
{
// Special case - accept vellum for armor/weapon requirements
@@ -652,14 +763,17 @@ bool Item::IsFitToSpellRequirements(SpellEntry const* spellInfo) const
||( spellInfo->EquippedItemClass==ITEM_CLASS_WEAPON && proto->IsWeaponVellum()))
if (spellmgr.IsSkillTypeSpell(spellInfo->Id, SKILL_ENCHANTING)) // only for enchanting spells
return true;
+
if(spellInfo->EquippedItemClass != int32(proto->Class))
return false; // wrong item class
+
if(spellInfo->EquippedItemSubClassMask != 0) // 0 == any subclass
{
if((spellInfo->EquippedItemSubClassMask & (1 << proto->SubClass)) == 0)
return false; // subclass not present in mask
}
}
+
if(spellInfo->EquippedItemInventoryTypeMask != 0) // 0 == any inventory type
{
// Special case - accept weapon type for main and offhand requirements
@@ -670,71 +784,90 @@ bool Item::IsFitToSpellRequirements(SpellEntry const* spellInfo) const
else if ((spellInfo->EquippedItemInventoryTypeMask & (1 << proto->InventoryType)) == 0)
return false; // inventory type not present in mask
}
+
return true;
}
+
bool Item::IsTargetValidForItemUse(Unit* pUnitTarget)
{
ItemRequiredTargetMapBounds bounds = objmgr.GetItemRequiredTargetMapBounds(GetProto()->ItemId);
+
if (bounds.first == bounds.second)
return true;
+
if (!pUnitTarget)
return false;
+
for(ItemRequiredTargetMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
if(itr->second.IsFitToRequirements(pUnitTarget))
return true;
+
return false;
}
+
void Item::SetEnchantment(EnchantmentSlot slot, uint32 id, uint32 duration, uint32 charges)
{
// Better lost small time at check in comparison lost time at item save to DB.
if((GetEnchantmentId(slot) == id) && (GetEnchantmentDuration(slot) == duration) && (GetEnchantmentCharges(slot) == charges))
return;
+
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_ID_OFFSET,id);
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET,duration);
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET,charges);
SetState(ITEM_CHANGED);
}
+
void Item::SetEnchantmentDuration(EnchantmentSlot slot, uint32 duration)
{
if(GetEnchantmentDuration(slot) == duration)
return;
+
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_DURATION_OFFSET,duration);
SetState(ITEM_CHANGED);
}
+
void Item::SetEnchantmentCharges(EnchantmentSlot slot, uint32 charges)
{
if(GetEnchantmentCharges(slot) == charges)
return;
+
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot*MAX_ENCHANTMENT_OFFSET + ENCHANTMENT_CHARGES_OFFSET,charges);
SetState(ITEM_CHANGED);
}
+
void Item::ClearEnchantment(EnchantmentSlot slot)
{
if(!GetEnchantmentId(slot))
return;
+
for(uint8 x = 0; x < 3; ++x)
SetUInt32Value(ITEM_FIELD_ENCHANTMENT_1_1 + slot*MAX_ENCHANTMENT_OFFSET + x, 0);
SetState(ITEM_CHANGED);
}
+
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 = GetProto()->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)
{
@@ -746,10 +879,12 @@ bool Item::GemsFitSockets() const
GemColor = gemProperty->color;
}
}
+
fits &= (GemColor & SocketColor) ? true : false;
}
return fits;
}
+
uint8 Item::GetGemCountWithID(uint32 GemID) const
{
uint8 count = 0;
@@ -758,14 +893,17 @@ uint8 Item::GetGemCountWithID(uint32 GemID) const
uint32 enchant_id = GetEnchantmentId(EnchantmentSlot(enchant_slot));
if(!enchant_id)
continue;
+
SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);
if(!enchantEntry)
continue;
+
if(GemID == enchantEntry->GemID)
++count;
}
return count;
}
+
uint8 Item::GetGemCountWithLimitCategory(uint32 limitCategory) const
{
uint8 count = 0;
@@ -774,22 +912,27 @@ uint8 Item::GetGemCountWithLimitCategory(uint32 limitCategory) const
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->ItemLimitCategory==limitCategory)
++count;
}
return count;
}
+
bool Item::IsLimitedToAnotherMapOrZone( uint32 cur_mapId, uint32 cur_zoneId) const
{
ItemPrototype const* proto = GetProto();
return proto && (proto->Map && proto->Map != cur_mapId || proto->Area && proto->Area != cur_zoneId );
}
+
// Though the client has the information in the item's data field,
// we have to send SMSG_ITEM_TIME_UPDATE to display the remaining
// time.
@@ -797,21 +940,26 @@ void Item::SendTimeUpdate(Player* owner)
{
if (!GetUInt32Value(ITEM_FIELD_DURATION))
return;
+
WorldPacket data(SMSG_ITEM_TIME_UPDATE, (8+4));
data << (uint64)GetGUID();
data << (uint32)GetUInt32Value(ITEM_FIELD_DURATION);
owner->GetSession()->SendPacket(&data);
}
+
Item* Item::CreateItem( uint32 item, uint32 count, Player const* player )
{
if ( count < 1 )
return NULL; //don't create item at zero count
+
ItemPrototype const *pProto = objmgr.GetItemPrototype( item );
if( pProto )
{
if ( count > pProto->GetMaxStackSize())
count = pProto->GetMaxStackSize();
+
assert(count !=0 && "pProto->Stackable==0 but checked at loading already");
+
Item *pItem = NewItemOrBag( pProto );
if( pItem->Create(objmgr.GenerateLowGuid(HIGHGUID_ITEM), item, player) )
{
@@ -825,11 +973,13 @@ Item* Item::CreateItem( uint32 item, uint32 count, Player const* player )
assert(false);
return NULL;
}
+
Item* Item::CloneItem( uint32 count, Player const* player ) const
{
Item* newItem = CreateItem( GetEntry(), count, player );
if(!newItem)
return NULL;
+
newItem->SetUInt32Value( ITEM_FIELD_CREATOR, GetUInt32Value( ITEM_FIELD_CREATOR ) );
newItem->SetUInt32Value( ITEM_FIELD_GIFTCREATOR, GetUInt32Value( ITEM_FIELD_GIFTCREATOR ) );
newItem->SetUInt32Value( ITEM_FIELD_FLAGS, GetUInt32Value( ITEM_FIELD_FLAGS ) );
@@ -837,17 +987,21 @@ Item* Item::CloneItem( uint32 count, Player const* player ) const
newItem->SetItemRandomProperties(GetItemRandomPropertyId());
return newItem;
}
+
bool Item::IsBindedNotWith( Player const* player ) const
{
// not binded item
if(!IsSoulBound())
return false;
+
// own item
if(GetOwnerGUID()== player->GetGUID())
return false;
+
// not BOA item case
if(!IsBoundAccountWide())
return true;
+
// online
if(Player* owner = objmgr.GetPlayer(GetOwnerGUID()))
{
@@ -859,12 +1013,15 @@ bool Item::IsBindedNotWith( Player const* player ) const
return objmgr.GetPlayerAccountIdByGUID(GetOwnerGUID()) != player->GetSession()->GetAccountId();
}
}
+
bool ItemRequiredTarget::IsFitToRequirements( Unit* pUnitTarget ) const
{
if(pUnitTarget->GetTypeId() != TYPEID_UNIT)
return false;
+
if(pUnitTarget->GetEntry() != m_uiTargetEntry)
return false;
+
switch(m_uiType)
{
case ITEM_TARGET_TYPE_CREATURE: