using Google.Protobuf.WellKnownTypes; using Newtonsoft.Json.Linq; using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; partial class EquipDesc { public void GetRandomAttr(JObject attr, Random rand, out string prop, out long value, Dictionary exclude, long lucky = 0) { prop = ""; value = 0; if (attr == null || attr.Count == 0) return; int allW = 0; var e = attr.GetEnumerator(); while (e.MoveNext()) { int val = e.Current.Value.ToObject(); allW += val; } int tryCount = 0; do { int rw = rand.Next(allW); e = attr.GetEnumerator(); int w = 0; while (e.MoveNext()) { var key = e.Current.Key; int val = e.Current.Value.ToObject(); w += val; if (rw < w) { if(key == "null" || key == "NULL") { return; } EquipAttrDesc equipAttrDesc = EquipAttrDescMgr.Instance.GetConfig(key); if (exclude != null && exclude.ContainsKey(equipAttrDesc.mainAttr)) { break; } value = equipAttrDesc.GetPropValue(rand, lucky, out _); prop = equipAttrDesc.mainAttr; return; } } } while (tryCount++ < 20); } //public void GetSkillAttr11(Random rand, out string prop, out long value, Dictionary exclude, long lucky = 0) //{ // GetRandomAttr(equipSkill1, rand, out prop, out value, exclude, lucky); //} //public void GetSkillAttr12(Random rand, out string prop, out long value, Dictionary exclude, long lucky = 0) //{ // GetRandomAttr(equipSkill2, rand, out prop, out value, exclude, lucky); //} //public void GetSkillAttr13(Random rand, out string prop, out long value, Dictionary exclude, long lucky = 0) //{ // GetRandomAttr(equipSkill3, rand, out prop, out value, exclude, lucky); //} public string GetRandomElement(Random rand) { string elem = ""; if (element == null || element.Count== 0) return elem; int allW = 0; var e = element.GetEnumerator(); while (e.MoveNext()) { int val = e.Current.Value.ToObject(); allW += val; } { int rw = rand.Next(allW); e = element.GetEnumerator(); int w = 0; while (e.MoveNext()) { var key = e.Current.Key; int val = e.Current.Value.ToObject(); w += val; if (rw < w) { elem = key; return elem; } } } return elem; } }