Exemplo n.º 1
0
        private void OnEntityKill(BaseEntity entity)
        {
            if (!(entity is SurveyCharge))
            {
                return;
            }
            OilConfigInfo info = new OilConfigInfo();

            if (wait.TryGetValue(entity, out info))
            {
                Vector3 Pos = entity.transform.position;
                NextTick(() =>
                {
                    var list = new List <SurveyCrater>();
                    Vis.Entities(Pos, 1f, list);
                    if (list.Count() > 0)
                    {
                        foreach (var survey in list)
                        {
                            if (readed.Contains(survey))
                            {
                                continue;
                            }
                            if (UnityEngine.Random.Range(0, 100) < info.Chance)
                            {
                                survey.Kill();

                                SurveyCrater oilEntity = GameManager.server.CreateEntity("assets/prefabs/tools/surveycharge/survey_crater_oil.prefab", survey.transform.position) as SurveyCrater;
                                if (oilEntity == null || oil == null)
                                {
                                    continue;
                                }
                                oilEntity.Spawn();

                                var res = ResourceDepositManager.GetOrCreate(oilEntity.transform.position);
                                if (res == null)
                                {
                                    continue;
                                }
                                res._resources.Clear();
                                float pm         = UnityEngine.Random.Range(info.PMMin, info.PMMax);
                                float workNeeded = 45f / pm;
                                int amount       = UnityEngine.Random.Range(50000, 100000);
                                res.Add(oil, 1, amount, workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.OIL, true);
                                oils.Add(new OilInfo(Pos, amount, workNeeded));
                                changed = true;
                                readed.Add(oilEntity);
                            }
                            if (!survey.IsDestroyed)
                            {
                                readed.Add(survey);
                            }
                        }
                    }
                });
                wait.Remove(entity);
            }
        }
Exemplo n.º 2
0
        //
        // Edit the stored resource deposits
        //
        void OnServerInitialized()
        {
            ValidateConfig();
            foreach (Deposit deposit in data.changedDeposits)
            {
                ResourceDepositManager.ResourceDeposit rd = ResourceDepositManager.GetOrCreate(GetVector3(deposit.origin));

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

                    case "metal.ore":
                        oreCount++;
                        break;

                    case "hq.metal.ore":
                        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");

                foreach (DepositEntry entry in deposit.entries)
                {
                    switch (entry.type)
                    {
                    case OreType.Metal:
                        rd.Add(metal, 1, entry.amount, entry.workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        break;

                    case OreType.Sulfur:
                        rd.Add(sulfur, 1, entry.amount, entry.workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void AddResource(OilInfo info)
        {
            var res = ResourceDepositManager.GetOrCreate(info.pos);

            if (res == null || oil == null)
            {
                return;
            }
            res._resources.Clear();
            res.Add(oil, 1, info.amount, info.workNeeded, ResourceDepositManager.ResourceDeposit.surveySpawnType.OIL, true);
        }
Exemplo n.º 4
0
 public override void ServerInit()
 {
     base.ServerInit();
     if (!this.isStatic)
     {
         this._linkedDeposit = ResourceDepositManager.GetOrCreate(base.transform.position);
     }
     else
     {
         this.UpdateStaticDeposit();
     }
     this.SpawnChildEntities();
     this.engineSwitchPrefab.instance.SetFlag(BaseEntity.Flags.On, base.HasFlag(BaseEntity.Flags.On), false, true);
 }
Exemplo n.º 5
0
        void getDeposit(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, $"oldschoolquarries.probe"))
            {
                PrintToChat(player, Lang("NoCommandPermission", player.UserIDString));
                return;
            }

            ResourceDepositManager.ResourceDeposit rd = ResourceDepositManager.GetOrCreate(player.transform.position);
            if (rd == null)
            {
                PrintToChat(player, Lang("NoResources", player.UserIDString));
                return;
            }

            PrintToChat(player, Lang("AnalysisHeader", player.UserIDString));
            float      num1     = 10f;
            float      num2     = 7.5f;
            List <int> fixIndex = new List <int>();
            int        index    = 0;

            foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry resource in rd._resources)
            {
                float num3 = (float)(60.0 / num1 * (num2 / (double)resource.workNeeded));
                if (float.IsInfinity(num3))
                {
                    fixIndex.Add(index);
                }
                if (config.Detailed_Analysis)
                {
                    PrintToChat(player, Lang("AnalysisDetailed", player.UserIDString, resource.type.displayName.translated, resource.amount, resource.workNeeded, Math.Round(num3, 1)));
                }
                else
                {
                    PrintToChat(player, Lang("Analysis", player.UserIDString, resource.type.displayName.translated, Math.Round(num3, 1)));
                }
                index++;
            }

            if (fixIndex.Count != 0)
            {
                foreach (int pos in fixIndex)
                {
                    rd._resources.RemoveAt(pos);
                }
            }

            PrintToChat(player, Lang("AnalysisFooter", player.UserIDString));
        }
    public void AnalysisComplete(BaseEntity.RPCMessage msg)
    {
        ResourceDepositManager.ResourceDeposit orCreate = ResourceDepositManager.GetOrCreate(base.transform.position);
        if (orCreate == null)
        {
            return;
        }
        Item item = ItemManager.CreateByName("note", 1, (ulong)0);

        item.text = "-Mineral Analysis-\n\n";
        float single  = 10f;
        float single1 = 7.5f;

        foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry _resource in orCreate._resources)
        {
            float single2 = 60f / single * (single1 / _resource.workNeeded);
            Item  item1   = item;
            item1.text = string.Concat(new string[] { item1.text, _resource.type.displayName.english, " : ", single2.ToString("0.0"), " pM\n" });
        }
        item.MarkDirty();
        msg.player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp);
    }
Exemplo n.º 7
0
    public void AnalysisComplete(BaseEntity.RPCMessage msg)
    {
        ResourceDepositManager.ResourceDeposit resourceDeposit = ResourceDepositManager.GetOrCreate(((Component)this).get_transform().get_position());
        if (resourceDeposit == null)
        {
            return;
        }
        Item byName = ItemManager.CreateByName("note", 1, 0UL);

        byName.text = "-Mineral Analysis-\n\n";
        float num1 = 10f;
        float num2 = 7.5f;

        foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry resource in resourceDeposit._resources)
        {
            float num3 = (float)(60.0 / (double)num1 * ((double)num2 / (double)resource.workNeeded));
            Item  obj  = byName;
            obj.text = obj.text + resource.type.displayName.english + " : " + num3.ToString("0.0") + " pM\n";
        }
        byName.MarkDirty();
        msg.player.GiveItem(byName, BaseEntity.GiveItemReason.PickedUp);
    }
Exemplo n.º 8
0
    public override void Explode()
    {
        RaycastHit raycastHit;

        base.Explode();
        if (WaterLevel.Test(base.transform.position))
        {
            return;
        }
        ResourceDepositManager.ResourceDeposit orCreate = ResourceDepositManager.GetOrCreate(base.transform.position);
        if (orCreate == null)
        {
            return;
        }
        if (Time.realtimeSinceStartup - orCreate.lastSurveyTime < 10f)
        {
            return;
        }
        orCreate.lastSurveyTime = Time.realtimeSinceStartup;
        if (!TransformUtil.GetGroundInfo(base.transform.position, out raycastHit, 0.3f, 8388608, null))
        {
            return;
        }
        Vector3             vector3  = raycastHit.point;
        Vector3             vector31 = raycastHit.normal;
        List <SurveyCrater> list     = Pool.GetList <SurveyCrater>();

        Vis.Entities <SurveyCrater>(base.transform.position, 10f, list, 1, QueryTriggerInteraction.Collide);
        bool count = list.Count > 0;

        Pool.FreeList <SurveyCrater>(ref list);
        if (count)
        {
            return;
        }
        bool flag  = false;
        bool flag1 = false;

        foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry _resource in orCreate._resources)
        {
            if (_resource.spawnType != ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM || _resource.isLiquid || _resource.amount < 1000)
            {
                continue;
            }
            int num  = Mathf.Clamp(Mathf.CeilToInt(2.5f / _resource.workNeeded * 10f), 0, 5);
            int num1 = 1;
            flag = true;
            if (_resource.isLiquid)
            {
                flag1 = true;
            }
            for (int i = 0; i < num; i++)
            {
                Item    item = ItemManager.Create(_resource.type, num1, (ulong)0);
                Vector3 modifiedAimConeDirection = AimConeUtil.GetModifiedAimConeDirection(20f, Vector3.up, true);
                item.Drop(base.transform.position + (Vector3.up * 1f), this.GetInheritedDropVelocity() + (modifiedAimConeDirection * UnityEngine.Random.Range(5f, 10f)), UnityEngine.Random.rotation).SetAngularVelocity(UnityEngine.Random.rotation.eulerAngles * 5f);
            }
        }
        if (flag)
        {
            string     str        = (flag1 ? this.craterPrefab_Oil.resourcePath : this.craterPrefab.resourcePath);
            BaseEntity baseEntity = GameManager.server.CreateEntity(str, vector3, Quaternion.identity, true);
            if (baseEntity)
            {
                baseEntity.Spawn();
            }
        }
    }
Exemplo n.º 9
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();
            }
        }
Exemplo n.º 10
0
    public override void Explode()
    {
        base.Explode();
        if (WaterLevel.Test(((Component)this).get_transform().get_position()))
        {
            return;
        }
        ResourceDepositManager.ResourceDeposit resourceDeposit = ResourceDepositManager.GetOrCreate(((Component)this).get_transform().get_position());
        if (resourceDeposit == null || (double)Time.get_realtimeSinceStartup() - (double)resourceDeposit.lastSurveyTime < 10.0)
        {
            return;
        }
        resourceDeposit.lastSurveyTime = Time.get_realtimeSinceStartup();
        RaycastHit hitOut;

        if (!TransformUtil.GetGroundInfo(((Component)this).get_transform().get_position(), out hitOut, 0.3f, LayerMask.op_Implicit(8388608), (Transform)null))
        {
            return;
        }
        Vector3 point = ((RaycastHit) ref hitOut).get_point();

        ((RaycastHit) ref hitOut).get_normal();
        List <SurveyCrater> list = (List <SurveyCrater>)Pool.GetList <SurveyCrater>();

        Vis.Entities <SurveyCrater>(((Component)this).get_transform().get_position(), 10f, list, 1, (QueryTriggerInteraction)2);
        int num1 = list.Count > 0 ? 1 : 0;

        // ISSUE: cast to a reference type
        Pool.FreeList <SurveyCrater>((List <M0>&) ref list);
        if (num1 != 0)
        {
            return;
        }
        bool flag1 = false;
        bool flag2 = false;

        foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry resource in resourceDeposit._resources)
        {
            if (resource.spawnType == ResourceDepositManager.ResourceDeposit.surveySpawnType.ITEM && !resource.isLiquid && resource.amount >= 1000)
            {
                int num2    = Mathf.Clamp(Mathf.CeilToInt((float)(2.5 / (double)resource.workNeeded * 10.0)), 0, 5);
                int iAmount = 1;
                flag1 = true;
                if (resource.isLiquid)
                {
                    flag2 = true;
                }
                for (int index = 0; index < num2; ++index)
                {
                    Item       obj = ItemManager.Create(resource.type, iAmount, 0UL);
                    Vector3    aimConeDirection = AimConeUtil.GetModifiedAimConeDirection(20f, Vector3.get_up(), true);
                    Vector3    vPos             = Vector3.op_Addition(((Component)this).get_transform().get_position(), Vector3.op_Multiply(Vector3.get_up(), 1f));
                    Vector3    vVelocity        = Vector3.op_Addition(this.GetInheritedDropVelocity(), Vector3.op_Multiply(aimConeDirection, Random.Range(5f, 10f)));
                    Quaternion rotation1        = Random.get_rotation();
                    BaseEntity baseEntity       = obj.Drop(vPos, vVelocity, rotation1);
                    Quaternion rotation2        = Random.get_rotation();
                    Vector3    velocity         = Vector3.op_Multiply(((Quaternion) ref rotation2).get_eulerAngles(), 5f);
                    baseEntity.SetAngularVelocity(velocity);
                }
            }
        }
        if (!flag1)
        {
            return;
        }
        string     strPrefab = flag2 ? this.craterPrefab_Oil.resourcePath : this.craterPrefab.resourcePath;
        BaseEntity entity    = GameManager.server.CreateEntity(strPrefab, point, Quaternion.get_identity(), true);

        if (!Object.op_Implicit((Object)entity))
        {
            return;
        }
        entity.Spawn();
    }
Exemplo n.º 11
0
 public override void ServerInit()
 {
     base.ServerInit();
     if (!isStatic)
     {
         ResourceDepositManager.ResourceDeposit resourceDeposit = (_linkedDeposit = ResourceDepositManager.GetOrCreate(base.transform.position));
     }
     else
     {
         UpdateStaticDeposit();
     }
     SpawnChildEntities();
     engineSwitchPrefab.instance.SetFlag(Flags.On, HasFlag(Flags.On));
 }