Пример #1
0
    public BaseNetworkGameRule GetGameRule(string gameRuleName)
    {
        BaseNetworkGameRule result = null;

        gameRules.TryGetValue(gameRuleName, out result);
        return(result);
    }
 public override void OnStopClient()
 {
     base.OnStopClient();
     if (gameRule != null)
     {
         gameRule.OnStopConnection();
         gameRule = null;
     }
 }
    protected void ReadMsgGameRule(NetworkMessage netMsg)
    {
        var msg = netMsg.ReadMessage <OpMsgGameRule>();
        BaseNetworkGameRule foundGameRule;

        if (BaseNetworkGameInstance.GameRules.TryGetValue(msg.gameRuleName, out foundGameRule))
        {
            gameRule = foundGameRule;
            gameRule.InitialClientObjects(client);
        }
    }
    protected void ReadMsgGameRule(MessageHandlerData messageHandler)
    {
        if (IsServer)
        {
            return;
        }
        var msg = messageHandler.ReadMessage <OpMsgGameRule>();
        BaseNetworkGameRule foundGameRule;

        if (BaseNetworkGameInstance.GameRules.TryGetValue(msg.gameRuleName, out foundGameRule))
        {
            gameRule = foundGameRule;
            gameRule.InitialClientObjects(Client);
        }
    }
Пример #5
0
    protected virtual void StartSpawned()
    {
        Msf.Server.Spawners.RegisterSpawnedProcess(Msf.Args.SpawnId, Msf.Args.SpawnCode, (controller, error) =>
        {
            if (controller == null)
            {
                logger.Error("Failed to register a spawned process: " + error);
                throw new Exception("Failed to register a spawned process: " + error);
            }

            // Set the static object, so that it can be used when creating a room
            IOGamesRoom.SpawnTaskController = controller;

            if (Msf.Args.IsProvided(Msf.Args.Names.WebGl))
            {
                networkManager.useWebSockets = true;
            }

            var prop = controller.Properties;
            // Use the assigned port from cmd args
            networkManager.networkPort = Msf.Args.AssignedPort;

            // Setup game rules/configs
            var ioGamesModule            = FindObjectOfType <IOGamesModule>();
            BaseNetworkGameRule gameRule = null;
            if (prop.ContainsKey(IOGamesModule.GameRuleNameKey))
            {
                gameRule = ioGamesModule.GetGameRule(prop[IOGamesModule.GameRuleNameKey]);
                if (gameRule != null)
                {
                    gameRule.ReadConfigs(prop);
                }
            }
            networkManager.gameRule = gameRule;

            if (prop.ContainsKey(MsfDictKeys.MaxPlayers))
            {
                networkManager.maxConnections = int.Parse(prop[MsfDictKeys.MaxPlayers]);
            }

            // Start the server
            networkManager.StartServerAndQuitIfCannotListen();
        });
        return;
    }
    protected void InitGameRule(string gameRuleName)
    {
        BaseNetworkGameRule foundGameRule;

        if (BaseNetworkGameInstance.GameRules.TryGetValue(gameRuleName, out foundGameRule) && onlineSceneLoaded)
        {
            gameRule = foundGameRule;
            gameRule.InitialClientObjects();
            if (PhotonNetwork.IsMasterClient && !MasterStarted)
            {
                MasterStarted = true;
                gameRule.OnStartMaster(this);
            }
            if (!PhotonNetwork.IsMasterClient && !ClientStarted)
            {
                ClientStarted = true;
                gameRule.OnStartClient(this);
            }
        }
    }
    public void SetGameRule(BaseNetworkGameRule gameRule)
    {
        // If room not created, set data to field to use later
        this.gameRule = gameRule;
        if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
        {
            Hashtable customProperties = new Hashtable();
            customProperties[CUSTOM_ROOM_GAME_RULE]             = gameRule == null ? "" : gameRule.name;
            customProperties[CUSTOM_ROOM_GAME_RULE_BOT_COUNT]   = gameRule == null ? 0 : gameRule.botCount;
            customProperties[CUSTOM_ROOM_GAME_RULE_MATCH_TIME]  = gameRule == null ? 0 : gameRule.matchTime;
            customProperties[CUSTOM_ROOM_GAME_RULE_MATCH_KILL]  = gameRule == null ? 0 : gameRule.matchKill;
            customProperties[CUSTOM_ROOM_GAME_RULE_MATCH_SCORE] = gameRule == null ? 0 : gameRule.matchScore;
            PhotonNetwork.CurrentRoom.SetCustomProperties(customProperties);

            foreach (var player in PhotonNetwork.PlayerList)
            {
                SetPlayerTeam(player);
            }
        }
    }
Пример #8
0
    public override void OnOnlineSceneChanged()
    {
        if (isLog)
        {
            Debug.Log("OnOnlineSceneChanged");
        }
        // Reset last game/match data
        ResetGame();
        // Get game rule to initial client objects
        var customProperties = PhotonNetwork.room.CustomProperties;
        var gameRuleName     = (string)customProperties[CUSTOM_ROOM_GAME_RULE];
        BaseNetworkGameRule foundGameRule;

        if (BaseNetworkGameInstance.GameRules.TryGetValue(gameRuleName, out foundGameRule))
        {
            gameRule = foundGameRule;
            gameRule.InitialClientObjects();
            if (PhotonNetwork.isMasterClient && !startUpdateGameRule)
            {
                startUpdateGameRule = true;
                gameRule.OnStartServer(this);
            }
        }
    }
    public void SetData(NetworkDiscoveryData data)
    {
        Data = data;

        if (textRoomName != null)
        {
            textRoomName.text = string.IsNullOrEmpty(data.roomName) ? "Untitled" : data.roomName;
        }
        if (textPlayerName != null)
        {
            textPlayerName.text = data.playerName;
        }
        if (textSceneName != null)
        {
            textSceneName.text = BaseNetworkGameInstance.GetMapNameByScene(data.sceneName);
        }
        if (textPlayerCount != null)
        {
            textPlayerCount.text = data.numPlayers + "/" + data.maxPlayers;
        }
        if (textRoomState != null)
        {
            switch ((SimplePhotonNetworkManager.RoomState)data.state)
            {
            case SimplePhotonNetworkManager.RoomState.Waiting:
                textRoomState.text = roomStateWaiting;
                break;

            case SimplePhotonNetworkManager.RoomState.Playing:
                textRoomState.text = roomStatePlaying;
                break;
            }
        }

        BaseNetworkGameRule gameRule = null;

        if (textGameRule != null &&
            BaseNetworkGameInstance.GameRules.TryGetValue(data.gameRule, out gameRule))
        {
            textGameRule.text = gameRule == null ? "" : gameRule.Title;
        }

        if (textBotCount != null)
        {
            textBotCount.text = data.botCount.ToString("N0");
            textBotCount.gameObject.SetActive(gameRule != null && gameRule.HasOptionBotCount);
        }

        if (textMatchTime != null)
        {
            textMatchTime.text = data.matchTime.ToString("N0");
            textMatchTime.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchTime);
        }

        if (textMatchKill != null)
        {
            textMatchKill.text = data.matchKill.ToString("N0");
            textMatchKill.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchKill);
        }

        if (textMatchScore != null)
        {
            textMatchScore.text = data.matchScore.ToString("N0");
            textMatchScore.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchScore);
        }

        if (hasPasswordObject != null)
        {
            hasPasswordObject.SetActive(!string.IsNullOrEmpty(data.roomPassword));
        }
    }
    private void UpdateRoomData()
    {
        var room             = PhotonNetwork.room;
        var customProperties = room.CustomProperties;
        var roomName         = (string)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_ROOM_NAME];
        var playerId         = (string)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_PLAYER_ID];
        var playerName       = (string)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_PLAYER_NAME];
        var sceneName        = (string)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_SCENE_NAME];
        var state            = (byte)customProperties[SimplePhotonNetworkManager.CUSTOM_ROOM_STATE];

        if (textRoomName != null)
        {
            textRoomName.text = string.IsNullOrEmpty(roomName) ? "Untitled" : roomName;
        }
        if (textPlayerName != null)
        {
            textPlayerName.text = playerName;
        }
        if (textSceneName != null)
        {
            textSceneName.text = BaseNetworkGameInstance.GetMapNameByScene(sceneName);
        }
        if (textPlayerCount != null)
        {
            textPlayerCount.text = room.PlayerCount + "/" + room.MaxPlayers;
        }
        if (textRoomState != null)
        {
            switch ((SimplePhotonNetworkManager.RoomState)state)
            {
            case SimplePhotonNetworkManager.RoomState.Waiting:
                textRoomState.text = roomStateWaiting;
                break;

            case SimplePhotonNetworkManager.RoomState.Playing:
                textRoomState.text = roomStatePlaying;
                break;
            }
        }

        object gameRuleObject;
        BaseNetworkGameRule gameRule = null;

        if (textGameRule != null &&
            customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE, out gameRuleObject) &&
            BaseNetworkGameInstance.GameRules.TryGetValue(gameRuleObject.ToString(), out gameRule))
        {
            textGameRule.text = gameRule == null ? "Unknow" : gameRule.Title;
        }

        waitingPlayerListRoot.SetActive(!gameRule.IsTeamGameplay);
        waitingPlayerTeamAListRoot.SetActive(gameRule.IsTeamGameplay);
        waitingPlayerTeamBListRoot.SetActive(gameRule.IsTeamGameplay);

        object botCountObject;

        if (textBotCount != null &&
            customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE_BOT_COUNT, out botCountObject))
        {
            textBotCount.text = ((int)botCountObject).ToString("N0");
            textBotCount.gameObject.SetActive(gameRule != null && gameRule.HasOptionBotCount);
        }

        object matchTimeObject;

        if (textMatchTime != null &&
            customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE_MATCH_TIME, out matchTimeObject))
        {
            textMatchTime.text = ((int)matchTimeObject).ToString("N0");
            textMatchTime.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchTime);
        }

        object matchKillObject;

        if (textMatchKill != null &&
            customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE_MATCH_KILL, out matchKillObject))
        {
            textMatchKill.text = ((int)matchKillObject).ToString("N0");
            textMatchKill.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchKill);
        }

        object matchScoreObject;

        if (textMatchScore != null &&
            customProperties.TryGetValue(BaseNetworkGameManager.CUSTOM_ROOM_GAME_RULE_MATCH_SCORE,
                                         out matchScoreObject))
        {
            textMatchScore.text = ((int)matchScoreObject).ToString("N0");
            textMatchScore.gameObject.SetActive(gameRule != null && gameRule.HasOptionMatchScore);
        }

        HostPlayerID = playerId;
    }