Ejemplo n.º 1
0
        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.º 2
0
        public void RemoveItemToProduce(MyFixedPoint amount, MyBlueprintToProduce blueprintInProduction, long senderEntityId)
        {
            SerializableDefinitionId blueprintId = blueprintInProduction.Blueprint.Id;

            int itemId = m_itemsToProduce.IndexOf(blueprintInProduction);

            if (m_itemsToProduce.IsValidIndex(itemId))
            {
                MyMultiplayer.RaiseEvent(this, x => x.RemoveItemToProduce_Request, amount, blueprintId, senderEntityId, itemId);
            }
        }
Ejemplo n.º 3
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!");
            }
        }
        public void RemoveItemToProduce(MyFixedPoint amount, MyBlueprintToProduce blueprintInProduction, long senderEntityId)
        {
            SerializableDefinitionId blueprintId = blueprintInProduction.Blueprint.Id;
            
            int itemId = m_itemsToProduce.IndexOf(blueprintInProduction);

            if (m_itemsToProduce.IsValidIndex(itemId))
            {
                MyMultiplayer.RaiseEvent(this, x => x.RemoveItemToProduce_Request, amount, blueprintId, senderEntityId, itemId);
            }
        }
        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);
            }
        }