Example #1
0
        public void Add(bool isSendByMe, bool isReceivedByMe, ItemFlags itemFlags, params Part[] parts)
        {
            if (settings.NumberOfOnScreenLogLines.Value == 0)
            {
                return;
            }

            if (isSendByMe || isReceivedByMe)
            {
                if (isReceivedByMe && !settings.ShowReceivedItemsFromMe.Value)
                {
                    return;
                }
                if (isSendByMe && !settings.ShowSendItemsFromMe.Value)
                {
                    return;
                }

                pendingImportantLines.Enqueue(new Message(parts));
            }
            else
            {
                if (itemFlags.HasFlag(ItemFlags.Advancement) && !settings.ShowSendProgressionItems.Value)
                {
                    return;
                }
                if (itemFlags.HasFlag(ItemFlags.NeverExclude) && !settings.ShowSendImportantItems.Value)
                {
                    return;
                }
                if (itemFlags.HasFlag(ItemFlags.Trap) && !settings.ShowSendTrapItems.Value)
                {
                    return;
                }
                if (itemFlags == ItemFlags.None && !settings.ShowSendGenericItems.Value)
                {
                    return;
                }

                pendingLines.Enqueue(new Message(parts));
            }
        }
Example #2
0
        //-----------------------------------------------------------------------------
        // Virtual
        //-----------------------------------------------------------------------------

        public virtual bool IsUsable()
        {
            if (Player.IsInMinecart && !flags.HasFlag(ItemFlags.UsableInMinecart))
            {
                return(false);
            }
            if (Player.IsInAir && !flags.HasFlag(ItemFlags.UsableWhileJumping))
            {
                return(false);
            }
            if (Player.Physics.IsInHole && !flags.HasFlag(ItemFlags.UsableWhileInHole))
            {
                return(false);
            }
            if (((Player.CurrentState is PlayerHoldSwordState) ||
                 (Player.CurrentState is PlayerSwingState) ||
                 (Player.CurrentState is PlayerSpinSwordState)) &&
                flags.HasFlag(ItemFlags.UsableWithSword))
            {
                return(true);
            }
            return(Player.CurrentState is PlayerNormalState);
        }
Example #3
0
        public IEnumerable <ItemInfo> GetAllItemInfo()
        {
            FileLoader loader = new FileLoader();

            loader.OpenFile(fileName);
            Node node = loader.GetRootNode();

            PropertyReader props;

            if (loader.GetProps(node, out props))
            {
                // 4 byte flags
                // attributes
                // 0x01 = version data
                uint flags = props.ReadUInt32();
                byte attr  = props.ReadByte();
                if (attr == 0x01)
                {
                    ushort datalen = props.ReadUInt16();
                    if (datalen != 140)
                    {
                        yield return(null);

                        yield break;
                    }
                    uint majorVersion = props.ReadUInt32();
                    uint minorVersion = props.ReadUInt32();
                    uint buildNumber  = props.ReadUInt32();
                }
            }

            node = node.Child;

            while (node != null)
            {
                if (!loader.GetProps(node, out props))
                {
                    yield return(null);

                    yield break;
                }

                ItemInfo info = new ItemInfo();

                info.Group = (ItemGroup)node.Type;

                ItemFlags flags = (ItemFlags)props.ReadUInt32();
                info.IsBlocking           = flags.HasFlag(ItemFlags.BlocksSolid);
                info.IsProjectileBlocking = flags.HasFlag(ItemFlags.BlocksProjectile);
                info.IsPathBlocking       = flags.HasFlag(ItemFlags.BlocksPathFinding);
                info.HasHeight            = flags.HasFlag(ItemFlags.HasHeight);
                info.IsUseable            = flags.HasFlag(ItemFlags.Useable);
                info.IsPickupable         = flags.HasFlag(ItemFlags.Pickupable);
                info.IsMoveable           = flags.HasFlag(ItemFlags.Moveable);
                info.IsStackable          = flags.HasFlag(ItemFlags.Stackable);
                info.IsAlwaysOnTop        = flags.HasFlag(ItemFlags.AlwaysOnTop);
                info.IsVertical           = flags.HasFlag(ItemFlags.Vertical);
                info.IsHorizontal         = flags.HasFlag(ItemFlags.Horizontal);
                info.IsHangable           = flags.HasFlag(ItemFlags.Hangable);
                info.IsDistanceReadable   = flags.HasFlag(ItemFlags.AllowDistanceRead);
                info.IsRotatable          = flags.HasFlag(ItemFlags.Rotatable);
                info.IsReadable           = flags.HasFlag(ItemFlags.Readable);
                info.HasClientCharges     = flags.HasFlag(ItemFlags.ClientCharges);
                info.CanLookThrough       = flags.HasFlag(ItemFlags.LookThrough);

                // process flags

                byte   attr;
                ushort datalen;
                while (props.PeekChar() != -1)
                {
                    attr    = props.ReadByte();
                    datalen = props.ReadUInt16();
                    switch ((ItemAttribute)attr)
                    {
                    case ItemAttribute.ServerId:
                        info.Id = props.ReadUInt16();
                        break;

                    case ItemAttribute.ClientId:
                        info.SpriteId = props.ReadUInt16();
                        break;

                    case ItemAttribute.TopOrder:
                        info.TopOrder = props.ReadByte();
                        break;

                    default:
                        props.ReadBytes(datalen);
                        break;
                    }
                }
                yield return(info);

                node = node.Next;
            }
        }
Example #4
0
        private static bool LoadFromOtb()
        {
            FileLoader fileLoader = new FileLoader();

            if (!fileLoader.OpenFile("Data/Items/items.otb", "OTBI"))
            {
                Logger.LogOperationFailed("OTB file could not be loaded!");
                return(false);
            }

            byte       type;
            NodeStruct node = fileLoader.GetChildNode(null, out type);

            MemoryStream props;

            if (fileLoader.GetProps(node, out props))
            {
                //4 byte flags
                //attributes
                //0x01 = version data
                props.ReadUInt32();
                props.ReadByte();
                byte attr = (byte)props.ReadByte();

                if (attr == 0x01)//ROOT_ATTR_VERSION
                {
                    ushort datalen = props.ReadUInt16();

                    if (datalen != 140) // 3 integers + 128 bytes
                    {
                        Logger.LogOperationFailed("OTB file is in invalid format!");
                        return(false);
                    }

                    DwMajorVersion = props.ReadUInt32();
                    DwMinorVersion = props.ReadUInt32();
                    DwBuildNumber  = props.ReadUInt32();
                }
            }

            if (DwMajorVersion == 0xFFFFFFFF)
            {
                Logger.Log(LogLevels.Warning, "items.otb using generic client version!");
            }
            else if (DwMajorVersion != 3)
            {
                Logger.LogOperationFailed("Old version detected, a newer version of items.otb is required.");
                return(false);
            }
            else if (DwMinorVersion < (uint)OtbClientVersion.V1076)
            {
                Logger.LogOperationFailed("A newer version of items.otb is required.");
                return(false);
            }

            node = fileLoader.GetChildNode(node, out type);
            while (node != null)
            {
                if (!fileLoader.GetProps(node, out props))
                {
                    Logger.LogOperationFailed("OTB file is in invalid format!");
                    return(false);
                }

                ItemFlags flags = (ItemFlags)props.ReadUInt32();

                ushort serverId         = 0;
                ushort clientId         = 0;
                ushort speed            = 0;
                ushort wareId           = 0;
                byte   lightLevel       = 0;
                byte   lightColor       = 0;
                byte   alwaysOnTopOrder = 0;

                int attrib;
                while ((attrib = props.ReadByte()) != -1)
                {
                    ushort datalen = props.ReadUInt16();

                    switch ((ItemAttributes)attrib)
                    {
                    case ItemAttributes.ServerId:
                        serverId = props.ReadUInt16();

                        if (serverId > 30000 && serverId < 30100)
                        {
                            serverId -= 30000;
                        }
                        break;

                    case ItemAttributes.ClientId:
                        clientId = props.ReadUInt16();
                        break;

                    case ItemAttributes.Speed:
                        speed = props.ReadUInt16();
                        break;

                    case ItemAttributes.Light2:
                        lightLevel = (byte)props.ReadUInt16();
                        lightColor = (byte)props.ReadUInt16();
                        break;

                    case ItemAttributes.TopOrder:
                        alwaysOnTopOrder = (byte)props.ReadByte();
                        break;

                    case ItemAttributes.WareId:
                        wareId = props.ReadUInt16();
                        break;

                    default:
                        props.ReadBytes(datalen);
                        break;
                    }
                }

                if (!ReverseItemDict.ContainsKey(clientId))
                {
                    ReverseItemDict[clientId] = serverId;
                }

                if (!Templates.ContainsKey(serverId))
                {
                    Templates[serverId] = new ItemTemplate();
                }

                ItemTemplate item = Templates[serverId];

                item.DoesBlockSolid       = flags.HasFlag(ItemFlags.BlocksSolid);
                item.DoesBlockProjectile  = flags.HasFlag(ItemFlags.BlocksProjectile);
                item.DoesBlockPathFinding = flags.HasFlag(ItemFlags.BlocksPathFinding);
                item.HasHeight            = flags.HasFlag(ItemFlags.HasHeight);
                item.IsUseable            = flags.HasFlag(ItemFlags.Useable);
                item.IsPickupable         = flags.HasFlag(ItemFlags.Pickupable);
                item.IsMoveable           = flags.HasFlag(ItemFlags.Moveable);
                item.IsStackable          = flags.HasFlag(ItemFlags.Stackable);
                item.IsAlwaysOnTop        = flags.HasFlag(ItemFlags.AlwaysOnTop);
                item.IsVertical           = flags.HasFlag(ItemFlags.Vertical);
                item.IsHorizontal         = flags.HasFlag(ItemFlags.Horizontal);
                item.IsHangable           = flags.HasFlag(ItemFlags.Hangable);
                item.AllowDistanceRead    = flags.HasFlag(ItemFlags.AllowDistanceRead);
                item.IsRotatable          = flags.HasFlag(ItemFlags.Rotatable);
                item.CanReadText          = flags.HasFlag(ItemFlags.Readable);
                item.CanLookThrough       = flags.HasFlag(ItemFlags.LookThrough);
                item.IsAnimation          = flags.HasFlag(ItemFlags.Animation);
                // item.WalkStack = flags.HasFlag(ItemFlags.FullTile);
                item.ForceUse = flags.HasFlag(ItemFlags.ForceUse);


                item.Group = (ItemGroups)type;
                switch ((ItemGroups)type)
                {
                case ItemGroups.Container:
                    item.Type = ItemTypes.Container;
                    break;

                case ItemGroups.Door:
                    item.Type = ItemTypes.Door;
                    break;

                case ItemGroups.MagicField:
                    item.Type = ItemTypes.MagicField;
                    break;

                case ItemGroups.Teleport:
                    item.Type = ItemTypes.Teleport;
                    break;
                }

                item.Id               = serverId;
                item.ClientId         = clientId;
                item.Speed            = speed;
                item.LightLevel       = lightLevel;
                item.LightColor       = lightColor;
                item.WareId           = wareId;
                item.AlwaysOnTopOrder = alwaysOnTopOrder;

                node = fileLoader.GetNextNode(node, out type);
            }

            fileLoader.Close();
            return(true);
        }
Example #5
0
        /// <summary>
        ///     Loads the specified file name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>The collection of items.</returns>
        /// <exception cref="FileFormatException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        private IEnumerable <IItem> Load(string fileName)
        {
            OpenFile(fileName);

            // File version
            Reader.ReadUInt32();

            // Initialize
            InitializeRoot();

            //if (!ParseNode(Root))
            //    throw new FileFormatException("Could not parse root node.");
            // TODO: This should probably throw an exception if the return is 'false'(?)
            ParseNode(Root);

            Node node = GetRootNode();

            if (!ReadProperty(node, out ItemStreamReader itemStreamReader))
            {
                throw new FileFormatException("Could not parse root node properties.");
            }

            // First byte of OTB is 0
            // TODO: Use propertyReader.Skip(byte.size); - byte.size is unknown
            itemStreamReader.ReadByte();

            // Flags (4 bytes) unused
            itemStreamReader.ReadUInt32();

            RootAttribute rootAttribute = (RootAttribute)itemStreamReader.ReadByte();

            if (rootAttribute != RootAttribute.Version)
            {
                throw new FileFormatException("Could not find item version.");
            }

            ItemsMetadata metadata = itemStreamReader.ReadMetadata();

            if (metadata == null)
            {
                throw new FileFormatException("Could not read OTBI metadata.");
            }

            Node childNode = node.Child;

            while (childNode != null)
            {
                if (!ReadProperty(childNode, out ItemStreamReader propertyReader))
                {
                    throw new FileFormatException("Could not parse waypoint properties.");
                }

                IItem item = new Item();
                item.GroupType = (ItemGroupType)childNode.Type;

                ItemFlags itemFlags = (ItemFlags)propertyReader.ReadUInt32();

                if (itemFlags.HasFlag(ItemFlags.Stackable))
                {
                    item.Features.Add(new StackableFeature(100));
                }

                if (itemFlags.HasFlag(ItemFlags.Pickupable))
                {
                    item.Features.Add(new PickupableFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.SolidBlock))
                {
                    item.Features.Add(new SolidBlockFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.ProjectileBlocker))
                {
                    item.Features.Add(new ProjectileBlockerFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.PathBlocker))
                {
                    item.Features.Add(new PathBlockerFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.HasHeight))
                {
                    item.Features.Add(new HeightFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.Useable))
                {
                    item.Features.Add(new UseableFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.Moveable))
                {
                    item.Features.Add(new MoveableFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.AlwaysOnTop))
                {
                    item.Features.Add(new AlwaysOnTopFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.Vertical))
                {
                    item.Features.Add(new VerticalFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.Horizontal))
                {
                    item.Features.Add(new HorizontalFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.Hangable))
                {
                    item.Features.Add(new HangableFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.DistanceReadable))
                {
                    item.Features.Add(new DistanceReadableFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.Rotatable))
                {
                    item.Features.Add(new RotatableFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.Readable))
                {
                    item.Features.Add(new ReadableFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.LookThrough))
                {
                    item.Features.Add(new LookThroughFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.Animation))
                {
                    item.Features.Add(new AnimationFeature());
                }

                if (itemFlags.HasFlag(ItemFlags.ForceUse))
                {
                    item.Features.Add(new ForceUseFeature());
                }

                while (propertyReader.PeekChar() != -1)
                {
                    ItemAttribute attribute  = (ItemAttribute)propertyReader.ReadByte();
                    ushort        dataLength = propertyReader.ReadUInt16();
                    switch (attribute)
                    {
                    case ItemAttribute.Id:
                        ushort serverId = propertyReader.ReadUInt16();
                        if (serverId > 30000 && serverId < 30100)
                        {
                            serverId -= 30000;
                        }
                        item.Id = serverId;
                        break;

                    case ItemAttribute.SpriteId:
                        item.SpriteId = propertyReader.ReadUInt16();
                        break;

                    case ItemAttribute.Speed:
                        item.Speed = propertyReader.ReadUInt16();
                        break;

                    case ItemAttribute.TopOrder:
                        // TODO: item.TileStackOrder = propertyReader.ReadTileStackOrder();
                        propertyReader.Skip(dataLength);
                        //propertyReader.ReadByte();
                        break;

                    case ItemAttribute.WareId:
                        // TODO: This should probably use a service to have a reference (e.g: item.WriteOnceItem [IItem])
                        item.WriteOnceItemId = propertyReader.ReadUInt16();
                        break;

                    case ItemAttribute.Name:
                        // TODO: item.Name = propertyReader.ReadString();
                        propertyReader.Skip(dataLength);
                        //propertyReader.ReadString();
                        break;

                    case ItemAttribute.SpriteHash:
                        // TODO: item.SpriteHash = propertyReader.ReadBytes(datalen);
                        propertyReader.Skip(dataLength);
                        //propertyReader.ReadBytes(dataLength);
                        break;

                    case ItemAttribute.Light2:
                        // TODO: item.LightLevel = propertyReader.ReadUInt16();
                        // TODO: item.LightColor = propertyReader.ReadUInt16();
                        propertyReader.Skip(dataLength);
                        //propertyReader.ReadUInt16();
                        //propertyReader.ReadUInt16();
                        break;

                    case ItemAttribute.MinimapColor:
                        // TODO: item.MinimapColor = propertyReader.ReadUInt16();
                        propertyReader.Skip(dataLength);
                        //propertyReader.ReadUInt16();
                        break;

                    case ItemAttribute.Unknown1:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown2:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown3:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown4:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown5:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown6:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown7:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown8:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown9:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown10:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown11:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown12:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown13:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown14:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown15:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown16:
                        throw new NotImplementedException();

                    case ItemAttribute.Description:
                        throw new NotImplementedException();

                    case ItemAttribute.Slot:
                        throw new NotImplementedException();

                    case ItemAttribute.MaxItems:
                        throw new NotImplementedException();

                    case ItemAttribute.Weight:
                        throw new NotImplementedException();

                    case ItemAttribute.Weapon:
                        throw new NotImplementedException();

                    case ItemAttribute.Ammo:
                        throw new NotImplementedException();

                    case ItemAttribute.Armor:
                        throw new NotImplementedException();

                    case ItemAttribute.Magiclevel:
                        throw new NotImplementedException();

                    case ItemAttribute.MagicFieldType:
                        throw new NotImplementedException();

                    case ItemAttribute.Writeable:
                        throw new NotImplementedException();

                    case ItemAttribute.Rotateable:
                        throw new NotImplementedException();

                    case ItemAttribute.Decay:
                        throw new NotImplementedException();

                    case ItemAttribute.Unknown17:
                        propertyReader.Skip(dataLength);
                        break;

                    case ItemAttribute.Unknown18:
                        propertyReader.Skip(dataLength);
                        break;

                    case ItemAttribute.Light:
                        throw new NotImplementedException();

                    case ItemAttribute.Decay2:
                        throw new NotImplementedException();

                    case ItemAttribute.Weapon2:
                        throw new NotImplementedException();

                    case ItemAttribute.Ammo2:
                        throw new NotImplementedException();

                    case ItemAttribute.Armor2:
                        throw new NotImplementedException();

                    case ItemAttribute.Writeable2:
                        throw new NotImplementedException();

                    case ItemAttribute.Writeable3:
                        throw new NotImplementedException();

                    default:
                        // TODO: Review whether this is necessary propertyReader.Skip(dataLength);
                        throw new ArgumentOutOfRangeException(nameof(attribute), attribute, "OTBI attribute is not supported.");
                    }
                }

                yield return(item);

                childNode = childNode.Next;
            }
        }
Example #6
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();
            }
        }
Example #7
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();
            }
        }