private JObject GenerateJson() { var j = new JObject( new JProperty("w", Width), new JProperty("h", Height), new JProperty("x", X), new JProperty("y", Y), new JProperty("name", NameLine), new JProperty("typeLine", TypeLine), new JProperty("frameType", Frame) ); if (_iconUrl != null) { j["icon"] = _iconUrl; } if (Properties.Count > 0) { j.Add(new JProperty("properties", new JArray(Properties.Select(p => p.ToJobject()).ToArray()))); } if (Requirements.Count > 0) { j.Add(new JProperty("requirements", new JArray(Requirements.Select(p => p.ToJobject()).ToArray()))); } if (ImplicitMods.Count > 0) { j.Add(new JProperty("implicitMods", new JArray(ImplicitMods.Select(p => p.ToJobject(true)).ToArray()))); } if (ExplicitMods.Count > 0) { j.Add(new JProperty("explicitMods", new JArray(ExplicitMods.Select(p => p.ToJobject(true)).ToArray()))); } if (CraftedMods.Count > 0) { j.Add(new JProperty("craftedMods", new JArray(CraftedMods.Select(p => p.ToJobject(true)).ToArray()))); } if (HaveFlavourText) { j.Add("flavourText", new JArray(FlavourText)); } return(j); }
private JObject GenerateJson() { var j = new JObject( new JProperty("w", Width), new JProperty("h", Height), new JProperty("x", X), new JProperty("y", Y), new JProperty("name", NameLine), new JProperty("typeLine", TypeLine), new JProperty("frameType", Frame) ); if (_iconUrl != null) { j["icon"] = _iconUrl; } if (Properties.Count > 0) { j.Add(new JProperty("properties", new JArray(Properties.Select(p => p.ToJobject()).ToArray()))); } if (Requirements.Count > 0) { j.Add(new JProperty("requirements", new JArray(Requirements.Select(p => p.ToJobject()).ToArray()))); } if (ImplicitMods.Count > 0) { j.Add(new JProperty("implicitMods", new JArray(ImplicitMods.Select(p => p.ToJobject(true)).ToArray()))); } if (ExplicitMods.Count > 0) { j.Add(new JProperty("explicitMods", new JArray(ExplicitMods.Select(p => p.ToJobject(true)).ToArray()))); } if (CraftedMods.Count > 0) { j.Add(new JProperty("craftedMods", new JArray(CraftedMods.Select(p => p.ToJobject(true)).ToArray()))); } if (Gems.Count > 0) { var sockets = new JArray(); var socketedItems = new JArray(); foreach (var gem in Gems) { sockets.Add(new JObject { { "group", gem.SocketGroup } }); socketedItems.Add(gem.JsonBase); } j["sockets"] = sockets; j["socketedItems"] = socketedItems; } if (HaveFlavourText) { j.Add("flavourText", new JArray(FlavourText)); } return(j); }
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); } } }
private void Init(ItemClass iClass, JObject val) { JSONBase = val; Attributes = new Dictionary <string, List <float> >(); Mods = new List <ItemMod>(); Class = iClass; 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 = val["name"].Value <string>(); } TypeLine = BaseType = val["typeLine"].Value <string>(); Frame = (FrameType)val["frameType"].Value <int>(); if (val["properties"] != null) { foreach (JObject obj in (JArray)val["properties"]) { var values = new List <float>(); string s = ""; foreach (JArray jva in (JArray)obj["values"]) { s += " " + jva[0].Value <string>(); } s = s.TrimStart(); if (s == "") { Properties.Add(ItemMod.CreateMod(this, obj["name"].Value <string>(), numberfilter)); Keywords = new List <string>(); string[] sl = obj["name"].Value <string>().Split(','); foreach (string i in sl) { Keywords.Add(i.Trim()); } continue; } foreach (Match m in numberfilter.Matches(s)) { if (m.Value == "") { values.Add(float.NaN); } else { values.Add(float.Parse(m.Value, CultureInfo.InvariantCulture)); } } string cs = obj["name"].Value <string>() + ": " + (numberfilter.Replace(s, "#")); var mod = ItemMod.CreateMod(this, obj, numberfilter2); Properties.Add(mod); mod.ValueColor = ((JArray)obj["values"]).Select(a => { var floats = ((JArray)a)[0].Value <string>().Split('-'); return(floats.Select(f => (ItemMod.ValueColoring)((JArray)a)[1].Value <int>())); }).SelectMany(c => c).ToList(); Attributes.Add(cs, values); } } if (val["requirements"] != null) { string reqs = ""; List <float> numbers = new List <float>(); List <ItemMod.ValueColoring> affects = new List <ItemMod.ValueColoring>(); foreach (JObject obj in (JArray)val["requirements"]) { var n = obj["name"].Value <string>(); if (obj["displayMode"].Value <int>() == 0) { n = n + " #"; } else { n = "# " + n; } numbers.Add(((JArray)((JArray)obj["values"])[0])[0].Value <float>()); affects.Add((ItemMod.ValueColoring)((JArray)((JArray)obj["values"])[0])[1].Value <int>()); if (!string.IsNullOrEmpty(reqs)) { reqs += ", " + n; } else { reqs += n; } } var m = ItemMod.CreateMod(this, "Requires " + reqs, numberfilter); m.Value = numbers; m.ValueColor = affects; Requirements.Add(m); } if (val["implicitMods"] != null) { foreach (string s in val["implicitMods"].Values <string>()) { List <ItemMod> mods = ItemMod.CreateMods(this, s.Replace("Additional ", ""), numberfilter); Mods.AddRange(mods); ImplicitMods.Add(ItemMod.CreateMod(this, s, numberfilter)); } } if (val["explicitMods"] != null) { foreach (string s in val["explicitMods"].Values <string>()) { List <ItemMod> mods = ItemMod.CreateMods(this, s.Replace("Additional ", ""), numberfilter); Mods.AddRange(mods); ExplicitMods.Add(ItemMod.CreateMod(this, s, numberfilter)); } } if (val["craftedMods"] != null) { foreach (string s in val["craftedMods"].Values <string>()) { List <ItemMod> mods = ItemMod.CreateMods(this, s.Replace("Additional ", ""), numberfilter); Mods.AddRange(mods); CraftedMods.Add(ItemMod.CreateMod(this, s, numberfilter)); } } if (val["flavourText"] != null) { FlavourText = string.Join("\r\n", val["flavourText"].Values <string>()); } if (iClass == ItemClass.Gem) { switch (val["colour"].Value <string>()) { case "S": Keywords.Add("Strength"); break; case "D": Keywords.Add("Dexterity"); break; case "I": Keywords.Add("Intelligence"); break; } } else { Gems = new List <Item>(); } var Sockets = new List <int>(); if (val["sockets"] != null) { foreach (JObject 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(ItemClass.Gem, obj); item.SocketGroup = Sockets[socket++]; Gems.Add(item); } } }
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. _itemGroup = ItemGroup.Gem; } else { if (Frame == FrameType.Magic) { _baseType = persistentData.EquipmentData.ItemBaseFromTypeline(TypeLine); } else { persistentData.EquipmentData.BaseDictionary.TryGetValue(TypeLine, out _baseType); } // For known bases, images are only downloaded if the item is unique. 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); if (_baseType == null) { _baseType = new ItemBase(persistentData.Options, itemSlot, TypeLine, _keywords == null ? "" : _keywords.FirstOrDefault(), Frame); } _itemType = BaseType.ItemType; _itemGroup = BaseType.ItemGroup; if (loadImageFromIconUrl) { _image = new ItemImageFromOfficial(_baseType.Image, _iconUrl); } else { _image = _baseType.Image; _image.DownloadMissingImage(); } FixOldItems(); } if (val["properties"] != null) { foreach (var obj in val["properties"]) { Properties.Add(ItemModFromJson(obj, false)); } if (Properties.Any(m => !m.Value.Any())) { // The name of one property of gems contains the Keywords of that gem. _keywords = Properties.First(m => !m.Value.Any()).Attribute.Split(',').Select(i => i.Trim()).ToList(); } } if (val["requirements"] != null) { var mods = val["requirements"].Select(t => ItemModFromJson(t, true)).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(_itemType, "Requires " + string.Join(", ", modsToMerge.Select(m => m.Attribute))) { Value = modsToMerge.Select(m => m.Value).Flatten().ToList(), ValueColor = modsToMerge.Select(m => m.ValueColor).Flatten().ToList() }); } _requirements.AddRange(mods); } if (val["implicitMods"] != null) { foreach (var s in val["implicitMods"].Values <string>()) { _implicitMods.Add(new ItemMod(_itemType, s, Numberfilter)); } } if (val["explicitMods"] != null) { foreach (var s in val["explicitMods"].Values <string>()) { ExplicitMods.Add(new ItemMod(_itemType, s, Numberfilter)); } } if (val["craftedMods"] != null) { foreach (var s in val["craftedMods"].Values <string>()) { CraftedMods.Add(new ItemMod(_itemType, s, Numberfilter)); } } if (val["flavourText"] != null) { FlavourText = string.Join("\r\n", val["flavourText"].Values <string>().Select(s => s.Replace("\r", ""))); } if (isGem) { switch (val["colour"].Value <string>()) { case "S": _keywords.Add("Strength"); break; case "D": _keywords.Add("Dexterity"); break; case "I": _keywords.Add("Intelligence"); break; } } else { _gems = new List <Item>(); } 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); } } }