Ejemplo n.º 1
0
        /// <param name="id">the id of this mod</param>
        /// <param name="jsonMod">the <see cref="JsonMod"/> to encapsulate</param>
        /// <param name="jsonBenchOptions">the master crafting options with which this mod can be crafted</param>
        /// <param name="spawnWeightsReplacement">replacement spawn weights if this mod can only be spawned by different
        /// means, e.g. as a master signature mod</param>
        public Mod(string id, JsonMod jsonMod, IEnumerable <JsonCraftingBenchOption> jsonBenchOptions,
                   IEnumerable <JsonSpawnWeight> spawnWeightsReplacement)
        {
            Id = id;
            foreach (var jsonMasterMod in jsonBenchOptions)
            {
                foreach (var itemClass in jsonMasterMod.ItemClasses)
                {
                    if (ItemClassEx.TryParse(itemClass, out ItemClass enumClass))
                    {
                        _itemClasses.Add(enumClass);
                    }
                }
            }
            var spawnWeights = spawnWeightsReplacement ?? jsonMod.SpawnWeights;

            foreach (var spawnWeight in spawnWeights)
            {
                if (TagsEx.TryParse(spawnWeight.Tag, out Tags tag))
                {
                    _spawnTags.Add(Tuple.Create(tag, spawnWeight.CanSpawn));
                }
            }
            JsonMod = jsonMod;
            Stats   = jsonMod.Stats.Select(s => new Stat(s)).ToList();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public void JsonCraftingBenchOption_UnknownItemClasses()
 {
     foreach (var benchOption in _benchOptions)
     {
         foreach (var itemClass in benchOption.ItemClasses)
         {
             if (!ItemClassEx.TryParse(itemClass, out _))
             {
                 Assert.IsTrue(UnknownItemClasses.Contains(itemClass), itemClass + " unknown");
             }
         }
     }
 }
Ejemplo n.º 4
0
        public async Task JsonCraftingBenchOption_UnknownItemClasses()
        {
            await _initialization;

            foreach (var benchOption in _benchOptions)
            {
                foreach (var itemClass in benchOption.ItemClasses)
                {
                    ItemClass enumClass;
                    if (!ItemClassEx.TryParse(itemClass, out enumClass))
                    {
                        Assert.IsTrue(UnknownItemClasses.Contains(itemClass), itemClass + " unknown");
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor for gems as items. Their properties are only gem tags and what is necessary to get the
        /// correct attributes from ItemDB (level and quality).
        /// </summary>
        public Item(string gemName, IEnumerable <string> tags, int level, int quality, int socketGroup)
        {
            ItemClass = ItemClassEx.ItemClassForGem(gemName);
            Tags      = ItemClass.ToTags();
            Keywords  = tags.ToList();
            _frame    = FrameType.Gem;

            var keywordProp = new ItemMod(string.Join(", ", Keywords), false);

            _properties.Add(keywordProp);
            var levelProp = new ItemMod($"Level: {level}", false, ValueColoring.LocallyAffected);

            _properties.Add(levelProp);
            var qualityProp = new ItemMod($"Quality: +{quality}%", false, ValueColoring.LocallyAffected);

            _properties.Add(qualityProp);

            NameLine    = "";
            TypeLine    = gemName;
            SocketGroup = socketGroup;

            Width  = 1;
            Height = 1;
        }
Ejemplo n.º 6
0
        public Item(IPersistentData persistentData, JObject val, ItemSlot itemSlot = ItemSlot.Unequipable, bool isGem = false)
        {
            JsonBase = val;
            Slot     = itemSlot;

            Width  = val["w"].Value <int>();
            Height = val["h"].Value <int>();
            if (val["x"] != null)
            {
                X = val["x"].Value <int>();
            }
            if (val["y"] != null)
            {
                Y = val["y"].Value <int>();
            }

            if (val["name"] != null)
            {
                NameLine = FilterJsonString(val["name"].Value <string>());
            }

            JToken iconToken;

            if (val.TryGetValue("icon", out iconToken))
            {
                _iconUrl = iconToken.Value <string>();
            }

            Frame    = (FrameType)val["frameType"].Value <int>();
            TypeLine = FilterJsonString(val["typeLine"].Value <string>());
            if (isGem)
            {
                // BaseType will be null for socketed gems.
                ItemClass = ItemClassEx.ItemClassForGem(TypeLine);
                Tags      = ItemClass.ToTags();
            }
            else
            {
                if (Frame == FrameType.Magic)
                {
                    BaseType = persistentData.EquipmentData.ItemBaseFromTypeline(TypeLine);
                }
                else if ((Frame == FrameType.Unique || Frame == FrameType.Foil) &&
                         persistentData.EquipmentData.UniqueBaseDictionary.ContainsKey(NameLine))
                {
                    BaseType = persistentData.EquipmentData.UniqueBaseDictionary[NameLine];
                }
                else
                {
                    // item is not unique or the unique is unknown
                    ItemBase iBase;
                    persistentData.EquipmentData.ItemBaseDictionary.TryGetValue(TypeLine, out iBase);
                    BaseType = iBase;
                }
                // For known bases, images are only downloaded if the item is unique or foil. All other items should
                // always have the same image. (except alt art non-uniques that are rare enough to be ignored)
                var loadImageFromIconUrl = _iconUrl != null &&
                                           (BaseType == null || Frame == FrameType.Unique || Frame == FrameType.Foil);
                if (BaseType == null)
                {
                    BaseType = new ItemBase(persistentData.EquipmentData.ItemImageService, itemSlot, TypeLine,
                                            Keywords == null ? "" : Keywords.FirstOrDefault(), Frame);
                }
                ItemClass = BaseType.ItemClass;
                Tags      = BaseType.Tags;
                if (loadImageFromIconUrl)
                {
                    Image = BaseType.Image.AsDefaultForImageFromUrl(
                        persistentData.EquipmentData.ItemImageService, _iconUrl);
                }
                else
                {
                    Image = BaseType.Image;
                }
            }

            if (val["properties"] != null)
            {
                foreach (var obj in val["properties"])
                {
                    Properties.Add(ItemModFromJson(obj, ModLocation.Property));
                }
                if (Properties.Any(m => !m.Values.Any()))
                {
                    // The name of one property of gems contains the Keywords of that gem.
                    Keywords = Properties.First(m => !m.Values.Any()).Attribute.Split(',').Select(i => i.Trim()).ToList();
                }
            }

            if (val["requirements"] != null)
            {
                var mods = val["requirements"].Select(t => ItemModFromJson(t, ModLocation.Requirement)).ToList();
                if (!mods.Any(m => m.Attribute.StartsWith("Requires ")))
                {
                    var modsToMerge = new []
                    {
                        mods.FirstOrDefault(m => m.Attribute == "Level #"),
                        mods.FirstOrDefault(m => m.Attribute == "# Str"),
                        mods.FirstOrDefault(m => m.Attribute == "# Dex"),
                        mods.FirstOrDefault(m => m.Attribute == "# Int")
                    }.Where(m => m != null).ToList();
                    modsToMerge.ForEach(m => mods.Remove(m));
                    mods.Add(new ItemMod(
                                 "Requires " + string.Join(", ", modsToMerge.Select(m => m.Attribute)),
                                 false,
                                 modsToMerge.Select(m => m.Values).Flatten(),
                                 modsToMerge.Select(m => m.ValueColors).Flatten()
                                 ));
                }
                _requirements.AddRange(mods);
            }


            if (val["implicitMods"] != null)
            {
                foreach (var s in val["implicitMods"].Values <string>())
                {
                    _implicitMods.Add(ItemModFromString(FixOldRanges(s), ModLocation.Implicit));
                }
            }
            if (val["explicitMods"] != null)
            {
                foreach (var s in val["explicitMods"].Values <string>())
                {
                    ExplicitMods.Add(ItemModFromString(FixOldRanges(s), ModLocation.Explicit));
                }
            }
            if (val["craftedMods"] != null)
            {
                foreach (var s in val["craftedMods"].Values <string>())
                {
                    CraftedMods.Add(ItemModFromString(FixOldRanges(s), ModLocation.Crafted));
                }
            }

            if (val["flavourText"] != null && val["flavourText"].HasValues)
            {
                FlavourText = string.Join("\r\n", val["flavourText"].Values <string>().Select(s => s.Replace("\r", "")));
            }

            var sockets = new List <int>();

            if (val["sockets"] != null)
            {
                foreach (var obj in (JArray)val["sockets"])
                {
                    sockets.Add(obj["group"].Value <int>());
                }
            }
            if (val["socketedItems"] != null)
            {
                int socket = 0;
                foreach (JObject obj in (JArray)val["socketedItems"])
                {
                    var item = new Item(persistentData, obj, isGem: true)
                    {
                        SocketGroup = sockets[socket++]
                    };
                    _gems.Add(item);
                }
            }
        }
Ejemplo n.º 7
0
 private static bool HasValidItemClass(JToken itemBaseJson)
 {
     return(ItemClassEx.TryParse(itemBaseJson.Value <string>("item_class"), out var itemClass) &&
            ItemClassWhitelist.Contains(itemClass));
 }
Ejemplo n.º 8
0
 private void ParseItemClass()
 {
     ItemClassEx.TryParse(_json.Value <string>("item_class"), out var itemClass);
     _xml.ItemClass = itemClass;
 }
Ejemplo n.º 9
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);
        }