Exemplo n.º 1
0
        public void Add(ItemDefinition type, float efficiency, int amount, float workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType spawnType, bool liquid = false)
        {
            ResourceDepositManager.ResourceDeposit.ResourceDepositEntry resourceDepositEntry = new ResourceDepositManager.ResourceDeposit.ResourceDepositEntry()
            {
                type       = type,
                efficiency = efficiency
            };
            int num  = amount;
            int num1 = num;

            resourceDepositEntry.amount      = num;
            resourceDepositEntry.startAmount = num1;
            resourceDepositEntry.spawnType   = spawnType;
            resourceDepositEntry.workNeeded  = workNeeded;
            resourceDepositEntry.isLiquid    = liquid;
            this._resources.Add(resourceDepositEntry);
        }
Exemplo n.º 2
0
 public void ProcessResources()
 {
     if (this._linkedDeposit == null)
     {
         return;
     }
     if (this.hopperPrefab.instance == null)
     {
         return;
     }
     foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry _resource in this._linkedDeposit._resources)
     {
         if (!this.canExtractLiquid && _resource.isLiquid || !this.canExtractSolid && !_resource.isLiquid)
         {
             continue;
         }
         _resource.workDone += this.workToAdd;
         if (_resource.workDone < _resource.workNeeded)
         {
             continue;
         }
         int num = Mathf.FloorToInt(_resource.workDone / _resource.workNeeded);
         ResourceDepositManager.ResourceDeposit.ResourceDepositEntry resourceDepositEntry = _resource;
         resourceDepositEntry.workDone = resourceDepositEntry.workDone - (float)num * _resource.workNeeded;
         Item item = ItemManager.Create(_resource.type, num, (ulong)0);
         Interface.CallHook("OnQuarryGather", this, item);
         if (item.MoveToContainer(this.hopperPrefab.instance.GetComponent <StorageContainer>().inventory, -1, true))
         {
             continue;
         }
         item.Remove(0f);
         this.SetOn(false);
     }
     if (!this.FuelCheck())
     {
         this.SetOn(false);
     }
 }
Exemplo n.º 3
0
        //
        // Update salt map when resource deposit is tapped for the first time
        //
        void OnEntitySpawned(BaseNetworkable entity)
        {
            if (entity is SurveyCharge)
            {
                OreType ore = OreType.None;

                ResourceDepositManager.ResourceDeposit rd = ResourceDepositManager.GetOrCreate(entity.transform.position);

                if (data.changedDeposits.Exists(d => GetVector3(d.origin) == rd.origin))
                {
                    return;
                }

                ResourceDepositManager.ResourceDeposit.ResourceDepositEntry originalResource = null;

                int oreCount = 0;
                foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry resource in rd._resources)
                {
                    switch (resource.type.shortname)
                    {
                    case "sulfur.ore":
                        ore = OreType.Sulfur;
                        originalResource = resource;
                        oreCount++;
                        break;

                    case "metal.ore":
                        ore = OreType.Metal;
                        originalResource = resource;
                        oreCount++;
                        break;

                    case "hq.metal.ore":
                        ore = OreType.HighQuality;
                        originalResource = resource;
                        oreCount++;
                        break;

                    default:
                        break;
                    }
                }

                if (oreCount > 1)
                {
                    return;
                }

                ItemDefinition sulfur = ItemManager.itemList.Find(x => x.shortname == "sulfur.ore");
                ItemDefinition metal  = ItemManager.itemList.Find(x => x.shortname == "metal.ore");
                ItemDefinition hq     = ItemManager.itemList.Find(x => x.shortname == "hq.metal.ore");

                Deposit deposit = new Deposit {
                    origin = GetOrigin(rd.origin)
                };

                if (originalResource == null && rd._resources.Count != 0)
                {
                    originalResource = rd._resources.ToArray()[0];
                }

                System.Random rng        = new System.Random();
                float         workNeeded = (float)(rng.Next(0, 2) + rng.NextDouble());
                int           choice     = rng.Next(1, 100);
                int           amount     = 0;
                switch (ore)
                {
                case OreType.Sulfur:                          // Give a chance at some amount of metal ore
                    if (workNeeded > 1f)
                    {
                        amount = rng.Next(10000, 100000);
                        rd.Add(metal, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Metal, amount = amount, workNeeded = workNeeded
                        });
                    }
                    break;

                case OreType.Metal:                         // Give a chance at some amount of sulfur ore
                    if (workNeeded > 1.75f)
                    {
                        amount = rng.Next(10000, 100000);
                        rd.Add(sulfur, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Sulfur, amount = amount, workNeeded = workNeeded
                        });
                    }
                    break;

                case OreType.HighQuality:                        // Give a chance at some amount of either metal, sulfur, or both ores
                    if (choice < 40)                             // Just sulfur
                    {
                        amount     = rng.Next(10000, 100000);
                        workNeeded = (float)(rng.Next(3, 4) + rng.NextDouble());
                        rd.Add(sulfur, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Sulfur, amount = amount, workNeeded = workNeeded
                        });
                    }
                    else if (choice < 80)                             // Just metal
                    {
                        if (workNeeded < 1.75f)
                        {
                            workNeeded += (1.75f - workNeeded);
                        }
                        amount = rng.Next(10000, 100000);
                        rd.Add(metal, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Metal, amount = amount, workNeeded = workNeeded
                        });
                    }
                    else                             // Both sulfur and metal
                    {
                        if (workNeeded < 1.75f)
                        {
                            workNeeded += (1.75f - workNeeded);
                        }
                        amount = rng.Next(10000, 100000);
                        rd.Add(metal, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Metal, amount = amount, workNeeded = workNeeded
                        });
                        amount     = rng.Next(10000, 100000);
                        workNeeded = (float)(rng.Next(3, 4) + rng.NextDouble());
                        rd.Add(sulfur, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Sulfur, amount = amount, workNeeded = workNeeded
                        });
                    }
                    break;

                default:                         // Give a chance at some amount of either metal, sulfur, or both ores
                    if (oreCount == 1)
                    {
                        return;
                    }
                    if (choice < 40)                             // Just sulfur
                    {
                        if (workNeeded > 1.75f)
                        {
                            return;
                        }
                        amount     = rng.Next(10000, 100000);
                        workNeeded = (float)(rng.Next(3, 4) + rng.NextDouble());
                        rd.Add(sulfur, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Sulfur, amount = amount, workNeeded = workNeeded
                        });
                    }
                    else if (choice < 80)                             // Just metal
                    {
                        if (workNeeded < 1.75f)
                        {
                            workNeeded += (1.75f - workNeeded);
                        }
                        amount = rng.Next(10000, 100000);
                        rd.Add(metal, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Metal, amount = amount, workNeeded = workNeeded
                        });
                    }
                    else                             // Both sulfur and metal
                    {
                        if (workNeeded < 1.75f)
                        {
                            workNeeded += (1.75f - workNeeded);
                        }
                        amount = rng.Next(10000, 100000);
                        rd.Add(metal, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Metal, amount = amount, workNeeded = workNeeded
                        });
                        amount     = rng.Next(10000, 100000);
                        workNeeded = (float)(rng.Next(3, 4) + rng.NextDouble());
                        rd.Add(sulfur, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        deposit.entries.Add(new DepositEntry()
                        {
                            type = OreType.Sulfur, amount = amount, workNeeded = workNeeded
                        });
                    }
                    break;
                }

                data.changedDeposits.Add(deposit);
                SaveData();
            }
        }