private void BTN_InventoryItem_Add_Click(object sender, EventArgs e) { if (CMB_ItemType.SelectedItem == null) return; if (Amount <= 0.0f) return; try { SandboxGameAssemblyWrapper.Instance.GameAction(() => { var amount = (MyFixedPoint) Amount; var content = (MyObjectBuilder_PhysicalObject) MyObjectBuilderSerializer.CreateNewObject(SelectedType); MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem { Amount = amount, Content = content }; if (InventoryContainer.CanItemsBeAdded(amount, SelectedType)) { InventoryContainer.AddItems(amount, inventoryItem.Content); } }); Close(); } catch (Exception ex) { ApplicationLog.BaseLog.Error(ex); } }
internal void Additem(MyObjectBuilder_InventoryItem item) { var contentPath = ToolboxUpdater.GetApplicationContentPath(); item.ItemId = _inventory.nextItemId++; _inventory.Items.Add(item); Items.Add(CreateItem(item, contentPath)); }
/// <summary> /// Only call from game thread! Spawns a rock to explode the missile. /// </summary> private void Explode() { myLogger.debugLog(!MyAPIGateway.Multiplayer.IsServer, "Not server!", Logger.severity.FATAL); if (MyEntity.Closed) return; m_stage = Stage.Terminated; MyEntity.Physics.LinearVelocity = Vector3.Zero; RemoveRock(); MyObjectBuilder_InventoryItem item = new MyObjectBuilder_InventoryItem() { Amount = 1, PhysicalContent = new MyObjectBuilder_Ore() { SubtypeName = "Stone" } }; MyObjectBuilder_FloatingObject rockBuilder = new MyObjectBuilder_FloatingObject(); rockBuilder.Item = item; rockBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene; rockBuilder.PositionAndOrientation = new MyPositionAndOrientation() { Position = MyEntity.GetPosition(), Forward = Vector3.Forward, Up = Vector3.Up }; myRock = MyEntities.CreateFromObjectBuilderAndAdd(rockBuilder); if (myRock == null) { myLogger.alwaysLog("failed to create rock, builder:\n" + MyAPIGateway.Utilities.SerializeToXML(rockBuilder), Logger.severity.ERROR); return; } myLogger.debugLog("created rock at " + myRock.PositionComp.GetPosition() + ", " + myRock.getBestName()); }
private InventoryModel CreateItem(MyObjectBuilder_InventoryItem item, string contentPath) { var definition = MyDefinitionManager.Static.GetDefinition(item.PhysicalContent.TypeId, item.PhysicalContent.SubtypeName) as MyPhysicalItemDefinition; string name; string textureFile; double massMultiplyer; double volumeMultiplyer; if (definition == null) { name = item.PhysicalContent.SubtypeName + " " + item.PhysicalContent.TypeId.ToString(); massMultiplyer = 1; volumeMultiplyer = 1; textureFile = null; } else { name = definition.DisplayNameText; massMultiplyer = definition.Mass; volumeMultiplyer = definition.Volume * SpaceEngineersConsts.VolumeMultiplyer; textureFile = (definition.Icons == null || definition.Icons.First() == null) ? null : SpaceEngineersCore.GetDataPathOrDefault(definition.Icons.First(), Path.Combine(contentPath, definition.Icons.First())); } var newItem = new InventoryModel(item) { Name = name, Amount = (decimal)item.Amount, SubtypeId = item.PhysicalContent.SubtypeName, TypeId = item.PhysicalContent.TypeId, MassMultiplyer = massMultiplyer, VolumeMultiplyer = volumeMultiplyer, TextureFile = textureFile, IsUnique = item.PhysicalContent.TypeId == SpaceEngineersTypes.PhysicalGunObject || item.PhysicalContent.TypeId == SpaceEngineersTypes.OxygenContainerObject, IsInteger = item.PhysicalContent.TypeId == SpaceEngineersTypes.Component || item.PhysicalContent.TypeId == SpaceEngineersTypes.AmmoMagazine, IsDecimal = item.PhysicalContent.TypeId == SpaceEngineersTypes.Ore || item.PhysicalContent.TypeId == SpaceEngineersTypes.Ingot, Exists = definition != null, // item no longer exists in Space Engineers definitions. }; TotalVolume += newItem.Volume; TotalMass += newItem.Mass; return newItem; }
public InventoryModel(MyObjectBuilder_InventoryItem item) { _item = item; }