/// <summary> /// Adds a new the <see cref="ItemEnchantment"/> to the given Slot. /// Will remove any existing Enchantment in that slot. /// </summary> /// <param name="enchantSlot"></param> public void ApplyEnchant(ItemEnchantmentEntry enchantEntry, EnchantSlot enchantSlot, int duration, int charges, bool applyBoni) { // TODO: Add charges if (m_enchantments == null) { m_enchantments = new ItemEnchantment[(int)EnchantSlot.End]; } if (m_enchantments[(int)enchantSlot] != null) { RemoveEnchant(enchantSlot); } var enchant = new ItemEnchantment(enchantEntry, enchantSlot, DateTime.Now, duration); m_enchantments[(int)enchantSlot] = enchant; m_record.SetEnchant(enchantSlot, (int)enchant.Entry.Id, duration); SetEnchantId(enchantSlot, enchantEntry.Id); SetEnchantDuration(enchantSlot, duration); if (charges > 0) { SetEnchantCharges(enchantSlot, charges - 1); } var owner = OwningCharacter; if (owner != null) { EnchantMgr.ApplyEnchantToItem(this, enchant); if (enchant.Entry.GemTemplate != null) { owner.Inventory.ModUniqueCount(enchant.Entry.GemTemplate, 1); } OnOwnerReceivedNewEnchant(enchant); if (applyBoni && IsEquippedItem) { // render on Character and apply boni SetEnchantEquipped(enchant); } } }
/// <summary> /// Adds a new the <see cref="T:WCell.RealmServer.Items.Enchanting.ItemEnchantment" /> to the given Slot. /// Will remove any existing Enchantment in that slot. /// </summary> /// <param name="enchantSlot"></param> public void ApplyEnchant(ItemEnchantmentEntry enchantEntry, EnchantSlot enchantSlot, int duration, int charges, bool applyBoni) { if (m_enchantments == null) { m_enchantments = new ItemEnchantment[12]; } if (m_enchantments[(int)enchantSlot] != null) { RemoveEnchant(enchantSlot); } ItemEnchantment enchant = new ItemEnchantment(enchantEntry, enchantSlot, DateTime.Now, duration); m_enchantments[(int)enchantSlot] = enchant; m_record.SetEnchant(enchantSlot, (int)enchant.Entry.Id, duration); SetEnchantId(enchantSlot, enchantEntry.Id); SetEnchantDuration(enchantSlot, duration); if (charges > 0) { SetEnchantCharges(enchantSlot, charges - 1); } Character owningCharacter = OwningCharacter; if (owningCharacter == null) { return; } EnchantMgr.ApplyEnchantToItem(this, enchant); if (enchant.Entry.GemTemplate != null) { owningCharacter.Inventory.ModUniqueCount(enchant.Entry.GemTemplate, 1); } OnOwnerReceivedNewEnchant(enchant); if (!applyBoni || !IsEquippedItem) { return; } SetEnchantEquipped(enchant); }