public override uint GetNextRoomByExit(RoomExit exit) { switch (exit) { case RoomExit.North: return(0); case RoomExit.South: return(0); case RoomExit.East: return(0); case RoomExit.West: return(0); default: return(0); } }
/// <summary> /// Scans through all of the instantiated rooms and find the RoomExit that contains the specified roomConnector. /// </summary> /// <param name="exitToFind"></param> /// <returns></returns> public RoomExit FindRoomExit(RoomConnector exitToFind) { RoomExit exit = null; foreach (var roomObj in GameObject.FindGameObjectsWithTag("RoomInstance")) { foreach (var roomExit in roomObj.GetComponent <Room>().GetRoomExits()) { if (roomExit.GetExit().Equals(exitToFind)) { exit = roomExit; break; } } } return(exit); }
public override void Execute(Match match, string pattern) { Group g_cmd = match.Groups["cmd"]; Group g_what = match.Groups["what"]; if (g_what.Success) { string whatToEnter = g_what.Value; // The search algo List <RoomExit> exits = FindItems <RoomExit>(whatToEnter, e => e.NextRoom.Name); if (exits.Count == 1) { RoomExit exit = exits[0]; CommandExit.ExitThroughDoor(exit); } else if (exits.Count > 1) { string joinedString = exits.Select(e => e.NextRoom.Name).ToArray().Join(", ", ", or ", " or "); Console.ForegroundColor = Colors.ErrorColor; ConsoleHelper.WriteLineWrap("Couldn't distinguish between {0}.", joinedString); } else { if (!TryFindItem(whatToEnter, out BaseItem item)) { return; } CommandExit.ExitThroughDoor(item); } } else { Console.ForegroundColor = Colors.ErrorColor; string cmd = g_cmd.Value.ToLower(); if (cmd.StartsWith("go")) { ConsoleHelper.WriteLineWrap("Go to what?"); } ConsoleHelper.WriteLineWrap("{0} what?", cmd.ToFirstUpper()); } }
void SpawnExitRoom(Floor floor) { exitRoom = Instantiate(roomExitPrefab) as RoomExit; exitRoom.transform.parent = floor.transform; List <Doorway> availableDoorsInFloor = new List <Doorway>(floor.doorways); Doorway exitDoor = exitRoom.doorways[0]; bool roomIsSafeToSpawn = false; exitRoom.GetComponentInChildren <MeshCombiner>().AdvancedMerge(); exitRoom.GetComponent <RoomExit>().meshCol = exitRoom.transform.GetChild(0).GetComponent <MeshCollider>(); foreach (Doorway availableDoorway in availableDoorsInFloor) { Room room = exitRoom; OrientRoomToDoorway(ref room, exitDoor, availableDoorway); if (CheckRoomOverlap(exitRoom)) { continue; } roomIsSafeToSpawn = true; floor.rooms.Add(exitRoom); exitRoom.floorNumber = floor.floorNumber; floor.doorways.Remove(exitDoor); floor.doorways.Remove(availableDoorway); availableDoorway.gameObject.SetActive(false); exitDoor.openable = true; break; } if (!roomIsSafeToSpawn) { Destroy(exitRoom.gameObject); ResetLevelGeneration(); } }
public void OpenDoors() { foreach (Door d in doors) { if (d) { d.Open(); } } foreach (GameObject go in spawnPlayer) { RoomExit temp = go.GetComponent <RoomExit>(); if (temp) { temp.EnableExit(true); } } }
public override void Execute(Session session, CommandContext context) { if (context.Arguments.Count == 0) { session.WriteLine("Close what?"); return; } Room room = Server.Current.Database.Get <Room>(session.Player.Location); string exitToFind = context.Arguments[0].ToLower(); var exit = room.FindExitByPartialName(exitToFind); if (exit == null || !exit.IsDoor) { session.WriteLine("Theres nothing to close..."); return; } if (!exit.IsOpen) { session.WriteLine("The door is already closed"); return; } exit.IsOpen = false; session.Player.Send("You close the door.", session.Player); room.SendPlayers("%d closes a door.", session.Player, null, session.Player); // Now update the linked room var linkedRoom = Server.Current.Database.Get <Room>(exit.LeadsTo); if (linkedRoom == null) { return; } RoomExit linkedExit = linkedRoom.FindExitByLinkedRoom(room.Key); if (linkedExit == null || !linkedExit.IsDoor || !linkedExit.IsOpen) { return; } linkedExit.IsOpen = false; linkedRoom.SendPlayers("A door closes.", null, null); }
IEnumerator ShowTransfer(Transform from, Transform to, float transferDuration, float waitAtEndDuration) { transferParticles.transform.position = from.position; transferParticles.Play(); float startTime = Time.time; float endTime = startTime + transferDuration; yield return(null); while (Time.time < endTime) { float t = Mathf.InverseLerp(startTime, endTime, Time.time); transferParticles.transform.position = Vector3.Lerp(from.position, to.position, t); yield return(null); } currentBody.DoPossess(this); stopUpdates = false; if (currentBody != realBody) { transferDisplayCoroutine = null; yield break; } startTime = endTime; endTime = startTime + waitAtEndDuration; while (Time.time < endTime) { transferParticles.transform.position = to.position; yield return(null); } transferParticles.Stop(); transferDisplayCoroutine = null; RoomExit.CheckForExit(currentBody); }
private void PopulateExits(DungeonBuilder.Node n, GameObject g, DungeonBuilder db) { GameObject[] verticalPathOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/PathVertical"); GameObject[] horizontalPathOptions = Resources.LoadAll <GameObject>(RoomPath + Tileset + "/PathHorizontal"); List <RoomExit> roomExitPoints = g.GetComponentsInChildren <RoomExit>().ToList(); Tuple <int, int> positionOfNode = db.nodePositions[n.spawnIndex]; if (db.nodePositions.Any(no => n.Connections.Any(k => k.spawnIndex == no.Key) && no.Value.Equals(new Tuple <int, int>(positionOfNode.Item1 - 1, positionOfNode.Item2)))) { RoomExit exit = roomExitPoints.OrderBy(r => r.transform.localPosition.x).First(); exit.activateTile = true; for (int i = (int)exit.transform.localPosition.x - 1; i >= -distanceBetweenNodes / 2; i--) { GameObject p = Instantiate(horizontalPathOptions[Random.Range(0, horizontalPathOptions.Length)]); objectsToDestroy.Add(p); p.transform.parent = g.transform; p.transform.localPosition = Vector3.zero + Vector3.right * i + Vector3.up * exit.transform.localPosition.y; } if (n.nodeType == DungeonBuilder.NodeType.Boss && n.Connections.Any(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure)) { int endNode = n.Connections.First(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure).spawnIndex; if (db.nodePositions[endNode].Equals(new Tuple <int, int>(positionOfNode.Item1 - 1, positionOfNode.Item2))) { exit.activateTile = false; exit.gameObject.AddComponent <PostBossItemTakey>(); BossEnemy boss = g.GetComponentInChildren <BossEnemy>(); if (boss != null) { boss.bossExit = exit; } } } } if (db.nodePositions.Any(no => n.Connections.Any(k => k.spawnIndex == no.Key) && no.Value.Equals(new Tuple <int, int>(positionOfNode.Item1 + 1, positionOfNode.Item2)))) { RoomExit exit = roomExitPoints.OrderBy(r => r.transform.localPosition.x).Last(); exit.activateTile = true; for (int i = (int)exit.transform.localPosition.x + 1; i <= distanceBetweenNodes / 2; i++) { GameObject p = Instantiate(horizontalPathOptions[Random.Range(0, horizontalPathOptions.Length)]); objectsToDestroy.Add(p); p.transform.parent = g.transform; p.transform.localPosition = Vector3.zero + Vector3.right * i + Vector3.up * exit.transform.localPosition.y; } if (n.nodeType == DungeonBuilder.NodeType.Boss && n.Connections.Any(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure)) { int endNode = n.Connections.First(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure).spawnIndex; if (db.nodePositions[endNode].Equals(new Tuple <int, int>(positionOfNode.Item1 + 1, positionOfNode.Item2))) { exit.activateTile = false; exit.gameObject.AddComponent <PostBossItemTakey>(); BossEnemy boss = g.GetComponentInChildren <BossEnemy>(); if (boss != null) { boss.bossExit = exit; } } } } if (db.nodePositions.Any(no => n.Connections.Any(k => k.spawnIndex == no.Key) && no.Value.Equals(new Tuple <int, int>(positionOfNode.Item1, positionOfNode.Item2 - 1)))) { RoomExit exit = roomExitPoints.OrderBy(r => r.transform.localPosition.y).First(); exit.activateTile = true; for (int i = (int)exit.transform.localPosition.y - 1; i >= -distanceBetweenNodes / 2; i--) { GameObject p = Instantiate(verticalPathOptions[Random.Range(0, verticalPathOptions.Length)]); objectsToDestroy.Add(p); p.transform.parent = g.transform; p.transform.localPosition = Vector3.zero + Vector3.up * i + Vector3.right * exit.transform.localPosition.x; } if (n.nodeType == DungeonBuilder.NodeType.Boss && n.Connections.Any(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure)) { int endNode = n.Connections.First(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure).spawnIndex; if (db.nodePositions[endNode].Equals(new Tuple <int, int>(positionOfNode.Item1, positionOfNode.Item2 - 1))) { exit.activateTile = false; exit.gameObject.AddComponent <PostBossItemTakey>(); BossEnemy boss = g.GetComponentInChildren <BossEnemy>(); if (boss != null) { boss.bossExit = exit; } } } } if (db.nodePositions.Any(no => n.Connections.Any(k => k.spawnIndex == no.Key) && no.Value.Equals(new Tuple <int, int>(positionOfNode.Item1, positionOfNode.Item2 + 1)))) { RoomExit exit = roomExitPoints.OrderBy(r => r.transform.localPosition.y).Last(); exit.activateTile = true; for (int i = (int)exit.transform.localPosition.y + 1; i <= distanceBetweenNodes / 2; i++) { GameObject p = Instantiate(verticalPathOptions[Random.Range(0, verticalPathOptions.Length)]); objectsToDestroy.Add(p); p.transform.parent = g.transform; p.transform.localPosition = Vector3.zero + Vector3.up * i + Vector3.right * exit.transform.localPosition.x; } if (n.nodeType == DungeonBuilder.NodeType.Boss && n.Connections.Any(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure)) { int endNode = n.Connections.First(no => no.nodeType == DungeonBuilder.NodeType.EndTreasure).spawnIndex; if (db.nodePositions[endNode].Equals(new Tuple <int, int>(positionOfNode.Item1, positionOfNode.Item2 + 1))) { exit.activateTile = false; exit.gameObject.AddComponent <PostBossItemTakey>(); BossEnemy boss = g.GetComponentInChildren <BossEnemy>(); if (boss != null) { boss.bossExit = exit; } } } } }
protected override bool Build() { InitRooms(); int distance; var retry = 0; do { if (retry++ > 10) { return(false); } var innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomEntrance = Random.Element(Rooms); } while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4); innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomExit = Random.Element(Rooms); }while (RoomExit == RoomEntrance || RoomExit.Width() < 7 || RoomExit.Height() < 7 || RoomExit.Top == 0); Graph.BuildDistanceMap(Rooms, RoomExit); distance = Graph.BuildPath(Rooms, RoomEntrance, RoomExit).Count; } while (distance < 3); RoomEntrance.type = RoomType.ENTRANCE; RoomExit.type = RoomType.BOSS_EXIT; var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); Graph.SetPrice(path, RoomEntrance.distance); Graph.BuildDistanceMap(Rooms, RoomExit); path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); _anteroom = path[path.Count - 2]; _anteroom.type = RoomType.STANDARD; var room = RoomEntrance; foreach (var next in path) { room.Connect(next); room = next; } foreach (var room1 in Rooms.Where(room1 => room1.type == RoomType.NULL && room1.Connected.Count > 0)) { room1.type = RoomType.PASSAGE; } Paint(); var r = RoomExit.Connected.Keys.ToArray()[0]; if (RoomExit.Connected[r].Y == RoomExit.Top) { return(false); } PaintWater(); PaintGrass(); PlaceTraps(); return(true); }
protected internal override void Decorate() { for (var i = Width + 1; i < Length - Width - 1; i++) { if (map[i] != Terrain.EMPTY) { continue; } var c = 0.15f; if (map[i + 1] == Terrain.WALL && map[i + Width] == Terrain.WALL) { c += 0.2f; } if (map[i - 1] == Terrain.WALL && map[i + Width] == Terrain.WALL) { c += 0.2f; } if (map[i + 1] == Terrain.WALL && map[i - Width] == Terrain.WALL) { c += 0.2f; } if (map[i - 1] == Terrain.WALL && map[i - Width] == Terrain.WALL) { c += 0.2f; } if (Random.Float() < c) { map[i] = Terrain.EMPTY_DECO; } } for (var i = 0; i < Width; i++) { if (map[i] == Terrain.WALL && (map[i + Width] == Terrain.EMPTY || map[i + Width] == Terrain.EMPTY_SP) && Random.Int(4) == 0) { map[i] = Terrain.WALL_DECO; } } for (var i = Width; i < Length - Width; i++) { if (map[i] == Terrain.WALL && map[i - Width] == Terrain.WALL && (map[i + Width] == Terrain.EMPTY || map[i + Width] == Terrain.EMPTY_SP) && Random.Int(2) == 0) { map[i] = Terrain.WALL_DECO; } } while (true) { var pos = RoomEntrance.Random(); if (pos == entrance) { continue; } map[pos] = Terrain.SIGN; break; } var door = RoomExit.Entrance(); _arenaDoor = door.X + door.Y * Width; Painter.Set(this, _arenaDoor, Terrain.LOCKED_DOOR); Painter.Fill(this, RoomExit.Left + 2, RoomExit.Top + 2, RoomExit.Width() - 3, RoomExit.Height() - 3, Terrain.INACTIVE_TRAP); }
public static void StartLevel(int cantidad) { actualRooms = new List <Room>(); List <Vector2> actualVectors; if (Program.ObteJuego().level > 5) { double prob = CustomMath.RandomUnit(); if (prob < 95d / 300d) { actualVectors = GenerateLevelVersion2(cantidad); } else if (prob < 190d / 300d) { actualVectors = GenerateLevel(cantidad); } else if (prob < 285d / 300d) { actualVectors = GenerateLevelVersion3(cantidad); } else { actualVectors = GenerateLevelVersion4(cantidad); } } else { actualVectors = GenerateLevel(cantidad); } for (int i = 0; i < actualVectors.Count; i++) { actualRooms.Add(new Room(actualVectors[i].x, actualVectors[i].y)); } //First Room is visible actualRooms[0].SetVisible(2); //SET DOORS for (int i = 0; i < actualRooms.Count; i++) { if (!(actualRooms[i].GetNorthRoom() != null && actualRooms[i].GetWestRoom() != null && actualRooms[i].GetSouthRoom() != null && actualRooms[i].GetEastRoom() != null)) { for (int j = i + 1; j < actualRooms.Count; j++) { if (actualRooms[i].GetNorthRoom() == null) { if (actualRooms[i].GetPosX() == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() + 1 == actualRooms[j].GetPosY()) { actualRooms[i].SetNorth(actualRooms[j]); actualRooms[j].SetSouth(actualRooms[i]); } } if (actualRooms[i].GetWestRoom() == null) { if (actualRooms[i].GetPosX() - 1 == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() == actualRooms[j].GetPosY()) { actualRooms[i].SetWest(actualRooms[j]); actualRooms[j].SetEast(actualRooms[i]); } } if (actualRooms[i].GetSouthRoom() == null) { if (actualRooms[i].GetPosX() == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() - 1 == actualRooms[j].GetPosY()) { actualRooms[i].SetSouth(actualRooms[j]); actualRooms[j].SetNorth(actualRooms[i]); } } if (actualRooms[i].GetEastRoom() == null) { if (actualRooms[i].GetPosX() + 1 == actualRooms[j].GetPosX() && actualRooms[i].GetPosY() == actualRooms[j].GetPosY()) { actualRooms[i].SetEast(actualRooms[j]); actualRooms[j].SetWest(actualRooms[i]); } } if (actualRooms[i].GetNorthRoom() != null && actualRooms[i].GetWestRoom() != null && actualRooms[i].GetSouthRoom() != null && actualRooms[i].GetEastRoom() != null) { j = actualRooms.Count; } } } } /*--------------------------------------Crear salas especiales------------------------------------------*/ List <Room> exitRooms = new List <Room>(); /*se usa para la cantidad de puertas que debe tener una sala*/ int temp = 3; do { for (int i = 1; i < actualRooms.Count; i++) { int noDoors = 0; if (actualRooms[i].GetEastRoom() == null) { noDoors++; } if (actualRooms[i].GetWestRoom() == null) { noDoors++; } if (actualRooms[i].GetNorthRoom() == null) { noDoors++; } if (actualRooms[i].GetSouthRoom() == null) { noDoors++; } if (noDoors == temp) { /*solo habitaciones con 3 salidas*/ exitRooms.Add(actualRooms[i]); } } if (exitRooms.Count == 0) { temp--; } } while (exitRooms.Count == 0); /*Salida_____________*/ int num = CustomMath.RandomIntNumber(exitRooms.Count - 1); Room exit = exitRooms[num]; exitRooms.RemoveAt(num);//Elimina la sala de las posibilidades de salida RoomExit texit = new RoomExit(exit.GetPosX(), exit.GetPosY()); texit.SetEast(exit.GetEastRoom()); texit.SetWest(exit.GetWestRoom()); texit.SetNorth(exit.GetNorthRoom()); texit.SetSouth(exit.GetSouthRoom()); if (texit.GetNorthRoom() != null) { texit.GetNorthRoom().SetSouth(texit); } if (texit.GetSouthRoom() != null) { texit.GetSouthRoom().SetNorth(texit); } if (texit.GetWestRoom() != null) { texit.GetWestRoom().SetEast(texit); } if (texit.GetEastRoom() != null) { texit.GetEastRoom().SetWest(texit); } actualRooms.Remove(exit); actualRooms.Add(texit); /*Habitacion cerrada__________*/ bool existsClosedRoom = false; if (temp == 3 && CustomMath.RandomUnit() < (Program.ObteJuego().level - 1) / 3f && exitRooms.Count > 0) { existsClosedRoom = true; num = CustomMath.RandomIntNumber(exitRooms.Count - 1); //num se esta reutilizando de salida Room tempRoom = exitRooms[num]; exitRooms.RemoveAt(num); //Elimina la sala cerrada de las posibilidades Room newRoom; newRoom = new RoomClosed(tempRoom.GetPosX(), tempRoom.GetPosY()); newRoom.SetEast(tempRoom.GetEastRoom()); newRoom.SetWest(tempRoom.GetWestRoom()); newRoom.SetNorth(tempRoom.GetNorthRoom()); newRoom.SetSouth(tempRoom.GetSouthRoom()); if (newRoom.GetNorthRoom() != null) { newRoom.GetNorthRoom().SetSouth(newRoom); } if (newRoom.GetSouthRoom() != null) { newRoom.GetSouthRoom().SetNorth(newRoom); } if (newRoom.GetWestRoom() != null) { newRoom.GetWestRoom().SetEast(newRoom); } if (newRoom.GetEastRoom() != null) { newRoom.GetEastRoom().SetWest(newRoom); } actualRooms.Remove(tempRoom); actualRooms.Add(newRoom); } /*Tesoro____________*/ int limit = (Program.ObteJuego().level > 5)? 3 : (Program.ObteJuego().level + 1) / 2; RoomTreasure treasure = null; while (limit > 0) { num = CustomMath.RandomIntNumber(actualRooms.Count - 1, 1);//num se esta reutilizando de salida if (actualRooms[num].GetType() == typeof(Room)) { Room r = actualRooms[num]; treasure = new RoomTreasure(r.GetPosX(), r.GetPosY()); treasure.SetEast(r.GetEastRoom()); treasure.SetWest(r.GetWestRoom()); treasure.SetNorth(r.GetNorthRoom()); treasure.SetSouth(r.GetSouthRoom()); if (treasure.GetNorthRoom() != null) { treasure.GetNorthRoom().SetSouth(treasure); } if (treasure.GetSouthRoom() != null) { treasure.GetSouthRoom().SetNorth(treasure); } if (treasure.GetWestRoom() != null) { treasure.GetWestRoom().SetEast(treasure); } if (treasure.GetEastRoom() != null) { treasure.GetEastRoom().SetWest(treasure); } actualRooms.Remove(r); actualRooms.Add(treasure); limit--; } } if (CustomMath.RandomUnit() < 0.5) { RoomBless bless; Room r; do { r = actualRooms[CustomMath.RandomIntNumber(actualRooms.Count - 1, 1)]; } while (r.GetType() != typeof(Room)); bless = new RoomBless(r.GetPosX(), r.GetPosY()); bless.SetEast(r.GetEastRoom()); bless.SetWest(r.GetWestRoom()); bless.SetNorth(r.GetNorthRoom()); bless.SetSouth(r.GetSouthRoom()); if (bless.GetNorthRoom() != null) { bless.GetNorthRoom().SetSouth(bless); } if (bless.GetSouthRoom() != null) { bless.GetSouthRoom().SetNorth(bless); } if (bless.GetWestRoom() != null) { bless.GetWestRoom().SetEast(bless); } if (bless.GetEastRoom() != null) { bless.GetEastRoom().SetWest(bless); } actualRooms.Remove(r); actualRooms.Add(bless); } /*Miscelaneous*/ if (existsClosedRoom) { bool control = true; do { num = CustomMath.RandomIntNumber(actualRooms.Count - 1, 1); if (actualRooms[num].GetType() == typeof(Room)) { actualRooms[num].GetItem(new Item("Llave vieja")); control = false; } } while (control); } }
/// <summary> /// Generates the fragment components and adds them to the level. /// </summary> public void AddFragmentsToLevel() { GameObject fragmentParent = new GameObject("Fragments - "); fragmentParent.transform.parent = GameObject.FindGameObjectWithTag("Dungeon").transform; int fragmentID = 0; List <Fragment> fragments; Transform roomExitTransform; Quaternion rotation; foreach (var roomObj in GameObject.FindGameObjectsWithTag("RoomInstance")) { foreach (var roomExit in roomObj.GetComponent <Room>().GetRoomExits()) { if (roomExit.FragmentSpawned) //if a fragment has already been spawned at this exit, skip it { continue; } int index = -1; if (roomExit.GetConnectionStatus().Equals(RoomExit.ExitStatus.Connected)) { //only one fragment needs to be spawned between the 2 connected exits so set the FragmentSpawned property of both exits to true roomExit.FragmentSpawned = true; RoomExit connectedExit = FindRoomExit(roomExit.GetConnectedTo()); if (connectedExit != null) { connectedExit.FragmentSpawned = true; } fragments = GetFragmentsMatchingType(Fragment.FragmentTypes.Door); index = rnd.GetUnityEngineRandom(0, fragments.Count); if (roomExit.GetExit().HasPriority()) { roomExitTransform = roomExit.GetExit().transform; } else { roomExitTransform = roomExit.GetConnectedTo().transform; } //rotate the fragment based on the angles of it's prefab and the Y axis of the exit rotation = Quaternion.Euler(fragments[index].transform.eulerAngles.x, fragments[index].transform.eulerAngles.y + roomExitTransform.eulerAngles.y + fragments[index].GetRotateAdditionalDegrees(), fragments[index].transform.eulerAngles.z); Fragment fr = UnityEngine.MonoBehaviour.Instantiate(fragments[index], roomExitTransform.position, rotation, fragmentParent.transform); fr.name += fragmentID; fr.transform.Translate(fragments[index].GetAdditonalMovement()); } else //if ((roomExit.GetConnectionStatus().Equals(RoomExit.ExitStatus.ClosedDueToCollision) || roomExit.GetConnectionStatus().Equals(RoomExit.ExitStatus.Open))) { roomExit.FragmentSpawned = true; fragments = GetFragmentsMatchingType(Fragment.FragmentTypes.Wall); index = rnd.GetUnityEngineRandom(0, fragments.Count); roomExitTransform = roomExit.GetExit().transform; rotation = Quaternion.Euler(fragments[index].transform.eulerAngles.x, fragments[index].transform.eulerAngles.y + roomExitTransform.eulerAngles.y + fragments[index].GetRotateAdditionalDegrees(), fragments[index].transform.eulerAngles.z); Fragment fr = UnityEngine.MonoBehaviour.Instantiate(fragments[index], roomExitTransform.position, rotation, fragmentParent.transform); fr.name += fragmentID; fr.transform.Translate(fragments[index].GetAdditonalMovement()); } fragmentID++; } } fragmentParent.name += fragmentParent.GetComponentsInChildren <Fragment>().Count(); }
public void ExitRoom(RoomExit exit) { // @OTOD: whatever room-specific stuff here... //exit.exit_direction; RoomManager.ExitCurrentRoom(this, exit); }
protected override bool Build() { InitRooms(); int distance; var retry = 0; var minDistance = (int)Math.Sqrt(Rooms.Count); do { var innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomEntrance = pdsharp.utils.Random.Element(Rooms); }while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4); innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomExit = pdsharp.utils.Random.Element(Rooms); }while (RoomExit == RoomEntrance || RoomExit.Width() < 6 || RoomExit.Height() < 6 || RoomExit.Top == 0); Graph.BuildDistanceMap(Rooms, RoomExit); distance = Graph.BuildPath(Rooms, RoomEntrance, RoomExit).Count; if (retry++ > 10) { return(false); } }while (distance < minDistance); RoomEntrance.type = RoomType.ENTRANCE; RoomExit.type = RoomType.EXIT; Graph.BuildDistanceMap(Rooms, RoomExit); var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); Graph.SetPrice(path, RoomEntrance.distance); Graph.BuildDistanceMap(Rooms, RoomExit); path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); var room = RoomEntrance; foreach (var next in path) { room.Connect(next); room = next; } Room roomShop = null; var shopSquare = 0; foreach (var r in Rooms) { if (r.type != RoomType.NULL || r.Connected.Count <= 0) { continue; } r.type = RoomType.PASSAGE; if (r.Square() <= shopSquare) { continue; } roomShop = r; shopSquare = r.Square(); } if (roomShop == null || shopSquare < 30) { return(false); } roomShop.type = Imp.Quest.IsCompleted ? RoomType.SHOP : RoomType.STANDARD; Paint(); PaintWater(); PaintGrass(); return(true); }
public void ChangeRoom(RoomExit roomExit) { Destroy(room.gameObject); room = Instantiate(roomExit.room, new Vector2(0, 0), Quaternion.identity).GetComponent <Room>(); }
public void InitRoom(GameObject roomPrefab, SMonsterSpawnConfiguration monstersToSpawn) { //SaveGameManager.instance.SaveGame(playerStats.roomNumber, playerStats.hp, playerStats.gold); int i, j; //GameObject room = room = Instantiate(roomPrefab); surface.BuildNavMesh(); players = new List <Player>(GameObject.FindObjectsOfType <Player>()); foreach (Player p in players) { p.EnableAgent(false); } spawnMonster = new List <GameObject>(GameObject.FindGameObjectsWithTag("Spawner")); j = 0; foreach (SMonsterSpawnConfiguration.Spawner s in monstersToSpawn.monsters) { for (i = 0; i < s.numberToSpawn; i++) { //Debug.Log("Instanzio nuovo mostro."); GameObject newMonster = Instantiate(s.monsterToSpawn, spawnMonster[j % spawnMonster.Count].transform.position, spawnMonster[j % spawnMonster.Count].transform.rotation); newMonster.transform.rotation = spawnMonster[j % spawnMonster.Count].transform.rotation; monsters.Add(newMonster.GetComponent <Monster>()); monstersAlive++; //Debug.Log("Mostro " + newMonster.name + " " + monstersAlive + " " + newMonster.transform.position + " " + monsters.Count); j++; } } doors = new List <Door>(GameObject.FindObjectsOfType <Door>()); spawnPlayer = new List <GameObject>(GameObject.FindGameObjectsWithTag("SpawnerPlayer")); for (i = 0; i < spawnPlayer.Count; i++) { RoomExit newSpawnPoint = Instantiate(playerSpawnExitPrefab, spawnPlayer[i].transform.position, spawnPlayer[i].transform.rotation); exits.Add(newSpawnPoint); newSpawnPoint.EnableExit(false); spawnPlayer[i] = newSpawnPoint.gameObject; } i = 0; foreach (Player p in players) { p.transform.position = spawnPlayer[i % spawnPlayer.Count].transform.position; p.transform.rotation = spawnPlayer[i % spawnPlayer.Count].transform.rotation; //elimino la possibilita' di uscire da qua spawnPlayer[i % spawnPlayer.Count].GetComponent <RoomExit>().CloseExit(); //print(p.transform.position + " " + spawnPlayer[i % spawnPlayer.Length].transform.position); float minDistance = 80000f; int closestDoor = 0; for (j = 0; j < doors.Count; j++) { if (Vector3.Distance(p.transform.position, doors[j].transform.position) < minDistance) { minDistance = Vector3.Distance(p.transform.position, doors[j].transform.position); closestDoor = j; } } doors[closestDoor].Block(); i++; p.EnableAgent(true); } roomLoaded.Raise(); //Debug.Log("Number of monsters: " + monsters.Count + " " + GameObject.FindGameObjectsWithTag("Monster").Length); }
// Used when user types 'exits' or similar command public static string CreateStringOfExitDescriptions(Character.Models.Character player, RoomExit roomExits) { var allRoomExits = ""; if (roomExits?.NorthRoom != null) { if (roomExits.NorthRoom?.AttributeRequirementToSee != null && !PlayerAttributeComparer.ComparePlayerTraitsToAttributeRequirement(player, roomExits.NorthRoom.AttributeRequirementToSee)) { allRoomExits += $"{ConsoleStrings.LackingRequirementRoomDescription} (<{roomExits.NorthRoom.AttributeRequirementToSee.RequirementName}> needed) \n\n"; } else if (roomExits.NorthRoom?.ItemRequirementToSee != null) { var hasItem = false; foreach (var item in player.CarriedItems) { if (item.ItemName == roomExits.NorthRoom.ItemRequirementToSee.RelevantItem.ItemName) { hasItem = true; } } if (hasItem) { allRoomExits += roomExits.NorthRoomDescription + "\n\n"; } else { allRoomExits += $"{ConsoleStrings.LackingRequirementRoomDescription} (<{roomExits.NorthRoom.ItemRequirementToSee.RequirementName}> needed) \n\n"; } } else { if (roomExits.NorthRoom.RoomEntered) { allRoomExits += roomExits.NorthRoomDescription + " \t(entered)\n\n"; } else { allRoomExits += roomExits.NorthRoomDescription + "\n\n"; } } } if (roomExits?.EastRoom != null) { if (roomExits.EastRoom?.AttributeRequirementToSee != null && !PlayerAttributeComparer.ComparePlayerTraitsToAttributeRequirement(player, roomExits.EastRoom.AttributeRequirementToSee)) { allRoomExits += $"{ConsoleStrings.LackingRequirementRoomDescription} (<{roomExits.EastRoom.AttributeRequirementToSee.RequirementName}> needed) \n\n"; } else if (roomExits.EastRoom?.ItemRequirementToSee != null) { var hasItem = false; foreach (var item in player.CarriedItems) { if (item.ItemName == roomExits.EastRoom.ItemRequirementToSee.RelevantItem.ItemName) { hasItem = true; } } if (hasItem) { allRoomExits += roomExits.EastRoomDescription + "\n\n"; } else { allRoomExits += $"{ConsoleStrings.LackingRequirementRoomDescription} (<{roomExits.EastRoom.ItemRequirementToSee.RequirementName}> needed) \n\n"; } } else { if (roomExits.EastRoom.RoomEntered) { allRoomExits += roomExits.EastRoomDescription + " \t(entered)\n\n"; } else { allRoomExits += roomExits.EastRoomDescription + "\n\n"; } } } if (roomExits?.SouthRoom != null) { if (roomExits.SouthRoom?.AttributeRequirementToSee != null && !PlayerAttributeComparer.ComparePlayerTraitsToAttributeRequirement(player, roomExits.SouthRoom.AttributeRequirementToSee)) { allRoomExits += $"{ConsoleStrings.LackingRequirementRoomDescription} (<{roomExits.SouthRoom.AttributeRequirementToSee.RequirementName}> needed) \n\n"; } else if (roomExits.SouthRoom?.ItemRequirementToSee != null) { var hasItem = false; foreach (var item in player.CarriedItems) { if (item.ItemName == roomExits.SouthRoom.ItemRequirementToSee.RelevantItem.ItemName) { hasItem = true; } } if (hasItem) { allRoomExits += roomExits.SouthRoomDescription + "\n\n"; } else { allRoomExits += $"{ConsoleStrings.LackingRequirementRoomDescription} (<{roomExits.SouthRoom.ItemRequirementToSee.RequirementName}> needed) \n\n"; } } else { if (roomExits.SouthRoom.RoomEntered) { allRoomExits += roomExits.SouthRoomDescription + " \t(entered)\n\n"; } else { allRoomExits += roomExits.SouthRoomDescription + "\n\n"; } } } if (roomExits?.WestRoom != null) { if (roomExits.WestRoom?.AttributeRequirementToSee != null && !PlayerAttributeComparer.ComparePlayerTraitsToAttributeRequirement(player, roomExits.WestRoom.AttributeRequirementToSee)) { allRoomExits += $"{ConsoleStrings.LackingRequirementRoomDescription} (<{roomExits.WestRoom.AttributeRequirementToSee.RequirementName}> needed) \n\n"; } else if (roomExits.WestRoom?.ItemRequirementToSee != null) { var hasItem = false; foreach (var item in player.CarriedItems) { if (item.ItemName == roomExits.WestRoom.ItemRequirementToSee.RelevantItem.ItemName) { hasItem = true; } } if (hasItem) { allRoomExits += roomExits.WestRoomDescription + "\n\n"; } else { allRoomExits += $"{ConsoleStrings.LackingRequirementRoomDescription} (<{roomExits.WestRoom.ItemRequirementToSee.RequirementName}> needed) \n\n"; } } else { if (roomExits.WestRoom.RoomEntered) { allRoomExits += roomExits.WestRoomDescription + " \t(entered)\n\n"; } else { allRoomExits += roomExits.WestRoomDescription + "\n\n"; } } } return(allRoomExits); }
protected override bool Build() { InitRooms(); int distance; var retry = 0; var minDistance = (int)Math.Sqrt(Rooms.Count); do { var innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomEntrance = pdsharp.utils.Random.Element(Rooms); }while (RoomEntrance.Width() < 4 || RoomEntrance.Height() < 4); innerRetry = 0; do { if (innerRetry++ > 10) { return(false); } RoomExit = pdsharp.utils.Random.Element(Rooms); }while (RoomExit == RoomEntrance || RoomExit.Width() < 6 || RoomExit.Height() < 6 || RoomExit.Top == 0); Graph.BuildDistanceMap(Rooms, RoomExit); distance = RoomEntrance.Distance(); if (retry++ > 10) { return(false); } }while (distance < minDistance); RoomEntrance.type = RoomType.ENTRANCE; RoomExit.type = RoomType.BOSS_EXIT; Graph.BuildDistanceMap(Rooms, RoomExit); var path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); Graph.SetPrice(path, RoomEntrance.distance); Graph.BuildDistanceMap(Rooms, RoomExit); path = Graph.BuildPath(Rooms, RoomEntrance, RoomExit); var room = RoomEntrance; foreach (var next in path) { room.Connect(next); room = next; } room = RoomExit.Connected.Keys.First(); if (RoomExit.Top == room.Bottom) { return(false); } foreach (var r in Rooms.Where(r => r.type == RoomType.NULL && r.Connected.Count > 0)) { r.type = RoomType.TUNNEL; } var candidates = new List <Room>(); foreach (var r in RoomExit.Neigbours) { if (!RoomExit.Connected.ContainsKey(r) && (RoomExit.Left == r.Right || RoomExit.Right == r.Left || RoomExit.Bottom == r.Top)) { candidates.Add(r); } } if (candidates.Count > 0) { var kingsRoom = pdsharp.utils.Random.Element(candidates); kingsRoom.Connect(RoomExit); kingsRoom.type = RoomType.RAT_KING; } Paint(); PaintWater(); PaintGrass(); PlaceTraps(); return(true); }
/* * So we now need a way to set the next room number to walk to when exiting * from one of this rooms sides. * When the client walks ot one of these exit's, we want to give them * the next room, so we need a way to get the room number from a exit * */ public virtual uint GetNextRoomByExit(RoomExit exit) { return(150000004); }
public Room buildRoom(String roomName) { if (roomName == "drewQtrs") //Drew's quarters { imageList.Add("n3c"); //north (door) imageList.Add("n3b"); //east (militerm) imageList.Add("n3a"); //south (desk) imageList.Add("n3d"); //west (bed) movieList.Add("N3C_3B"); //north to east movieList.Add("N3B_3A"); //east to south movieList.Add("N3A_3D"); //south to west movieList.Add("N3D_3C"); //west to north movieList.Add("N3C_3D"); //north to east movieList.Add("N3D_3A"); //west to south movieList.Add("N3A_3B"); //south to west movieList.Add("N3B_3C"); //west to north var basePath = (@".\content\drewqtrs\"); var northExit = new RoomExit("north", "enlistedQtrs", "N3C_2C", basePath, "north", false); exitList.Add(northExit); var drewQtrs = new Room(imageList, movieList, exitList, basePath, "Drew's Quarters"); return(drewQtrs); } if (roomName == "enlistedQtrs") //Enlisted Men's quarters { imageList.Add("n2c"); //north imageList.Add("n2b"); //east imageList.Add("n2a"); //south imageList.Add("n2d"); //west movieList.Add("N2C_2B"); //north to east movieList.Add("N2B_2A"); //east to south movieList.Add("N2A_2D"); //south to west movieList.Add("N2D_2C"); //west to north movieList.Add("N2C_2D"); //north to west movieList.Add("N2D_2A"); //west to south movieList.Add("N2A_2B"); //south to east movieList.Add("N2B_2C"); //east to north var basePath = (@".\content\drewqtrs\"); var exit1 = new RoomExit("east", "drewQtrs", "N2B_3A", basePath, "south", false); var exit2 = new RoomExit("north", "deck2area1", "N2C_1", basePath, "north", false); exitList.Add(exit1); exitList.Add(exit2); var enlistedQtrs = new Room(imageList, movieList, exitList, basePath, "Corporate Quarters"); return(enlistedQtrs); } if (roomName.Substring(0, 9) == "deck2area") //Deck 2 corridor { imageList.Add("NSI1"); //north imageList.Add("NHW1"); //east imageList.Add("NSO1"); //south imageList.Add("NHE1"); //west movieList.Add("NSIHW"); //north to east movieList.Add("NHWSO"); //east to south movieList.Add("NSOHE"); //south to west movieList.Add("NHESI"); //west to north movieList.Add("NSIHE"); //north to west movieList.Add("NHESO"); //west to south movieList.Add("NSOHW"); //south to east movieList.Add("NHWSI"); //east to north var basePath = (@".\content\main\"); int areaNumber = Convert.ToInt16(roomName.Substring(9, 1)); if (areaNumber == 1) { var exit1 = new RoomExit("south", "enlistedQtrs", "corpqrtrs", basePath, "south", false); var exit2 = new RoomExit("east", "deck2area5", "NHW", basePath, "east", false); var exit3 = new RoomExit("west", "deck2area2", "NHE", basePath, "west", false); var exit4 = new RoomExit("north", "lift1deck2", "deck2lift1", basePath, "north", true); exitList.Add(exit1); exitList.Add(exit2); exitList.Add(exit3); exitList.Add(exit4); var corridor = new Room(imageList, movieList, exitList, basePath, "Corridor - Corporate Quarters"); return(corridor); } else if (areaNumber == 2) { //RoomExit exit1 = new RoomExit("south", "enlistedQtrs", "corpqrtrs", basePath, "south"); var exit2 = new RoomExit("west", "deck2area3", "NHE", basePath, "west", false); var exit3 = new RoomExit("east", "deck2area1", "NHW", basePath, "east", false); //exitList.Add(exit1); exitList.Add(exit2); exitList.Add(exit3); var corridor = new Room(imageList, movieList, exitList, basePath, "Corridor - Sick Bay"); return(corridor); } else if (areaNumber == 3) { //RoomExit exit1 = new RoomExit("south", "enlistedQtrs", "corpqrtrs", basePath, "south"); var exit2 = new RoomExit("west", "deck2area4", "NHE", basePath, "west", false); var exit3 = new RoomExit("east", "deck2area2", "NHW", basePath, "east", false); //exitList.Add(exit1); exitList.Add(exit2); exitList.Add(exit3); var corridor = new Room(imageList, movieList, exitList, basePath, "Corridor - Lounge"); return(corridor); } else if (areaNumber == 4) { // RoomExit exit1 = new RoomExit("south", "enlistedQtrs", "corpqrtrs", basePath, "south"); var exit2 = new RoomExit("west", "deck2area5", "NHE", basePath, "west", false); var exit3 = new RoomExit("east", "deck2area3", "NHW", basePath, "east", false); //exitList.Add(exit1); exitList.Add(exit2); exitList.Add(exit3); var corridor = new Room(imageList, movieList, exitList, basePath, "Corridor - Kitchen/Mess"); return(corridor); } else if (areaNumber == 5) { //RoomExit exit1 = new RoomExit("south", "enlistedQtrs", "corpqrtrs", basePath, "south"); var exit2 = new RoomExit("west", "deck2area1", "NHE", basePath, "west", false); var exit3 = new RoomExit("east", "deck2area4", "NHW", basePath, "east", false); //exitList.Add(exit1); exitList.Add(exit3); exitList.Add(exit2); var corridor = new Room(imageList, movieList, exitList, basePath, "Corridor - Science"); return(corridor); } } return(null); }
public void AddRoomExit(Room nextRoom, string name, string description) { var exit = new RoomExit(nextRoom, name, description); this.AddToInventory(exit); }