コード例 #1
0
ファイル: FacilitySpawner.cs プロジェクト: wolfrug/ldjam43
 void CountDownFacilityList(FacilityRoom target, int amount)
 {
     target.amount -= amount;
     Debug.LogWarning("Removed " + amount + " of Facility Room " + target.roomName_ + " Remaining: " + target.amount);
     if (target.amount < 1)
     {
         facilityRooms_.Remove(target);
         facilityRooms_.RemoveAll(item => item == null);
         Debug.LogWarning("Last room of type " + target.roomName_ + " placed!");
     }
 }
コード例 #2
0
ファイル: FacilitySpawner.cs プロジェクト: wolfrug/ldjam43
 FacilityRoom GetRandomFacilityRoom(bool countDownAndRemove = false)
 {// Gets a random facility room from all available ones
     if (facilityRooms_.Count > 0)
     {
         FacilityRoom randomFR = facilityRooms_[Random.Range(0, facilityRooms_.Count)];
         if (countDownAndRemove)
         { // Count down the amount and remove the room if there's now less than 1
             CountDownFacilityList(randomFR, 1);
         }
         return(randomFR);
     }
     else
     {
         return(null);
     }
 }
コード例 #3
0
 private Facility(FacilityRoom facilityRoom)
 {
     DebugHelper.Log("Found gameplay room of type Facility Room");
     _facilityRoom = facilityRoom;
 }
コード例 #4
0
 private Facility(FacilityRoom facilityRoom)
 {
     _facilityRoom = facilityRoom;
 }
コード例 #5
0
        public static void PopulateDatabase()
        {
            List <DateTime> rangePeriodList = GetPeriodVacation();

            using (var context = new ModelContext())
            {
                try
                {
                    User user = new User();
                    user.Username = "******";
                    user.Password = "******";
                    context.Users.Add(user);
                    context.SaveChanges();

                    County county = new County();
                    county.Name = "Brasov";
                    context.Counties.Add(county);
                    context.SaveChanges();

                    County county2 = new County();
                    county2.Name = "Maramures";
                    context.Counties.Add(county2);
                    context.SaveChanges();

                    City city = new City();
                    city.Name   = "Rasnov";
                    city.County = context.Counties.FirstOrDefault(c => c.CountyId == 1);
                    context.Cities.Add(city);
                    context.SaveChanges();

                    City city2 = new City();
                    city2.Name  = "Baia Mare";
                    city.County = context.Counties.FirstOrDefault(c => c.CountyId == 2);
                    context.Cities.Add(city2);
                    context.SaveChanges();

                    Hotel hotel = new Hotel();
                    hotel.Name = "Pensiunea Fermecata";
                    hotel.City = context.Cities.FirstOrDefault(c => c.CityId == 1);
                    context.Hotels.Add(hotel);

                    Hotel hotel2 = new Hotel();
                    hotel2.Name = "Norocul plutitor";
                    hotel2.City = context.Cities.FirstOrDefault(c => c.CityId == 2);
                    context.Hotels.Add(hotel2);
                    context.SaveChanges();

                    RoomType singleRoomType = new RoomType();
                    singleRoomType.Name = "Single";
                    context.RoomTypes.Add(singleRoomType);
                    context.SaveChanges();

                    RoomType doubleRoomType = new RoomType();
                    doubleRoomType.Name = "Double";
                    context.RoomTypes.Add(doubleRoomType);
                    context.SaveChanges();

                    Facility facility = new Facility();
                    facility.Name = "Air conditioner";
                    context.Facilities.Add(facility);
                    context.SaveChanges();

                    Facility facility2 = new Facility();
                    facility2.Name = "Plasma TV";
                    context.Facilities.Add(facility2);
                    context.SaveChanges();

                    Facility facility3 = new Facility();
                    facility3.Name = "Big Balcony";
                    context.Facilities.Add(facility3);
                    context.SaveChanges();

                    Facility facility4 = new Facility();
                    facility4.Name = "Refrigerator";
                    context.Facilities.Add(facility4);
                    context.SaveChanges();

                    Room room = new Room();
                    room.Price    = 180;
                    room.Hotel    = context.Hotels.FirstOrDefault(h => h.HotelId == 1);
                    room.RoomType = context.RoomTypes.FirstOrDefault(rt => rt.RoomTypeId == 1);
                    context.Rooms.Add(room);
                    context.SaveChanges();

                    Room room2 = new Room();
                    room2.Price    = 300;
                    room2.Hotel    = context.Hotels.FirstOrDefault(h => h.HotelId == 2);
                    room2.RoomType = context.RoomTypes.FirstOrDefault(rt => rt.RoomTypeId == 2);
                    context.Rooms.Add(room2);
                    context.SaveChanges();

                    Rezervation rezervation = new Rezervation();
                    rezervation.User     = context.Users.FirstOrDefault(u => u.UserId == 1);
                    rezervation.CheckIn  = rangePeriodList[0];
                    rezervation.CheckOut = rangePeriodList[1];
                    context.Rezervations.Add(rezervation);
                    context.SaveChanges();

                    var rezerv = new Rezervation()
                    {
                        CheckIn = rangePeriodList[0], CheckOut = rangePeriodList[1]
                    };
                    var specialRoom = new Room()
                    {
                        Price = 245
                    };
                    RezervationRoom rezervRoom = new RezervationRoom();
                    rezervRoom.Rezervation = rezerv;
                    rezervRoom.Room        = room;
                    context.RezervationRooms.Add(rezervRoom);
                    context.SaveChanges();

                    FacilityRoom facilRoom = new FacilityRoom();
                    facilRoom.Facility = context.Facilities.FirstOrDefault(f => f.FacilityId == 1);
                    facilRoom.Room     = context.Rooms.FirstOrDefault(r => r.RoomId == 1);
                    context.FacilityRooms.Add(facilRoom);
                    context.SaveChanges();
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
コード例 #6
0
ファイル: FacilitySpawner.cs プロジェクト: wolfrug/ldjam43
    IEnumerator SpawnFacility()
    { // Spawns the facility, with one random facility room as the first and last placed
        Debug.LogWarning("SPAWNFACILITY COROUTINE RUNNING: THIS WARNING SHOULD ONLY HAPPEN ONCE");
        FacilityRoom firstRoom = GetRandomFacilityRoom(true);
        Room         FRRoom    = SpawnRoom(firstRoom.room);

        FRRoom.coordinate_ = new Vector2(0, 0);
        facilityObjects_.Add(FRRoom.gameObject);
        coordinates_.Add(FRRoom, new Vector2(0, 0));
        roomsUntilFacilityRoom = data_.connectiveRoomAmount_;
        facilityRooms         -= 1;
        roomsSpawned          += 1;

        // This is where the next room will be spawned
        Room     previousRoom = FRRoom;
        Exits    nextExit     = Exits.NONE;
        RoomData nextRoom     = null;

        while (facilityRooms > 0)
        {
            yield return(new WaitForSeconds(0.1f));

            // Get the next random connective room that fits the previous exit
            nextExit = previousRoom.GetRandomFreeConnection();
            if (nextExit == Exits.NONE)
            {
                Debug.LogWarning("No more free exits, looking for other exits further back...");
                for (int i = 0; i < facilityObjects_.Count; i++)
                {
                    nextExit = facilityObjects_[i].GetComponent <Room>().GetRandomFreeConnection();
                    if (nextExit != Exits.NONE)
                    {
                        previousRoom = facilityObjects_[i].GetComponent <Room>();
                        break;
                    }
                }
                if (nextExit == Exits.NONE)
                {
                    if (facilityRooms <= 0)
                    {
                        Debug.LogWarning("Couldn't find any more free exits. Oh well");
                        break;
                    }
                    else
                    {// F****d up - restart whole facility generation!
                        DespawnFacility(true);
                    }
                }
            }
            if (roomsUntilFacilityRoom <= 0)
            {
                FacilityRoom randomFC = GetRandomFacilityRoom();
                if (randomFC != null)
                {
                    if (randomFC.room.ContainsExit(GetOppositeExit(nextExit)))
                    {
                        nextRoom = randomFC.room;
                        nextRoomIsFacilityRoom = true;
                    }
                    else
                    {
                        nextRoom = GetRandomConnectiveRoom(GetOppositeExit(randomFC.room.GetRandomExit()));
                    }
                }
            }
            else
            {
                nextRoom = GetRandomConnectiveRoom(GetOppositeExit(nextExit));
            }
            if (nextRoom != null)
            {
                // Spawn it, and connect it to the previous room
                Room nextRoomRoom = SpawnRoom(nextRoom, previousRoom, GetOppositeExit(nextExit));
                if (nextRoomRoom != null)
                {
                    //Debug.Log(returnRoomGO);
                    if (previousRoom != null)
                    {
                        /*if (previousRoom.AttemptConnectRoom(nextRoomRoom, nextExit, true))
                         * {*/
                        coordinates_.Add(nextRoomRoom, GetNewCoordinates(coordinates_[previousRoom], nextExit));
                        previousRoom = nextRoomRoom;
                        facilityObjects_.Add(nextRoomRoom.gameObject);
                        roomsSpawned += 1;
                        if (nextRoomIsFacilityRoom)
                        { // Try to count it down, might not work because of...reasons. So check that first.
                            if (CountDownFacilityList(nextRoomRoom, 1))
                            {
                                facilityRooms         -= 1;
                                nextRoomIsFacilityRoom = false;
                                if (facilityRooms > 0)
                                {
                                    roomsUntilFacilityRoom = data_.connectiveRoomAmount_;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        roomsUntilFacilityRoom -= 1;

                        /*}
                         * else
                         * {
                         *  //Destroy(nextRoomRoom.gameObject);
                         * }*/
                    }
                }
                ;
            }
        }
        Debug.Log("FINISHED SPAWNING FACILITY!");
        allRooms_.Clear();
        foreach (KeyValuePair <Room, Vector2> pair in coordinates_)
        {
            allRooms_.Add(pair.Key);
        }
        // Attempt to finalize all connections between rooms
        foreach (Room room in allRooms_)
        {
            room.AttemptConnectAll(false);
            //yield return new WaitForSeconds(0.1f);
        }
        Debug.Log("FINISHED CONNECTING ALL");
        // Attempts to add a blocker (if found) to each remaining empty exit

        foreach (Room room in allRooms_)
        {
            foreach (Exits exit in room.GetAllFreeExits())
            {
                //yield return new WaitForSeconds(0.1f);
                bool     isTileEmpty       = !coordinates_.ContainsValue(GetNewCoordinates(coordinates_[room], exit));
                RoomData randomBlockerData = GetRandomBlockerRoom(GetOppositeExit(exit), isTileEmpty);
                if (randomBlockerData != null)
                {
                    Room blockerRoom = SpawnRoom(randomBlockerData, room, GetOppositeExit(exit));
                    if (room.AttemptConnectRoom(blockerRoom, exit, true))
                    {
                        coordinates_.Add(blockerRoom, GetNewCoordinates(coordinates_[room], nextExit));
                        facilityObjects_.Add(blockerRoom.gameObject);
                        roomsSpawned += 1;
                    }

                    /*else
                     * {
                     *  Destroy(blockerRoom.gameObject);
                     * }*/
                }
            }
        }
        Debug.Log("FINISHED ADDING BLOCKERS");
    }