public override ItemRandomSuffixEntry ConvertTo(byte[] rawData, ref int id) { var suffix = new ItemRandomSuffixEntry(); var maxCount = 5u; int currentIndex = 0; suffix.Id = id = GetInt32(rawData, currentIndex++); //0 currentIndex += 18; suffix.Enchants = new ItemEnchantmentEntry[maxCount]; suffix.Values = new int[maxCount]; for (var i = 0; i < maxCount; i++) { var enchantId = GetUInt32(rawData, currentIndex); if (enchantId != 0) { var enchant = EnchantMgr.GetEnchantmentEntry(enchantId); if (enchant != null) { suffix.Enchants[i] = enchant; suffix.Values[i] = GetInt32(rawData, (int)(currentIndex + maxCount)); } } currentIndex++; } ArrayUtil.Trunc(ref suffix.Enchants); ArrayUtil.TruncVals(ref suffix.Values); return(suffix); }
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 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 ItemEnchantmentEntry GetEnchant(EnchantSlot slot) { if (EnchantIds != null) { return(EnchantMgr.GetEnchantmentEntry((uint)EnchantIds[(int)slot])); } return(null); }
public void ApplyEnchant(int enchantEntryId, EnchantSlot enchantSlot, int duration, int charges, bool applyBoni) { if (enchantEntryId != 0) { var enchant = EnchantMgr.GetEnchantmentEntry((uint)enchantEntryId); if (enchant != null) { ApplyEnchant(enchant, enchantSlot, duration, charges, applyBoni); } } }
public override GemProperties ConvertTo(byte[] rawData, ref int id) { GemProperties gemProperties = new GemProperties(); gemProperties.Id = (uint)(id = GetInt32(rawData, 0)); uint uint32 = GetUInt32(rawData, 1); gemProperties.Enchantment = EnchantMgr.GetEnchantmentEntry(uint32); gemProperties.Color = (SocketColor)GetUInt32(rawData, 4); return(gemProperties); }
public override GemProperties ConvertTo(byte[] rawData, ref int id) { var props = new GemProperties(); props.Id = (uint)(id = GetInt32(rawData, 0)); var enchantmentId = GetUInt32(rawData, 1); props.Enchantment = EnchantMgr.GetEnchantmentEntry(enchantmentId); props.Color = (SocketColor)GetUInt32(rawData, 4); return(props); }
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); }
public override void Process(CmdTrigger <RealmServerCmdArgs> trigger) { var mod = trigger.Text.NextModifiers(); if (mod == "l") { var text = trigger.Text.Remainder.Trim(); var enchants = EnchantMgr.EnchantmentEntryReader.Entries.Values.Where( enchant => enchant.Description.IndexOf(text, StringComparison.InvariantCultureIgnoreCase) > -1); trigger.Reply("{0} Enchantments found", enchants.Count()); var i = 0; foreach (var enchant in enchants) { i++; trigger.Reply("{2}. {0} - {1})", enchant.Id, enchant.Description, i); } } else { var slot = trigger.Text.NextEnum(InventorySlot.Invalid); if (slot == InventorySlot.Invalid) { trigger.Reply("Invalid slot."); } else { var item = ((Character)trigger.Args.Target).Inventory[slot]; if (item == null) { trigger.Reply("There is no Item in slot " + slot); } else { var id = trigger.Text.NextUInt(); var enchantSlot = trigger.Text.NextEnum(EnchantSlot.Permanent); var enchant = EnchantMgr.GetEnchantmentEntry(id); if (enchant == null) { trigger.Reply("Invalid EnchantId: " + id); } else { item.ApplyEnchant(enchant, enchantSlot, 0, 0, true); } } } } }
private void SetEnchantUnequipped(ItemEnchantment enchant) { if (enchant.Slot == EnchantSlot.Permanent) { Owner.SetUInt16Low((PlayerFields)(284 + Slot * 2), 0); } else if (enchant.Slot == EnchantSlot.Temporary) { Owner.SetUInt16High((PlayerFields)(284 + Slot * 2), 0); } for (int index = 0; index < enchant.Entry.Effects.Length; ++index) { EnchantMgr.RemoveEffect(this, enchant.Entry.Effects[index]); } }
/// <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); } } }
public override ItemRandomPropertyEntry ConvertTo(byte[] rawData, ref int id) { int num4; ItemRandomPropertyEntry entry = new ItemRandomPropertyEntry(); int num = 0; id = num4 = DBCRecordConverter.GetInt32(rawData, num++); entry.Id = (uint)num4; num++; for (int i = 0; i < entry.Enchants.Length; i++) { uint num3 = DBCRecordConverter.GetUInt32(rawData, num++); entry.Enchants[i] = EnchantMgr.GetEnchantmentEntry(num3); } return(entry); }
public override ItemRandomPropertyEntry ConvertTo(byte[] rawData, ref int id) { var entry = new ItemRandomPropertyEntry(); int currentIndex = 0; entry.Id = (uint)(id = GetInt32(rawData, currentIndex++)); currentIndex++; // skip the name for (int i = 0; i < entry.Enchants.Length; i++) { var enchantId = GetUInt32(rawData, currentIndex++); entry.Enchants[i] = EnchantMgr.GetEnchantmentEntry(enchantId); } return(entry); }
void SetEnchantUnequipped(ItemEnchantment enchant) { if (enchant.Slot == EnchantSlot.Permanent) { Owner.SetUInt16Low( PlayerFields.VISIBLE_ITEM_1_ENCHANTMENT + (Slot * ItemConstants.PlayerFieldVisibleItemSize), 0); } else if (enchant.Slot == EnchantSlot.Temporary) { Owner.SetUInt16High( PlayerFields.VISIBLE_ITEM_1_ENCHANTMENT + (Slot * ItemConstants.PlayerFieldVisibleItemSize), 0); } for (var i = 0; i < enchant.Entry.Effects.Length; i++) { EnchantMgr.RemoveEffect(this, enchant.Entry.Effects[i]); } }
/// <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) { var slot = from; if (m_enchantments != null) { while (m_enchantments[(int)slot] != null && m_enchantments.Length > (int)++slot) { } if (slot > to) { // no more free slots return(false); } } var applied = false; foreach (var entry in entries) { if (Utility.Random(0, 100f) < entry.ChancePercent) { var enchant = EnchantMgr.GetEnchantmentEntry(entry.EnchantId); if (enchant != null) { ApplyEnchant(enchant, slot, 0, 0, true); applied = true; // ReSharper disable PossibleNullReferenceException while (m_enchantments[(int)slot] != null && ++slot <= to) { } // ReSharper restore PossibleNullReferenceException if (slot > to) { // no more free slots return(true); } } } } return(applied); }
/// <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); }
public override ItemEnchantmentEntry ConvertTo(byte[] rawData, ref int id) { var enchant = new ItemEnchantmentEntry(); enchant.Id = (uint)(id = GetInt32(rawData, 0)); enchant.Charges = GetUInt32(rawData, 1); enchant.Description = GetString(rawData, 14); enchant.Effects = new ItemEnchantmentEffect[3]; for (var i = 0; i < 3; i++) { var type = (ItemEnchantmentType)GetUInt32(rawData, 2 + i); if (type != ItemEnchantmentType.None) { var effect = new ItemEnchantmentEffect(); enchant.Effects[i] = effect; effect.Type = type; effect.MinAmount = GetInt32(rawData, 5 + i); effect.MaxAmount = GetInt32(rawData, 8 + i); effect.Misc = GetUInt32(rawData, 11 + i); } } ArrayUtil.Prune(ref enchant.Effects); var currentIndex = 31; enchant.Visual = GetUInt32(rawData, currentIndex++); enchant.Flags = GetUInt32(rawData, currentIndex++); enchant.SourceItemId = GetUInt32(rawData, currentIndex++); var conditionId = GetUInt32(rawData, currentIndex++); if (conditionId > 0) { enchant.Condition = EnchantMgr.GetEnchantmentCondition(conditionId); } enchant.RequiredSkillId = (SkillId)GetUInt32(rawData, currentIndex++); enchant.RequiredSkillAmount = GetInt32(rawData, currentIndex); return(enchant); }
public void RemoveEnchant(ItemEnchantment enchant) { m_enchantments[(int)enchant.Slot] = null; m_record.SetEnchant(enchant.Slot, 0, 0); var owner = OwningCharacter; if (owner != null) { EnchantMgr.RemoveEnchantFromItem(this, enchant); if (IsEquipped) { SetEnchantUnequipped(enchant); } if (enchant.Entry.GemTemplate != null) { owner.Inventory.ModUniqueCount(enchant.Entry.GemTemplate, -1); } } }
private static void LoadDBCs() { RandomPropPointReader = new MappedDBCReader <ItemLevelInfo, ItemRandPropPointConverter>( RealmServerConfiguration.GetDBCFile(WCellConstants.DBC_RANDPROPPOINTS)); EnchantMgr.Init(); RandomPropertiesReader = new MappedDBCReader <ItemRandomPropertyEntry, ItemRandomPropertiesConverter>(RealmServerConfiguration.GetDBCFile( WCellConstants.DBC_ITEMRANDOMPROPERTIES)); RandomSuffixReader = new MappedDBCReader <ItemRandomSuffixEntry, ItemRandomSuffixConverter>(RealmServerConfiguration.GetDBCFile( WCellConstants.DBC_ITEMRANDOMSUFFIX)); ScalingStatDistributionReader = new MappedDBCReader <ScalingStatDistributionEntry, ScalingStatDistributionConverter>(RealmServerConfiguration.GetDBCFile( WCellConstants.DBC_SCALINGSTATDISTRIBUTION)); ScalingStatValuesReader = new MappedDBCReader <ScalingStatValues, ScalingStatValuesConverter>(RealmServerConfiguration.GetDBCFile( WCellConstants.DBC_SCALINGSTATVALUES)); }
/// <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); }
/// <summary> /// Sends a list of mail messages to the client. /// </summary> public static void SendMailList(IPacketReceiver client, IList <MailMessage> messages) { using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_MAIL_LIST_RESULT, 128 * messages.Count)) { const int enchantCount = (int)EnchantSlot.Prismatic + 1; packet.Write(messages.Count); var count = Math.Min(messages.Count, 0xFF); packet.Write((byte)count); for (var m = 0; m < count; m++) { var letter = messages[m]; // Skip deleted mails if (letter.IsDeleted) { continue; } var sizePos = packet.Position; packet.Position = sizePos + 2; // size of message packet.Write((uint)letter.Guid); packet.Write((byte)letter.MessageType); switch (letter.MessageType) { case MailType.Normal: packet.Write(letter.SenderEntityId); break; case MailType.Creature: packet.Write(letter.SenderEntityId.Low); break; case MailType.GameObject: packet.Write(letter.SenderEntityId.Low); break; case MailType.Auction: packet.Write(letter.SenderEntityId.Low); break; case MailType.Item: packet.WriteUInt(0); // ? 3.2.2 // What should go here? break; default: break; } packet.Write(letter.CashOnDelivery); //packet.Write(letter.TextId); packet.Write(0u); packet.Write((uint)letter.MessageStationary); packet.Write(letter.IncludedMoney); var flags = letter.ReadTime != null ? MailListFlags.Read : MailListFlags.NotRead; switch (letter.MessageType) { case MailType.Normal: flags |= MailListFlags.Delete; if (letter.IncludedItemCount > 0) { flags |= MailListFlags.Return; } break; case MailType.Auction: flags |= MailListFlags.Auction; break; } packet.Write((uint)flags); packet.Write((float)((letter.ExpireTime - DateTime.Now).TotalMilliseconds / (24 * 60 * 60 * 1000))); packet.Write(0u); packet.Write(letter.Subject); packet.Write(letter.Body); if (letter.IncludedItemCount == 0) { // No items packet.Write((byte)0); } else { // There are items to display var items = letter.IncludedItems; packet.Write((byte)items.Count); byte i = 0; foreach (var record in items) { packet.Write(i++); if (record != null) { packet.Write(record.EntityLowId); packet.Write(record.EntryId); if (record.EnchantIds != null) { for (var j = 0; j < enchantCount; ++j) { var enchantId = record.EnchantIds[j]; if (enchantId != 0) { var enchant = EnchantMgr.GetEnchantmentEntry((uint)enchantId); if (enchant != null) { packet.Write(0); // charges if (j == (int)EnchantSlot.Temporary) { packet.Write(record.EnchantTempTime); } else { packet.Write(0); } packet.Write(enchantId); continue; } } packet.Write(0); packet.Write(0); packet.Write(0); } } else { for (var j = 0; j < enchantCount; ++j) { packet.Write(0u); packet.Write(0); packet.Write(0u); } } packet.Write(record.RandomProperty); packet.Write(record.RandomSuffix); packet.Write(record.Amount); packet.Write((uint)record.Charges); packet.Write(record.Template.MaxDurability); packet.Write(record.Durability); packet.Write((byte)0); } else { packet.Write(0u); packet.Write(0u); for (byte j = 0; j < enchantCount; ++j) { packet.Write(0u); packet.Write(0u); packet.Write(0u); } packet.Write(0); packet.Write(0); packet.Write(0); packet.Write(0); packet.Write(0); packet.Write(0); packet.Write((byte)0); } } } var endPos = packet.Position; packet.Position = sizePos; packet.Write((ushort)(endPos - sizePos)); packet.Position = endPos; } client.Send(packet, addEnd: false); } }
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(); } }
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(); } }
/// <summary>Sends a list of mail messages to the client.</summary> public static void SendMailList(IPacketReceiver client, IList <MailMessage> messages) { using (RealmPacketOut packet = new RealmPacketOut((PacketId)RealmServerOpCode.SMSG_MAIL_LIST_RESULT, 128 * messages.Count)) { packet.Write(messages.Count); int num1 = Math.Min(messages.Count, (int)byte.MaxValue); packet.Write((byte)num1); for (int index1 = 0; index1 < num1; ++index1) { MailMessage message = messages[index1]; if (!message.IsDeleted) { long position1 = packet.Position; packet.Position = position1 + 2L; packet.Write((uint)message.Guid); packet.Write((byte)message.MessageType); switch (message.MessageType) { case MailType.Normal: packet.Write((ulong)message.SenderEntityId); break; case MailType.Auction: packet.Write(message.SenderEntityId.Low); break; case MailType.Creature: packet.Write(message.SenderEntityId.Low); break; case MailType.GameObject: packet.Write(message.SenderEntityId.Low); break; case MailType.Item: packet.WriteUInt(0); break; } packet.Write(message.CashOnDelivery); packet.Write(0U); packet.Write((uint)message.MessageStationary); packet.Write(message.IncludedMoney); MailListFlags mailListFlags = message.ReadTime.HasValue ? MailListFlags.Read : MailListFlags.NotRead; switch (message.MessageType) { case MailType.Normal: mailListFlags |= MailListFlags.Delete; if (message.IncludedItemCount > 0) { mailListFlags |= MailListFlags.Return; break; } break; case MailType.Auction: mailListFlags |= MailListFlags.Auction; break; } packet.Write((uint)mailListFlags); packet.Write((float)((message.ExpireTime - DateTime.Now).TotalMilliseconds / 86400000.0)); packet.Write(0U); packet.Write(message.Subject); packet.Write(message.Body); if (message.IncludedItemCount == 0) { packet.Write((byte)0); } else { ICollection <ItemRecord> includedItems = message.IncludedItems; packet.Write((byte)includedItems.Count); byte num2 = 0; foreach (ItemRecord itemRecord in (IEnumerable <ItemRecord>)includedItems) { packet.Write(num2++); if (itemRecord != null) { packet.Write(itemRecord.EntityLowId); packet.Write(itemRecord.EntryId); if (itemRecord.EnchantIds != null) { for (int index2 = 0; index2 < 7; ++index2) { int enchantId = itemRecord.EnchantIds[index2]; if (enchantId != 0 && EnchantMgr.GetEnchantmentEntry((uint)enchantId) != null) { packet.Write(0); if (index2 == 1) { packet.Write(itemRecord.EnchantTempTime); } else { packet.Write(0); } packet.Write(enchantId); } else { packet.Write(0); packet.Write(0); packet.Write(0); } } } else { for (int index2 = 0; index2 < 7; ++index2) { packet.Write(0U); packet.Write(0); packet.Write(0U); } } packet.Write(itemRecord.RandomProperty); packet.Write(itemRecord.RandomSuffix); packet.Write(itemRecord.Amount); packet.Write((uint)itemRecord.Charges); packet.Write(itemRecord.Template.MaxDurability); packet.Write(itemRecord.Durability); packet.Write((byte)0); } else { packet.Write(0U); packet.Write(0U); for (byte index2 = 0; index2 < (byte)7; ++index2) { packet.Write(0U); packet.Write(0U); packet.Write(0U); } packet.Write(0); packet.Write(0); packet.Write(0); packet.Write(0); packet.Write(0); packet.Write(0); packet.Write((byte)0); } } } long position2 = packet.Position; packet.Position = position1; packet.Write((ushort)(position2 - position1)); packet.Position = position2; } } client.Send(packet, false); } }
public ItemEnchantmentEntry GetEnchant(EnchantSlot slot) { if(EnchantIds != null) return EnchantMgr.GetEnchantmentEntry((uint) EnchantIds[(int) slot]); return null; }
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()); } }
public override ItemEnchantmentEntry ConvertTo(byte[] rawData, ref int id) { ItemEnchantmentEntry enchantmentEntry1 = new ItemEnchantmentEntry(); enchantmentEntry1.Id = (uint)(id = DBCRecordConverter.GetInt32(rawData, 0)); enchantmentEntry1.Charges = DBCRecordConverter.GetUInt32(rawData, 1); enchantmentEntry1.Description = this.GetString(rawData, 14); enchantmentEntry1.Effects = new ItemEnchantmentEffect[3]; for (int index = 0; index < 3; ++index) { ItemEnchantmentType uint32 = (ItemEnchantmentType)DBCRecordConverter.GetUInt32(rawData, 2 + index); if (uint32 != ItemEnchantmentType.None) { ItemEnchantmentEffect enchantmentEffect = new ItemEnchantmentEffect(); enchantmentEntry1.Effects[index] = enchantmentEffect; enchantmentEffect.Type = uint32; enchantmentEffect.MinAmount = DBCRecordConverter.GetInt32(rawData, 5 + index); enchantmentEffect.MaxAmount = DBCRecordConverter.GetInt32(rawData, 8 + index); enchantmentEffect.Misc = DBCRecordConverter.GetUInt32(rawData, 11 + index); } } ArrayUtil.Prune <ItemEnchantmentEffect>(ref enchantmentEntry1.Effects); int num1 = 31; ItemEnchantmentEntry enchantmentEntry2 = enchantmentEntry1; byte[] data1 = rawData; int field1 = num1; int num2 = field1 + 1; int uint32_1 = (int)DBCRecordConverter.GetUInt32(data1, field1); enchantmentEntry2.Visual = (uint)uint32_1; ItemEnchantmentEntry enchantmentEntry3 = enchantmentEntry1; byte[] data2 = rawData; int field2 = num2; int num3 = field2 + 1; int uint32_2 = (int)DBCRecordConverter.GetUInt32(data2, field2); enchantmentEntry3.Flags = (uint)uint32_2; ItemEnchantmentEntry enchantmentEntry4 = enchantmentEntry1; byte[] data3 = rawData; int field3 = num3; int num4 = field3 + 1; int uint32_3 = (int)DBCRecordConverter.GetUInt32(data3, field3); enchantmentEntry4.SourceItemId = (uint)uint32_3; byte[] data4 = rawData; int field4 = num4; int num5 = field4 + 1; uint uint32_4 = DBCRecordConverter.GetUInt32(data4, field4); if (uint32_4 > 0U) { enchantmentEntry1.Condition = EnchantMgr.GetEnchantmentCondition(uint32_4); } ItemEnchantmentEntry enchantmentEntry5 = enchantmentEntry1; byte[] data5 = rawData; int field5 = num5; int field6 = field5 + 1; int uint32_5 = (int)DBCRecordConverter.GetUInt32(data5, field5); enchantmentEntry5.RequiredSkillId = (SkillId)uint32_5; enchantmentEntry1.RequiredSkillAmount = DBCRecordConverter.GetInt32(rawData, field6); return(enchantmentEntry1); }