private static void Reload(IMyInventoryOwner gun, SerializableDefinitionId ammo, bool reactor = false)
        {
            var cGun = gun;
            Sandbox.ModAPI.IMyInventory inv = (Sandbox.ModAPI.IMyInventory)cGun.GetInventory(0);
            VRage.MyFixedPoint point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);
            Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt");
            if (point.RawValue > 1000000)
                return;
            //inv.Clear();
            VRage.MyFixedPoint amount = new VRage.MyFixedPoint();
            amount.RawValue = 2000000;

            MyObjectBuilder_InventoryItem ii;
            if (reactor)
            {
                ii = new MyObjectBuilder_InventoryItem()
                {
                    Amount = 10,
                    Content = new MyObjectBuilder_Ingot() { SubtypeName = ammo.SubtypeName }
                };
            }
            else
            {
                ii = new MyObjectBuilder_InventoryItem()
                {
                    Amount = 4,
                    Content = new MyObjectBuilder_AmmoMagazine() { SubtypeName = ammo.SubtypeName }
                };
            }
            inv.AddItems(amount, ii.PhysicalContent);

            point = inv.GetItemAmount(ammo, MyItemFlags.None | MyItemFlags.Damaged);
            Util.GetInstance().Log(ammo.SubtypeName + " [ReloadGuns] Amount " + point.RawValue, "ItemManager.txt");
        }
 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 override bool Invoke(string messageText)
        {
            MyObjectBuilder_Base content = null;
            string[] options;
            decimal amount = 1;

            var match = Regex.Match(messageText, @"/invadd\s{1,}(?:(?<Key>.+)\s(?<Value>[+-]?((\d+(\.\d*)?)|(\.\d+)))|(?<Key>.+))", RegexOptions.IgnoreCase);
            if (match.Success && content == null)
            {
                var itemName = match.Groups["Key"].Value;
                var strAmount = match.Groups["Value"].Value;
                if (!decimal.TryParse(strAmount, out amount))
                    amount = 1;

                if (!Support.FindPhysicalParts(_oreNames, _ingotNames, _physicalItemNames, _physicalItems, itemName, out content, out options) && options.Length > 0)
                {
                    MyAPIGateway.Utilities.ShowMessage("Did you mean", String.Join(", ", options) + " ?");
                    return true;
                }
            }

            if (content != null)
            {
                if (amount < 0)
                    amount = 1;

                if (content.TypeId != typeof(MyObjectBuilder_Ore) && content.TypeId != typeof(MyObjectBuilder_Ingot))
                {
                    // must be whole numbers.
                    amount = Math.Round(amount, 0);
                }

                MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem() { Amount = MyFixedPoint.DeserializeString(amount.ToString(CultureInfo.InvariantCulture)), Content = content };
                var inventoryOwnwer = MyAPIGateway.Session.Player.Controller.ControlledEntity as IMyInventoryOwner;
                var inventory = inventoryOwnwer.GetInventory(0) as Sandbox.ModAPI.IMyInventory;
                inventory.AddItems(inventoryItem.Amount, (MyObjectBuilder_PhysicalObject)inventoryItem.Content, -1);
                return true;
            }

            MyAPIGateway.Utilities.ShowMessage("Unknown Item", "Could not find the specified name.");
            return true;
        }
示例#4
0
		/// <summary>
		/// Spawns a rock to explode the missile.
		/// </summary>
		/// <remarks>
		/// Runs on separate thread. (sort-of)
		/// </remarks>
		private void Explode()
		{
			MyAPIGateway.Utilities.TryInvokeOnGameThread(() => {
				if (MyEntity.Closed)
					return;
				m_stage = Stage.Terminated;

				MyEntity.Physics.LinearVelocity = Vector3.Zero;

				RemoveRock();

				MyObjectBuilder_InventoryItem item = new MyObjectBuilder_InventoryItem() { Amount = 100, Content = 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)MyEntity.WorldMatrix.Forward,
					Up = (Vector3)MyEntity.WorldMatrix.Up
				};

				myRock = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(rockBuilder);
				myLogger.debugLog("created rock at " + MyEntity.GetPosition() + ", " + myRock.getBestName(), "Explode()");
			}, myLogger);
		}
        public InventoryItemEntity(MyObjectBuilder_InventoryItem definition, Object backingObject)
            : base(definition, backingObject)
        {
            if (m_physicalItemsManager == null)
            {
                m_physicalItemsManager = new PhysicalItemDefinitionsManager();
                m_physicalItemsManager.Load(PhysicalItemDefinitionsManager.GetContentDataFile("PhysicalItems.sbc"));
            }
            if (m_componentsManager == null)
            {
                m_componentsManager = new ComponentDefinitionsManager();
                m_componentsManager.Load(ComponentDefinitionsManager.GetContentDataFile("Components.sbc"));
            }
            if (m_ammoManager == null)
            {
                m_ammoManager = new AmmoMagazinesDefinitionsManager();
                m_ammoManager.Load(AmmoMagazinesDefinitionsManager.GetContentDataFile("AmmoMagazines.sbc"));
            }

            FindMatchingItem();
        }
        public InventoryItemEntity NewEntry()
        {
            MyObjectBuilder_InventoryItem defaults = new MyObjectBuilder_InventoryItem();
            SerializableDefinitionId itemTypeId = new SerializableDefinitionId(typeof(MyObjectBuilder_Ore), "Stone");
            defaults.PhysicalContent = (MyObjectBuilder_PhysicalObject)MyObjectBuilder_PhysicalObject.CreateNewObject(itemTypeId);
            defaults.Amount = 1;

            InventoryItemEntity newItem = m_itemManager.NewEntry<InventoryItemEntity>(defaults);
            newItem.ItemId = NextItemId;
            NextItemId = NextItemId + 1;

            RefreshInventory();

            return newItem;
        }
        public static bool InventoryAdd(Sandbox.ModAPI.IMyInventory inventory, MyFixedPoint amount, MyDefinitionId definitionId)
        {
            var content = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId);

            var gasContainer = content as MyObjectBuilder_GasContainerObject;
            if (gasContainer != null)
                gasContainer.GasLevel = 1f;

            MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem { Amount = amount, Content = content };

            if (inventory.CanItemsBeAdded(inventoryItem.Amount, definitionId))
            {
                inventory.AddItems(inventoryItem.Amount, (MyObjectBuilder_PhysicalObject)inventoryItem.Content, -1);
                return true;
            }

            // Inventory full. Could not add the item.
            return false;
        }
示例#8
0
 public InventoryModel(MyObjectBuilder_InventoryItem item)
 {
     _item = item;
 }
		public InventoryItemEntity( MyObjectBuilder_InventoryItem definition, Object backingObject )
			: base( definition, backingObject )
		{
			m_definition = MyDefinitionManager.Static.GetPhysicalItemDefinition( PhysicalContent );
			m_definitionId = m_definition.Id;
		}
示例#10
0
 internal void Additem(MyObjectBuilder_InventoryItem item)
 {
     var contentPath = ToolboxUpdater.GetApplicationContentPath();
     item.ItemId = _inventory.nextItemId++;
     _inventory.Items.Add(item);
     Items.Add(CreateItem(item, contentPath));
 }
示例#11
0
        private InventoryModel CreateItem(MyObjectBuilder_InventoryItem item, string contentPath)
        {
            var definition = SpaceEngineersApi.GetDefinition(item.Content.TypeId, item.Content.SubtypeName) as MyObjectBuilder_PhysicalItemDefinition;

            string name;
            string textureFile;
            double massMultiplyer;
            double volumeMultiplyer;

            if (definition == null)
            {
                name = item.Content.SubtypeName + " " + item.Content.TypeId.ToString();
                massMultiplyer = 1;
                volumeMultiplyer = 1;
                textureFile = null;
            }
            else
            {
                name = definition.DisplayName;
                massMultiplyer = definition.Mass;
                volumeMultiplyer = definition.Volume.Value;
                textureFile = SpaceEngineersCore.GetDataPathOrDefault(definition.Icon, Path.Combine(contentPath, definition.Icon));
            }

            var newItem = new InventoryModel(item)
            {
                Name = name,
                Amount = (decimal)item.Amount,
                SubtypeId = item.Content.SubtypeName,
                TypeId = item.Content.TypeId,
                MassMultiplyer = massMultiplyer,
                VolumeMultiplyer = volumeMultiplyer,
                TextureFile = textureFile,
                IsUnique = item.Content.TypeId == SpaceEngineersTypes.PhysicalGunObject || item.Content.TypeId == SpaceEngineersTypes.OxygenContainerObject,
                IsInteger = item.Content.TypeId == SpaceEngineersTypes.Component || item.Content.TypeId == SpaceEngineersTypes.AmmoMagazine,
                IsDecimal = item.Content.TypeId == SpaceEngineersTypes.Ore || item.Content.TypeId == SpaceEngineersTypes.Ingot,
                Exists = definition != null, // item no longer exists in Space Engineers definitions.
            };

            TotalVolume += newItem.Volume;
            TotalMass += newItem.Mass;

            return newItem;
        }
        public override bool Invoke(string messageText)
        {
            MyObjectBuilder_Base content = null;
            string[] options;
            decimal amount = 1;
            IMyEntity entity = null;

            var match = Regex.Match(messageText, @"/((invins)|(invinsert))\s{1,}(?:(?<Key>.+)\s(?<Value>[+-]?((\d+(\.\d*)?)|(\.\d+)))|(?<Key>.+))", RegexOptions.IgnoreCase);
            if (match.Success && content == null)
            {
                double distance;
                Support.FindLookAtEntity(MyAPIGateway.Session.ControlledObject, out entity, out distance, false, true, false, false, false);
                if (entity == null || !(entity is IMyInventoryOwner))
                {
                    MyAPIGateway.Utilities.ShowMessage("Target", "Is not an inventory cube.");
                    return true;
                }

                var itemName = match.Groups["Key"].Value;
                var strAmount = match.Groups["Value"].Value;
                if (!decimal.TryParse(strAmount, out amount))
                    amount = 1;

                if (!Support.FindPhysicalParts(_oreNames, _ingotNames, _physicalItemNames, _physicalItems, itemName, out content, out options) && options.Length > 0)
                {
                    MyAPIGateway.Utilities.ShowMessage("Did you mean", String.Join(", ", options) + " ?");
                    return true;
                }
            }

            if (content != null)
            {
                if (amount < 0)
                    amount = 1;

                if (content.TypeId != typeof(MyObjectBuilder_Ore) && content.TypeId != typeof(MyObjectBuilder_Ingot))
                {
                    // must be whole numbers.
                    amount = Math.Round(amount, 0);
                }

                MyObjectBuilder_InventoryItem inventoryItem = new MyObjectBuilder_InventoryItem() { Amount = MyFixedPoint.DeserializeString(amount.ToString(CultureInfo.InvariantCulture)), Content = content };
                var inventoryOwnwer = entity as IMyInventoryOwner;
                var itemAdded = false;

                for (int i = 0; i < inventoryOwnwer.InventoryCount; i++)
                {
                    var inventory = inventoryOwnwer.GetInventory(i) as Sandbox.ModAPI.IMyInventory;
                    var definitionId = new MyDefinitionId(inventoryItem.Content.GetType(), inventoryItem.Content.SubtypeName);

                    if (inventory.CanItemsBeAdded(inventoryItem.Amount, definitionId))
                    {
                        itemAdded = true;
                        inventory.AddItems(inventoryItem.Amount, (MyObjectBuilder_PhysicalObject)inventoryItem.Content, -1);
                        break;
                    }
                }
                if (!itemAdded)
                    MyAPIGateway.Utilities.ShowMessage("Failed", "Invalid container or Full container. Could not add the item.");
                return true;
            }

            MyAPIGateway.Utilities.ShowMessage("Unknown Item", "Could not find the specified name.");
            return true;
        }
示例#13
0
        private void spawnMeteor(Vector3Wrapper spawnpos, Vector3Wrapper vel, Vector3Wrapper up, Vector3Wrapper forward)
        {
            if (SandboxGameAssemblyWrapper.IsDebugging)
            {
                LogManager.APILog.WriteLineAndConsole("Physics Meteroid - spawnMeteor(" + spawnpos.ToString() + ", " + vel.ToString() + ", " + up.ToString() + ", " + forward.ToString() + ")" );
            }
            MyObjectBuilder_FloatingObject tempobject;
            MyObjectBuilder_Ore tempore = new MyObjectBuilder_Ore();
            MyObjectBuilder_InventoryItem tempitem = new MyObjectBuilder_InventoryItem();
            tempore.SetDefaultProperties();
            FloatingObject physicsmeteor;
            m_ore_fctr = m_gen.NextDouble();

            tempitem = (MyObjectBuilder_InventoryItem)MyObjectBuilder_InventoryItem.CreateNewObject(m_InventoryItemType);
            tempitem.PhysicalContent = (MyObjectBuilder_PhysicalObject)MyObjectBuilder_PhysicalObject.CreateNewObject(m_OreType);
            tempitem.PhysicalContent.SubtypeName = getRandomOre();
            tempitem.AmountDecimal = Math.Round((decimal)(ore_amt * getOreFctr(tempitem.PhysicalContent.SubtypeName) * m_ore_fctr));
            if (tempitem.AmountDecimal < 1) tempitem.AmountDecimal = 1;
            tempitem.ItemId = 0;

            tempobject = (MyObjectBuilder_FloatingObject)MyObjectBuilder_FloatingObject.CreateNewObject(m_FloatingObjectType);
            tempobject.Item = tempitem;

            physicsmeteor = new FloatingObject(tempobject);
            physicsmeteor.Up = up;
            physicsmeteor.Forward = forward;
            physicsmeteor.Position = spawnpos;
            physicsmeteor.LinearVelocity = vel;
            physicsmeteor.MaxLinearVelocity = 104.7F * maxVelocityFctr;
            if (SandboxGameAssemblyWrapper.IsDebugging)
            {
                LogManager.APILog.WriteLineAndConsole("Meteor entityID: " + physicsmeteor.EntityId.ToString() + " Velocity: " + vel.ToString());
            }
            SectorObjectManager.Instance.AddEntity(physicsmeteor);
            //workaround for the velocity problem.
            Thread physicsthread = new Thread(() => velocityloop(physicsmeteor, vel));
            physicsthread.Start();
        }