public void RemoveFromCart(CargoOrder orderToRemove) { if (!CustomNetworkManager.Instance._isServer) { return; } CurrentCart.Remove(orderToRemove); OnCartUpdate?.Invoke(); }
public void AddToCart(CargoOrder orderToAdd) { if (!CustomNetworkManager.Instance._isServer) { return; } if (CurrentCart.Count > cartSizeLimit) { return; } CurrentCart.Add(orderToAdd); OnCartUpdate?.Invoke(); }
/// <summary> /// Spawns the order inside cargo shuttle. /// Server only. /// </summary> /// <param name="order">Order to spawn.</param> public bool SpawnOrder(CargoOrder order) { Vector3 pos = GetRandomFreePos(); if (pos == TransformState.HiddenPos) { return(false); } var crate = Spawn.ServerPrefab(order.Crate, pos).GameObject; Dictionary <GameObject, Stackable> stackableItems = new Dictionary <GameObject, Stackable>(); //error occurred trying to spawn, just ignore this order. if (crate == null) { return(true); } if (crate.TryGetComponent <ClosetControl>(out var closetControl)) { for (int i = 0; i < order.Items.Count; i++) { var entryPrefab = order.Items[i]; if (entryPrefab == null) { Logger.Log($"Error with order fulfilment. Can't add items index: {i} for {order.OrderName} as the prefab is null. Skipping.."); continue; } if (!stackableItems.ContainsKey(entryPrefab)) { var orderedItem = Spawn.ServerPrefab(order.Items[i], pos).GameObject; if (orderedItem == null) { //let the shuttle still be able to complete the order empty otherwise it will be stuck permantly Logger.Log($"Can't add ordered item to create because it doesn't have a GameObject", Category.ItemSpawn); continue; } var stackableItem = orderedItem.GetComponent <Stackable>(); if (stackableItem != null) { stackableItems.Add(entryPrefab, stackableItem); } AddItemToCrate(closetControl, orderedItem); } else { if (stackableItems[entryPrefab].Amount < stackableItems[entryPrefab].MaxAmount) { stackableItems[entryPrefab].ServerIncrease(1); } else { //Start a new one to start stacking var orderedItem = Spawn.ServerPrefab(entryPrefab, pos).GameObject; if (orderedItem == null) { //let the shuttle still be able to complete the order empty otherwise it will be stuck permantly Logger.Log($"Can't add ordered item to create because it doesn't have a GameObject", Category.ItemSpawn); continue; } var stackableItem = orderedItem.GetComponent <Stackable>(); stackableItems[entryPrefab] = stackableItem; AddItemToCrate(closetControl, orderedItem); } } } } else { Logger.LogWarning($"{crate.ExpensiveName()} does not have ClosetControl. Please fix CargoData" + $" to ensure that the crate prefab is actually a crate (with ClosetControl component)." + $" This order will be ignored."); return(true); } CargoManager.Instance.CentcomMessage += "Loaded " + order.OrderName + " onto shuttle.\n"; return(true); }