示例#1
0
        /// <summary>
        /// Creates an ItemBase that sets <see cref="ItemClass"/> and <see cref="Tags"/> on
        /// a best effort basis. They might not be set correctly.
        /// <para/>
        /// Only <see cref="Name"/>, <see cref="ItemClass"/> and <see cref="Tags"/> may be called on
        /// ItemBases created via this constructor. It is not meant to produce bases that can exist independent
        /// of the <see cref="Item"/> they are created for.
        /// </summary>
        /// <param name="itemImageService"></param>
        /// <param name="itemSlot">The slot the parent <see cref="Item"/> is slotted into.
        /// <see cref="ItemSlot.Unequipable"/> if is not equipped.</param>
        /// <param name="typeLine">The TypeLine property of the parent <see cref="Item"/>.</param>
        /// <param name="frameType">The frame type of the item.</param>
        public ItemBase(ItemImageService itemImageService, ItemSlot itemSlot, string typeLine, FrameType frameType)
        {
            // These don't matter as we won't create new items from this base.
            Level                = 0;
            RequiredStrength     = 0;
            RequiredDexterity    = 0;
            RequiredIntelligence = 0;
            DropDisabled         = false;
            InventoryHeight      = 0;
            InventoryWidth       = 0;
            MetadataId           = "";
            ImplicitMods         = new List <IMod>();
            _properties          = new List <string>();
            CanHaveQuality       = false;

            Name      = typeLine;
            ItemClass = ItemSlotToClass(itemSlot);
            if (ItemClass == ItemClass.ActiveSkillGem)
            {
                ItemClass = ItemClassEx.ItemClassForGem(typeLine);
            }
            if (ItemClass == ItemClass.Unknown)
            {
                if (frameType == FrameType.Gem)
                {
                    ItemClass = ItemClassEx.ItemClassForGem(typeLine);
                }
                else if (frameType == FrameType.Currency || frameType == FrameType.DivinationCard ||
                         frameType == FrameType.QuestItem || frameType == FrameType.Prophecy)
                {
                    ItemClass = ItemClass.Unknown;
                }
                else if (typeLine.Contains("Quiver"))
                {
                    ItemClass = ItemClass.Quiver;
                }
                else if (typeLine.Contains("Shield") || typeLine.Contains("Buckler"))
                {
                    ItemClass = ItemClass.Shield;
                }
                else if (typeLine.Contains("Amulet") || typeLine.Contains("Talisman"))
                {
                    ItemClass = ItemClass.Amulet;
                }
                else if (typeLine.Contains("Ring"))
                {
                    ItemClass = ItemClass.Ring;
                }
                else if (typeLine.Contains("Belt"))
                {
                    ItemClass = ItemClass.Belt;
                }
            }

            // This might miss some tags, but those are only important for mod crafting,
            // which will not happen with this item.
            Tags = ItemClass.ToTags();

            Image = new ItemImage(itemImageService, ItemClass);
        }
示例#2
0
        public ItemBase(ItemImageService itemImageService, XmlItemBase xmlBase)
        {
            Level                = xmlBase.Level;
            RequiredStrength     = xmlBase.Strength;
            RequiredDexterity    = xmlBase.Dexterity;
            RequiredIntelligence = xmlBase.Intelligence;
            DropDisabled         = xmlBase.DropDisabled;
            InventoryHeight      = xmlBase.InventoryHeight;
            InventoryWidth       = xmlBase.InventoryWidth;

            Name       = xmlBase.Name;
            ItemType   = xmlBase.ItemType;
            ItemGroup  = ItemType.Group();
            MetadataId = xmlBase.MetadataId;

            ImplicitMods   = xmlBase.Implicit.Select(i => new Stat(i, ItemType)).ToList();
            _properties    = xmlBase.Properties.Select(p => new Stat(p, ItemType)).ToList();
            CanHaveQuality = ItemGroup == ItemGroup.OneHandedWeapon || ItemGroup == ItemGroup.TwoHandedWeapon ||
                             ItemGroup == ItemGroup.BodyArmour || ItemGroup == ItemGroup.Boots ||
                             ItemGroup == ItemGroup.Gloves || ItemGroup == ItemGroup.Helmet ||
                             ItemGroup == ItemGroup.Shield;

            Image = new ItemImage(itemImageService, Name, ItemGroup);

            MaximumNumberOfSockets = GetMaximumNumberOfSockets();
        }
示例#3
0
 /// <summary>
 /// Returns a unique image that is loaded asynchronously.
 /// This image is used as default as long as the loading is not done and in case it fails.
 /// </summary>
 public ItemImage AsDefaultForUniqueImage(ItemImageService itemImageService, string uniqueName)
 {
     return(new ItemImage(
                ImageSource.Result,
                itemImageService.LoadItemImageAsync(uniqueName, ImageSource.Task),
                "Loading of unique item image failed"
                ));
 }
示例#4
0
 /// <summary>
 /// Returns an image that is loaded asynchronously from an url. Only urls stored in an item's json as
 /// retrieved from the official api are supported. This image is used as default as long as
 /// the loading is not done and in case it fails.
 /// </summary>
 public ItemImage AsDefaultForImageFromUrl(ItemImageService itemImageService, string imageUrl)
 {
     return(new ItemImage(
                ImageSource.Result,
                itemImageService.LoadFromUrlAsync(MakeUrl(imageUrl), ImageSource.Task),
                "Downloading of item image from official url failed"
                ));
 }
示例#5
0
 private EquipmentData(Options options)
 {
     if (!UriParser.IsKnownScheme("pack"))
     {
         // Necessary for unit tests. Accessing PackUriHelper triggers static initialization.
         // Without it, creating resource URIs from unit tests would throw UriFormatExceptions.
         var _ = System.IO.Packaging.PackUriHelper.UriSchemePack;
     }
     _itemImageService = new ItemImageService(options);
 }
示例#6
0
        /// <summary>
        /// Represents an image for an item base. First the classes's image will be loaded synchronously,
        /// which is then used as the image until the base item's image is loaded asynchronously.
        /// </summary>
        public ItemImage(ItemImageService itemImageService, string baseName, ItemClass baseClass)
        {
            var defaultImage = itemImageService.LoadDefaultImage(baseClass);

            ImageSource = NewImageSourceTask(
                itemImageService.LoadItemImageAsync(baseName, Task.FromResult(defaultImage)),
                "Loading of base item image failed",
                defaultImage
                );
        }
示例#7
0
        /// <summary>
        /// Represents an image for an item class. The image will be loaded synchronously.
        /// </summary>
        public ItemImage(ItemImageService itemImageService, ItemClass baseClass)
        {
            var defaultImage = itemImageService.LoadDefaultImage(baseClass);

            ImageSource = NewImageSourceTask(
                Task.FromResult(defaultImage),
                "Exception in completed task",
                defaultImage
                );
        }
示例#8
0
        public UniqueBase(ItemImageService itemImageService, ItemBase itemBase, XmlUnique xmlUnique)
        {
            UniqueName   = xmlUnique.Name;
            Level        = xmlUnique.Level;
            DropDisabled = xmlUnique.DropDisabled;
            _base        = itemBase;
            ExplicitMods = xmlUnique.Explicit.Select(e => new Stat(e, itemBase.ItemType)).ToList();

            Image = itemBase.Image.AsDefaultForUniqueImage(itemImageService, UniqueName);
        }
示例#9
0
        /// <summary>
        /// Represents an image for an item base. First the group's image will be loaded synchronously,
        /// which is then used as the image until the base item's image is loaded asynchronously.
        /// </summary>
        public ItemImage(ItemImageService itemImageService, string baseName, ItemGroup baseGroup)
        {
            var defaultImage = itemImageService.LoadDefaultImage(baseGroup);

            ImageSource = NewImageSourceTask(
                itemImageService.LoadItemImageAsync(baseName, defaultImage),
                "Loading of base item image failed",
                defaultImage
                );
        }
示例#10
0
        public ItemBase(ItemImageService itemImageService, ModDatabase modDatabase, XmlItemBase xmlBase)
        {
            Level                = xmlBase.Level;
            RequiredStrength     = xmlBase.Strength;
            RequiredDexterity    = xmlBase.Dexterity;
            RequiredIntelligence = xmlBase.Intelligence;
            DropDisabled         = xmlBase.DropDisabled;
            InventoryHeight      = xmlBase.InventoryHeight;
            InventoryWidth       = xmlBase.InventoryWidth;

            Name       = xmlBase.Name;
            ItemClass  = xmlBase.ItemClass;
            Tags       = xmlBase.Tags;
            MetadataId = xmlBase.MetadataId;

            ImplicitMods   = xmlBase.Implicit.Select(id => modDatabase.Mods[id]).ToList();
            _properties    = xmlBase.Properties;
            CanHaveQuality = Tags.HasFlag(Tags.Weapon) || Tags.HasFlag(Tags.Armour);

            Image = new ItemImage(itemImageService, Name, ItemClass);

            MaximumNumberOfSockets = GetMaximumNumberOfSockets();
        }
示例#11
0
        public UniqueBase(ItemImageService itemImageService, ModDatabase modDatabase, ItemBase itemBase,
                          XmlUnique xmlUnique)
        {
            UniqueName   = xmlUnique.Name;
            Level        = xmlUnique.Level;
            DropDisabled = xmlUnique.DropDisabled;
            _base        = itemBase;
            _properties  = xmlUnique.Properties;
            var explicits = new List <IMod>();

            foreach (var id in xmlUnique.Explicit)
            {
                Mod mod;
                if (!modDatabase.Mods.TryGetValue(id, out mod))
                {
                    Log.Error($"Unknown mod id {id} on unique {UniqueName}");
                    continue;
                }
                explicits.Add(mod);
            }
            ExplicitMods = explicits;

            Image = itemBase.Image.AsDefaultForUniqueImage(itemImageService, UniqueName);
        }
示例#12
0
        /// <summary>
        /// Creates an ItemBase that sets <see cref="ItemGroup"/> and <see cref="ItemType"/> on
        /// a best effort basis. They might not be set correctly.
        /// <para/>
        /// Only <see cref="Name"/>, <see cref="ItemGroup"/> and <see cref="ItemType"/> may be called on
        /// ItemBases created via this constructor. It is not meant to produce bases that can exist independent
        /// of the <see cref="Item"/> they are created for.
        /// </summary>
        /// <param name="itemImageService"></param>
        /// <param name="itemSlot">The slot the parent <see cref="Item"/> is slotted into.
        /// <see cref="ItemSlot.Unequipable"/> if is not equipped.</param>
        /// <param name="typeLine">The TypeLine property of the parent <see cref="Item"/>.</param>
        /// <param name="weaponClass">A string representing the weapon class of the parent <see cref="Item"/>.
        /// Can be null or empty if that item is not a weapon. The weapon class generally is a property without value.</param>
        /// <param name="frameType">The frame type of the item.</param>
        public ItemBase(ItemImageService itemImageService,
                        ItemSlot itemSlot, string typeLine, string weaponClass, FrameType frameType)
        {
            // These don't matter as we won't create new items from this base.
            Level                = 0;
            RequiredStrength     = 0;
            RequiredDexterity    = 0;
            RequiredIntelligence = 0;
            DropDisabled         = false;
            InventoryHeight      = 0;
            InventoryWidth       = 0;
            MetadataId           = "";
            ImplicitMods         = new List <Stat>();
            _properties          = new List <Stat>();
            CanHaveQuality       = false;

            Name      = typeLine;
            ItemGroup = ItemSlotToGroup(itemSlot);
            if (ItemGroup != ItemGroup.Unknown)
            {
                // This might be wrong for Armour slots, but the item will most likely not be edited so this is not important.
                ItemType = ItemGroup.Types()[0];
            }
            else if (frameType == FrameType.Gem)
            {
                ItemType = ItemType.Gem;
            }
            else if (frameType == FrameType.Currency || frameType == FrameType.DivinationCard ||
                     frameType == FrameType.QuestItem || frameType == FrameType.Prophecy)
            {
                ItemType = ItemType.Unknown;
            }
            else if (typeLine.Contains("Quiver"))
            {
                ItemType = ItemType.Quiver;
            }
            else if (typeLine.Contains("Shield") || typeLine.Contains("Buckler"))
            {
                ItemType = ItemType.ShieldArmour;
            }
            else if (typeLine.Contains("Amulet") || typeLine.Contains("Talisman"))
            {
                ItemType = ItemType.Amulet;
            }
            else if (typeLine.Contains("Ring"))
            {
                ItemType = ItemType.Ring;
            }
            else if (typeLine.Contains("Belt"))
            {
                ItemType = ItemType.Belt;
            }
            else if (!string.IsNullOrEmpty(weaponClass.Trim()))
            {
                ItemType type;
                if (Enum.TryParse(Regex.Replace(weaponClass.Trim(), "([a-z]) ([A-Z])", "$1$2"), true, out type))
                {
                    ItemType = type;
                }
            }

            if (ItemGroup == ItemGroup.Unknown)
            {
                ItemGroup = ItemType.Group();
            }
            Image = new ItemImage(itemImageService, ItemGroup);
        }
示例#13
0
 private EquipmentData(Options options)
 {
     _itemImageService = new ItemImageService(options);
 }
示例#14
0
 private EquipmentData(Options options)
 {
     Util.TriggerPackUriSchemeInitialization();
     _itemImageService = new ItemImageService(options);
 }
示例#15
0
        /// <summary>
        /// Creates an ItemBase that sets <see cref="ItemClass"/> and <see cref="Tags"/> on
        /// a best effort basis. They might not be set correctly.
        /// <para/>
        /// Only <see cref="Name"/>, <see cref="ItemClass"/> and <see cref="Tags"/> may be called on
        /// ItemBases created via this constructor. It is not meant to produce bases that can exist independent
        /// of the <see cref="Item"/> they are created for.
        /// </summary>
        /// <param name="itemImageService"></param>
        /// <param name="itemSlot">The slot the parent <see cref="Item"/> is slotted into.
        /// <see cref="ItemSlot.Unequipable"/> if is not equipped.</param>
        /// <param name="typeLine">The TypeLine property of the parent <see cref="Item"/>.</param>
        /// <param name="weaponClass">A string representing the weapon class of the parent <see cref="Item"/>.
        /// Can be null or empty if that item is not a weapon. The weapon class generally is a property without value.</param>
        /// <param name="frameType">The frame type of the item.</param>
        public ItemBase(ItemImageService itemImageService,
                        ItemSlot itemSlot, string typeLine, string weaponClass, FrameType frameType)
        {
            // These don't matter as we won't create new items from this base.
            Level                = 0;
            RequiredStrength     = 0;
            RequiredDexterity    = 0;
            RequiredIntelligence = 0;
            DropDisabled         = false;
            InventoryHeight      = 0;
            InventoryWidth       = 0;
            MetadataId           = "";
            ImplicitMods         = new List <IMod>();
            _properties          = new List <string>();
            CanHaveQuality       = false;

            Name      = typeLine;
            ItemClass = ItemSlotToClass(itemSlot);
            if (ItemClass == ItemClass.ActiveSkillGem)
            {
                ItemClass = ItemClassEx.ItemClassForGem(typeLine);
            }
            if (ItemClass == ItemClass.Unknown)
            {
                if (frameType == FrameType.Gem)
                {
                    ItemClass = ItemClassEx.ItemClassForGem(typeLine);
                }
                else if (frameType == FrameType.Currency || frameType == FrameType.DivinationCard ||
                         frameType == FrameType.QuestItem || frameType == FrameType.Prophecy)
                {
                    ItemClass = ItemClass.Unknown;
                }
                else if (typeLine.Contains("Quiver"))
                {
                    ItemClass = ItemClass.Quiver;
                }
                else if (typeLine.Contains("Shield") || typeLine.Contains("Buckler"))
                {
                    ItemClass = ItemClass.Shield;
                }
                else if (typeLine.Contains("Amulet") || typeLine.Contains("Talisman"))
                {
                    ItemClass = ItemClass.Amulet;
                }
                else if (typeLine.Contains("Ring"))
                {
                    ItemClass = ItemClass.Ring;
                }
                else if (typeLine.Contains("Belt"))
                {
                    ItemClass = ItemClass.Belt;
                }
                else if (!string.IsNullOrWhiteSpace(weaponClass))
                {
                    // This will not catch ThrustingOneHandSword and Sceptre,
                    // but the distinction between those and OneHandSword and OneHandMace only matters for mod crafting
                    var itemClassStr = weaponClass.Replace("Handed", "Hand")
                                       .Replace(" ", "").Trim();
                    ItemClass type;
                    if (Enum.TryParse(itemClassStr, true, out type))
                    {
                        ItemClass = type;
                    }
                }
            }

            // This might miss some tags, but those are only important for mod crafting,
            // which will not happen with this item.
            Tags = ItemClass.ToTags();

            Image = new ItemImage(itemImageService, ItemClass);
        }