private static DoorNode GetDoorNodeFromLevel(LevelMap map, string levelName, int id) { int levelIndex = Main.GetLevelIdFromName(levelName); LevelNode levelNode = map.GetNodeFromIndex(levelIndex) as LevelNode; if (id >= levelNode.doors.Count) { id = 0; } int targetIndex = levelNode.doors[id]; DoorNode result = map.GetNodeFromIndex(targetIndex) as DoorNode; return(result); }
public static bool Prefix(DoorNode __instance, DoorNode ___targetNode, LevelMap ___map, ref DoorNode __result) { LevelNode parent = __instance.GetParent(); if (parent.Label == Main.StartingLevel) { string levelString = Main.GetNextLevel(parent.Label); __result = GetDoorNodeFromLevel(___map, levelString, 0); } else if (parent.Label == Main.EndingLevel) { string levelString = Main.GetPrevLevel(parent.Label); __result = GetDoorNodeFromLevel(___map, levelString, 1); } else if (Main.IsPuzzleLevel(parent)) { int id = parent.GetDoorID(__instance); string levelString; switch (id) { case 0: levelString = Main.GetPrevLevel(parent.Label); __result = GetDoorNodeFromLevel(___map, levelString, 1); break; case 1: levelString = Main.GetNextLevel(parent.Label); __result = GetDoorNodeFromLevel(___map, levelString, 0); break; default: __result = ___targetNode; break; } } else { __result = ___targetNode; } return(false); }
private DoorNode[] TryExpand(DoorNode node) { for (var i = 0; i < 10; i++) { var roomPrefab = RandomRoomPrefab(); if (node.isCorridor && roomPrefab.IsCorridor) { continue; } var doorwayIndex = Random.Range(0, roomPrefab.Doorways.Length); var doorway = roomPrefab.Doorways[doorwayIndex]; var targetRotation = node.doorway.transform.eulerAngles.y + 180; var currentRotation = doorway.transform.eulerAngles.y; var rotation = Quaternion.Euler(0, targetRotation - currentRotation, 0); var doorwayToOrigin = transform.position - doorway.transform.position; var origin = node.doorway.transform.position + rotation * doorwayToOrigin; var size = Physics.BoxCastNonAlloc(origin + rotation * roomPrefab.Bounds.center, roomPrefab.Bounds.extents, -node.doorway.transform.forward, new RaycastHit[1], rotation); if (size > 0) { continue; } node.doorway.SetActive(); var room = Instantiate(roomPrefab, origin, rotation); room.SetParentDoorway(doorwayIndex); return(room.GetNodes()); } return(null); }