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; } } }
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; } } }
internal static void SendTransferItemsMessage(MyInventoryBase sourceInventory, MyInventoryBase destinationInventory, IMyInventoryItem item, MyFixedPoint amount) { if (sourceInventory == null || destinationInventory == null || item == null) { Debug.Fail("Invalid parameters!"); return; } Debug.Assert(amount > 0, "Amount is <= 0! Sending meaningless message! Don't call this if transferring amount is 0"); var msg = new TransferItemsBaseMsg(); msg.Amount = amount; msg.SourceContainerId = sourceInventory.Container.Entity.EntityId; msg.DestinationContainerId = destinationInventory.Container.Entity.EntityId; msg.SourceItemId = item.ItemId; msg.SourceInventoryId = MyStringHash.GetOrCompute(sourceInventory.InventoryId.ToString()); msg.DestinationInventoryId = MyStringHash.GetOrCompute(destinationInventory.InventoryId.ToString()); Sync.Layer.SendMessageToServer(ref msg); }