public bool ContainItems(MyFixedPoint?amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { int?itemPos = FindFirstPositionOfType(contentId, flags); if (!itemPos.HasValue) { return(false); } int i = itemPos.Value; MyFixedPoint amountPresent = m_items[i].Amount; if (!amount.HasValue || amountPresent >= amount) { return(true); } for (i++; i < m_items.Count; ++i) { var content = m_items[i].Content; if (contentId == content.GetObjectId() && flags == content.Flags) { amountPresent += m_items[i].Amount; } } return(amountPresent >= amount); }
public virtual bool CanStack(string typeId, string subtypeId, MyItemFlags flags) { if (flags == Flags && typeId == TypeId && subtypeId == SubtypeId) { return(true); } return(false); }
public override MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { float amount = 0; foreach (MyInventoryBase inventory in m_children.Reader) { amount += (float)inventory.GetItemAmount(contentId, flags); } return((MyFixedPoint)amount); }
public override MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = 0, bool substitute = false) { float num = 0f; foreach (MyInventoryBase base2 in this.m_children.Reader) { num += (float)base2.GetItemAmount(contentId, flags, substitute); } return((MyFixedPoint)num); }
public virtual bool CanStack(MyObjectBuilderType typeId, MyStringId subtypeId, MyItemFlags flags) { if (flags == Flags && typeId == TypeId && subtypeId == SubtypeId) { return true; } return false; }
public int GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { foreach (var item in m_items) { if (item.Content.CanStack(contentId.TypeId, contentId.SubtypeId, flags)) { return(item.Amount); } } return(0); }
public bool AddItems(int count, MyDefinitionId contentId, MyItemFlags flags = 0) { MyObjectBuilder_PhysicalObject physicalObject = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject((SerializableDefinitionId)contentId); if (physicalObject == null) { return(false); } physicalObject.Flags = flags; return(this.AddItems(count, physicalObject)); }
private int? FindFirstPositionOfType(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { for (int i = 0; i < m_items.Count; ++i) { var content = m_items[i].Content; if (content.GetObjectId() == contentId && content.Flags == flags) return i; } return null; }
public bool RemoveItems(int count, MyDefinitionId id, MyItemFlags flags = 0) { int index = 0; using (List <MyStockpileItem> .Enumerator enumerator = this.m_items.GetEnumerator()) { while (enumerator.MoveNext() && !enumerator.Current.Content.CanStack(id.TypeId, id.SubtypeId, flags)) { index++; } } return(this.RemoveItemsInternal(index, count)); }
public bool AddItems(int count, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { var componentBuilder = (MyObjectBuilder_PhysicalObject)Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(contentId); Debug.Assert(componentBuilder != null, "Could not cast object builder to physical object"); if (componentBuilder == null) { return(false); } componentBuilder.Flags = flags; return(AddItems(count, componentBuilder)); }
public bool RemoveItems(int count, MyDefinitionId id, MyItemFlags flags = MyItemFlags.None) { int index = 0; foreach (var item in m_items) { if (item.Content.CanStack(id.TypeId, id.SubtypeId, flags)) { break; } index++; } return(RemoveItemsInternal(index, count)); }
public override MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { MyFixedPoint amount = 0; foreach (var item in m_items) { if (item.Content.GetObjectId() == contentId && item.Content.Flags == flags) { amount += item.Amount; } } return(amount); }
public override MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { MyFixedPoint amount = 0; foreach (var item in m_items) { var objectId = item.Content.GetObjectId(); if (contentId != objectId && item.Content.TypeId == typeof(MyObjectBuilder_BlockItem)) { objectId = MyDefinitionManager.Static.GetComponentId(item.Content.GetObjectId()); } if (objectId == contentId && item.Content.Flags == flags) amount += item.Amount; } return amount; }
public int GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = 0) { using (List <MyStockpileItem> .Enumerator enumerator = this.m_items.GetEnumerator()) { while (true) { if (!enumerator.MoveNext()) { break; } MyStockpileItem current = enumerator.Current; if (current.Content.CanStack(contentId.TypeId, contentId.SubtypeId, flags)) { return(current.Amount); } } } return(0); }
public abstract MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool substitute = false);
public abstract MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None);
public bool RemoveItems(int count, MyDefinitionId id, MyItemFlags flags = MyItemFlags.None) { int index = 0; foreach (var item in m_items) { if (item.Content.CanStack(id.TypeId, id.SubtypeId, flags)) break; index++; } return RemoveItemsInternal(index, count); }
void IMySlimBlock.MoveItemsFromConstructionStockpile(IMyInventory toInventory, MyItemFlags flags) { MoveItemsFromConstructionStockpile(toInventory as MyInventory, flags); }
void VRage.Game.ModAPI.IMyInventory.RemoveItemsOfType(VRage.MyFixedPoint amount, SerializableDefinitionId contentId, MyItemFlags flags, bool spawn) { RemoveItemsOfType(amount, contentId, flags, spawn); }
public override void RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool spawn = false) { var restAmount = amount; foreach (MyInventoryBase inventory in m_children.Reader) { var contains = inventory.GetItemAmount(contentId, flags); if (contains > restAmount) { contains = restAmount; } if (contains > 0) { inventory.RemoveItemsOfType(contains, contentId, flags, spawn); } restAmount -= contains; } }
public override bool CanStack(MyObjectBuilderType type, MyStringId subtypeId, MyItemFlags flags) { return false; // weapons shouldn't stack }
public override MyFixedPoint RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool spawn = false) { return TransferOrRemove(this, amount, contentId, flags, null, spawn, onlyWhole: false); }
public MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { MyFixedPoint amount = 0; foreach (var item in m_items) { if (item.Content.GetObjectId() == contentId && item.Content.Flags == flags) amount += item.Amount; } return amount; }
public bool ContainItems(MyFixedPoint? amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { MyFixedPoint amountPresent = GetItemAmount(contentId, flags); return amountPresent >= amount; }
public bool ContainItems(MyFixedPoint? amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { int? itemPos = FindFirstPositionOfType(contentId, flags); if (!itemPos.HasValue) return false; int i = itemPos.Value; MyFixedPoint amountPresent = m_items[i].Amount; if (!amount.HasValue || amountPresent >= amount) return true; for (i++; i < m_items.Count; ++i) { var content = m_items[i].Content; if (contentId == content.GetObjectId() && flags == content.Flags) { amountPresent += m_items[i].Amount; } } return amountPresent >= amount; }
public override MyFixedPoint RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool spawn = false) { var restAmount = amount; foreach (MyInventoryBase inventory in m_children.Reader) { restAmount -= inventory.RemoveItemsOfType(restAmount, contentId, flags, spawn); } return amount - restAmount; }
public virtual bool CanStack(MyObjectBuilderType typeId, MyStringId subtypeId, MyItemFlags flags) { if (flags == Flags && typeId == TypeId && subtypeId == SubtypeId) { return(true); } return(false); }
private static MyFixedPoint TransferOrRemove(MyInventory src, MyFixedPoint? amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyInventory dst = null, bool spawn = false, bool onlyWhole = true) { MyFixedPoint removedAmount = 0; if (!onlyWhole) { amount = MyFixedPoint.Min(amount.Value, src.GetItemAmount(contentId, flags)); } //Debug.Assert(!amount.HasValue || amount.Value > 0, "Transfering 0 amount of item."); if (!onlyWhole || src.ContainItems(amount, contentId, flags)) { bool transferAll = !amount.HasValue; MyFixedPoint remainingAmount = transferAll ? 0 : amount.Value; //TODO(AF) Remove oxygen specific code from inventory. //Will be fixed once MyInventory will support Entities. // If the requested item is an oxygen container, do a preliminary loop to pull any non-full items first. if (contentId.TypeId == typeof(MyObjectBuilder_OxygenContainerObject) || contentId.TypeId == typeof(MyObjectBuilder_GasContainerObject)) { int k = 0; while (k < src.m_items.Count) { if (!transferAll && remainingAmount == 0) break; MyPhysicalInventoryItem item = src.m_items[k]; // Skip full oxygen bottles in this loop. They will not be skipped in the next one. var oxygenBottle = item.Content as MyObjectBuilder_GasContainerObject; if (oxygenBottle != null && oxygenBottle.GasLevel == 1f) { k++; continue; } if (item.Content.GetObjectId() != contentId) { k++; continue; } if (transferAll || remainingAmount >= item.Amount) { removedAmount += item.Amount; remainingAmount -= item.Amount; Transfer(src, dst, item.ItemId, -1, spawn: spawn); } else { removedAmount += item.Amount; Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn); remainingAmount = 0; } } } // End of oxygen specific code int i = 0; while (i < src.m_items.Count) { if (!transferAll && remainingAmount == 0) break; MyPhysicalInventoryItem item = src.m_items[i]; var objectId = item.Content.GetId(); if (objectId != contentId && item.Content.TypeId == typeof(MyObjectBuilder_BlockItem)) { //objectId = MyDefinitionManager.Static.GetComponentId(item.Content.GetObjectId()); objectId = item.Content.GetObjectId(); } if (objectId != contentId) { i++; continue; } if (transferAll || remainingAmount >= item.Amount) { removedAmount += item.Amount; remainingAmount -= item.Amount; Transfer(src, dst, item.ItemId, -1, spawn: spawn); } else { removedAmount += remainingAmount; Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn); remainingAmount = 0; } } } return removedAmount; }
public MyObjectBuilder_PhysicalObject(MyItemFlags flags) { Flags = flags; }
public override bool CanStack(MyObjectBuilderType typeId, MyStringHash subtypeId, MyItemFlags flags) { return false; }
public override bool CanStack(MyObjectBuilderType typeId, MyStringHash subtypeId, MyItemFlags flags) { MyDefinitionId defId = new MyDefinitionId(typeId, subtypeId); MyDefinitionId myId = new MyDefinitionId(BlockDefId.TypeId, BlockDefId.SubtypeId); return(myId == BlockDefId && flags == this.Flags); }
private static void TransferOrRemove(MyInventory src, MyFixedPoint? amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyInventory dst = null, bool spawn = false) { //Debug.Assert(!amount.HasValue || amount.Value > 0, "Transfering 0 amount of item."); if (src.ContainItems(amount, contentId, flags)) { bool transferAll = !amount.HasValue; MyFixedPoint remainingAmount = transferAll ? 0 : amount.Value; int i = 0; while (i < src.m_items.Count) { if (!transferAll && remainingAmount == 0) break; MyInventoryItem item = src.m_items[i]; //TODO(AF) Remove oxygen specific code from inventory. //Will be fixed once MyInventory will support Entities. var oxygenBottle = item.Content as MyObjectBuilder_OxygenContainerObject; if (oxygenBottle != null && oxygenBottle.OxygenLevel == 1f) { i++; continue; } // End of oxygen specific code if (item.Content.GetObjectId() != contentId) { i++; continue; } if (transferAll || remainingAmount >= item.Amount) { remainingAmount -= item.Amount; Transfer(src, dst, item.ItemId, -1, spawn: spawn); } else { Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn); remainingAmount = 0; } } } }
VRage.MyFixedPoint IMyInventory.GetItemAmount(SerializableDefinitionId contentId, MyItemFlags flags) { return(GetItemAmount(contentId, flags)); }
/// <summary> /// Remove items of a given amount and definition /// </summary> /// <param name="amount">amount ot remove</param> /// <param name="contentId">definition id of items to be removed</param> /// <param name="spawn">Set tru to spawn object in the world, after it was removed</param> /// <returns>Returns the actually removed amount</returns> public abstract MyFixedPoint RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool spawn = false);
void Sandbox.ModAPI.IMyInventory.RemoveItemsOfType(VRage.MyFixedPoint amount, SerializableDefinitionId contentId, MyItemFlags flags, bool spawn) { RemoveItemsOfType(amount, contentId, flags, spawn); }
public bool AddItems(int count, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { var componentBuilder = (MyObjectBuilder_PhysicalObject)Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(contentId); Debug.Assert(componentBuilder != null, "Could not cast object builder to physical object"); if (componentBuilder == null) return false; componentBuilder.Flags = flags; return AddItems(count, componentBuilder); }
public override bool CanStack(MyObjectBuilderType typeId, MyStringId subtypeId, MyItemFlags flags) { return(false); }
public int GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { foreach (var item in m_items) { if (item.Content.CanStack(contentId.TypeId, contentId.SubtypeId, flags)) { return item.Amount; } } return 0; }
public override bool CanStack(MyObjectBuilderType typeId, MyStringHash subtypeId, MyItemFlags flags) { MyDefinitionId defId = new MyDefinitionId(typeId, subtypeId); MyDefinitionId myId = new MyDefinitionId(BlockDefId.TypeId, BlockDefId.SubtypeId); return myId == BlockDefId && flags == this.Flags; }
public override MyFixedPoint RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = 0, bool spawn = false) { MyFixedPoint point = amount; foreach (MyInventoryBase base2 in this.m_children.Reader) { point -= base2.RemoveItemsOfType(point, contentId, flags, spawn); } return(amount - point); }
VRage.MyFixedPoint Sandbox.ModAPI.Interfaces.IMyInventory.GetItemAmount(SerializableDefinitionId contentId, MyItemFlags flags) { return GetItemAmount(contentId,flags); }
public static MyFixedPoint Transfer(MyInventory src, MyInventory dst, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyFixedPoint? amount = null, bool spawn = false) { return TransferOrRemove(src, amount, contentId, flags, dst); }
public override void RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool spawn = false) { TransferOrRemove(this, amount, contentId, flags, null, spawn); }
public override MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool substitute = false) { MyFixedPoint amount = 0; foreach (var item in m_items) { var objectId = item.Content.GetId(); if (contentId != objectId && item.Content.TypeId == typeof(MyObjectBuilder_BlockItem)) { //objectId = MyDefinitionManager.Static.GetComponentId(item.Content.GetObjectId()); objectId = item.Content.GetObjectId(); } if (substitute && MySessionComponentEquivalency.Static != null) { objectId = MySessionComponentEquivalency.Static.GetMainElement(objectId); contentId = MySessionComponentEquivalency.Static.GetMainElement(contentId); } if (objectId == contentId && item.Content.Flags == flags) amount += item.Amount; //if (objectId == contentId && item.Content.Flags == flags) // amount += item.Amount; } return amount; }
public static void Transfer(MyInventory src, MyInventory dst, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyFixedPoint?amount = null, bool spawn = false) { TransferOrRemove(src, amount, contentId, flags, dst); }
private static void TransferOrRemove(MyInventory src, MyFixedPoint?amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, MyInventory dst = null, bool spawn = false) { //Debug.Assert(!amount.HasValue || amount.Value > 0, "Transfering 0 amount of item."); if (src.ContainItems(amount, contentId, flags)) { bool transferAll = !amount.HasValue; MyFixedPoint remainingAmount = transferAll ? 0 : amount.Value; //TODO(AF) Remove oxygen specific code from inventory. //Will be fixed once MyInventory will support Entities. // If the requested item is an oxygen container, do a preliminary loop to pull any non-full items first. if (contentId.TypeId == typeof(MyObjectBuilder_OxygenContainerObject)) { int k = 0; while (k < src.m_items.Count) { if (!transferAll && remainingAmount == 0) { break; } MyPhysicalInventoryItem item = src.m_items[k]; // Skip full oxygen bottles in this loop. They will not be skipped in the next one. var oxygenBottle = item.Content as MyObjectBuilder_OxygenContainerObject; if (oxygenBottle != null && oxygenBottle.OxygenLevel == 1f) { k++; continue; } if (item.Content.GetObjectId() != contentId) { k++; continue; } if (transferAll || remainingAmount >= item.Amount) { remainingAmount -= item.Amount; Transfer(src, dst, item.ItemId, -1, spawn: spawn); } else { Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn); remainingAmount = 0; } } } // End of oxygen specific code int i = 0; while (i < src.m_items.Count) { if (!transferAll && remainingAmount == 0) { break; } MyPhysicalInventoryItem item = src.m_items[i]; if (item.Content.GetObjectId() != contentId) { i++; continue; } if (transferAll || remainingAmount >= item.Amount) { remainingAmount -= item.Amount; Transfer(src, dst, item.ItemId, -1, spawn: spawn); } else { Transfer(src, dst, item.ItemId, -1, remainingAmount, spawn); remainingAmount = 0; } } } }
VRage.MyFixedPoint IMyInventory.GetItemAmount(SerializableDefinitionId contentId, MyItemFlags flags) { return GetItemAmount(contentId,flags); }
public override MyFixedPoint GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None) { float amount = 0; foreach (MyInventoryBase inventory in m_children.Reader) { amount += (float)inventory.GetItemAmount(contentId, flags); } return (MyFixedPoint) amount; }
/// <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(); }
public override bool RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool spawn = false) { var restAmount = amount; foreach (MyInventoryBase inventory in m_children.Reader) { var contains = inventory.GetItemAmount(contentId, flags); if (contains > restAmount) { contains = restAmount; } if (contains > 0) inventory.RemoveItemsOfType(contains, contentId, flags, spawn); restAmount -= contains; } return restAmount == 0; }
public override MyFixedPoint RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool spawn = false) { var restAmount = amount; foreach (MyInventoryBase inventory in m_children.Reader) { restAmount -= inventory.RemoveItemsOfType(restAmount, contentId, flags, spawn); } return(amount - restAmount); }
public void RemoveItemsOfType(MyFixedPoint amount, MyDefinitionId contentId, MyItemFlags flags = MyItemFlags.None, bool spawn = false) { TransferOrRemove(this, amount, contentId, flags, null, spawn); }