Ejemplo n.º 1
0
        private float priceWorth(MyCubeBlockDefinition.Component component, string priceType)
        {
            MyBlueprintDefinitionBase bpDef = MyDefinitionManager.Static.TryGetBlueprintDefinitionByResultId(component.Definition.Id);
            int   p     = 0;
            float price = 0;

            if (priceType == "Ingot")
            {
                for (p = 0; p < bpDef.Prerequisites.Length; p++)
                {
                    if (bpDef.Prerequisites[p].Id != null)
                    {
                        MyDefinitionBase oreDef = MyDefinitionManager.Static.GetDefinition(bpDef.Prerequisites[p].Id);
                        if (oreDef != null)
                        {
                            MyPhysicalItemDefinition ore = oreDef as MyPhysicalItemDefinition;
                            float amn = Math.Abs(ore.MinimumOfferAmount);
                            amn   = (float)Math.Round(amn * 2);
                            price = price + amn;
                            //MyVisualScriptLogicProvider.SendChatMessage(bpDef.Prerequisites[p].Id.ToString() + " - " + amn.ToString() + " SC");
                        }
                    }
                }
            }
            if (priceType == "Component")
            {
                float amn = Math.Abs(component.Definition.MinimumOfferAmount);
                //MyAPIGateway.Utilities.ShowNotification(amn.ToString(), 1, "White");
                amn   = (float)Math.Round(amn * 8);
                price = price + amn;
                //MyVisualScriptLogicProvider.SendChatMessage(component.Definition.Id.ToString() + " - " + amn.ToString() + " SC");
            }

            return(price);
        }
Ejemplo n.º 2
0
        public void AddQueueItemRequest(MyBlueprintDefinitionBase blueprint, MyFixedPoint ammount, int idx = -1)
        {
            SerializableDefinitionId id = (SerializableDefinitionId)blueprint.Id;
            EndpointId targetEndpoint   = new EndpointId();

            Sandbox.Engine.Multiplayer.MyMultiplayer.RaiseEvent <MyProductionBlock, int, SerializableDefinitionId, MyFixedPoint>(this, x => new Action <int, SerializableDefinitionId, MyFixedPoint>(x.OnAddQueueItemRequest), idx, id, ammount, targetEndpoint);
        }
 public MyRepairBlueprintToProduce(MyFixedPoint amount, MyBlueprintDefinitionBase blueprint, uint inventoryItemId, MyObjectBuilderType inventoryItemType, MyStringHash inventoryItemSubtypeId) : base(amount, blueprint)
 {
     System.Diagnostics.Debug.Assert(Blueprint is MyRepairBlueprintDefinition, "MyRepairBlueprintToProduce class should be used together with blueprints type of MyRepairBlueprintDefinition only!");
     InventoryItemId        = inventoryItemId;
     InventoryItemType      = inventoryItemType;
     InventoryItemSubtypeId = inventoryItemSubtypeId;
 }
Ejemplo n.º 4
0
        private void MissingRequiredItem_Implementation(SerializableDefinitionId blueprintId, SerializableDefinitionId missingItemId)
        {
            MyBlueprintDefinitionBase.Item missingItem = default(MyBlueprintDefinitionBase.Item);
            MyDefinitionId definitionId = missingItemId;
            bool           found        = false;

            MyBlueprintDefinitionBase blueprint = MyDefinitionManager.Static.GetBlueprintDefinition(blueprintId);

            if (blueprint == null)
            {
                System.Diagnostics.Debug.Fail("Couldn't find blueprint definition for: " + blueprintId);
                return;
            }

            foreach (var requiredItem in blueprint.Prerequisites)
            {
                if (requiredItem.Id == definitionId)
                {
                    missingItem = requiredItem;
                    found       = true;
                }
            }

            if (!found)
            {
                System.Diagnostics.Debug.Fail("Item " + definitionId + " wasn't found in blueprint " + blueprint);
            }

            var handler = MissingRequiredItem;

            if (handler != null && found)
            {
                handler(this, blueprint, missingItem);
            }
        }
        protected MyFixedPoint MaxAmountToFitInventory(MyBlueprintDefinitionBase definition)
        {
            var inventory = (Entity as MyEntity).GetInventory();

            if (inventory == null)
            {
                System.Diagnostics.Debug.Fail("Inventory was not found on the entity!");
                return(0);
            }

            var maxAmount = MyFixedPoint.MaxValue;

            float volumeToBeRemoved = 0;
            float massToBeRemoved   = 0;

            if (!MySession.Static.CreativeMode)
            {
                foreach (var item in definition.Prerequisites)
                {
                    float itemMass, itemVolume;
                    MyInventory.GetItemVolumeAndMass(item.Id, out itemMass, out itemVolume);
                    volumeToBeRemoved += itemVolume;
                    massToBeRemoved   += itemMass;
                }
            }

            foreach (var item in definition.Results)
            {
                var fittableAmount = inventory.ComputeAmountThatFits(item.Id, volumeToBeRemoved, massToBeRemoved);

                maxAmount = MyFixedPoint.Min(fittableAmount, maxAmount);
            }

            return(maxAmount);
        }
        public MyFixedPoint MaxProducableAmount(MyBlueprintDefinitionBase blueprintDefinition, bool raiseMissingRequiredItemEvent = false)
        {
            if (MySession.Static.CreativeMode)
            {
                return(MyFixedPoint.MaxValue);
            }

            var inventory = (Entity as MyEntity).GetInventory();

            if (inventory == null)
            {
                System.Diagnostics.Debug.Fail("Inventory was not found on the entity!");
                return(0);
            }

            MyFixedPoint maxProducableAmount = MyFixedPoint.MaxValue;

            foreach (var requiredItem in blueprintDefinition.Prerequisites)
            {
                var itemAmount       = inventory.GetItemAmount(requiredItem.Id, substitute: true);
                var producableAmount = MyFixedPoint.Floor((MyFixedPoint)((float)itemAmount / (float)requiredItem.Amount));
                maxProducableAmount = MyFixedPoint.Min(maxProducableAmount, producableAmount);
                if (maxProducableAmount == 0)
                {
                    if (raiseMissingRequiredItemEvent)
                    {
                        RaiseEvent_MissingRequiredItem(blueprintDefinition, requiredItem);
                    }
                    return(maxProducableAmount);
                }
            }

            return(maxProducableAmount);
        }
Ejemplo n.º 7
0
        private StateEnum CheckInventory(MyBlueprintDefinitionBase blueprint)
        {
            var amountMult = (MyFixedPoint)(1.0f / MySession.Static.AssemblerEfficiencyMultiplier);

            if (DisassembleEnabled)
            {
                if (!CheckInventoryCapacity(InputInventory, blueprint.Prerequisites, amountMult))
                {
                    return(StateEnum.InventoryFull);
                }

                if (!CheckInventoryContents(OutputInventory, blueprint.Results, 1))
                {
                    return(StateEnum.MissingItems);
                }
            }
            else
            {
                if (!CheckInventoryCapacity(OutputInventory, blueprint.Results, 1))
                {
                    return(StateEnum.InventoryFull);
                }

                if (!CheckInventoryContents(InputInventory, blueprint.Prerequisites, amountMult))
                {
                    return(StateEnum.MissingItems);
                }
            }

            return(StateEnum.Ok);
        }
        private void AddItemToProduce_Implementation(MyFixedPoint amount, SerializableDefinitionId blueprintId)
        {
            System.Diagnostics.Debug.Assert(amount > 0, "Adding zero or negative amount!");

            MyBlueprintDefinitionBase blueprint = MyDefinitionManager.Static.GetBlueprintDefinition(blueprintId);

            if (blueprint == null)
            {
                System.Diagnostics.Debug.Fail("Couldn't find blueprint definition for: " + blueprintId);
                return;
            }

            MyBlueprintToProduce itemToProduce = m_itemsToProduce.Find(x => x.Blueprint == blueprint);

            if (itemToProduce != null)
            {
                itemToProduce.Amount = itemToProduce.Amount + amount;
            }
            else
            {
                itemToProduce = new MyBlueprintToProduce(amount, blueprint);
                m_itemsToProduce.Add(itemToProduce);
            }

            var handler = ProductionChanged;

            if (handler != null)
            {
                handler(this, itemToProduce);
            }
        }
Ejemplo n.º 9
0
        protected void RemovePrereqItemsFromInventory(MyBlueprintDefinitionBase definition, MyFixedPoint amountMult)
        {
            System.Diagnostics.Debug.Assert(Sync.IsServer, "This method should be called only on server!");

            if (!Sync.IsServer)
            {
                return;
            }

            if (MySession.Static.CreativeMode)
            {
                return;
            }

            var inventory = (Entity as MyEntity).GetInventory();

            if (inventory == null)
            {
                System.Diagnostics.Debug.Fail("Inventory was not found on the entity!");
                return;
            }

            foreach (var reqItem in definition.Prerequisites)
            {
                var amountToRemove = reqItem.Amount * amountMult;

                System.Diagnostics.Debug.Assert(amountToRemove <= inventory.GetItemAmount(reqItem.Id), "Trying to remove higher amount than is present in inventory!");

                var removed = inventory.RemoveItemsOfType(amountToRemove, reqItem.Id);

                System.Diagnostics.Debug.Assert(removed == amountToRemove, "Removed different amount, than expected!");
            }
        }
Ejemplo n.º 10
0
        protected virtual void AddProducedItemToInventory(MyBlueprintDefinitionBase definition, MyFixedPoint amountMult)
        {
            System.Diagnostics.Debug.Assert(Sync.IsServer, "This method should be called only on server!");

            if (!Sync.IsServer)
            {
                return;
            }

            var inventory = (Entity as MyEntity).GetInventory();

            if (inventory == null)
            {
                System.Diagnostics.Debug.Fail("Inventory was not found on the entity!");
                return;
            }

            foreach (var prodItem in definition.Results)
            {
                var amountToAdd = prodItem.Amount * amountMult;

                var inventoryItem = CreateInventoryItem(prodItem.Id, amountToAdd);

                var resultAdded = inventory.Add(inventoryItem, inventoryItem.Amount);

                System.Diagnostics.Debug.Assert(resultAdded, "Result of adding is false!");
            }
        }
Ejemplo n.º 11
0
        private void ChangeRequirementsToResults(MyBlueprintDefinitionBase queueItem, MyFixedPoint blueprintAmount)
        {
            Debug.Assert(Sync.IsServer);

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

            foreach (var prerequisite in queueItem.Prerequisites)
            {
                var obPrerequisite     = (MyObjectBuilder_PhysicalObject)Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(prerequisite.Id);
                var prerequisiteAmount = blueprintAmount * prerequisite.Amount;
                InputInventory.RemoveItemsOfType(prerequisiteAmount, obPrerequisite);
            }

            foreach (var result in queueItem.Results)
            {
                var resultId     = result.Id;
                var obResult     = (MyObjectBuilder_PhysicalObject)Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(resultId);
                var resultAmount = blueprintAmount * result.Amount * m_refineryDef.MaterialEfficiency * UpgradeValues["Effectiveness"];
                OutputInventory.AddItems(resultAmount, obResult);
            }

            RemoveFirstQueueItemAnnounce(blueprintAmount);
        }
Ejemplo n.º 12
0
        private void ChangeRequirementsToResults(MyBlueprintDefinitionBase queueItem, MyFixedPoint blueprintAmount)
        {
            Debug.Assert(Sync.IsServer);

            Debug.Assert(m_refineryDef != null, "m_refineryDef shouldn't be null!!!");

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

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

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

            if (blueprintAmount == 0)
            {
                return;
            }

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

            foreach (var result in queueItem.Results)
            {
                var resultId = result.Id;
                var obResult = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(resultId);
                if (obResult == null)
                {
                    Debug.Fail("obResult shouldn't be null!!!");
                    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);
        }
        protected override void AddProducedItemToInventory(MyBlueprintDefinitionBase definition, MyFixedPoint amountMult)
        {
            System.Diagnostics.Debug.Assert(Sync.IsServer, "This method should be called only on server!");

            if (!Sync.IsServer)
            {
                return;
            }

            MyInventory interactingInventory = null;
            MyInventory innerInventory       = (Entity as MyEntity).GetInventory();
            bool        resultAdded          = false;

            if (m_lastEntityInteraction != null)
            {
                interactingInventory = (m_lastEntityInteraction as MyEntity).GetInventory();

                if (interactingInventory != null)
                {
                    foreach (var prodItem in definition.Results)
                    {
                        var amountToAdd = prodItem.Amount * amountMult;

                        var inventoryItem = CreateInventoryItem(prodItem.Id, amountToAdd);

                        resultAdded = interactingInventory.Add(inventoryItem, inventoryItem.Amount);

                        if (!resultAdded)
                        {
                            resultAdded = innerInventory.Add(inventoryItem, inventoryItem.Amount);
                        }

                        System.Diagnostics.Debug.Assert(resultAdded, "Result of adding is false!");
                    }
                }
            }
            else
            {
                if (innerInventory == null)
                {
                    System.Diagnostics.Debug.Fail("Inventory was not found on the entity!");
                    return;
                }

                foreach (var prodItem in definition.Results)
                {
                    var amountToAdd = prodItem.Amount * amountMult;

                    var inventoryItem = CreateInventoryItem(prodItem.Id, amountToAdd);

                    resultAdded = innerInventory.Add(inventoryItem, inventoryItem.Amount);

                    System.Diagnostics.Debug.Assert(resultAdded, "Result of adding is false!");
                }
            }

            m_lastEntityInteraction = null;
        }
Ejemplo n.º 14
0
 public static BlueprintDefinition ToBlueprintDefinition(this MyBlueprintDefinitionBase bp)
 {
     return(new BlueprintDefinition()
     {
         DisplayName = bp.DisplayNameText,
         Prerequisites = bp.Prerequisites.Select(i => i.ToAmountedDefinition()).ToList(),
         Results = bp.Results.Select(i => i.ToAmountedDefinition()).ToList(),
     });
 }
Ejemplo n.º 15
0
        protected virtual void InsertQueueItem(int idx, MyBlueprintDefinitionBase blueprint, MyFixedPoint amount)
        {
            Debug.Assert(idx <= m_queue.Count);
            Debug.Assert(CanUseBlueprint(blueprint));
            Debug.Assert(amount > 0);

            QueueItem item = new QueueItem();

            item.Amount    = amount;
            item.Blueprint = blueprint;

            if (CanUseBlueprint(item.Blueprint))
            {
                if (m_queue.IsValidIndex(idx) && m_queue[idx].Blueprint == item.Blueprint)
                {
                    // Increase amount if there is same kind of item at this index.
                    item.Amount += m_queue[idx].Amount;
                    item.ItemId  = m_queue[idx].ItemId;
                    m_queue[idx] = item;
                }
                else if (m_queue.Count > 0 && (idx >= m_queue.Count || idx == -1) && m_queue[m_queue.Count - 1].Blueprint == item.Blueprint)
                {
                    // Add to the last item in the queue if it is the same.
                    item.Amount += m_queue[m_queue.Count - 1].Amount;
                    item.ItemId  = m_queue[m_queue.Count - 1].ItemId;
                    m_queue[m_queue.Count - 1] = item;
                }
                else
                {
                    if (idx == -1)
                    {
                        idx = m_queue.Count;
                    }

                    if (idx > m_queue.Count)
                    {
                        MyLog.Default.WriteLine("Production block.InsertQueueItem: Index out of bounds, desync!");
                        idx = m_queue.Count;
                    }

                    // Reset timer when adding first item. Otherwise we might produce it faster than possible.
                    if (m_queue.Count == 0)
                    {
                        m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                    }

                    // Put new item into the queue with given amount and type.
                    item.ItemId = NextItemId;
                    m_queue.Insert(idx, item);
                }

                UpdatePower();

                OnQueueChanged();
            }
        }
Ejemplo n.º 16
0
 private void EnqueueBlueprint(MyBlueprintDefinitionBase blueprint, MyFixedPoint amount)
 {
     m_blueprintCache.Clear();
     blueprint.GetBlueprints(m_blueprintCache);
     foreach (var entry in m_blueprintCache)
     {
         m_selectedAssembler.InsertQueueItemRequest(-1, entry.Blueprint, entry.Amount * amount);
     }
     m_blueprintCache.Clear();
 }
Ejemplo n.º 17
0
 public bool CanUseBlueprint(MyBlueprintDefinitionBase blueprint)
 {
     foreach (var blueprintClass in ProductionBlockDefinition.BlueprintClasses)
     {
         if (blueprintClass.ContainsBlueprint(blueprint))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 18
0
        private void OnAddQueueItemRequest(int idx, SerializableDefinitionId defId, MyFixedPoint ammount)
        {
            MyBlueprintDefinitionBase blueprintDefinition = MyDefinitionManager.Static.GetBlueprintDefinition(defId);

            if (blueprintDefinition != null)
            {
                this.InsertQueueItem(idx, blueprintDefinition, ammount);
                EndpointId targetEndpoint = new EndpointId();
                Sandbox.Engine.Multiplayer.MyMultiplayer.RaiseEvent <MyProductionBlock, int, SerializableDefinitionId, MyFixedPoint>(this, x => new Action <int, SerializableDefinitionId, MyFixedPoint>(x.OnAddQueueItemSuccess), idx, defId, ammount, targetEndpoint);
            }
        }
            /// <summary>
            /// idx - index to insert (-1 = last)
            /// </summary>
            public void AddQueueItemRequest(MyBlueprintDefinitionBase blueprint, MyFixedPoint amount, int idx = -1)
            {
                Debug.Assert(idx != -2, "No longer supported.");
                var msg = new AddQueueItemMsg();

                msg.Idx                = idx;
                msg.Blueprint          = blueprint.Id;
                msg.Amount             = amount;
                msg.ProductionEntityId = Block.EntityId;

                Sync.Layer.SendMessageToServer(ref msg);
            }
Ejemplo n.º 20
0
        private void ShowBlueprintComponents(MyBlueprintDefinitionBase blueprint, MyFixedPoint amount)
        {
            m_materialsList.Clear();
            if (blueprint == null)
            {
                return;
            }

            AddComponentPrerequisites(blueprint, amount, m_requiredCountCache);
            FillMaterialList(m_requiredCountCache);
            m_requiredCountCache.Clear();
        }
Ejemplo n.º 21
0
 protected override void InsertQueueItem(int idx, MyBlueprintDefinitionBase blueprint, MyFixedPoint amount)
 {
     if (idx == 0)
     {
         var queueItem = TryGetFirstQueueItem();
         if (queueItem.HasValue && queueItem.Value.Blueprint != blueprint)
         {
             CurrentProgress = 0f;
         }
     }
     base.InsertQueueItem(idx, blueprint, amount);
 }
Ejemplo n.º 22
0
 public override void UpdateCurrentItemStatus(float statusDelta)
 {
     if (base.IsProducing)
     {
         MyCraftingComponentBase.MyBlueprintToProduce itemToProduce = base.GetItemToProduce(base.m_currentItem);
         if (itemToProduce != null)
         {
             MyBlueprintDefinitionBase blueprint = itemToProduce.Blueprint;
             base.m_currentItemStatus = Math.Min((float)1f, (float)(base.m_currentItemStatus + ((statusDelta * base.m_craftingSpeedMultiplier) / (blueprint.BaseProductionTimeInSeconds * 1000f))));
         }
     }
 }
Ejemplo n.º 23
0
        private void RemoveItemToProduce_Implementation(MyFixedPoint amount, SerializableDefinitionId blueprintId, int itemId = -1)
        {
            System.Diagnostics.Debug.Assert(amount > 0, "Removing zero or negative amount!");

            MyBlueprintDefinitionBase blueprint = MyDefinitionManager.Static.GetBlueprintDefinition(blueprintId);

            if (blueprint == null)
            {
                System.Diagnostics.Debug.Fail("Couldn't find blueprint definition for: " + blueprintId);
                return;
            }

            MyBlueprintToProduce removingItem;
            MyBlueprintToProduce currentItem = GetCurrentItemInProduction();

            if (m_itemsToProduce.IsValidIndex(itemId))
            {
                removingItem = m_itemsToProduce[itemId];
                System.Diagnostics.Debug.Assert(removingItem.Blueprint == blueprint, "The item was retrieved with index, but the passed blueprint don't match items blueprint!");
            }
            else
            {
                removingItem = m_itemsToProduce.Find(x => x.Blueprint == blueprint);
            }

            if (removingItem != null)
            {
                System.Diagnostics.Debug.Assert(removingItem.Amount - amount >= 0, "Trying to remove more amount, than was set to be produced!");

                removingItem.Amount = removingItem.Amount - amount;

                if (removingItem.Amount <= 0)
                {
                    m_itemsToProduce.Remove(removingItem);
                }

                if (currentItem == removingItem && (m_currentItemStatus >= 1.0f || removingItem.Amount == 0))
                {
                    SelectItemToProduction();
                }

                var handler = ProductionChanged;
                if (handler != null)
                {
                    handler(this, removingItem);
                }
            }
            else
            {
                // On MP it can easily happen that we are removing an item that was already produced on the server, so don't assert in that case
                System.Diagnostics.Debug.Assert(Sync.Clients.Count != 0, "Trying to remove item from production, but item wasn't found!");
            }
        }
Ejemplo n.º 24
0
 protected virtual unsafe void InsertQueueItem(int idx, MyBlueprintDefinitionBase blueprint, MyFixedPoint amount)
 {
     if (this.CanUseBlueprint(blueprint))
     {
         QueueItem item = new QueueItem {
             Amount    = amount,
             Blueprint = blueprint
         };
         if (this.m_queue.IsValidIndex <QueueItem>(idx) && ReferenceEquals(this.m_queue[idx].Blueprint, item.Blueprint))
         {
             MyFixedPoint *pointPtr1 = (MyFixedPoint *)ref item.Amount;
             pointPtr1[0] += this.m_queue[idx].Amount;
             item.ItemId   = this.m_queue[idx].ItemId;
             if ((this.m_currentQueueItem != null) && (this.m_queue[idx].ItemId == this.m_currentQueueItem.Value.ItemId))
             {
                 this.m_currentQueueItem = new QueueItem?(item);
             }
             this.m_queue[idx] = item;
         }
         else if (((this.m_queue.Count > 0) && ((idx >= this.m_queue.Count) || (idx == -1))) && ReferenceEquals(this.m_queue[this.m_queue.Count - 1].Blueprint, item.Blueprint))
         {
             MyFixedPoint *pointPtr2 = (MyFixedPoint *)ref item.Amount;
             pointPtr2[0] += this.m_queue[this.m_queue.Count - 1].Amount;
             item.ItemId   = this.m_queue[this.m_queue.Count - 1].ItemId;
             if ((this.m_currentQueueItem != null) && (this.m_queue[this.m_queue.Count - 1].ItemId == this.m_currentQueueItem.Value.ItemId))
             {
                 this.m_currentQueueItem = new QueueItem?(item);
             }
             this.m_queue[this.m_queue.Count - 1] = item;
         }
         else
         {
             if (idx == -1)
             {
                 idx = this.m_queue.Count;
             }
             if (idx > this.m_queue.Count)
             {
                 MyLog.Default.WriteLine("Production block.InsertQueueItem: Index out of bounds, desync!");
                 idx = this.m_queue.Count;
             }
             if (this.m_queue.Count == 0)
             {
                 this.m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
             }
             item.ItemId = this.NextItemId;
             this.m_queue.Insert(idx, item);
         }
         this.UpdatePower();
         this.OnQueueChanged();
     }
 }
Ejemplo n.º 25
0
        private static void AddComponentPrerequisites(MyBlueprintDefinitionBase blueprint, MyFixedPoint multiplier, Dictionary <MyDefinitionId, MyFixedPoint> outputAmounts)
        {
            foreach (var prerequisite in blueprint.Prerequisites)
            {
                if (!outputAmounts.ContainsKey(prerequisite.Id))
                {
                    outputAmounts[prerequisite.Id] = 0;
                }

                var amountMult = (MyFixedPoint)(1.0f / MySession.Static.AssemblerEfficiencyMultiplier);
                outputAmounts[prerequisite.Id] += prerequisite.Amount * multiplier * amountMult;
            }
        }
Ejemplo n.º 26
0
        public MyFixedPoint ComputeAmountThatFits(MyBlueprintDefinitionBase blueprint)
        {
            if (!MyPerGameSettings.ConstrainInventory())
                return MyFixedPoint.MaxValue;

            var amountThatFits = (MaxVolume - m_currentVolume) * (1.0f / blueprint.OutputVolume);
            amountThatFits = MyFixedPoint.Max(amountThatFits, 0); // In case we added more than we can carry using debug keys.

            if (blueprint.Atomic)
                amountThatFits = MyFixedPoint.Floor(amountThatFits);

            return amountThatFits;
        }
            public void AddQueueItemAnnounce(MyBlueprintDefinitionBase blueprint, MyFixedPoint amount, int idx = -1)
            {
                Debug.Assert(idx != -2, "No longer supported.");
                Debug.Assert(Sync.IsServer);
                var msg = new AddQueueItemMsg();

                msg.Idx                = idx;
                msg.Blueprint          = blueprint.Id;
                msg.Amount             = amount;
                msg.ProductionEntityId = Block.EntityId;

                Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
            }
Ejemplo n.º 28
0
 private void ChangeRequirementsToResults(MyBlueprintDefinitionBase queueItem, MyFixedPoint blueprintAmount)
 {
     if (this.m_refineryDef == null)
     {
         MyLog.Default.WriteLine("m_refineryDef shouldn't be null!!!" + this);
     }
     else if (Sync.IsServer && (((MySession.Static != null) && ((queueItem != null) && ((queueItem.Prerequisites != null) && ((base.OutputInventory != null) && ((base.InputInventory != null) && (queueItem.Results != null)))))) && (this.m_refineryDef != null)))
     {
         if (!MySession.Static.CreativeMode)
         {
             MyFixedPoint point1 = MyFixedPoint.Min(base.OutputInventory.ComputeAmountThatFits(queueItem), blueprintAmount);
             blueprintAmount = point1;
         }
         if (blueprintAmount != 0)
         {
             foreach (MyBlueprintDefinitionBase.Item item in queueItem.Prerequisites)
             {
                 MyObjectBuilder_PhysicalObject objectBuilder = MyObjectBuilderSerializer.CreateNewObject((SerializableDefinitionId)item.Id) as MyObjectBuilder_PhysicalObject;
                 if (objectBuilder == null)
                 {
                     MyLog.Default.WriteLine("obPrerequisite shouldn't be null!!! " + this);
                 }
                 else
                 {
                     float num2 = ((float)blueprintAmount) * ((float)item.Amount);
                     base.InputInventory.RemoveItemsOfType((MyFixedPoint)num2, objectBuilder, false, false);
                     MyFixedPoint amount = base.InputInventory.GetItemAmount(item.Id, MyItemFlags.None, false);
                     if (amount < ((MyFixedPoint)0.01f))
                     {
                         base.InputInventory.RemoveItemsOfType(amount, item.Id, MyItemFlags.None, false);
                     }
                 }
             }
             foreach (MyBlueprintDefinitionBase.Item item2 in queueItem.Results)
             {
                 MyObjectBuilder_PhysicalObject objectBuilder = MyObjectBuilderSerializer.CreateNewObject((SerializableDefinitionId)item2.Id) as MyObjectBuilder_PhysicalObject;
                 if (objectBuilder == null)
                 {
                     MyLog.Default.WriteLine("obResult shouldn't be null!!! " + this);
                 }
                 else
                 {
                     float        num3   = (((float)item2.Amount) * this.m_refineryDef.MaterialEfficiency) * base.UpgradeValues["Effectiveness"];
                     MyFixedPoint amount = (MyFixedPoint)(((float)blueprintAmount) * num3);
                     base.OutputInventory.AddItems(amount, objectBuilder);
                 }
             }
             base.RemoveFirstQueueItemAnnounce(blueprintAmount, 0f);
         }
     }
 }
        protected void RemovePrereqItemsFromInventory(MyBlueprintDefinitionBase definition, MyFixedPoint amountMult)
        {
            System.Diagnostics.Debug.Assert(Sync.IsServer, "This method should be called only on server!");

            if (!Sync.IsServer)
            {
                return;
            }

            if (MySession.Static.CreativeMode)
            {
                return;
            }

            var inventory = (Entity as MyEntity).GetInventory();

            if (inventory == null)
            {
                System.Diagnostics.Debug.Fail("Inventory was not found on the entity!");
                return;
            }

            foreach (var reqItem in definition.Prerequisites)
            {
                MyFixedPoint   amountToRemove = reqItem.Amount * amountMult;
                MyDefinitionId itemId         = reqItem.Id;
                MyFixedPoint   removed        = 0;

                if (MySessionComponentEquivalency.Static != null && MySessionComponentEquivalency.Static.HasEquivalents(itemId))
                {
                    MyFixedPoint amountRemaining = amountToRemove;
                    var          eqGroup         = MySessionComponentEquivalency.Static.GetEquivalents(itemId);
                    foreach (var element in eqGroup)
                    {
                        MyFixedPoint removedThisItem = inventory.RemoveItemsOfType(amountRemaining, element);
                        amountRemaining -= removedThisItem;
                        removed         += removedThisItem;
                        if (amountRemaining == 0)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    System.Diagnostics.Debug.Assert(amountToRemove <= inventory.GetItemAmount(reqItem.Id, substitute: true), "Trying to remove higher amount than is present in inventory!");
                    removed += inventory.RemoveItemsOfType(amountToRemove, itemId);
                }
                System.Diagnostics.Debug.Assert(removed == amountToRemove, "Removed different amount, than expected!");
            }
        }
Ejemplo n.º 30
0
        public bool CanUseBlueprint(MyBlueprintDefinitionBase blueprint)
        {
            System.Diagnostics.Debug.Assert(blueprint != null, "Passing blueprint as null argument!");

            foreach (var blueprintClass in m_blueprintClasses)
            {
                if (blueprintClass.ContainsBlueprint(blueprint))
                {
                    return(true);
                }
            }

            return(false);
        }