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


C# InventoryManager.RemoveItems方法代码示例

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


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

示例1: Run

        private static long _tickThreashold = 3; //number of ticks before output is generated //TODO:  SAMPLE VALUE, also wrong type, a tick is not a long

        #endregion Fields

        #region Methods

        //TODO: decide the best way to pass back errors
        public static void Run(InventoryManager inventory, BuildingItem item, long ticks)
        {
            for (long tick = item.CurrentTicks; tick == _tickThreashold; tick++) //TODO: loop through ticks
            {
                if (HasEnoughEnergy())
                {
                    //consumablematerials = KeyValuePair<ItemTypeBase, long>
                    foreach (KeyValuePair<ItemTypeBase, long> consumable in ((BuildingItemType)item.ItemType).ConsumableMaterials)
                    {
                        //first pass - make sure inventory has enough of everything needed for this building
                        if (!inventory.HasEnoughItems(consumable.Key, consumable.Value))
                        {
                            break; //throw?
                        }
                    }

                    //all necessary input is available in inventory, so subtract it for this pass.
                    foreach (KeyValuePair<ItemTypeBase, long> consumable in ((BuildingItemType)item.ItemType).ConsumableMaterials)
                    {
                        inventory.RemoveItems(consumable.Key, consumable.Value);
                    }

                    //if this process has run the necessary number of ticks
                    if (item.CurrentTicks == _tickThreashold)
                    {
                        foreach (KeyValuePair<ItemTypeBase, long> output in ((BuildingItemType)item.ItemType).OutputMaterials)
                        {
                            inventory.AddItems(output.Key, output.Value);
                        }
                        item.ResetCurrentTicks();
                    }
                    else
                    {
                        item.IncrementCurrentTicks();
                    }
                }
            }
        }
开发者ID:NaterTots,项目名称:NasaChallenge,代码行数:45,代码来源:BuildingProductionRule.cs


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