コード例 #1
0
        public void UpdateItemAmount(InventoryItemEntity item, float newAmount)
        {
            InventoryDelta delta = new InventoryDelta();

            delta.item      = item;
            delta.oldAmount = item.Amount;
            delta.newAmount = newAmount;

            m_itemDeltaQueue.Enqueue(delta);

            Action action = InternalUpdateItemAmount;

            SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
        }
コード例 #2
0
        protected void InternalUpdateItemAmount()
        {
            try
            {
                if (m_itemDeltaQueue.Count == 0)
                {
                    return;
                }

                InventoryDelta itemDelta = m_itemDeltaQueue.Dequeue();

                float delta = itemDelta.newAmount - itemDelta.oldAmount;

                MyObjectBuilder_PhysicalObject physicalContent = itemDelta.item.ObjectBuilder.PhysicalContent;

                if (delta > 0)
                {
                    Object[] parameters = new object[] {
                        (MyFixedPoint)delta,
                        physicalContent,
                        -1
                    };

                    InvokeEntityMethod(BackingObject, InventoryAddItemAmountMethod, parameters);
                }
                else
                {
                    Type[] argTypes = new Type[3];
                    argTypes[0] = typeof(MyFixedPoint);
                    argTypes[1] = typeof(MyObjectBuilder_PhysicalObject);
                    argTypes[2] = typeof(bool);

                    Object[] parameters = new object[] {
                        (MyFixedPoint)(-delta),
                        physicalContent,
                        Type.Missing
                    };

                    InvokeEntityMethod(BackingObject, InventoryRemoveItemAmountMethod, parameters, argTypes);
                }
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
            }
        }
コード例 #3
0
		public void UpdateItemAmount(InventoryItemEntity item, float newAmount)
		{
			InventoryDelta delta = new InventoryDelta();
			delta.item = item;
			delta.oldAmount = item.Amount;
			delta.newAmount = newAmount;

			m_itemDeltaQueue.Enqueue(delta);

			Action action = InternalUpdateItemAmount;
			SandboxGameAssemblyWrapper.Instance.EnqueueMainGameAction(action);
		}