public override ItemRandomSuffixEntry ConvertTo(byte[] rawData, ref int id) { ItemRandomSuffixEntry entry = new ItemRandomSuffixEntry(); uint num = 5; int field = 0; entry.Id = id = DBCRecordConverter.GetInt32(rawData, field++); field += 0x12; entry.Enchants = new ItemEnchantmentEntry[num]; entry.Values = new int[num]; for (int i = 0; i < num; i++) { uint num4 = DBCRecordConverter.GetUInt32(rawData, field); if (num4 != 0) { ItemEnchantmentEntry enchantmentEntry = EnchantMgr.GetEnchantmentEntry(num4); if (enchantmentEntry != null) { entry.Enchants[i] = enchantmentEntry; entry.Values[i] = DBCRecordConverter.GetInt32(rawData, field + ((int) num)); } } field++; } ArrayUtil.Trunc<ItemEnchantmentEntry>(ref entry.Enchants); ArrayUtil.TruncVals<int>(ref entry.Values); return entry; }
public override SpellFailedReason Initialize() { if (m_cast.TargetItem == null) { return(SpellFailedReason.ItemGone); } if (m_cast.TargetItem.Template.Level < Effect.Spell.BaseLevel) { return(SpellFailedReason.TargetLowlevel); } enchantEntry = EnchantMgr.GetEnchantmentEntry((uint)Effect.MiscValue); if (enchantEntry == null) { log.Error("Spell {0} refers to invalid EnchantmentEntry {1}", Effect.Spell, Effect.MiscValue); return(SpellFailedReason.Error); } if (!enchantEntry.CheckRequirements(m_cast.CasterUnit)) { return(SpellFailedReason.MinSkill); } return(SpellFailedReason.Ok); }
public void ApplyEnchant(int enchantEntryId, EnchantSlot enchantSlot, int duration, int charges, bool applyBoni) { if (enchantEntryId == 0) { return; } ItemEnchantmentEntry enchantmentEntry = EnchantMgr.GetEnchantmentEntry((uint)enchantEntryId); if (enchantmentEntry == null) { return; } ApplyEnchant(enchantmentEntry, enchantSlot, duration, charges, applyBoni); }
/// <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> /// Applies a set of random enchants in the prop slots between from and to /// </summary> public bool ApplyRandomEnchants(List <ItemRandomEnchantEntry> entries, EnchantSlot from, EnchantSlot to) { EnchantSlot enchantSlot = from; if (m_enchantments != null) { do { ; }while(m_enchantments[(int)enchantSlot] != null && m_enchantments.Length > (int)++enchantSlot); if (enchantSlot > to) { return(false); } } bool flag = false; foreach (ItemRandomEnchantEntry entry in entries) { if (Utility.Random(0.0f, 100f) < (double)entry.ChancePercent) { ItemEnchantmentEntry enchantmentEntry = EnchantMgr.GetEnchantmentEntry(entry.EnchantId); if (enchantmentEntry != null) { ApplyEnchant(enchantmentEntry, enchantSlot, 0, 0, true); flag = true; do { ; }while(m_enchantments[(int)enchantSlot] != null && ++enchantSlot <= to); if (enchantSlot > to) { return(true); } } } } return(flag); }
/// <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); }
public override SpellFailedReason Initialize() { if (this.m_cast.TargetItem == null) { return(SpellFailedReason.ItemGone); } if ((long)this.m_cast.TargetItem.Template.Level < (long)this.Effect.Spell.BaseLevel) { return(SpellFailedReason.TargetLowlevel); } this.enchantEntry = EnchantMgr.GetEnchantmentEntry((uint)this.Effect.MiscValue); if (this.enchantEntry == null) { EnchantItemEffectHandler.log.Error("Spell {0} refers to invalid EnchantmentEntry {1}", (object)this.Effect.Spell, (object)this.Effect.MiscValue); return(SpellFailedReason.Error); } return(!this.enchantEntry.CheckRequirements(this.m_cast.CasterUnit) ? SpellFailedReason.MinSkill : SpellFailedReason.Ok); }
internal void InitializeTemplate() { if (this.Names == null) { this.Names = new string[8]; } if (this.Descriptions == null) { this.Descriptions = new string[8]; } if (this.DefaultDescription == null) { this.DefaultDescription = ""; } if (string.IsNullOrEmpty(this.DefaultName) || this.Id == 0U) { return; } this.ItemId = (Asda2ItemId)this.Id; this.RequiredSkill = SkillHandler.Get(this.RequiredSkillId); this.Set = ItemMgr.GetSet(this.SetId); this.Lock = LockEntry.Entries.Get <LockEntry>(this.LockId); this.RequiredFaction = FactionMgr.Get(this.RequiredFactionId); this.RequiredProfession = SpellHandler.Get(this.RequiredProfessionId); this.SubClassMask = (ItemSubClassMask)(1 << (int)(this.SubClass & (ItemSubClass.WeaponDagger | ItemSubClass.WeaponThrown)) ); this.EquipmentSlots = ItemMgr.EquipmentSlotsByInvSlot.Get <EquipmentSlot[]>((uint)this.InventorySlotType); this.InventorySlotMask = (InventorySlotTypeMask)(1 << (int)(this.InventorySlotType & (InventorySlotType.WeaponRanged | InventorySlotType.Cloak))); this.IsAmmo = this.InventorySlotType == InventorySlotType.Ammo; this.IsKey = this.Class == ItemClass.Key; this.IsBag = this.InventorySlotType == InventorySlotType.Bag; this.IsContainer = this.Class == ItemClass.Container || this.Class == ItemClass.Quiver; this.IsStackable = this.MaxAmount > 1 && this.RandomSuffixId == 0U && this.RandomPropertiesId == 0U; this.IsTwoHandWeapon = this.InventorySlotType == InventorySlotType.TwoHandWeapon; this.SetIsWeapon(); if (this.ToolCategory != ToolCategory.None) { ItemMgr.FirstTotemsPerCat[(uint)this.ToolCategory] = this; } if (this.GemPropertiesId != 0U) { this.GemProperties = EnchantMgr.GetGemproperties(this.GemPropertiesId); if (this.GemProperties != null) { this.GemProperties.Enchantment.GemTemplate = this; } } if (this.Sockets == null) { this.Sockets = new SocketInfo[3]; } else if (((IEnumerable <SocketInfo>) this.Sockets).Contains <SocketInfo>( (Func <SocketInfo, bool>)(sock => sock.Color != SocketColor.None))) { this.HasSockets = true; } if (this.Damages == null) { this.Damages = DamageInfo.EmptyArray; } if (this.Resistances == null) { this.Resistances = new int[7]; } if (this.SocketBonusEnchantId != 0U) { this.SocketBonusEnchant = EnchantMgr.GetEnchantmentEntry(this.SocketBonusEnchantId); } switch (this.Class) { case ItemClass.Weapon: this.ItemProfession = ItemProfessions.WeaponSubClassProfessions.Get <SkillId>((uint)this.SubClass); break; case ItemClass.Armor: this.ItemProfession = ItemProfessions.ArmorSubClassProfessions.Get <SkillId>((uint)this.SubClass); break; } int sheathType = (int)this.SheathType; if (this.Spells != null) { ArrayUtil.Prune <ItemSpell>(ref this.Spells); for (int index = 0; index < 5; ++index) { this.Spells[index].Index = (uint)index; this.Spells[index].FinalizeAfterLoad(); } } else { this.Spells = ItemSpell.EmptyArray; } this.UseSpell = ((IEnumerable <ItemSpell>) this.Spells).Where <ItemSpell>( (Func <ItemSpell, bool>)(itemSpell => { if (itemSpell.Trigger == ItemSpellTrigger.Use) { return(itemSpell.Spell != null); } return(false); })).FirstOrDefault <ItemSpell>(); if (this.UseSpell != null) { this.UseSpell.Spell.RequiredTargetType = this.RequiredTargetType; this.UseSpell.Spell.RequiredTargetId = this.RequiredTargetId; } this.EquipSpells = ((IEnumerable <ItemSpell>) this.Spells).Where <ItemSpell>((Func <ItemSpell, bool>)(spell => { if (spell.Trigger == ItemSpellTrigger.Equip) { return(spell.Spell != null); } return(false); })).Select <ItemSpell, Spell>((Func <ItemSpell, Spell>)(itemSpell => itemSpell.Spell)).ToArray <Spell>(); this.SoulstoneSpell = ((IEnumerable <ItemSpell>) this.Spells).Where <ItemSpell>( (Func <ItemSpell, bool>)(spell => { if (spell.Trigger == ItemSpellTrigger.Soulstone) { return(spell.Spell != null); } return(false); })).Select <ItemSpell, Spell>((Func <ItemSpell, Spell>)(itemSpell => itemSpell.Spell)) .FirstOrDefault <Spell>(); this.HitSpells = ((IEnumerable <ItemSpell>) this.Spells).Where <ItemSpell>((Func <ItemSpell, bool>)(spell => { if (spell.Trigger == ItemSpellTrigger.ChanceOnHit) { return(spell.Spell != null); } return(false); })).Select <ItemSpell, Spell>((Func <ItemSpell, Spell>)(itemSpell => itemSpell.Spell)).ToArray <Spell>(); this.ConsumesAmount = (this.Class == ItemClass.Consumable || ((IEnumerable <ItemSpell>) this.Spells).Contains <ItemSpell>( (Func <ItemSpell, bool>)(spell => spell.Trigger == ItemSpellTrigger.Consume))) && (this.UseSpell == null || !this.UseSpell.HasCharges); this.IsHearthStone = this.UseSpell != null && this.UseSpell.Spell.IsHearthStoneSpell; this.IsInventory = this.InventorySlotType != InventorySlotType.None && this.InventorySlotType != InventorySlotType.Bag && this.InventorySlotType != InventorySlotType.Quiver && this.InventorySlotType != InventorySlotType.Relic; if (this.SetId != ItemSetId.None) { ItemSet itemSet = ItemMgr.Sets.Get <ItemSet>((uint)this.SetId); if (itemSet != null) { int num = (int)ArrayUtil.Add <ItemTemplate>(ref itemSet.Templates, this); } } if (this.Mods != null) { ArrayUtil.TruncVals <StatModifier>(ref this.Mods); } else { this.Mods = StatModifier.EmptyArray; } this.IsCharter = this.Flags.HasFlag((Enum)ItemFlags.Charter); this.RandomSuffixFactor = EnchantMgr.GetRandomSuffixFactor(this); if (this.IsCharter) { this.Creator = (Func <Item>)(() => (Item) new PetitionCharter()); } else if (this.IsContainer) { this.Creator = (Func <Item>)(() => (Item) new Container()); } else { this.Creator = (Func <Item>)(() => new Item()); } }
internal void InitializeTemplate() { if (Names == null) { Names = new string[(int)ClientLocale.End]; } if (Descriptions == null) { Descriptions = new string[(int)ClientLocale.End]; } if (DefaultDescription == null) { DefaultDescription = ""; } if (string.IsNullOrEmpty(DefaultName) || Id == 0) { // something's off with these entries return; } ItemId = (ItemId)Id; //Faction = (FactionId)Faction; // faction, 3.2.2 RequiredSkill = SkillHandler.Get(RequiredSkillId); Set = ItemMgr.GetSet(SetId); Lock = LockEntry.Entries.Get(LockId); RequiredFaction = FactionMgr.Get(RequiredFactionId); RequiredProfession = SpellHandler.Get(RequiredProfessionId); SubClassMask = (ItemSubClassMask)(1 << (int)SubClass); EquipmentSlots = ItemMgr.EquipmentSlotsByInvSlot.Get((uint)InventorySlotType); InventorySlotMask = (InventorySlotTypeMask)(1 << (int)InventorySlotType); IsAmmo = InventorySlotType == InventorySlotType.Ammo; IsKey = Class == ItemClass.Key; IsBag = InventorySlotType == InventorySlotType.Bag; IsContainer = Class == ItemClass.Container || Class == ItemClass.Quiver; // enchantables can't be stacked IsStackable = MaxAmount > 1 && RandomSuffixId == 0 && RandomPropertiesId == 0; IsTwoHandWeapon = InventorySlotType == InventorySlotType.TwoHandWeapon; SetIsWeapon(); if (ToolCategory != 0) // && TotemCategory != TotemCategory.SkinningKnife) { ItemMgr.FirstTotemsPerCat[(uint)ToolCategory] = this; } if (GemPropertiesId != 0) { GemProperties = EnchantMgr.GetGemproperties(GemPropertiesId); if (GemProperties != null) { GemProperties.Enchantment.GemTemplate = this; } } if (Sockets == null) { Sockets = new SocketInfo[ItemConstants.MaxSocketCount]; } else if (Sockets.Contains(sock => sock.Color != 0)) { HasSockets = true; } if (Damages == null) { Damages = DamageInfo.EmptyArray; } if (Resistances == null) { Resistances = new int[(int)DamageSchool.Count]; } if (SocketBonusEnchantId != 0) { SocketBonusEnchant = EnchantMgr.GetEnchantmentEntry(SocketBonusEnchantId); } switch (Class) { case ItemClass.Weapon: ItemProfession = ItemProfessions.WeaponSubClassProfessions.Get((uint)SubClass); break; case ItemClass.Armor: ItemProfession = ItemProfessions.ArmorSubClassProfessions.Get((uint)SubClass); break; } if (SheathType == SheathType.Undetermined) { // TODO: Read sheath-id from Item.dbc } // spells if (Spells != null) { ArrayUtil.Prune(ref Spells); for (int i = 0; i < 5; i++) { Spells[i].Index = (uint)i; Spells[i].FinalizeAfterLoad(); } } else { Spells = ItemSpell.EmptyArray; } UseSpell = Spells.Where(itemSpell => itemSpell.Trigger == ItemSpellTrigger.Use && itemSpell.Spell != null).FirstOrDefault(); if (UseSpell != null) { UseSpell.Spell.RequiredTargetType = RequiredTargetType; UseSpell.Spell.RequiredTargetId = RequiredTargetId; } EquipSpells = Spells.Where(spell => spell.Trigger == ItemSpellTrigger.Equip && spell.Spell != null).Select(itemSpell => itemSpell.Spell).ToArray(); SoulstoneSpell = Spells.Where(spell => spell.Trigger == ItemSpellTrigger.Soulstone && spell.Spell != null).Select(itemSpell => itemSpell.Spell).FirstOrDefault(); HitSpells = Spells.Where(spell => spell.Trigger == ItemSpellTrigger.ChanceOnHit && spell.Spell != null).Select(itemSpell => itemSpell.Spell).ToArray(); if (UseSpell != null && (UseSpell.Id == SpellId.Learning || UseSpell.Id == SpellId.Learning_2)) { // Teaching TeachSpell = Spells.Where(spell => spell.Trigger == ItemSpellTrigger.Consume).FirstOrDefault(); } ConsumesAmount = (Class == ItemClass.Consumable || Spells.Contains(spell => spell.Trigger == ItemSpellTrigger.Consume)) && (UseSpell == null || !UseSpell.HasCharges); IsHearthStone = UseSpell != null && UseSpell.Spell.IsHearthStoneSpell; IsInventory = InventorySlotType != InventorySlotType.None && InventorySlotType != InventorySlotType.Bag && InventorySlotType != InventorySlotType.Quiver && InventorySlotType != InventorySlotType.Relic; // find set if (SetId != 0) { var set = ItemMgr.Sets.Get((uint)SetId); if (set != null) { ArrayUtil.Add(ref set.Templates, this); } } // truncate arrays if (Mods != null) { ArrayUtil.TruncVals(ref Mods); } else { Mods = StatModifier.EmptyArray; } IsCharter = Flags.HasFlag(ItemFlags.Charter); RandomSuffixFactor = EnchantMgr.GetRandomSuffixFactor(this); if (IsCharter) { Creator = () => new PetitionCharter(); } else if (IsContainer) { Creator = () => new Container(); } else { Creator = () => new Item(); } }
internal void InitializeTemplate() { if (Names == null) { Names = new string[8]; } if (Descriptions == null) { Descriptions = new string[8]; } if (DefaultDescription == null) { DefaultDescription = ""; } if (string.IsNullOrEmpty(DefaultName) || Id == 0U) { return; } ItemId = (Asda2ItemId)Id; RequiredSkill = SkillHandler.Get(RequiredSkillId); Set = ItemMgr.GetSet(SetId); Lock = LockEntry.Entries.Get(LockId); RequiredFaction = FactionMgr.Get(RequiredFactionId); RequiredProfession = SpellHandler.Get(RequiredProfessionId); SubClassMask = (ItemSubClassMask)(1 << (int)(SubClass & (ItemSubClass.WeaponDagger | ItemSubClass.WeaponThrown)) ); EquipmentSlots = ItemMgr.EquipmentSlotsByInvSlot.Get((uint)InventorySlotType); InventorySlotMask = (InventorySlotTypeMask)(1 << (int)(InventorySlotType & (InventorySlotType.WeaponRanged | InventorySlotType.Cloak))); IsAmmo = InventorySlotType == InventorySlotType.Ammo; IsKey = Class == ItemClass.Key; IsBag = InventorySlotType == InventorySlotType.Bag; IsContainer = Class == ItemClass.Container || Class == ItemClass.Quiver; IsStackable = MaxAmount > 1 && RandomSuffixId == 0U && RandomPropertiesId == 0U; IsTwoHandWeapon = InventorySlotType == InventorySlotType.TwoHandWeapon; SetIsWeapon(); if (ToolCategory != ToolCategory.None) { ItemMgr.FirstTotemsPerCat[(uint)ToolCategory] = this; } if (GemPropertiesId != 0U) { GemProperties = EnchantMgr.GetGemproperties(GemPropertiesId); if (GemProperties != null) { GemProperties.Enchantment.GemTemplate = this; } } if (Sockets == null) { Sockets = new SocketInfo[3]; } else if (Sockets.Contains( sock => sock.Color != SocketColor.None)) { HasSockets = true; } if (Damages == null) { Damages = DamageInfo.EmptyArray; } if (Resistances == null) { Resistances = new int[7]; } if (SocketBonusEnchantId != 0U) { SocketBonusEnchant = EnchantMgr.GetEnchantmentEntry(SocketBonusEnchantId); } switch (Class) { case ItemClass.Weapon: ItemProfession = ItemProfessions.WeaponSubClassProfessions.Get((uint)SubClass); break; case ItemClass.Armor: ItemProfession = ItemProfessions.ArmorSubClassProfessions.Get((uint)SubClass); break; } int sheathType = (int)SheathType; if (Spells != null) { ArrayUtil.Prune(ref Spells); for (int index = 0; index < 5; ++index) { Spells[index].Index = (uint)index; Spells[index].FinalizeAfterLoad(); } } else { Spells = ItemSpell.EmptyArray; } UseSpell = Spells.Where( itemSpell => { if (itemSpell.Trigger == ItemSpellTrigger.Use) { return(itemSpell.Spell != null); } return(false); }).FirstOrDefault(); if (UseSpell != null) { UseSpell.Spell.RequiredTargetType = RequiredTargetType; UseSpell.Spell.RequiredTargetId = RequiredTargetId; } EquipSpells = Spells.Where(spell => { if (spell.Trigger == ItemSpellTrigger.Equip) { return(spell.Spell != null); } return(false); }).Select(itemSpell => itemSpell.Spell).ToArray(); SoulstoneSpell = Spells.Where( spell => { if (spell.Trigger == ItemSpellTrigger.Soulstone) { return(spell.Spell != null); } return(false); }).Select(itemSpell => itemSpell.Spell) .FirstOrDefault(); HitSpells = Spells.Where(spell => { if (spell.Trigger == ItemSpellTrigger.ChanceOnHit) { return(spell.Spell != null); } return(false); }).Select(itemSpell => itemSpell.Spell).ToArray(); ConsumesAmount = (Class == ItemClass.Consumable || Spells.Contains( spell => spell.Trigger == ItemSpellTrigger.Consume)) && (UseSpell == null || !UseSpell.HasCharges); IsHearthStone = UseSpell != null && UseSpell.Spell.IsHearthStoneSpell; IsInventory = InventorySlotType != InventorySlotType.None && InventorySlotType != InventorySlotType.Bag && InventorySlotType != InventorySlotType.Quiver && InventorySlotType != InventorySlotType.Relic; if (SetId != ItemSetId.None) { ItemSet itemSet = ItemMgr.Sets.Get((uint)SetId); if (itemSet != null) { int num = (int)ArrayUtil.Add(ref itemSet.Templates, this); } } if (Mods != null) { ArrayUtil.TruncVals(ref Mods); } else { Mods = StatModifier.EmptyArray; } IsCharter = Flags.HasFlag(ItemFlags.Charter); RandomSuffixFactor = EnchantMgr.GetRandomSuffixFactor(this); if (IsCharter) { Creator = () => (Item) new PetitionCharter(); } else if (IsContainer) { Creator = () => (Item) new Container(); } else { Creator = () => new Item(); } }