private void RollRandomPool(MatrixInfo matrixInfo)
        {
            for (int i = 0; i < lootCount; i++)
            {
                PoolData pool = null;
                // Roll attempt is a safe check in the case the mapper did tables with low % and we can't find
                // anything to spawn in 5 attempts
                int rollAttempt = 0;

                while (pool == null)
                {
                    if (rollAttempt >= MaxAmountRolls)
                    {
                        break;
                    }

                    var tryPool = poolList.PickRandom();
                    if (DMMath.Prob(tryPool.Probability))
                    {
                        pool = tryPool;
                    }
                    else
                    {
                        rollAttempt++;
                    }
                }

                if (pool == null)
                {
                    // didn't spawned anything - just destroy spawner
                    _ = Despawn.ServerSingle(gameObject);
                    return;
                }

                SpawnItems(pool);
            }

            _ = Despawn.ServerSingle(gameObject);
        }
Exemple #2
0
        private void SpawnItems(PoolData poolData)
        {
            if (poolData == null)
            {
                return;
            }
            var item   = poolData.RandomItemPool.Pool.PickRandom();
            var spread = fanOut ? Random.Range(-0.5f, 0.5f) : (float?)null;

            if (!DMMath.Prob(item.Probability))
            {
                return;
            }

            var maxAmt = Random.Range(1, item.MaxAmount + 1);

            Spawn.ServerPrefab(
                item.Prefab,
                gameObject.RegisterTile().WorldPositionServer,
                count: maxAmt,
                scatterRadius: spread);
        }
        private void GenerateItem(PoolData poolData, bool spawn)
        {
            if (poolData == null)
            {
                return;
            }

            var itemPool = poolData.RandomItemPool;

            if (itemPool == null)
            {
                Logger.LogError($"Item pool was null in {gameObject.name}", Category.ItemSpawn);
                return;
            }

            var item   = poolData.RandomItemPool.Pool.PickRandom();
            var spread = fanOut ? Random.Range(-0.5f, 0.5f) : (float?)null;

            if (!DMMath.Prob(item.Probability))
            {
                return;
            }

            var maxAmt = Random.Range(1, item.MaxAmount + 1);

            this.spawnedItem = item.Prefab;
            if (spawn == false)
            {
                return;
            }

            var worldPos = gameObject.AssumedWorldPosServer();
            var pushPull = GetComponent <PushPull>();

            Spawn.ServerPrefab(item.Prefab, worldPos, count: maxAmt, scatterRadius: spread, sharePosition: pushPull);
        }
        public void RollRandomPool(bool UnrestrictedAndspawn, bool overrideTrigger = false)
        {
            if (overrideTrigger == false && triggerManually)
            {
                return;
            }

            var RegisterTile = this.GetComponent <RegisterTile>();

            for (int i = 0; i < lootCount; i++)
            {
                PoolData pool = null;
                // Roll attempt is a safe check in the case the mapper did tables with low % and we can't find
                // anything to spawn in 5 attempts
                int rollAttempt = 0;

                while (pool == null)
                {
                    if (rollAttempt >= MaxAmountRolls)
                    {
                        break;
                    }

                    var tryPool = poolList.PickRandom();
                    if (DMMath.Prob(tryPool.Probability))
                    {
                        pool = tryPool;
                    }
                    else
                    {
                        rollAttempt++;
                    }
                }

                if (pool == null)
                {
                    continue;
                }

                GenerateItem(pool, UnrestrictedAndspawn);
                if (UnrestrictedAndspawn == false)
                {
                    return;
                }
            }

            if (UnrestrictedAndspawn)
            {
                if (RegisterTile.TryGetComponent <ObjectBehaviour>(out var ObjectBehaviour))
                {
                    if (ObjectBehaviour.parentContainer != null)
                    {
                        //TODO Do item storage
                        if (ObjectBehaviour.parentContainer.TryGetComponent <ObjectContainer>(out var ObjectContainer))
                        {
                            ObjectContainer.RetrieveObject(this.gameObject);
                        }
                    }
                }

                RegisterTile.Matrix.MetaDataLayer.InitialObjects[this.gameObject] = this.transform.localPosition;
                this.GetComponent <CustomNetTransform>().DisappearFromWorldServer(true);
                this.GetComponent <RegisterTile>().UpdatePositionServer();
            }
        }