int32 Item::AddEnchantment(EnchantEntry* Enchantment, uint32 Duration, bool Perm /* = false */, bool apply /* = true */, bool RemoveAtLogout /* = false */, uint32 Slot_, uint32 RandomSuffix, bool dummy /* = false */ ) { int32 Slot = Slot_; m_isDirty = true; // Create the enchantment struct. EnchantmentInstance Instance; Instance.ApplyTime = UNIXTIME; Instance.BonusApplied = false; Instance.Slot = Slot; Instance.Enchantment = Enchantment; Instance.Duration = Duration; Instance.RemoveAtLogout = RemoveAtLogout; Instance.RandomSuffix = RandomSuffix; Instance.Dummy = dummy; // Set the enchantment in the item fields. SetEnchantmentId(Slot, Enchantment->Id); SetEnchantmentDuration(Slot, (uint32)Instance.ApplyTime); SetEnchantmentCharges(Slot, 0); // Add it to our map. Enchantments.insert(make_pair((uint32)Slot, Instance)); if( m_owner == NULL ) return Slot; // Add the removal event. if( Duration ) sEventMgr.AddEvent( this, &Item::RemoveEnchantment, uint32(Slot), EVENT_REMOVE_ENCHANTMENT1 + Slot, Duration * 1000, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT ); // No need to send the log packet, if the owner isn't in world (we're still loading) if( !m_owner->IsInWorld() ) return Slot; if( apply ) { /* WorldPacket EnchantLog( SMSG_ENCHANTMENTLOG, 25 ); EnchantLog << m_owner->GetGUID(); EnchantLog << m_owner->GetGUID(); EnchantLog << m_uint32Values[OBJECT_FIELD_ENTRY]; EnchantLog << Enchantment->Id; EnchantLog << uint8(0); m_owner->GetSession()->SendPacket( &EnchantLog );*/ if( m_owner->GetTradeTarget() ) m_owner->SendTradeUpdate(); if(Instance.Dummy) return Slot; /* Only apply the enchantment bonus if we're equipped */ uint8 slot = m_owner->GetItemInterface()->GetInventorySlotByGuid( GetGUID() ); if( slot > EQUIPMENT_SLOT_START && slot < EQUIPMENT_SLOT_END ) ApplyEnchantmentBonus( Slot, APPLY ); } m_owner->SaveToDB(false); return Slot; }
void Item::RemoveEnchantment(uint32 EnchantmentSlot) { // Make sure we actually exist. EnchantmentMap::iterator itr = Enchantments.find(EnchantmentSlot); if (itr == Enchantments.end()) return; m_isDirty = true; uint32 Slot = itr->first; if (itr->second.BonusApplied) ApplyEnchantmentBonus(EnchantmentSlot, REMOVE); // Unset the item fields. SetEnchantmentId(Slot, 0); SetEnchantmentDuration(Slot, 0); SetEnchantmentCharges(Slot, 0); // Remove the enchantment event for removal. event_RemoveEvents(EVENT_REMOVE_ENCHANTMENT1 + Slot); // Remove the enchantment instance. Enchantments.erase(itr); }
void Item::LoadFromDB(Field* fields, Player* plr, bool light) { uint32 itemid = fields[2].GetUInt32(); uint32 random_prop, random_suffix; uint32 count; m_itemProto = ItemPrototypeStorage.LookupEntry(itemid); ARCEMU_ASSERT(m_itemProto != NULL); locked = m_itemProto->LockId ? true : false; SetEntry(itemid); m_owner = plr; wrapped_item_id = fields[3].GetUInt32(); SetGiftCreatorGUID(fields[4].GetUInt32()); SetCreatorGUID(fields[5].GetUInt32()); count = fields[6].GetUInt32(); if (count > m_itemProto->MaxCount && (m_owner && !m_owner->ItemStackCheat)) count = m_itemProto->MaxCount; SetStackCount(count); SetChargesLeft(fields[7].GetUInt32()); SetUInt32Value(ITEM_FIELD_FLAGS, fields[8].GetUInt32()); random_prop = fields[9].GetUInt32(); random_suffix = fields[10].GetUInt32(); SetItemRandomPropertyId(random_prop); int32 rprop = int32(random_prop); // If random properties point is negative that means the item uses random suffix as random enchantment if (rprop < 0) SetItemRandomSuffixFactor(random_suffix); else SetItemRandomSuffixFactor(0); //SetTextId( fields[11].GetUInt32() ); SetDurabilityMax(m_itemProto->MaxDurability); SetDurability(fields[12].GetUInt32()); if (light) return; string enchant_field = fields[15].GetString(); vector< string > enchants = StrSplit(enchant_field, ";"); uint32 enchant_id; EnchantEntry* entry; uint32 time_left; uint32 enchslot; for (vector<string>::iterator itr = enchants.begin(); itr != enchants.end(); ++itr) { if (sscanf((*itr).c_str(), "%u,%u,%u", (unsigned int*)&enchant_id, (unsigned int*)&time_left, (unsigned int*)&enchslot) == 3) { entry = dbcEnchant.LookupEntryForced(enchant_id); if (entry && entry->Id == enchant_id && m_itemProto->SubClass != ITEM_SUBCLASS_WEAPON_THROWN) { AddEnchantment(entry, time_left, (time_left == 0), false, false, enchslot); //(enchslot != 2) ? false : true, false); } else { /* EnchantEntry *pEnchant = new EnchantEntry; memset(pEnchant,0,sizeof(EnchantEntry)); pEnchant->Id = enchant_id; if(enchslot != 2) AddEnchantment(pEnchant,0,true, false); else AddEnchantment(pEnchant,0,false,false); */ } } } ItemExpiresOn = fields[16].GetUInt32(); ///////////////////////////////////////////////////// Refund stuff //////////////////////// std::pair< time_t, uint32 > refundentry; refundentry.first = fields[17].GetUInt32(); refundentry.second = fields[18].GetUInt32(); if (refundentry.first != 0 && refundentry.second != 0 && GetOwner() != NULL) { uint32* played = GetOwner()->GetPlayedtime(); if (played[1] < uint32(refundentry.first + 60 * 60 * 2)) m_owner->GetItemInterface()->AddRefundable(this, refundentry.second, refundentry.first); } /////////////////////////////////////////////////////////////////////////////////////////// text = fields[19].GetString(); ApplyRandomProperties(false); // Charter stuff if (GetEntry() == ITEM_ENTRY_GUILD_CHARTER) { SoulBind(); SetStackCount(1); SetItemRandomSuffixFactor(57813883); if (plr != NULL && plr->m_charters[CHARTER_TYPE_GUILD]) SetEnchantmentId(0, plr->m_charters[CHARTER_TYPE_GUILD]->GetID()); } if (GetEntry() == ARENA_TEAM_CHARTER_2v2) { SoulBind(); SetStackCount(1); SetItemRandomSuffixFactor(57813883); if (plr != NULL && plr->m_charters[CHARTER_TYPE_ARENA_2V2]) SetEnchantmentId(0, plr->m_charters[CHARTER_TYPE_ARENA_2V2]->GetID()); } if (GetEntry() == ARENA_TEAM_CHARTER_3v3) { SoulBind(); SetStackCount(1); SetItemRandomSuffixFactor(57813883); if (plr != NULL && plr->m_charters[CHARTER_TYPE_ARENA_3V3]) SetEnchantmentId(0, plr->m_charters[CHARTER_TYPE_ARENA_3V3]->GetID()); } if (GetEntry() == ARENA_TEAM_CHARTER_5v5) { SoulBind(); SetStackCount(1); SetItemRandomSuffixFactor(57813883); if (plr != NULL && plr->m_charters[CHARTER_TYPE_ARENA_5V5]) SetEnchantmentId(0, plr->m_charters[CHARTER_TYPE_ARENA_5V5]->GetID()); } }