void OnEnable() { if (config == null) { throw new NullReferenceException("MasterConfiguration is not set in GameManager"); } else if (config.roomConfiguration == null) { throw new NullReferenceException("MasterConfiguration exists, but has no RoomConfiguration"); } else if (config.roomConfiguration.FirstRoom == null) { throw new NullReferenceException("First room is null. Is GlobalGameData set up correctly?"); } var startingScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); var startingRoomDefinition = SceneToRoom(startingScene); _currentRoom = startingRoomDefinition; _currentRoomManager = FindObjectOfType(typeof(BaseRoomManager)) as BaseRoomManager; if (Camera.main != null && _currentRoomManager != null) { Camera.main.backgroundColor = _currentRoomManager.cameraClearColor; } }
//Called via GameManager when we begin loading a room scene public virtual void StartedLoadingRoom(RoomDefinition room) { if (onStartedLoadingRoom != null) { onStartedLoadingRoom.Invoke(); } }
//Helper method to determine whether we should use columns in this room. //Any column spawn checks can be put in this method. bool CanUseRoomColumns(RoomDefinition floorRoom) { //Room Type Checks if (floorRoom.roomType == NodeType.Puzzle) { return(false); } //Item Checks for (var i = 0; i < floorRoom.size; i++) { for (var j = 0; j < floorRoom.size; j++) { var itemType = (ItemTypes)floorRoom.itemGrid[i, j]; //Check for chasing robots since they will go right through columns; if (itemType == ItemTypes.RobotChasing) { return(false); } } } return(true); //all checks passed. we can use columns }
internal override RoomDefinition PlaceDoor(RoomDefinition room, int wallPosition, ModuleTypes doorModule, bool addGround) { switch (wallPosition) { case 1: room.SetModulePosition(1, 2, ModuleTypes.PlatformLarge); room.SetModulePosition(0, 2, doorModule); RemoveFromList(moduleSpaces, PositionToNumber(0, 2 - 1, innerSize)); break; case 3: room.SetModulePosition(2, 1, ModuleTypes.PlatformLarge); room.SetModulePosition(2, 0, doorModule); RemoveFromList(moduleSpaces, PositionToNumber(2 - 1, 0, innerSize)); break; case 2: room.SetModulePosition(2, size - 2, ModuleTypes.PlatformLarge); room.SetModulePosition(2, size - 1, doorModule); RemoveFromList(moduleSpaces, PositionToNumber(2 - 1, size - 3, innerSize)); break; case 0: room.SetModulePosition(size - 2, 2, ModuleTypes.PlatformLarge); room.SetModulePosition(size - 1, 2, doorModule); RemoveFromList(moduleSpaces, PositionToNumber(size - 3, 2 - 1, innerSize)); break; } return(room); }
//Called via GameManager when we are done loading a room scene public virtual void DoneLoadingRoom(RoomDefinition room) { if (onDoneLoadingRoom != null) { onDoneLoadingRoom.Invoke(); } }
private void OnSceneGUI() { RoomDefinition roomDefinition = target as RoomDefinition; DrawRoomDefinitionEditorSceneGUI(target as RoomDefinition); Repaint(); }
private void OnSceneGUI() { SpawnPoint spawnSet = target as SpawnPoint; RoomDefinition roomDefinition = spawnSet.GetComponentInParent <RoomDefinition>(); RoomDefinitionEditor.DrawRoomDefinitionEditorSceneGUI(roomDefinition); Repaint(); }
public List <RoomDefinition> LoadTemplates(string path) { List <RoomDefinition> templates = new List <RoomDefinition>(); string[] text; if (templateDict.ContainsKey(path)) { text = templateDict[path]; } else { var assetString = Resources.Load <TextAsset>(path).text; text = Helper.SplitLines(assetString); templateDict[path] = text; } var roomLinesRead = 0; RoomDefinition room = new RoomDefinition(0, NodeType.Any); for (int i = 0; i < text.Length; i++) { string line = text[i]; if (line == "") { room = MakeOuterModuleGrid(room, roomLinesRead + 2); room = SetDoors(room); templates.Add(room); roomLinesRead = 0; } else if (line.Length == 1) { } else { string[] blocks = line.Split(' '); if (roomLinesRead == 0) { int roomSize = blocks.Length; room = new RoomDefinition(roomSize + 2, NodeType.Any); } for (int j = 0; j < blocks.Length; j++) { room.moduleGrid[roomLinesRead + 1, j + 1] = (int)ModuleLookUp(blocks[j][0]); room.itemGrid[roomLinesRead + 1, j + 1] = (int)ItemLookUp(blocks[j][1]); } roomLinesRead += 1; } } return(templates); }
RoomSpecificElevatorAnimatorController CreateRoomSpecificAnimatorController(RoomDefinition room) { //no matter what's null, destroy the current controller RoomSpecificElevatorAnimatorController contr = null; if (roomSpecificAnimatorControllerTarget != null) { contr = roomSpecificAnimatorControllerTarget.GetComponent <RoomSpecificElevatorAnimatorController>(); } //if null room, error out if (room == null) { UnityEngine.Debug.LogError("Null room definition"); return(default(RoomSpecificElevatorAnimatorController)); } //if not room anim controller, error out if (room.roomSpecificElevatorAnimController == null) { UnityEngine.Debug.LogError("No room specific elevator animator controller"); return(default(RoomSpecificElevatorAnimatorController)); } else { //if the controller already exists and is of the same type as the current room, just return it if (contr != null && contr.GetType() == room.roomSpecificElevatorAnimController.GetType()) { return(contr); } } //destroy the old controller if (contr != null) { Component.Destroy(contr); } if (roomSpecificAnimatorControllerTarget != null) { roomSpecificAnimatorControllerTarget.GetOrAddComponent <Animator>(); //add a new controller component of the proper type contr = roomSpecificAnimatorControllerTarget.gameObject.AddComponent(room.roomSpecificElevatorAnimController.GetType()) as RoomSpecificElevatorAnimatorController; //initialize the controller with the prefab values, since we didn't instantiate from prefab exactly, but rather just created a new component contr.Initialize(room.roomSpecificElevatorAnimController); return(contr); } else { return(null); } }
public static float CalculateAverageTreatmentChance(this Patient patient, RoomDefinition roomDef) { if (roomDef == null) { return(0); } Level level = patient.Level; level.WorldState.GetRoomsOfType(roomDef._type, false, _roomsCache); int count = 0; float chanceOfSuccess = 0; foreach (Room room in _roomsCache) { if (room.WhoCanUse.IsMember(patient) && room.IsFunctional()) { try { var staff = room.AssignedStaff.FirstOrDefault(x => x.Definition._type == StaffDefinition.Type.Doctor); staff = staff ?? room.AssignedStaff.FirstOrDefault(x => x.Definition._type == StaffDefinition.Type.Nurse); if (staff == null || staff.Definition._type == StaffDefinition.Type.Nurse && !room.RequiredStaffAssigned()) { var leaveHistory = Room_StaffLeaveRoom_Patch.leaveHistory; for (int i = leaveHistory.Count - 1; i >= 0; i--) { if (leaveHistory.ElementAt(i).roomId == room.ID) { staff = patient.Level.CharacterManager.StaffMembers.Find(x => x.ID == leaveHistory.ElementAt(i).staffId); if (staff != null) { break; } } } } var breakdown = GameAlgorithms.CalculateEstimatedTreatmentOutcome(patient, staff, room); chanceOfSuccess += breakdown.ChanceOfSuccess; count++; } catch (Exception e) { Main.Logger.Error(e.ToString()); } } } _roomsCache.Clear(); return(count > 0 ? chanceOfSuccess / count : 0); }
public void LoadRoom(RoomDefinition room) { UnityEngine.Debug.Log("LoadRoom: " + (room != null ? room.name : "NULL")); if (room == null) { throw new ArgumentNullException("room"); } if (string.IsNullOrEmpty(room.scenePath)) { throw new ArgumentException("room must have a non-null path"); } _previousRoomManager = _currentRoomManager; _currentRoomManager = null; StartCoroutine(_LoadRoom_Inner(room)); }
public static void TransitionToCopyRoomBlueprintState(this BuildingLogic __instance, Room room, Level level) { RoomDefinition definition = room.Definition; //var NewRoomState = typeof(BuildingLogic).GetNestedType("NewRoomState", AccessTools.all); var _newRoomState = Traverse.Create(__instance).Field("_newRoomState").GetValue(); var LeaveCurrentState = Traverse.Create(__instance).Method("LeaveCurrentState", new Type[] { typeof(bool) }).GetValue(false); var BlueprintFloorPlan = new BlueprintFloorPlan(room.FloorPlan) { AutoFlowActive = true }; Traverse.Create(_newRoomState).Field("BlueprintFloorPlan").SetValue(BlueprintFloorPlan); var BlueprintFloorPlanVisual = new BlueprintFloorPlanVisual(level.WorldState, level.VisualManager, level.DataViewManager, __instance.Configuration.RoomItemEditConfig, level.BuildEvents, "Blueprint", __instance.Configuration.BlueprintFloorTilePrefab, definition._blueprintWallDefinition.Instance, __instance.Configuration.BlueprintFloorMaterialValid, __instance.Configuration.BlueprintFloorMaterialInvalid, __instance.Configuration.BlueprintFloorMaterialInvalidSize); Traverse.Create(_newRoomState).Field("BlueprintFloorPlanVisual").SetValue(BlueprintFloorPlanVisual); Traverse.Create(__instance).Field("_newRoomState").SetValue(_newRoomState); level.BuildEvents.OnBeginNewRoom.InvokeSafe(definition); level.CursorManager.PopMode <CursorRoomBuild>(); level.CursorManager.PushMode(new CursorRoomBuild(level.CursorManager, level, level.Config.GetCursorRoomBuildConfig(), BlueprintFloorPlan, BlueprintFloorPlanVisual)); level.CursorManager.PushMode(new CursorRoomMove(level.CursorManager, level, level.WorldState, level.BuildEvents, BlueprintFloorPlan, BlueprintFloorPlanVisual, false)); Traverse.Create(__instance).Field("_currentState").SetValue(BuildingLogic.State.NewRoom); level.BuildEvents.OnEnterNewRoomState.InvokeSafe(BlueprintFloorPlan, BlueprintFloorPlanVisual); level.HospitalHUDManager.ShowItemsList(definition._type, BlueprintFloorPlan, false); level.HospitalHUDManager.TryShowBuildBar(); foreach (var item in __instance.CurrentBlueprintFloorPlan.Items) { if (item.UpgradeLevel > 0) { Traverse.Create(item).Field("_upgradeLevel").SetValue(0); } if (item.MaintenanceLevel != null && item.MaintenanceLevel.Value() > 0) { item.MaintenanceLevel.SetValue(0, false); } } }
public void ResetRoom(RoomDefinition floorRoom) { room = floorRoom; roomTheme = floorRoom.visualTheme; DestroyModules(); for (var i = 0; i < room.size; i++) { for (var j = 0; j < room.size; j++) { if (i > 0 && j > 0 && i < room.size - 1 && j < room.size - 1) { InitializeScenery(i, j); } InitializeModule(i, j); InitializeItem(i, j); } } }
public static void DrawRoomDefinitionEditorSceneGUI(RoomDefinition roomDefinition) { Handles.BeginGUI(); { scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Width(250), GUILayout.Height(500)); { foreach (var spawnSet in roomDefinition.GetComponentsInChildren <SpawnSet>()) { EditorGUICustomUtility.DrawSelectableNameField(0, spawnSet.gameObject, "Edit Spawn Set"); spawnSet.weight = EditorGUILayout.FloatField("Weight", spawnSet.weight); foreach (var spawnPoint in spawnSet.GetComponentsInChildren <SpawnPoint>()) { EditorGUICustomUtility.DrawSelectableNameField(20, spawnPoint.gameObject, "Edit Spawn Point"); } GUILayout.BeginHorizontal(); { GUILayout.Space(20); if (GUILayout.Button("Add Spawn Point")) { var spawnPoint = GameObjectFactory.Create("SpawnPoint", Vector3.zero, Quaternion.identity, spawnSet.transform); spawnPoint.AddComponent <SpawnPoint>(); Undo.RegisterCreatedObjectUndo(spawnPoint, "Create Spawn Point"); } } GUILayout.EndHorizontal(); } if (GUILayout.Button("Create new Spawn Set")) { var spawnSet = GameObjectFactory.Create("SpawnSet", Vector3.zero, Quaternion.identity, roomDefinition.transform); spawnSet.AddComponent <SpawnSet>(); Undo.RegisterCreatedObjectUndo(spawnSet, "Create Spawn Set"); } } EditorGUILayout.EndScrollView(); } Handles.EndGUI(); }
internal override RoomDefinition GenerateRoom(int targetDifficulty, int roomSize, Cell roomCell) { roomType = roomCell.node.type; doors = roomCell.doorTypes; difficulty = targetDifficulty; defaultModule = SetDefaultModule(); size = roomSize; innerSize = size - 2; workingRoom = new RoomDefinition(size, roomCell.node.type); moduleSpaces = Enumerable.Range(0, innerSize * innerSize).ToList(); if (roomType == NodeType.Key) { itemSpaces = Enumerable.Range(0, innerSize * innerSize).ToList(); } else { itemSpaces.Clear(); } workingRoom = SetDoors(workingRoom); SetModuleGridRandom(); SetItemGridRandom(); return(workingRoom); }
//Get the next room in the rooms array. If currentRoom is null, returns the first value public RoomDefinition GetNextRoom(RoomDefinition currentRoom) { if (rooms != null && rooms.Length > 0) { if (currentRoom == null) { return(rooms[0]); } else { for (int i = 0; i < rooms.Length; ++i) { if (rooms[i] == currentRoom && i < (rooms.Length - 1)) { return(rooms[i + 1]); } } } } return(rooms != null && rooms.Length > 0 ? rooms[0] : default(RoomDefinition)); }
public static RoomDefinition MakeOuterModuleGrid(RoomDefinition room, int totalSize) { for (var i = 0; i < totalSize; i++) { for (var j = 0; j < totalSize; j++) { // Create corner. if (i == 0 && j == 0 || i == 0 && j == totalSize - 1 || i == totalSize - 1 && j == 0 || i == totalSize - 1 && j == totalSize - 1) { room.SetModulePosition(i, j, ModuleTypes.WallCorner); } // Check for edge and create wall. else if ((i == 0 || i == totalSize - 1 || j == 0 || j == totalSize - 1) && (int)room.GetModuleType(i, j) == 0) { room.SetModulePosition(i, j, ModuleTypes.WallWindow); } } } return(room); }
// Start is called before the first frame update public void InitializeRoomGen() { room = new RoomDefinition(MinWidth, MaxWidth, MinHeight, MaxHeight); }
internal RoomDefinition SetDoors(RoomDefinition room) { bool placedSpecialDoor = false; for (int i = 0; i < doors.Length; i++) { var doorType = doors[i]; ModuleTypes doorModule; switch (doorType) { case DoorType.Open: doorModule = ModuleTypes.DoorBetween; break; case DoorType.KeyLock: doorModule = ModuleTypes.DoorLocked; break; case DoorType.LeverLock: doorModule = ModuleTypes.DoorLever; break; case DoorType.OneWay: doorModule = ModuleTypes.DoorOneWay; break; case DoorType.PuzzleLock: doorModule = ModuleTypes.DoorPuzzle; break; default: doorModule = ModuleTypes.Wall; if (!placedSpecialDoor) { if (roomType == NodeType.Start && doorType == 0) { doorModule = ModuleTypes.DoorEntrance; placedSpecialDoor = true; } if (roomType == NodeType.End && doorType == 0) { doorModule = ModuleTypes.DoorExit; placedSpecialDoor = true; } if (roomType == NodeType.Basement && doorType == DoorType.Start) { doorModule = ModuleTypes.DoorEntrance; } if (roomType == NodeType.Basement && doorType == DoorType.Exit) { doorModule = ModuleTypes.DoorExit; } } break; } if (doorModule != ModuleTypes.Wall) { room = PlaceDoor(room, i, doorModule, true); } } return(room); }
internal virtual RoomDefinition PlaceDoor(RoomDefinition room, int wallPosition, ModuleTypes doorModule, bool addGround) { var doorPosition = 2; if (room.size == 7) { doorPosition = 3; } switch (wallPosition) { case 1: if (addGround) { room.SetModulePosition(1, doorPosition, ModuleTypes.PlatformLarge); } for (int i = 1; i < size - 1; i++) { room.SetModulePosition(0, i, ModuleTypes.Wall); } room.SetModulePosition(0, doorPosition, doorModule); break; case 3: if (addGround) { room.SetModulePosition(doorPosition, 1, ModuleTypes.PlatformLarge); } for (int i = 1; i < size - 1; i++) { room.SetModulePosition(i, 0, ModuleTypes.Wall); } room.SetModulePosition(doorPosition, 0, doorModule); break; case 2: if (addGround) { room.SetModulePosition(doorPosition, size - 2, ModuleTypes.PlatformLarge); } for (int i = 1; i < size - 1; i++) { room.SetModulePosition(i, size - 1, ModuleTypes.Wall); } room.SetModulePosition(doorPosition, size - 1, doorModule); break; case 0: if (addGround) { room.SetModulePosition(size - 2, doorPosition, ModuleTypes.PlatformLarge); } for (int i = 1; i < size - 1; i++) { room.SetModulePosition(size - 1, i, ModuleTypes.Wall); } room.SetModulePosition(size - 1, doorPosition, doorModule); break; } return(room); }
IEnumerator _LoadRoom_Inner(RoomDefinition room) { var previousScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); //get the lighting settings for the current scene _previousLightingSettings = RoomLightingSettings.CreateFromCurrentRoom(); var loadOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(room.scenePath, UnityEngine.SceneManagement.LoadSceneMode.Additive); while (!loadOperation.isDone) { yield return(new WaitForEndOfFrame()); } //HACK-ish: do not break the "Assets/.../*.unity" convention for scenes // For whatever reason, the naming is very particular for GetSceneByPath() var nextScene = UnityEngine.SceneManagement.SceneManager.GetSceneByPath("Assets/" + room.scenePath + ".unity"); if (nextScene.IsValid()) { _hasTransitionedLightingForCurrentRoom = false; UnityEngine.SceneManagement.SceneManager.SetActiveScene(nextScene); //get the lighting settings for the current room _currentLightingSettings = RoomLightingSettings.CreateFromCurrentRoom(); RoomLightingSettings.Set(_previousLightingSettings, null); } else { _currentLightingSettings = _previousLightingSettings; } var allRoomManagers = FindObjectsOfType(typeof(BaseRoomManager)); foreach (var obj in allRoomManagers) { if (obj != null && (obj is BaseRoomManager)) { var man = (obj as BaseRoomManager); if (man != null && man.gameObject.scene.IsValid()) { if (man.gameObject.scene == nextScene) { _currentRoomManager = man; } else if (man.gameObject.scene == previousScene) { _previousRoomManager = man; } } } } _currentRoom = room; if (_previousRoomManager != null && _currentRoomManager != null) { float originalRoomYPosition = _currentRoomManager.transform.position.y; _currentRoomManager.transform.position = Vector3.up * (_previousRoomManager.topPlane.transform.position.y + (_currentRoomManager.transform.position.y - _currentRoomManager.bottomPlane.transform.position.y)); if (originalRoomYPosition != _currentRoomManager.transform.position.y) { UnityEngine.Debug.LogWarning("The Y-position for (" + _currentRoomManager.GetType().Name + ") does not correspond to its position as saved in the scene asset. The scene-manager will be moved, but objects marked as static may break."); } } }