Esempio n. 1
0
        void OnLeftRoom()
        {
            Gamemodes.CurrentMode.CleanUp();

            PhotonNetwork.SetPlayerCustomProperties(null);

            DiscordRPC.SetPresence(new Discord.Activity
            {
                Details = "Idle..."
            });
        }
Esempio n. 2
0
        void OnLevelWasLoaded(int level)
        {
            ApplyCustomRenderSettings();

            if (IN_GAME_MAIN_CAMERA.Gametype == GameType.Singleplayer || PhotonNetwork.offlineMode)
            {
                string difficulty = IN_GAME_MAIN_CAMERA.Difficulty switch
                {
                    0 => "Normal",
                    1 => "Hard",
                    2 => "Abnormal",
                    _ => "Training"
                };

                DiscordRPC.SetPresence(new Discord.Activity
                {
                    Details = $"Playing offline.",
                    State   = $"{FengGameManagerMKII.Level.Name} / {difficulty}"
                });
            }

            if (PhotonNetwork.isMasterClient)
            {
                Gamemodes.CurrentMode.OnReset();
            }

            if (HasJoinedRoom)
            {
                return;
            }
            HasJoinedRoom = true;

            string joinMessage = Properties.JoinMessage.Value.NGUIToUnity();

            if (joinMessage.StripNGUI().Length < 1)
            {
                joinMessage = Properties.JoinMessage.Value;
            }

            if (joinMessage.Length < 1)
            {
                return;
            }
            Commands.Find("say").Execute(InRoomChat.Instance, joinMessage.Split(' '));
        }

        void OnPhotonPlayerConnected(PhotonPlayer player)
        {
            if (PhotonNetwork.isMasterClient)
            {
                Gamemodes.CurrentMode.OnPlayerJoin(player);
            }

            Logger.Info($"({player.Id}) " + player.Username.NGUIToUnity() + " connected.".AsColor("00FF00"));
        }

        void OnPhotonPlayerDisconnected(PhotonPlayer player)
        {
            if (PhotonNetwork.isMasterClient)
            {
                Gamemodes.CurrentMode.OnPlayerLeave(player);
            }

            Logger.Info($"({player.Id}) " + player.Username.NGUIToUnity() + " disconnected.".AsColor("FF0000"));
        }

        void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
        {
            NetworkChecker.OnPlayerPropertyModification(playerAndUpdatedProps);

            ModDetector.OnPlayerPropertyModification(playerAndUpdatedProps);
        }

        void OnPhotonCustomRoomPropertiesChanged(ExitGames.Client.Photon.Hashtable propertiesThatChanged)
        {
            NetworkChecker.OnRoomPropertyModification(propertiesThatChanged);

            PhotonPlayer sender = null;

            if (propertiesThatChanged.ContainsKey("sender") && propertiesThatChanged["sender"] is PhotonPlayer player)
            {
                sender = player;
            }

            if (sender != null && !sender.isMasterClient)
            {
                return;
            }

            if (propertiesThatChanged.ContainsKey("Map") && propertiesThatChanged["Map"] is string mapName)
            {
                LevelInfo levelInfo = LevelInfo.GetInfo(mapName);
                if (levelInfo != null)
                {
                    FengGameManagerMKII.Level = levelInfo;
                }
            }

            if (propertiesThatChanged.ContainsKey("Lighting") && propertiesThatChanged["Lighting"] is string lightLevel &&
                GExtensions.TryParseEnum(lightLevel, out DayLight time))
            {
                Camera.main.GetComponent <IN_GAME_MAIN_CAMERA>().SetLighting(time);
            }
        }

        void OnJoinedLobby()
        {
            // TODO: Begin working on Friend system with Photon Friend API
            PhotonNetwork.playerName = Properties.PhotonUserId.Value;
        }

        void OnJoinedRoom()
        {
            HasJoinedRoom = false;

            // TODO: Potentially use custom event/group combo to sync game-settings whilst not triggering other mods
            int[] groups = new int[byte.MaxValue];
            for (int i = 0; i < byte.MaxValue; i++)
            {
                groups[i] = i + 1;
            }
            PhotonNetwork.SetReceivingEnabled(groups, null);
            PhotonNetwork.SetSendingEnabled(groups, null);

            PhotonNetwork.player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable
            {
                { CustomPropertyName, Build }
            });

            StartCoroutine(CoUpdateMyPing());

            string[] roomInfo = PhotonNetwork.room.name.Split('`');
            if (roomInfo.Length < 7)
            {
                return;
            }

            DiscordRPC.SetPresence(new Discord.Activity
            {
                Details = $"Playing in {(roomInfo[5].Length < 1 ? string.Empty : "[PWD]")} {roomInfo[0].StripNGUI()}",
                State   = $"({NetworkHelper.GetRegionCode().ToUpper()}) {roomInfo[1]} / {roomInfo[2].ToUpper()}"
            });
        }