コード例 #1
0
        static void OnTransferItemsRequest(ref TransferItemsMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId) || !MyEntities.EntityExists(msg.DestOwnerEntityId))
            {
                return;
            }

            IMyInventoryOwner srcOwner  = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            IMyInventoryOwner destOwner = MyEntities.GetEntityById(msg.DestOwnerEntityId) as IMyInventoryOwner;
            MyInventory       src       = srcOwner.GetInventory(msg.InventoryIndex);
            MyInventory       dst       = destOwner.GetInventory(msg.DestInventoryIndex);

            TransferItemsInternal(src, dst, msg.itemId, msg.Spawn, msg.DestItemIndex, msg.Amount);
        }
コード例 #2
0
        private static TransferItemsMsg PrepareTransferItemMessage(MyInventory source, MyFixedPoint amount, uint itemId, MyInventory destination, int destinationIndex, bool spawn)
        {
            var msg = new TransferItemsMsg();

            msg.OwnerEntityId = source.Owner.EntityId;
            for (byte i = 0; i < source.Owner.InventoryCount; i++)
            {
                if (source.Owner.GetInventory(i).Equals(source))
                {
                    msg.InventoryIndex = i;
                    break;
                }
            }
            msg.itemId = itemId;
            msg.Amount = amount;
            msg.Spawn  = spawn;

            if (source.Equals(destination))
            {
                msg.DestOwnerEntityId  = msg.OwnerEntityId;
                msg.DestInventoryIndex = msg.InventoryIndex;
            }
            else
            {
                msg.DestOwnerEntityId = destination.Owner.EntityId;
                for (byte i = 0; i < destination.Owner.InventoryCount; i++)
                {
                    if (destination.Owner.GetInventory(i).Equals(destination))
                    {
                        msg.DestInventoryIndex = i;
                        break;
                    }
                }
            }
            msg.DestItemIndex = destinationIndex;
            return(msg);
        }
コード例 #3
0
        static void OnTransferItemsRequest(ref TransferItemsMsg msg, MyNetworkClient sender)
        {
            if (!MyEntities.EntityExists(msg.OwnerEntityId) || !MyEntities.EntityExists(msg.DestOwnerEntityId)) return;

            IMyInventoryOwner srcOwner = MyEntities.GetEntityById(msg.OwnerEntityId) as IMyInventoryOwner;
            IMyInventoryOwner destOwner = MyEntities.GetEntityById(msg.DestOwnerEntityId) as IMyInventoryOwner;
            MyInventory src = srcOwner.GetInventory(msg.InventoryIndex);
            MyInventory dst = destOwner.GetInventory(msg.DestInventoryIndex);

            TransferItemsInternal(src, dst, msg.itemId, msg.Spawn, msg.DestItemIndex, msg.Amount);
        }
コード例 #4
0
        private static TransferItemsMsg PrepareTransferItemMessage(MyInventory source, MyFixedPoint amount, uint itemId, MyInventory destination, int destinationIndex, bool spawn)
        {
            var msg = new TransferItemsMsg();
            msg.OwnerEntityId = source.Owner.EntityId;
            for (byte i = 0; i < source.Owner.InventoryCount; i++)
            {
                if (source.Owner.GetInventory(i).Equals(source))
                {
                    msg.InventoryIndex = i;
                    break;
                }
            }
            msg.itemId = itemId;
            msg.Amount = amount;
            msg.Spawn = spawn;

            if (source.Equals(destination))
            {
                msg.DestOwnerEntityId = msg.OwnerEntityId;
                msg.DestInventoryIndex = msg.InventoryIndex;
            }
            else
            {
                msg.DestOwnerEntityId = destination.Owner.EntityId;
                for (byte i = 0; i < destination.Owner.InventoryCount; i++)
                {
                    if (destination.Owner.GetInventory(i).Equals(destination))
                    {
                        msg.DestInventoryIndex = i;
                        break;
                    }
                }
            }
            msg.DestItemIndex = destinationIndex;
            return msg;
        }