示例#1
0
        private IEnumerable <Entity> SpawnEntitiesUsingRandomDistribution(EntitySpawnPoint entitySpawnPoint, List <UwePrefab> prefabs, DeterministicBatchGenerator deterministicBatchGenerator)
        {
            List <UwePrefab> allowedPrefabs = FilterAllowedPrefabs(prefabs, entitySpawnPoint);

            float rollingProbabilityDensity = allowedPrefabs.Sum(prefab => prefab.Probability / entitySpawnPoint.Density);

            if (rollingProbabilityDensity <= 0)
            {
                yield break;
            }

            double randomNumber = deterministicBatchGenerator.NextDouble();

            if (rollingProbabilityDensity > 1f)
            {
                randomNumber *= rollingProbabilityDensity;
            }

            double rollingProbability = 0;

            UwePrefab selectedPrefab = allowedPrefabs.FirstOrDefault(prefab =>
            {
                if (prefab.Probability == 0)
                {
                    return(false);
                }

                float probabilityDensity = prefab.Probability / entitySpawnPoint.Density;

                rollingProbability += probabilityDensity;

                return(rollingProbability >= randomNumber);
            });

            if (selectedPrefab == null)
            {
                yield break;
            }

            Optional <UweWorldEntity> opWorldEntity = worldEntityFactory.From(selectedPrefab.ClassId);

            if (opWorldEntity.IsPresent())
            {
                UweWorldEntity uweWorldEntity = opWorldEntity.Get();

                for (int i = 0; i < selectedPrefab.Count; i++)
                {
                    IEnumerable <Entity> entities = CreateEntityWithChildren(entitySpawnPoint,
                                                                             uweWorldEntity.Scale,
                                                                             uweWorldEntity.TechType,
                                                                             uweWorldEntity.CellLevel,
                                                                             selectedPrefab.ClassId,
                                                                             deterministicBatchGenerator);
                    foreach (Entity entity in entities)
                    {
                        yield return(entity);
                    }
                }
            }
        }
示例#2
0
        public override List <UwePrefab> GetPossiblePrefabs(string biome)
        {
            List <UwePrefab> prefabs = new List <UwePrefab>();

            if (biome == null)
            {
                return(prefabs);
            }


            BiomeType biomeType = (BiomeType)Enum.Parse(typeof(BiomeType), biome);

            if (lootDistributionData.GetBiomeLoot(biomeType, out DstData dstData))
            {
                foreach (PrefabData prefabData in dstData.prefabs)
                {
                    UwePrefab prefab = new UwePrefab(prefabData.classId, prefabData.probability, prefabData.count);
                    prefabs.Add(prefab);
                }
            }

            return(prefabs);
        }