public override bool CanStack(MyObjectBuilder_PhysicalObject a) { MyObjectBuilder_BlockItem other = a as MyObjectBuilder_BlockItem; if (other == null) return false; return other.BlockDefId.TypeId == BlockDefId.TypeId && other.BlockDefId.SubtypeId == this.BlockDefId.SubtypeId && a.Flags == this.Flags; }
public MyInventoryItem(MyObjectBuilder_InventoryItem item) { Debug.Assert(item.Amount > 0, "Creating inventory item with zero amount!"); ItemId = 0; Amount = item.Amount; Content = item.PhysicalContent; }
public MyInventoryItem(MyFixedPoint amount, MyObjectBuilder_PhysicalObject content) { Debug.Assert(amount > 0, "Creating inventory item with zero amount!"); ItemId = 0; Amount = amount; Content = content; }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var generatorBuilder = builder as MyObjectBuilder_ReactorDefinition; MyDebug.AssertDebug(generatorBuilder != null, "Initializing thrust definition using wrong object builder."); InventorySize = generatorBuilder.InventorySize; InventoryMaxVolume = InventorySize.X * InventorySize.Y * InventorySize.Z; FuelId = generatorBuilder.FuelId; FuelDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(FuelId); MyDebug.AssertDebug(FuelDefinition != null); FuelItem = MyObjectBuilderSerializer.CreateNewObject(generatorBuilder.FuelId) as MyObjectBuilder_PhysicalObject; MyDebug.AssertDebug(FuelItem != null); //StringBuilder constraintTooltip = new StringBuilder(); //constraintTooltip.Append(FuelDefinition.DisplayNameText); //InventoryConstraint = new MyInventoryConstraint(constraintTooltip).Add(FuelId); String constraintTooltip = FuelDefinition.DisplayNameText; InventoryConstraint = new MyInventoryConstraint(constraintTooltip).Add(FuelId); }
public void AddItems(MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, int index = -1) { if (amount == 0) return; if (!CanItemsBeAdded(amount, objectBuilder.GetObjectId())) return; if (Sync.IsServer) { if (MyPerGameSettings.ConstrainInventory()) AffectAddBySurvival(ref amount, objectBuilder); if (amount == 0) return; AddItemsInternal(amount, objectBuilder, index); SyncObject.SendAddItemsAnnounce(this, amount, objectBuilder, index); } else SyncObject.SendAddItemsRequest(this, index, amount, objectBuilder); }
private int? FindFirstStackablePosition(MyObjectBuilder_PhysicalObject toStack) { for (int i = 0; i < m_items.Count; ++i) { if (m_items[i].Content.CanStack(toStack)) return i; } return null; }
public bool ContainItems(MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob) { return ContainItems(amount, ob.GetObjectId()); }
public virtual bool CanStack(MyObjectBuilder_PhysicalObject a) { return(CanStack(a.TypeId, a.SubtypeId, a.Flags)); }
public bool AddItems(MyInventory inventory, MyObjectBuilder_PhysicalObject obj, bool overrideCheck) { return AddItems(inventory, obj, overrideCheck, 1); }
public void RemoveItemsOfType(MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, bool spawn = false) { TransferOrRemove(this, amount, objectBuilder.GetObjectId(), objectBuilder.Flags, null, spawn); }
void Sandbox.ModAPI.IMyInventory.RemoveItemsOfType(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, bool spawn) { RemoveItemsOfType(amount, objectBuilder, spawn); }
void Sandbox.ModAPI.IMyInventory.AddItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, int index) { AddItems(amount, objectBuilder, index); }
bool Sandbox.ModAPI.Interfaces.IMyInventory.ContainItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob) { return ContainItems(amount, ob); }
public override bool CanStack(MyObjectBuilder_PhysicalObject a) { return false; }
public override bool CanStack(MyObjectBuilder_PhysicalObject a) { return(false); }
public bool AddItems(MyInventory inventory, MyObjectBuilder_PhysicalObject obj, bool overrideCheck, MyFixedPoint amount) { if (overrideCheck || !inventory.ContainItems(amount, obj)) { if (inventory.CanItemsBeAdded(amount, obj.GetId())) { inventory.AddItems(amount, obj); return true; } else { return false; } } else { return false; } }
private void AffectAddBySurvival(ref MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder) { Debug.Assert(Sync.IsServer); MyFixedPoint space = ComputeAmountThatFits(objectBuilder.GetObjectId()); if (space < amount) { if (Owner.InventoryOwnerType == MyInventoryOwnerTypeEnum.Character) { MyCharacter c = (Owner as MyCharacter); Matrix m = c.GetHeadMatrix(true); MyEntity entity = MyFloatingObjects.Spawn(new MyInventoryItem(amount - space, objectBuilder), m.Translation, m.Forward, m.Up, c.Physics); entity.Physics.ApplyImpulse(m.Forward.Cross(m.Up), c.PositionComp.GetPosition()); } amount = space; } }
public bool AddItems(int count, MyObjectBuilder_PhysicalObject physicalObject) { int index = 0; foreach (var item in m_items) { if (item.Content.CanStack(physicalObject)) break; index++; } if (index == m_items.Count()) { Debug.Assert(count < int.MaxValue, "Trying to add more items into construction stockpile than int.MaxValue"); if (count >= int.MaxValue) return false; MyStockpileItem item = new MyStockpileItem(); item.Amount = (int)count; item.Content = physicalObject; m_items.Add(item); AddSyncItem(item); return true; } else { Debug.Assert((long)m_items[index].Amount + count < int.MaxValue, "Trying to add more items into construction stockpile than int.MaxValue"); if ((long)m_items[index].Amount + count >= int.MaxValue) return false; MyStockpileItem item = new MyStockpileItem(); item.Amount = (int)(m_items[index].Amount + count); item.Content = m_items[index].Content; m_items[index] = item; MyStockpileItem syncItem = new MyStockpileItem(); syncItem.Content = m_items[index].Content; syncItem.Amount = (int)count; AddSyncItem(syncItem); return true; } return false; }
public void AddItemsInternal(MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, int index = -1, uint? itemId = null) { Debug.Assert(amount > 0, "Adding 0 amount of item."); var newItem = new MyInventoryItem() { Amount = amount, Content = objectBuilder }; if (index >= 0 && index < m_items.Count) { if (m_items[index].Content.CanStack(objectBuilder)) { newItem.Amount += m_items[index].Amount; newItem.ItemId = m_items[index].ItemId; m_items[index] = newItem; } else { newItem.ItemId = NextItemID; m_items.Insert(index, newItem); } } else { bool add = true; bool canStackWithItself = newItem.Content.CanStack(newItem.Content); if (index < 0 && canStackWithItself) { int? itemPos = FindFirstStackablePosition(objectBuilder); if (itemPos.HasValue) { newItem.ItemId = m_items[itemPos.Value].ItemId; newItem.Amount += m_items[itemPos.Value].Amount; m_items[itemPos.Value] = newItem; add = false; } } if (add) { if (canStackWithItself) { newItem.ItemId = itemId.HasValue ? itemId.Value : NextItemID; m_items.Add(newItem); } else { var targetAmount = newItem.Amount; newItem.Amount = 1; for (MyFixedPoint addedAmount = 0; addedAmount < targetAmount; addedAmount += 1) { newItem.ItemId = itemId.HasValue ? itemId.Value : NextItemID; itemId = null; // so we use NextItemID next time m_items.Add(newItem); newItem.Content = newItem.Content.Clone() as MyObjectBuilder_PhysicalObject; Debug.Assert(newItem.Content != null); } } } } RefreshVolumeAndMass(); VerifyIntegrity(); if (ContentsChanged != null) ContentsChanged(this); }
public void SendAddItemsRequest(MyInventory inv, int index, MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder) { Debug.Assert(inv.Owner != null, "Inventory must have owner to be able to add items synchronously!"); var msg = new AddItemsMsg(); msg.OwnerEntityId = inv.Owner.EntityId; msg.InventoryIndex = inv.InventoryIdx; msg.itemIdx = index; msg.Item = objectBuilder; msg.Amount = amount; Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request); }
private void SpawnOrePieces(MyFixedPoint amountItems, MyFixedPoint maxAmountPerDrop, Vector3 hitPosition, MyObjectBuilder_PhysicalObject oreObjBuilder, MyVoxelMaterialDefinition voxelMaterial) { ProfilerShort.Begin("SpawnOrePieces"); var forward = Vector3.Normalize(m_sensor.FrontPoint - m_sensor.Center); //var pos = m_sensor.CutOutSphere.Center + forward * m_floatingObjectSpawnOffset; var pos = hitPosition - forward * m_floatingObjectSpawnRadius; BoundingSphere bsphere = new BoundingSphere(pos, m_floatingObjectSpawnRadius); while (amountItems > 0) { MyFixedPoint dropAmount = MyFixedPoint.Min(amountItems, maxAmountPerDrop); amountItems -= dropAmount; var inventoryItem = new MyPhysicalInventoryItem(dropAmount, oreObjBuilder); var item = MyFloatingObjects.Spawn(inventoryItem, bsphere, null, voxelMaterial); item.Physics.LinearVelocity = MyUtils.GetRandomVector3HemisphereNormalized(forward) * MyUtils.GetRandomFloat(5, 8); item.Physics.AngularVelocity = MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(4, 8); } ProfilerShort.End(); }
public bool ContainItems(MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob) { throw new NotImplementedException(); }
public bool RemoveItems(int count, MyObjectBuilder_PhysicalObject physicalObject) { return RemoveItems(count, physicalObject.GetId(), physicalObject.Flags); }
public bool ContainItems(MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob) { if (ob == null) return false; return ContainItems(amount, ob.GetObjectId()); }
public virtual bool CanStack(MyObjectBuilder_PhysicalObject a) { return CanStack(a.TypeId, a.SubtypeId, a.Flags); }
private int? FindFirstStackablePosition(MyObjectBuilder_PhysicalObject toStack, MyFixedPoint wantedAmount) { for (int i = 0; i < m_items.Count; ++i) { if (m_items[i].Content.CanStack(toStack) && m_items[i].Amount <= wantedAmount) return i; } return null; }
public void AddItemsInternal(MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, int index = -1, uint? itemId = null, bool stack = true) { Debug.Assert(amount > 0, "Adding 0 amount of item."); var newItem = new MyPhysicalInventoryItem() { Amount = amount, Content = objectBuilder }; MyFixedPoint maxStack = MyFixedPoint.MaxValue; MyComponentDefinition compDef = null; if (MyDefinitionManager.Static.TryGetComponentDefinition(objectBuilder.GetId(), out compDef)) maxStack = compDef.MaxStackAmount; if (index >= 0 && index < m_items.Count) { if (m_items[index].Content.CanStack(objectBuilder)) { var newStackVal = m_items[index].Amount + newItem.Amount - maxStack; if (newStackVal > 0) { newItem.Amount = maxStack; newItem.ItemId = m_items[index].ItemId; m_items[index] = newItem; newItem.Amount = newStackVal; newItem.ItemId = GetNextItemID(); newItem.Content = objectBuilder.Clone() as MyObjectBuilder_PhysicalObject; m_items.Add(newItem); } else { newItem.Amount += m_items[index].Amount; newItem.ItemId = m_items[index].ItemId; m_items[index] = newItem; } } else { newItem.ItemId = GetNextItemID(); m_items.Insert(index, newItem); } } else { bool add = true; bool canStackWithItself = newItem.Content.CanStack(newItem.Content); if (index < 0 && canStackWithItself && stack) { int? itemPos = FindFirstStackablePosition(objectBuilder, maxStack - amount); if (itemPos.HasValue) { newItem.ItemId = m_items[itemPos.Value].ItemId; newItem.Amount += m_items[itemPos.Value].Amount; m_items[itemPos.Value] = newItem; add = false; } } if (add) { MyFixedPoint stackSize = canStackWithItself ? MyFixedPoint.Min(maxStack, amount) : 1; var targetAmount = newItem.Amount; MyFixedPoint addAmount = stackSize; while (targetAmount > 0) { targetAmount -= stackSize; if (targetAmount < 0) addAmount = targetAmount + stackSize; newItem.Amount = addAmount; newItem.ItemId = itemId.HasValue ? itemId.Value : GetNextItemID(); itemId = null; // so we use NextItemID next time m_items.Add(newItem); newItem.Content = newItem.Content.Clone() as MyObjectBuilder_PhysicalObject; Debug.Assert(newItem.Content != null); } } } RefreshVolumeAndMass(); VerifyIntegrity(); OnContentsChanged(); }
public static int getitemidfromitemname(string itemname,ulong userID, ShopItem item) { var temp = new MyObjectBuilder_PhysicalObject(); if (item != null) { if (item.ItemName == itemname) { temp = new MyObjectBuilder_Ingot() { SubtypeName = itemname }; ChatUtil.SendPrivateChat(userID, Convert.ToString(temp.GetHashCode())); return temp.GetHashCode(); } else { ChatUtil.SendPrivateChat(userID, "Please enter a valid item name."); } } return 0; }