Exemple #1
0
        /// <summary>
        /// Generates specific values for the DungeonType.
        /// </summary>
        /// <param name="room">The current room.</param>
        /// <param name="dungeonRoomObject">The gameobject to which the room should be generate don.</param>
        /// <param name="levelNumber">The number of the level.</param>
        /// <returns>The fully generated DungeonRoom.</returns>
        private DungeonRoom SetRoomType(Room room, GameObject dungeonRoomObject, int levelNumber, DungeonConfig config)
        {
            switch (room.Type)
            {
            case RoomType.Start:
                StartRoom startRoom = dungeonRoomObject.AddComponent <StartRoom>();
                if (Player.LocalPlayer.isServer && levelNumber == 0)
                {
                    startRoom.SpawnItems(RegionDict.Instance.StartingRoomPickables, DungeonCreator.Instance.TilePositionToWorldPosition(room.Position + (room.Layout.Size / 2)));
                }
                return(startRoom);

            case RoomType.Combat:
                CombatRoom combatRoom = dungeonRoomObject.AddComponent <CombatRoom>();
                combatRoom.ThreatLevel    = room.TileCount;
                combatRoom.enemiesToSpawn = new EnemyObject[combatRoom.ThreatLevel / 48];
                for (int j = 0; j < combatRoom.enemiesToSpawn.Length; j++)
                {
                    combatRoom.enemiesToSpawn[j] = RandomUtil.Element(RegionDict.Instance.EnemiesToSpawn);
                }
                return(combatRoom);

            case RoomType.Loot:
                LootRoom lootRoom = dungeonRoomObject.AddComponent <LootRoom>();
                lootRoom.pickables = new Pickable[room.TileCount / 48];
                for (int j = 0; j < lootRoom.pickables.Length; j++)
                {
                    lootRoom.pickables[j] = RandomUtil.Element(RegionDict.Instance.LootingRoomPickables);
                }
                return(lootRoom);

            case RoomType.Shop:
                ShopRoom  shopRoom = dungeonRoomObject.AddComponent <ShopRoom>();
                const int numItems = 4;
                shopRoom.shopItems = new Pickable[numItems];
                shopRoom.locations = new Vector2[numItems];
                // TODO: Replace Pickabledict with dungeon config shop pickables.
                for (int j = 0; j < numItems; j++)
                {
                    int rnd = Random.Range(0, config.shopItems.Length);
                    shopRoom.shopItems[j] = config.shopItems[rnd];
                    shopRoom.locations[j] = room.Position + new Vector2Int((int)room.GameObjects[j + 4].Position.x, (int)room.GameObjects[j + 4].Position.y);
                }
                shopRoom.SpawnItems();
                return(shopRoom);

            case RoomType.Boss:
                BossRoom bossRoom = dungeonRoomObject.AddComponent <BossRoom>();
                bossRoom.bossObjects = new BossObject[] { RandomUtil.Element(RegionDict.Instance.BossesToSpawn) };
                DungeonDict.Instance.SetBossRoom(bossRoom);
                return(bossRoom);

            case RoomType.Empty:
                EmptyRoom emptyRoom = dungeonRoomObject.AddComponent <EmptyRoom>();
                return(emptyRoom);

            default:
                throw new System.Exception("Unknown room type! (" + room.Type + ")");
            }
        }
Exemple #2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (NetworkServer.active == false ||
            collision.gameObject.TryGetComponent(out Player _) == false)
        {
            return;
        }

        PickableInWorld.Place(RandomUtil.Element(toSpawnWeapons), transform.position + gunSpawnPoint);
    }
Exemple #3
0
    private Player JoinCreateNewPlayer(NetworkConnection connection, JoinMessage joinMessage)
    {
        Player newPlayer = Instantiate(CharacterDict.Instance.GetPlayerForType(joinMessage.characterType));

        newPlayer.SmoothSync.setPosition(
            RandomUtil.Element(startPositions).position,
            true
            );
        newPlayer.playerId         = connection.connectionId;
        newPlayer.uniqueIdentifier = joinMessage.uniqueIdentifier;
        return(newPlayer);
    }
Exemple #4
0
    private void spawnRooms()
    {
        Transform roomFolder = new GameObject("Rooms").transform;

        roomFolder.parent = transform;
        var        roomPrefabs = new List <Object>(Resources.LoadAll("Rooms"));
        GameObject startPrefab = roomPrefabWithName(startRoomName, roomPrefabs);

        roomPrefabs.Remove(startPrefab);

        for (int i = 0; i < width; ++i)
        {
            for (int j = 0; j < height; ++j)
            {
                Room room = rooms[i, j];
                if (room != null)
                {
                    GameObject prefab;
                    if (room.isStartRoom)
                    {
                        prefab = startPrefab;
                    }
                    else
                    {
                        prefab = RandomUtil.Element(roomPrefabs) as GameObject;
                    }

                    GameObject roomObject = Instantiate(prefab);
                    roomObject.name = string.Format("({1}, {2}) {0}", prefab.name, i, j);
                    roomObject.transform.position = positionForRoom(i, j);
                    roomObject.transform.parent   = roomFolder;

                    var roomAware = roomObject.GetComponentsInChildren <RoomAwareComponent>();
                    foreach (RoomAwareComponent aware in roomAware)
                    {
                        aware.SetRoom(room);
                    }
                }
            }
        }
    }
Exemple #5
0
 private void Start()
 {
     Config.Instance.PlayerName = RandomUtil.Element(names);
     Debug.Log("Set random name! Name is now: " + Config.Instance.PlayerName);
 }