Exemplo n.º 1
0
        public IRuleRetriever SetEntity(ExportedItem exportedItem)
        {
            string group            = exportedItem.File.group_customer;
            string receivingCountry = GetCountryToCompare(group, exportedItem.Receiving_Country_Code, rule => rule.Receiving_Country_Code);
            string shippingCountry  = GetCountryToCompare(group, exportedItem.Shipping_Country_Code, rule => rule.Shipping_Country_Code);
            string recordId         = exportedItem.Id.ToString();

            this.ClearQueryConditions(recordId)
            .SetCriteria((field) => field.Group, group)
            .SetCriteria((field) => field.Receiving_Country_Code, receivingCountry)
            .SetCriteria((field) => field.Shipping_Country_Code, shippingCountry)
            .SetCriteria((field) => field.Shipping_Company, exportedItem.Shipping_Company_Name)
            .SetCriteria((field) => field.Receving_Company, exportedItem.Receiving_Company_Name)
            .SetCriteria((field) => field.Shipping_PostalCode, exportedItem.Shipping_Postal_Code)
            .SetCriteria((field) => field.Receiving_PostalCode, exportedItem.Receiving_Postal_Code)
            ;


            return(this);
        }
Exemplo n.º 2
0
    public void DestroyItem(ObjectBehaviour item, HashSet <GameObject> alreadySold)
    {
        //already sold this this sales cycle.
        if (alreadySold.Contains(item.gameObject))
        {
            return;
        }
        var storage = item.GetComponent <InteractableStorage>();

        if (storage)
        {
            foreach (var slot in storage.ItemStorage.GetItemSlots())
            {
                if (slot.Item)
                {
                    DestroyItem(slot.Item.GetComponent <ObjectBehaviour>(), alreadySold);
                }
            }
        }

        //note: it seems the held items are also detected in UnloadCargo as being on the matrix but only
        //when they were spawned or moved onto that cargo shuttle (outside of the crate) prior to being placed into the crate. If they
        //were instead placed into the crate and then the crate was moved onto the cargo shuttle, they
        //will only be found with this check and won't be found in UnloadCargo.
        //TODO: Better logic for ClosetControl updating its held items' parent matrix when crossing matrix with items inside.
        var closet = item.GetComponent <ClosetControl>();

        if (closet)
        {
            foreach (var closetItem in closet.ServerHeldItems)
            {
                DestroyItem(closetItem, alreadySold);
            }
        }

        // If there is no bounty for the item - we dont destroy it.
        var credits = Instance.GetSellPrice(item);

        Credits += credits;
        OnCreditsUpdate?.Invoke();

        var    attributes = item.gameObject.GetComponent <Attributes>();
        string exportName;

        if (attributes)
        {
            if (string.IsNullOrEmpty(attributes.ExportName))
            {
                exportName = attributes.ArticleName;
            }
            else
            {
                exportName = attributes.ExportName;
            }
        }
        else
        {
            exportName = item.gameObject.ExpensiveName();
        }
        ExportedItem export;

        if (exportedItems.ContainsKey(exportName))
        {
            export = exportedItems[exportName];
        }
        else
        {
            export = new ExportedItem
            {
                ExportMessage = attributes ? attributes.ExportMessage : "",
                ExportName    = attributes ? attributes.ExportName : ""              // Need to always use the given export name
            };
            exportedItems.Add(exportName, export);
        }

        var stackable = item.gameObject.GetComponent <Stackable>();
        var count     = 1;

        if (stackable)
        {
            count = stackable.Amount;
        }

        export.Count      += count;
        export.TotalValue += credits;

        var playerScript = item.GetComponent <PlayerScript>();

        if (playerScript != null)
        {
            playerScript.playerHealth.ServerGibPlayer();
        }

        item.registerTile.UnregisterClient();
        item.registerTile.UnregisterServer();
        alreadySold.Add(item.gameObject);
        Despawn.ServerSingle(item.gameObject);
    }
Exemplo n.º 3
0
    public void DestroyItem(ObjectBehaviour item)
    {
        var storage = item.GetComponent <InteractableStorage>();

        if (storage)
        {
            foreach (var slot in storage.ItemStorage.GetItemSlots())
            {
                if (slot.Item)
                {
                    DestroyItem(slot.Item.GetComponent <ObjectBehaviour>());
                }
            }
        }

        var closet = item.GetComponent <ClosetControl>();

        if (closet)
        {
            foreach (var closetItem in closet.ServerHeldItems)
            {
                DestroyItem(closetItem);
            }
        }

        // If there is no bounty for the item - we dont destroy it.
        var credits = Instance.GetSellPrice(item);

        Credits += credits;
        OnCreditsUpdate?.Invoke();

        var    attributes = item.gameObject.GetComponent <Attributes>();
        string exportName;

        if (attributes)
        {
            if (string.IsNullOrEmpty(attributes.ExportName))
            {
                exportName = attributes.ArticleName;
            }
            else
            {
                exportName = attributes.ExportName;
            }
        }
        else
        {
            exportName = item.gameObject.ExpensiveName();
        }
        ExportedItem export;

        if (exportedItems.ContainsKey(exportName))
        {
            export = exportedItems[exportName];
        }
        else
        {
            export = new ExportedItem
            {
                ExportMessage = attributes ? attributes.ExportMessage : "",
                ExportName    = attributes ? attributes.ExportName : ""              // Need to always use the given export name
            };
            exportedItems.Add(exportName, export);
        }

        var stackable = item.gameObject.GetComponent <Stackable>();
        var count     = 1;

        if (stackable)
        {
            count = stackable.Amount;
        }

        export.Count      += count;
        export.TotalValue += credits;

        item.registerTile.UnregisterClient();
        item.registerTile.UnregisterServer();
        Despawn.ServerSingle(item.gameObject);
    }
Exemplo n.º 4
0
        public void ProcessCargo(GameObject obj, HashSet <GameObject> alreadySold)
        {
            if (obj.TryGetComponent <WrappedBase>(out var wrappedObject))
            {
                var wrappedContents = wrappedObject.GetOrGenerateContent();
                ProcessCargo(wrappedContents, alreadySold);
                DespawnItem(obj, alreadySold);
                return;
            }

            // already sold this this sales cycle.
            if (alreadySold.Contains(obj))
            {
                return;
            }

            if (obj.TryGetComponent <ItemStorage>(out var storage))
            {
                // Check to spawn initial contents, can't just use prefab data due to recursion
                if (storage.ContentsSpawned == false)
                {
                    storage.TrySpawnContents();
                }

                foreach (var slot in storage.GetItemSlots())
                {
                    if (slot.Item)
                    {
                        ProcessCargo(slot.Item.gameObject, alreadySold);
                    }
                }
            }

            if (obj.TryGetComponent <ObjectContainer>(out var container))
            {
                container.TrySpawnInitialContents(true);

                //Check to spawn initial contents, cant just use prefab data due to recursion
                foreach (var recursiveObj in container.GetStoredObjects())
                {
                    ProcessCargo(recursiveObj, alreadySold);
                }
            }

            // If there is no bounty for the item - we dont destroy it.
            var credits = Instance.GetSellPrice(obj);

            Credits += credits;
            OnCreditsUpdate.Invoke();

            string exportName;

            if (obj.TryGetComponent <Attributes>(out var attributes))
            {
                exportName = string.IsNullOrEmpty(attributes.ExportName) ? attributes.ArticleName : attributes.ExportName;
            }
            else
            {
                exportName = obj.gameObject.ExpensiveName();
            }

            if (exportedItems.TryGetValue(exportName, out ExportedItem export) == false)
            {
                export = new ExportedItem
                {
                    ExportMessage = attributes ? attributes.ExportMessage : string.Empty,
                    ExportName    = attributes ? attributes.ExportName : string.Empty                  // Need to always use the given export name
                };
                exportedItems.Add(exportName, export);
            }

            var count = obj.TryGetComponent <Stackable>(out var stackable) ? stackable.Amount : 1;

            export.Count      += count;
            export.TotalValue += credits;

            if (obj.TryGetComponent <ItemAttributesV2>(out var itemAttributes))
            {
                foreach (var itemTrait in itemAttributes.GetTraits())
                {
                    if (itemTrait == null)
                    {
                        Logger.LogError($"{itemAttributes.name} has null or empty item trait, please fix");
                        continue;
                    }

                    if (SoldHistory.ContainsKey(itemTrait) == false)
                    {
                        SoldHistory.Add(itemTrait, 0);
                    }
                    SoldHistory[itemTrait] += count;
                    count = TryCompleteBounty(itemTrait, count);

                    if (count == 0)
                    {
                        break;
                    }
                }
            }

            // Add value of mole inside gas container
            if (obj.TryGetComponent <GasContainer>(out var gasContainer))
            {
                var stringBuilder = new StringBuilder(export.ExportMessage);

                lock (gasContainer.GasMix.GasesArray)                   //no Double lock
                {
                    foreach (var gas in gasContainer.GasMix.GasesArray) //doesn't appear to modify list while iterating
                    {
                        int gasValue = (int)gas.Moles * gas.GasSO.ExportPrice;
                        stringBuilder.AppendLine($"Exported {gas.Moles} moles of {gas.GasSO.Name} for {gasValue} credits");
                        export.TotalValue += gasValue;
                        Credits           += gasValue;
                    }
                }


                export.ExportMessage = stringBuilder.ToString();
                OnCreditsUpdate.Invoke();
            }

            if (obj.TryGetComponent <PlayerScript>(out var playerScript))
            {
                // No one must survive to tell the secrets of Central Command's cargo handling techniques.
                playerScript.playerHealth.Gib();
            }

            if (attributes != null && attributes.ExportType != Attributes.CargoExportType.Always &&
                (Credits == 0 || export.TotalValue == 0))
            {
                return;
            }

            DespawnItem(obj, alreadySold);
        }
Exemplo n.º 5
0
        public void ProcessCargo(PushPull item, HashSet <GameObject> alreadySold)
        {
            var wrappedItem = item.GetComponent <WrappedBase>();

            if (wrappedItem)
            {
                var wrappedContents = wrappedItem.GetOrGenerateContent().GetComponent <PushPull>();
                ProcessCargo(wrappedContents, alreadySold);
                DespawnItem(item, alreadySold);
                return;
            }

            //already sold this this sales cycle.
            if (alreadySold.Contains(item.gameObject))
            {
                return;
            }
            var storage = item.GetComponent <InteractableStorage>();

            if (storage)
            {
                //Check to spawn initial contents, cant just use prefab data due to recursion
                if (storage.ItemStorage.ContentsSpawned == false)
                {
                    storage.ItemStorage.TrySpawnContents();
                }

                foreach (var slot in storage.ItemStorage.GetItemSlots())
                {
                    if (slot.Item)
                    {
                        ProcessCargo(slot.Item.GetComponent <PushPull>(), alreadySold);
                    }
                }
            }

            // note: it seems the held items are also detected in UnloadCargo as being on the matrix but only
            // when they were spawned or moved onto that cargo shuttle (outside of the crate) prior to being placed into the crate. If they
            // were instead placed into the crate and then the crate was moved onto the cargo shuttle, they
            // will only be found with this check and won't be found in UnloadCargo.
            // TODO: Better logic for ClosetControl updating its held items' parent matrix when crossing matrix with items inside.
            var closet = item.GetComponent <ClosetControl>();

            if (closet)
            {
                //Check to spawn initial contents, cant just use prefab data due to recursion
                if (closet.ContentsSpawned == false && closet.InitialContents != null)
                {
                    closet.TrySpawnContents(true);
                }

                foreach (var closetItem in closet.ServerHeldItems)
                {
                    ProcessCargo(closetItem, alreadySold);
                }
            }

            // If there is no bounty for the item - we dont destroy it.
            var credits = Instance.GetSellPrice(item);

            Credits += credits;
            OnCreditsUpdate.Invoke();

            var    attributes = item.gameObject.GetComponent <Attributes>();
            string exportName = String.Empty;

            if (attributes)
            {
                if (string.IsNullOrEmpty(attributes.ExportName))
                {
                    exportName = attributes.ArticleName;
                }
                else
                {
                    exportName = attributes.ExportName;
                }
            }
            else
            {
                exportName = item.gameObject.ExpensiveName();
            }
            ExportedItem export;

            if (exportedItems.ContainsKey(exportName))
            {
                export = exportedItems[exportName];
            }
            else
            {
                export = new ExportedItem
                {
                    ExportMessage = attributes ? attributes.ExportMessage : "",
                    ExportName    = attributes ? attributes.ExportName : ""                  // Need to always use the given export name
                };
                exportedItems.Add(exportName, export);
            }

            var stackable = item.gameObject.GetComponent <Stackable>();
            var count     = 1;

            if (stackable)
            {
                count = stackable.Amount;
            }

            export.Count      += count;
            export.TotalValue += credits;

            var itemAttributes = item.GetComponent <ItemAttributesV2>();

            if (itemAttributes)
            {
                foreach (var itemTrait in itemAttributes.GetTraits())
                {
                    if (itemTrait == null)
                    {
                        Logger.LogError($"{itemAttributes.name} has null or empty item trait, please fix");
                        continue;
                    }
                    if (SoldHistory.ContainsKey(itemTrait) == false)
                    {
                        SoldHistory.Add(itemTrait, 0);
                    }
                    SoldHistory[itemTrait] += count;
                    count = TryCompleteBounty(itemTrait, count);
                    if (count == 0)
                    {
                        break;
                    }
                }
            }

            var playerScript = item.GetComponent <PlayerScript>();

            if (playerScript != null)
            {
                playerScript.playerHealth.ServerGibPlayer();
            }

            DespawnItem(item, alreadySold);
        }
Exemplo n.º 6
0
        public void ProcessCargo(GameObject obj, HashSet <GameObject> alreadySold)
        {
            if (obj.TryGetComponent <WrappedBase>(out var wrappedObject))
            {
                var wrappedContents = wrappedObject.GetOrGenerateContent();
                ProcessCargo(wrappedContents, alreadySold);
                DespawnItem(obj, alreadySold);
                return;
            }

            //already sold this this sales cycle.
            if (alreadySold.Contains(obj))
            {
                return;
            }
            var storage = obj.GetComponent <InteractableStorage>();

            if (storage)
            {
                //Check to spawn initial contents, cant just use prefab data due to recursion
                if (storage.ItemStorage.ContentsSpawned == false)
                {
                    storage.ItemStorage.TrySpawnContents();
                }

                foreach (var slot in storage.ItemStorage.GetItemSlots())
                {
                    if (slot.Item)
                    {
                        ProcessCargo(slot.Item.gameObject, alreadySold);
                    }
                }
            }

            if (obj.TryGetComponent <ObjectContainer>(out var container))
            {
                container.TrySpawnInitialContents(true);

                //Check to spawn initial contents, cant just use prefab data due to recursion
                foreach (var recursiveObj in container.GetStoredObjects())
                {
                    ProcessCargo(recursiveObj, alreadySold);
                }
            }

            // If there is no bounty for the item - we dont destroy it.
            var credits = Instance.GetSellPrice(obj);

            Credits += credits;
            OnCreditsUpdate.Invoke();

            var    attributes = obj.gameObject.GetComponent <Attributes>();
            string exportName = String.Empty;

            if (attributes)
            {
                if (string.IsNullOrEmpty(attributes.ExportName))
                {
                    exportName = attributes.ArticleName;
                }
                else
                {
                    exportName = attributes.ExportName;
                }
            }
            else
            {
                exportName = obj.gameObject.ExpensiveName();
            }
            ExportedItem export;

            if (exportedItems.ContainsKey(exportName))
            {
                export = exportedItems[exportName];
            }
            else
            {
                export = new ExportedItem
                {
                    ExportMessage = attributes ? attributes.ExportMessage : "",
                    ExportName    = attributes ? attributes.ExportName : ""                  // Need to always use the given export name
                };
                exportedItems.Add(exportName, export);
            }

            var stackable = obj.gameObject.GetComponent <Stackable>();
            var count     = 1;

            if (stackable)
            {
                count = stackable.Amount;
            }

            export.Count      += count;
            export.TotalValue += credits;

            var itemAttributes = obj.GetComponent <ItemAttributesV2>();

            if (itemAttributes)
            {
                foreach (var itemTrait in itemAttributes.GetTraits())
                {
                    if (itemTrait == null)
                    {
                        Logger.LogError($"{itemAttributes.name} has null or empty item trait, please fix");
                        continue;
                    }
                    if (SoldHistory.ContainsKey(itemTrait) == false)
                    {
                        SoldHistory.Add(itemTrait, 0);
                    }
                    SoldHistory[itemTrait] += count;
                    count = TryCompleteBounty(itemTrait, count);
                    if (count == 0)
                    {
                        break;
                    }
                }
            }

            //Add value of mole inside gas container
            var gasContainer = obj.GetComponent <GasContainer>();

            if (gasContainer)
            {
                int gasPrise      = 0;
                var stringBuilder = new StringBuilder();
                stringBuilder.Append(export.ExportMessage);

                foreach (var gas in gasContainer.GasMix.GasesArray)
                {
                    gasPrise = (int)gas.Moles * gas.GasSO.ExportPrice;
                    stringBuilder.AppendLine($"Exported {gas.Moles} moles of {gas.GasSO.Name} for {gasPrise} credits");
                    export.TotalValue += gasPrise;
                    Credits           += gasPrise;
                }

                export.ExportMessage = stringBuilder.ToString();
                OnCreditsUpdate.Invoke();
            }

            var playerScript = obj.GetComponent <PlayerScript>();

            if (playerScript != null)
            {
                playerScript.playerHealth.Gib();
            }

            DespawnItem(obj, alreadySold);
        }