public object Clone() { RoundGoalProfitItem outdata = new RoundGoalProfitItem { ProfitType = ProfitType, Sign = Sign, RolePay = RolePay, Value = Value }; return(outdata); }
//解析支付规则字符串 public void PerseRule(ref List <RoundGoalProfitItem> allitems, string input = "-50=B<0=D<A=9<C=100") { allitems.Clear(); int N = input.Length; int start = 0; int length = 0; for (int i = 0; i < N;) { char current = input[i]; if (current == '-' || current >= '0' && current <= '9') { i++; length++; if (i >= N) { i = N - 1; string num = input.Substring(start, N - start); int Num = int.Parse(num); RoundGoalProfitItem item = new RoundGoalProfitItem { ProfitType = EnumProperty.RoundProfitType.Number, Value = Num }; allitems.Add(item); length = 0; start = i; i = N; } else { char next = input[i]; if (next < '0' || next > '9') { string num = input.Substring(start, length); int Num = int.Parse(num); RoundGoalProfitItem item = new RoundGoalProfitItem { ProfitType = EnumProperty.RoundProfitType.Number, Value = Num }; allitems.Add(item); length = 0; start = i; } } } else { if (current == '>' || current == '<' || current == '=') { if (input[i + 1] == '=' && current != '=') { i = i + 2; length = 2; } else { i++; length = 1; } string sign = input.Substring(start, length); RoundGoalProfitItem item = new RoundGoalProfitItem { ProfitType = EnumProperty.RoundProfitType.Sign }; switch (sign) { case ">=": item.Sign = EnumProperty.RoundProfitSign.NotLess; break; case ">": item.Sign = EnumProperty.RoundProfitSign.More; break; case "<": item.Sign = EnumProperty.RoundProfitSign.Less; break; case "<=": item.Sign = EnumProperty.RoundProfitSign.NotMore; break; case "=": item.Sign = EnumProperty.RoundProfitSign.Equal; break; default: item.Sign = EnumProperty.RoundProfitSign.None; break; } allitems.Add(item); start = i; length = 0; } else { if (current >= 'A' && current <= 'H') { i++; length = 1; string pay = input.Substring(start, length); RoundGoalProfitItem item = new RoundGoalProfitItem { ProfitType = EnumProperty.RoundProfitType.RolePay, RolePay = (EnumProperty.RoundProfitRolePay)(current - 'A' + 1) }; allitems.Add(item); start = i; length = 0; } } } } }
//填充规则Profit public void FillProfit(ref Vector2[] Profit, ref List <RoundGoalProfitItem> allitems) { for (int i = 0; i < allitems.Count; i++) { RoundGoalProfitItem item = allitems[i]; int Left = 0; int Right = 0; int numless = 0; int nummore = 0; bool LeftEqual = false; bool RightEqual = false; if (item.ProfitType == EnumProperty.RoundProfitType.RolePay) { for (int k = i - 1; k >= 0; k--) { RoundGoalProfitItem item2 = allitems[k]; if (k == i - 1 && item2.ProfitType == EnumProperty.RoundProfitType.Sign && item2.Sign == EnumProperty.RoundProfitSign.Equal) { RoundGoalProfitItem item3 = allitems[i - 2]; if (item3.ProfitType == EnumProperty.RoundProfitType.Number) { LeftEqual = true; Left = item3.Value; break; } } if (item2.ProfitType == EnumProperty.RoundProfitType.Sign && item2.Sign == EnumProperty.RoundProfitSign.Less) { nummore++; } if (item2.ProfitType == EnumProperty.RoundProfitType.Number) { Left = item2.Value + nummore; break; } } for (int j = i + 1; j < allitems.Count; j++) { RoundGoalProfitItem item2 = allitems[j]; if (j == i + 1 && item2.ProfitType == EnumProperty.RoundProfitType.Sign && item2.Sign == EnumProperty.RoundProfitSign.Equal) { RoundGoalProfitItem item3 = allitems[i + 2]; if (item3.ProfitType == EnumProperty.RoundProfitType.Number) { RightEqual = true; Right = item3.Value; break; } RightEqual = true; } if (item2.ProfitType == EnumProperty.RoundProfitType.Sign && item2.Sign == EnumProperty.RoundProfitSign.Less) { numless++; } if (item2.ProfitType == EnumProperty.RoundProfitType.Number) { Right = item2.Value - numless; break; } } if (Left > Right) { Debug.LogError("Left > Right Check the Data"); return; } int index = (int)item.RolePay; int f = (index - 1) % 4; int xy = (index - 1) / 4; int rnum = 0; if (LeftEqual) { rnum = Left; } else if (RightEqual) { rnum = Right; } else { rnum = MathUtil.GetRandom(Left, Right); } if (xy == 0) { Profit[f].x = rnum; } if (xy == 1) { Profit[f].y = rnum; } item.ProfitType = EnumProperty.RoundProfitType.Number; item.RolePay = EnumProperty.RoundProfitRolePay.None; item.Value = rnum; Debug.Log("rnum " + rnum); } } }