public void ConnectNodes(GenerationNode NodeToConnectTo) { ConnectedNode = NodeToConnectTo; //NodeToConnectTo.ConnectedNode = this; }
public XmlDocument GenerateEquipment(string flags, string statsName, string parent, string itemType, string maxDurabilityPatchCheck, GenerationNode generation, StatsNode stats) { var doc = new XmlDocument(); // common attributes var baseNode = $@"<node id=""Item""> <attribute id=""Translate"" value=""0 0 0"" type=""12"" /> <attribute id=""Flags"" value=""{flags}"" type=""5"" /> <attribute id=""Level"" value="""" type=""22"" /> <attribute id=""Rotate"" value="" 1.00 0.00 0.00 
 0.00 1.00 0.00 
 0.00 0.00 1.00 
"" type=""15"" /> <attribute id=""Scale"" value=""1"" type=""6"" /> <attribute id=""Global"" value=""True"" type=""19"" /> <attribute id=""Velocity"" value=""0 0 0"" type=""12"" /> <attribute id=""GoldValueOverwrite"" value=""-1"" type=""4"" /> <attribute id=""UnsoldGenerated"" value=""False"" type=""19"" /> <attribute id=""IsKey"" value=""False"" type=""19"" /> <attribute id=""TreasureGenerated"" value=""False"" type=""19"" /> <attribute id=""CurrentTemplate"" value=""50ebbcff-e6d7-4a02-94ba-0978adcdb024"" type=""22"" /> <attribute id=""CurrentTemplateType"" value=""0"" type=""1"" /> <attribute id=""OriginalTemplate"" value=""50ebbcff-e6d7-4a02-94ba-0978adcdb024"" type=""22"" /> <attribute id=""OriginalTemplateType"" value=""0"" type=""1"" /> <attribute id=""Stats"" value=""{statsName}"" type=""22"" /> <attribute id=""IsGenerated"" value=""True"" type=""19"" /> <attribute id=""Inventory"" value=""0"" type=""5"" /> <attribute id=""Parent"" value=""{parent}"" type=""5"" /> <attribute id=""Slot"" value=""43"" type=""3"" /> <attribute id=""Amount"" value=""1"" type=""4"" /> <attribute id=""Key"" value="""" type=""22"" /> <attribute id=""LockLevel"" value=""1"" type=""4"" /> <attribute id=""SurfaceCheckTimer"" value=""0"" type=""6"" /> <attribute id=""Vitality"" value=""-1"" type=""4"" /> <attribute id=""LifeTime"" value=""0"" type=""6"" /> <attribute id=""owner"" value=""67174634"" type=""5"" /> <attribute id=""ItemType"" value=""{itemType}"" type=""22"" /> <attribute id=""MaxVitalityPatchCheck"" value=""-1"" type=""4"" /> <attribute id=""MaxDurabilityPatchCheck"" value=""{maxDurabilityPatchCheck}"" type=""4"" /> </node>"; doc.LoadXml(baseNode); return(doc); }
public void GenerateRoom(ExitDirections[] DirectionsArray) { // Debug.Log("Amount of rooms generated: " + AmountOfRoomsGenerated); { if (AmountOfRoomsGenerated == 0) { //StarterRoom ActuallyGenerated++; GenerationRoom StarterRoom = new GenerationRoom(x, y, true, false, ActuallyGenerated); //Debug.Log("StarterRoomX: " + StarterRoom.x + ", StarterRoomY: " + StarterRoom.y); if (CheckAvailability()) { StarterRoom.Nodes.Add(new GenerationNode(DirectionsArray[DirectionValue])); generationRooms[x, y] = StarterRoom; IncrementXY(DirectionValue); AmountOfRoomsGenerated++; GenerateRoom(DirectionsArray); } else { Debug.Log("Unable to add node because direction is not available, exiting."); return; } } else { if (AmountOfRoomsGenerated >= floorInfo.RoomsInFloor1 && BossRoomDone == false) { BossRoomDone = true; ActuallyGenerated++; GenerationRoom randomRoom = new GenerationRoom(x, y, false, true, ActuallyGenerated); if (randomRoom.y + 1 < floorInfo.FloorWidthHeight) { if (generationRooms[randomRoom.x, randomRoom.y + 1] != null) { if (generationRooms[randomRoom.x, randomRoom.y + 1].BossRoomEntryRoom) { GenerationNode node = new GenerationNode(ExitDirections.Up); foreach (GenerationNode otherNode in generationRooms[randomRoom.x, randomRoom.y + 1].Nodes) { if (otherNode.exitDirection == ExitDirections.Down) { node.ConnectNodes(otherNode); otherNode.ConnectNodes(node); } } randomRoom.Nodes.Add(node); } } } if (randomRoom.x + 1 < floorInfo.FloorWidthHeight) { if (generationRooms[randomRoom.x + 1, randomRoom.y] != null) { if (generationRooms[randomRoom.x + 1, randomRoom.y].BossRoomEntryRoom) { GenerationNode node = new GenerationNode(ExitDirections.Right); foreach (GenerationNode otherNode in generationRooms[randomRoom.x + 1, randomRoom.y].Nodes) { if (otherNode.exitDirection == ExitDirections.Left) { node.ConnectNodes(otherNode); otherNode.ConnectNodes(node); } } randomRoom.Nodes.Add(node); } } } if (randomRoom.y - 1 >= 0) { if (generationRooms[randomRoom.x, randomRoom.y - 1] != null) { if (generationRooms[randomRoom.x, randomRoom.y - 1].BossRoomEntryRoom) { GenerationNode node = new GenerationNode(ExitDirections.Down); foreach (GenerationNode otherNode in generationRooms[randomRoom.x, randomRoom.y - 1].Nodes) { if (otherNode.exitDirection == ExitDirections.Up) { node.ConnectNodes(otherNode); otherNode.ConnectNodes(node); } } randomRoom.Nodes.Add(node); } } } if (randomRoom.x - 1 >= 0) { if (generationRooms[randomRoom.x - 1, randomRoom.y] != null) { if (generationRooms[randomRoom.x - 1, randomRoom.y].BossRoomEntryRoom) { GenerationNode node = new GenerationNode(ExitDirections.Left); foreach (GenerationNode otherNode in generationRooms[randomRoom.x - 1, randomRoom.y].Nodes) { if (otherNode.exitDirection == ExitDirections.Right) { node.ConnectNodes(otherNode); otherNode.ConnectNodes(node); } } randomRoom.Nodes.Add(node); } } } if (randomRoom.y + 1 < floorInfo.FloorWidthHeight) { if (generationRooms[randomRoom.x, randomRoom.y + 1] != null) { for (int i = 0; i < generationRooms[randomRoom.x, randomRoom.y + 1].Nodes.Count; i++) { if (generationRooms[randomRoom.x, randomRoom.y + 1].Nodes[i].exitDirection == ExitDirections.Down) { if (randomRoom.Nodes[0].ConnectedNode != generationRooms[randomRoom.x, randomRoom.y + 1].Nodes[i]) { generationRooms[randomRoom.x, randomRoom.y + 1].Nodes.Remove(generationRooms[randomRoom.x, randomRoom.y + 1].Nodes[i]); } } } } } if (randomRoom.x + 1 < floorInfo.FloorWidthHeight) { if (generationRooms[randomRoom.x + 1, randomRoom.y] != null) { for (int i = 0; i < generationRooms[randomRoom.x + 1, randomRoom.y].Nodes.Count; i++) { if (generationRooms[randomRoom.x + 1, randomRoom.y].Nodes[i].exitDirection == ExitDirections.Left) { if (randomRoom.Nodes[0].ConnectedNode != generationRooms[randomRoom.x + 1, randomRoom.y].Nodes[i]) { generationRooms[randomRoom.x + 1, randomRoom.y].Nodes.Remove(generationRooms[randomRoom.x + 1, randomRoom.y].Nodes[i]); } } } } } if (randomRoom.y - 1 >= 0) { if (generationRooms[randomRoom.x, randomRoom.y - 1] != null) { for (int i = 0; i < generationRooms[randomRoom.x, randomRoom.y - 1].Nodes.Count; i++) { if (generationRooms[randomRoom.x, randomRoom.y - 1].Nodes[i].exitDirection == ExitDirections.Up) { if (randomRoom.Nodes[0].ConnectedNode != generationRooms[randomRoom.x, randomRoom.y - 1].Nodes[i]) { generationRooms[randomRoom.x, randomRoom.y - 1].Nodes.Remove(generationRooms[randomRoom.x, randomRoom.y - 1].Nodes[i]); } } } } } if (randomRoom.x - 1 >= 0) { if (generationRooms[randomRoom.x - 1, randomRoom.y] != null) { for (int i = 0; i < generationRooms[randomRoom.x - 1, randomRoom.y].Nodes.Count; i++) { if (generationRooms[randomRoom.x - 1, randomRoom.y].Nodes[i].exitDirection == ExitDirections.Right) { if (randomRoom.Nodes[0].ConnectedNode != generationRooms[randomRoom.x - 1, randomRoom.y].Nodes[i]) { generationRooms[randomRoom.x - 1, randomRoom.y].Nodes.Remove(generationRooms[randomRoom.x - 1, randomRoom.y].Nodes[i]); } } } } } generationRooms[randomRoom.x, randomRoom.y] = randomRoom; } else if (ActuallyGenerated <= floorInfo.RoomsInFloor1 && ActuallyGenerated != 0) { //Regular room ActuallyGenerated++; GenerationRoom randomRoom = new GenerationRoom(x, y, false, false, ActuallyGenerated); // Debug.Log("randomRoomNr: " + AmountOfRoomsGenerated + ", X: " + randomRoom.x + ", Y: " + randomRoom.y); //Debug.Log("randomRoomNr: " + AmountOfRoomsGenerated + ", CurrentX: " + x + ", CurrentY: " + y); bool NorthAvailable = true; bool EastAvailable = true; bool SouthAvailable = true; bool WestAvailable = true; if (x + 1 >= floorInfo.FloorWidthHeight) { //Debug.Log("DebugXEast: " + x + ", DebugYEast: " + y + ", FloorWidthHeight: " + floorInfo.FloorWidthHeight); EastAvailable = false; } else { //Debug.Log("DebugXEast: " + x + ", DebugYEast: " + y); if (generationRooms[x + 1, y] != null) { if (generationRooms[x + 1, y].bossRoom == false) { //Debug.Log("ABC0"); EastAvailable = false; GenerationNode node = new GenerationNode(ExitDirections.Right); foreach (GenerationNode OtherNode in generationRooms[x + 1, y].Nodes) { if (OtherNode.exitDirection == ExitDirections.Left) { node.ConnectNodes(OtherNode); OtherNode.ConnectNodes(node); randomRoom.Nodes.Add(node); // Debug.Log("CBA0"); } } } } } if (x - 1 <= -1) { //Debug.Log("DebugXWest: " + x + ", DebugYWest: " + y + ", FloorWidthHeight: " + floorInfo.FloorWidthHeight); WestAvailable = false; } else { // Debug.Log("DebugXWest: " + x + ", DebugYWest: " + y); if (generationRooms[x - 1, y] != null) { if (generationRooms[x - 1, y].bossRoom == false) { //Debug.Log("ABC1"); WestAvailable = false; GenerationNode node = new GenerationNode(ExitDirections.Left); foreach (GenerationNode OtherNode in generationRooms[x - 1, y].Nodes) { if (OtherNode.exitDirection == ExitDirections.Right) { node.ConnectNodes(OtherNode); OtherNode.ConnectNodes(node); randomRoom.Nodes.Add(node); //Debug.Log("CBA1"); } } } } } if (y + 1 >= floorInfo.FloorWidthHeight) { //Debug.Log("DebugXNorth: " + x + ", DebugYNorth: " + y + ", FloorWidthHeight: " + floorInfo.FloorWidthHeight); NorthAvailable = false; } else { // Debug.Log("DebugXNorth: " + x + ", DebugYNorth: " + y); if (generationRooms[x, y + 1] != null) { if (generationRooms[x, y + 1].bossRoom == false) { // Debug.Log("ABC2"); NorthAvailable = false; GenerationNode node = new GenerationNode(ExitDirections.Up); foreach (GenerationNode OtherNode in generationRooms[x, y + 1].Nodes) { if (OtherNode.exitDirection == ExitDirections.Down) { node.ConnectNodes(OtherNode); OtherNode.ConnectNodes(node); randomRoom.Nodes.Add(node); //Debug.Log("CBA2"); } } } } } if (y - 1 <= -1) { //Debug.Log("DebugXSouth: " + x + ", DebugYSouth: " + y + ", FloorWidthHeight: " + floorInfo.FloorWidthHeight); SouthAvailable = false; } else { // Debug.Log("DebugXSouth: " + x + ", DebugYSouth: " + y); if (generationRooms[x, y - 1] != null) { if (generationRooms[x, y - 1].bossRoom == false) { //Debug.Log("ABC3"); SouthAvailable = false; GenerationNode node = new GenerationNode(ExitDirections.Down); foreach (GenerationNode OtherNode in generationRooms[x, y - 1].Nodes) { if (OtherNode.exitDirection == ExitDirections.Up) { node.ConnectNodes(OtherNode); OtherNode.ConnectNodes(node); randomRoom.Nodes.Add(node); //Debug.Log("CBA3"); } } } } } //Debug.Log("North: " + NorthAvailable + ", East: " + EastAvailable + ", South: " + SouthAvailable + ", West: " + WestAvailable); int available = (NorthAvailable ? 1 : 0) + (EastAvailable ? 1 : 0) + (SouthAvailable ? 1 : 0) + (WestAvailable ? 1 : 0); //Debug.Log("AmountGenerated: " + AmountOfRoomsGenerated + ", AvailableNodes: " + available); for (int i = 0; i < available; i++) { if (AmountOfRoomsGenerated >= Mathf.CeilToInt(floorInfo.RoomsInFloor1 / 1.5f)) { if (Random.Range(0, 2) == 1) { for (int k = 0; k < 30; k++) { int randNumber = Random.Range(0, 4); if (randNumber == 0 && NorthAvailable == true && AmountOfRoomsGenerated + 1 <= floorInfo.RoomsInFloor1) { randomRoom.Nodes.Add(new GenerationNode(ExitDirections.Up)); AmountOfRoomsGenerated++; if (AmountOfRoomsGenerated == floorInfo.RoomsInFloor1) { randomRoom.BossRoomEntryRoom = true; } NorthAvailable = false; break; } if (randNumber == 1 && EastAvailable == true && AmountOfRoomsGenerated + 1 <= floorInfo.RoomsInFloor1) { randomRoom.Nodes.Add(new GenerationNode(ExitDirections.Right)); AmountOfRoomsGenerated++; if (AmountOfRoomsGenerated == floorInfo.RoomsInFloor1) { randomRoom.BossRoomEntryRoom = true; } EastAvailable = false; break; } if (randNumber == 2 && SouthAvailable == true && AmountOfRoomsGenerated + 1 <= floorInfo.RoomsInFloor1) { randomRoom.Nodes.Add(new GenerationNode(ExitDirections.Down)); AmountOfRoomsGenerated++; if (AmountOfRoomsGenerated == floorInfo.RoomsInFloor1) { randomRoom.BossRoomEntryRoom = true; } SouthAvailable = false; break; } if (randNumber == 3 && WestAvailable == true && AmountOfRoomsGenerated + 1 <= floorInfo.RoomsInFloor1) { randomRoom.Nodes.Add(new GenerationNode(ExitDirections.Left)); AmountOfRoomsGenerated++; if (AmountOfRoomsGenerated == floorInfo.RoomsInFloor1) { randomRoom.BossRoomEntryRoom = true; } WestAvailable = false; break; } } } } else { for (int k = 0; k < 30; k++) { int randNumber = Random.Range(0, 4); if (randNumber == 0 && NorthAvailable == true && AmountOfRoomsGenerated + 1 <= floorInfo.RoomsInFloor1) { randomRoom.Nodes.Add(new GenerationNode(ExitDirections.Up)); AmountOfRoomsGenerated++; if (AmountOfRoomsGenerated == floorInfo.RoomsInFloor1) { randomRoom.BossRoomEntryRoom = true; } NorthAvailable = false; break; } if (randNumber == 1 && EastAvailable == true && AmountOfRoomsGenerated + 1 <= floorInfo.RoomsInFloor1) { randomRoom.Nodes.Add(new GenerationNode(ExitDirections.Right)); AmountOfRoomsGenerated++; if (AmountOfRoomsGenerated == floorInfo.RoomsInFloor1) { randomRoom.BossRoomEntryRoom = true; } EastAvailable = false; break; } if (randNumber == 2 && SouthAvailable == true && AmountOfRoomsGenerated + 1 <= floorInfo.RoomsInFloor1) { randomRoom.Nodes.Add(new GenerationNode(ExitDirections.Down)); AmountOfRoomsGenerated++; if (AmountOfRoomsGenerated == floorInfo.RoomsInFloor1) { randomRoom.BossRoomEntryRoom = true; } SouthAvailable = false; break; } if (randNumber == 3 && WestAvailable == true && AmountOfRoomsGenerated + 1 <= floorInfo.RoomsInFloor1) { randomRoom.Nodes.Add(new GenerationNode(ExitDirections.Left)); AmountOfRoomsGenerated++; if (AmountOfRoomsGenerated == floorInfo.RoomsInFloor1) { randomRoom.BossRoomEntryRoom = true; } WestAvailable = false; break; } } } } generationRooms[randomRoom.x, randomRoom.y] = randomRoom; //Debug.Log("Actually Generated: " + ActuallyGenerated); bool up = true; bool right = true; bool down = true; bool left = true; //Debug.Log("Before Node shit, roomID: " + randomRoom.ID + ", NodeCount: " + randomRoom.Nodes.Count); for (int i = 0; i < randomRoom.Nodes.Count; i++) { //Debug.Log("NodeDingOfzo, roomID: " + randomRoom.ID); x = randomRoom.x; y = randomRoom.y; if (randomRoom.Nodes[i].exitDirection == ExitDirections.Up && up && generationRooms[x, y + 1] == null) { up = false; y++; GenerateRoom(DirectionsArray); } if (randomRoom.Nodes[i].exitDirection == ExitDirections.Right && right && generationRooms[x + 1, y] == null) { right = false; x++; GenerateRoom(DirectionsArray); } if (randomRoom.Nodes[i].exitDirection == ExitDirections.Down && down && generationRooms[x, y - 1] == null) { down = false; y--; GenerateRoom(DirectionsArray); } if (randomRoom.Nodes[i].exitDirection == ExitDirections.Left && left && generationRooms[x - 1, y] == null) { left = false; x--; GenerateRoom(DirectionsArray); } } } } } }