Beispiel #1
0
 public BuildTask(Blueprint blueprint)
 {
     BluePrint = blueprint;
     Progress = 0;
     Materials = new List<IItem>();
 }
Beispiel #2
0
        public void Build(Blueprint blueprint)
        {
            var task = new BuildTask(blueprint);

            foreach ( Material material in blueprint.Materials )
            {
                try
                {
                    IItem item = Stores.Find(i => i.ItemID == material.ItemID);
                    if ( item == null )
                        throw new InvalidOperationException("Manufactory does not have any {0}".Expand(material.Name));

                    if ( item.Quantity < material.Quantity )
                        throw new InvalidOperationException("Manufactory does not have enough {0}".Expand(material.Name));

                    IItem buildMaterials = item.Unstack(material.Quantity);
                    task.Materials.Add(buildMaterials);
                }
                catch (Exception)
                {
                    task.Materials.ForEach(AddItem);
                    throw;
                }
            }

            if (currentTask != null)
            {
                currentTask.Materials.ForEach(AddItem);
            }

            currentTask = task;
        }