Ejemplo n.º 1
0
        void RandomItemGeneration()
        {
            for (int i = 0; i < itemNum; i++)
            {
                int r1 = Random.Range(0, itemNum);
                int r2 = Random.Range(0, itemNum);

                GameObject temp = itemPrefabs[r1];
                itemPrefabs[r1] = itemPrefabs[r2];
                itemPrefabs[r2] = temp;
            }

            MapDataManager mapDataManager = MapDataManager.Instance;

            if (mapDataManager.ItemGenPoints.Count > itemNum)
            {
                Debug.LogError("There are fewer items than generation points.");
                return;
            }

            for (int i = 0; i < mapDataManager.ItemGenPoints.Count; i++)
            {
                GameObject newItem = Instantiate(itemPrefabs[i], mapDataManager.ItemGenPoints[i].transform.position, Quaternion.identity);

                ExhibitRoom roomOfItem = mapDataManager.ItemGenPoints[i].GetComponentInParent <ExhibitRoom>();
                //newItem.GetComponent<ItemController>().Init(roomOfItem.Floor, mapDataManager.Rooms.FindIndex(room => room == roomOfItem), i, new int[1]);
            }
        }
Ejemplo n.º 2
0
 private void Awake()
 {
     room = GetComponentInParent <ExhibitRoom>();
     if (room == null)
     {
         Debug.LogError("Error in ItemGenPoint " + gameObject.GetInstanceID());
         Debug.LogError("An Item generation point should be a child of an exhibit room.");
         return;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Generate items at generation points randomly.
        /// </summary>
        private void GenerateItems()
        {
            // Initialize variables related to items.
            int numOfItems        = itemPrefabs.Length;
            int numOfItemGenPoint = mapDataManager.ItemGenPoints.Count;

            if (numOfItemGenPoint > numOfItems)
            {
                Debug.LogError("There are fewer items than generation points.");
                return;
            }
            if (numOfItemGenPoint < targetItemNum)
            {
                Debug.LogError("The number of items to steal can't exceed the number of all items in the level.");
                return;
            }

            // Select the target item property and divide the item prefab list
            // to the group which has that property and the group which doesn't have.
            // issue: 카테고리 및 속성 번호를 수동으로 지정, 이후 enum 활용식 혹은 다른 방법 고안 필요.
            int category     = Random.Range(0, 3);
            int selectedProp = Random.Range(0, 3);

            switch (category)
            {
            case 0:
                Debug.Log("Selected property: " + (EItemColor)selectedProp);
                break;

            case 1:
                Debug.Log("Selected property: " + (EItemAge)selectedProp);
                break;

            case 2:
                Debug.Log("Selected property: " + (EItemUsage)selectedProp);
                break;
            }

            List <GameObject> ItemsHaveProp = new List <GameObject>();

            foreach (GameObject item in itemPrefabs)
            {
                ItemController itemController = item.GetComponent <ItemController>();
                //issue: Error
                if (itemController == null)
                {
                    Debug.LogError("The prefab name " + item.name + " in item list doesn't have ItemContorller.");
                    return;
                }

                switch (category)
                {
                case 0:
                    if (itemController.Color == (EItemColor)selectedProp)
                    {
                        ItemsHaveProp.Add(item);
                    }
                    break;

                case 1:
                    if (itemController.Age == (EItemAge)selectedProp)
                    {
                        ItemsHaveProp.Add(item);
                    }
                    break;

                case 2:
                    if (itemController.Usage == (EItemUsage)selectedProp)
                    {
                        ItemsHaveProp.Add(item);
                    }
                    break;
                }
            }


            // Select steal target/non-target items to generate;
            GlobalFunctions.RandomizeList <GameObject>(ItemsHaveProp);
            List <GameObject> targetItems = new List <GameObject>();

            for (int i = 0; i < targetItemNum; i++)
            {
                targetItems.Add(ItemsHaveProp[i]);
            }

            List <GameObject> nonTargetItems = new List <GameObject>();

            for (int i = 0; i < numOfItems; i++)
            {
                if (!targetItems.Contains(itemPrefabs[i]))
                {
                    nonTargetItems.Add(itemPrefabs[i]);
                }
            }
            GlobalFunctions.RandomizeList <GameObject>(nonTargetItems);


            // Select generation points where the target items are generated.
            int[] targetItemPointSelector = new int[numOfItemGenPoint];
            for (int i = 0; i < numOfItemGenPoint; i++)
            {
                targetItemPointSelector[i] = i;
            }
            GlobalFunctions.RandomizeArray <int>(targetItemPointSelector);

            List <int>         targetItemPoints      = new List <int>();
            List <ExhibitRoom> roomContainTargetItem = new List <ExhibitRoom>();

            for (int i = 0; i < numOfItemGenPoint; i++)
            {
                // Not allow the case in which multiple items in a same room.
                ExhibitRoom roomOfPoint = mapDataManager.ItemGenPoints[targetItemPointSelector[i]].GetComponentInParent <ExhibitRoom>();
                if (!roomContainTargetItem.Contains(roomOfPoint))
                {
                    targetItemPoints.Add(targetItemPointSelector[i]);
                    roomContainTargetItem.Add(roomOfPoint);
                    if (targetItemPoints.Count == targetItemNum)
                    {
                        break;
                    }
                }
            }
            if (targetItemPoints.Count != targetItemNum)
            {
                Debug.LogError("There are not enough rooms for item generation.");
                return;
            }

            // Generate items.
            for (int i = 0; i < numOfItemGenPoint; i++)
            {
                GameObject newItemPrefab;
                if (targetItemPoints.Contains(i))
                {
                    newItemPrefab = targetItems[0];
                    targetItems.RemoveAt(0);
                }
                else
                {
                    newItemPrefab = nonTargetItems[0];
                    nonTargetItems.RemoveAt(0);
                }

                GameObject newItem = PhotonNetwork.InstantiateSceneObject("Items\\" + newItemPrefab.name,
                                                                          mapDataManager.ItemGenPoints[i].ItemPos, Quaternion.identity, 0, null);
                PhotonView.Get(newItem).RPC("Init", PhotonTargets.All, i);
            }

            photonView.RPC("SetTargetItemList", PhotonTargets.All, targetItemPoints.ToArray());

            // Select put item point to activate in this game.
            Dictionary <int, List <int> > roomsInFloor = new Dictionary <int, List <int> >();

            for (int i = 0; i < mapDataManager.Rooms.Count; i++)
            {
                ExhibitRoom room = mapDataManager.Rooms[i];

                if (!roomsInFloor.ContainsKey(room.Floor))
                {
                    roomsInFloor[room.Floor] = new List <int>();
                }
                roomsInFloor[room.Floor].Add(i);
            }

            foreach (int floor in roomsInFloor.Keys)
            {
                int r               = Random.Range(0, roomsInFloor[floor].Count);
                int randRoomIdx     = roomsInFloor[floor][r];
                int randPutPointIdx = Random.Range(0, mapDataManager.Rooms[randRoomIdx].PutItemPoints.Length);
                //issue: 인덱스 오류남
                photonView.RPC("ActivatePutItemPointInRoom", PhotonTargets.All, randRoomIdx, randPutPointIdx);
            }
        }