예제 #1
0
        void CalculateCraftingCosts()
        {
            lvCrafting.Items.Clear();

            List <CraftingIngredient> ingredients = new List <CraftingIngredient>();

            SlaveLordCrafting.ESlaveLordItemSlots[] slots = (SlaveLordCrafting.ESlaveLordItemSlots[])Enum.GetValues(typeof(SlaveLordCrafting.ESlaveLordItemSlots));
            foreach (var slot in slots)
            {
                CraftedItemProperty cip = SLItem.Slots[(int)slot];
                if (cip?.Cost == null)
                {
                    continue;
                }
                foreach (var ing in cip.Cost)
                {
                    bool found = false;
                    for (int i = 0; i < ingredients.Count; i++)
                    {
                        if (ingredients[i].Name == ing.Name)
                        {
                            CraftingIngredient ci = ingredients[i];
                            ci.Amount     += ing.Amount;
                            ingredients[i] = ci;
                            found          = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        ingredients.Add(ing);
                    }
                }
            }

            ingredients.ForEach(i => lvCrafting.Items.Add(i));
        }
        void CalculateCraftingCosts()
        {
            tvBreakdown.Items.Clear();
            lvCrafting.Items.Clear();

            List <LGSCrafting.LGSCraftingIngredient> lgsci = new List <LGSCrafting.LGSCraftingIngredient>();
            List <CraftingIngredient> totalci = new List <CraftingIngredient>();

            for (int t = 0; t < LGSCrafting.Tiers; t++)
            {
                LGSCrafting.LGSCraftedItemProperty cip = LGSItem.Slots[t];
                if (cip?.Cost == null)
                {
                    continue;
                }
                foreach (var lgsi in cip.Cost)
                {
                    LGSCrafting.LGSCraftingIngredient tlgsci = lgsci.Find(l => l.Name == lgsi.Name);
                    if (tlgsci != null)
                    {
                        tlgsci.Count++;
                    }
                    else
                    {
                        tlgsci = new LGSCrafting.LGSCraftingIngredient {
                            Name = lgsi.Name, Ingredients = lgsi.Ingredients
                        };
                        lgsci.Add(tlgsci);
                    }

                    foreach (var ing in lgsi.Ingredients)
                    {
                        bool found = false;
                        for (int i = 0; i < totalci.Count; i++)
                        {
                            if (totalci[i].Name == ing.Name)
                            {
                                CraftingIngredient ci = totalci[i];
                                ci.Amount += ing.Amount;
                                totalci[i] = ci;
                                found      = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            totalci.Add(ing);
                        }
                    }
                }
            }

            // populate ingredient breakdown treeview
            foreach (var lgsi in lgsci)
            {
                TreeViewItem litvi = new TreeViewItem();
                litvi.Header = lgsi.Name;
                tvBreakdown.Items.Add(litvi);
                foreach (var li in lgsi.Ingredients)
                {
                    TreeViewItem citvi = new TreeViewItem();
                    citvi.Header = "(" + (lgsi.Count * li.Amount) + ") " + li.Name;
                    litvi.Items.Add(citvi);
                }
            }

            // populate total ingredients list
            totalci.ForEach(i => lvCrafting.Items.Add(i));
        }