Beispiel #1
0
        public override void AddItems(MyCharacter character)
        {
            MyWeaponDefinition definition;

            base.AddItems(character);
            MyObjectBuilder_PhysicalGunObject objectBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>(this.StartingWeaponDefinitionId.SubtypeName);

            if (character.WeaponTakesBuilderFromInventory(new MyDefinitionId?(this.StartingWeaponDefinitionId)))
            {
                character.GetInventory(0).AddItems(1, objectBuilder);
            }
            foreach (MyDefinitionId id in this.InventoryItems)
            {
                objectBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_PhysicalGunObject>(id.SubtypeName);
                character.GetInventory(0).AddItems(1, objectBuilder);
            }
            character.SwitchToWeapon(this.StartingWeaponDefinitionId);
            MyDefinitionId defId = new MyDefinitionId(typeof(MyObjectBuilder_WeaponDefinition), this.StartingWeaponDefinitionId.SubtypeName);

            if (MyDefinitionManager.Static.TryGetWeaponDefinition(defId, out definition) && definition.HasAmmoMagazines())
            {
                MyObjectBuilder_AmmoMagazine magazine = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_AmmoMagazine>(definition.AmmoMagazinesId[0].SubtypeName);
                character.GetInventory(0).AddItems(3, magazine);
            }
        }
Beispiel #2
0
        private void AddAmmo()
        {
            List <MyInventoryItem> items = new List <MyInventoryItem>();

            m_inventory.GetItems(items);
            if (items.Capacity <= 1)
            {
                var ammo = new MyObjectBuilder_AmmoMagazine()
                {
                    SubtypeName = "SpotlightTurretAmmoMagazine"
                };

                m_inventory.AddItems(2, ammo);
            }
        }
Beispiel #3
0
        // Closing Event Callbacks
        private void OnMarkForClose(IMyEntity obj)
        {
            var ammo = new MyObjectBuilder_AmmoMagazine()
            {
                SubtypeName = "SpotlightTurretAmmoMagazine"
            };
            IMyInventory           inv   = obj.GameLogic.GetAs <TurretSpotlight>().m_inventory;
            List <MyInventoryItem> items = new List <MyInventoryItem>();

            inv.GetItems(items);
            MyFixedPoint amount = 0;

            foreach (var item in items)
            {
                amount += item.Amount;
            }

            obj.GameLogic.GetAs <TurretSpotlight>().m_inventory.RemoveItemsOfType(amount, ammo);
        }
Beispiel #4
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();


            IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(0) as IMyInventory;

            if (inventory.ItemCount < 1)
            {
                MyObjectBuilder_AmmoMagazine builder = new MyObjectBuilder_AmmoMagazine()
                {
                    SubtypeName = "Missile200mm"
                };
                inventory.AddItems((MyFixedPoint)6, builder);
            }


            TerminalalBlock.RefreshCustomInfo();
        }
Beispiel #5
0
    public void Update(int spread = 1)
    {
        for (var i = _updateId; i < _turretsForUpdate.Count; i += spread)
        {
            var target = _turretsForUpdate[i];
            var inv    = target.AmmoInventory;
            if (inv == null)
            {
                continue;
            }
            var entity = (IMyEntity)target;
            var weapon = WeaponShortcuts.GetWeaponDefinition(entity);
            if (weapon == null || !weapon.HasAmmoMagazines())
            {
                continue;
            }

            MyObjectBuilder_PhysicalObject[] ammoMags;
            if (!_ammoTypes.TryGetValue(weapon, out ammoMags))
            {
                ammoMags = new MyObjectBuilder_PhysicalObject[weapon.AmmoMagazinesId.Length];
                for (var j = 0; j < ammoMags.Length; j++)
                {
                    ammoMags[j] = new MyObjectBuilder_AmmoMagazine()
                    {
                        SubtypeName = weapon.AmmoMagazinesId[j].SubtypeName
                    }
                }
                ;
                _ammoTypes[weapon] = ammoMags;
            }
            foreach (var mag in ammoMags)
            {
                if (inv.GetItemAmount(mag.GetObjectId(), mag.Flags) > _thresholdAmount)
                {
                    continue;
                }
                inv.AddItems(_addAmount, mag);
            }
        }
        _updateId = (_updateId + 1) % spread;
    }
        public override void OnAddedToContainer()
        {
            base.OnAddedToContainer();
            _weapon = WeaponShortcuts.GetWeaponDefinition(Entity);
            if (_weapon != null && _weapon.HasAmmoMagazines())
            {
                _weaponAmmoMags = new MyObjectBuilder_PhysicalObject[_weapon.AmmoMagazinesId.Length];
                for (var i = 0; i < _weaponAmmoMags.Length; i++)
                {
                    _weaponAmmoMags[i] =
                        new MyObjectBuilder_AmmoMagazine()
                    {
                        SubtypeName = _weapon.AmmoMagazinesId[i].SubtypeName
                    }
                }
                ;
            }

            NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME;
        }
        private void AddItemsToInventory(int variant)
        {
            bool overrideCheck = variant != 0;
            bool spawnNonfitting = variant != 0;
            bool componentsOnly = variant == 2;

            var invObject = MySession.Static.ControlledEntity as MyEntity;
            if (invObject != null && invObject.HasInventory)
            {
                System.Diagnostics.Debug.Assert(invObject.GetInventory(0) as MyInventory != null, "Null or unexpected inventory type returned!");
                MyInventory inventory = invObject.GetInventory(0) as MyInventory;
                //inventory.Clear();

                if (!componentsOnly)
                {
                    MyObjectBuilder_AmmoMagazine ammoMag = new MyObjectBuilder_AmmoMagazine();
                    ammoMag.SubtypeName = "NATO_5p56x45mm";
                    ammoMag.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag, false, 5);

                    MyObjectBuilder_AmmoMagazine ammoMag2 = new MyObjectBuilder_AmmoMagazine();
                    ammoMag2.SubtypeName = "NATO_25x184mm";
                    ammoMag2.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag2, false);

                    MyObjectBuilder_AmmoMagazine ammoMag3 = new MyObjectBuilder_AmmoMagazine();
                    ammoMag3.SubtypeName = "Missile200mm";
                    ammoMag3.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag3, false);


                    AddItems(inventory, CreateGunContent("AutomaticRifleItem"), false);
                    AddItems(inventory, CreateGunContent("WelderItem"), false);
                    AddItems(inventory, CreateGunContent("AngleGrinderItem"), false);
                    AddItems(inventory, CreateGunContent("HandDrillItem"), false);
                }

                // Add all components
                foreach (var definition in MyDefinitionManager.Static.GetAllDefinitions())
                {
                    if (definition.Id.TypeId != typeof(MyObjectBuilder_Component) &&
                        definition.Id.TypeId != typeof(MyObjectBuilder_Ingot))
                        continue;

                    if (componentsOnly && definition.Id.TypeId != typeof(MyObjectBuilder_Component))
                        continue;

                    if (componentsOnly && ((MyComponentDefinition)definition).Volume > 0.05f)
                        continue;

                    var component = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definition.Id.TypeId);
                    component.SubtypeName = definition.Id.SubtypeName;
                    if (!AddItems(inventory, component, overrideCheck, 1) && spawnNonfitting)
                    {
                        Matrix headMatrix = MySession.Static.ControlledEntity.GetHeadMatrix(true);
                        MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(1, component), headMatrix.Translation + headMatrix.Forward * 0.2f, headMatrix.Forward, headMatrix.Up, MySession.Static.ControlledEntity.Entity.Physics);
                    }
                }

                if (!componentsOnly)
                {
                    string[] ores;
                    MyDefinitionManager.Static.GetOreTypeNames(out ores);
                    foreach (var ore in ores)
                    {
                        var oreBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Ore>(ore);
                        if (!AddItems(inventory, oreBuilder, overrideCheck, 1) && spawnNonfitting)
                        {
                            Matrix headMatrix = MySession.Static.ControlledEntity.GetHeadMatrix(true);
                            MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(1, oreBuilder), headMatrix.Translation + headMatrix.Forward * 0.2f, headMatrix.Forward, headMatrix.Up, MySession.Static.ControlledEntity.Entity.Physics);
                        }
                    }
                }
            }
        }
        private void AddItemsToInventory(int variant)
        {
            bool overrideCheck   = variant != 0;
            bool spawnNonfitting = variant != 0;
            bool componentsOnly  = variant == 2;

            IMyInventoryOwner invObject = MySession.ControlledEntity as IMyInventoryOwner;

            if (invObject != null)
            {
                MyInventory inventory = invObject.GetInventory(0);
                //inventory.Clear();

                if (!componentsOnly)
                {
                    MyObjectBuilder_AmmoMagazine ammoMag = new MyObjectBuilder_AmmoMagazine();
                    ammoMag.SubtypeName      = "NATO_5p56x45mm";
                    ammoMag.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag, false, 5);

                    MyObjectBuilder_AmmoMagazine ammoMag2 = new MyObjectBuilder_AmmoMagazine();
                    ammoMag2.SubtypeName      = "NATO_25x184mm";
                    ammoMag2.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag2, false);

                    MyObjectBuilder_AmmoMagazine ammoMag3 = new MyObjectBuilder_AmmoMagazine();
                    ammoMag3.SubtypeName      = "Missile200mm";
                    ammoMag3.ProjectilesCount = 50;
                    AddItems(inventory, ammoMag3, false);


                    AddItems(inventory, CreateGunContent("AutomaticRifleItem"), false);
                    AddItems(inventory, CreateGunContent("WelderItem"), false);
                    AddItems(inventory, CreateGunContent("AngleGrinderItem"), false);
                    AddItems(inventory, CreateGunContent("HandDrillItem"), false);
                }

                // Add all components
                foreach (var definition in MyDefinitionManager.Static.GetAllDefinitions())
                {
                    if (definition.Id.TypeId != typeof(MyObjectBuilder_Component) &&
                        definition.Id.TypeId != typeof(MyObjectBuilder_Ingot))
                    {
                        continue;
                    }

                    if (componentsOnly && definition.Id.TypeId != typeof(MyObjectBuilder_Component))
                    {
                        continue;
                    }

                    if (componentsOnly && ((MyComponentDefinition)definition).Volume > 0.05f)
                    {
                        continue;
                    }

                    var component = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definition.Id.TypeId);
                    component.SubtypeName = definition.Id.SubtypeName;
                    if (!AddItems(inventory, component, overrideCheck, 1) && spawnNonfitting)
                    {
                        Matrix headMatrix = MySession.ControlledEntity.GetHeadMatrix(true);
                        MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(1, component), headMatrix.Translation + headMatrix.Forward * 0.2f, headMatrix.Forward, headMatrix.Up, MySession.ControlledEntity.Entity.Physics);
                    }
                }

                if (!componentsOnly)
                {
                    string[] ores;
                    MyDefinitionManager.Static.GetOreTypeNames(out ores);
                    foreach (var ore in ores)
                    {
                        var oreBuilder = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Ore>(ore);
                        if (!AddItems(inventory, oreBuilder, overrideCheck, 1) && spawnNonfitting)
                        {
                            Matrix headMatrix = MySession.ControlledEntity.GetHeadMatrix(true);
                            MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(1, oreBuilder), headMatrix.Translation + headMatrix.Forward * 0.2f, headMatrix.Forward, headMatrix.Up, MySession.ControlledEntity.Entity.Physics);
                        }
                    }
                }
            }
        }