/// <summary> /// Destroys the Room and /// </summary> public override void Destroy() { Doorways.Clear(); Doorways = null; List <IPlayer> playerCollection = new List <IPlayer>(); foreach (IMob mob in Occupants) { if (mob is IPlayer) { playerCollection.Add((IPlayer)mob); } } this.BroadcastMessage("Room is being destroyed! You will be teleported to a new location.", playerCollection.ToList()); // Trace back up through the environment path to get the World IWorld world = Zone.Realm.World; //Get the initial Room location, and split it up into an array so we can parse it string[] roomPath = EngineSettings.Default.InitialRoom.Split('>'); // Make sure we have three entries, Realm, Zone and Room if (roomPath.Length != 3) { return; } // Get the Realm IRealm realm = world.GetRealm(roomPath[0]); if (realm == null) { return; } // Get our Zone IZone zone = realm.GetZone(roomPath[1]); if (zone == null) { return; } // Get the initial Room IRoom room = zone.GetRoom(roomPath[2]); if (room == null) { return; } // Loop through each player in this Room and move them to the initial Room. foreach (IPlayer player in Occupants) { player.Move(room); player.SendMessage("You have been moved to " + room.Name); } }
public void RemoveConnectionPoint(String ID) { for (int i = 0; i < Doorways.Count; i++) { if (Doorways[i].ID == ID) { Doorways.RemoveAt(i); break; } } }
/// <summary> /// Gets a reference to the doorway that matches the specified direction, if it exists /// </summary> /// <param name="direction">The direction that you want the doorway for.</param> /// <returns></returns> public IDoor GetDoorway(AvailableTravelDirections direction) { // Check if the doorway collection has the specified direction if (Doorways.ContainsKey(direction)) { return(Doorways[direction]); // return it } else { return(null); } }
/// <summary> /// Allows for removal of a doorway. /// </summary> /// <param name="direction">The direction of travel that the doorway should be removed.</param> /// <param name="autoRemoveReverseDirection">If true, the room on the otherside of the doorway will have it's door removed as well.</param> public virtual void RemoveDoorway(AvailableTravelDirections direction, bool autoRemoveReverseDirection = true) { if (Doorways.ContainsKey(direction)) { if (autoRemoveReverseDirection) { //When removig the reverse direction, always set "autoRemoveReverseDirection" within the Arrival room //to false, otherwise a circular loop will start. Doorways[direction].Arrival.RemoveDoorway(TravelDirections.GetReverseDirection(direction), false); } Doorways.Remove(direction); } }
void PlaceEndRoom() { //Instanitate room endRoom = Instantiate(endRoomPrefab) as EndRoom; endRoom.transform.parent = this.transform; //Create doorway lists to loop over List <Doorways> allAvailableDoorways = new List <Doorways>(availableDoorways); Doorways doorway = endRoom.doorways[0]; bool roomPlaced = false; //Try all available doorways foreach (Doorways availableDoorway in allAvailableDoorways) { //Position room BasicRoomScript room = (BasicRoomScript)endRoom; PositionRoomAtDoorway(ref room, doorway, availableDoorway); //Check room overlaps if (CheckRoomOverlap(endRoom)) { continue; } roomPlaced = true; //Remove occupied doorways doorway.gameObject.SetActive(false); availableDoorways.Remove(doorway); availableDoorway.gameObject.SetActive(false); availableDoorways.Remove(availableDoorway); //Exit loop if room has been placed break; } //Room couldn't be placed. Restart generator and try again if (!roomPlaced) { ResetLevelGenerator(); } }
void PositionRoomAtDoorway(ref BasicRoomScript room, Doorways roomDoorways, Doorways targetDoorway) { //Reset room position and rotation room.transform.position = Vector3.zero; room.transform.rotation = Quaternion.identity; //Rotate room to match previous doorway orientation Vector3 targetDoorwayEuler = targetDoorway.transform.eulerAngles; Vector3 roomDoorwaysEuler = roomDoorways.transform.eulerAngles; float deltaAngle = Mathf.DeltaAngle(roomDoorwaysEuler.y, targetDoorwayEuler.y); Quaternion currentRoomTargetRotation = Quaternion.AngleAxis(deltaAngle, Vector3.up); room.transform.rotation = currentRoomTargetRotation * Quaternion.Euler(0, 180f, 0); //Position room Vector3 roomPositionOffset = roomDoorways.transform.position - room.transform.position; room.transform.position = targetDoorway.transform.position - roomPositionOffset; }
/// <summary> /// Adds a doorway to the Room, linking it to another Room in the world. /// </summary> /// <param name="direction">The direction that the player must travel in order to move through the doorway</param> /// <param name="arrivalRoom">The room that the player will enter, once they walk through the doorway</param> /// <param name="autoAddReverseDirection">If true, the arrival room will have the opposite doorway automatically linked back to this Room</param> /// <param name="forceOverwrite">If true, if a doorway already exists for the specified direction, it will overwrite it.</param> public virtual void AddDoorway(AvailableTravelDirections direction, IRoom arrivalRoom, bool autoAddReverseDirection = true, bool forceOverwrite = true) { // Check if room is null. if (arrivalRoom == null) { return; // No null references within our collections! } // If this direction already exists, overwrite it // but only if 'forceOverwrite' is true if (Doorways.ContainsKey(direction)) { // Remove the old door RemoveDoorway(direction); // Get a scripted Door instance to add back to the collection var door = (Door)ScriptFactory.GetScript(MudDesigner.Engine.Properties.EngineSettings.Default.DoorScript); door.SetArrivalRoom(arrivalRoom); door.SetDepartingRoom(this); door.SetFacingDirection(direction); Doorways.Add(direction, door); } // Direction does not exist, so lets add a new doorway else { // Get a scripted instance of a Door. var door = (Door)ScriptFactory.GetScript(MudDesigner.Engine.Properties.EngineSettings.Default.DoorScript); door.SetFacingDirection(direction); door.SetArrivalRoom(arrivalRoom); door.SetDepartingRoom(this); // Add the new doorway to this rooms collection. Doorways.Add(direction, door); // If autoreverse is enabled, add the doorway to the arrival room too. if (autoAddReverseDirection) { arrivalRoom.AddDoorway(TravelDirections.GetReverseDirection(direction), this, false, forceOverwrite); } } }
/// <summary> /// Going to read char-by-char from the given filepath. /// We will generate a gameRectangle at a calculated position if we read an 'X', 'N', 'S', 'E', or 'W'. /// Creates a Connection point if we read an 'N', 'S', 'E', or 'W'. /// /// 'N', 'S', 'E', and 'W' stands for the direction the prefab piece has a "doorway"( an ability to connect to other prefab pieces ). /// /// These "doorways" must point away from the prefab piece. /// /// 'N' stands for a doorway pointing North /// 'S' stands for a doorway pointing South /// 'E' stands for a doorway pointing East /// 'W' stands for a doorway pointing West /// /// Input is not Case sensitive; values read in will be upp cased. /// /// </summary> /// <param name="PrefabFile">filepath to the PreFab piece file</param> private void GeneratePrefabPiece(string PrefabFile) { try { // open a stream reader to the prefab file StreamReader reader = new StreamReader(PrefabFile); string line = ""; char ch; // We will use this Point to calculate a GameRectangle's position Point currentPos = new Point(0, 0); // we will use this boolean to signify if we are creating a GameRectangle or not during each do/while loop iteration bool addBlock; do { // read a line into our string line = reader.ReadLine(); foreach (var character in line) { // first read our input char and set it to Upper Case ch = Char.ToUpper(character); // assume that we aren't adding a GameRectangle this current iteration addBlock = false; // check the ascii value and respond appropriately (see function header for details) if (ch == 'N') { Doorways.Add(new ConnectionPoint(currentPos, prefabID, Direction.North)); addBlock = true; } else if (ch == 'S') { Point adjustedPos = new Point(); adjustedPos.X = currentPos.X; adjustedPos.Y = currentPos.Y + Constants.RectangleChunk; Doorways.Add(new ConnectionPoint(adjustedPos, prefabID, Direction.South)); addBlock = true; } else if (ch == 'E') { Point adjustedPos = new Point(); adjustedPos.X = currentPos.X + Constants.RectangleChunk; adjustedPos.Y = currentPos.Y; Doorways.Add(new ConnectionPoint(adjustedPos, prefabID, Direction.East)); addBlock = true; } else if (ch == 'W') { Doorways.Add(new ConnectionPoint(currentPos, prefabID, Direction.West)); addBlock = true; } else if (ch == 'X') { addBlock = true; } // adjust our calculated point position currentPos.X += Constants.RectangleChunk; // add a game rectangle to our prefab list if (addBlock) { rectangles.Add(new GameRectangle(currentPos.X, currentPos.Y, Constants.RectangleChunk, Constants.RectangleChunk, color)); } } // once we read a line, reset the coordinates X and Y to 0 and +10, respectively currentPos.X = 0; currentPos.Y += Constants.RectangleChunk; } while (!reader.EndOfStream); // clean up reader.Close(); reader.Dispose(); } catch (IOException e) { MessageBox.Show(e.ToString()); } }