本文整理汇总了C#中InventoryManager.HasEnoughItems方法的典型用法代码示例。如果您正苦于以下问题:C# InventoryManager.HasEnoughItems方法的具体用法?C# InventoryManager.HasEnoughItems怎么用?C# InventoryManager.HasEnoughItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InventoryManager
的用法示例。
在下文中一共展示了InventoryManager.HasEnoughItems方法的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();
}
}
}
}