Esempio n. 1
0
        public void UpdateItemAmount(InventoryItemEntity item, float newAmount)
        {
            if (BackingObject != null)
            {
                SandboxGameAssemblyWrapper.Instance.GameAction(new Action(delegate()
                {
                    IMyInventory myInventory = (IMyInventory)BackingObject;
                    if (newAmount == 0)
                    {
                        myInventory.RemoveItems(item.ItemId);
                    }
                    else if (newAmount > item.Amount)
                    {
                        myInventory.AddItems((MyFixedPoint)(newAmount - item.Amount), item.PhysicalContent, (int)item.ItemId);
                    }
                    else if (newAmount < item.Amount)
                    {
                        myInventory.RemoveItemsAt((int)item.ItemId, (MyFixedPoint)(item.Amount - newAmount), true);
                    }
                }));
            }

            /*
             * 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);
             */
        }
Esempio n. 2
0
        public bool DeleteEntry(InventoryItemEntity source)
        {
            if (BackingObject != null)
            {
                SandboxGameAssemblyWrapper.Instance.GameAction(new Action(delegate()
                {
                    IMyInventory myInventory = (IMyInventory)BackingObject;
                    myInventory.RemoveItems(source.ItemId);
                }));
            }

            return(true);

            /*
             * bool result = m_itemManager.DeleteEntry(source);
             * RefreshInventory();
             * return result;
             */
        }
Esempio n. 3
0
        public bool NewEntry(InventoryItemEntity source)
        {
            /*
             * m_itemManager.AddEntry<InventoryItemEntity>(NextItemId, source);
             *
             * NextItemId = NextItemId + 1;
             * //TODO - Figure out the right way to add new items
             * //Just updating an item amount doesn't seem to work right
             * UpdateItemAmount(source, source.Amount * 2);
             *
             * RefreshInventory();
             */

            if (BackingObject != null)
            {
                SandboxGameAssemblyWrapper.Instance.GameAction(new Action(delegate()
                {
                    IMyInventory inventory = (IMyInventory)BackingObject;
                    inventory.AddItems((MyFixedPoint)source.Amount, source.PhysicalContent);
                }));
            }

            return(true);
        }