public MyPhysicalInventoryItem(MyObjectBuilder_InventoryItem item)
 {
     Debug.Assert(item.Amount > 0, "Creating inventory item with zero amount!");
     ItemId = 0;
     Amount = item.Amount;
     Scale = item.Scale;
     Content = item.PhysicalContent;
 }
 public MyPhysicalInventoryItem(MyFixedPoint amount, MyObjectBuilder_PhysicalObject content, float scale = 1)
 {
     Debug.Assert(amount > 0, "Creating inventory item with zero amount!");
     ItemId = 0;
     Amount = amount;
     Scale = scale;
     Content = content;
 }
Пример #3
0
        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 override bool CanStack(MyObjectBuilder_PhysicalObject a)
 {
     return false;
 }
Пример #5
0
        private void AddItemsInternal(MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, uint? itemId = null, int index = -1)
        {
            Debug.Assert(amount > 0, "Adding 0 amount of item.");

            OnBeforeContentsChanged();

            MyFixedPoint maxStack = MyFixedPoint.MaxValue;

            var adapter = MyInventoryItemAdapter.Static;
            adapter.Adapt(objectBuilder.GetObjectId());
            maxStack = adapter.MaxStackAmount;

            // If this object can't even stack with itself, the max stack size would be 1
            bool canStackSelf = objectBuilder.CanStack(objectBuilder);
            if (!canStackSelf)
                maxStack = 1;

            // This is hack if we don't have entity created yet, components weren't intialized yet and OB don't contains thi and thus updated health points
            // TODO: This would reaquire in future to init also components when creating OB for entities, no just init components when creating entity instances
            if (MyFakes.ENABLE_DURABILITY_COMPONENT)
            {
                FixDurabilityForInventoryItem(objectBuilder);
            }

            bool clone = false;

            // First try to add a new item at the specified index
            if (index >= 0)
            {
                if (index >= m_items.Count && index < MaxItemCount)
                {
                    amount = AddItemsToNewStack(amount, maxStack, objectBuilder, itemId);
                    clone = true; // We already used the original OB, so we have to clone next time
                }
                else if (index < m_items.Count)
                {
                    var item = m_items[index];
                    if (item.Content.CanStack(objectBuilder))
                    {
                        amount = AddItemsToExistingStack(index, amount, maxStack);
                    }
                    else if (m_items.Count < MaxItemCount)
                    {
                        amount = AddItemsToNewStack(amount, maxStack, objectBuilder, itemId, index);
                        clone = true; // We already used the original OB, so we have to clone next time
                    }
                }
            }

            // Then, distribute the remaining items to the rest of the inventory
            for (int i = 0; i < MaxItemCount; ++i)
            {
                if (i < m_items.Count)
                {
                    var item = m_items[i];
                    if (item.Content.CanStack(objectBuilder))
                    {
                        amount = AddItemsToExistingStack(i, amount, maxStack);
                    }
                }
                else
                {
                    amount = AddItemsToNewStack(amount, maxStack, (clone ? (MyObjectBuilder_PhysicalObject)objectBuilder.Clone() : objectBuilder), itemId);
                    clone = true;
                }

                if (amount == 0) break;
            }

            RefreshVolumeAndMass();
            VerifyIntegrity();
            OnContentsChanged();
        }
Пример #6
0
        // CH: TODO: Unused, might be useful for when we activate the tool durability
        /// <summary>
        /// TODO: This should be removed when we can initialize components on items that are stored in inventory but don't have entity with components initialized yet.
        /// DurabilityComponent is not created until Entity is initialized.
        /// </summary>
        private void FixDurabilityForInventoryItem(MyObjectBuilder_PhysicalObject objectBuilder)
        {
            MyPhysicalItemDefinition definition = null;
            if (MyDefinitionManager.Static.TryGetPhysicalItemDefinition(objectBuilder.GetId(), out definition))
            {
                // Physical gun objects have different types of entities, therefore also different definitions
                MyContainerDefinition containerDefinition = null;

                if (!MyComponentContainerExtension.TryGetContainerDefinition(definition.Id.TypeId, definition.Id.SubtypeId, out containerDefinition))
                {
                    if (objectBuilder.GetObjectId().TypeId == typeof(MyObjectBuilder_PhysicalGunObject))
                    {
                        var handItemDefinition = MyDefinitionManager.Static.TryGetHandItemForPhysicalItem(objectBuilder.GetObjectId());
                        if (handItemDefinition != null)
                        {
                            MyComponentContainerExtension.TryGetContainerDefinition(handItemDefinition.Id.TypeId, handItemDefinition.Id.SubtypeId, out containerDefinition);
                        }
                    }
                }

                if (containerDefinition != null)
                {
                    if (containerDefinition.HasDefaultComponent("MyObjectBuilder_EntityDurabilityComponent") && !objectBuilder.DurabilityHP.HasValue)
                        objectBuilder.DurabilityHP = 100f;
                }
            }
        }
 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;
     }
 }
Пример #8
0
        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;
        }
Пример #9
0
        /// <summary>
        /// Add maxNeeded amount of items into inventory.
        /// -If not maxNeeded could be added as amany as possible is added and the added amout is returned
        /// -If maxNeeded is less than MyFixedPoint can handle 0 is returned
        /// </summary>
        public static float AddMaxItems(this IMyInventory destInventory, float maxNeeded, MyObjectBuilder_PhysicalObject objectBuilder)
        {
            var maxNeededFP = (VRage.MyFixedPoint)maxNeeded;

            return((float)destInventory.AddMaxItems(maxNeededFP, objectBuilder));
        }
Пример #10
0
 void Sandbox.ModAPI.IMyInventory.RemoveItemsOfType(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, bool spawn)
 {
     RemoveItemsOfType(amount, objectBuilder, spawn);
 }
Пример #11
0
        private void SpawnOrePieces(MyFixedPoint amountItems, MyFixedPoint maxAmountPerDrop, Vector3 hitPosition, MyObjectBuilder_PhysicalObject oreObjBuilder, MyVoxelMaterialDefinition voxelMaterial)
        {
            if(Sync.IsServer == false)
            {
                return;
            }

            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)
            {
                //new: MyFixedPoint dropAmount = amountItems;
                //original: MyFixedPoint dropAmount = MyFixedPoint.Min(amountItems, maxAmountPerDrop);
                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(1.5f, 4);//original speed 5-8
                item.Physics.AngularVelocity = MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(4, 8);
            }
            ProfilerShort.End();
        }
Пример #12
0
        public static VRage.MyFixedPoint RemoveMaxItems(this IMyInventory srcInventory, VRage.MyFixedPoint maxRemoveFP, MyObjectBuilder_PhysicalObject objectBuilder)
        {
            var contentId = objectBuilder.GetObjectId();

            VRage.MyFixedPoint removedAmount = 0;
            if (!srcInventory.ContainItems(maxRemoveFP, objectBuilder))
            {
                maxRemoveFP = srcInventory.GetItemAmount(contentId);
            }
            if (maxRemoveFP > 0)
            {
                srcInventory.RemoveItemsOfType(maxRemoveFP, contentId, MyItemFlags.None, false);
                removedAmount = maxRemoveFP;
            }
            return(maxRemoveFP);
        }
Пример #13
0
 public bool RemoveItems(int count, MyObjectBuilder_PhysicalObject physicalObject) =>
 this.RemoveItems(count, physicalObject.GetId(), physicalObject.Flags);
Пример #14
0
        private void ChangeRequirementsToResults(MyBlueprintDefinitionBase queueItem, MyFixedPoint blueprintAmount)
        {
            Debug.Assert(Sync.IsServer);

            Debug.Assert(m_refineryDef != null, "m_refineryDef shouldn't be null!!!");
            if (m_refineryDef == null)
            {
                MyLog.Default.WriteLine("m_refineryDef shouldn't be null!!!" + this);
                return;
            }

            if(Sync.IsServer == false)
            {
                return;
            }

            if (MySession.Static == null || queueItem == null || queueItem.Prerequisites == null || OutputInventory == null || InputInventory == null || queueItem.Results == null || m_refineryDef == null) 
            {
                return;
            }

            if (!MySession.Static.CreativeMode)
            {
                blueprintAmount = MyFixedPoint.Min(OutputInventory.ComputeAmountThatFits(queueItem), blueprintAmount);
            }

            if (blueprintAmount == 0)
                return;

            foreach (var prerequisite in queueItem.Prerequisites)
            {
                MyObjectBuilder_PhysicalObject obPrerequisite = MyObjectBuilderSerializer.CreateNewObject(prerequisite.Id) as MyObjectBuilder_PhysicalObject;
                if (obPrerequisite == null)
                {
                    Debug.Fail("obPrerequisite shouldn't be null!!!");
                    MyLog.Default.WriteLine("obPrerequisite shouldn't be null!!! " + this);
                    continue;
                }
                var prerequisiteAmount = blueprintAmount * prerequisite.Amount;
                InputInventory.RemoveItemsOfType(prerequisiteAmount, obPrerequisite);
            }

            foreach (var result in queueItem.Results)
            {
                var resultId = result.Id;
                MyObjectBuilder_PhysicalObject obResult = MyObjectBuilderSerializer.CreateNewObject(resultId) as MyObjectBuilder_PhysicalObject;
                if (obResult == null)
                {
                    Debug.Fail("obResult shouldn't be null!!!");
                    MyLog.Default.WriteLine("obResult shouldn't be null!!! " + this);
                    continue;
                }
                var conversionRatio = result.Amount * m_refineryDef.MaterialEfficiency * UpgradeValues["Effectiveness"];
                if (conversionRatio > (MyFixedPoint)1.0f)
                {
                    conversionRatio = (MyFixedPoint)1.0f;
                }

                var resultAmount = blueprintAmount * conversionRatio;
                OutputInventory.AddItems(resultAmount, obResult);
            }

            RemoveFirstQueueItemAnnounce(blueprintAmount);
        }
 public bool RemoveItems(int count, MyObjectBuilder_PhysicalObject physicalObject)
 {
     return RemoveItems(count, physicalObject.GetId(), physicalObject.Flags);
 }
        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;
        }
Пример #17
0
        private void addtoContainer2(IMyCargoContainer FoundCargoCont, MyObjectBuilder_PhysicalObject item, int amount)
        {
            IMyInventory inventory = ((Sandbox.ModAPI.Ingame.IMyTerminalBlock)FoundCargoCont).GetInventory(0) as IMyInventory;

            inventory.AddItems(amount, item);
        }
Пример #18
0
 void VRage.Game.ModAPI.IMyInventory.AddItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, int index)
 {
     AddItems(amount, objectBuilder, null, index);
 }
Пример #19
0
 bool IMyInventory.ContainItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob)
 {
     return(ContainItems(amount, ob));
 }
Пример #20
0
        public static void Spawn(MyPhysicalItemDefinition itemDefinition, Vector3D translation, Vector3D forward, Vector3D up, int amount = 1, float scale = 1f)
        {
            MyObjectBuilder_PhysicalObject content = MyObjectBuilderSerializer.CreateNewObject(itemDefinition.Id.TypeId, itemDefinition.Id.SubtypeName) as MyObjectBuilder_PhysicalObject;

            Spawn(new MyPhysicalInventoryItem(amount, content, scale), translation, forward, up, null, null);
        }
Пример #21
0
 bool Sandbox.ModAPI.Interfaces.IMyInventory.ContainItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob)
 {
     return(ContainItems(amount, ob));
 }
Пример #22
0
        public static VRage.MyFixedPoint AddMaxItems(this IMyInventory destInventory, VRage.MyFixedPoint maxNeededFP, MyObjectBuilder_PhysicalObject objectBuilder)
        {
            var contentId = objectBuilder.GetObjectId();

            if (maxNeededFP <= 0)
            {
                return(0); //Amount to small
            }

            var maxPossible = destInventory.MaxFractionItemsAddable(maxNeededFP, contentId);

            if (maxPossible > 0)
            {
                destInventory.AddItems(maxPossible, objectBuilder);
                return(maxPossible);
            }
            else
            {
                return(0);
            }
        }
Пример #23
0
 void Sandbox.ModAPI.IMyInventory.AddItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, int index)
 {
     AddItems(amount, objectBuilder, index);
 }
 public override bool CanStack(MyObjectBuilder_PhysicalObject a)
 {
     return(false);
 }
Пример #25
0
        public override void UpdateBeforeSimulation()
        {
            if (MyAPIGateway.Multiplayer.IsServer == false)
            {
                return;
            }

            if (scriptInit == false)
            {
                scriptInit = true;


                var definitionId = new MyDefinitionId(typeof(MyObjectBuilder_Component), "Nadium_Radioactive");
                radioactive_nadium = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId);

                definitionId            = new MyDefinitionId(typeof(MyObjectBuilder_Ore), "Unknown_Element");
                electromagnetic_element = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId);

                definitionId    = new MyDefinitionId(typeof(MyObjectBuilder_Component), "composite_plate");
                composite_plate = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(definitionId);
            }

            tickTimer++;

            if (tickTimer < 180)
            {
                return;
            }

            tickTimer = 0;

            var playerList = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(playerList);

            if (playerList.Count == 0)
            {
                return;
            }

            foreach (var player in playerList)
            {
                if (player.IsBot == true)
                {
                    continue;
                }

                if (player.Character == null)
                {
                    continue;
                }

                float health = MyVisualScriptLogicProvider.GetPlayersHealth(player.IdentityId);
                float energy = MyVisualScriptLogicProvider.GetPlayersEnergyLevel(player.IdentityId);

                if (health <= 0)
                {
                    continue;
                }


                var          playerInv = player.Character.GetInventory();
                MyFixedPoint amount    = playerInv.GetItemAmount(electromagnetic_element);
                MyFixedPoint composite_plate_amount = playerInv.GetItemAmount(composite_plate);

                if (playerInv.ContainItems(1, radioactive_nadium) == true)
                {
                    MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, health - 5);
                    health = MyVisualScriptLogicProvider.GetPlayersHealth(player.IdentityId);
                    MyVisualScriptLogicProvider.ShowNotification(">>> WARNING RADIATION ALERT <<<\n\nToxic Nadium radiation detected\nIntensity: 2,5 Rad/s", 2000, "Red", player.IdentityId);
                    //MyVisualScriptLogicProvider.ShowNotificationToAll("WARNING RADIATION ALERT\n\nDetected toxic substance\n\nTriNadiumTaloxid-438", 2000, "White");
                }
                if (playerInv.ContainItems(1, composite_plate) == true)
                {
                    playerInv.RemoveItemsOfType(composite_plate_amount, composite_plate);
                    MyVisualScriptLogicProvider.SetPlayersHealth(player.IdentityId, health - 50);
                    health = MyVisualScriptLogicProvider.GetPlayersHealth(player.IdentityId);
                    MyVisualScriptLogicProvider.ShowNotification(">>> WARNING RADIATION ALERT <<<\n\nUnknown radiation detected\nIntensity: 50 Rad/s", 2000, "Red", player.IdentityId);
                }

                if (playerInv.ContainItems(1, electromagnetic_element) == true)
                {
                    if (energy <= 0)
                    {
                        MyVisualScriptLogicProvider.SetPlayersEnergyLevel(player.IdentityId, 0);
                    }
                    else
                    {
                        MyVisualScriptLogicProvider.SetPlayersEnergyLevel(player.IdentityId, energy - .04f);
                        playerInv.RemoveItemsOfType(amount, electromagnetic_element);
                        energy = MyVisualScriptLogicProvider.GetPlayersEnergyLevel(player.IdentityId);
                        MyVisualScriptLogicProvider.ShowNotification(">>> INTERNAL ENERGY LOSS DETECTED <<<", 2000, "White", player.IdentityId);
                    }
                }
            }
        }
Пример #26
0
        private void SpawnOrePieces(MyFixedPoint amountItems, MyFixedPoint maxAmountPerDrop, Vector3 hitPosition, MyObjectBuilder_PhysicalObject oreObjBuilder, MyVoxelMaterialDefinition voxelMaterial)
        {
            if (Sync.IsServer == false)
            {
                return;
            }

            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)
            {
                //new: MyFixedPoint dropAmount = amountItems;
                //original: MyFixedPoint dropAmount = MyFixedPoint.Min(amountItems, maxAmountPerDrop);
                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(1.5f, 4);//original speed 5-8
                item.Physics.AngularVelocity = MyUtils.GetRandomVector3Normalized() * MyUtils.GetRandomFloat(4, 8);
            }
            ProfilerShort.End();
        }
Пример #27
0
        private void UnmountInternal(float unmountAmount, MyConstructionStockpile outputStockpile = null, bool damageItems = false, bool useDefaultDeconstructEfficiency = false)
        {
            // We don't have to update functional state in this function, because it is done in the caller functions.
            // If you start using this function anywhere else, don't forget to update functional state yourself!

            float topIntegrity = GetTopComponentIntegrity();
            int   groupIndex   = (int)m_topGroupIndex;
            int   compIndex    = (int)m_topComponentIndex;

            // Continue removing components, until the to be removed component's health is larger than unmountAmount
            MyObjectBuilder_PhysicalObject componentBuilder = null;
            var scrapBuilder = MyFloatingObject.ScrapBuilder;

            while (unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems || useDefaultDeconstructEfficiency) >= topIntegrity)
            {
                Integrity     -= topIntegrity;
                unmountAmount -= topIntegrity;

                // In creative mode, the outputInventory should normally be null.
                // However, if we load the game from the realistic mode, it would not be necessarilly null.
                if (outputStockpile != null && MySession.Static.SurvivalMode)
                {
                    bool doDamage = damageItems && MyFakes.ENABLE_DAMAGED_COMPONENTS;
                    if (!damageItems || (doDamage && MyRandom.Instance.NextFloat() <= m_blockDefinition.Components[groupIndex].Definition.DropProbability))
                    {
                        componentBuilder = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(m_blockDefinition.Components[groupIndex].DeconstructItem.Id);
                        //componentBuilder = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_Component>();
                        //componentBuilder.SubtypeName = m_blockDefinition.Components[groupIndex].Definition.Id.SubtypeName;
                        if (doDamage)
                        {
                            componentBuilder.Flags |= MyItemFlags.Damaged;
                        }
                        if (!outputStockpile.AddItems(1, componentBuilder))
                        {
                            // TODO: Throw the items into space (although this branch should probably not happen)
                        }
                    }

                    MyComponentDefinition destroyedComponentDefinition = m_blockDefinition.Components[groupIndex].Definition;
                    if (MyFakes.ENABLE_SCRAP && damageItems && (MyRandom.Instance.NextFloat() < destroyedComponentDefinition.DropProbability))
                    {
                        outputStockpile.AddItems((int)(0.8f * destroyedComponentDefinition.Mass), scrapBuilder);
                    }
                }

                compIndex--;
                if (compIndex < 0)
                {
                    groupIndex--;
                    if (groupIndex < 0)
                    {
                        SetTopIndex(0, 0);
                        Integrity = 0.0f;
                        return;
                    }
                    else
                    {
                        compIndex = m_blockDefinition.Components[groupIndex].Count - 1;
                    }
                }


                topIntegrity = m_blockDefinition.Components[groupIndex].Definition.MaxIntegrity;
                SetTopIndex(groupIndex, compIndex);
            }

            // Damage the remaining component
            Integrity    -= unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems || useDefaultDeconstructEfficiency);
            topIntegrity -= unmountAmount * GetDeconstructionEfficiency(groupIndex, damageItems || useDefaultDeconstructEfficiency);

            if (topIntegrity < MOUNT_THRESHOLD)
            {
                Integrity   += MOUNT_THRESHOLD - topIntegrity;
                topIntegrity = MOUNT_THRESHOLD;
            }

            Debug.Assert(Integrity >= MOUNT_THRESHOLD, "Integrity inconsistent after a dismount of component stack");
        }
 public bool AddItems(MyInventory inventory, MyObjectBuilder_PhysicalObject obj, bool overrideCheck)
 {
     return AddItems(inventory, obj, overrideCheck, 1);
 }
Пример #29
0
 public bool ContainItems(MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob)
 {
     return(ContainItems(amount, ob.GetObjectId()));
 }
Пример #30
0
 public bool ContainItems(MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob)
 {
     if (ob == null) return false;
     return ContainItems(amount, ob.GetObjectId());
 }
Пример #31
0
        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);
            }
        }
Пример #32
0
 private void AffectAddBySurvival(ref MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder)
 {
     Debug.Assert(Sync.IsServer);
     MyFixedPoint space = ComputeAmountThatFits(objectBuilder.GetObjectId());
     if (space < amount)
     {
         Debug.Assert(Owner != null, "Owner can't be null!");
         if (Owner is MyCharacter)
         {
             MyCharacter c = (Owner as MyCharacter);
             Matrix m = c.GetHeadMatrix(true);
             MyEntity entity = MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(amount - space, objectBuilder), m.Translation, m.Forward, m.Up, c.Physics);
             entity.Physics.ApplyImpulse(m.Forward.Cross(m.Up), c.PositionComp.GetPosition());
         }
         amount = space;
     }
 }
Пример #33
0
 public void RemoveItemsOfType(MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, bool spawn = false)
 {
     TransferOrRemove(this, amount, objectBuilder.GetObjectId(), objectBuilder.Flags, null, spawn);
 }
Пример #34
0
        private MyFixedPoint AddItemsToNewStack(MyFixedPoint amount, MyFixedPoint maxStack, MyObjectBuilder_PhysicalObject objectBuilder, uint? itemId, int index = -1)
        {
            Debug.Assert(m_items.Count < MaxItemCount, "Adding a new item beyond the max item count limit!");

            MyFixedPoint addedAmount = MyFixedPoint.Min(amount, maxStack);

            var newItem = new MyPhysicalInventoryItem() { Amount = addedAmount, Scale = 1f, Content = objectBuilder };
            newItem.ItemId = itemId.HasValue ? itemId.Value : GetNextItemID();

            if (index >= 0 && index < m_items.Count)
            {
                //GR: Shift items not add to last position. Slower but more consistent with game logic
                m_items.Add(m_items[m_items.Count - 1]);
                for (int i = m_items.Count - 3; i >= index; i--)
                {
                    m_items[i+1] = m_items[i];
                }
                m_items[index] = newItem;
                
            }
            else
            {
                m_items.Add(newItem);
            }

            m_usedIds.Add(newItem.ItemId);

            if (Sync.IsServer)
                NotifyHudChangedInventoryItem(addedAmount, ref newItem, true);

            return amount - addedAmount;
        }
Пример #35
0
        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);
        }
Пример #36
0
 public bool RemoveItemsOfType(MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, bool spawn = false)
 {
     return TransferOrRemove(this, amount, objectBuilder.GetObjectId(), objectBuilder.Flags, null, spawn) == amount;
 }
Пример #37
0
        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;
        }
Пример #38
0
 bool IMyInventory.ContainItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob)
 {
     return ContainItems(amount, ob);
 }
Пример #39
0
        private 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.");

            OnBeforeContentsChanged();
            
            var newItem = new MyPhysicalInventoryItem() { Amount = amount, Scale = 1f, Content = objectBuilder };

            MyFixedPoint maxStack = MyFixedPoint.MaxValue;
            MyComponentDefinition compDef = null;
            if (MyPerGameSettings.Game == GameEnum.ME_GAME && MyDefinitionManager.Static.TryGetComponentDefinition(objectBuilder.GetId(), out compDef))
                maxStack = compDef.MaxStackAmount;

            // This is hack if we don't have entity created yet, components weren't intialized yet and OB don't contains thi and thus updated health points
            // TODO: This would reaquire in future to init also components when creating OB for entities, no just init components when creating entity instances
            if (MyFakes.ENABLE_DURABILITY_COMPONENT)
            {
                FixDurabilityForInventoryItem(newItem, objectBuilder);
            }

            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;
                        Debug.Assert(m_usedIds.Contains(newItem.ItemId));

                        newItem.Amount = newStackVal;
                        newItem.ItemId = GetNextItemID();
                        newItem.Content = objectBuilder.Clone() as MyObjectBuilder_PhysicalObject;
                        m_items.Add(newItem);
                        m_usedIds.Add(newItem.ItemId);
                    }
                    else
                    {
                        newItem.Amount += m_items[index].Amount;
                        newItem.ItemId = m_items[index].ItemId;
                        m_items[index] = newItem;
                        Debug.Assert(m_usedIds.Contains(newItem.ItemId));
                    }
                }
                else
                {
                    newItem.ItemId = GetNextItemID();
                    m_items.Insert(index, newItem);
                    m_usedIds.Add(newItem.ItemId);
                }
            }
            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;
                        Debug.Assert(m_usedIds.Contains(newItem.ItemId));
                        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();
                        m_items.Add(newItem);
                        m_usedIds.Add(newItem.ItemId);
                        newItem.Content = newItem.Content.Clone() as MyObjectBuilder_PhysicalObject;
                        Debug.Assert(newItem.Content != null);
                        itemId = null; // so we use NextItemID next time
                    }
                }
            }

            RefreshVolumeAndMass();

            VerifyIntegrity();

            OnContentsChanged();

            if (Sync.IsServer)
                NotifyHudPickedItem(amount, ref newItem, true);
        }
Пример #40
0
 void VRage.Game.ModAPI.IMyInventory.RemoveItemsOfType(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, bool spawn)
 {
     RemoveItemsOfType(amount, objectBuilder, spawn);
 }
 public bool AddItems(MyInventory inventory, MyObjectBuilder_PhysicalObject obj, bool overrideCheck)
 {
     return(AddItems(inventory, obj, overrideCheck, 1));
 }