Exemple #1
0
        public void SetPosAndCycle()
        {
            Vector3 diffVec = sensingTarget.transform.position - PlayerController.LocalPlayer.transform.position;

            float dist = diffVec.magnitude;

            dist = Mathf.Min(dist, maxSensingDist);
            float m = (maxSensingDist - dist) / maxSensingDist;

            alphaChangeSpeed = 0.5f + 4.5f * m;
            float signScale = 1.0f + 2.0f * m;

            float angle = GlobalFunctions.GetAngle(diffVec, new Vector2());

            if (angle >= quadrantAngles[2] && angle < quadrantAngles[3])
            {
                m = (-Screen.height / 2) / diffVec.y;
            }
            else if (angle >= quadrantAngles[3] && angle < quadrantAngles[0])
            {
                m = (Screen.width / 2) / diffVec.x;
            }
            else if (angle >= quadrantAngles[0] && angle < quadrantAngles[1])
            {
                m = (Screen.height / 2) / diffVec.y;
            }
            else
            {
                m = (-Screen.width / 2) / diffVec.x;
            }

            sameFloorSign.rectTransform.anchoredPosition = diffVec * m;
            sameFloorSign.rectTransform.localScale       = new Vector3(signScale, signScale);
            upstairGroup.anchoredPosition   = diffVec * m - new Vector3(0f, upstairGroup.rect.height / 2);
            downstairGroup.anchoredPosition = diffVec * m + new Vector3(0f, downstairGroup.rect.height / 2);
        }
Exemple #2
0
 public void InitNPCGenPoint()
 {
     assignedPointNum = 0;
     GlobalFunctions.RandomizeArray <int>(NPCGenPointSelector);
 }
Exemple #3
0
        private void Awake()
        {
            Debug.Assert(!PhotonNetwork.connected, "Multiplay manager must be used in online environment.");

            // Modify PhotonNetwork settings according to in-game mode.
            PhotonNetwork.BackgroundTimeout   = 1000f;
            PhotonNetwork.sendRate            = 10;
            PhotonNetwork.sendRateOnSerialize = 10;

            //Set the singleton
            Debug.Assert(instance != null, "Multiple instantiation of the room Manager.");
            instance = this;

            mapDataManager = MapDataManager.Instance;
            uiManager      = UIManager.Instance;

            Hashtable roomCp = PhotonNetwork.room.CustomProperties;

            //Get the number of NPCs(only in test version).
            int tempNPCNum;

            if (int.TryParse(roomCp[Constants.NPCNumKey].ToString(), out tempNPCNum))
            {
                NPCNum = tempNPCNum;
            }

            //Get the number of thief players.
            if (!int.TryParse(roomCp["Thieves Number"].ToString(), out thievesNum))
            {
                Debug.LogError("Thieves number(in custom property) is not set properly.");
                return;
            }

            PhotonExtends.SetLocalPlayerProp(pauseKey, false);

            if (PhotonNetwork.isMasterClient)
            {
                //Randomly switch the master client. It prevents that the player who made room always be picked as a thief.
                int[] randomPlayerSelector = new int[PhotonNetwork.playerList.Length];
                for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
                {
                    randomPlayerSelector[i] = PhotonNetwork.playerList[i].ID;
                }

                GlobalFunctions.RandomizeArray <int>(randomPlayerSelector);

                if (randomPlayerSelector[0] == PhotonNetwork.player.ID)
                {
                    SetTeamOfPlayers();
                }
                else
                {
                    Debug.Log("Change the master client.");

                    for (int i = 0; i < randomPlayerSelector.Length; i++)
                    {
                        PhotonPlayer newMaster = PhotonPlayer.Find(randomPlayerSelector[i]);
                        if (newMaster != null &&
                            newMaster.CustomProperties[pauseKey] != null && !(bool)newMaster.CustomProperties[pauseKey])
                        {
                            PhotonNetwork.SetMasterClient(newMaster);
                            break;
                        }
                    }
                }
            }
        }
Exemple #4
0
        private void Awake()
        {
            maxRandomValue = rooms.Count - 1;
            foreach (StairRouteContainer container in stairToStairRoutes)
            {
                if (container.LeftDownRoutes.Length != 0 &&
                    maxRandomValue % container.LeftDownRoutes.Length != 0)
                {
                    maxRandomValue *= container.LeftDownRoutes.Length;
                }
                if (container.LeftUpRoutes.Length != 0 &&
                    maxRandomValue % container.LeftUpRoutes.Length != 0)
                {
                    maxRandomValue *= container.LeftUpRoutes.Length;
                }
                if (container.RightDownRoutes.Length != 0 &&
                    maxRandomValue % container.RightDownRoutes.Length != 0)
                {
                    maxRandomValue *= container.RightDownRoutes.Length;
                }
                if (container.RightUpRoutes.Length != 0 &&
                    maxRandomValue % container.RightUpRoutes.Length != 0)
                {
                    maxRandomValue *= container.RightUpRoutes.Length;
                }
            }

            List <Route> NPCGenRoutes = new List <Route>();

            nPCGenPoints = new List <RouteNode>();

            int genPointCnt = 0;

            foreach (ExhibitRoom room in rooms)
            {
                //Find all NPC-generatable routes and make all routes set.
                NPCGenRoutes.Add(room.InRoomRoute);

                foreach (List <Route> routes in room.ToRoomRoutes.Values)
                {
                    NPCGenRoutes.AddRange(routes);

                    if (maxRandomValue % routes.Count != 0)
                    {
                        maxRandomValue *= routes.Count;
                    }
                }

                NPCGenRoutes.AddRange(room.FromStairRoutes.LeftDownRoutes);
                NPCGenRoutes.AddRange(room.FromStairRoutes.LeftUpRoutes);
                NPCGenRoutes.AddRange(room.FromStairRoutes.RightDownRoutes);
                NPCGenRoutes.AddRange(room.FromStairRoutes.RightUpRoutes);

                if (room.FromStairRoutes.LeftDownRoutes.Length != 0 &&
                    maxRandomValue % room.FromStairRoutes.LeftDownRoutes.Length != 0)
                {
                    maxRandomValue *= room.FromStairRoutes.LeftDownRoutes.Length;
                }
                if (room.FromStairRoutes.LeftUpRoutes.Length != 0 &&
                    maxRandomValue % room.FromStairRoutes.LeftUpRoutes.Length != 0)
                {
                    maxRandomValue *= room.FromStairRoutes.LeftUpRoutes.Length;
                }
                if (room.FromStairRoutes.RightDownRoutes.Length != 0 &&
                    maxRandomValue % room.FromStairRoutes.RightDownRoutes.Length != 0)
                {
                    maxRandomValue *= room.FromStairRoutes.RightDownRoutes.Length;
                }
                if (room.FromStairRoutes.RightUpRoutes.Length != 0 &&
                    maxRandomValue % room.FromStairRoutes.RightUpRoutes.Length != 0)
                {
                    maxRandomValue *= room.FromStairRoutes.RightUpRoutes.Length;
                }

                if (room.ToStairRoutes.LeftDownRoutes.Length != 0 &&
                    maxRandomValue % room.ToStairRoutes.LeftDownRoutes.Length != 0)
                {
                    maxRandomValue *= room.ToStairRoutes.LeftDownRoutes.Length;
                }
                if (room.ToStairRoutes.LeftUpRoutes.Length != 0 &&
                    maxRandomValue % room.ToStairRoutes.LeftUpRoutes.Length != 0)
                {
                    maxRandomValue *= room.ToStairRoutes.LeftUpRoutes.Length;
                }
                if (room.ToStairRoutes.RightDownRoutes.Length != 0 &&
                    maxRandomValue % room.ToStairRoutes.RightDownRoutes.Length != 0)
                {
                    maxRandomValue *= room.ToStairRoutes.RightDownRoutes.Length;
                }
                if (room.ToStairRoutes.RightUpRoutes.Length != 0 &&
                    maxRandomValue % room.ToStairRoutes.RightUpRoutes.Length != 0)
                {
                    maxRandomValue *= room.ToStairRoutes.RightUpRoutes.Length;
                }

                //Find all Item Generation Points
                foreach (ItemGenPoint itemGenPoint in room.ItemGenPoints)
                {
                    itemGenPoint.Index = genPointCnt++;
                    itemGenPoints.Add(itemGenPoint);
                }
            }

            List <Vector3> assignedLoc = new List <Vector3>();

            foreach (Route route in NPCGenRoutes)
            {
                for (int i = 1; i < route.NodeSet.Length - 1; i++)
                {
                    Vector3 nodeLoc = route.NodeSet[i].DefaultPos;
                    if (!assignedLoc.Contains(nodeLoc))
                    {
                        nPCGenPoints.Add(route.NodeSet[i]);
                        assignedLoc.Add(nodeLoc);
                    }
                }
            }

            NPCGenPointSelector = new int[nPCGenPoints.Count];
            for (int i = 0; i < nPCGenPoints.Count; i++)
            {
                NPCGenPointSelector[i] = i;
            }

            GlobalFunctions.RandomizeArray <int>(NPCGenPointSelector);

            //Routing Manager Singlton 생성
            if (instance == null)
            {
                instance = this;
            }
            else
            {
                Debug.Log("Error: Multiple instantiation of the routing manager.");
            }
        }
Exemple #5
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);
            }
        }