public void Start() { gm = GameManager.instance; entropy = Entropy.instance; handler = entropy.GetHandler("dungeon"); Debug.Log(handler.rand_seed); //Randomize Dungeon Size dungeonSize = entropy.GetHandler("dungeon").randomValue(minSize, maxSize); handler.OverridePool(exit_table); startRoom = Instantiate(handler.Randomize(), transform.position, transform.rotation); startRoom.transform.SetParent(transform); //Make the dungeon StartCoroutine("CreateDungeon"); }
//Drop all the loot before dying. public override void Die() { RandomHandler handler = Entropy.instance.GetHandler("enemy"); handler.OverridePool(table.entries); int amount = handler.randomValue(table.rolls[0], table.rolls[1]); for (int i = 0; i < amount; i++) { GameObject result = handler.Randomize(); Instantiate(result, transform.position, transform.rotation); } //Charge the player's active item GameObject player = GameObject.FindGameObjectWithTag("player"); player.SendMessage("GainCharge", 0.2f, SendMessageOptions.DontRequireReceiver); base.Die(); }
//Create the Dungeon public IEnumerator CreateDungeon() { yield return(new WaitForSeconds(2f)); nodes = Find("node_spawn"); nodes_center = Find("node_center"); int startIndex = handler.randomValue(0, dungeonSize / 2); handler.OverridePool(spawn_table); while (nodes.Length > 0) { //After reaching the max body rooms, add in the treasure room, then close the dungeon. if (nodes_center.Length >= dungeonSize && !GameObject.FindGameObjectWithTag("node_treasure")) { handler.OverridePool(treasure_table); } else if (nodes_center.Length >= dungeonSize) { handler.OverridePool(exit_table); } int newNode = handler.randomValue(0, nodes.Length); Node node = nodes[newNode].GetComponent <Node>(); //Grab a random node GameObject newRoom = handler.Randomize(); //Grab a random room Room room = newRoom.GetComponent <Room>(); //Grab the room info //Spawn the room! In order for it to spawn, must be no collisions and must match up doors. if (!CanSpawn(nodes[newNode].transform.position, room.size, 0, dungeon) && HasDoor(room, node.doors)) { if (roomsGenerated == startIndex) { SpawnRoom(start, nodes[newNode]); } else { SpawnRoom(newRoom, nodes[newNode]); } roomsGenerated++; } //We have a wait time between generations to allow for rooms to detect collisions and destroy nodes. yield return(new WaitForSeconds(waitTime)); //Find the nodes that still exist. nodes = Find("node_spawn"); nodes_center = Find("node_center"); if (nodes.Length < 1 && roomsGenerated < dungeonSize) { yield return(StartCoroutine("RevertStep")); // yield return new WaitForSeconds(3f); } } //Possible places to put an exit door GameObject[] possibleExits = GameObject.FindGameObjectsWithTag("node_exit"); int newExit = handler.randomValue(0, possibleExits.Length); //Instantiate the Goal Point GameObject dungeonExit = Instantiate(exit, possibleExits[newExit].transform.position, exit.transform.rotation); dungeonExit.transform.SetParent(transform); Debug.Log("Dungeon Complete!"); gm.levelStart(); }