Esempio n. 1
0
        private void productItemsAddButton_Click(object sender, EventArgs e)
        {
            addingItemsRichTextBox.Text = Clipboard.GetText();

            foreach (string str in addingItemsRichTextBox.Text.Split('\n'))
            {
                var output   = ParseString(str);
                var itemStr  = output[0];
                var countStr = output[1];

                if (itemStr != "")
                {
                    var item = Program.DataBase.Items
                               .Where(i => i.Name == itemStr).Single();
                    var items = project.ProductionsItems
                                .Where(i => i.Item == item).SingleOrDefault();
                    var count = ParseCount(countStr)
                                * project.BlueprintsCount;


                    if (items == null)
                    {
                        items = new ItemsProduction
                        {
                            Project = project,
                            Item    = item,
                            Count   = count,
                        };
                        project.ProductionsItems.Add(items);
                    }

                    else
                    {
                        items.Count += count;
                    }
                }
            }
            addingItemsRichTextBox.Clear();

            RefreshProductionItems();
        }
        private static void AddNewProjectFromBlueprint(YamlBlueprint blueprint, int maxInventionTime)
        {
            foreach (var child in blueprint.activities.invention.products)
            {
                int inventionRuns = 1 + (int)maxInventionTime / blueprint.activities.invention.time;

                YamlBlueprint childBp = Program.Blueprints[child.typeID];
                Project       proj    = new Project();
                string        itemId  = childBp.activities.manufacturing.products[0]
                                        .typeID.ToString();

                Item readyItem = Program.DataBase.Items.SingleOrDefault
                                     (x => x.Id == itemId);
                if (readyItem == null)
                {
                    readyItem = new Item {
                        Id = itemId, Name = $"itemId: " + itemId,
                    };
                    Program.DataBase.Items.Add(readyItem);
                }
                proj.Name = readyItem.Name;
                proj.Item = readyItem;

                if (blueprint.activities.copying.materials != null)
                {
                    foreach (var copyingItem in blueprint.activities.copying.materials)
                    {
                        proj.ModernisationItems.Add(
                            new ItemsModernisation
                        {
                            Item = Program.DataBase.Items.FirstOrDefault(
                                x => x.Id == copyingItem.typeID.ToString()),
                            Count = copyingItem.quantity * inventionRuns,
                        });
                    }
                }

                if (blueprint.activities.invention.materials != null)
                {
                    foreach (var inventionItem in blueprint.activities.invention.materials)
                    {
                        proj.ModernisationItems.Add(
                            new ItemsModernisation
                        {
                            Item = Program.DataBase.Items.FirstOrDefault(
                                x => x.Id == inventionItem.typeID.ToString()),
                            Count = inventionItem.quantity * inventionRuns,
                        });
                    }
                }

                if (blueprint.activities.manufacturing.materials != null)
                {
                    foreach (var manufacturingItem in childBp.activities.manufacturing.materials)
                    {
                        var production = new ItemsProduction();
                        var item       = Program.DataBase.Items.FirstOrDefault(
                            x => x.Id == manufacturingItem.typeID.ToString());
                        if (item == null)
                        {
                            item = new Item
                            {
                                Id   = manufacturingItem.typeID.ToString(),
                                Name = "ItemId: " + manufacturingItem.typeID.ToString()
                            };
                            DataBase.Items.Add(item);
                        }
                        production.Item = item;
                        int count = manufacturingItem.quantity * childBp.maxProductionLimit;
                        count = (int)Math.Ceiling(0.98 * count);

                        production.Count = count;

                        proj.ProductionsItems.Add(production);
                    }
                }

                proj.BlueprintsCount = (int)((child.probability + 0.10) * inventionRuns);
                proj.ItemsCount      = childBp.maxProductionLimit;


                Program.DataBase.Projects.Add(proj);

                DataBase.SaveChanges();
            }
        }