using System.Collections; using System.Collections.Generic; using UnityEngine; using LitJson; public class LegendPropertyUtility { static PropertyColor propertyColor; static PropertyMap dogzPropertyMap; static PropertyCount dogzPropertyCount; static QualityPropertyValue dogzQualityPropertyValue; public static void Init() { propertyColor = new PropertyColor("LegendAttrColor"); dogzPropertyMap = new PropertyMap(FuncConfigConfig.Get("DogzLegendAttrColor").Numerical1, FuncConfigConfig.Get("DogzLegendAttrRulePreview").Numerical1); dogzPropertyCount = new PropertyCount(FuncConfigConfig.Get("DogzLegendAttrCountPreview").Numerical1); dogzQualityPropertyValue = new QualityPropertyValue(FuncConfigConfig.Get("DogzLegendAttrValueByColorPreview").Numerical1); } public static List GetEquipProperties(int itemId) { var config = ItemConfig.Get(itemId); if (config == null) { return null; } var legendPropertyConfig = LegendPropertyValueConfig.Get(config.Type, config.LV, config.ItemColor, config.SuiteiD != 0); if (legendPropertyConfig == null) { return null; } return new List(legendPropertyConfig.previewValue); } public static int GetEquipPropertyCount(int itemId) { var config = ItemConfig.Get(itemId); if (config == null) { return 0; } var legendPropertyConfig = LegendPropertyValueConfig.Get(config.Type, config.LV, config.ItemColor, config.SuiteiD != 0); if (legendPropertyConfig == null) { return 0; } return legendPropertyConfig.propertyCount; } public static LegendAttrType GetDogzPropertyType(int propertyId) { return dogzPropertyMap.GetPropertyType(propertyId); } public static bool HasDogzPlace(int place) { return dogzPropertyMap.HasPlace(place); } public static List GetDogzPlaceProperties(int place) { return dogzPropertyMap.GetProperties(place); } public static int GetDogzPropertyCount(int quality, int star, LegendAttrType type) { return dogzPropertyCount.GetCount(quality, star, type); } public static int GetDogzQualityPropertyValue(int property, int quality) { return dogzQualityPropertyValue.GetValue(property, quality); } public class PropertyColor { Dictionary> wingLegendPropertyColors = new Dictionary>(); public PropertyColor(string configId) { var config = FuncConfigConfig.Get(configId); var wingColorJsonData = JsonMapper.ToObject(config.Numerical2); foreach (var key in wingColorJsonData.Keys) { var propertyId = int.Parse(key); if (!wingLegendPropertyColors.ContainsKey(propertyId)) { wingLegendPropertyColors[propertyId] = new Dictionary(); } var subJson = wingColorJsonData[key]; var colors = wingLegendPropertyColors[propertyId]; foreach (var key2 in subJson.Keys) { var limit = int.Parse(key2); colors[limit] = subJson[key2][0].ToString(); } } } public string GetWingPropertyColor(int propertyId, int value) { if (!wingLegendPropertyColors.ContainsKey(propertyId)) { return "ffffff"; } var colors = wingLegendPropertyColors[propertyId]; var ienumerator = colors.GetEnumerator(); ienumerator.MoveNext(); var color = ienumerator.Current.Value; while (ienumerator.MoveNext()) { if (value < ienumerator.Current.Key) { color = ienumerator.Current.Value; } else { break; } } return color; } } public class PropertyMap { Dictionary propertyTypes = new Dictionary(); // key 装备位 value 属性ID Dictionary> placeToProperties = new Dictionary>(); public PropertyMap(string typeConfig, string placeConfig) { var json = JsonMapper.ToObject(typeConfig); foreach (var item in json.Keys) { var type = (LegendAttrType)(int.Parse(item) - 1); var propertyId = 0; int.TryParse(json[item].ToString(), out propertyId); propertyTypes[propertyId] = type; } json = JsonMapper.ToObject(placeConfig); foreach (var key in json.Keys) { var equipPlace = int.Parse(key); var properties = new List(); placeToProperties.Add(equipPlace, properties); if (json[key].IsArray) { var subJson = json[key]; for (var i = 0; i < subJson.Count; i++) { if (subJson[i].IsArray) { for (var j = 0; j < subJson[i].Count; j++) { var propertyId = (int)subJson[i][j]; properties.Add(propertyId); } } } } } } public bool HasProperty(int propertyId) { return propertyTypes.ContainsKey(propertyId); } public LegendAttrType GetPropertyType(int propertyId) { if (HasProperty(propertyId)) { return propertyTypes[propertyId]; } else { return LegendAttrType.Normal; } } public bool HasPlace(int place) { return placeToProperties.ContainsKey(place); } public List GetProperties(int place) { if (HasPlace(place)) { return placeToProperties[place]; } else { return null; } } public List GetProperties(int place, LegendAttrType type) { if (!HasPlace(place)) { return null; } var allProperties = placeToProperties[place]; var properties = new List(); for (var i = 0; i < allProperties.Count; i++) { var propertyId = allProperties[i]; if (propertyTypes[propertyId] == type) { properties.Add(propertyId); } } return properties; } } public class PropertyCount { Dictionary qualityToStarLegendPropertyCounts = new Dictionary(); public PropertyCount(string config) { var json = JsonMapper.ToObject(config); foreach (var key in json.Keys) { var quality = int.Parse(key); qualityToStarLegendPropertyCounts[quality] = new StarPropertyCount(json[key]); } } public bool Has(int quality) { return qualityToStarLegendPropertyCounts.ContainsKey(quality); } public bool Has(int quality, int star) { if (!qualityToStarLegendPropertyCounts.ContainsKey(quality)) { return false; } return qualityToStarLegendPropertyCounts[quality].Has(star); } public int GetCount(int quality, int star, LegendAttrType type) { if (!Has(quality, star)) { return 0; } return qualityToStarLegendPropertyCounts[quality].GetCount(star, type); } class StarPropertyCount { Dictionary> counts = new Dictionary>(); public StarPropertyCount(JsonData json) { foreach (var key in json.Keys) { var star = int.Parse(key); var typeCounts = counts[star] = new Dictionary(); var subJson = json[key]; if (subJson.IsArray) { for (int i = 0; i < subJson.Count; i++) { var type = (LegendAttrType)(i); typeCounts[type] = (int)subJson[i]; } } } } public bool Has(int star) { return counts.ContainsKey(star); } public int GetCount(int star, LegendAttrType type) { if (!counts.ContainsKey(star)) { return 0; } if (!counts[star].ContainsKey(type)) { return 0; } return counts[star][type]; } } } public class QualityPropertyValue { // key 属性ID value 装备品质,属性数值 Dictionary> qualityValues = new Dictionary>(); public QualityPropertyValue(string config) { var json = JsonMapper.ToObject(config); foreach (var key in json.Keys) { var propertyId = int.Parse(key); var qualityToValue = new Dictionary(); qualityValues.Add(propertyId, qualityToValue); var subJson = json[key]; for (var i = 0; i < subJson.Count; i++) { qualityToValue[(int)subJson[i][0]] = (int)subJson[i][1]; } } } public bool Has(int property) { return qualityValues.ContainsKey(property); } public bool Has(int property, int quality) { if (!qualityValues.ContainsKey(property)) { return false; } return qualityValues[property].ContainsKey(property); } public int GetValue(int property, int quality) { if (Has(property, quality)) { return qualityValues[property][quality]; } else { return 0; } } } }