Example #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]);
            }
        }
Example #2
0
 void Start()
 {
     //오프라인 테스트시 수동으로 생성하는 인스턴스에 대한 초기화
     if (mapDataManager == null)
     {
         mapDataManager = MapDataManager.Instance;
     }
 }
Example #3
0
        public void Init(int genPointIdx)
        {
            mapDataManager = MapDataManager.Instance;

            RouteNode genPoint = mapDataManager.NPCGenPoints[genPointIdx];

            curRoute = genPoint.gameObject.GetComponentInParent <Route>();

            switch (curRoute.RouteType)
            {
            case ERouteType.In_Room:
                nextRoom = curRoute.CurRoom;
                break;

            case ERouteType.Room_to_Room:
            case ERouteType.Stair_to_Room:
                nextRoom = curRoute.EndRoom;
                break;

            default:
                Debug.LogError("Route type error.");
                break;
            }

            curFloor = mapDataManager.Rooms[nextRoom].Floor;
            for (int i = 0; i < curRoute.NodeSet.Length; i++)
            {
                if (genPoint == curRoute.NodeSet[i])
                {
                    curNodeNum = i;
                    break;
                }
            }

            targetPoint = startPoint = transform.position = (Vector2)curRoute.NodeSet[curNodeNum].DefaultPos;
        }
Example #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.");
            }
        }
Example #5
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;
                        }
                    }
                }
            }
        }