本文整理汇总了C#中MyInventory.ComputeAmountThatFits方法的典型用法代码示例。如果您正苦于以下问题:C# MyInventory.ComputeAmountThatFits方法的具体用法?C# MyInventory.ComputeAmountThatFits怎么用?C# MyInventory.ComputeAmountThatFits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyInventory
的用法示例。
在下文中一共展示了MyInventory.ComputeAmountThatFits方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveItemsFromConstructionStockpile
/// <summary>
/// Moves items with the given flags from the construction inventory to the character.
/// If the flags are None, all items are moved.
/// </summary>
public void MoveItemsFromConstructionStockpile(MyInventory toInventory, MyItemFlags flags = MyItemFlags.None)
{
if (m_stockpile == null) return;
Debug.Assert(toInventory != null);
if (toInventory == null) return;
m_tmpItemList.Clear();
foreach (var item in m_stockpile.GetItems())
{
if (flags == MyItemFlags.None || (item.Content.Flags & flags) != 0)
m_tmpItemList.Add(item);
}
m_stockpile.ClearSyncList();
foreach (var item in m_tmpItemList)
{
var amount = (int)toInventory.ComputeAmountThatFits(item.Content.GetId());
amount = Math.Min(amount, item.Amount);
toInventory.AddItems(amount, item.Content);
m_stockpile.RemoveItems(amount, item.Content);
}
CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
m_stockpile.ClearSyncList();
}
示例2: MoveUnneededItemsFromConstructionStockpile
public void MoveUnneededItemsFromConstructionStockpile(MyInventory toInventory)
{
if (m_stockpile == null) return;
Debug.Assert(toInventory != null);
if (toInventory == null) return;
m_tmpItemList.Clear();
AcquireUnneededStockpileItems(m_tmpItemList);
m_stockpile.ClearSyncList();
foreach (var item in m_tmpItemList)
{
var amount = (int)toInventory.ComputeAmountThatFits(item.Content.GetId());
amount = Math.Min(amount, item.Amount);
toInventory.AddItems(amount, item.Content);
m_stockpile.RemoveItems(amount, item.Content);
}
CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
m_stockpile.ClearSyncList();
}
示例3: FixTransferAmount
private static void FixTransferAmount(MyInventory src, MyInventory dst, MyInventoryItem? srcItem, bool spawn, ref MyFixedPoint remove, ref MyFixedPoint add)
{
Debug.Assert(Sync.IsServer);
if (srcItem.Value.Amount < remove)
{
remove = srcItem.Value.Amount;
add = remove;
}
if (!MySession.Static.CreativeMode && !src.Equals(dst))
{
MyFixedPoint space = dst.ComputeAmountThatFits(srcItem.Value.Content.GetId());
if (space < remove)
{
if (spawn)
{
MyEntity e = (dst.Owner as MyEntity);
Matrix m = e.WorldMatrix;
MyFloatingObjects.Spawn(new MyInventoryItem(remove - space, srcItem.Value.Content), e.PositionComp.GetPosition() + m.Forward + m.Up, m.Forward, m.Up, e.Physics);
}
else
{
remove = space;
}
add = space;
}
}
}
示例4: ComputeFloatingObjectAmount
private static bool ComputeFloatingObjectAmount(MyFloatingObject obj, ref MyFixedPoint amount, MyInventory inv)
{
amount = obj.Item.Amount;
if (!MySession.Static.CreativeMode)
amount = MyFixedPoint.Min(amount, inv.ComputeAmountThatFits(obj.Item.Content.GetId()));
if (amount <= 0) // does not fit into inventory
return false;
return true;
}
示例5: ItemPullAll
private static bool ItemPullAll(IMyConveyorEndpointBlock start, MyInventory destinationInventory)
{
MyCubeBlock startingBlock = start as MyCubeBlock;
if (startingBlock == null) return false;
bool itemsPulled = false;
// Try and get the block from the cache
MyGridConveyorSystem conveyorSystem = startingBlock.CubeGrid.GridSystems.ConveyorSystem;
MyGridConveyorSystem.ConveyorEndpointMapping endpoints = conveyorSystem.GetConveyorEndpointMapping(start);
if (endpoints.pullElements != null)
{
// Iterate to the other elements, see if we can collect some amount of items to pull
for (int i = 0; i < endpoints.pullElements.Count; i++)
{
MyCubeBlock sourceBlock = endpoints.pullElements[i] as MyCubeBlock;
if (sourceBlock == null) continue;
int inventoryCount = sourceBlock.InventoryCount;
for (int inventoryIndex = 0; inventoryIndex < inventoryCount; inventoryIndex++)
{
MyInventory inventory = sourceBlock.GetInventory(inventoryIndex);
if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
continue;
if (inventory == destinationInventory)
continue;
var items = inventory.GetItems().ToArray();
for (int itemIndex = 0; itemIndex < items.Length; itemIndex++)
{
var item = items[itemIndex];
var itemId = item.GetDefinitionId();
var amountThatFits = destinationInventory.ComputeAmountThatFits(itemId);
if (amountThatFits <= 0)
continue;
// Verify that this item can, in fact, make it past sorters, etc
if (!CanTransfer(start, endpoints.pullElements[i], itemId, false))
continue;
var availableAmount = inventory.GetItemAmount(itemId);
var transferAmount = MyFixedPoint.Min(availableAmount, amountThatFits);
MyInventory.Transfer(inventory, destinationInventory, itemId, MyItemFlags.None, transferAmount);
itemsPulled = true;
if (destinationInventory.CargoPercentage >= 0.99f)
break;
}
if (destinationInventory.CargoPercentage >= 0.99f)
break;
}
if (destinationInventory.CargoPercentage >= 0.99f)
break;
}
}
else
{
// Cache may need to be recomputed
if (!conveyorSystem.m_isRecomputingGraph)
conveyorSystem.RecomputeConveyorEndpoints();
}
return itemsPulled;
}
示例6: PullAllRequest
public static bool PullAllRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyInventoryConstraint requestedTypeIds)
{
MyCubeBlock startingBlock = start as MyCubeBlock;
if (startingBlock == null) return false;
m_tmpRequestedItemSet.Set(requestedTypeIds);
// Try and get the block from the cache
MyGridConveyorSystem conveyorSystem = startingBlock.CubeGrid.GridSystems.ConveyorSystem;
MyGridConveyorSystem.ConveyorEndpointMapping endpoints = conveyorSystem.GetConveyorEndpointMapping(start);
if (endpoints.pullElements != null)
{
bool didTransfer = false;
// Iterate to the other elements, see if we can collect some amount of items to pull
for (int i = 0; i < endpoints.pullElements.Count; i++)
{
MyCubeBlock sourceBlock = endpoints.pullElements[i] as MyCubeBlock;
if (sourceBlock == null) continue;
int inventoryCount = sourceBlock.InventoryCount;
for (int inventoryIndex = 0; inventoryIndex < inventoryCount; inventoryIndex++)
{
MyInventory inventory = sourceBlock.GetInventory(inventoryIndex);
if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
continue;
if (inventory == destinationInventory)
continue;
m_tmpInventoryItems.Clear();
foreach (var item in inventory.GetItems())
{
m_tmpInventoryItems.Add(item);
}
foreach (var item in m_tmpInventoryItems)
{
if (destinationInventory.VolumeFillFactor >= 1.0f)
{
m_tmpInventoryItems.Clear();
return true;
}
var itemId = item.Content.GetId();
if (requestedTypeIds != null && !m_tmpRequestedItemSet.Contains(itemId))
continue;
// Verify that this item can, in fact, make it past sorters, etc
if (!CanTransfer(start, endpoints.pullElements[i], itemId, false))
continue;
var transferedAmount = item.Amount;
var oxygenBottle = item.Content as Sandbox.Common.ObjectBuilders.Definitions.MyObjectBuilder_GasContainerObject;
if (oxygenBottle != null && oxygenBottle.GasLevel >= 1f)
continue;
if (!MySession.Static.CreativeMode)
{
var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
{
fittingAmount = MyFixedPoint.Floor(fittingAmount);
}
transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);
}
if (transferedAmount == 0)
continue;
didTransfer = true;
MyInventory.Transfer(inventory, destinationInventory, item.Content.GetId(), MyItemFlags.None, transferedAmount);
if (destinationInventory.CargoPercentage >= 0.99f)
break;
}
if (destinationInventory.CargoPercentage >= 0.99f)
break;
}
if (destinationInventory.CargoPercentage >= 0.99f)
break;
}
return didTransfer;
}
else
{
// Cache may need to be recomputed
if (!conveyorSystem.m_isRecomputingGraph)
conveyorSystem.RecomputeConveyorEndpoints();
}
return false;
}
示例7: ItemPullAllInternal
private static void ItemPullAllInternal(MyInventory destinationInventory, PullRequestItemSet requestedTypeIds, bool onlySmall)
{
SetTraversalInventoryItemDefinitionId();
Debug.Assert(m_tmpPullRequests.Count == 0, "m_tmpPullRequests is not empty!");
using (var invertedConductivity = new MyConveyorLine.InvertedConductivity())
{
foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding)
{
IMyInventoryOwner owner = conveyorEndpoint.CubeBlock as IMyInventoryOwner;
if (owner == null) continue;
for (int i = 0; i < owner.InventoryCount; ++i)
{
var inventory = owner.GetInventory(i);
if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
continue;
if (inventory == destinationInventory)
continue;
m_tmpInventoryItems.Clear();
foreach (var item in inventory.GetItems())
{
m_tmpInventoryItems.Add(item);
}
foreach (var item in m_tmpInventoryItems)
{
if (destinationInventory.VolumeFillFactor >= 1.0f)
{
m_tmpInventoryItems.Clear();
return;
}
var itemId = item.Content.GetId();
if (requestedTypeIds != null && !requestedTypeIds.Contains(itemId))
continue;
if (onlySmall && NeedsLargeTube(itemId))
continue;
var transferedAmount = item.Amount;
var oxygenBottle = item.Content as Sandbox.Common.ObjectBuilders.Definitions.MyObjectBuilder_OxygenContainerObject;
if (oxygenBottle != null && oxygenBottle.OxygenLevel == 1f)
continue;
if (!MySession.Static.CreativeMode)
{
var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
{
fittingAmount = MyFixedPoint.Floor(fittingAmount);
}
transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);
}
if (transferedAmount == 0)
continue;
// SK: this is mental
m_tmpPullRequests.Add(new MyTuple<IMyConveyorEndpointBlock, MyPhysicalInventoryItem>(m_startingEndpoint.CubeBlock as IMyConveyorEndpointBlock, item));
//MyInventory.Transfer(inventory, destinationInventory, item.Content.GetId(), MyItemFlags.None, transferedAmount);
}
}
}
}
foreach (var tuple in m_tmpPullRequests)
{
if (destinationInventory.VolumeFillFactor >= 1.0f)
{
m_tmpPullRequests.Clear();
return;
}
var start = tuple.Item1;
var item = tuple.Item2;
var transferedAmount = item.Amount;
var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
{
fittingAmount = MyFixedPoint.Floor(fittingAmount);
}
transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);
if (transferedAmount == 0)
continue;
var itemId = item.Content.GetId();
SetTraversalInventoryItemDefinitionId(itemId);
ItemPullRequest(start, destinationInventory, m_playerIdForAccessiblePredicate, itemId, transferedAmount);
}
m_tmpPullRequests.Clear();
}