Пример #1
0
        public static void GetMountedComponents(MyComponentList addToList, MyObjectBuilder_CubeBlock block)
        {
            int topGroupIndex     = 0;
            int topComponentIndex = 0;
            MyCubeBlockDefinition blockDefinition = null;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);
            if ((blockDefinition != null) && (block != null))
            {
                float integrity = block.IntegrityPercent * blockDefinition.MaxIntegrity;
                CalculateIndicesInternal(integrity, blockDefinition, ref topGroupIndex, ref topComponentIndex);
                if ((topGroupIndex < blockDefinition.Components.Length) && (topComponentIndex < blockDefinition.Components[topGroupIndex].Count))
                {
                    int amount = topComponentIndex;
                    if (integrity >= 1.525902E-05f)
                    {
                        amount++;
                    }
                    for (int i = 0; i < topGroupIndex; i++)
                    {
                        MyCubeBlockDefinition.Component component = blockDefinition.Components[i];
                        addToList.AddMaterial(component.Definition.Id, component.Count, component.Count, false);
                    }
                    MyDefinitionId myDefinitionId = blockDefinition.Components[topGroupIndex].Definition.Id;
                    addToList.AddMaterial(myDefinitionId, amount, amount, false);
                }
            }
        }
Пример #2
0
        public void GetMissingComponents(Dictionary <string, int> addToDictionary, MyConstructionStockpile availableItems = null)
        {
            Dictionary <string, int> dictionary;
            string str2;
            int    topGroupIndex = this.m_topGroupIndex;

            MyCubeBlockDefinition.Component component = this.m_blockDefinition.Components[topGroupIndex];
            int num2 = this.m_topComponentIndex + 1;

            if (this.IsFullyDismounted)
            {
                num2--;
            }
            if (num2 < component.Count)
            {
                string subtypeName = component.Definition.Id.SubtypeName;
                if (!addToDictionary.ContainsKey(subtypeName))
                {
                    addToDictionary[subtypeName] = component.Count - num2;
                }
                else
                {
                    dictionary        = addToDictionary;
                    str2              = subtypeName;
                    dictionary[str2] += component.Count - num2;
                }
            }
            topGroupIndex++;
            while (topGroupIndex < this.m_blockDefinition.Components.Length)
            {
                component = this.m_blockDefinition.Components[topGroupIndex];
                string subtypeName = component.Definition.Id.SubtypeName;
                if (!addToDictionary.ContainsKey(subtypeName))
                {
                    addToDictionary[subtypeName] = component.Count;
                }
                else
                {
                    dictionary        = addToDictionary;
                    str2              = subtypeName;
                    dictionary[str2] += component.Count;
                }
                topGroupIndex++;
            }
            if (availableItems != null)
            {
                for (topGroupIndex = 0; topGroupIndex < addToDictionary.Keys.Count; topGroupIndex++)
                {
                    string subtypeName = addToDictionary.Keys.ElementAt <string>(topGroupIndex);
                    dictionary        = addToDictionary;
                    str2              = subtypeName;
                    dictionary[str2] -= availableItems.GetItemAmount(new MyDefinitionId(typeof(MyObjectBuilder_Component), subtypeName), MyItemFlags.None);
                    if (addToDictionary[subtypeName] <= 0)
                    {
                        addToDictionary.Remove(subtypeName);
                        topGroupIndex--;
                    }
                }
            }
        }
Пример #3
0
        private float priceWorth(MyCubeBlockDefinition.Component component, string priceType)
        {
            MyBlueprintDefinitionBase bpDef = MyDefinitionManager.Static.TryGetBlueprintDefinitionByResultId(component.Definition.Id);
            int   p     = 0;
            float price = 0;

            if (priceType == "Ingot")
            {
                for (p = 0; p < bpDef.Prerequisites.Length; p++)
                {
                    if (bpDef.Prerequisites[p].Id != null)
                    {
                        MyDefinitionBase oreDef = MyDefinitionManager.Static.GetDefinition(bpDef.Prerequisites[p].Id);
                        if (oreDef != null)
                        {
                            MyPhysicalItemDefinition ore = oreDef as MyPhysicalItemDefinition;
                            float amn = Math.Abs(ore.MinimumOfferAmount);
                            amn   = (float)Math.Round(amn * 2);
                            price = price + amn;
                            //MyVisualScriptLogicProvider.SendChatMessage(bpDef.Prerequisites[p].Id.ToString() + " - " + amn.ToString() + " SC");
                        }
                    }
                }
            }
            if (priceType == "Component")
            {
                float amn = Math.Abs(component.Definition.MinimumOfferAmount);
                //MyAPIGateway.Utilities.ShowNotification(amn.ToString(), 1, "White");
                amn   = (float)Math.Round(amn * 8);
                price = price + amn;
                //MyVisualScriptLogicProvider.SendChatMessage(component.Definition.Id.ToString() + " - " + amn.ToString() + " SC");
            }

            return(price);
        }
 private static Component GetComponent(MyCubeBlockDefinition.Component myComponent)
 {
     return(new Component()
     {
         Count = myComponent.Count,
         DeconstructItem = GetPhysicalItemDefinition(myComponent.DeconstructItem),
         Definition = GetPhysicalItemDefinition(myComponent.Definition),
     });
 }
Пример #5
0
        public static void GetMountedComponents(MyComponentList addToList, MyObjectBuilder_CubeBlock block)
        {
            int topGroup     = 0;
            int topComponent = 0;

            MyCubeBlockDefinition blockDef = null;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDef);
            Debug.Assert(blockDef != null, "Could not find block definition");
            if (blockDef == null)
            {
                return;
            }

            Debug.Assert(block != null, "Getting mounted components of a null block");
            if (block == null)
            {
                return;
            }

            float integrity = block.IntegrityPercent * blockDef.MaxIntegrity;

            CalculateIndicesInternal(integrity, blockDef, ref topGroup, ref topComponent);

            Debug.Assert(topGroup < blockDef.Components.Count(), "Component group overflow in CalculateItemRequirements");
            if (topGroup >= blockDef.Components.Count())
            {
                return;
            }

            Debug.Assert(topComponent < blockDef.Components[topGroup].Count, "Component overflow in CalculateItemRequirements");
            if (topComponent >= blockDef.Components[topGroup].Count)
            {
                return;
            }

            int mountCount = topComponent;

            if (integrity >= MOUNT_THRESHOLD)
            {
                mountCount++;
            }

            MyDefinitionId componentId;

            for (int group = 0; group < topGroup; ++group)
            {
                MyCubeBlockDefinition.Component component = blockDef.Components[group];
                addToList.AddMaterial(component.Definition.Id, component.Count, component.Count, addToDisplayList: false);
            }
            componentId = blockDef.Components[topGroup].Definition.Id;
            addToList.AddMaterial(componentId, mountCount, mountCount, addToDisplayList: false);
        }
Пример #6
0
        public GroupInfo GetGroupInfo(int index)
        {
            MyCubeBlockDefinition.Component component = this.m_blockDefinition.Components[index];
            GroupInfo info = new GroupInfo {
                Component      = component.Definition,
                TotalCount     = component.Count,
                MountedCount   = 0,
                AvailableCount = 0,
                Integrity      = 0f,
                MaxIntegrity   = component.Count * component.Definition.MaxIntegrity
            };

            if (index < this.m_topGroupIndex)
            {
                info.MountedCount = component.Count;
                info.Integrity    = component.Count * component.Definition.MaxIntegrity;
            }
            else if (index == this.m_topGroupIndex)
            {
                info.MountedCount = this.m_topComponentIndex + 1;
                info.Integrity    = this.GetTopComponentIntegrity() + (this.m_topComponentIndex * component.Definition.MaxIntegrity);
            }
            return(info);
        }