当前位置: 首页>>代码示例>>C#>>正文


C# MyInventoryBase.CountItems方法代码示例

本文整理汇总了C#中VRage.Game.Entity.MyInventoryBase.CountItems方法的典型用法代码示例。如果您正苦于以下问题:C# MyInventoryBase.CountItems方法的具体用法?C# MyInventoryBase.CountItems怎么用?C# MyInventoryBase.CountItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VRage.Game.Entity.MyInventoryBase的用法示例。


在下文中一共展示了MyInventoryBase.CountItems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetItemAmountCombined

        public MyFixedPoint GetItemAmountCombined(MyInventoryBase inventory, MyDefinitionId contentId)
        {
            int amount = 0;
            var group = MyDefinitionManager.Static.GetGroupForComponent(contentId, out amount);
            if (group == null)
            {
                //MyComponentSubstitutionDefinition substitutions;
                //if (MyDefinitionManager.Static.TryGetComponentSubstitutionDefinition(contentId, out substitutions))
                //{
                //    foreach (var providingComponent in substitutions.ProvidingComponents)
                //    {
                //        amount += (int)inventory.GetItemAmount(providingComponent.Key) / providingComponent.Value;
                //    }
                //}

                return amount + inventory.GetItemAmount(contentId, substitute: true);
            }
            else
            {
                Clear();
                inventory.CountItems(m_componentCounts);
                AddItem(group.Id, amount, int.MaxValue);
                Solve(m_componentCounts);
                return GetSolvedItemCount();
            }
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:26,代码来源:MyComponentCombiner.cs

示例2: CanCombineItems

        public bool CanCombineItems(MyInventoryBase inventory, DictionaryReader<MyDefinitionId, int> items)
        {
            bool result = true;

            Clear();
            inventory.CountItems(m_componentCounts);

            foreach (var item in items)
            {
                int itemValue = 0;
                int neededAmount = item.Value;

                MyComponentGroupDefinition group = null;
                group = MyDefinitionManager.Static.GetGroupForComponent(item.Key, out itemValue);
                if (group == null)
                {
                    MyFixedPoint itemAmount;

                    if (MySessionComponentEquivalency.Static != null && MySessionComponentEquivalency.Static.HasEquivalents(item.Key))
                    {
                        if (!MySessionComponentEquivalency.Static.IsProvided(m_componentCounts, item.Key, item.Value))
                        {
                            result = false;
                            break;
                        }
                    }
                    // Checking if this component is not provided by the group
                    //MyComponentSubstitutionDefinition substitutions;
                    //if (MyDefinitionManager.Static.TryGetComponentSubstitutionDefinition(item.Key, out substitutions))
                    //{
                    //    int providedAmount;
                    //    if (!substitutions.IsProvidedByComponents(m_componentCounts, out providedAmount))
                    //    {
                    //        result = false;
                    //        break;
                    //    }
                    //    else if (providedAmount < neededAmount)
                    //    {
                    //        result = false;
                    //        break;
                    //    }
                    //}
                    else if (!m_componentCounts.TryGetValue(item.Key, out itemAmount))
                    {
                        result = false;
                        break;
                    }
                    else if (itemAmount < neededAmount)
                    {
                        result = false;
                        break;
                    }
                }
                else
                {
                    AddItem(group.Id, itemValue, neededAmount);
                }
            }

            if (result)
            {
                result &= Solve(m_componentCounts);
            }

            if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW)
            {
                if (result == false)
                    MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 0.0f), "Can not build", Color.Red, 1.0f);
                else
                {
                    List<MyComponentChange> solution = null;
                    GetSolution(out solution);

                    float yCoord = 0.0f;
                    foreach (var change in solution)
                    {
                        string text = "";
                        if (change.IsAddition())
                        {
                            text += "+ " + change.Amount.ToString() + "x" + change.ToAdd.ToString();
                            MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, yCoord), text, Color.Green, 1.0f);
                            yCoord += 20.0f;
                        }
                        else if (change.IsRemoval())
                        {
                            text += "- " + change.Amount.ToString() + "x" + change.ToRemove.ToString();
                            MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, yCoord), text, Color.Red, 1.0f);
                            yCoord += 20.0f;
                        }
                        else
                        {
                            text += "- " + change.Amount.ToString() + "x" + change.ToRemove.ToString();
                            MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, yCoord), text, Color.Orange, 1.0f);
                            yCoord += 20.0f;

                            text = "";
                            text += "+ " + change.Amount.ToString() + "x" + change.ToAdd.ToString();
                            MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, yCoord), text, Color.Orange, 1.0f);
                            yCoord += 20.0f;
                        }
//.........这里部分代码省略.........
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:101,代码来源:MyComponentCombiner.cs

示例3: RemoveItemsCombined

        public void RemoveItemsCombined(MyInventoryBase inventory, DictionaryReader<MyDefinitionId, int> toRemove)
        {
            Clear();
            foreach (var material in toRemove) // rename material to component
            {
                int groupAmount = 0;
                MyComponentGroupDefinition group = MyDefinitionManager.Static.GetGroupForComponent(material.Key, out groupAmount);

                // The component does not belong to any component group => we are looking exactly for the given component
                if (group == null)
                {
                    if (MySessionComponentEquivalency.Static != null && MySessionComponentEquivalency.Static.HasEquivalents(material.Key))
                    {
                        var eqGroup = MySessionComponentEquivalency.Static.GetEquivalents(material.Key);
                        if (eqGroup != null)
                        {
                            int amountToRemove = material.Value;
                            foreach (var element in eqGroup)
                            {
                                if (amountToRemove > 0)
                                {
                                    var removed = inventory.RemoveItemsOfType(amountToRemove, element);
                                    amountToRemove -= (int)removed;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        inventory.RemoveItemsOfType(material.Value, material.Key);
                        continue;
                    }


                    //MyComponentSubstitutionDefinition substitutionDefinition = null;
                    //if (MyDefinitionManager.Static.TryGetComponentSubstitutionDefinition(material.Key, out substitutionDefinition))
                    //{
                    //    int amountToRemove = material.Value;
                    //    foreach (var entry in substitutionDefinition.ProvidingComponents)
                    //    {
                    //        if (amountToRemove > 0)
                    //        {
                    //            var removed = inventory.RemoveItemsOfType(amountToRemove * entry.Value, entry.Key);
                    //            amountToRemove -= (int)removed;
                    //        }
                    //        else
                    //        {
                    //            break;
                    //        }
                    //    }

                    //    if (amountToRemove > 0)
                    //    {
                    //        var removed = inventory.RemoveItemsOfType(amountToRemove, material.Key);
                    //        amountToRemove -= (int)removed;
                    //    }
                    //}
                    //else
                    //{
                    //    inventory.RemoveItemsOfType(material.Value, material.Key);
                    //    continue;
                    //}
                }
                else
                {
                    AddItem(group.Id, groupAmount, material.Value);
                }
            }

            inventory.CountItems(m_componentCounts);
            bool success = Solve(m_componentCounts);
            Debug.Assert(success, "Could not combine required items!");

            inventory.ApplyChanges(m_solution);

            /*CheckUpdate();

            m_remainder.Clear();
            foreach (var material in toRemove)
            {
                m_remainder.Add(material.Key, material.Value);
            }

            bool success = true;

            m_cuttingSolver.Clear();
            foreach (var material in m_remainder)
            {
                int groupAmount = 0;
                MyComponentGroupDefinition group = MyDefinitionManager.Static.GetGroupForComponent(material.Key, out groupAmount);

                // The component does not belong to any component group => we are looking exactly for the given component
                if (group == null)
                {
                    success &= RemoveItemsOfTypeInternal(material.Key, material.Value);
                    Debug.Assert(success, "Could not find the required component although we were permitted to build!");
//.........这里部分代码省略.........
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:101,代码来源:MyComponentCombiner.cs


注:本文中的VRage.Game.Entity.MyInventoryBase.CountItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。