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


C# Entity.MyInventoryBase类代码示例

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


MyInventoryBase类属于VRage.Game.Entity命名空间,在下文中一共展示了MyInventoryBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: RemoveItemsCombined

 protected internal void RemoveItemsCombined(MyInventoryBase inventory, int itemAmount, MyDefinitionId itemDefinitionId)
 {
     m_materialListCombined.Clear();
     m_materialListCombined.AddMaterial(itemDefinitionId, itemAmount);
     m_componentCombiner.RemoveItemsCombined(inventory, m_materialListCombined.TotalMaterials);
     m_materialListCombined.Clear();
     return;
 }
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:8,代码来源:MyBuildComponentBase.cs

示例3: InventoryChanged

 void InventoryChanged(MyInventoryBase obj)
 {
     if (m_clientInventoryUpdate == null)
     {
         return;
     }
     foreach (var clientData in m_clientInventoryUpdate)
     {
         m_clientInventoryUpdate[clientData.Key].Dirty = true;
     }
 }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:11,代码来源:MyEntityInventoryStateGroup.cs

示例4: OnBeforeInventoryRemovedFromAggregate

 protected override void OnBeforeInventoryRemovedFromAggregate(Inventory.MyInventoryAggregate aggregate, MyInventoryBase inventory)
 {                        
     if (inventory == InputInventory)
     {
         InputInventory.ContentsChanged += inventory_OnContentsChanged;
     }
     else if (inventory == OutputInventory)
     {
         OutputInventory.ContentsChanged += inventory_OnContentsChanged;
     }
     else
     {
         Debug.Fail("Added inventory to aggregate, but not input or output invenoty?! This shouldn't happen.");
     }
     base.OnBeforeInventoryRemovedFromAggregate(aggregate, inventory); // Base method needs to be called here, cuz it removes the inventories from properties
 }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:16,代码来源:MyRefinery.cs

示例5: PasteGrid

 public virtual bool PasteGrid(MyInventoryBase buildInventory = null, bool deactivate = true)
 {
     return PasteGridInternal(buildInventory, deactivate, touchingGrids: m_touchingGrids);
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:4,代码来源:MyGridClipboard.cs

示例6: ShowAggregateInventoryScreen

 public MyGuiScreenBase ShowAggregateInventoryScreen(MyInventoryBase rightSelectedInventory = null)
 {
     if (MyPerGameSettings.GUI.InventoryScreen != null)
     {
         if (InventoryAggregate != null)
         {
             InventoryAggregate.Init();
             m_InventoryScreen = MyGuiSandbox.CreateScreen(MyPerGameSettings.GUI.InventoryScreen, InventoryAggregate, rightSelectedInventory);
             MyGuiSandbox.AddScreen(m_InventoryScreen);
             m_InventoryScreen.Closed += (scr) => { if (InventoryAggregate != null) { InventoryAggregate.DetachCallbacks(); } m_InventoryScreen = null; };
         }
     }
     return m_InventoryScreen;
 }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:14,代码来源:MyCharacter.cs

示例7: DecreaseMountLevelToDesiredRatio

        public void DecreaseMountLevelToDesiredRatio(float desiredIntegrityRatio, MyInventoryBase outputInventory)
        {
            float desiredIntegrity = desiredIntegrityRatio * MaxIntegrity;
            float grinderAmount = Integrity - desiredIntegrity;
            Debug.Assert(grinderAmount >= 0f);
            if (grinderAmount <= 0f)
                return;

            if (FatBlock != null)
                grinderAmount *= FatBlock.DisassembleRatio;
            else
                grinderAmount *= BlockDefinition.DisassembleRatio;

            DecreaseMountLevel(grinderAmount / BlockDefinition.IntegrityPointsPerSec, outputInventory, useDefaultDeconstructEfficiency: true);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:15,代码来源:MySlimBlock.cs

示例8: 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

示例9: TryGetInventory

        // ----------- inventory --------------------

        public static bool TryGetInventory(this MyEntity thisEntity, out MyInventoryBase inventoryBase)
        {
            inventoryBase = null;
            return thisEntity.Components.TryGet<MyInventoryBase>(out inventoryBase);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:7,代码来源:MyEntityExtensions.cs

示例10: MoveItemsToConstructionStockpile

        public void MoveItemsToConstructionStockpile(MyInventoryBase fromInventory)
        {
            if (MySession.Static.CreativeMode)
                return;

            m_tmpComponents.Clear();
            GetMissingComponents(m_tmpComponents);

            if (m_tmpComponents.Count != 0)
            {
                EnsureConstructionStockpileExists();

                m_stockpile.ClearSyncList();
                foreach (var kv in m_tmpComponents)
                {
                    var id = new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key);
                    int amountAvailable = (int)MyCubeBuilder.BuildComponent.GetItemAmountCombined(fromInventory, id);
                    int moveAmount = Math.Min(kv.Value, amountAvailable);
                    if (moveAmount > 0)
                    {
                        MyCubeBuilder.BuildComponent.RemoveItemsCombined(fromInventory, moveAmount, id);
                        m_stockpile.AddItems((int)moveAmount, new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key));
                    }
                }
                CubeGrid.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:28,代码来源:MySlimBlock.cs

示例11: AddBlockComponent

        private static void AddBlockComponent(MyHudBlockInfo hudInfo, MyComponentStack.GroupInfo groupInfo, MyInventoryBase availableInventory)
        {
            var componentInfo = new MyHudBlockInfo.ComponentInfo();
            componentInfo.DefinitionId = groupInfo.Component.Id;
            componentInfo.ComponentName = groupInfo.Component.DisplayNameText;
            componentInfo.Icons = groupInfo.Component.Icons;
            componentInfo.TotalCount = groupInfo.TotalCount;
            componentInfo.MountedCount = groupInfo.MountedCount;
            if (availableInventory != null)
                componentInfo.AvailableAmount = (int)MyCubeBuilder.BuildComponent.GetItemAmountCombined(availableInventory, groupInfo.Component.Id);

            hudInfo.Components.Add(componentInfo);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:13,代码来源:MySlimBlock.cs

示例12: SetBlockComponentsInternal

        // CH: TODO: This method actually doesn't have a bad internal structure, but it should be refactored BIG TIME (and put to MyHudBlockInfo)!
        private static void SetBlockComponentsInternal(MyHudBlockInfo hudInfo, MyCubeBlockDefinition blockDefinition, MySlimBlock block, MyInventoryBase availableInventory)
        {
            hudInfo.Components.Clear();

            if (block != null)
            {
                Debug.Assert(block.BlockDefinition == blockDefinition, "The definition given to SetBlockComponnentsInternal was not a definition of the block");
            }

            hudInfo.InitBlockInfo(blockDefinition);
            hudInfo.ShowAvailable = MyPerGameSettings.AlwaysShowAvailableBlocksOnHud;

            if (!MyFakes.ENABLE_SMALL_GRID_BLOCK_COMPONENT_INFO && blockDefinition.CubeSize == MyCubeSize.Small) return;

            if (block != null)
            {
                hudInfo.BlockIntegrity = block.Integrity / block.MaxIntegrity;
            }

            // CH: TODO: Multiblocks
            if (block != null && block.IsMultiBlockPart)
            {
                var multiBlockInfo = block.CubeGrid.GetMultiBlockInfo(block.MultiBlockId);
                Debug.Assert(multiBlockInfo != null);
                if (multiBlockInfo != null)
                {
                    // Load all block definition components
                    foreach (var blockDefId in multiBlockInfo.MultiBlockDefinition.BlockDefinitions) 
                    {
                        MyCubeBlockDefinition blockDef;
                        if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(blockDefId.Id, out blockDef))
                        {
                            hudInfo.AddComponentsForBlock(blockDef);
                        }
                    }

                    // Merge components from all blocks
                    hudInfo.MergeSameComponents();

                    // Add mounted counts to components
                    foreach (var multiBlockPart in multiBlockInfo.Blocks)
                    {
                        for (int j = 0; j < multiBlockPart.BlockDefinition.Components.Length; ++j)
                        {
                            var comp = multiBlockPart.BlockDefinition.Components[j];
                            var groupInfo = multiBlockPart.ComponentStack.GetGroupInfo(j);

                            for (int i = 0; i < hudInfo.Components.Count; i++)
                            {
                                if (hudInfo.Components[i].DefinitionId == comp.Definition.Id)
                                {
                                    var c = hudInfo.Components[i];
                                    c.MountedCount += groupInfo.MountedCount;
                                    hudInfo.Components[i] = c;
                                    break;
                                }
                            }
                        }
                    }

                    // Inventory counts
                    for (int i = 0; i < hudInfo.Components.Count; i++)
                    {
                        if (availableInventory != null)
                        {
                            var c = hudInfo.Components[i];
                            c.AvailableAmount = (int)MyCubeBuilder.BuildComponent.GetItemAmountCombined(availableInventory, c.DefinitionId);
                            hudInfo.Components[i] = c;
                        }

                        // Get amount in stockpile
                        int amount = 0;
                        foreach (var multiBlockPart in multiBlockInfo.Blocks)
                        {
                            if (!multiBlockPart.StockpileEmpty)
                                amount += multiBlockPart.GetConstructionStockpileItemAmount(hudInfo.Components[i].DefinitionId);
                        }

                        if (amount > 0)
                        {
                            //RKTODO: ??? see below code for non multiblocks
                            /*amount =*/ SetHudInfoComponentAmount(hudInfo, amount, i);
                        }
                    }
                }
            }
            else if (block == null && blockDefinition.MultiBlock != null)
            {
                MyDefinitionId defId = new MyDefinitionId(typeof(MyObjectBuilder_MultiBlockDefinition), blockDefinition.MultiBlock);
                var mbDefinition = MyDefinitionManager.Static.TryGetMultiBlockDefinition(defId);
                if (mbDefinition != null)
                {
                    foreach (var blockDefId in mbDefinition.BlockDefinitions)
                    {
                        MyCubeBlockDefinition blockDef;
                        if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(blockDefId.Id, out blockDef))
                        {
                            hudInfo.AddComponentsForBlock(blockDef);
                        }
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:101,代码来源:MySlimBlock.cs

示例13: SetBlockComponents

 public static void SetBlockComponents(MyHudBlockInfo hudInfo, MyCubeBlockDefinition blockDefinition, MyInventoryBase availableInventory = null)
 {
     SetBlockComponentsInternal(hudInfo, blockDefinition, null, availableInventory);
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:4,代码来源:MySlimBlock.cs

示例14: DeconstructStockpile

        private void DeconstructStockpile(float deconstructAmount, MyInventoryBase outputInventory, bool useDefaultDeconstructEfficiency = false)
        {
            Debug.Assert(Sync.IsServer, "This method is only meant to be called on the server!");
            if (MySession.Static.CreativeMode)
            {
                ClearConstructionStockpile(outputInventory);
            }
            else
            {
                EnsureConstructionStockpileExists();
            }

            if (m_stockpile != null)
            {
                m_stockpile.ClearSyncList();
                m_componentStack.DecreaseMountLevel(deconstructAmount, m_stockpile, useDefaultDeconstructEfficiency: useDefaultDeconstructEfficiency);
                CubeGrid.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
            else
            {
                m_componentStack.DecreaseMountLevel(deconstructAmount, null, useDefaultDeconstructEfficiency: useDefaultDeconstructEfficiency);
            }
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:24,代码来源:MySlimBlock.cs

示例15: DecreaseMountLevel

        public void DecreaseMountLevel(float grinderAmount, MyInventoryBase outputInventory, bool useDefaultDeconstructEfficiency = false)
        {
            Debug.Assert(Sync.IsServer, "This method is only meant to be called on the server!");
            if (!Sync.IsServer||m_componentStack.IsFullyDismounted)
                return;

            if (FatBlock != null)
                grinderAmount /= FatBlock.DisassembleRatio;
            else
                grinderAmount /= BlockDefinition.DisassembleRatio;

            grinderAmount = grinderAmount * BlockDefinition.IntegrityPointsPerSec;
            float oldBuildRatio = m_componentStack.BuildRatio;
            DeconstructStockpile(grinderAmount, outputInventory, useDefaultDeconstructEfficiency: useDefaultDeconstructEfficiency);

            float newBuildRatio = (BuildIntegrity - grinderAmount) / BlockDefinition.MaxIntegrity;

            //Call Integrity Changed if owner is nobody or is not local player
            if (BlockDefinition.RatioEnoughForDamageEffect(BuildLevelRatio))
            {
                if (FatBlock != null && FatBlock.OwnerId != 0 && FatBlock.OwnerId != MySession.Static.LocalPlayerId)
                {
                    FatBlock.OnIntegrityChanged(BuildIntegrity, Integrity, false, MySession.Static.LocalPlayerId);
                }
            }

            long toolOwner = 0;
            if (outputInventory != null && outputInventory.Entity != null)
            {
                var inventoryOwner = outputInventory.Entity;
                var moduleOwner = inventoryOwner as IMyComponentOwner<MyIDModule>;
                var character = inventoryOwner as MyCharacter;
                if (moduleOwner == null)
                {
                    if (character != null)
                    {
                        Debug.Assert(character.ControllerInfo.Controller != null, "Controller was null on the character in DecreaseMountLevel!");
                        if (character.ControllerInfo.Controller == null)
                            toolOwner = character.ControllerInfo.ControllingIdentityId;
                    }
                }
                else
                {
                    MyIDModule module;
                    if (moduleOwner.GetComponent(out module))
                        toolOwner = module.Owner;
                }
            }

            UpdateHackingIndicator(newBuildRatio, oldBuildRatio, toolOwner);

            bool modelChangeNeeded = BlockDefinition.ModelChangeIsNeeded(m_componentStack.BuildRatio, oldBuildRatio);

            MyIntegrityChangeEnum integrityChangeType = MyIntegrityChangeEnum.Damage;
            if (modelChangeNeeded)
            {
                UpdateVisual();

                if (FatBlock != null)
                {
                    int buildProgressID = CalculateCurrentModelID();
                    if ((buildProgressID == -1) || (BuildLevelRatio == 0f))
                    {
                        integrityChangeType = MyIntegrityChangeEnum.ConstructionEnd;
                    }
                    else if (buildProgressID == BlockDefinition.BuildProgressModels.Length - 1)
                    {
                        integrityChangeType = MyIntegrityChangeEnum.ConstructionBegin;
                    }
                    else
                    {
                        integrityChangeType = MyIntegrityChangeEnum.ConstructionProcess;
                    }
                }

                PlayConstructionSound(integrityChangeType, true);
                CreateConstructionSmokes();
            }

            if (CubeGrid.GridSystems.GasSystem != null)
            {
                CubeGrid.GridSystems.GasSystem.Pressurize();
            }

            if (MyFakes.ENABLE_GENERATED_BLOCKS && !BlockDefinition.IsGeneratedBlock && BlockDefinition.GeneratedBlockDefinitions != null && BlockDefinition.GeneratedBlockDefinitions.Length > 0)
            {
                UpdateProgressGeneratedBlocks(oldBuildRatio);
            }

            CubeGrid.SendIntegrityChanged(this, integrityChangeType, toolOwner);
            CubeGrid.OnIntegrityChanged(this);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:92,代码来源:MySlimBlock.cs


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