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


C# MyInventoryBase.Remove方法代码示例

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


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

示例1: TransferItemsFrom

        /// <summary>
        /// Transfers safely given item from inventory given as parameter to this instance.
        /// </summary>
        /// <returns>true if items were succesfully transfered, otherwise, false</returns>
        public override bool TransferItemsFrom(MyInventoryBase sourceInventory, IMyInventoryItem item, MyFixedPoint amount)
        {
            if (sourceInventory == null)
            {
                System.Diagnostics.Debug.Fail("Source inventory is null!");
                return false;
            }
            MyInventoryBase destinationInventory = this;
            if (destinationInventory == null)
            {
                System.Diagnostics.Debug.Fail("Destionation inventory is null!");
                return false;
            }
            if (item == null)
            {
                System.Diagnostics.Debug.Fail("Item is null!");
                return false;
            }
            if (amount == 0)
            {
                return true;
            }

            bool transfered = false;
            if ((destinationInventory.ItemsCanBeAdded(amount, item) || destinationInventory == sourceInventory) && sourceInventory.ItemsCanBeRemoved(amount, item))
            {
                if (Sync.IsServer)
                {
                    if (destinationInventory != sourceInventory)
                    {
                        // try to add first and then remove to ensure this items don't disappear
                        if (destinationInventory.Add(item, amount))
                        {
                            if (sourceInventory.Remove(item, amount))
                            {
                                // successfull transaction
                                return true;
                            }
                            else
                            {
                                // This can happend, that it can't be removed due to some lock, then we need to revert the add.
                                destinationInventory.Remove(item, amount);
                            }
                        }
                    }
                    else
                    {
                        // same inventory transfer = splitting amount, need to remove first and add second
                        if (sourceInventory.Remove(item, amount) && destinationInventory.Add(item, amount))
                        {
                            return true;
                        }
                        else
                        {
                            System.Diagnostics.Debug.Fail("Error! Unsuccesfull splitting!");
                        }
                    }
                }
                else
                {
                    Debug.Assert(sourceInventory != null);
                    MyInventoryTransferEventContent eventParams = new MyInventoryTransferEventContent();
                    eventParams.Amount = amount;
                    eventParams.ItemId = item.ItemId;
                    eventParams.SourceOwnerId = sourceInventory.Entity.EntityId;
                    eventParams.SourceInventoryId = sourceInventory.InventoryId;
                    eventParams.DestinationOwnerId = destinationInventory.Entity.EntityId;
                    eventParams.DestinationInventoryId = destinationInventory.InventoryId;
                    MyMultiplayer.RaiseStaticEvent(s => InventoryBaseTransferItem_Implementation, eventParams);
                }
            }

            return transfered;
        }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:78,代码来源:MyInventoryAggregate.cs


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