ArrayList SelectionSortAscendingByProperty(ArrayList PropertyBox) { for (int i = 0; i < PropertyBox.Count - 1; i++) { int min = i; for (int j = i + 1; j < PropertyBox.Count; j++) { RecipeUI.PropertyElementBase _proi = (RecipeUI.PropertyElementBase)PropertyBox[i]; RecipeUI.PropertyElementBase _proj = (RecipeUI.PropertyElementBase)PropertyBox[j]; int _i = _proi.Property.ID; int _j = _proj.Property.ID; if (_i < _j) { min = j; } } if (min != i) { RecipeUI.PropertyElementBase temp = (RecipeUI.PropertyElementBase)PropertyBox[i]; PropertyBox[i] = PropertyBox[min]; PropertyBox[min] = temp; } } return(PropertyBox); }
ArrayList FindAllComposeResult(ArrayList PropertyBox) { ArrayList result = new ArrayList(); for (int i = 0; i < PropertyBox.Count; i++) { RecipeUI.PropertyElementBase _proBase1 = (RecipeUI.PropertyElementBase)PropertyBox[i]; Materiral.Property p1 = _proBase1.Property; for (int j = i + 1; j < PropertyBox.Count; j++) { RecipeUI.PropertyElementBase _proBase2 = (RecipeUI.PropertyElementBase)PropertyBox[j]; Materiral.Property p2 = _proBase2.Property; //用于储存合成的结果数字(求和)和合成属性的ID,第一个为属性1,第二个为属性2 Result _r = new Result(); _r.sum = p1.ID + p2.ID; _r.Base1 = _proBase1; _r.Base2 = _proBase2; result.Add(_r); } } return(result); }
//合成属性的方法 public ArrayList ComposeProperty(ArrayList PropertyBox, out Result Compose) { //ArrayList SortPropertyBox = SelectionSortAscendingByProperty(PropertyBox); ArrayList AllComposeResult = FindAllComposeResult(PropertyBox); Compose = new Result(); bool canCompose = false; foreach (Result r in AllComposeResult) { //如何有可以合成的属性则跳出循环 if (canCompose) { break; } foreach (PropertyRecipe pr in PropertyRecipeList) { int _sum = pr.Slots[0] + pr.Slots[1]; if (_sum == r.sum) { if (pr.Slots[0] == r.Base1.Property.ID && pr.Slots[1] == r.Base2.Property.ID) { //表示可以合成 canCompose = true; Compose.sum = pr.Target; Compose.Base1 = r.Base1; Compose.Base2 = r.Base2; break; } if (pr.Slots[1] == r.Base1.Property.ID && pr.Slots[0] == r.Base2.Property.ID) { //表示可以合成 canCompose = true; Compose.sum = pr.Target; Compose.Base1 = r.Base1; Compose.Base2 = r.Base2; break; } } } } if (canCompose) { Compose.Base1.Property = Materiral.GetProNameByProID(Compose.sum); PropertyBox[Compose.Base1.ID - 1] = Compose.Base1; PropertyBox.Remove(Compose.Base2); for (int i = 0; i < PropertyBox.Count; i++) { RecipeUI.PropertyElementBase _p = (RecipeUI.PropertyElementBase)PropertyBox[i]; _p.ID = i + 1; PropertyBox[i] = _p; } } return(PropertyBox); }