예제 #1
0
        public GameObjectChanceTable Clone()
        {
            GameObjectChanceTable newTable = new GameObjectChanceTable();

            foreach (var w in Weights)
            {
                newTable.Weights.Add(new GameObjectChance(w.Value, w.MainPathWeight, w.BranchPathWeight, w.TileSet)
                {
                    UseDepthScale = w.UseDepthScale, DepthWeightScale = w.DepthWeightScale
                });
            }

            return(newTable);
        }
예제 #2
0
        private List <GameObjectChance> CalculateOrderedListOfTiles()
        {
            List <GameObjectChance> tiles = new List <GameObjectChance>(TileWeights.Count);

            GameObjectChanceTable table = new GameObjectChanceTable();

            table.Weights.AddRange(TileWeights);

            while (table.Weights.Any(x => x.Value != null && x.GetWeight(IsOnMainPath, NormalizedDepth) > 0.0f))
            {
                tiles.Add(table.GetRandom(RandomStream, IsOnMainPath, NormalizedDepth, null, true, true));
            }

            return(tiles);
        }
예제 #3
0
        public static GameObjectChanceTable Combine(params GameObjectChanceTable[] tables)
        {
            GameObjectChanceTable combined = new GameObjectChanceTable();

            foreach (var t in tables)
            {
                foreach (var w in t.Weights)
                {
                    combined.Weights.Add(new GameObjectChance(w.Value, w.MainPathWeight, w.BranchPathWeight, w.TileSet)
                    {
                        UseDepthScale = w.UseDepthScale, DepthWeightScale = w.DepthWeightScale
                    });
                }
            }

            return(combined);
        }
예제 #4
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);
            }
        }