Ejemplo n.º 1
0
        protected virtual void ProcessGlobalProps()
        {
            Dictionary <int, GameObjectChanceTable> globalPropWeights = new Dictionary <int, GameObjectChanceTable>();

            foreach (var tile in currentDungeon.AllTiles)
            {
                foreach (var prop in tile.GetComponentsInChildren <GlobalProp>())
                {
                    GameObjectChanceTable table = null;

                    if (!globalPropWeights.TryGetValue(prop.PropGroupID, out table))
                    {
                        table = new GameObjectChanceTable();
                        globalPropWeights[prop.PropGroupID] = table;
                    }

                    float weight = (tile.Placement.IsOnMainPath) ? prop.MainPathWeight : prop.BranchPathWeight;
                    weight *= prop.DepthWeightScale.Evaluate(tile.Placement.NormalizedDepth);

                    table.Weights.Add(new GameObjectChance(prop.gameObject, weight, 0, null));
                }
            }

            foreach (var chanceTable in globalPropWeights.Values)
            {
                foreach (var weight in chanceTable.Weights)
                {
                    weight.Value.SetActive(false);
                }
            }

            List <int> processedPropGroups = new List <int>(globalPropWeights.Count);

            foreach (var pair in globalPropWeights)
            {
                if (processedPropGroups.Contains(pair.Key))
                {
                    Debug.LogWarning("Dungeon Flow contains multiple entries for the global prop group ID: " + pair.Key + ". Only the first entry will be used.");
                    continue;
                }

                int index = DungeonFlow.GlobalPropGroupIDs.IndexOf(pair.Key);

                if (index == -1)
                {
                    continue;
                }

                IntRange range = DungeonFlow.GlobalPropRanges[index];

                var weights   = pair.Value.Clone();
                int propCount = range.GetRandom(RandomStream);
                propCount = Mathf.Clamp(propCount, 0, weights.Weights.Count);

                for (int i = 0; i < propCount; i++)
                {
                    var chosenEntry = weights.GetRandom(RandomStream, true, 0, null, true, true);

                    if (chosenEntry != null && chosenEntry.Value != null)
                    {
                        chosenEntry.Value.SetActive(true);
                    }
                }

                processedPropGroups.Add(pair.Key);
            }
        }