Exemplo n.º 1
0
        public void RemoveFromCart(CargoOrderSO orderToRemove)
        {
            if (!CustomNetworkManager.Instance._isServer)
            {
                return;
            }

            CurrentCart.Remove(orderToRemove);
            OnCartUpdate.Invoke();
        }
Exemplo n.º 2
0
        public void AddToCart(CargoOrderSO orderToAdd)
        {
            if (!CustomNetworkManager.Instance._isServer)
            {
                return;
            }

            if (CurrentCart.Count > cartSizeLimit)
            {
                return;
            }

            CurrentCart.Add(orderToAdd);
            OnCartUpdate.Invoke();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Spawns the order inside cargo shuttle.
        /// Server only.
        /// </summary>
        /// <param name="order">Order to spawn.</param>
        public bool SpawnOrder(CargoOrderSO 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 <ObjectContainer>(out var container))
            {
                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..", Category.Cargo);
                        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.Cargo);
                            continue;
                        }

                        var stackableItem = orderedItem.GetComponent <Stackable>();
                        if (stackableItem != null)
                        {
                            stackableItems.Add(entryPrefab, stackableItem);
                        }

                        AddItemToCrate(container, 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.Cargo);
                                continue;
                            }

                            var stackableItem = orderedItem.GetComponent <Stackable>();
                            stackableItems[entryPrefab] = stackableItem;

                            AddItemToCrate(container, orderedItem);
                        }
                    }
                }
            }
            else
            {
                Logger.LogWarning($"{crate.ExpensiveName()} does not have {nameof(ObjectBehaviour)}. Please fix CargoData" +
                                  $" to ensure that the crate prefab is actually a crate (with {nameof(ObjectBehaviour)} component)." +
                                  $" This order will be ignored.", Category.Cargo);
                return(true);
            }

            CargoManager.Instance.CentcomMessage += "Loaded " + order.OrderName + " onto shuttle.\n";
            return(true);
        }