Exemple #1
0
        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();
            }
        }
Exemple #2
0
        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());
            }
        }
Exemple #3
0
        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();
            }
        }