protected void Start() { uint num = base.transform.position.Seed(World.Seed + this.Seed); if (SeedRandom.Value(ref num) > this.Probability) { for (int i = 0; i < (int)this.Candidates.Length; i++) { GameManager.Destroy(this.Candidates[i], 0f); } GameManager.Destroy(this, 0f); return; } int num1 = SeedRandom.Range(num, 0, base.transform.childCount); for (int j = 0; j < (int)this.Candidates.Length; j++) { GameObject candidates = this.Candidates[j]; if (j != num1) { GameManager.Destroy(candidates, 0f); } else { candidates.SetActive(true); } } GameManager.Destroy(this, 0f); }
public override void Apply(ref Vector3 pos, ref Quaternion rot, ref Vector3 scale) { uint num = pos.Seed(World.Seed) + 4; if (SeedRandom.Value(ref num) > 0.5f) { return; } switch (this.FlipAxis) { case DecorFlip.AxisType.X: case DecorFlip.AxisType.Z: { rot = Quaternion.AngleAxis(180f, rot * Vector3.up) * rot; return; } case DecorFlip.AxisType.Y: { rot = Quaternion.AngleAxis(180f, rot * Vector3.forward) * rot; return; } default: { return; } } }
private Climate.WeatherState GetWeatherState(uint seed) { int num1 = (int)SeedRandom.Wanghash(ref seed); bool flag1 = (double)SeedRandom.Value(ref seed) < (double)this.Weather.CloudChance; bool flag2 = (double)SeedRandom.Value(ref seed) < (double)this.Weather.FogChance; bool flag3 = (double)SeedRandom.Value(ref seed) < (double)this.Weather.RainChance; int num2 = (double)SeedRandom.Value(ref seed) < (double)this.Weather.StormChance ? 1 : 0; float num3 = flag1 ? SeedRandom.Value(ref seed) : 0.0f; float num4 = flag2 ? 1f : 0.0f; float num5 = flag3 ? 1f : 0.0f; float num6 = num2 != 0 ? SeedRandom.Value(ref seed) : 0.0f; if ((double)num5 > 0.0) { num5 = Mathf.Max(num5, 0.5f); num4 = Mathf.Max(num4, num5); num3 = Mathf.Max(num3, num5); } return(new Climate.WeatherState() { Clouds = num3, Fog = num4, Wind = num6, Rain = num5 }); }
protected void Start() { uint num1 = SeedEx.Seed(((Component)this).get_transform().get_position(), World.Seed + this.Seed); if ((double)SeedRandom.Value(ref num1) > (double)this.Probability) { for (int index = 0; index < this.Candidates.Length; ++index) { GameManager.Destroy(this.Candidates[index], 0.0f); } GameManager.Destroy((Component)this, 0.0f); } else { int num2 = SeedRandom.Range(num1, 0, ((Component)this).get_transform().get_childCount()); for (int index = 0; index < this.Candidates.Length; ++index) { GameObject candidate = this.Candidates[index]; if (index == num2) { candidate.SetActive(true); } else { GameManager.Destroy(candidate, 0.0f); } } GameManager.Destroy((Component)this, 0.0f); } }
private void OnEnable() { this.isRegistered = false; if (Object.op_Equality((Object)SingletonComponent <AiManager> .Instance, (Object)null) || !((Behaviour)SingletonComponent <AiManager> .Instance).get_enabled() || AiManager.nav_disable) { ((Behaviour)this).set_enabled(false); } else { this.agent = (IAIAgent)((Component)this).GetComponent <IAIAgent>(); if (this.agent == null) { return; } if (this.agent.Entity.isClient) { ((Behaviour)this).set_enabled(false); } else { this.agent.AgentTypeIndex = this.AgentTypeIndex; this.Invoke(new Action(this.DelayedRegistration), SeedRandom.Value((uint)Mathf.Abs(((Object)this).GetInstanceID())) * 3f); } } }
public override void Process(uint seed) { TerrainHeightMap heightMap = TerrainMeta.HeightMap; Vector3 position1 = TerrainMeta.Position; Vector3 size = TerrainMeta.Size; float x1 = (float)position1.x; float z1 = (float)position1.z; float num1 = (float)(position1.x + size.x); float num2 = (float)(position1.z + size.z); PlaceMonument.SpawnInfo spawnInfo1 = new PlaceMonument.SpawnInfo(); int num3 = int.MinValue; Prefab <MonumentInfo> prefab1 = Prefab.Load <MonumentInfo>(this.Monument.resourceID, (GameManager)null, (PrefabAttribute.Library)null); for (int index = 0; index < 10000; ++index) { float x2 = SeedRandom.Range(ref seed, x1, num1); float z2 = SeedRandom.Range(ref seed, z1, num2); float normX = TerrainMeta.NormalizeX(x2); float normZ = TerrainMeta.NormalizeZ(z2); float num4 = SeedRandom.Value(ref seed); double factor = (double)this.Filter.GetFactor(normX, normZ); if (factor * factor >= (double)num4) { float height = heightMap.GetHeight(normX, normZ); Vector3 pos; ((Vector3) ref pos).\u002Ector(x2, height, z2); Quaternion localRotation = prefab1.Object.get_transform().get_localRotation(); Vector3 localScale = prefab1.Object.get_transform().get_localScale(); prefab1.ApplyDecorComponents(ref pos, ref localRotation, ref localScale); if ((!Object.op_Implicit((Object)prefab1.Component) || prefab1.Component.CheckPlacement(pos, localRotation, localScale)) && (prefab1.ApplyTerrainAnchors(ref pos, localRotation, localScale, this.Filter) && prefab1.ApplyTerrainChecks(pos, localRotation, localScale, this.Filter)) && (prefab1.ApplyTerrainFilters(pos, localRotation, localScale, (SpawnFilter)null) && prefab1.ApplyWaterChecks(pos, localRotation, localScale) && !prefab1.CheckEnvironmentVolumes(pos, localRotation, localScale, EnvironmentType.Underground))) { PlaceMonument.SpawnInfo spawnInfo2 = new PlaceMonument.SpawnInfo(); spawnInfo2.prefab = (Prefab)prefab1; spawnInfo2.position = pos; spawnInfo2.rotation = localRotation; spawnInfo2.scale = localScale; int num5 = -Mathf.RoundToInt(Vector3Ex.Magnitude2D(pos)); if (num5 > num3) { num3 = num5; spawnInfo1 = spawnInfo2; } } } } if (num3 == int.MinValue) { return; } Prefab prefab2 = spawnInfo1.prefab; Vector3 position2 = spawnInfo1.position; Quaternion rotation = spawnInfo1.rotation; Vector3 scale = spawnInfo1.scale; prefab2.ApplyTerrainPlacements(position2, rotation, scale); prefab2.ApplyTerrainModifiers(position2, rotation, scale); World.AddPrefab("Monument", prefab2.ID, position2, rotation, scale); }
public override void Process(uint seed) { TerrainHeightMap heightMap = TerrainMeta.HeightMap; Vector3 position = TerrainMeta.Position; Vector3 size = TerrainMeta.Size; float single = position.x; float single1 = position.z; float single2 = position.x + size.x; float single3 = position.z + size.z; PlaceMonument.SpawnInfo spawnInfo = new PlaceMonument.SpawnInfo(); int num = -2147483648; Prefab <MonumentInfo> prefab = Prefab.Load <MonumentInfo>(this.Monument.resourceID, null, null); for (int i = 0; i < 10000; i++) { float single4 = SeedRandom.Range(ref seed, single, single2); float single5 = SeedRandom.Range(ref seed, single1, single3); float single6 = TerrainMeta.NormalizeX(single4); float single7 = TerrainMeta.NormalizeZ(single5); float single8 = SeedRandom.Value(ref seed); float factor = this.Filter.GetFactor(single6, single7); if (factor * factor >= single8) { float height = heightMap.GetHeight(single6, single7); Vector3 vector3 = new Vector3(single4, height, single5); Quaternion obj = prefab.Object.transform.localRotation; Vector3 obj1 = prefab.Object.transform.localScale; prefab.ApplyDecorComponents(ref vector3, ref obj, ref obj1); if ((!prefab.Component || prefab.Component.CheckPlacement(vector3, obj, obj1)) && prefab.ApplyTerrainAnchors(ref vector3, obj, obj1, this.Filter) && prefab.ApplyTerrainChecks(vector3, obj, obj1, this.Filter) && prefab.ApplyTerrainFilters(vector3, obj, obj1, null) && prefab.ApplyWaterChecks(vector3, obj, obj1) && !prefab.CheckEnvironmentVolumes(vector3, obj, obj1, EnvironmentType.Underground)) { PlaceMonument.SpawnInfo spawnInfo1 = new PlaceMonument.SpawnInfo() { prefab = prefab, position = vector3, rotation = obj, scale = obj1 }; int num1 = -Mathf.RoundToInt(vector3.Magnitude2D()); if (num1 > num) { num = num1; spawnInfo = spawnInfo1; } } } } if (num != -2147483648) { Prefab prefab1 = spawnInfo.prefab; Vector3 vector31 = spawnInfo.position; Quaternion quaternion = spawnInfo.rotation; Vector3 vector32 = spawnInfo.scale; prefab1.ApplyTerrainPlacements(vector31, quaternion, vector32); prefab1.ApplyTerrainModifiers(vector31, quaternion, vector32); World.AddPrefab("Monument", prefab1.ID, vector31, quaternion, vector32); } }
public override void Apply(ref Vector3 pos, ref Quaternion rot, ref Vector3 scale) { uint num = pos.Seed(World.Seed) + 3; float single = SeedRandom.Value(ref num); scale.x *= Mathf.Lerp(this.MinScale.x, this.MaxScale.x, single); scale.y *= Mathf.Lerp(this.MinScale.y, this.MaxScale.y, single); scale.z *= Mathf.Lerp(this.MinScale.z, this.MaxScale.z, single); }
public override void Apply(ref Vector3 pos, ref Quaternion rot, ref Vector3 scale) { uint seed = pos.Seed(World.Seed) + 3; float t = SeedRandom.Value(ref seed); scale.x *= Mathf.Lerp(MinScale.x, MaxScale.x, t); scale.y *= Mathf.Lerp(MinScale.y, MaxScale.y, t); scale.z *= Mathf.Lerp(MinScale.z, MaxScale.z, t); }
protected void Start() { uint num = base.transform.position.Seed(World.Seed + this.Seed); if (SeedRandom.Value(ref num) > this.Probability) { GameManager.Destroy(this, 0f); return; } GameManager.Destroy(base.gameObject, 0f); }
protected void Start() { uint num = base.transform.position.Seed(World.Seed + this.Seed); if (SeedRandom.Value(ref num) > this.Probability) { GameManager.Destroy(this, 0f); return; } Prefab.LoadRandom(string.Concat("assets/bundled/prefabs/autospawn/", this.ResourceFolder), ref num, null, null, true).Spawn(base.transform); GameManager.Destroy(this, 0f); }
protected void Start() { uint num = SeedEx.Seed(((Component)this).get_transform().get_position(), World.Seed + this.Seed); if ((double)SeedRandom.Value(ref num) > (double)this.Probability) { GameManager.Destroy((Component)this, 0.0f); } else { GameManager.Destroy(((Component)this).get_gameObject(), 0.0f); } }
protected void Start() { uint seed = SeedEx.Seed(((Component)this).get_transform().get_position(), World.Seed + this.Seed); if ((double)SeedRandom.Value(ref seed) > (double)this.Probability) { GameManager.Destroy((Component)this, 0.0f); } else { Prefab.LoadRandom("assets/bundled/prefabs/autospawn/" + this.ResourceFolder, ref seed, (GameManager)null, (PrefabAttribute.Library)null, true).Spawn(((Component)this).get_transform()); GameManager.Destroy((Component)this, 0.0f); } }
public override void Process(uint seed) { TerrainHeightMap heightMap = TerrainMeta.HeightMap; Prefab[] array = Prefab.Load("assets/bundled/prefabs/autospawn/" + this.ResourceFolder, (GameManager)null, (PrefabAttribute.Library)null, true); if (array == null || array.Length == 0) { return; } Vector3 position = TerrainMeta.Position; Vector3 size = TerrainMeta.Size; int num1 = Mathf.RoundToInt((float)((double)this.ObjectDensity * size.x * size.z * 9.99999997475243E-07)); float x1 = (float)position.x; float z1 = (float)position.z; float num2 = (float)(position.x + size.x); float num3 = (float)(position.z + size.z); float num4 = SeedRandom.Range(ref seed, -1000000f, 1000000f); float num5 = SeedRandom.Range(ref seed, -1000000f, 1000000f); int octaves = this.Cluster.Octaves; float offset = this.Cluster.Offset; float frequency = this.Cluster.Frequency * 0.01f; float amplitude = this.Cluster.Amplitude; for (int index = 0; index < num1; ++index) { float x2 = SeedRandom.Range(ref seed, x1, num2); float z2 = SeedRandom.Range(ref seed, z1, num3); float normX = TerrainMeta.NormalizeX(x2); float normZ = TerrainMeta.NormalizeZ(z2); float num6 = SeedRandom.Value(ref seed); float factor = this.Filter.GetFactor(normX, normZ); Prefab random = array.GetRandom <Prefab>(ref seed); if ((double)factor > 0.0 && ((double)offset + (double)Noise.Turbulence(num4 + x2, num5 + z2, octaves, frequency, amplitude, 2f, 0.5f)) * (double)factor * (double)factor >= (double)num6) { float height = heightMap.GetHeight(normX, normZ); Vector3 pos; ((Vector3) ref pos).\u002Ector(x2, height, z2); Quaternion localRotation = random.Object.get_transform().get_localRotation(); Vector3 localScale = random.Object.get_transform().get_localScale(); random.ApplyDecorComponents(ref pos, ref localRotation, ref localScale); if (random.ApplyTerrainAnchors(ref pos, localRotation, localScale, this.Filter) && random.ApplyTerrainChecks(pos, localRotation, localScale, this.Filter) && (random.ApplyTerrainFilters(pos, localRotation, localScale, (SpawnFilter)null) && random.ApplyWaterChecks(pos, localRotation, localScale))) { random.ApplyTerrainModifiers(pos, localRotation, localScale); World.AddPrefab("Decor", random.ID, pos, localRotation, localScale); } } } }
private Climate.WeatherState GetWeatherState(uint seed) { object obj; object obj1; SeedRandom.Wanghash(ref seed); bool flag = SeedRandom.Value(ref seed) < this.Weather.CloudChance; bool flag1 = SeedRandom.Value(ref seed) < this.Weather.FogChance; bool flag2 = SeedRandom.Value(ref seed) < this.Weather.RainChance; bool flag3 = SeedRandom.Value(ref seed) < this.Weather.StormChance; float single = (flag ? SeedRandom.Value(ref seed) : 0f); if (flag1) { obj = 1; } else { obj = null; } float single1 = (float)obj; if (flag2) { obj1 = 1; } else { obj1 = null; } float single2 = (float)obj1; float single3 = (flag3 ? SeedRandom.Value(ref seed) : 0f); if (single2 > 0f) { single2 = Mathf.Max(single2, 0.5f); single1 = Mathf.Max(single1, single2); single = Mathf.Max(single, single2); } Climate.WeatherState weatherState = new Climate.WeatherState() { Clouds = single, Fog = single1, Wind = single3, Rain = single2 }; return(weatherState); }
public override void Process(uint seed) { TerrainHeightMap heightMap = TerrainMeta.HeightMap; Prefab[] prefabArray = Prefab.Load(string.Concat("assets/bundled/prefabs/autospawn/", this.ResourceFolder), null, null, true); if (prefabArray == null || prefabArray.Length == 0) { return; } Vector3 position = TerrainMeta.Position; Vector3 size = TerrainMeta.Size; int num = Mathf.RoundToInt(this.ObjectDensity * size.x * size.z * 1E-06f); float single = position.x; float single1 = position.z; float single2 = position.x + size.x; float single3 = position.z + size.z; float single4 = SeedRandom.Range(ref seed, -1000000f, 1000000f); float single5 = SeedRandom.Range(ref seed, -1000000f, 1000000f); int octaves = this.Cluster.Octaves; float offset = this.Cluster.Offset; float frequency = this.Cluster.Frequency * 0.01f; float amplitude = this.Cluster.Amplitude; for (int i = 0; i < num; i++) { float single6 = SeedRandom.Range(ref seed, single, single2); float single7 = SeedRandom.Range(ref seed, single1, single3); float single8 = TerrainMeta.NormalizeX(single6); float single9 = TerrainMeta.NormalizeZ(single7); float single10 = SeedRandom.Value(ref seed); float factor = this.Filter.GetFactor(single8, single9); Prefab random = prefabArray.GetRandom <Prefab>(ref seed); if (factor > 0f && (offset + Noise.Turbulence(single4 + single6, single5 + single7, octaves, frequency, amplitude, 2f, 0.5f)) * factor * factor >= single10) { float height = heightMap.GetHeight(single8, single9); Vector3 vector3 = new Vector3(single6, height, single7); Quaternion obj = random.Object.transform.localRotation; Vector3 obj1 = random.Object.transform.localScale; random.ApplyDecorComponents(ref vector3, ref obj, ref obj1); if (random.ApplyTerrainAnchors(ref vector3, obj, obj1, this.Filter) && random.ApplyTerrainChecks(vector3, obj, obj1, this.Filter) && random.ApplyTerrainFilters(vector3, obj, obj1, null) && random.ApplyWaterChecks(vector3, obj, obj1)) { random.ApplyTerrainModifiers(vector3, obj, obj1); World.AddPrefab("Decor", random.ID, vector3, obj, obj1); } } } }
public static float GetRainbow(Vector3 position) { if (!Initialized()) { return(0f); } TOD_Sky instance = TOD_Sky.Instance; if (!instance || !instance.IsDay || instance.LerpValue < 1f) { return(0f); } if (GetFog(position) > 0.25f) { return(0f); } float num = (TerrainMeta.BiomeMap ? TerrainMeta.BiomeMap.GetBiome(position, 3) : 0f); if (num <= 0f) { return(0f); } float rainbow = SingletonComponent <Climate> .Instance.WeatherOverrides.Rainbow; if (rainbow >= 0f) { return(rainbow * num); } if (SingletonComponent <Climate> .Instance.WeatherState.Rainbow <= 0f) { return(0f); } if (SingletonComponent <Climate> .Instance.WeatherStateTarget.Rainbow > 0f) { return(0f); } float rainbow2 = SingletonComponent <Climate> .Instance.WeatherStatePrevious.Rainbow; float num2 = SeedRandom.Value(SingletonComponent <Climate> .Instance.WeatherSeedPrevious); if (rainbow2 < num2) { return(0f); } return(num); }
public override void Process(uint seed) { TerrainHeightMap heightMap = TerrainMeta.HeightMap; Prefab[] array = Prefab.Load("assets/bundled/prefabs/autospawn/" + this.ResourceFolder, (GameManager)null, (PrefabAttribute.Library)null, true); if (array == null || array.Length == 0) { return; } Vector3 position = TerrainMeta.Position; Vector3 size = TerrainMeta.Size; float x1 = (float)position.x; float z1 = (float)position.z; float num1 = (float)(position.x + size.x); float num2 = (float)(position.z + size.z); for (float num3 = z1; (double)num3 < (double)num2; num3 += this.ObjectDistance) { for (float num4 = x1; (double)num4 < (double)num1; num4 += this.ObjectDistance) { float x2 = num4 + SeedRandom.Range(ref seed, -this.ObjectDithering, this.ObjectDithering); float z2 = num3 + SeedRandom.Range(ref seed, -this.ObjectDithering, this.ObjectDithering); float normX = TerrainMeta.NormalizeX(x2); float normZ = TerrainMeta.NormalizeZ(z2); float num5 = SeedRandom.Value(ref seed); double factor = (double)this.Filter.GetFactor(normX, normZ); Prefab random = array.GetRandom <Prefab>(ref seed); if (factor * factor >= (double)num5) { float height = heightMap.GetHeight(normX, normZ); Vector3 pos; ((Vector3) ref pos).\u002Ector(x2, height, z2); Quaternion localRotation = random.Object.get_transform().get_localRotation(); Vector3 localScale = random.Object.get_transform().get_localScale(); random.ApplyDecorComponents(ref pos, ref localRotation, ref localScale); if (random.ApplyTerrainAnchors(ref pos, localRotation, localScale, this.Filter) && random.ApplyTerrainChecks(pos, localRotation, localScale, this.Filter) && (random.ApplyTerrainFilters(pos, localRotation, localScale, (SpawnFilter)null) && random.ApplyWaterChecks(pos, localRotation, localScale))) { random.ApplyTerrainModifiers(pos, localRotation, localScale); World.AddPrefab("Decor", random.ID, pos, localRotation, localScale); } } } } }
public override void Process(uint seed) { TerrainHeightMap heightMap = TerrainMeta.HeightMap; Prefab[] prefabArray = Prefab.Load(string.Concat("assets/bundled/prefabs/autospawn/", this.ResourceFolder), null, null, true); if (prefabArray == null || prefabArray.Length == 0) { return; } Vector3 position = TerrainMeta.Position; Vector3 size = TerrainMeta.Size; float single = position.x; float single1 = position.z; float single2 = position.x + size.x; float single3 = position.z + size.z; for (float i = single1; i < single3; i += this.ObjectDistance) { for (float j = single; j < single2; j += this.ObjectDistance) { float single4 = j + SeedRandom.Range(ref seed, -this.ObjectDithering, this.ObjectDithering); float single5 = i + SeedRandom.Range(ref seed, -this.ObjectDithering, this.ObjectDithering); float single6 = TerrainMeta.NormalizeX(single4); float single7 = TerrainMeta.NormalizeZ(single5); float single8 = SeedRandom.Value(ref seed); float factor = this.Filter.GetFactor(single6, single7); Prefab random = prefabArray.GetRandom <Prefab>(ref seed); if (factor * factor >= single8) { float height = heightMap.GetHeight(single6, single7); Vector3 vector3 = new Vector3(single4, height, single5); Quaternion obj = random.Object.transform.localRotation; Vector3 obj1 = random.Object.transform.localScale; random.ApplyDecorComponents(ref vector3, ref obj, ref obj1); if (random.ApplyTerrainAnchors(ref vector3, obj, obj1, this.Filter) && random.ApplyTerrainChecks(vector3, obj, obj1, this.Filter) && random.ApplyTerrainFilters(vector3, obj, obj1, null) && random.ApplyWaterChecks(vector3, obj, obj1)) { random.ApplyTerrainModifiers(vector3, obj, obj1); World.AddPrefab("Decor", random.ID, vector3, obj, obj1); } } } } }
public override void Apply(ref Vector3 pos, ref Quaternion rot, ref Vector3 scale) { uint seed = pos.Seed(World.Seed) + 4; if (!(SeedRandom.Value(ref seed) > 0.5f)) { switch (FlipAxis) { case AxisType.X: case AxisType.Z: rot = Quaternion.AngleAxis(180f, rot * Vector3.up) * rot; break; case AxisType.Y: rot = Quaternion.AngleAxis(180f, rot * Vector3.forward) * rot; break; } } }
public override void Apply(ref Vector3 pos, ref Quaternion rot, ref Vector3 scale) { uint num = SeedEx.Seed(pos, World.Seed) + 4U; if ((double)SeedRandom.Value(ref num) > 0.5) { return; } switch (this.FlipAxis) { case DecorFlip.AxisType.X: case DecorFlip.AxisType.Z: rot = Quaternion.op_Multiply(Quaternion.AngleAxis(180f, Quaternion.op_Multiply(rot, Vector3.get_up())), rot); break; case DecorFlip.AxisType.Y: rot = Quaternion.op_Multiply(Quaternion.AngleAxis(180f, Quaternion.op_Multiply(rot, Vector3.get_forward())), rot); break; } }
private void OnEnable() { this.isRegistered = false; if (SingletonComponent <AiManager> .Instance == null || !SingletonComponent <AiManager> .Instance.enabled || AiManager.nav_disable) { base.enabled = false; return; } this.agent = base.GetComponent <IAIAgent>(); if (this.agent != null) { if (this.agent.Entity.isClient) { base.enabled = false; return; } this.agent.AgentTypeIndex = this.AgentTypeIndex; float single = SeedRandom.Value((uint)Mathf.Abs(base.GetInstanceID())); base.Invoke(new Action(this.DelayedRegistration), single * 3f); } }
public void SpawnAlong(ref uint seed, PathList.PathObject obj) { if (string.IsNullOrEmpty(obj.Folder)) { return; } Prefab[] prefabArray = Prefab.Load(string.Concat("assets/bundled/prefabs/autospawn/", obj.Folder), null, null, true); if (prefabArray == null || prefabArray.Length == 0) { Debug.LogError(string.Concat("Empty decor folder: ", obj.Folder)); return; } SpawnFilter filter = obj.Filter; float density = obj.Density; float distance = obj.Distance; float dithering = obj.Dithering; TerrainHeightMap heightMap = TerrainMeta.HeightMap; Vector3 startPoint = this.Path.GetStartPoint(); List <Vector3> vector3s = new List <Vector3>(); float single = distance * 0.25f; float single1 = distance * 0.5f; float length = this.Path.Length - this.Path.EndOffset - single1; for (float i = this.Path.StartOffset + single1; i <= length; i += single) { Vector3 vector3 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i)); if ((vector3 - startPoint).magnitude >= distance) { Vector3 tangent = this.Path.GetTangent(i); Vector3 vector31 = PathList.rot90 * tangent; Vector3 height = vector3; height.x += SeedRandom.Range(ref seed, -dithering, dithering); height.z += SeedRandom.Range(ref seed, -dithering, dithering); float single2 = TerrainMeta.NormalizeX(height.x); float single3 = TerrainMeta.NormalizeZ(height.z); if (filter.GetFactor(single2, single3) >= SeedRandom.Value(ref seed)) { if (density >= SeedRandom.Value(ref seed)) { height.y = heightMap.GetHeight(single2, single3); if (obj.Alignment == PathList.Alignment.None) { if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.identity, filter)) { goto Label1; } goto Label0; } else if (obj.Alignment == PathList.Alignment.Forward) { if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(tangent), filter)) { goto Label1; } goto Label0; } else if (obj.Alignment != PathList.Alignment.Inward) { vector3s.Add(height); } else { if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(vector31), filter)) { goto Label1; } goto Label0; } } Label1: startPoint = vector3; } } Label0: } if (vector3s.Count > 0) { this.SpawnObjectsNeighborAligned(ref seed, prefabArray, vector3s, filter); } }
public void SpawnSide(ref uint seed, PathList.SideObject obj) { if (string.IsNullOrEmpty(obj.Folder)) { return; } Prefab[] prefabArray = Prefab.Load(string.Concat("assets/bundled/prefabs/autospawn/", obj.Folder), null, null, true); if (prefabArray == null || prefabArray.Length == 0) { Debug.LogError(string.Concat("Empty decor folder: ", obj.Folder)); return; } PathList.Side side = obj.Side; SpawnFilter filter = obj.Filter; float density = obj.Density; float distance = obj.Distance; float width = this.Width * 0.5f + obj.Offset; TerrainHeightMap heightMap = TerrainMeta.HeightMap; float[] singleArray = new float[] { -width, width }; int num = 0; Vector3 startPoint = this.Path.GetStartPoint(); List <Vector3> vector3s = new List <Vector3>(); float single = distance * 0.25f; float single1 = distance * 0.5f; float length = this.Path.Length - this.Path.EndOffset - single1; for (float i = this.Path.StartOffset + single1; i <= length; i += single) { Vector3 vector3 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i)); if ((vector3 - startPoint).magnitude >= distance) { Vector3 tangent = this.Path.GetTangent(i); Vector3 vector31 = PathList.rot90 * tangent; for (int j = 0; j < (int)singleArray.Length; j++) { int length1 = (num + j) % (int)singleArray.Length; if ((side != PathList.Side.Left || length1 == 0) && (side != PathList.Side.Right || length1 == 1)) { float single2 = singleArray[length1]; Vector3 height = vector3; ref float singlePointer = ref height.x; singlePointer = singlePointer + vector31.x * single2; ref float singlePointer1 = ref height.z; singlePointer1 = singlePointer1 + vector31.z * single2; float single3 = TerrainMeta.NormalizeX(height.x); float single4 = TerrainMeta.NormalizeZ(height.z); if (filter.GetFactor(single3, single4) >= SeedRandom.Value(ref seed)) { if (density >= SeedRandom.Value(ref seed)) { height.y = heightMap.GetHeight(single3, single4); if (obj.Alignment == PathList.Alignment.None) { if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.identity, filter)) { goto Label1; } goto Label0; } else if (obj.Alignment == PathList.Alignment.Forward) { if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(tangent * single2), filter)) { goto Label1; } goto Label0; } else if (obj.Alignment != PathList.Alignment.Inward) { vector3s.Add(height); } else { if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(-vector31 * single2), filter)) { goto Label1; } goto Label0; } } Label1: num = length1; startPoint = vector3; if (side == PathList.Side.Any) { break; } } } Label0: } }
public override void Process(uint seed) { if ((long)World.Size < (long)this.MinSize) { return; } TerrainHeightMap heightMap = TerrainMeta.HeightMap; Prefab <MonumentInfo>[] array = Prefab.Load <MonumentInfo>("assets/bundled/prefabs/autospawn/" + this.ResourceFolder, (GameManager)null, (PrefabAttribute.Library)null, true); if (array == null || array.Length == 0) { return; } array.Shuffle <Prefab <MonumentInfo> >(seed); array.BubbleSort <Prefab <MonumentInfo> >(); Vector3 position1 = TerrainMeta.Position; Vector3 size = TerrainMeta.Size; float x1 = (float)position1.x; float z1 = (float)position1.z; float num1 = (float)(position1.x + size.x); float num2 = (float)(position1.z + size.z); List <PlaceMonuments.SpawnInfo> a = new List <PlaceMonuments.SpawnInfo>(); int num3 = 0; List <PlaceMonuments.SpawnInfo> b = new List <PlaceMonuments.SpawnInfo>(); for (int index1 = 0; index1 < 10; ++index1) { int num4 = 0; a.Clear(); foreach (Prefab <MonumentInfo> prefab in array) { int num5 = Object.op_Implicit((Object)prefab.Parameters) ? (int)(prefab.Parameters.Priority + 1) : 1; int num6 = num5 * num5 * num5 * num5; for (int index2 = 0; index2 < 10000; ++index2) { float x2 = SeedRandom.Range(ref seed, x1, num1); float z2 = SeedRandom.Range(ref seed, z1, num2); float normX = TerrainMeta.NormalizeX(x2); float normZ = TerrainMeta.NormalizeZ(z2); float num7 = SeedRandom.Value(ref seed); double factor = (double)this.Filter.GetFactor(normX, normZ); if (factor * factor >= (double)num7) { float height = heightMap.GetHeight(normX, normZ); Vector3 pos; ((Vector3) ref pos).\u002Ector(x2, height, z2); Quaternion localRotation = prefab.Object.get_transform().get_localRotation(); Vector3 localScale = prefab.Object.get_transform().get_localScale(); if (!this.CheckRadius(a, pos, (float)this.Distance)) { prefab.ApplyDecorComponents(ref pos, ref localRotation, ref localScale); if ((!Object.op_Implicit((Object)prefab.Component) || prefab.Component.CheckPlacement(pos, localRotation, localScale)) && (prefab.ApplyTerrainAnchors(ref pos, localRotation, localScale, this.Filter) && prefab.ApplyTerrainChecks(pos, localRotation, localScale, this.Filter)) && (prefab.ApplyTerrainFilters(pos, localRotation, localScale, (SpawnFilter)null) && prefab.ApplyWaterChecks(pos, localRotation, localScale) && !prefab.CheckEnvironmentVolumes(pos, localRotation, localScale, EnvironmentType.Underground))) { a.Add(new PlaceMonuments.SpawnInfo() { prefab = (Prefab)prefab, position = pos, rotation = localRotation, scale = localScale }); num4 += num6; break; } } } } } if (num4 > num3) { num3 = num4; GenericsUtil.Swap <List <PlaceMonuments.SpawnInfo> >(ref a, ref b); } } foreach (PlaceMonuments.SpawnInfo spawnInfo in b) { Prefab prefab = spawnInfo.prefab; Vector3 position2 = spawnInfo.position; Quaternion rotation = spawnInfo.rotation; Vector3 scale = spawnInfo.scale; prefab.ApplyTerrainPlacements(position2, rotation, scale); prefab.ApplyTerrainModifiers(position2, rotation, scale); World.AddPrefab("Monument", prefab.ID, position2, rotation, scale); } }
public override void Process(uint seed) { if (World.Cached) { TerrainMeta.Path.DungeonRoot = HierarchyUtil.GetRoot("Dungeon"); return; } if (World.Networked) { World.Spawn("Dungeon"); TerrainMeta.Path.DungeonRoot = HierarchyUtil.GetRoot("Dungeon"); return; } Prefab <DungeonCell>[] array = Prefab.Load <DungeonCell>("assets/bundled/prefabs/autospawn/" + TunnelFolder); if (array == null || array.Length == 0) { return; } Prefab <DungeonCell>[] array2 = Prefab.Load <DungeonCell>("assets/bundled/prefabs/autospawn/" + StationFolder); if (array2 == null || array2.Length == 0) { return; } Prefab <DungeonCell>[] array3 = Prefab.Load <DungeonCell>("assets/bundled/prefabs/autospawn/" + TransitionFolder); if (array3 == null) { return; } Prefab <DungeonLink>[] array4 = Prefab.Load <DungeonLink>("assets/bundled/prefabs/autospawn/" + LinkFolder); if (array4 == null) { return; } array4 = array4.OrderByDescending((Prefab <DungeonLink> x) => x.Component.Priority).ToArray(); List <DungeonInfo> list = (TerrainMeta.Path ? TerrainMeta.Path.DungeonEntrances : null); WorldSpaceGrid <Prefab <DungeonCell> > worldSpaceGrid = new WorldSpaceGrid <Prefab <DungeonCell> >(TerrainMeta.Size.x * 2f, CellSize); int[,] array5 = new int[worldSpaceGrid.CellCount, worldSpaceGrid.CellCount]; _003C_003Ec__DisplayClass17_0 _003C_003Ec__DisplayClass17_ = default(_003C_003Ec__DisplayClass17_0); _003C_003Ec__DisplayClass17_.hashmap = new DungeonConnectionHash[worldSpaceGrid.CellCount, worldSpaceGrid.CellCount]; _003C_003Ec__DisplayClass17_.pathFinder = new PathFinder(array5, false); int cellCount = worldSpaceGrid.CellCount; int num = 0; int num2 = worldSpaceGrid.CellCount - 1; for (int i = 0; i < cellCount; i++) { for (int j = 0; j < cellCount; j++) { array5[j, i] = 1; } } List <PathSegment> list2 = new List <PathSegment>(); List <PathLink> list3 = new List <PathLink>(); List <PathNode> list4 = new List <PathNode>(); _003C_003Ec__DisplayClass17_.unconnectedNodeList = new List <PathNode>(); _003C_003Ec__DisplayClass17_.secondaryNodeList = new List <PathNode>(); List <PathFinder.Point> list5 = new List <PathFinder.Point>(); List <PathFinder.Point> list6 = new List <PathFinder.Point>(); List <PathFinder.Point> list7 = new List <PathFinder.Point>(); _003C_003Ec__DisplayClass17_1 _003C_003Ec__DisplayClass17_2 = default(_003C_003Ec__DisplayClass17_1); _003C_003Ec__DisplayClass17_3 _003C_003Ec__DisplayClass17_3 = default(_003C_003Ec__DisplayClass17_3); foreach (DungeonInfo item in list) { _003C_003Ec__DisplayClass17_2.entrance = item; TerrainPathConnect[] componentsInChildren = _003C_003Ec__DisplayClass17_2.entrance.GetComponentsInChildren <TerrainPathConnect>(true); foreach (TerrainPathConnect terrainPathConnect in componentsInChildren) { _003C_003Ec__DisplayClass17_2 CS_0024_003C_003E8__locals0 = new _003C_003Ec__DisplayClass17_2(); CS_0024_003C_003E8__locals0._003C_003E4__this = this; if (terrainPathConnect.Type != ConnectionType) { continue; } Vector2i cellPos = worldSpaceGrid.WorldToGridCoords(terrainPathConnect.transform.position); if (array5[cellPos.x, cellPos.y] == int.MaxValue) { continue; } CS_0024_003C_003E8__locals0.stationNode = _003C_003Ec__DisplayClass17_.pathFinder.FindClosestWalkable(new PathFinder.Point(cellPos.x, cellPos.y), 1); if (CS_0024_003C_003E8__locals0.stationNode == null) { continue; } Prefab <DungeonCell> prefab = ((cellPos.x > num) ? worldSpaceGrid[cellPos.x - 1, cellPos.y] : null); Prefab <DungeonCell> prefab2 = ((cellPos.x < num2) ? worldSpaceGrid[cellPos.x + 1, cellPos.y] : null); Prefab <DungeonCell> prefab3 = ((cellPos.y > num) ? worldSpaceGrid[cellPos.x, cellPos.y - 1] : null); Prefab <DungeonCell> prefab4 = ((cellPos.y < num2) ? worldSpaceGrid[cellPos.x, cellPos.y + 1] : null); Prefab <DungeonCell> prefab5 = null; float num3 = float.MaxValue; ArrayEx.Shuffle(array2, ref seed); Prefab <DungeonCell>[] array6 = array2; foreach (Prefab <DungeonCell> prefab6 in array6) { if ((prefab != null && prefab6.Component.West != prefab.Component.East) || (prefab2 != null && prefab6.Component.East != prefab2.Component.West) || (prefab3 != null && prefab6.Component.South != prefab3.Component.North) || (prefab4 != null && prefab6.Component.North != prefab4.Component.South)) { continue; } DungeonLinkBlockVolume componentInChildren = prefab6.Object.GetComponentInChildren <DungeonLinkBlockVolume>(); DungeonLinkBlockVolume componentInChildren2 = _003C_003Ec__DisplayClass17_2.entrance.GetComponentInChildren <DungeonLinkBlockVolume>(); OBB bounds = componentInChildren.GetBounds(worldSpaceGrid.GridToWorldCoords(cellPos), Quaternion.identity); OBB bounds2 = componentInChildren2.GetBounds(_003C_003Ec__DisplayClass17_2.entrance.transform.position, Quaternion.identity); if (!bounds.Intersects2D(bounds2)) { DungeonLink componentInChildren3 = prefab6.Object.GetComponentInChildren <DungeonLink>(); Vector3 vector = worldSpaceGrid.GridToWorldCoords(new Vector2i(cellPos.x, cellPos.y)) + componentInChildren3.UpSocket.localPosition; float num4 = (terrainPathConnect.transform.position - vector).Magnitude2D(); if (!(num3 < num4)) { prefab5 = prefab6; num3 = num4; } } } if (prefab5 != null) { worldSpaceGrid[cellPos.x, cellPos.y] = prefab5; array5[cellPos.x, cellPos.y] = int.MaxValue; _003C_003Ec__DisplayClass17_3.isStartPoint = _003C_003Ec__DisplayClass17_.secondaryNodeList.Count == 0; _003C_003Ec__DisplayClass17_.secondaryNodeList.RemoveAll((PathNode x) => x.node.point == CS_0024_003C_003E8__locals0.stationNode.point); _003C_003Ec__DisplayClass17_.unconnectedNodeList.RemoveAll((PathNode x) => x.node.point == CS_0024_003C_003E8__locals0.stationNode.point); if (prefab5.Component.West != 0) { CS_0024_003C_003E8__locals0._003CProcess_003Eg__AddNode_007C1(cellPos.x - 1, cellPos.y, ref _003C_003Ec__DisplayClass17_, ref _003C_003Ec__DisplayClass17_2, ref _003C_003Ec__DisplayClass17_3); } if (prefab5.Component.East != 0) { CS_0024_003C_003E8__locals0._003CProcess_003Eg__AddNode_007C1(cellPos.x + 1, cellPos.y, ref _003C_003Ec__DisplayClass17_, ref _003C_003Ec__DisplayClass17_2, ref _003C_003Ec__DisplayClass17_3); } if (prefab5.Component.South != 0) { CS_0024_003C_003E8__locals0._003CProcess_003Eg__AddNode_007C1(cellPos.x, cellPos.y - 1, ref _003C_003Ec__DisplayClass17_, ref _003C_003Ec__DisplayClass17_2, ref _003C_003Ec__DisplayClass17_3); } if (prefab5.Component.North != 0) { CS_0024_003C_003E8__locals0._003CProcess_003Eg__AddNode_007C1(cellPos.x, cellPos.y + 1, ref _003C_003Ec__DisplayClass17_, ref _003C_003Ec__DisplayClass17_2, ref _003C_003Ec__DisplayClass17_3); } PathLink pathLink = new PathLink(); DungeonLink componentInChildren4 = _003C_003Ec__DisplayClass17_2.entrance.gameObject.GetComponentInChildren <DungeonLink>(); Vector3 position = _003C_003Ec__DisplayClass17_2.entrance.transform.position; Vector3 eulerAngles = _003C_003Ec__DisplayClass17_2.entrance.transform.rotation.eulerAngles; DungeonLink componentInChildren5 = prefab5.Object.GetComponentInChildren <DungeonLink>(); Vector3 position2 = worldSpaceGrid.GridToWorldCoords(new Vector2i(cellPos.x, cellPos.y)); Vector3 zero = Vector3.zero; pathLink.downwards = new PathLinkSide(); pathLink.downwards.origin = new PathLinkSegment(); pathLink.downwards.origin.position = position; pathLink.downwards.origin.rotation = Quaternion.Euler(eulerAngles); pathLink.downwards.origin.scale = Vector3.one; pathLink.downwards.origin.link = componentInChildren4; pathLink.downwards.segments = new List <PathLinkSegment>(); pathLink.upwards = new PathLinkSide(); pathLink.upwards.origin = new PathLinkSegment(); pathLink.upwards.origin.position = position2; pathLink.upwards.origin.rotation = Quaternion.Euler(zero); pathLink.upwards.origin.scale = Vector3.one; pathLink.upwards.origin.link = componentInChildren5; pathLink.upwards.segments = new List <PathLinkSegment>(); list3.Add(pathLink); } } } while (_003C_003Ec__DisplayClass17_.unconnectedNodeList.Count != 0 || _003C_003Ec__DisplayClass17_.secondaryNodeList.Count != 0) { if (_003C_003Ec__DisplayClass17_.unconnectedNodeList.Count == 0) { PathNode node3 = _003C_003Ec__DisplayClass17_.secondaryNodeList[0]; _003C_003Ec__DisplayClass17_.unconnectedNodeList.AddRange(_003C_003Ec__DisplayClass17_.secondaryNodeList.Where((PathNode x) => x.monument == node3.monument)); _003C_003Ec__DisplayClass17_.secondaryNodeList.RemoveAll((PathNode x) => x.monument == node3.monument); Vector2i vector2i = worldSpaceGrid.WorldToGridCoords(node3.monument.transform.position); _003C_003Ec__DisplayClass17_.pathFinder.PushPoint = new PathFinder.Point(vector2i.x, vector2i.y); _003C_003Ec__DisplayClass17_.pathFinder.PushRadius = 2; _003C_003Ec__DisplayClass17_.pathFinder.PushDistance = 2; _003C_003Ec__DisplayClass17_.pathFinder.PushMultiplier = 4; } list7.Clear(); list7.AddRange(_003C_003Ec__DisplayClass17_.unconnectedNodeList.Select((PathNode x) => x.node.point)); list6.Clear(); list6.AddRange(list4.Select((PathNode x) => x.node.point)); list6.AddRange(_003C_003Ec__DisplayClass17_.secondaryNodeList.Select((PathNode x) => x.node.point)); list6.AddRange(list5); PathFinder.Node node4 = _003C_003Ec__DisplayClass17_.pathFinder.FindPathUndirected(list6, list7, 100000); if (node4 == null) { PathNode node2 = _003C_003Ec__DisplayClass17_.unconnectedNodeList[0]; _003C_003Ec__DisplayClass17_.secondaryNodeList.AddRange(_003C_003Ec__DisplayClass17_.unconnectedNodeList.Where((PathNode x) => x.monument == node2.monument)); _003C_003Ec__DisplayClass17_.unconnectedNodeList.RemoveAll((PathNode x) => x.monument == node2.monument); _003C_003Ec__DisplayClass17_.secondaryNodeList.Remove(node2); list4.Add(node2); continue; } PathSegment segment = new PathSegment(); for (PathFinder.Node node5 = node4; node5 != null; node5 = node5.next) { if (node5 == node4) { segment.start = node5; } if (node5.next == null) { segment.end = node5; } } list2.Add(segment); PathNode node = _003C_003Ec__DisplayClass17_.unconnectedNodeList.Find((PathNode x) => x.node.point == segment.start.point || x.node.point == segment.end.point); _003C_003Ec__DisplayClass17_.secondaryNodeList.AddRange(_003C_003Ec__DisplayClass17_.unconnectedNodeList.Where((PathNode x) => x.monument == node.monument)); _003C_003Ec__DisplayClass17_.unconnectedNodeList.RemoveAll((PathNode x) => x.monument == node.monument); _003C_003Ec__DisplayClass17_.secondaryNodeList.Remove(node); list4.Add(node); PathNode pathNode = _003C_003Ec__DisplayClass17_.secondaryNodeList.Find((PathNode x) => x.node.point == segment.start.point || x.node.point == segment.end.point); if (pathNode != null) { _003C_003Ec__DisplayClass17_.secondaryNodeList.Remove(pathNode); list4.Add(pathNode); } for (PathFinder.Node node6 = node4; node6 != null; node6 = node6.next) { if (node6 != node4 && node6.next != null) { list5.Add(node6.point); } } } foreach (PathSegment item2 in list2) { PathFinder.Node node7 = item2.start; while (node7 != null && node7.next != null) { DungeonConnectionHash dungeonConnectionHash = _003C_003Ec__DisplayClass17_.hashmap[node7.point.x, node7.point.y]; DungeonConnectionHash dungeonConnectionHash2 = _003C_003Ec__DisplayClass17_.hashmap[node7.next.point.x, node7.next.point.y]; if (node7.point.x > node7.next.point.x) { dungeonConnectionHash.West = true; dungeonConnectionHash2.East = true; } if (node7.point.x < node7.next.point.x) { dungeonConnectionHash.East = true; dungeonConnectionHash2.West = true; } if (node7.point.y > node7.next.point.y) { dungeonConnectionHash.South = true; dungeonConnectionHash2.North = true; } if (node7.point.y < node7.next.point.y) { dungeonConnectionHash.North = true; dungeonConnectionHash2.South = true; } _003C_003Ec__DisplayClass17_.hashmap[node7.point.x, node7.point.y] = dungeonConnectionHash; _003C_003Ec__DisplayClass17_.hashmap[node7.next.point.x, node7.next.point.y] = dungeonConnectionHash2; node7 = node7.next; } } for (int m = 0; m < worldSpaceGrid.CellCount; m++) { for (int n = 0; n < worldSpaceGrid.CellCount; n++) { if (array5[m, n] == int.MaxValue) { continue; } DungeonConnectionHash dungeonConnectionHash3 = _003C_003Ec__DisplayClass17_.hashmap[m, n]; if (dungeonConnectionHash3.Value == 0) { continue; } ArrayEx.Shuffle(array, ref seed); Prefab <DungeonCell>[] array6 = array; foreach (Prefab <DungeonCell> prefab7 in array6) { Prefab <DungeonCell> prefab8 = ((m > num) ? worldSpaceGrid[m - 1, n] : null); if (((prefab8 != null) ? ((prefab7.Component.West == prefab8.Component.East) ? 1 : 0) : (dungeonConnectionHash3.West ? ((int)prefab7.Component.West) : ((prefab7.Component.West == DungeonConnectionType.None) ? 1 : 0))) == 0) { continue; } Prefab <DungeonCell> prefab9 = ((m < num2) ? worldSpaceGrid[m + 1, n] : null); if (((prefab9 != null) ? ((prefab7.Component.East == prefab9.Component.West) ? 1 : 0) : (dungeonConnectionHash3.East ? ((int)prefab7.Component.East) : ((prefab7.Component.East == DungeonConnectionType.None) ? 1 : 0))) == 0) { continue; } Prefab <DungeonCell> prefab10 = ((n > num) ? worldSpaceGrid[m, n - 1] : null); if (((prefab10 != null) ? ((prefab7.Component.South == prefab10.Component.North) ? 1 : 0) : (dungeonConnectionHash3.South ? ((int)prefab7.Component.South) : ((prefab7.Component.South == DungeonConnectionType.None) ? 1 : 0))) == 0) { continue; } Prefab <DungeonCell> prefab11 = ((n < num2) ? worldSpaceGrid[m, n + 1] : null); if (((prefab11 != null) ? ((prefab7.Component.North == prefab11.Component.South) ? 1 : 0) : (dungeonConnectionHash3.North ? ((int)prefab7.Component.North) : ((prefab7.Component.North == DungeonConnectionType.None) ? 1 : 0))) != 0 && (prefab7.Component.West == DungeonConnectionType.None || prefab8 == null || !prefab7.Component.ShouldAvoid(prefab8.ID)) && (prefab7.Component.East == DungeonConnectionType.None || prefab9 == null || !prefab7.Component.ShouldAvoid(prefab9.ID)) && (prefab7.Component.South == DungeonConnectionType.None || prefab10 == null || !prefab7.Component.ShouldAvoid(prefab10.ID)) && (prefab7.Component.North == DungeonConnectionType.None || prefab11 == null || !prefab7.Component.ShouldAvoid(prefab11.ID))) { worldSpaceGrid[m, n] = prefab7; bool num5 = prefab8 == null || prefab7.Component.WestVariant == prefab8.Component.EastVariant; bool flag = prefab10 == null || prefab7.Component.SouthVariant == prefab10.Component.NorthVariant; if (num5 && flag) { break; } } } } } Vector3 zero2 = Vector3.zero; Vector3 zero3 = Vector3.zero; Vector3 vector2 = Vector3.up * 10f; Vector3 vector3 = Vector3.up * (LinkTransition + 1f); do { zero3 = zero2; for (int num6 = 0; num6 < worldSpaceGrid.CellCount; num6++) { for (int num7 = 0; num7 < worldSpaceGrid.CellCount; num7++) { Prefab <DungeonCell> prefab12 = worldSpaceGrid[num6, num7]; if (prefab12 != null) { Vector2i cellPos2 = new Vector2i(num6, num7); Vector3 vector4 = worldSpaceGrid.GridToWorldCoords(cellPos2); while (!prefab12.CheckEnvironmentVolumesInsideTerrain(zero2 + vector4 + vector2, Quaternion.identity, Vector3.one, EnvironmentType.Underground) || prefab12.CheckEnvironmentVolumes(zero2 + vector4 + vector3, Quaternion.identity, Vector3.one, EnvironmentType.Underground | EnvironmentType.Building) || prefab12.CheckEnvironmentVolumes(zero2 + vector4, Quaternion.identity, Vector3.one, EnvironmentType.Underground | EnvironmentType.Building)) { zero2.y -= 9f; } } } } }while (zero2 != zero3); foreach (PathLink item3 in list3) { item3.upwards.origin.position += zero2; } for (int num8 = 0; num8 < worldSpaceGrid.CellCount; num8++) { for (int num9 = 0; num9 < worldSpaceGrid.CellCount; num9++) { Prefab <DungeonCell> prefab13 = worldSpaceGrid[num8, num9]; if (prefab13 != null) { Vector2i cellPos3 = new Vector2i(num8, num9); Vector3 vector5 = worldSpaceGrid.GridToWorldCoords(cellPos3); World.AddPrefab("Dungeon", prefab13, zero2 + vector5, Quaternion.identity, Vector3.one); } } } for (int num10 = 0; num10 < worldSpaceGrid.CellCount - 1; num10++) { for (int num11 = 0; num11 < worldSpaceGrid.CellCount - 1; num11++) { Prefab <DungeonCell> prefab14 = worldSpaceGrid[num10, num11]; Prefab <DungeonCell> prefab15 = worldSpaceGrid[num10 + 1, num11]; Prefab <DungeonCell> prefab16 = worldSpaceGrid[num10, num11 + 1]; Prefab <DungeonCell>[] array6; if (prefab14 != null && prefab15 != null && prefab14.Component.EastVariant != prefab15.Component.WestVariant) { ArrayEx.Shuffle(array3, ref seed); array6 = array3; foreach (Prefab <DungeonCell> prefab17 in array6) { if (prefab17.Component.West == prefab14.Component.East && prefab17.Component.East == prefab15.Component.West && prefab17.Component.WestVariant == prefab14.Component.EastVariant && prefab17.Component.EastVariant == prefab15.Component.WestVariant) { Vector2i cellPos4 = new Vector2i(num10, num11); Vector3 vector6 = worldSpaceGrid.GridToWorldCoords(cellPos4) + new Vector3(worldSpaceGrid.CellSizeHalf, 0f, 0f); World.AddPrefab("Dungeon", prefab17, zero2 + vector6, Quaternion.identity, Vector3.one); break; } } } if (prefab14 == null || prefab16 == null || prefab14.Component.NorthVariant == prefab16.Component.SouthVariant) { continue; } ArrayEx.Shuffle(array3, ref seed); array6 = array3; foreach (Prefab <DungeonCell> prefab18 in array6) { if (prefab18.Component.South == prefab14.Component.North && prefab18.Component.North == prefab16.Component.South && prefab18.Component.SouthVariant == prefab14.Component.NorthVariant && prefab18.Component.NorthVariant == prefab16.Component.SouthVariant) { Vector2i cellPos5 = new Vector2i(num10, num11); Vector3 vector7 = worldSpaceGrid.GridToWorldCoords(cellPos5) + new Vector3(0f, 0f, worldSpaceGrid.CellSizeHalf); World.AddPrefab("Dungeon", prefab18, zero2 + vector7, Quaternion.identity, Vector3.one); break; } } } } foreach (PathLink item4 in list3) { Vector3 vector8 = item4.upwards.origin.position + item4.upwards.origin.rotation * Vector3.Scale(item4.upwards.origin.upSocket.localPosition, item4.upwards.origin.scale); Vector3 vector9 = item4.downwards.origin.position + item4.downwards.origin.rotation * Vector3.Scale(item4.downwards.origin.downSocket.localPosition, item4.downwards.origin.scale) - vector8; Vector3[] array7 = new Vector3[2] { new Vector3(0f, 1f, 0f), new Vector3(1f, 1f, 1f) }; for (int k = 0; k < array7.Length; k++) { Vector3 b = array7[k]; int num12 = 0; int num13 = 0; while (vector9.magnitude > 1f && (num12 < 8 || num13 < 8)) { bool flag2 = num12 > 2 && num13 > 2; bool flag3 = num12 > 4 && num13 > 4; Prefab <DungeonLink> prefab19 = null; Vector3 vector10 = Vector3.zero; int num14 = int.MinValue; Vector3 position3 = Vector3.zero; Quaternion rotation = Quaternion.identity; PathLinkSegment prevSegment = item4.downwards.prevSegment; Vector3 vector11 = prevSegment.position + prevSegment.rotation * Vector3.Scale(prevSegment.scale, prevSegment.downSocket.localPosition); Quaternion quaternion = prevSegment.rotation * prevSegment.downSocket.localRotation; Prefab <DungeonLink>[] array8 = array4; foreach (Prefab <DungeonLink> prefab20 in array8) { float num15 = SeedRandom.Value(ref seed); DungeonLink component = prefab20.Component; if (prevSegment.downType != component.UpType) { continue; } switch (component.DownType) { case DungeonLinkType.Elevator: if (flag2 || b.x != 0f || b.z != 0f) { continue; } break; case DungeonLinkType.Transition: if (b.x != 0f || b.z != 0f) { continue; } break; } int num16 = ((!flag2) ? component.Priority : 0); if (num14 > num16) { continue; } Quaternion quaternion2 = quaternion * Quaternion.Inverse(component.UpSocket.localRotation); Quaternion quaternion3 = quaternion2 * component.DownSocket.localRotation; PathLinkSegment prevSegment2 = item4.upwards.prevSegment; Quaternion quaternion4 = prevSegment2.rotation * prevSegment2.upSocket.localRotation; if (component.Rotation > 0) { if (Quaternion.Angle(quaternion4, quaternion3) > (float)component.Rotation) { continue; } Quaternion quaternion5 = quaternion4 * Quaternion.Inverse(quaternion3); quaternion2 *= quaternion5; quaternion3 *= quaternion5; } Vector3 vector12 = vector11 - quaternion2 * component.UpSocket.localPosition; Vector3 vector13 = quaternion2 * (component.DownSocket.localPosition - component.UpSocket.localPosition); Vector3 a = vector9 + vector10; Vector3 a2 = vector9 + vector13; float magnitude = a.magnitude; float magnitude2 = a2.magnitude; Vector3 vector14 = Vector3.Scale(a, b); Vector3 vector15 = Vector3.Scale(a2, b); float magnitude3 = vector14.magnitude; float magnitude4 = vector15.magnitude; if (vector10 != Vector3.zero) { if (magnitude3 < magnitude4 || (magnitude3 == magnitude4 && magnitude < magnitude2) || (magnitude3 == magnitude4 && magnitude == magnitude2 && num15 < 0.5f)) { continue; } } else if (magnitude3 <= magnitude4) { continue; } if (Mathf.Abs(vector15.x) - Mathf.Abs(vector14.x) > 0.01f || (Mathf.Abs(vector15.x) > 0.01f && a.x * a2.x < 0f) || Mathf.Abs(vector15.y) - Mathf.Abs(vector14.y) > 0.01f || (Mathf.Abs(vector15.y) > 0.01f && a.y * a2.y < 0f) || Mathf.Abs(vector15.z) - Mathf.Abs(vector14.z) > 0.01f || (Mathf.Abs(vector15.z) > 0.01f && a.z * a2.z < 0f) || (flag2 && b.x == 0f && b.z == 0f && component.DownType == DungeonLinkType.Default && ((Mathf.Abs(a2.x) > 0.01f && Mathf.Abs(a2.x) < LinkRadius * 2f - 0.1f) || (Mathf.Abs(a2.z) > 0.01f && Mathf.Abs(a2.z) < LinkRadius * 2f - 0.1f)))) { continue; } num14 = num16; if (b.x == 0f && b.z == 0f) { if (!flag2 && Mathf.Abs(a2.y) < LinkTransition - 0.1f) { continue; } } else if ((!flag2 && magnitude4 > 0.01f && (Mathf.Abs(a2.x) < LinkRadius * 2f - 0.1f || Mathf.Abs(a2.z) < LinkRadius * 2f - 0.1f)) || (!flag3 && magnitude4 > 0.01f && (Mathf.Abs(a2.x) < LinkRadius * 1f - 0.1f || Mathf.Abs(a2.z) < LinkRadius * 1f - 0.1f))) { continue; } if (!flag2 || !(magnitude4 < 0.01f) || !(magnitude2 < 0.01f) || !(Quaternion.Angle(quaternion4, quaternion3) > 10f)) { prefab19 = prefab20; vector10 = vector13; num14 = num16; position3 = vector12; rotation = quaternion2; } } if (vector10 != Vector3.zero) { PathLinkSegment pathLinkSegment = new PathLinkSegment(); pathLinkSegment.position = position3; pathLinkSegment.rotation = rotation; pathLinkSegment.scale = Vector3.one; pathLinkSegment.prefab = prefab19; pathLinkSegment.link = prefab19.Component; item4.downwards.segments.Add(pathLinkSegment); vector9 += vector10; } else { num13++; } if (b.x > 0f || b.z > 0f) { Prefab <DungeonLink> prefab21 = null; Vector3 vector16 = Vector3.zero; int num17 = int.MinValue; Vector3 position4 = Vector3.zero; Quaternion rotation2 = Quaternion.identity; PathLinkSegment prevSegment3 = item4.upwards.prevSegment; Vector3 vector17 = prevSegment3.position + prevSegment3.rotation * Vector3.Scale(prevSegment3.scale, prevSegment3.upSocket.localPosition); Quaternion quaternion6 = prevSegment3.rotation * prevSegment3.upSocket.localRotation; array8 = array4; foreach (Prefab <DungeonLink> prefab22 in array8) { float num18 = SeedRandom.Value(ref seed); DungeonLink component2 = prefab22.Component; if (prevSegment3.upType != component2.DownType) { continue; } switch (component2.DownType) { case DungeonLinkType.Elevator: if (flag2 || b.x != 0f || b.z != 0f) { continue; } break; case DungeonLinkType.Transition: if (b.x != 0f || b.z != 0f) { continue; } break; } int num19 = ((!flag2) ? component2.Priority : 0); if (num17 > num19) { continue; } Quaternion quaternion7 = quaternion6 * Quaternion.Inverse(component2.DownSocket.localRotation); Quaternion quaternion8 = quaternion7 * component2.UpSocket.localRotation; PathLinkSegment prevSegment4 = item4.downwards.prevSegment; Quaternion quaternion9 = prevSegment4.rotation * prevSegment4.downSocket.localRotation; if (component2.Rotation > 0) { if (Quaternion.Angle(quaternion9, quaternion8) > (float)component2.Rotation) { continue; } Quaternion quaternion10 = quaternion9 * Quaternion.Inverse(quaternion8); quaternion7 *= quaternion10; quaternion8 *= quaternion10; } Vector3 vector18 = vector17 - quaternion7 * component2.DownSocket.localPosition; Vector3 vector19 = quaternion7 * (component2.UpSocket.localPosition - component2.DownSocket.localPosition); Vector3 a3 = vector9 - vector16; Vector3 a4 = vector9 - vector19; float magnitude5 = a3.magnitude; float magnitude6 = a4.magnitude; Vector3 vector20 = Vector3.Scale(a3, b); Vector3 vector21 = Vector3.Scale(a4, b); float magnitude7 = vector20.magnitude; float magnitude8 = vector21.magnitude; if (vector16 != Vector3.zero) { if (magnitude7 < magnitude8 || (magnitude7 == magnitude8 && magnitude5 < magnitude6) || (magnitude7 == magnitude8 && magnitude5 == magnitude6 && num18 < 0.5f)) { continue; } } else if (magnitude7 <= magnitude8) { continue; } if (Mathf.Abs(vector21.x) - Mathf.Abs(vector20.x) > 0.01f || (Mathf.Abs(vector21.x) > 0.01f && a3.x * a4.x < 0f) || Mathf.Abs(vector21.y) - Mathf.Abs(vector20.y) > 0.01f || (Mathf.Abs(vector21.y) > 0.01f && a3.y * a4.y < 0f) || Mathf.Abs(vector21.z) - Mathf.Abs(vector20.z) > 0.01f || (Mathf.Abs(vector21.z) > 0.01f && a3.z * a4.z < 0f) || (flag2 && b.x == 0f && b.z == 0f && component2.UpType == DungeonLinkType.Default && ((Mathf.Abs(a4.x) > 0.01f && Mathf.Abs(a4.x) < LinkRadius * 2f - 0.1f) || (Mathf.Abs(a4.z) > 0.01f && Mathf.Abs(a4.z) < LinkRadius * 2f - 0.1f)))) { continue; } num17 = num19; if (b.x == 0f && b.z == 0f) { if (!flag2 && Mathf.Abs(a4.y) < LinkTransition - 0.1f) { continue; } } else if ((!flag2 && magnitude8 > 0.01f && (Mathf.Abs(a4.x) < LinkRadius * 2f - 0.1f || Mathf.Abs(a4.z) < LinkRadius * 2f - 0.1f)) || (!flag3 && magnitude8 > 0.01f && (Mathf.Abs(a4.x) < LinkRadius * 1f - 0.1f || Mathf.Abs(a4.z) < LinkRadius * 1f - 0.1f))) { continue; } if (!flag2 || !(magnitude8 < 0.01f) || !(magnitude6 < 0.01f) || !(Quaternion.Angle(quaternion9, quaternion8) > 10f)) { prefab21 = prefab22; vector16 = vector19; num17 = num19; position4 = vector18; rotation2 = quaternion7; } } if (vector16 != Vector3.zero) { PathLinkSegment pathLinkSegment2 = new PathLinkSegment(); pathLinkSegment2.position = position4; pathLinkSegment2.rotation = rotation2; pathLinkSegment2.scale = Vector3.one; pathLinkSegment2.prefab = prefab21; pathLinkSegment2.link = prefab21.Component; item4.upwards.segments.Add(pathLinkSegment2); vector9 -= vector16; } else { num12++; } } else { num12++; } } } } foreach (PathLink item5 in list3) { foreach (PathLinkSegment segment2 in item5.downwards.segments) { World.AddPrefab("Dungeon", segment2.prefab, segment2.position, segment2.rotation, segment2.scale); } foreach (PathLinkSegment segment3 in item5.upwards.segments) { World.AddPrefab("Dungeon", segment3.prefab, segment3.position, segment3.rotation, segment3.scale); } } if ((bool)TerrainMeta.Path) { TerrainMeta.Path.DungeonRoot = HierarchyUtil.GetRoot("Dungeon"); } }
public override void Apply(ref Vector3 pos, ref Quaternion rot, ref Vector3 scale) { uint num1 = SeedEx.Seed(pos, World.Seed) + 3U; float num2 = SeedRandom.Value(ref num1); ref __Null local1 = ref scale.x;
public static Vector2 Value2D(ref uint seed) { float single = SeedRandom.Value(ref seed) * 3.14159274f * 2f; return(new Vector2(Mathf.Cos(single), Mathf.Sin(single))); }
public override void Process(uint seed) { int priority; if ((ulong)World.Size < (long)this.MinSize) { return; } TerrainHeightMap heightMap = TerrainMeta.HeightMap; Prefab <MonumentInfo>[] prefabArray = Prefab.Load <MonumentInfo>(string.Concat("assets/bundled/prefabs/autospawn/", this.ResourceFolder), null, null, true); if (prefabArray == null || prefabArray.Length == 0) { return; } prefabArray.Shuffle <Prefab <MonumentInfo> >(seed); prefabArray.BubbleSort <Prefab <MonumentInfo> >(); Vector3 position = TerrainMeta.Position; Vector3 size = TerrainMeta.Size; float single = position.x; float single1 = position.z; float single2 = position.x + size.x; float single3 = position.z + size.z; int num = 0; List <PlaceMonuments.SpawnInfo> spawnInfos = new List <PlaceMonuments.SpawnInfo>(); int num1 = 0; List <PlaceMonuments.SpawnInfo> spawnInfos1 = new List <PlaceMonuments.SpawnInfo>(); for (int i = 0; i < 10; i++) { num = 0; spawnInfos.Clear(); Prefab <MonumentInfo>[] prefabArray1 = prefabArray; for (int j = 0; j < (int)prefabArray1.Length; j++) { Prefab <MonumentInfo> prefab = prefabArray1[j]; if (prefab.Parameters) { priority = (int)prefab.Parameters.Priority + (int)PrefabPriority.Low; } else { priority = 1; } int num2 = priority; int num3 = num2 * num2 * num2 * num2; for (int k = 0; k < 10000; k++) { float single4 = SeedRandom.Range(ref seed, single, single2); float single5 = SeedRandom.Range(ref seed, single1, single3); float single6 = TerrainMeta.NormalizeX(single4); float single7 = TerrainMeta.NormalizeZ(single5); float single8 = SeedRandom.Value(ref seed); float factor = this.Filter.GetFactor(single6, single7); if (factor * factor >= single8) { float height = heightMap.GetHeight(single6, single7); Vector3 vector3 = new Vector3(single4, height, single5); Quaternion obj = prefab.Object.transform.localRotation; Vector3 obj1 = prefab.Object.transform.localScale; if (!this.CheckRadius(spawnInfos, vector3, (float)this.Distance)) { prefab.ApplyDecorComponents(ref vector3, ref obj, ref obj1); if ((!prefab.Component || prefab.Component.CheckPlacement(vector3, obj, obj1)) && prefab.ApplyTerrainAnchors(ref vector3, obj, obj1, this.Filter) && prefab.ApplyTerrainChecks(vector3, obj, obj1, this.Filter) && prefab.ApplyTerrainFilters(vector3, obj, obj1, null) && prefab.ApplyWaterChecks(vector3, obj, obj1) && !prefab.CheckEnvironmentVolumes(vector3, obj, obj1, EnvironmentType.Underground)) { PlaceMonuments.SpawnInfo spawnInfo = new PlaceMonuments.SpawnInfo() { prefab = prefab, position = vector3, rotation = obj, scale = obj1 }; spawnInfos.Add(spawnInfo); num += num3; break; } } } } } if (num > num1) { num1 = num; GenericsUtil.Swap <List <PlaceMonuments.SpawnInfo> >(ref spawnInfos, ref spawnInfos1); } } foreach (PlaceMonuments.SpawnInfo spawnInfo1 in spawnInfos1) { Prefab prefab1 = spawnInfo1.prefab; Vector3 vector31 = spawnInfo1.position; Quaternion quaternion = spawnInfo1.rotation; Vector3 vector32 = spawnInfo1.scale; prefab1.ApplyTerrainPlacements(vector31, quaternion, vector32); prefab1.ApplyTerrainModifiers(vector31, quaternion, vector32); World.AddPrefab("Monument", prefab1.ID, vector31, quaternion, vector32); } }