Exemplo n.º 1
0
        private static void OnTransferItemsBaseMsg(ref TransferItemsBaseMsg msg, MyNetworkClient sender)
        {
            MyEntity sourceContainer      = MyEntities.GetEntityById(msg.SourceContainerId);
            MyEntity destinationContainer = MyEntities.GetEntityById(msg.DestinationContainerId);

            if (sourceContainer == null || destinationContainer == null)
            {
                Debug.Fail("Containers/Entities weren't found!");
                return;
            }

            MyInventoryBase sourceInventory      = sourceContainer.GetInventory(msg.SourceInventoryId);
            MyInventoryBase destinationInventory = destinationContainer.GetInventory(msg.DestinationInventoryId);

            if (sourceInventory == null || destinationInventory == null)
            {
                Debug.Fail("Inventories weren't found!");
                return;
            }

            var items = sourceInventory.GetItems();

            foreach (var item in items)
            {
                if (item.ItemId == msg.SourceItemId)
                {
                    MyInventoryBase.TransferItems(sourceInventory, destinationInventory, item, msg.Amount);
                    return;
                }
            }
        }
Exemplo n.º 2
0
        private static void OnTransferItemsBaseMsg(ref TransferItemsBaseMsg msg, MyNetworkClient sender)
        {
            MyEntity sourceContainer      = MyEntities.GetEntityById(msg.SourceContainerId);
            MyEntity destinationContainer = MyEntities.GetEntityById(msg.DestinationContainerId);

            if (sourceContainer == null || destinationContainer == null)
            {
                Debug.Fail("Containers/Entities weren't found!");
                return;
            }

            // CH: TODO: This breaks the object design, but so far we wouldn't be able to move items between other inventories than MyInventory anyway
            MyInventory     sourceInventory      = sourceContainer.GetInventory(msg.SourceInventoryId) as MyInventory;
            MyInventoryBase destinationInventory = destinationContainer.GetInventory(msg.DestinationInventoryId);

            if (sourceInventory == null || destinationInventory == null)
            {
                Debug.Fail("Inventories weren't found!");
                return;
            }

            var items = sourceInventory.GetItems();

            foreach (var item in items)
            {
                if (item.ItemId == msg.SourceItemId)
                {
                    MyInventoryBase.TransferItems(sourceInventory, destinationInventory, item, msg.Amount);
                    return;
                }
            }
        }