| using System; |
| using System; |
| using System.Collections.Generic; |
| using System.Collections.Generic; |
| using System.IO; |
| using System.IO; |
| using System.Linq; |
| using System.Linq; |
| using SoftReferenceableAssets; |
| using SoftReferenceableAssets; |
| using UnityEngine; |
| using UnityEngine; |
| |
| |
| public class DungeonGenerator : MonoBehaviour |
| public class DungeonGenerator : MonoBehaviour |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.m_nview = base.GetComponent<ZNetView>(); |
| this.Load(); |
| this.Load(); |
| if (this.m_loadedRooms.Length != 0) |
| if (this.m_loadedRooms.Length != 0) |
| { |
| { |
| this.LoadRoomPrefabsAsync(); |
| this.LoadRoomPrefabsAsync(); |
| } |
| } |
| } |
| } |
| |
| |
| private void OnDestroy() |
| private void OnDestroy() |
| { |
| { |
| this.ReleaseHeldReferences(); |
| this.ReleaseHeldReferences(); |
| } |
| } |
| |
| |
| private void ReleaseHeldReferences() |
| private void ReleaseHeldReferences() |
| { |
| { |
| for (int i = 0; i < this.m_heldReferences.Count; i++) |
| for (int i = 0; i < this.m_heldReferences.Count; i++) |
| { |
| { |
| this.m_heldReferences[i].Release(); |
| this.m_heldReferences[i].Release(); |
| } |
| } |
| this.m_heldReferences.Clear(); |
| this.m_heldReferences.Clear(); |
| if (this.m_zdoSetToBeLoadingInZone != null) |
| if (this.m_zdoSetToBeLoadingInZone != null) |
| { |
| { |
| ZoneSystem.instance.UnsetLoadingInZone(this.m_zdoSetToBeLoadingInZone); |
| ZoneSystem.instance.UnsetLoadingInZone(this.m_zdoSetToBeLoadingInZone); |
| this.m_zdoSetToBeLoadingInZone = null; |
| this.m_zdoSetToBeLoadingInZone = null; |
| } |
| } |
| } |
| } |
| |
| |
| public void Clear() |
| public void Clear() |
| { |
| { |
| while (base.transform.childCount > 0) |
| while (base.transform.childCount > 0) |
| { |
| { |
| UnityEngine.Object.DestroyImmediate(base.transform.GetChild(0).gameObject); |
| UnityEngine.Object.DestroyImmediate(base.transform.GetChild(0).gameObject); |
| } |
| } |
| } |
| } |
| |
| |
| public void Generate(ZoneSystem.SpawnMode mode) |
| public void Generate(ZoneSystem.SpawnMode mode) |
| { |
| { |
| int seed = this.GetSeed(); |
| int seed = this.GetSeed(); |
| this.Generate(seed, mode); |
| this.Generate(seed, mode); |
| } |
| } |
| |
| |
| public int GetSeed() |
| public int GetSeed() |
| { |
| { |
| if (this.m_hasGeneratedSeed) |
| if (this.m_hasGeneratedSeed) |
| { |
| { |
| return this.m_generatedSeed; |
| return this.m_generatedSeed; |
| } |
| } |
| if (DungeonGenerator.m_forceSeed != -2147483648) |
| if (DungeonGenerator.m_forceSeed != -2147483648) |
| { |
| { |
| this.m_generatedSeed = DungeonGenerator.m_forceSeed; |
| this.m_generatedSeed = DungeonGenerator.m_forceSeed; |
| DungeonGenerator.m_forceSeed = int.MinValue; |
| DungeonGenerator.m_forceSeed = int.MinValue; |
| } |
| } |
| else |
| else |
| { |
| { |
| int seed = WorldGenerator.instance.GetSeed(); |
| int seed = WorldGenerator.instance.GetSeed(); |
| Vector3 position = base.transform.position; |
| Vector3 position = base.transform.position; |
| Vector2i zone = ZoneSystem.instance.GetZone(base.transform.position); |
| Vector2i zone = ZoneSystem.instance.GetZone(base.transform.position); |
| this.m_generatedSeed = seed + zone.x * 4271 + zone.y * -7187 + (int)position.x * -4271 + (int)position.y * 9187 + (int)position.z * -2134; |
| this.m_generatedSeed = seed + zone.x * 4271 + zone.y * -7187 + (int)position.x * -4271 + (int)position.y * 9187 + (int)position.z * -2134; |
| } |
| } |
| this.m_hasGeneratedSeed = true; |
| this.m_hasGeneratedSeed = true; |
| return this.m_generatedSeed; |
| return this.m_generatedSeed; |
| } |
| } |
| |
| |
| public void Generate(int seed, ZoneSystem.SpawnMode mode) |
| public void Generate(int seed, ZoneSystem.SpawnMode mode) |
| { |
| { |
| DateTime now = DateTime.Now; |
| DateTime now = DateTime.Now; |
| this.m_generatedSeed = seed; |
| this.m_generatedSeed = seed; |
| this.Clear(); |
| this.Clear(); |
| this.SetupColliders(); |
| this.SetupColliders(); |
| this.SetupAvailableRooms(); |
| this.SetupAvailableRooms(); |
| for (int i = 0; i < DungeonGenerator.m_availableRooms.Count; i++) |
| for (int i = 0; i < DungeonGenerator.m_availableRooms.Count; i++) |
| { |
| { |
| DungeonGenerator.m_availableRooms[i].m_prefab.Load(); |
| DungeonGenerator.m_availableRooms[i].m_prefab.Load(); |
| } |
| } |
| if (ZoneSystem.instance) |
| if (ZoneSystem.instance) |
| { |
| { |
| Vector2i zone = ZoneSystem.instance.GetZone(base.transform.position); |
| Vector2i zone = ZoneSystem.instance.GetZone(base.transform.position); |
| this.m_zoneCenter = ZoneSystem.instance.GetZonePos(zone); |
| this.m_zoneCenter = ZoneSystem.instance.GetZonePos(zone); |
| this.m_zoneCenter.y = base.transform.position.y - this.m_originalPosition.y; |
| this.m_zoneCenter.y = base.transform.position.y - this.m_originalPosition.y; |
| } |
| } |
| Bounds bounds = new Bounds(this.m_zoneCenter, this.m_zoneSize); |
| Bounds bounds = new Bounds(this.m_zoneCenter, this.m_zoneSize); |
| ZLog.Log(string.Format("Generating {0}, Seed: {1}, Bounds diff: {2} / {3}", new object[] |
| ZLog.Log(string.Format("Generating {0}, Seed: {1}, Bounds diff: {2} / {3}", new object[] |
| { |
| { |
| base.name, |
| base.name, |
| seed, |
| seed, |
| bounds.min - base.transform.position, |
| bounds.min - base.transform.position, |
| bounds.max - base.transform.position |
| bounds.max - base.transform.position |
| })); |
| })); |
| ZLog.Log("Available rooms:" + DungeonGenerator.m_availableRooms.Count.ToString()); |
| ZLog.Log("Available rooms:" + DungeonGenerator.m_availableRooms.Count.ToString()); |
| ZLog.Log("To place:" + this.m_maxRooms.ToString()); |
| ZLog.Log("To place:" + this.m_maxRooms.ToString()); |
| DungeonGenerator.m_placedRooms.Clear(); |
| DungeonGenerator.m_placedRooms.Clear(); |
| DungeonGenerator.m_openConnections.Clear(); |
| DungeonGenerator.m_openConnections.Clear(); |
| DungeonGenerator.m_doorConnections.Clear(); |
| DungeonGenerator.m_doorConnections.Clear(); |
| UnityEngine.Random.State state = UnityEngine.Random.state; |
| UnityEngine.Random.State state = UnityEngine.Random.state; |
| UnityEngine.Random.InitState(seed); |
| UnityEngine.Random.InitState(seed); |
| this.GenerateRooms(mode); |
| this.GenerateRooms(mode); |
| for (int j = 0; j < DungeonGenerator.m_availableRooms.Count; j++) |
| for (int j = 0; j < DungeonGenerator.m_availableRooms.Count; j++) |
| { |
| { |
| DungeonGenerator.m_availableRooms[j].m_prefab.Release(); |
| DungeonGenerator.m_availableRooms[j].m_prefab.Release(); |
| } |
| } |
| this.Save(); |
| this.Save(); |
| ZLog.Log("Placed " + DungeonGenerator.m_placedRooms.Count.ToString() + " rooms"); |
| ZLog.Log("Placed " + DungeonGenerator.m_placedRooms.Count.ToString() + " rooms"); |
| UnityEngine.Random.state = state; |
| UnityEngine.Random.state = state; |
| SnapToGround.SnappAll(); |
| SnapToGround.SnappAll(); |
| if (mode == ZoneSystem.SpawnMode.Ghost) |
| if (mode == ZoneSystem.SpawnMode.Ghost) |
| { |
| { |
| foreach (Room room in DungeonGenerator.m_placedRooms) |
| foreach (Room room in DungeonGenerator.m_placedRooms) |
| { |
| { |
| UnityEngine.Object.DestroyImmediate(room.gameObject); |
| UnityEngine.Object.DestroyImmediate(room.gameObject); |
| } |
| } |
| } |
| } |
| UnityEngine.Object.DestroyImmediate(this.m_colliderA); |
| UnityEngine.Object.DestroyImmediate(this.m_colliderA); |
| UnityEngine.Object.DestroyImmediate(this.m_colliderB); |
| UnityEngine.Object.DestroyImmediate(this.m_colliderB); |
| DungeonGenerator.m_placedRooms.Clear(); |
| DungeonGenerator.m_placedRooms.Clear(); |
| DungeonGenerator.m_openConnections.Clear(); |
| DungeonGenerator.m_openConnections.Clear(); |
| DungeonGenerator.m_doorConnections.Clear(); |
| DungeonGenerator.m_doorConnections.Clear(); |
| DateTime.Now - now; |
| DateTime.Now - now; |
| } |
| } |
| |
| |
| private void LoadRoomPrefabsAsync() |
| private void LoadRoomPrefabsAsync() |
| { |
| { |
| ZLog.Log("Loading room prefabs asynchronously"); |
| ZLog.Log("Loading room prefabs asynchronously"); |
| if (this.m_zdoSetToBeLoadingInZone == null) |
| if (this.m_zdoSetToBeLoadingInZone == null) |
| { |
| { |
| this.m_zdoSetToBeLoadingInZone = this.m_nview.GetZDO(); |
| this.m_zdoSetToBeLoadingInZone = this.m_nview.GetZDO(); |
| ZoneSystem.instance.SetLoadingInZone(this.m_zdoSetToBeLoadingInZone); |
| ZoneSystem.instance.SetLoadingInZone(this.m_zdoSetToBeLoadingInZone); |
| } |
| } |
| this.m_roomsToLoad = this.m_loadedRooms.Length; |
| this.m_roomsToLoad = this.m_loadedRooms.Length; |
| int num = this.m_loadedRooms.Length; |
| int num = this.m_loadedRooms.Length; |
| for (int i = 0; i < num; i++) |
| for (int i = 0; i < num; i++) |
| { |
| { |
| this.m_heldReferences.Add(this.m_loadedRooms[i].m_roomData.m_prefab); |
| this.m_heldReferences.Add(this.m_loadedRooms[i].m_roomData.m_prefab); |
| this.m_loadedRooms[i].m_roomData.m_prefab.LoadAsync(new LoadedHandler(this.OnRoomLoaded)); |
| this.m_loadedRooms[i].m_roomData.m_prefab.LoadAsync(new LoadedHandler(this.OnRoomLoaded)); |
| } |
| } |
| } |
| } |
| |
| |
| private void OnRoomLoaded(LoadResult result) |
| private void OnRoomLoaded(LoadResult result) |
| { |
| { |
| if (result != LoadResult.Succeeded) |
| if (result != LoadResult.Succeeded) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (this == null || base.gameObject == null) |
| if (this == null || base.gameObject == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.m_roomsToLoad--; |
| this.m_roomsToLoad--; |
| if (this.m_roomsToLoad > 0) |
| if (this.m_roomsToLoad > 0) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| this.Spawn(); |
| this.Spawn(); |
| this.ReleaseHeldReferences(); |
| this.ReleaseHeldReferences(); |
| } |
| } |
| |
| |
| private void Spawn() |
| private void Spawn() |
| { |
| { |
| ZLog.Log("Spawning dungeon"); |
| ZLog.Log("Spawning dungeon"); |
| for (int i = 0; i < this.m_loadedRooms.Length; i++) |
| for (int i = 0; i < this.m_loadedRooms.Length; i++) |
| { |
| { |
| this.PlaceRoom(this.m_loadedRooms[i].m_roomData, this.m_loadedRooms[i].m_position, this.m_loadedRooms[i].m_rotation, null, ZoneSystem.SpawnMode.Client); |
| this.PlaceRoom(this.m_loadedRooms[i].m_roomData, this.m_loadedRooms[i].m_position, this.m_loadedRooms[i].m_rotation, null, ZoneSystem.SpawnMode.Client); |
| } |
| } |
| SnapToGround.SnappAll(); |
| SnapToGround.SnappAll(); |
| this.m_loadedRooms = null; |
| this.m_loadedRooms = null; |
| } |
| } |
| |
| |
| private void GenerateRooms(ZoneSystem.SpawnMode mode) |
| private void GenerateRooms(ZoneSystem.SpawnMode mode) |
| { |
| { |
| switch (this.m_algorithm) |
| switch (this.m_algorithm) |
| { |
| { |
| case DungeonGenerator.Algorithm.Dungeon: |
| case DungeonGenerator.Algorithm.Dungeon: |
| this.GenerateDungeon(mode); |
| this.GenerateDungeon(mode); |
| return; |
| return; |
| case DungeonGenerator.Algorithm.CampGrid: |
| case DungeonGenerator.Algorithm.CampGrid: |
| this.GenerateCampGrid(mode); |
| this.GenerateCampGrid(mode); |
| return; |
| return; |
| case DungeonGenerator.Algorithm.CampRadial: |
| case DungeonGenerator.Algorithm.CampRadial: |
| this.GenerateCampRadial(mode); |
| this.GenerateCampRadial(mode); |
| return; |
| return; |
| default: |
| default: |
| return; |
| return; |
| } |
| } |
| } |
| } |
| |
| |
| private void GenerateDungeon(ZoneSystem.SpawnMode mode) |
| private void GenerateDungeon(ZoneSystem.SpawnMode mode) |
| { |
| { |
| this.PlaceStartRoom(mode); |
| this.PlaceStartRoom(mode); |
| this.PlaceRooms(mode); |
| this.PlaceRooms(mode); |
| this.PlaceEndCaps(mode); |
| this.PlaceEndCaps(mode); |
| this.PlaceDoors(mode); |
| this.PlaceDoors(mode); |
| } |
| } |
| |
| |
| private void GenerateCampGrid(ZoneSystem.SpawnMode mode) |
| private void GenerateCampGrid(ZoneSystem.SpawnMode mode) |
| { |
| { |
| float num = Mathf.Cos(0.017453292f * this.m_maxTilt); |
| float num = Mathf.Cos(0.017453292f * this.m_maxTilt); |
| Vector3 vector = base.transform.position + new Vector3((float)(-(float)this.m_gridSize) * this.m_tileWidth * 0.5f, 0f, (float)(-(float)this.m_gridSize) * this.m_tileWidth * 0.5f); |
| Vector3 vector = base.transform.position + new Vector3((float)(-(float)this.m_gridSize) * this.m_tileWidth * 0.5f, 0f, (float)(-(float)this.m_gridSize) * this.m_tileWidth * 0.5f); |
| for (int i = 0; i < this.m_gridSize; i++) |
| for (int i = 0; i < this.m_gridSize; i++) |
| { |
| { |
| for (int j = 0; j < this.m_gridSize; j++) |
| for (int j = 0; j < this.m_gridSize; j++) |
| { |
| { |
| if (UnityEngine.Random.value <= this.m_spawnChance) |
| if (UnityEngine.Random.value <= this.m_spawnChance) |
| { |
| { |
| Vector3 vector2 = vector + new Vector3((float)j * this.m_tileWidth, 0f, (float)i * this.m_tileWidth); |
| Vector3 vector2 = vector + new Vector3((float)j * this.m_tileWidth, 0f, (float)i * this.m_tileWidth); |
| DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(false); |
| DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(false); |
| if (randomWeightedRoom != null) |
| if (randomWeightedRoom != null) |
| { |
| { |
| if (ZoneSystem.instance) |
| if (ZoneSystem.instance) |
| { |
| { |
| Vector3 vector3; |
| Vector3 vector3; |
| Heightmap.Biome biome; |
| Heightmap.Biome biome; |
| Heightmap.BiomeArea biomeArea; |
| Heightmap.BiomeArea biomeArea; |
| Heightmap heightmap; |
| Heightmap heightmap; |
| ZoneSystem.instance.GetGroundData(ref vector2, out vector3, out biome, out biomeArea, out heightmap); |
| ZoneSystem.instance.GetGroundData(ref vector2, out vector3, out biome, out biomeArea, out heightmap); |
| if (vector3.y < num) |
| if (vector3.y < num) |
| { |
| { |
| goto IL_FF; |
| goto IL_FF; |
| } |
| } |
| } |
| } |
| Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 16) * 22.5f, 0f); |
| Quaternion quaternion = Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 16) * 22.5f, 0f); |
| this.PlaceRoom(randomWeightedRoom, vector2, quaternion, null, mode); |
| this.PlaceRoom(randomWeightedRoom, vector2, quaternion, null, mode); |
| } |
| } |
| } |
| } |
| IL_FF:; |
| IL_FF:; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void GenerateCampRadial(ZoneSystem.SpawnMode mode) |
| private void GenerateCampRadial(ZoneSystem.SpawnMode mode) |
| { |
| { |
| float num = UnityEngine.Random.Range(this.m_campRadiusMin, this.m_campRadiusMax); |
| float num = UnityEngine.Random.Range(this.m_campRadiusMin, this.m_campRadiusMax); |
| float num2 = Mathf.Cos(0.017453292f * this.m_maxTilt); |
| float num2 = Mathf.Cos(0.017453292f * this.m_maxTilt); |
| int num3 = UnityEngine.Random.Range(this.m_minRooms, this.m_maxRooms); |
| int num3 = UnityEngine.Random.Range(this.m_minRooms, this.m_maxRooms); |
| int num4 = num3 * 20; |
| int num4 = num3 * 20; |
| int num5 = 0; |
| int num5 = 0; |
| for (int i = 0; i < num4; i++) |
| for (int i = 0; i < num4; i++) |
| { |
| { |
| Vector3 vector = base.transform.position + Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f) * Vector3.forward * UnityEngine.Random.Range(0f, num - this.m_perimeterBuffer); |
| Vector3 vector = base.transform.position + Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f) * Vector3.forward * UnityEngine.Random.Range(0f, num - this.m_perimeterBuffer); |
| DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(false); |
| DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(false); |
| if (randomWeightedRoom != null) |
| if (randomWeightedRoom != null) |
| { |
| { |
| if (ZoneSystem.instance) |
| if (ZoneSystem.instance) |
| { |
| { |
| Vector3 vector2; |
| Vector3 vector2; |
| Heightmap.Biome biome; |
| Heightmap.Biome biome; |
| Heightmap.BiomeArea biomeArea; |
| Heightmap.BiomeArea biomeArea; |
| Heightmap heightmap; |
| Heightmap heightmap; |
| ZoneSystem.instance.GetGroundData(ref vector, out vector2, out biome, out biomeArea, out heightmap); |
| ZoneSystem.instance.GetGroundData(ref vector, out vector2, out biome, out biomeArea, out heightmap); |
| . | if (vector2.y < num2 || vector.y - ZoneSystem.instance.m_waterLevel < this.m_minAltitude) |
| if (vector2.y < num2 || vector.y - 30f < this.m_minAltitude) |
| { |
| { |
| . | goto IL_11E; |
| goto IL_119; |
| } |
| } |
| } |
| } |
| Quaternion campRoomRotation = this.GetCampRoomRotation(randomWeightedRoom, vector); |
| Quaternion campRoomRotation = this.GetCampRoomRotation(randomWeightedRoom, vector); |
| if (!this.TestCollision(randomWeightedRoom.RoomInPrefab, vector, campRoomRotation)) |
| if (!this.TestCollision(randomWeightedRoom.RoomInPrefab, vector, campRoomRotation)) |
| { |
| { |
| this.PlaceRoom(randomWeightedRoom, vector, campRoomRotation, null, mode); |
| this.PlaceRoom(randomWeightedRoom, vector, campRoomRotation, null, mode); |
| num5++; |
| num5++; |
| if (num5 >= num3) |
| if (num5 >= num3) |
| { |
| { |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| . | IL_11E:; |
| IL_119:; |
| } |
| } |
| if (this.m_perimeterSections > 0) |
| if (this.m_perimeterSections > 0) |
| { |
| { |
| this.PlaceWall(num, this.m_perimeterSections, mode); |
| this.PlaceWall(num, this.m_perimeterSections, mode); |
| } |
| } |
| } |
| } |
| |
| |
| private Quaternion GetCampRoomRotation(DungeonDB.RoomData room, Vector3 pos) |
| private Quaternion GetCampRoomRotation(DungeonDB.RoomData room, Vector3 pos) |
| { |
| { |
| if (room.RoomInPrefab.m_faceCenter) |
| if (room.RoomInPrefab.m_faceCenter) |
| { |
| { |
| Vector3 vector = base.transform.position - pos; |
| Vector3 vector = base.transform.position - pos; |
| vector.y = 0f; |
| vector.y = 0f; |
| if (vector == Vector3.zero) |
| if (vector == Vector3.zero) |
| { |
| { |
| vector = Vector3.forward; |
| vector = Vector3.forward; |
| } |
| } |
| vector.Normalize(); |
| vector.Normalize(); |
| . | float num = Mathf.Round(Utils.YawFromDirection(vector) / 22.5f) * 22.5f; |
| float num = Mathf.Round(global::Utils.YawFromDirection(vector) / 22.5f) * 22.5f; |
| return Quaternion.Euler(0f, num, 0f); |
| return Quaternion.Euler(0f, num, 0f); |
| } |
| } |
| return Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 16) * 22.5f, 0f); |
| return Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 16) * 22.5f, 0f); |
| } |
| } |
| |
| |
| private void PlaceWall(float radius, int sections, ZoneSystem.SpawnMode mode) |
| private void PlaceWall(float radius, int sections, ZoneSystem.SpawnMode mode) |
| { |
| { |
| float num = Mathf.Cos(0.017453292f * this.m_maxTilt); |
| float num = Mathf.Cos(0.017453292f * this.m_maxTilt); |
| int num2 = 0; |
| int num2 = 0; |
| int num3 = sections * 20; |
| int num3 = sections * 20; |
| for (int i = 0; i < num3; i++) |
| for (int i = 0; i < num3; i++) |
| { |
| { |
| DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(true); |
| DungeonDB.RoomData randomWeightedRoom = this.GetRandomWeightedRoom(true); |
| if (randomWeightedRoom != null) |
| if (randomWeightedRoom != null) |
| { |
| { |
| Vector3 vector = base.transform.position + Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f) * Vector3.forward * radius; |
| Vector3 vector = base.transform.position + Quaternion.Euler(0f, (float)UnityEngine.Random.Range(0, 360), 0f) * Vector3.forward * radius; |
| Quaternion campRoomRotation = this.GetCampRoomRotation(randomWeightedRoom, vector); |
| Quaternion campRoomRotation = this.GetCampRoomRotation(randomWeightedRoom, vector); |
| if (ZoneSystem.instance) |
| if (ZoneSystem.instance) |
| { |
| { |
| Vector3 vector2; |
| Vector3 vector2; |
| Heightmap.Biome biome; |
| Heightmap.Biome biome; |
| Heightmap.BiomeArea biomeArea; |
| Heightmap.BiomeArea biomeArea; |
| Heightmap heightmap; |
| Heightmap heightmap; |
| ZoneSystem.instance.GetGroundData(ref vector, out vector2, out biome, out biomeArea, out heightmap); |
| ZoneSystem.instance.GetGroundData(ref vector, out vector2, out biome, out biomeArea, out heightmap); |
| . | if (vector2.y < num || vector.y - ZoneSystem.instance.m_waterLevel < this.m_minAltitude) |
| if (vector2.y < num || vector.y - 30f < this.m_minAltitude) |
| { |
| { |
| . | goto IL_E7; |
| goto IL_E2; |
| } |
| } |
| } |
| } |
| if (!this.TestCollision(randomWeightedRoom.RoomInPrefab, vector, campRoomRotation)) |
| if (!this.TestCollision(randomWeightedRoom.RoomInPrefab, vector, campRoomRotation)) |
| { |
| { |
| this.PlaceRoom(randomWeightedRoom, vector, campRoomRotation, null, mode); |
| this.PlaceRoom(randomWeightedRoom, vector, campRoomRotation, null, mode); |
| num2++; |
| num2++; |
| if (num2 >= sections) |
| if (num2 >= sections) |
| { |
| { |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| . | IL_E7:; |
| IL_E2:; |
| } |
| } |
| } |
| } |
| |
| |
| private void Save() |
| private void Save() |
| { |
| { |
| if (this.m_nview == null) |
| if (this.m_nview == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| ZDO zdo = this.m_nview.GetZDO(); |
| ZDO zdo = this.m_nview.GetZDO(); |
| DungeonGenerator.saveStream.SetLength(0L); |
| DungeonGenerator.saveStream.SetLength(0L); |
| DungeonGenerator.saveWriter.Write(DungeonGenerator.m_placedRooms.Count); |
| DungeonGenerator.saveWriter.Write(DungeonGenerator.m_placedRooms.Count); |
| for (int i = 0; i < DungeonGenerator.m_placedRooms.Count; i++) |
| for (int i = 0; i < DungeonGenerator.m_placedRooms.Count; i++) |
| { |
| { |
| Room room = DungeonGenerator.m_placedRooms[i]; |
| Room room = DungeonGenerator.m_placedRooms[i]; |
| DungeonGenerator.saveWriter.Write(room.GetHash()); |
| DungeonGenerator.saveWriter.Write(room.GetHash()); |
| DungeonGenerator.saveWriter.Write(room.transform.position); |
| DungeonGenerator.saveWriter.Write(room.transform.position); |
| DungeonGenerator.saveWriter.Write(room.transform.rotation); |
| DungeonGenerator.saveWriter.Write(room.transform.rotation); |
| } |
| } |
| zdo.Set(ZDOVars.s_roomData, DungeonGenerator.saveStream.ToArray()); |
| zdo.Set(ZDOVars.s_roomData, DungeonGenerator.saveStream.ToArray()); |
| int num; |
| int num; |
| if (zdo.GetInt(ZDOVars.s_rooms, out num)) |
| if (zdo.GetInt(ZDOVars.s_rooms, out num)) |
| { |
| { |
| zdo.RemoveInt(ZDOVars.s_rooms); |
| zdo.RemoveInt(ZDOVars.s_rooms); |
| for (int j = 0; j < num; j++) |
| for (int j = 0; j < num; j++) |
| { |
| { |
| string text = "room" + j.ToString(); |
| string text = "room" + j.ToString(); |
| zdo.RemoveInt(text); |
| zdo.RemoveInt(text); |
| zdo.RemoveVec3(text + "_pos"); |
| zdo.RemoveVec3(text + "_pos"); |
| zdo.RemoveQuaternion(text + "_rot"); |
| zdo.RemoveQuaternion(text + "_rot"); |
| zdo.RemoveInt(text + "_seed"); |
| zdo.RemoveInt(text + "_seed"); |
| } |
| } |
| ZLog.Log(string.Format("Cleaned up old dungeon data format for {0} rooms.", num)); |
| ZLog.Log(string.Format("Cleaned up old dungeon data format for {0} rooms.", num)); |
| } |
| } |
| } |
| } |
| |
| |
| private void Load() |
| private void Load() |
| { |
| { |
| if (this.m_nview == null) |
| if (this.m_nview == null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| DateTime now = DateTime.Now; |
| DateTime now = DateTime.Now; |
| ZLog.Log("Loading dungeon"); |
| ZLog.Log("Loading dungeon"); |
| ZDO zdo = this.m_nview.GetZDO(); |
| ZDO zdo = this.m_nview.GetZDO(); |
| int num = 0; |
| int num = 0; |
| byte[] array; |
| byte[] array; |
| if (zdo.GetByteArray(ZDOVars.s_roomData, out array)) |
| if (zdo.GetByteArray(ZDOVars.s_roomData, out array)) |
| { |
| { |
| BinaryReader binaryReader = new BinaryReader(new MemoryStream(array)); |
| BinaryReader binaryReader = new BinaryReader(new MemoryStream(array)); |
| int num2 = binaryReader.ReadInt32(); |
| int num2 = binaryReader.ReadInt32(); |
| this.m_loadedRooms = new DungeonGenerator.RoomPlacementData[num2]; |
| this.m_loadedRooms = new DungeonGenerator.RoomPlacementData[num2]; |
| for (int i = 0; i < num2; i++) |
| for (int i = 0; i < num2; i++) |
| { |
| { |
| int num3 = binaryReader.ReadInt32(); |
| int num3 = binaryReader.ReadInt32(); |
| Vector3 vector = binaryReader.ReadVector3(); |
| Vector3 vector = binaryReader.ReadVector3(); |
| Quaternion quaternion = binaryReader.ReadQuaternion(); |
| Quaternion quaternion = binaryReader.ReadQuaternion(); |
| DungeonDB.RoomData room = DungeonDB.instance.GetRoom(num3); |
| DungeonDB.RoomData room = DungeonDB.instance.GetRoom(num3); |
| if (room == null) |
| if (room == null) |
| { |
| { |
| ZLog.LogWarning("Missing room:" + num3.ToString()); |
| ZLog.LogWarning("Missing room:" + num3.ToString()); |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_loadedRooms[num++] = new DungeonGenerator.RoomPlacementData(room, vector, quaternion); |
| this.m_loadedRooms[num++] = new DungeonGenerator.RoomPlacementData(room, vector, quaternion); |
| } |
| } |
| } |
| } |
| ZLog.Log(string.Format("Dungeon loaded with {0} rooms in {1} ms.", num2, (DateTime.Now - now).TotalMilliseconds)); |
| ZLog.Log(string.Format("Dungeon loaded with {0} rooms in {1} ms.", num2, (DateTime.Now - now).TotalMilliseconds)); |
| } |
| } |
| else |
| else |
| { |
| { |
| int @int = zdo.GetInt("rooms", 0); |
| int @int = zdo.GetInt("rooms", 0); |
| this.m_loadedRooms = new DungeonGenerator.RoomPlacementData[@int]; |
| this.m_loadedRooms = new DungeonGenerator.RoomPlacementData[@int]; |
| for (int j = 0; j < @int; j++) |
| for (int j = 0; j < @int; j++) |
| { |
| { |
| string text = "room" + j.ToString(); |
| string text = "room" + j.ToString(); |
| int int2 = zdo.GetInt(text, 0); |
| int int2 = zdo.GetInt(text, 0); |
| Vector3 vec = zdo.GetVec3(text + "_pos", Vector3.zero); |
| Vector3 vec = zdo.GetVec3(text + "_pos", Vector3.zero); |
| Quaternion quaternion2 = zdo.GetQuaternion(text + "_rot", Quaternion.identity); |
| Quaternion quaternion2 = zdo.GetQuaternion(text + "_rot", Quaternion.identity); |
| DungeonDB.RoomData room2 = DungeonDB.instance.GetRoom(int2); |
| DungeonDB.RoomData room2 = DungeonDB.instance.GetRoom(int2); |
| if (room2 == null) |
| if (room2 == null) |
| { |
| { |
| ZLog.LogWarning("Missing room:" + int2.ToString()); |
| ZLog.LogWarning("Missing room:" + int2.ToString()); |
| } |
| } |
| else |
| else |
| { |
| { |
| this.m_loadedRooms[num++] = new DungeonGenerator.RoomPlacementData(room2, vec, quaternion2); |
| this.m_loadedRooms[num++] = new DungeonGenerator.RoomPlacementData(room2, vec, quaternion2); |
| } |
| } |
| } |
| } |
| ZLog.Log(string.Format("Dungeon loaded with {0} rooms from old format in {1} ms.", @int, (DateTime.Now - now).TotalMilliseconds)); |
| ZLog.Log(string.Format("Dungeon loaded with {0} rooms from old format in {1} ms.", @int, (DateTime.Now - now).TotalMilliseconds)); |
| } |
| } |
| if (num < this.m_loadedRooms.Length) |
| if (num < this.m_loadedRooms.Length) |
| { |
| { |
| DungeonGenerator.RoomPlacementData[] array2 = new DungeonGenerator.RoomPlacementData[num]; |
| DungeonGenerator.RoomPlacementData[] array2 = new DungeonGenerator.RoomPlacementData[num]; |
| Array.Copy(this.m_loadedRooms, array2, num); |
| Array.Copy(this.m_loadedRooms, array2, num); |
| this.m_loadedRooms = array2; |
| this.m_loadedRooms = array2; |
| } |
| } |
| } |
| } |
| |
| |
| private void SetupAvailableRooms() |
| private void SetupAvailableRooms() |
| { |
| { |
| DungeonGenerator.m_availableRooms.Clear(); |
| DungeonGenerator.m_availableRooms.Clear(); |
| foreach (DungeonDB.RoomData roomData in DungeonDB.GetRooms()) |
| foreach (DungeonDB.RoomData roomData in DungeonDB.GetRooms()) |
| { |
| { |
| . | if ((roomData.m_prefabData.m_theme & this.m_themes) != Room.Theme.None && roomData.m_prefabData.m_enabled) |
| if ((roomData.m_theme & this.m_themes) != Room.Theme.None && roomData.m_enabled) |
| { |
| { |
| DungeonGenerator.m_availableRooms.Add(roomData); |
| DungeonGenerator.m_availableRooms.Add(roomData); |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| public SoftReference<GameObject>[] GetAvailableRoomPrefabs() |
| public SoftReference<GameObject>[] GetAvailableRoomPrefabs() |
| { |
| { |
| this.SetupAvailableRooms(); |
| this.SetupAvailableRooms(); |
| SoftReference<GameObject>[] array = new SoftReference<GameObject>[DungeonGenerator.m_availableRooms.Count]; |
| SoftReference<GameObject>[] array = new SoftReference<GameObject>[DungeonGenerator.m_availableRooms.Count]; |
| for (int i = 0; i < DungeonGenerator.m_availableRooms.Count; i++) |
| for (int i = 0; i < DungeonGenerator.m_availableRooms.Count; i++) |
| { |
| { |
| array[i] = DungeonGenerator.m_availableRooms[i].m_prefab; |
| array[i] = DungeonGenerator.m_availableRooms[i].m_prefab; |
| } |
| } |
| return array; |
| return array; |
| } |
| } |
| |
| |
| private DungeonGenerator.DoorDef FindDoorType(string type) |
| private DungeonGenerator.DoorDef FindDoorType(string type) |
| { |
| { |
| List<DungeonGenerator.DoorDef> list = new List<DungeonGenerator.DoorDef>(); |
| List<DungeonGenerator.DoorDef> list = new List<DungeonGenerator.DoorDef>(); |
| foreach (DungeonGenerator.DoorDef doorDef in this.m_doorTypes) |
| foreach (DungeonGenerator.DoorDef doorDef in this.m_doorTypes) |
| { |
| { |
| if (doorDef.m_connectionType == type) |
| if (doorDef.m_connectionType == type) |
| { |
| { |
| list.Add(doorDef); |
| list.Add(doorDef); |
| } |
| } |
| } |
| } |
| if (list.Count == 0) |
| if (list.Count == 0) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| return list[UnityEngine.Random.Range(0, list.Count)]; |
| return list[UnityEngine.Random.Range(0, list.Count)]; |
| } |
| } |
| |
| |
| private void PlaceDoors(ZoneSystem.SpawnMode mode) |
| private void PlaceDoors(ZoneSystem.SpawnMode mode) |
| { |
| { |
| int num = 0; |
| int num = 0; |
| foreach (RoomConnection roomConnection in DungeonGenerator.m_doorConnections) |
| foreach (RoomConnection roomConnection in DungeonGenerator.m_doorConnections) |
| { |
| { |
| DungeonGenerator.DoorDef doorDef = this.FindDoorType(roomConnection.m_type); |
| DungeonGenerator.DoorDef doorDef = this.FindDoorType(roomConnection.m_type); |
| if (doorDef == null) |
| if (doorDef == null) |
| { |
| { |
| ZLog.Log("No door type for connection:" + roomConnection.m_type); |
| ZLog.Log("No door type for connection:" + roomConnection.m_type); |
| } |
| } |
| else if ((doorDef.m_chance <= 0f || UnityEngine.Random.value <= doorDef.m_chance) && (doorDef.m_chance > 0f || UnityEngine.Random.value <= this.m_doorChance)) |
| else if ((doorDef.m_chance <= 0f || UnityEngine.Random.value <= doorDef.m_chance) && (doorDef.m_chance > 0f || UnityEngine.Random.value <= this.m_doorChance)) |
| { |
| { |
| GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(doorDef.m_prefab, roomConnection.transform.position, roomConnection.transform.rotation); |
| GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(doorDef.m_prefab, roomConnection.transform.position, roomConnection.transform.rotation); |
| if (mode == ZoneSystem.SpawnMode.Ghost) |
| if (mode == ZoneSystem.SpawnMode.Ghost) |
| { |
| { |
| UnityEngine.Object.Destroy(gameObject); |
| UnityEngine.Object.Destroy(gameObject); |
| } |
| } |
| num++; |
| num++; |
| } |
| } |
| } |
| } |
| ZLog.Log("placed " + num.ToString() + " doors"); |
| ZLog.Log("placed " + num.ToString() + " doors"); |
| } |
| } |
| |
| |
| private void PlaceEndCaps(ZoneSystem.SpawnMode mode) |
| private void PlaceEndCaps(ZoneSystem.SpawnMode mode) |
| { |
| { |
| for (int i = 0; i < DungeonGenerator.m_openConnections.Count; i++) |
| for (int i = 0; i < DungeonGenerator.m_openConnections.Count; i++) |
| { |
| { |
| RoomConnection roomConnection = DungeonGenerator.m_openConnections[i]; |
| RoomConnection roomConnection = DungeonGenerator.m_openConnections[i]; |
| RoomConnection roomConnection2 = null; |
| RoomConnection roomConnection2 = null; |
| for (int j = 0; j < DungeonGenerator.m_openConnections.Count; j++) |
| for (int j = 0; j < DungeonGenerator.m_openConnections.Count; j++) |
| { |
| { |
| if (j != i && roomConnection.TestContact(DungeonGenerator.m_openConnections[j])) |
| if (j != i && roomConnection.TestContact(DungeonGenerator.m_openConnections[j])) |
| { |
| { |
| roomConnection2 = DungeonGenerator.m_openConnections[j]; |
| roomConnection2 = DungeonGenerator.m_openConnections[j]; |
| break; |
| break; |
| } |
| } |
| } |
| } |
| if (roomConnection2 != null) |
| if (roomConnection2 != null) |
| { |
| { |
| if (roomConnection.m_type != roomConnection2.m_type) |
| if (roomConnection.m_type != roomConnection2.m_type) |
| { |
| { |
| this.FindDividers(DungeonGenerator.m_tempRooms); |
| this.FindDividers(DungeonGenerator.m_tempRooms); |
| if (DungeonGenerator.m_tempRooms.Count > 0) |
| if (DungeonGenerator.m_tempRooms.Count > 0) |
| { |
| { |
| DungeonDB.RoomData weightedRoom = this.GetWeightedRoom(DungeonGenerator.m_tempRooms); |
| DungeonDB.RoomData weightedRoom = this.GetWeightedRoom(DungeonGenerator.m_tempRooms); |
| RoomConnection[] connections = weightedRoom.RoomInPrefab.GetConnections(); |
| RoomConnection[] connections = weightedRoom.RoomInPrefab.GetConnections(); |
| Vector3 vector; |
| Vector3 vector; |
| Quaternion quaternion; |
| Quaternion quaternion; |
| this.CalculateRoomPosRot(connections[0], roomConnection.transform.position, roomConnection.transform.rotation, out vector, out quaternion); |
| this.CalculateRoomPosRot(connections[0], roomConnection.transform.position, roomConnection.transform.rotation, out vector, out quaternion); |
| bool flag = false; |
| bool flag = false; |
| foreach (Room room in DungeonGenerator.m_placedRooms) |
| foreach (Room room in DungeonGenerator.m_placedRooms) |
| { |
| { |
| if (room.m_divider && Vector3.Distance(room.transform.position, vector) < 0.5f) |
| if (room.m_divider && Vector3.Distance(room.transform.position, vector) < 0.5f) |
| { |
| { |
| flag = true; |
| flag = true; |
| break; |
| break; |
| } |
| } |
| } |
| } |
| if (!flag) |
| if (!flag) |
| { |
| { |
| this.PlaceRoom(weightedRoom, vector, quaternion, roomConnection, mode); |
| this.PlaceRoom(weightedRoom, vector, quaternion, roomConnection, mode); |
| ZLog.Log(string.Concat(new string[] |
| ZLog.Log(string.Concat(new string[] |
| { |
| { |
| "Cyclic detected. Door missmatch for cyclic room '", |
| "Cyclic detected. Door missmatch for cyclic room '", |
| roomConnection.m_type, |
| roomConnection.m_type, |
| "'-'", |
| "'-'", |
| roomConnection2.m_type, |
| roomConnection2.m_type, |
| "', placing divider: ", |
| "', placing divider: ", |
| weightedRoom.m_prefab.Name |
| weightedRoom.m_prefab.Name |
| })); |
| })); |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.LogWarning(string.Concat(new string[] { "Cyclic detected. Door missmatch for cyclic room '", roomConnection.m_type, "'-'", roomConnection2.m_type, "', but no dividers defined!" })); |
| ZLog.LogWarning(string.Concat(new string[] { "Cyclic detected. Door missmatch for cyclic room '", roomConnection.m_type, "'-'", roomConnection2.m_type, "', but no dividers defined!" })); |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| ZLog.Log("cyclic detected and door types match, cool"); |
| ZLog.Log("cyclic detected and door types match, cool"); |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| this.FindEndCaps(roomConnection, DungeonGenerator.m_tempRooms); |
| this.FindEndCaps(roomConnection, DungeonGenerator.m_tempRooms); |
| bool flag2 = false; |
| bool flag2 = false; |
| if (this.m_alternativeFunctionality) |
| if (this.m_alternativeFunctionality) |
| { |
| { |
| for (int k = 0; k < 5; k++) |
| for (int k = 0; k < 5; k++) |
| { |
| { |
| DungeonDB.RoomData weightedRoom2 = this.GetWeightedRoom(DungeonGenerator.m_tempRooms); |
| DungeonDB.RoomData weightedRoom2 = this.GetWeightedRoom(DungeonGenerator.m_tempRooms); |
| if (this.PlaceRoom(roomConnection, weightedRoom2, mode)) |
| if (this.PlaceRoom(roomConnection, weightedRoom2, mode)) |
| { |
| { |
| flag2 = true; |
| flag2 = true; |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| IOrderedEnumerable<DungeonDB.RoomData> orderedEnumerable = DungeonGenerator.m_tempRooms.OrderByDescending((DungeonDB.RoomData item) => item.RoomInPrefab.m_endCapPrio); |
| IOrderedEnumerable<DungeonDB.RoomData> orderedEnumerable = DungeonGenerator.m_tempRooms.OrderByDescending((DungeonDB.RoomData item) => item.RoomInPrefab.m_endCapPrio); |
| if (!flag2) |
| if (!flag2) |
| { |
| { |
| foreach (DungeonDB.RoomData roomData in orderedEnumerable) |
| foreach (DungeonDB.RoomData roomData in orderedEnumerable) |
| { |
| { |
| if (this.PlaceRoom(roomConnection, roomData, mode)) |
| if (this.PlaceRoom(roomConnection, roomData, mode)) |
| { |
| { |
| flag2 = true; |
| flag2 = true; |
| break; |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |
| if (!flag2) |
| if (!flag2) |
| { |
| { |
| ZLog.LogWarning("Failed to place end cap " + roomConnection.name + " " + roomConnection.transform.parent.gameObject.name); |
| ZLog.LogWarning("Failed to place end cap " + roomConnection.name + " " + roomConnection.transform.parent.gameObject.name); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void FindDividers(List<DungeonDB.RoomData> rooms) |
| private void FindDividers(List<DungeonDB.RoomData> rooms) |
| { |
| { |
| rooms.Clear(); |
| rooms.Clear(); |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| { |
| { |
| if (roomData.RoomInPrefab.m_divider) |
| if (roomData.RoomInPrefab.m_divider) |
| { |
| { |
| rooms.Add(roomData); |
| rooms.Add(roomData); |
| } |
| } |
| } |
| } |
| rooms.Shuffle(true); |
| rooms.Shuffle(true); |
| } |
| } |
| |
| |
| private void FindEndCaps(RoomConnection connection, List<DungeonDB.RoomData> rooms) |
| private void FindEndCaps(RoomConnection connection, List<DungeonDB.RoomData> rooms) |
| { |
| { |
| rooms.Clear(); |
| rooms.Clear(); |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| { |
| { |
| if (roomData.RoomInPrefab.m_endCap && roomData.RoomInPrefab.HaveConnection(connection)) |
| if (roomData.RoomInPrefab.m_endCap && roomData.RoomInPrefab.HaveConnection(connection)) |
| { |
| { |
| rooms.Add(roomData); |
| rooms.Add(roomData); |
| } |
| } |
| } |
| } |
| rooms.Shuffle(true); |
| rooms.Shuffle(true); |
| } |
| } |
| |
| |
| private DungeonDB.RoomData FindEndCap(RoomConnection connection) |
| private DungeonDB.RoomData FindEndCap(RoomConnection connection) |
| { |
| { |
| DungeonGenerator.m_tempRooms.Clear(); |
| DungeonGenerator.m_tempRooms.Clear(); |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| { |
| { |
| if (roomData.RoomInPrefab.m_endCap && roomData.RoomInPrefab.HaveConnection(connection)) |
| if (roomData.RoomInPrefab.m_endCap && roomData.RoomInPrefab.HaveConnection(connection)) |
| { |
| { |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| } |
| } |
| } |
| } |
| if (DungeonGenerator.m_tempRooms.Count == 0) |
| if (DungeonGenerator.m_tempRooms.Count == 0) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| return DungeonGenerator.m_tempRooms[UnityEngine.Random.Range(0, DungeonGenerator.m_tempRooms.Count)]; |
| return DungeonGenerator.m_tempRooms[UnityEngine.Random.Range(0, DungeonGenerator.m_tempRooms.Count)]; |
| } |
| } |
| |
| |
| private void PlaceRooms(ZoneSystem.SpawnMode mode) |
| private void PlaceRooms(ZoneSystem.SpawnMode mode) |
| { |
| { |
| for (int i = 0; i < this.m_maxRooms; i++) |
| for (int i = 0; i < this.m_maxRooms; i++) |
| { |
| { |
| this.PlaceOneRoom(mode); |
| this.PlaceOneRoom(mode); |
| if (this.CheckRequiredRooms() && DungeonGenerator.m_placedRooms.Count > this.m_minRooms) |
| if (this.CheckRequiredRooms() && DungeonGenerator.m_placedRooms.Count > this.m_minRooms) |
| { |
| { |
| ZLog.Log("All required rooms have been placed, stopping generation"); |
| ZLog.Log("All required rooms have been placed, stopping generation"); |
| return; |
| return; |
| } |
| } |
| } |
| } |
| } |
| } |
| |
| |
| private void PlaceStartRoom(ZoneSystem.SpawnMode mode) |
| private void PlaceStartRoom(ZoneSystem.SpawnMode mode) |
| { |
| { |
| DungeonDB.RoomData roomData = this.FindStartRoom(); |
| DungeonDB.RoomData roomData = this.FindStartRoom(); |
| RoomConnection entrance = roomData.RoomInPrefab.GetEntrance(); |
| RoomConnection entrance = roomData.RoomInPrefab.GetEntrance(); |
| Quaternion rotation = base.transform.rotation; |
| Quaternion rotation = base.transform.rotation; |
| Vector3 vector; |
| Vector3 vector; |
| Quaternion quaternion; |
| Quaternion quaternion; |
| this.CalculateRoomPosRot(entrance, base.transform.position, rotation, out vector, out quaternion); |
| this.CalculateRoomPosRot(entrance, base.transform.position, rotation, out vector, out quaternion); |
| this.PlaceRoom(roomData, vector, quaternion, entrance, mode); |
| this.PlaceRoom(roomData, vector, quaternion, entrance, mode); |
| } |
| } |
| |
| |
| private bool PlaceOneRoom(ZoneSystem.SpawnMode mode) |
| private bool PlaceOneRoom(ZoneSystem.SpawnMode mode) |
| { |
| { |
| RoomConnection openConnection = this.GetOpenConnection(); |
| RoomConnection openConnection = this.GetOpenConnection(); |
| if (openConnection == null) |
| if (openConnection == null) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| for (int i = 0; i < 10; i++) |
| for (int i = 0; i < 10; i++) |
| { |
| { |
| DungeonDB.RoomData roomData = (this.m_alternativeFunctionality ? this.GetRandomWeightedRoom(openConnection) : this.GetRandomRoom(openConnection)); |
| DungeonDB.RoomData roomData = (this.m_alternativeFunctionality ? this.GetRandomWeightedRoom(openConnection) : this.GetRandomRoom(openConnection)); |
| if (roomData == null) |
| if (roomData == null) |
| { |
| { |
| break; |
| break; |
| } |
| } |
| if (this.PlaceRoom(openConnection, roomData, mode)) |
| if (this.PlaceRoom(openConnection, roomData, mode)) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private void CalculateRoomPosRot(RoomConnection roomCon, Vector3 exitPos, Quaternion exitRot, out Vector3 pos, out Quaternion rot) |
| private void CalculateRoomPosRot(RoomConnection roomCon, Vector3 exitPos, Quaternion exitRot, out Vector3 pos, out Quaternion rot) |
| { |
| { |
| Quaternion quaternion = Quaternion.Inverse(roomCon.transform.localRotation); |
| Quaternion quaternion = Quaternion.Inverse(roomCon.transform.localRotation); |
| rot = exitRot * quaternion; |
| rot = exitRot * quaternion; |
| Vector3 localPosition = roomCon.transform.localPosition; |
| Vector3 localPosition = roomCon.transform.localPosition; |
| pos = exitPos - rot * localPosition; |
| pos = exitPos - rot * localPosition; |
| } |
| } |
| |
| |
| private bool PlaceRoom(RoomConnection connection, DungeonDB.RoomData roomData, ZoneSystem.SpawnMode mode) |
| private bool PlaceRoom(RoomConnection connection, DungeonDB.RoomData roomData, ZoneSystem.SpawnMode mode) |
| { |
| { |
| SoftReference<GameObject> prefab = roomData.m_prefab; |
| SoftReference<GameObject> prefab = roomData.m_prefab; |
| prefab.Load(); |
| prefab.Load(); |
| Room component = prefab.Asset.GetComponent<Room>(); |
| Room component = prefab.Asset.GetComponent<Room>(); |
| Quaternion quaternion = connection.transform.rotation; |
| Quaternion quaternion = connection.transform.rotation; |
| quaternion *= Quaternion.Euler(0f, 180f, 0f); |
| quaternion *= Quaternion.Euler(0f, 180f, 0f); |
| RoomConnection connection2 = component.GetConnection(connection); |
| RoomConnection connection2 = component.GetConnection(connection); |
| if (connection2.transform.parent.gameObject != component.gameObject) |
| if (connection2.transform.parent.gameObject != component.gameObject) |
| { |
| { |
| ZLog.LogWarning(string.Concat(new string[] { "Connection '", component.name, "->", connection2.name, "' is not placed as a direct child of room!" })); |
| ZLog.LogWarning(string.Concat(new string[] { "Connection '", component.name, "->", connection2.name, "' is not placed as a direct child of room!" })); |
| } |
| } |
| Vector3 vector; |
| Vector3 vector; |
| Quaternion quaternion2; |
| Quaternion quaternion2; |
| this.CalculateRoomPosRot(connection2, connection.transform.position, quaternion, out vector, out quaternion2); |
| this.CalculateRoomPosRot(connection2, connection.transform.position, quaternion, out vector, out quaternion2); |
| if (component.m_size.x != 0 && component.m_size.z != 0 && this.TestCollision(component, vector, quaternion2)) |
| if (component.m_size.x != 0 && component.m_size.z != 0 && this.TestCollision(component, vector, quaternion2)) |
| { |
| { |
| prefab.Release(); |
| prefab.Release(); |
| return false; |
| return false; |
| } |
| } |
| this.PlaceRoom(roomData, vector, quaternion2, connection, mode); |
| this.PlaceRoom(roomData, vector, quaternion2, connection, mode); |
| if (!component.m_endCap) |
| if (!component.m_endCap) |
| { |
| { |
| if (connection.m_allowDoor && (!connection.m_doorOnlyIfOtherAlsoAllowsDoor || connection2.m_allowDoor)) |
| if (connection.m_allowDoor && (!connection.m_doorOnlyIfOtherAlsoAllowsDoor || connection2.m_allowDoor)) |
| { |
| { |
| DungeonGenerator.m_doorConnections.Add(connection); |
| DungeonGenerator.m_doorConnections.Add(connection); |
| } |
| } |
| DungeonGenerator.m_openConnections.Remove(connection); |
| DungeonGenerator.m_openConnections.Remove(connection); |
| } |
| } |
| prefab.Release(); |
| prefab.Release(); |
| return true; |
| return true; |
| } |
| } |
| |
| |
| private Room PlaceRoom(DungeonDB.RoomData roomData, Vector3 pos, Quaternion rot, RoomConnection fromConnection, ZoneSystem.SpawnMode mode) |
| private Room PlaceRoom(DungeonDB.RoomData roomData, Vector3 pos, Quaternion rot, RoomConnection fromConnection, ZoneSystem.SpawnMode mode) |
| { |
| { |
| roomData.m_prefab.Load(); |
| roomData.m_prefab.Load(); |
| Room component = roomData.m_prefab.Asset.GetComponent<Room>(); |
| Room component = roomData.m_prefab.Asset.GetComponent<Room>(); |
| . | ZNetView[] enabledComponentsInChildren = Utils.GetEnabledComponentsInChildren<ZNetView>(roomData.m_prefab.Asset); |
| ZNetView[] enabledComponentsInChildren = global::Utils.GetEnabledComponentsInChildren<ZNetView>(roomData.m_prefab.Asset); |
| RandomSpawn[] enabledComponentsInChildren2 = Utils.GetEnabledComponentsInChildren<RandomSpawn>(roomData.m_prefab.Asset); |
| RandomSpawn[] enabledComponentsInChildren2 = global::Utils.GetEnabledComponentsInChildren<RandomSpawn>(roomData.m_prefab.Asset); |
| for (int i = 0; i < enabledComponentsInChildren2.Length; i++) |
| for (int i = 0; i < enabledComponentsInChildren2.Length; i++) |
| { |
| { |
| enabledComponentsInChildren2[i].Prepare(); |
| enabledComponentsInChildren2[i].Prepare(); |
| } |
| } |
| Vector3 vector = pos; |
| Vector3 vector = pos; |
| if (this.m_useCustomInteriorTransform) |
| if (this.m_useCustomInteriorTransform) |
| { |
| { |
| vector = pos - base.transform.position; |
| vector = pos - base.transform.position; |
| } |
| } |
| int num = (int)vector.x * 4271 + (int)vector.y * 9187 + (int)vector.z * 2134; |
| int num = (int)vector.x * 4271 + (int)vector.y * 9187 + (int)vector.z * 2134; |
| UnityEngine.Random.State state = UnityEngine.Random.state; |
| UnityEngine.Random.State state = UnityEngine.Random.state; |
| UnityEngine.Random.InitState(num); |
| UnityEngine.Random.InitState(num); |
| . | RandomSpawn[] array; |
| Vector3 position = component.transform.position; |
| |
| Quaternion quaternion = Quaternion.Inverse(component.transform.rotation); |
| if (mode == ZoneSystem.SpawnMode.Full || mode == ZoneSystem.SpawnMode.Ghost) |
| if (mode == ZoneSystem.SpawnMode.Full || mode == ZoneSystem.SpawnMode.Ghost) |
| { |
| { |
| UnityEngine.Random.InitState(num); |
| UnityEngine.Random.InitState(num); |
| . | array = enabledComponentsInChildren2; |
| foreach (RandomSpawn randomSpawn in enabledComponentsInChildren2) |
| for (int j = 0; j < array.Length; j++) |
| |
| { |
| { |
| . | array[j].Randomize(null, this); |
| Vector3 vector2 = quaternion * (randomSpawn.gameObject.transform.position - position); |
| |
| Vector3 vector3 = pos + rot * vector2; |
| |
| randomSpawn.Randomize(vector3, null, this); |
| } |
| } |
| . | Vector3 position = component.transform.position; |
| |
| Quaternion quaternion = Quaternion.Inverse(component.transform.rotation); |
| |
| foreach (ZNetView znetView in enabledComponentsInChildren) |
| foreach (ZNetView znetView in enabledComponentsInChildren) |
| { |
| { |
| if (znetView.gameObject.activeSelf) |
| if (znetView.gameObject.activeSelf) |
| { |
| { |
| . | Vector3 vector2 = quaternion * (znetView.gameObject.transform.position - position); |
| Vector3 vector4 = quaternion * (znetView.gameObject.transform.position - position); |
| Vector3 vector3 = pos + rot * vector2; |
| Vector3 vector5 = pos + rot * vector4; |
| Quaternion quaternion2 = quaternion * znetView.gameObject.transform.rotation; |
| Quaternion quaternion2 = quaternion * znetView.gameObject.transform.rotation; |
| Quaternion quaternion3 = rot * quaternion2; |
| Quaternion quaternion3 = rot * quaternion2; |
| . | GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(znetView.gameObject, vector3, quaternion3); |
| GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(znetView.gameObject, vector5, quaternion3); |
| gameObject.GetComponent<ZNetView>().HoldReferenceTo(roomData.m_prefab); |
| gameObject.HoldReferenceTo(roomData.m_prefab); |
| if (mode == ZoneSystem.SpawnMode.Ghost) |
| if (mode == ZoneSystem.SpawnMode.Ghost) |
| { |
| { |
| UnityEngine.Object.Destroy(gameObject); |
| UnityEngine.Object.Destroy(gameObject); |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| } |
| else |
| else |
| { |
| { |
| UnityEngine.Random.InitState(num); |
| UnityEngine.Random.InitState(num); |
| . | array = enabledComponentsInChildren2; |
| foreach (RandomSpawn randomSpawn2 in enabledComponentsInChildren2) |
| for (int j = 0; j < array.Length; j++) |
| |
| { |
| { |
| . | array[j].Randomize(null, this); |
| Vector3 vector6 = quaternion * (randomSpawn2.gameObject.transform.position - position); |
| |
| Vector3 vector7 = pos + rot * vector6; |
| |
| randomSpawn2.Randomize(vector7, null, this); |
| } |
| } |
| } |
| } |
| ZNetView[] array2 = enabledComponentsInChildren; |
| ZNetView[] array2 = enabledComponentsInChildren; |
| for (int j = 0; j < array2.Length; j++) |
| for (int j = 0; j < array2.Length; j++) |
| { |
| { |
| array2[j].gameObject.SetActive(false); |
| array2[j].gameObject.SetActive(false); |
| } |
| } |
| . | GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(component.gameObject, pos, rot, base.transform); |
| Room component2 = SoftReferenceableAssets.Utils.Instantiate(roomData.m_prefab, pos, rot, base.transform).GetComponent<Room>(); |
| ReferenceHolder referenceHolder = gameObject2.GetComponent<ReferenceHolder>(); |
| component2.gameObject.name = roomData.m_prefab.Name; |
| if (referenceHolder == null) |
| |
| { |
| |
| referenceHolder = gameObject2.AddComponent<ReferenceHolder>(); |
| |
| } |
| |
| referenceHolder.HoldReferenceTo(roomData.m_prefab); |
| |
| Room component2 = gameObject2.GetComponent<Room>(); |
| |
| component2.gameObject.name = component.gameObject.name; |
| |
| if (mode != ZoneSystem.SpawnMode.Client) |
| if (mode != ZoneSystem.SpawnMode.Client) |
| { |
| { |
| component2.m_placeOrder = (fromConnection ? (fromConnection.m_placeOrder + 1) : 0); |
| component2.m_placeOrder = (fromConnection ? (fromConnection.m_placeOrder + 1) : 0); |
| component2.m_seed = num; |
| component2.m_seed = num; |
| DungeonGenerator.m_placedRooms.Add(component2); |
| DungeonGenerator.m_placedRooms.Add(component2); |
| this.AddOpenConnections(component2, fromConnection); |
| this.AddOpenConnections(component2, fromConnection); |
| } |
| } |
| UnityEngine.Random.state = state; |
| UnityEngine.Random.state = state; |
| . | array = enabledComponentsInChildren2; |
| RandomSpawn[] array = enabledComponentsInChildren2; |
| for (int j = 0; j < array.Length; j++) |
| for (int j = 0; j < array.Length; j++) |
| { |
| { |
| array[j].Reset(); |
| array[j].Reset(); |
| } |
| } |
| array2 = enabledComponentsInChildren; |
| array2 = enabledComponentsInChildren; |
| for (int j = 0; j < array2.Length; j++) |
| for (int j = 0; j < array2.Length; j++) |
| { |
| { |
| array2[j].gameObject.SetActive(true); |
| array2[j].gameObject.SetActive(true); |
| } |
| } |
| roomData.m_prefab.Release(); |
| roomData.m_prefab.Release(); |
| return component2; |
| return component2; |
| } |
| } |
| |
| |
| private void AddOpenConnections(Room newRoom, RoomConnection skipConnection) |
| private void AddOpenConnections(Room newRoom, RoomConnection skipConnection) |
| { |
| { |
| RoomConnection[] connections = newRoom.GetConnections(); |
| RoomConnection[] connections = newRoom.GetConnections(); |
| if (skipConnection != null) |
| if (skipConnection != null) |
| { |
| { |
| foreach (RoomConnection roomConnection in connections) |
| foreach (RoomConnection roomConnection in connections) |
| { |
| { |
| if (!roomConnection.m_entrance && Vector3.Distance(roomConnection.transform.position, skipConnection.transform.position) >= 0.1f) |
| if (!roomConnection.m_entrance && Vector3.Distance(roomConnection.transform.position, skipConnection.transform.position) >= 0.1f) |
| { |
| { |
| roomConnection.m_placeOrder = newRoom.m_placeOrder; |
| roomConnection.m_placeOrder = newRoom.m_placeOrder; |
| DungeonGenerator.m_openConnections.Add(roomConnection); |
| DungeonGenerator.m_openConnections.Add(roomConnection); |
| } |
| } |
| } |
| } |
| return; |
| return; |
| } |
| } |
| RoomConnection[] array = connections; |
| RoomConnection[] array = connections; |
| for (int i = 0; i < array.Length; i++) |
| for (int i = 0; i < array.Length; i++) |
| { |
| { |
| array[i].m_placeOrder = newRoom.m_placeOrder; |
| array[i].m_placeOrder = newRoom.m_placeOrder; |
| } |
| } |
| DungeonGenerator.m_openConnections.AddRange(connections); |
| DungeonGenerator.m_openConnections.AddRange(connections); |
| } |
| } |
| |
| |
| private void SetupColliders() |
| private void SetupColliders() |
| { |
| { |
| if (this.m_colliderA != null) |
| if (this.m_colliderA != null) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| BoxCollider[] componentsInChildren = base.gameObject.GetComponentsInChildren<BoxCollider>(); |
| BoxCollider[] componentsInChildren = base.gameObject.GetComponentsInChildren<BoxCollider>(); |
| for (int i = 0; i < componentsInChildren.Length; i++) |
| for (int i = 0; i < componentsInChildren.Length; i++) |
| { |
| { |
| UnityEngine.Object.DestroyImmediate(componentsInChildren[i]); |
| UnityEngine.Object.DestroyImmediate(componentsInChildren[i]); |
| } |
| } |
| this.m_colliderA = base.gameObject.AddComponent<BoxCollider>(); |
| this.m_colliderA = base.gameObject.AddComponent<BoxCollider>(); |
| this.m_colliderB = base.gameObject.AddComponent<BoxCollider>(); |
| this.m_colliderB = base.gameObject.AddComponent<BoxCollider>(); |
| } |
| } |
| |
| |
| public void Derp() |
| public void Derp() |
| { |
| { |
| } |
| } |
| |
| |
| private bool IsInsideDungeon(Room room, Vector3 pos, Quaternion rot) |
| private bool IsInsideDungeon(Room room, Vector3 pos, Quaternion rot) |
| { |
| { |
| Bounds bounds = new Bounds(this.m_zoneCenter, this.m_zoneSize); |
| Bounds bounds = new Bounds(this.m_zoneCenter, this.m_zoneSize); |
| Vector3 vector = room.m_size; |
| Vector3 vector = room.m_size; |
| vector *= 0.5f; |
| vector *= 0.5f; |
| return bounds.Contains(pos + rot * new Vector3(vector.x, vector.y, -vector.z)) && bounds.Contains(pos + rot * new Vector3(-vector.x, vector.y, -vector.z)) && bounds.Contains(pos + rot * new Vector3(vector.x, vector.y, vector.z)) && bounds.Contains(pos + rot * new Vector3(-vector.x, vector.y, vector.z)) && bounds.Contains(pos + rot * new Vector3(vector.x, -vector.y, -vector.z)) && bounds.Contains(pos + rot * new Vector3(-vector.x, -vector.y, -vector.z)) && bounds.Contains(pos + rot * new Vector3(vector.x, -vector.y, vector.z)) && bounds.Contains(pos + rot * new Vector3(-vector.x, -vector.y, vector.z)); |
| return bounds.Contains(pos + rot * new Vector3(vector.x, vector.y, -vector.z)) && bounds.Contains(pos + rot * new Vector3(-vector.x, vector.y, -vector.z)) && bounds.Contains(pos + rot * new Vector3(vector.x, vector.y, vector.z)) && bounds.Contains(pos + rot * new Vector3(-vector.x, vector.y, vector.z)) && bounds.Contains(pos + rot * new Vector3(vector.x, -vector.y, -vector.z)) && bounds.Contains(pos + rot * new Vector3(-vector.x, -vector.y, -vector.z)) && bounds.Contains(pos + rot * new Vector3(vector.x, -vector.y, vector.z)) && bounds.Contains(pos + rot * new Vector3(-vector.x, -vector.y, vector.z)); |
| } |
| } |
| |
| |
| private bool TestCollision(Room room, Vector3 pos, Quaternion rot) |
| private bool TestCollision(Room room, Vector3 pos, Quaternion rot) |
| { |
| { |
| if (!this.IsInsideDungeon(room, pos, rot)) |
| if (!this.IsInsideDungeon(room, pos, rot)) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| this.m_colliderA.size = new Vector3((float)room.m_size.x - 0.1f, (float)room.m_size.y - 0.1f, (float)room.m_size.z - 0.1f); |
| this.m_colliderA.size = new Vector3((float)room.m_size.x - 0.1f, (float)room.m_size.y - 0.1f, (float)room.m_size.z - 0.1f); |
| foreach (Room room2 in DungeonGenerator.m_placedRooms) |
| foreach (Room room2 in DungeonGenerator.m_placedRooms) |
| { |
| { |
| this.m_colliderB.size = room2.m_size; |
| this.m_colliderB.size = room2.m_size; |
| Vector3 vector; |
| Vector3 vector; |
| float num; |
| float num; |
| if (Physics.ComputePenetration(this.m_colliderA, pos, rot, this.m_colliderB, room2.transform.position, room2.transform.rotation, out vector, out num)) |
| if (Physics.ComputePenetration(this.m_colliderA, pos, rot, this.m_colliderB, room2.transform.position, room2.transform.rotation, out vector, out num)) |
| { |
| { |
| return true; |
| return true; |
| } |
| } |
| } |
| } |
| return false; |
| return false; |
| } |
| } |
| |
| |
| private DungeonDB.RoomData GetRandomWeightedRoom(bool perimeterRoom) |
| private DungeonDB.RoomData GetRandomWeightedRoom(bool perimeterRoom) |
| { |
| { |
| DungeonGenerator.m_tempRooms.Clear(); |
| DungeonGenerator.m_tempRooms.Clear(); |
| float num = 0f; |
| float num = 0f; |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| { |
| { |
| if (!roomData.RoomInPrefab.m_entrance && !roomData.RoomInPrefab.m_endCap && !roomData.RoomInPrefab.m_divider && roomData.RoomInPrefab.m_perimeter == perimeterRoom) |
| if (!roomData.RoomInPrefab.m_entrance && !roomData.RoomInPrefab.m_endCap && !roomData.RoomInPrefab.m_divider && roomData.RoomInPrefab.m_perimeter == perimeterRoom) |
| { |
| { |
| num += roomData.RoomInPrefab.m_weight; |
| num += roomData.RoomInPrefab.m_weight; |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| } |
| } |
| } |
| } |
| if (DungeonGenerator.m_tempRooms.Count == 0) |
| if (DungeonGenerator.m_tempRooms.Count == 0) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| float num2 = UnityEngine.Random.Range(0f, num); |
| float num2 = UnityEngine.Random.Range(0f, num); |
| float num3 = 0f; |
| float num3 = 0f; |
| foreach (DungeonDB.RoomData roomData2 in DungeonGenerator.m_tempRooms) |
| foreach (DungeonDB.RoomData roomData2 in DungeonGenerator.m_tempRooms) |
| { |
| { |
| num3 += roomData2.RoomInPrefab.m_weight; |
| num3 += roomData2.RoomInPrefab.m_weight; |
| if (num2 <= num3) |
| if (num2 <= num3) |
| { |
| { |
| return roomData2; |
| return roomData2; |
| } |
| } |
| } |
| } |
| return DungeonGenerator.m_tempRooms[0]; |
| return DungeonGenerator.m_tempRooms[0]; |
| } |
| } |
| |
| |
| private DungeonDB.RoomData GetRandomWeightedRoom(RoomConnection connection) |
| private DungeonDB.RoomData GetRandomWeightedRoom(RoomConnection connection) |
| { |
| { |
| DungeonGenerator.m_tempRooms.Clear(); |
| DungeonGenerator.m_tempRooms.Clear(); |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| { |
| { |
| if (!roomData.RoomInPrefab.m_entrance && !roomData.RoomInPrefab.m_endCap && !roomData.RoomInPrefab.m_divider && (!connection || (roomData.RoomInPrefab.HaveConnection(connection) && connection.m_placeOrder >= roomData.RoomInPrefab.m_minPlaceOrder))) |
| if (!roomData.RoomInPrefab.m_entrance && !roomData.RoomInPrefab.m_endCap && !roomData.RoomInPrefab.m_divider && (!connection || (roomData.RoomInPrefab.HaveConnection(connection) && connection.m_placeOrder >= roomData.RoomInPrefab.m_minPlaceOrder))) |
| { |
| { |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| } |
| } |
| } |
| } |
| if (DungeonGenerator.m_tempRooms.Count == 0) |
| if (DungeonGenerator.m_tempRooms.Count == 0) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| return this.GetWeightedRoom(DungeonGenerator.m_tempRooms); |
| return this.GetWeightedRoom(DungeonGenerator.m_tempRooms); |
| } |
| } |
| |
| |
| private DungeonDB.RoomData GetWeightedRoom(List<DungeonDB.RoomData> rooms) |
| private DungeonDB.RoomData GetWeightedRoom(List<DungeonDB.RoomData> rooms) |
| { |
| { |
| float num = 0f; |
| float num = 0f; |
| foreach (DungeonDB.RoomData roomData in rooms) |
| foreach (DungeonDB.RoomData roomData in rooms) |
| { |
| { |
| num += roomData.RoomInPrefab.m_weight; |
| num += roomData.RoomInPrefab.m_weight; |
| } |
| } |
| float num2 = UnityEngine.Random.Range(0f, num); |
| float num2 = UnityEngine.Random.Range(0f, num); |
| float num3 = 0f; |
| float num3 = 0f; |
| foreach (DungeonDB.RoomData roomData2 in rooms) |
| foreach (DungeonDB.RoomData roomData2 in rooms) |
| { |
| { |
| num3 += roomData2.RoomInPrefab.m_weight; |
| num3 += roomData2.RoomInPrefab.m_weight; |
| if (num2 <= num3) |
| if (num2 <= num3) |
| { |
| { |
| return roomData2; |
| return roomData2; |
| } |
| } |
| } |
| } |
| return DungeonGenerator.m_tempRooms[0]; |
| return DungeonGenerator.m_tempRooms[0]; |
| } |
| } |
| |
| |
| private DungeonDB.RoomData GetRandomRoom(RoomConnection connection) |
| private DungeonDB.RoomData GetRandomRoom(RoomConnection connection) |
| { |
| { |
| DungeonGenerator.m_tempRooms.Clear(); |
| DungeonGenerator.m_tempRooms.Clear(); |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| { |
| { |
| if (!roomData.RoomInPrefab.m_entrance && !roomData.RoomInPrefab.m_endCap && !roomData.RoomInPrefab.m_divider && (!connection || (roomData.RoomInPrefab.HaveConnection(connection) && connection.m_placeOrder >= roomData.RoomInPrefab.m_minPlaceOrder))) |
| if (!roomData.RoomInPrefab.m_entrance && !roomData.RoomInPrefab.m_endCap && !roomData.RoomInPrefab.m_divider && (!connection || (roomData.RoomInPrefab.HaveConnection(connection) && connection.m_placeOrder >= roomData.RoomInPrefab.m_minPlaceOrder))) |
| { |
| { |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| } |
| } |
| } |
| } |
| if (DungeonGenerator.m_tempRooms.Count == 0) |
| if (DungeonGenerator.m_tempRooms.Count == 0) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| return DungeonGenerator.m_tempRooms[UnityEngine.Random.Range(0, DungeonGenerator.m_tempRooms.Count)]; |
| return DungeonGenerator.m_tempRooms[UnityEngine.Random.Range(0, DungeonGenerator.m_tempRooms.Count)]; |
| } |
| } |
| |
| |
| private RoomConnection GetOpenConnection() |
| private RoomConnection GetOpenConnection() |
| { |
| { |
| if (DungeonGenerator.m_openConnections.Count == 0) |
| if (DungeonGenerator.m_openConnections.Count == 0) |
| { |
| { |
| return null; |
| return null; |
| } |
| } |
| return DungeonGenerator.m_openConnections[UnityEngine.Random.Range(0, DungeonGenerator.m_openConnections.Count)]; |
| return DungeonGenerator.m_openConnections[UnityEngine.Random.Range(0, DungeonGenerator.m_openConnections.Count)]; |
| } |
| } |
| |
| |
| private DungeonDB.RoomData FindStartRoom() |
| private DungeonDB.RoomData FindStartRoom() |
| { |
| { |
| DungeonGenerator.m_tempRooms.Clear(); |
| DungeonGenerator.m_tempRooms.Clear(); |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| foreach (DungeonDB.RoomData roomData in DungeonGenerator.m_availableRooms) |
| { |
| { |
| if (roomData.RoomInPrefab.m_entrance) |
| if (roomData.RoomInPrefab.m_entrance) |
| { |
| { |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| DungeonGenerator.m_tempRooms.Add(roomData); |
| } |
| } |
| } |
| } |
| return DungeonGenerator.m_tempRooms[UnityEngine.Random.Range(0, DungeonGenerator.m_tempRooms.Count)]; |
| return DungeonGenerator.m_tempRooms[UnityEngine.Random.Range(0, DungeonGenerator.m_tempRooms.Count)]; |
| } |
| } |
| |
| |
| private bool CheckRequiredRooms() |
| private bool CheckRequiredRooms() |
| { |
| { |
| if (this.m_minRequiredRooms == 0 || this.m_requiredRooms.Count == 0) |
| if (this.m_minRequiredRooms == 0 || this.m_requiredRooms.Count == 0) |
| { |
| { |
| return false; |
| return false; |
| } |
| } |
| int num = 0; |
| int num = 0; |
| foreach (Room room in DungeonGenerator.m_placedRooms) |
| foreach (Room room in DungeonGenerator.m_placedRooms) |
| { |
| { |
| if (this.m_requiredRooms.Contains(room.gameObject.name)) |
| if (this.m_requiredRooms.Contains(room.gameObject.name)) |
| { |
| { |
| num++; |
| num++; |
| } |
| } |
| } |
| } |
| return num >= this.m_minRequiredRooms; |
| return num >= this.m_minRequiredRooms; |
| } |
| } |
| |
| |
| private void OnDrawGizmos() |
| private void OnDrawGizmos() |
| { |
| { |
| Gizmos.color = new Color(0f, 1.5f, 0f, 0.5f); |
| Gizmos.color = new Color(0f, 1.5f, 0f, 0.5f); |
| Gizmos.DrawWireCube(this.m_zoneCenter, new Vector3(this.m_zoneSize.x, this.m_zoneSize.y, this.m_zoneSize.z)); |
| Gizmos.DrawWireCube(this.m_zoneCenter, new Vector3(this.m_zoneSize.x, this.m_zoneSize.y, this.m_zoneSize.z)); |
| Gizmos.matrix = Matrix4x4.identity; |
| Gizmos.matrix = Matrix4x4.identity; |
| } |
| } |
| |
| |
| private static MemoryStream saveStream = new MemoryStream(); |
| private static MemoryStream saveStream = new MemoryStream(); |
| |
| |
| private static BinaryWriter saveWriter = new BinaryWriter(DungeonGenerator.saveStream); |
| private static BinaryWriter saveWriter = new BinaryWriter(DungeonGenerator.saveStream); |
| |
| |
| public static int m_forceSeed = int.MinValue; |
| public static int m_forceSeed = int.MinValue; |
| |
| |
| public DungeonGenerator.Algorithm m_algorithm; |
| public DungeonGenerator.Algorithm m_algorithm; |
| |
| |
| public int m_maxRooms = 3; |
| public int m_maxRooms = 3; |
| |
| |
| public int m_minRooms = 20; |
| public int m_minRooms = 20; |
| |
| |
| public int m_minRequiredRooms; |
| public int m_minRequiredRooms; |
| |
| |
| public List<string> m_requiredRooms = new List<string>(); |
| public List<string> m_requiredRooms = new List<string>(); |
| |
| |
| [global::Tooltip("Rooms and endcaps will be placed using weights.")] |
| [global::Tooltip("Rooms and endcaps will be placed using weights.")] |
| public bool m_alternativeFunctionality; |
| public bool m_alternativeFunctionality; |
| |
| |
| [BitMask(typeof(Room.Theme))] |
| [BitMask(typeof(Room.Theme))] |
| public Room.Theme m_themes = Room.Theme.Crypt; |
| public Room.Theme m_themes = Room.Theme.Crypt; |
| |
| |
| [Header("Dungeon")] |
| [Header("Dungeon")] |
| public List<DungeonGenerator.DoorDef> m_doorTypes = new List<DungeonGenerator.DoorDef>(); |
| public List<DungeonGenerator.DoorDef> m_doorTypes = new List<DungeonGenerator.DoorDef>(); |
| |
| |
| [Range(0f, 1f)] |
| [Range(0f, 1f)] |
| public float m_doorChance = 0.5f; |
| public float m_doorChance = 0.5f; |
| |
| |
| [Header("Camp")] |
| [Header("Camp")] |
| public float m_maxTilt = 10f; |
| public float m_maxTilt = 10f; |
| |
| |
| public float m_tileWidth = 8f; |
| public float m_tileWidth = 8f; |
| |
| |
| public int m_gridSize = 4; |
| public int m_gridSize = 4; |
| |
| |
| public float m_spawnChance = 1f; |
| public float m_spawnChance = 1f; |
| |
| |
| [Header("Camp radial")] |
| [Header("Camp radial")] |
| public float m_campRadiusMin = 15f; |
| public float m_campRadiusMin = 15f; |
| |
| |
| public float m_campRadiusMax = 30f; |
| public float m_campRadiusMax = 30f; |
| |
| |
| public float m_minAltitude = 1f; |
| public float m_minAltitude = 1f; |
| |
| |
| public int m_perimeterSections; |
| public int m_perimeterSections; |
| |
| |
| public float m_perimeterBuffer = 2f; |
| public float m_perimeterBuffer = 2f; |
| |
| |
| [Header("Misc")] |
| [Header("Misc")] |
| public Vector3 m_zoneCenter = new Vector3(0f, 0f, 0f); |
| public Vector3 m_zoneCenter = new Vector3(0f, 0f, 0f); |
| |
| |
| public Vector3 m_zoneSize = new Vector3(64f, 64f, 64f); |
| public Vector3 m_zoneSize = new Vector3(64f, 64f, 64f); |
| |
| |
| [global::Tooltip("Makes the dungeon entrance start at the given interior transform (including rotation) rather than straight above the entrance, which gives the dungeon much more room to fill out the entire zone. Must use together with Location.m_useCustomInteriorTransform to make sure seeds are deterministic.")] |
| [global::Tooltip("Makes the dungeon entrance start at the given interior transform (including rotation) rather than straight above the entrance, which gives the dungeon much more room to fill out the entire zone. Must use together with Location.m_useCustomInteriorTransform to make sure seeds are deterministic.")] |
| public bool m_useCustomInteriorTransform; |
| public bool m_useCustomInteriorTransform; |
| |
| |
| [HideInInspector] |
| [HideInInspector] |
| public int m_generatedSeed; |
| public int m_generatedSeed; |
| |
| |
| private bool m_hasGeneratedSeed; |
| private bool m_hasGeneratedSeed; |
| |
| |
| private ZDO m_zdoSetToBeLoadingInZone; |
| private ZDO m_zdoSetToBeLoadingInZone; |
| |
| |
| private int m_roomsToLoad; |
| private int m_roomsToLoad; |
| |
| |
| private DungeonGenerator.RoomPlacementData[] m_loadedRooms; |
| private DungeonGenerator.RoomPlacementData[] m_loadedRooms; |
| |
| |
| private List<IReferenceCounted> m_heldReferences = new List<IReferenceCounted>(); |
| private List<IReferenceCounted> m_heldReferences = new List<IReferenceCounted>(); |
| |
| |
| private static List<Room> m_placedRooms = new List<Room>(); |
| private static List<Room> m_placedRooms = new List<Room>(); |
| |
| |
| private static List<RoomConnection> m_openConnections = new List<RoomConnection>(); |
| private static List<RoomConnection> m_openConnections = new List<RoomConnection>(); |
| |
| |
| private static List<RoomConnection> m_doorConnections = new List<RoomConnection>(); |
| private static List<RoomConnection> m_doorConnections = new List<RoomConnection>(); |
| |
| |
| private static List<DungeonDB.RoomData> m_availableRooms = new List<DungeonDB.RoomData>(); |
| private static List<DungeonDB.RoomData> m_availableRooms = new List<DungeonDB.RoomData>(); |
| |
| |
| private static List<DungeonDB.RoomData> m_tempRooms = new List<DungeonDB.RoomData>(); |
| private static List<DungeonDB.RoomData> m_tempRooms = new List<DungeonDB.RoomData>(); |
| |
| |
| private BoxCollider m_colliderA; |
| private BoxCollider m_colliderA; |
| |
| |
| private BoxCollider m_colliderB; |
| private BoxCollider m_colliderB; |
| |
| |
| private ZNetView m_nview; |
| private ZNetView m_nview; |
| |
| |
| [HideInInspector] |
| [HideInInspector] |
| public Vector3 m_originalPosition; |
| public Vector3 m_originalPosition; |
| |
| |
| [Serializable] |
| [Serializable] |
| public class DoorDef |
| public class DoorDef |
| { |
| { |
| public GameObject m_prefab; |
| public GameObject m_prefab; |
| |
| |
| public string m_connectionType = ""; |
| public string m_connectionType = ""; |
| |
| |
| [global::Tooltip("Will use default door chance set in DungeonGenerator if set to zero to default to old behaviour")] |
| [global::Tooltip("Will use default door chance set in DungeonGenerator if set to zero to default to old behaviour")] |
| [Range(0f, 1f)] |
| [Range(0f, 1f)] |
| public float m_chance; |
| public float m_chance; |
| } |
| } |
| |
| |
| private struct RoomPlacementData |
| private struct RoomPlacementData |
| { |
| { |
| public RoomPlacementData(DungeonDB.RoomData roomData, Vector3 position, Quaternion rotation) |
| public RoomPlacementData(DungeonDB.RoomData roomData, Vector3 position, Quaternion rotation) |
| { |
| { |
| this.m_roomData = roomData; |
| this.m_roomData = roomData; |
| this.m_position = position; |
| this.m_position = position; |
| this.m_rotation = rotation; |
| this.m_rotation = rotation; |
| } |
| } |
| |
| |
| public DungeonDB.RoomData m_roomData; |
| public DungeonDB.RoomData m_roomData; |
| |
| |
| public Vector3 m_position; |
| public Vector3 m_position; |
| |
| |
| public Quaternion m_rotation; |
| public Quaternion m_rotation; |
| } |
| } |
| |
| |
| public enum Algorithm |
| public enum Algorithm |
| { |
| { |
| Dungeon, |
| Dungeon, |
| CampGrid, |
| CampGrid, |
| CampRadial |
| CampRadial |
| } |
| } |
| } |
| } |
| |
| |