コード例 #1
0
    public void RemovePlayerByChairID(PlayerTeam.PlayerTeamType teamType, byte cbChairID, byte cbAIId = HNMJ_Defines.INVALID_AI_ID)
    {
        PlayerTeam team = GetPlayerTeam(teamType);

        if (team != null)
        {
            team.RemovePlayerByChairID(cbChairID);
        }
    }
コード例 #2
0
        protected override GamePlayer CreatePlayer(IClientUserItem pIClientUserItem)
        {
            lock (HNGameManager.LockObjOfLoadScene)
            {
                int nChairID = pIClientUserItem.GetChairID();

                if (pIClientUserItem.GetUserID() == UserInfo.getInstance().getUserID())
                {
                    m_pLocal.setUserItem(pIClientUserItem);

                    Debug.Log("---------------------CreatePlayer m_pLocal");

                    //mChen add, for HideSeek
                    Loom.QueueOnMainThread(() =>
                    {
                        GameObjectsManager.s_LocalHumanTeamType = PlayerTeam.PlayerTeamType.TaggerTeam;
                        //GameObjectsManager.s_LocalHumanTeamType = PlayerTeam.PlayerTeamType.HideTeam; //测试
                        HNGameManager.m_iLocalChairID = nChairID;

                        if (GameManager.s_gameSingleMultiType == GameSingleMultiType.MultiGame_WangHu)
                        {
                            PlayerTeam.PlayerTeamType teamType = pIClientUserItem.GetTeamType();// PlayerTeam.PlayerTeamType.TaggerTeam;
                            //PlayerTeam.PlayerTeamType teamType = PlayerTeam.PlayerTeamType.HideTeam; //测试
                            GameObjectsManager.s_LocalHumanTeamType = teamType;

                            byte cbModelIndex = pIClientUserItem.GetModelIndex();

                            PlayerTeam team = GameObjectsManager.GetInstance().GetPlayerTeam(teamType);
                            team.AddAPlayer(false, nChairID, cbModelIndex);
                        }
                    });

                    return(m_pLocal);
                }
                else
                {
                    GamePlayer pPlayer = getPlayerByChairID(pIClientUserItem.GetChairID());
                    pPlayer.setUserItem(pIClientUserItem);

                    //mChen add, for HideSeek
                    Loom.QueueOnMainThread(() =>
                    {
                        if (GameManager.s_gameSingleMultiType == GameSingleMultiType.MultiGame_WangHu)
                        {
                            PlayerTeam.PlayerTeamType teamType = pIClientUserItem.GetTeamType();//PlayerTeam.PlayerTeamType.TaggerTeam;
                            //PlayerTeam.PlayerTeamType teamType = PlayerTeam.PlayerTeamType.HideTeam; //测试
                            byte cbModelIndex = pIClientUserItem.GetModelIndex();

                            PlayerTeam team = GameObjectsManager.GetInstance().GetPlayerTeam(teamType);
                            team.AddAPlayer(false, nChairID, cbModelIndex);
                        }
                    });

                    return(pPlayer);
                }
            }
        }
コード例 #3
0
    // for HideSeek WangHu
    public PlayerBase GetPlayerByChairID(PlayerTeam.PlayerTeamType teamType, int nChairID, byte cbAIId = HNMJ_Defines.INVALID_AI_ID)
    {
        PlayerBase player = null;

        if (_playerTeams != null && _playerTeams[(int)teamType] != null)
        {
            player = _playerTeams[(int)teamType].GetPlayerByChairID(nChairID, cbAIId);
        }
        return(player);
    }
コード例 #4
0
    public void RemovePlayers(bool bRemoveAI = true)
    {
        if (Camera.main.gameObject != null && Camera.main.transform.parent != null)
        {
            GameObject PosPoint    = GameObject.Find("PosPoint");
            GameObject LookAtPoint = GameObject.Find("LookAtPoint");
            if (PosPoint != null && LookAtPoint != null)
            {
                Camera.main.transform.parent.SetParent(null, false);
                Camera.main.transform.parent.transform.position         = PosPoint.transform.position;
                Camera.main.transform.parent.transform.localEulerAngles = PosPoint.transform.localEulerAngles;
                Camera.main.transform.LookAt(LookAtPoint.transform);
            }
        }

        for (PlayerTeam.PlayerTeamType teamType = PlayerTeam.PlayerTeamType.TaggerTeam; teamType < PlayerTeam.PlayerTeamType.MaxTeamNum; teamType++)
        {
            PlayerTeam team = GetPlayerTeam(teamType);
            if (team != null)
            {
                team.RemovePlayers(bRemoveAI);
            }
        }

        //GameObject LocalTaggerObj = GameObject.Find("Player/TaggerTeam/LocalTagger");
        //GameObject.Destroy(LocalTaggerObj);

        //GameObject LocalHideObj = GameObject.Find("Player/HideTeam/LocalHide");
        //GameObject.Destroy(LocalHideObj);

        GameObject LocalHumanObj = GameObject.FindGameObjectWithTag("LocalHuman");

        GameObject.Destroy(LocalHumanObj);

        if (bRemoveAI)
        {
            GameObject TaggerTeam = GameObject.Find("Player/TaggerTeam");
            if (TaggerTeam != null)
            {
                for (int i = 0; i < TaggerTeam.transform.childCount; i++)
                {
                    GameObject.Destroy(TaggerTeam.transform.GetChild(i).gameObject);
                }
            }

            GameObject HideTeam = GameObject.Find("Player/HideTeam");
            if (HideTeam != null)
            {
                for (int i = 0; i < HideTeam.transform.childCount; i++)
                {
                    GameObject.Destroy(HideTeam.transform.GetChild(i).gameObject);
                }
            }
        }
    }
コード例 #5
0
 public void CustomUpdate()
 {
     // Humans
     if (_playerTeams != null)
     {
         for (PlayerTeam.PlayerTeamType teamType = PlayerTeam.PlayerTeamType.TaggerTeam; teamType < PlayerTeam.PlayerTeamType.MaxTeamNum; teamType++)
         {
             _playerTeams[(int)teamType].CustomUpdate();
         }
     }
 }
コード例 #6
0
    public int GetAINum(PlayerTeam.PlayerTeamType teamType, int nChaidID)
    {
        int nAINum = 0;

        if (_playerTeams != null && _playerTeams[(int)teamType] != null)
        {
            nAINum = _playerTeams[(int)teamType].GetAINum(nChaidID);
        }

        return(nAINum);
    }
コード例 #7
0
    public PlayerBase GetPlayer(PlayerTeam.PlayerTeamType teamType, int playerIndex)
    {
        PlayerBase player = null;

        if (_playerTeams != null && _playerTeams[(int)teamType] != null)
        {
            player = _playerTeams[(int)teamType].GetPlayer(playerIndex);
        }

        return(player);
    }
コード例 #8
0
    public PlayerTeam GetPlayerTeam(PlayerTeam.PlayerTeamType teamType)
    {
        if (_playerTeams == null)
        {
            CreateHumanTeams();
        }

        PlayerTeam team = null;

        if (teamType != PlayerTeam.PlayerTeamType.MaxTeamNum)
        {
            team = _playerTeams[(int)teamType];
        }
        return(team);
    }
コード例 #9
0
    public int GetPlayerMaxChairId(PlayerTeam.PlayerTeamType teamType)
    {
        int        chairId = 0;
        PlayerTeam team    = null;

        if (teamType != PlayerTeam.PlayerTeamType.MaxTeamNum)
        {
            team = _playerTeams[(int)teamType];
            for (int i = 0; i < team.GetPlayerNum(); i++)
            {
                PlayerBase playerBase = GetPlayer(teamType, i);
                if (!playerBase.IsAI)
                {
                    chairId = playerBase.ChairID > chairId ? playerBase.ChairID : chairId;
                }
            }
        }
        return(chairId);
    }
コード例 #10
0
    public int GetRealPlayerNum(PlayerTeam.PlayerTeamType teamType)
    {
        int        num  = 0;
        PlayerTeam team = null;

        if (teamType != PlayerTeam.PlayerTeamType.MaxTeamNum)
        {
            team = _playerTeams[(int)teamType];
            for (int i = 0; i < team.GetPlayerNum(); i++)
            {
                PlayerBase playerBase = GetPlayer(teamType, i);
                if (!playerBase.IsAI)
                {
                    num++;
                }
            }
        }
        return(num);
    }
コード例 #11
0
    public PlayerBase GetPlayerByChairID(int nChaidID, byte cbAIId = HNMJ_Defines.INVALID_AI_ID)
    {
        PlayerBase player = null;

        for (PlayerTeam.PlayerTeamType teamType = PlayerTeam.PlayerTeamType.TaggerTeam; teamType < PlayerTeam.PlayerTeamType.MaxTeamNum; teamType++)
        {
            if (_playerTeams != null && _playerTeams[(int)teamType] != null)
            {
                player = _playerTeams[(int)teamType].GetPlayerByChairID(nChaidID, cbAIId);
                if (player != null)
                {
                    return(player);
                }
            }
        }
        ///PlayerBase player = _playerTeams[(int)teamType].GetPlayerByChairID(nChaidID);

        return(null);
    }
コード例 #12
0
    public void CreateHumanTeams()
    {
        if (GameManager.LockObj == null)
        {
            GameManager.LockObj = new object();
        }

        lock (GameManager.LockObj)
        {
            if (_playerTeams == null)
            {
                _playerTeams = new PlayerTeam[(int)PlayerTeam.PlayerTeamType.MaxTeamNum];
                for (PlayerTeam.PlayerTeamType type = PlayerTeam.PlayerTeamType.TaggerTeam; type < PlayerTeam.PlayerTeamType.MaxTeamNum; type++)
                {
                    _playerTeams[(int)type] = new PlayerTeam(type);
                }
            }
        }
    }
コード例 #13
0
    public void EnableLocalAI(PlayerTeam.PlayerTeamType teamType, bool bEnable)
    {
        PlayerTeam team = GameObjectsManager.GetInstance().GetPlayerTeam(teamType);

        if (team == null)
        {
            return;
        }

        int nPlayerNum = team.GetPlayerNum();

        for (int i = 0; i < nPlayerNum; i++)
        {
            PlayerBase player = team.GetPlayer(i);

            if (player == null)
            {
                continue;
            }

            if (!player.IsAI)
            {
                continue;
            }

            //Local AI
            if (player.ChairID == HNGameManager.m_iLocalChairID)
            {
                BehaviorDesigner.Runtime.BehaviorTree behaviorTree = player.GetComponent <BehaviorDesigner.Runtime.BehaviorTree>();
                if (behaviorTree != null)
                {
                    behaviorTree.enabled = bEnable;
                }

                UnityEngine.AI.NavMeshAgent navMeshAgent = player.GetComponent <UnityEngine.AI.NavMeshAgent>();
                if (navMeshAgent != null)
                {
                    navMeshAgent.enabled = bEnable;
                }
            }
        }
    }
コード例 #14
0
    void Update()
    {
        if (TaggerCount != null)
        {
            TaggerCount.text = "0";
        }
        if (HideCount != null)
        {
            HideCount.text = "0";
        }
        for (PlayerTeam.PlayerTeamType teamType = PlayerTeam.PlayerTeamType.TaggerTeam; teamType < PlayerTeam.PlayerTeamType.MaxTeamNum; teamType++)
        {
            PlayerTeam team = GameObjectsManager.GetInstance().GetPlayerTeam(teamType);
            if (team == null)
            {
                continue;
            }
            for (int i = 0; i < team.GetPlayerNum(); i++)
            {
                PlayerBase playerBase = GameObjectsManager.GetInstance().GetPlayer(teamType, i);
                if (playerBase != null && playerBase.Hp != 0)
                {
                    if (teamType == PlayerTeam.PlayerTeamType.TaggerTeam)
                    {
                        taggerCount++;
                    }
                    else if (teamType == PlayerTeam.PlayerTeamType.HideTeam)
                    {
                        hideCount++;
                    }

                    ShowPlayerTopHeadInfo(playerBase);
                }
            }
            TaggerCount.text = taggerCount.ToString();
            HideCount.text   = hideCount.ToString();
        }

        taggerCount = 0;
        hideCount   = 0;
    }
コード例 #15
0
    private void SetupNetReceiverHandler()
    {
        NetReceiver.AddHandler <Protocol.handshake>((_) =>
        {
            Debug.Log("handshake");
            SprotoType.handshake.request req = _ as handshake.request;
            switch (TheUserLoginState)
            {
            case UserLoginState.LoginStart:
                {
                    //Debug.Log("challenge receive ");
                    _challengeStr = Convert.FromBase64String(req.msg);

                    DH64 dhforKey = new DH64();
                    dhforKey.KeyPair(out _privateKey, out _publicKey);
                    SprotoType.handshake.request clientkey = new handshake.request();

                    clientkey.msg = Convert.ToBase64String(BitConverter.GetBytes(_publicKey));

                    clientkey.socketfd = req.socketfd;
                    NetSender.Send <Protocol.handshake>(clientkey);

                    Debug.Log("challengeStr" + _challengeStr + " ori " + req.msg + " fd " + clientkey.socketfd);
                    TheUserLoginState = UserLoginState.LoginPublicServerKey;
                }
                break;

            case UserLoginState.LoginPublicServerKey:
                {
                    //string serverKey = System.Text.Encoding.Default.GetString(Convert.FromBase64String(req.msg));
                    byte[] ServerKey = Convert.FromBase64String(req.msg);

                    ulong serverKey = BitConverter.ToUInt64(ServerKey, 0);
                    _secretKey      = DH64.Secret(_privateKey, serverKey);
                    SprotoType.handshake.request challengeMsg = new handshake.request();

                    challengeMsg.msg =
                        Convert.ToBase64String(
                            BitConverter.GetBytes(
                                HMac64.hmac(
                                    BitConverter.ToUInt64(_challengeStr, 0),
                                    _secretKey)));

                    challengeMsg.socketfd = req.socketfd;
                    NetSender.Send <Protocol.handshake>(challengeMsg);
                    TheUserLoginState = UserLoginState.LoginCheckSecret;
                }
                break;

            case UserLoginState.LoginCheckSecret:
                {
                    if (Convert.ToBase64String(Encoding.UTF8.GetBytes(challengeSuccess)) == req.msg)
                    {
                        if (UserName != string.Empty)
                        {
                            Debug.Log("login " + UserName);
                            string token = string.Format("{0}:{1}",
                                                         Convert.ToBase64String(Encoding.UTF8.GetBytes(UserName)),
                                                         Convert.ToBase64String(Encoding.UTF8.GetBytes(PassWord)));

                            SprotoType.handshake.request tokenMsg = new handshake.request
                            {
                                msg      = DesCrypt.desencode(_secretKey, token),
                                socketfd = req.socketfd
                            };

                            NetSender.Send <Protocol.handshake>(tokenMsg);

                            TheUserLoginState = UserLoginState.LoginCheckTokenResult;
                        }
                        else
                        {
                            Debug.Log("register");
                            DisplayName  = RandomName.GetRandomName();
                            string token = Convert.ToBase64String(Encoding.UTF8.GetBytes(DisplayName));
                            SprotoType.handshake.request tokenMsg = new handshake.request
                            {
                                msg      = DesCrypt.desencode(_secretKey, token),
                                socketfd = req.socketfd
                            };

                            NetSender.Send <Protocol.handshake>(tokenMsg);
                            TheUserLoginState = UserLoginState.LoginRegistResult;
                        }
                    }
                    else if (Convert.ToBase64String(Encoding.UTF8.GetBytes(challengeFailed)) == req.msg)
                    {
                        Debug.Log("sercet incorrect!");
                        //error handle
                        TheUserLoginState = UserLoginState.LoginFailed;
                    }
                }
                break;

            case UserLoginState.LoginRegistResult:
                {
                    var msg      = Encoding.UTF8.GetString(Convert.FromBase64String(req.msg));
                    var msgArray = msg.Split(':');
                    UserName     = Encoding.UTF8.GetString(Convert.FromBase64String(msgArray[0]));
                    PassWord     = Encoding.UTF8.GetString(Convert.FromBase64String(msgArray[1]));

                    Loom.QueueOnMainThread(() =>
                    {
                        //save registed info
                        PlayerPrefs.SetString("username", UserName);
                        //GameManager.NetWorkClient.UserName = String.Empty;
                        PlayerPrefs.SetString("password", PassWord);
                        PlayerPrefs.SetString("displayname", DisplayName);
                        Debug.Log("saving name " + UserName + " : " + PassWord);
                        PlayerPrefs.Save();
                    });
                    Debug.Log("name " + UserName + " : " + PassWord);

                    //Thread.Sleep(5);
                    TheUserLoginState = UserLoginState.LoginSuccess;
                }
                break;

            case UserLoginState.LoginCheckTokenResult:
            case UserLoginState.LoginSuccess:
                {
                    if (Convert.ToBase64String(Encoding.UTF8.GetBytes(challengeSuccess)) == req.msg)
                    {
                        //Thread.Sleep(5);
                        Debug.Log("token right");

                        TheUserLoginState = UserLoginState.LoginSuccess;

                        // mChen
                        //if(MultiGameState == GameState.Game_NullState)
                        //{
                        //    FindMatch();
                        //}
                    }
                    else if (Convert.ToBase64String(Encoding.UTF8.GetBytes(challengeFailed)) == req.msg)
                    {
                        //error handle
                        TheUserLoginState = UserLoginState.LoginFailed;
                    }
                }
                break;
            }
            //NetSender.Send<Protocol.handshake>(req);
            //Debug.Log(TheUserLoginState.ToString());
            return(null);
        });

        NetReceiver.AddHandler <Protocol.matchMsg>((_) =>
        {
            SprotoType.matchMsg.request req = _ as matchMsg.request;

            switch (req.matchMsgType)
            {
            case (Int64)MatchMsgType.Match_PlayerJoinedRoom:
                int playerTeamType = Convert.ToInt32(req.matchInfo);
                TheUserMatchState  = UserMatchState.JoinedRoom;
                Debug.Log("NetReceiver: matchMsg: MatchMsgType.Match_PlayerJoinRoom: playerTeamType=" + playerTeamType);
                break;

            case (Int64)MatchMsgType.Match_CountDownTime:
                float countDowmTime = Convert.ToSingle(req.matchInfo) / 100;
                Debug.Log("NetReceiver: matchMsg: MatchMsgType.Match_CountDownTime =" + countDowmTime);
                // UI
                Loom.QueueOnMainThread(() =>
                {
                    UIManager.GetInstance().ShowMatchStartCountDown(countDowmTime);
                });
                break;

            case (Int64)MatchMsgType.Match_TryToJoinMatch:
                int result = Convert.ToInt32(req.matchInfo);
                Debug.Log("NetReceiver: matchMsg: MatchMsgType.Match_TryToJoinMatch: result=" + result);
                MultiGameState = GameState.Game_Match;
                if (result == 0)
                {
                    TheUserMatchState = UserMatchState.WaitToJoinNextMatch;
                    Loom.QueueOnMainThread(() =>
                    {
                        UIManager.GetInstance().ShowWaitToJoinNextMatchLabel();
                    });
                }
                else if (result == 1)
                {
                    TheUserMatchState = UserMatchState.PlayingMatch;
                    Loom.QueueOnMainThread(() =>
                    {
                        UIManager.GetInstance().HideWaitToJoinNextMatchLabel();
                    });
                }
                else
                {
                    Debug.Log("error TryToJoinMatch result from Server" + result);
                    throw new Exception("error TryToJoinMatch result from Server");
                }
                break;

            //case (Int64)MatchMsgType.Match_CancelMatching:
            //    if (QuitMatchingMsg != null)
            //    {
            //        QuitMatchingMsg(this, EventArgs.Empty);
            //    }
            //    break;

            default:
                Debug.Log("error match type" + req.matchMsgType);
                throw new Exception("error msg type");
            }
            return(null);
        });

        NetReceiver.AddHandler <Protocol.usersInfoMsg>((_) =>
        {
            if (MultiGameState == GameState.Game_NullState)
            {
                return(null);
            }
            Debug.Log("get usersInfoMsg");

            SprotoType.usersInfoMsg.request req           = _ as SprotoType.usersInfoMsg.request;
            GameObjectsManager.s_LocalPlayerIndexInGlobal = (int)req.curUserGlobalIndex;
            //Debug.Log("get player index in global: " + GameObjectsManager.s_LocalPlayerIndexInGlobal);

            //Create players
            Loom.QueueOnMainThread(() =>
            {
                AllPlayers.Clear();
                GameObjectsManager.GetInstance().ClearPlayers();

                Debug.Log("received usersInfoMsg:");
                foreach (SprotoType.UserInfo serverPlayerinfo in req.userArray)
                {
                    PlayerTeam.PlayerTeamType teamType = (PlayerTeam.PlayerTeamType)serverPlayerinfo.playerTeamType;
                    PlayerTeam team = GameObjectsManager.GetInstance().GetPlayerTeam(teamType);
                    int userState   = (int)serverPlayerinfo.userState;

                    Debug.Log("     UserIndexInGlobal=" + serverPlayerinfo.playerIndex + " UserName="******" userState=" + userState + " TeamType=" + teamType);

                    if (serverPlayerinfo.playerIndex == req.curUserGlobalIndex)
                    {
                        // is local player

                        if (userState == (int)UserMatchState.PlayingMatch)
                        {
                            GameObjectsManager.s_LocalHumanTeamType = teamType;
                        }
                    }

                    int playerIndexInTeam = -1;
                    if (userState == (int)UserMatchState.PlayingMatch)
                    {
                        // create a new player

                        playerIndexInTeam = team.AddAPlayer(false);
                    }

                    // set AllPlayers
                    AllPlayers.Add(new MultiPlayerInfo
                    {
                        PlayIndexInGlobal = serverPlayerinfo.playerIndex,
                        PlayerName        = serverPlayerinfo.username,
                        SkinId            = 0,
                        PlayerId          = 1,
                        ThePlayerTeamType = teamType,
                        PlayerIndexInTeam = playerIndexInTeam
                    });
                }
            });

            //TheUserMatchState = UserMatchState.AllPlayersJoinedRoom;
            return(null);
        });

        NetReceiver.AddHandler <Protocol.waitforstart>((_) =>
        {
            Debug.Log("Second half start!!");
            var res = _ as SprotoType.waitforstart.request;
            //mChen
            //switch (GameManager.GetInstance().TheGamePrePeriod)
            //{
            //    case GamePeriod.Opening:
            //        break;
            //    case GamePeriod.FirstHalf:
            //        break;
            //    case GamePeriod.Halftime:
            //        break;
            //    case GamePeriod.CutsceneAfterScoredOr24SecondsViolation:
            //        break;
            //    case GamePeriod.WairForGameToContinue:
            //        break;
            //    case GamePeriod.SecondHalf:
            //        GameManager.GetInstance().HalfTimeReadyFrame = res.readyFrame;
            //        break;
            //    case GamePeriod.Ending:
            //        break;
            //    default:
            //        throw new ArgumentOutOfRangeException();
            //}

            return(null);
        });

        NetReceiver.AddHandler <Protocol.gameTick>((_) =>
        {
            //Debug.Log("response called");
            if (false)//mChen if (GameManager.TheGameMode > GameMode.MultiGame_3v3)
            {
                //when single mode, do not handle this server tick
                return(null);
            }

            if (MultiGameState == GameState.Game_Match)
            {
                MultiGameState = GameState.Game_Running;

                Loom.QueueOnMainThread(() =>
                {
                    UIManager.GetInstance().HideMatchStartCountDown();
                });

                //mChen
                _sendHeartBeatThread = new Thread(SendHeartBeatMsg)
                {
                    IsBackground = true
                };
                //防止后台现成。相反需要后台线程就设为false
                _sendHeartBeatThread.Start();
                while (_sendHeartBeatThread.IsAlive == false)
                {
                }
            }

            SprotoType.gameTick.request res = _ as gameTick.request;
            {
                // bool bOnlyFrameInfo = true;

                if (res.HasButtonMsg)
                {
                    //mChen
                    //foreach (var btnMsg in res.buttonMsg)
                    //{
                    //    ButtonInfo msg = new ButtonInfo
                    //    {
                    //        TeamType =
                    //            (PlayerTeamType)((btnMsg.playerIndex) / GameManager.TeamPlayerNum),
                    //        PlayerIndexInTeam = (btnMsg.playerIndex) % GameManager.TeamPlayerNum,
                    //        FrameNum = res.frame,
                    //        Action = (ButtonAction)btnMsg.btnAction,
                    //        Type = (ButtonType)btnMsg.btnType
                    //    };

                    //    if (btnMsg.HasBtnValueX)
                    //    {
                    //        msg.Value.x = (float)BitConverter.ToDouble(BitConverter.GetBytes(btnMsg.btnValueX), 0);
                    //        msg.Value.y = (float)BitConverter.ToDouble(BitConverter.GetBytes(btnMsg.btnValueY), 0); ;
                    //    }
                    //    ControlManager.GetInstance().AddControlInfo(msg);
                    //    //Debug.Log("Button msg");
                    //}

                    // bOnlyFrameInfo = false;
                }

                //_controllerMsg.Clear();
                if (res.HasControlMsg)
                {
                    //Debug.Log("controller called");
                    //List < ControlMsg > tempList = new List<ControlMsg>();

                    foreach (var resControl in res.controlMsg)
                    {
                        //mChen
                        //DPadInfo msg = new DPadInfo
                        //{
                        //    FrameNum = res.frame,
                        //    TeamType = (PlayerTeamType)(resControl.playerIndex / GameManager.TeamPlayerNum),
                        //    PlayerIndexInTeam = resControl.playerIndex % GameManager.TeamPlayerNum,
                        //    //H = Convert.ToSingle(resControl.x),
                        //    //V = Convert.ToSingle(resControl.y)
                        //    H = (float)BitConverter.ToDouble(BitConverter.GetBytes(resControl.x), 0),
                        //    V = (float)BitConverter.ToDouble(BitConverter.GetBytes(resControl.y), 0)
                        //};

                        //ControlManager.GetInstance().AddControlInfo(msg);
#if false
                        if (ControlManager.GetInstance().GameFrameNum % 150 == 1)
                        {
                            GameManager.GetInstance().InfoStr += string.Format("\n dpad info {0} {1} at frame {2}",
                                                                               msg.H, msg.V, ControlManager.GetInstance().GameFrameNum);
                        }
#endif
                        // Debug.LogFormat("dpad msg frame {0} : h {1} v {2} ", res.frame, msg.H, msg.V);
                    }


                    // bOnlyFrameInfo = false;
                }

                if (res.HasPlayersGamePlayMsg)
                {
                    Loom.QueueOnMainThread(() =>
                    {
                        foreach (var playerGamePlayMsg in res.playersGamePlayMsg)
                        {
                            int playerIndex = (int)playerGamePlayMsg.playerIndex;
                            float posX      = (float)BitConverter.ToDouble(BitConverter.GetBytes(playerGamePlayMsg.posX), 0);
                            float posY      = (float)BitConverter.ToDouble(BitConverter.GetBytes(playerGamePlayMsg.posY), 0);
                            float posZ      = (float)BitConverter.ToDouble(BitConverter.GetBytes(playerGamePlayMsg.posZ), 0);
                            float angleX    = (float)BitConverter.ToDouble(BitConverter.GetBytes(playerGamePlayMsg.angleX), 0);
                            float angleY    = (float)BitConverter.ToDouble(BitConverter.GetBytes(playerGamePlayMsg.angleY), 0);
                            float angleZ    = (float)BitConverter.ToDouble(BitConverter.GetBytes(playerGamePlayMsg.angleZ), 0);
                            //Debug.Log("playerInfoMsg:" + playerGamePlayMsg.playerIndex + " pos:" + posX + posY + posZ);

                            if (playerIndex == GameObjectsManager.s_LocalPlayerIndexInGlobal)
                            {
                            }
                            else
                            {
                                PlayerTeam.PlayerTeamType teamType = AllPlayers[playerIndex].ThePlayerTeamType;
                                int playerIndexInTeam = AllPlayers[playerIndex].PlayerIndexInTeam;
                                PlayerBase player     = GameObjectsManager.GetInstance().GetPlayer(teamType, playerIndexInTeam);
                                if (player != null)
                                {
                                    player.transform.position    = new Vector3(posX, posY, posZ);
                                    player.transform.eulerAngles = new Vector3(angleX, angleY, angleZ);
                                }
                            }
                        }
                    });
                }

                //添加一般帧信息
                //if (bOnlyFrameInfo)
                {
                    //mChen ControlManager.GetInstance().AddControlInfo(res.frame);
                }
            }
            return(null);
        });

        NetReceiver.AddHandler <Protocol.restoreStates>((_) =>
        {
            var req           = _ as SprotoType.restoreStates.request;
            TheUserMatchState = (UserMatchState)req.serverState;
            Debug.Log("resotre user state now " + TheUserMatchState.ToString());
            var infoArray = req.stateInfo.Split(':');

            switch (req.serverState)
            {
            case (int)UserMatchState.FindRoom:
                ParseFindMatchMsg(infoArray);
                TheUserMatchState = UserMatchState.FindRoom;
                //mChen Loom.QueueOnMainThread(GameUIManager.GetInstance().UIChangeToMatching);
                //GameUIManager.GetInstance().UIChangeToMatching();//go to matching ui
                break;
            }
            return(null);
        });
    }
コード例 #16
0
 // for HideSeek WangHu
 public PlayerTeam.PlayerTeamType GetTeamType()
 {
     PlayerTeam.PlayerTeamType teamType = (PlayerTeam.PlayerTeamType)m_UserInfo.cbTeamType;
     return(teamType);
 }
コード例 #17
0
    public void PickupObject(GameObject objToPick, Vector3 pickupPos)
    {
        if (gameObject.GetComponent <PlayerBase>().TeamType == PlayerTeam.PlayerTeamType.HideTeam)  //躲藏的玩家无法执行找操作
        {
            return;
        }
        else
        {
            if (GameManager.s_gameSingleMultiType == GameSingleMultiType.MultiGame_WangHu)
            {
                byte Gamestate = CServerItem.get().GetGameStatus();
                if (Gamestate != SocketDefines.GAME_STATUS_PLAY)
                {
                    return;
                }
            }
            else if (GameManager.s_gameSingleMultiType == GameSingleMultiType.SingleGame)
            {
                if (GameManager.s_singleGameStatus != SocketDefines.GAME_STATUS_PLAY)
                {
                    return;
                }
            }
        }
        if (objToPick == null || this.Hp <= 0)
        {
            return;
        }

        if (this.IsAI)
        {
            //AI没有用射线检测,也就没有距离判断,所以这里要加入

            Vector3 distToPick = objToPick.transform.position - this.transform.position;
            if (distToPick.magnitude > ControlManager.s_MaxTouchCheckDistance)
            {
                Debug.LogError("-----------距离过远!!!!!" + distToPick.magnitude + " " + objToPick.transform.position + " " + this.transform.position);
                //if (objToPick.tag == "Hide" || objToPick.tag == "NormalFurniture") //objToPick.name
                {
                    UIManager.GetInstance().ShowPickupTooFarText();

                    return;
                }
            }
        }

        if (GameManager.s_gameSingleMultiType == GameSingleMultiType.MultiGame_WangHu)
        {
            // Pick event sync
            PlayerEventItem pickEvent = new PlayerEventItem();
            pickEvent.cbTeamType  = (byte)TeamType;
            pickEvent.wChairId    = (ushort)ChairID;
            pickEvent.cbAIId      = (byte)AIId;
            pickEvent.cbEventKind = (byte)PlayerBase.PlayerEventKind.Pick;
            GameObjectsManager.GetInstance().PlayerEventList.Add(pickEvent);
        }
        else
        {
            if (IsAI || !ControlManager.isPerson_1st)  //只有第三人称才有拾取动画
            {
                if (IsLocalHuman())
                {
                    EnableModelDisplay();
                }

                PlayPickupAnim();
                //if (_avatarAnimator != null)
                //{
                //    _avatarAnimator.SetBool("Pickup_b", true);
                //}
            }
        }

        PlayerBase pickedPlayer    = null;
        string     strObjToPickTag = null;

        if (this.IsAI)
        {
            //this是AI时,传的objToPick是根节点(PlayerBase都在根节点)

            pickedPlayer = objToPick.GetComponent <PlayerBase>();

            if (pickedPlayer == null)
            {
                //objToPick是场景中的物体,不是躲藏者

                strObjToPickTag = objToPick.tag;
            }
            else
            {
                Transform model = pickedPlayer.transform.FindChild("Model");
                if (model != null)
                {
                    strObjToPickTag = model.tag;    //tag在model节点
                }
                else
                {
                    Debug.LogError("PickupObject IsAI: model==null");
                }
            }
        }
        else
        {
            //this不是AI时,objToPick如果是躲藏者,传的是Model子节点,否则传的也是根节点

            pickedPlayer = objToPick.transform.parent.GetComponent <PlayerBase>();
            if (pickedPlayer == null)
            {
                //objToPick是场景中的物体,不是躲藏者

                strObjToPickTag = objToPick.tag;
            }
            else
            {
                strObjToPickTag = objToPick.tag;
            }
        }

        if (strObjToPickTag == "Hide" || (strObjToPickTag == "LocalHuman" && pickedPlayer != null && pickedPlayer.TeamType == PlayerTeam.PlayerTeamType.HideTeam)) //objToPick.name
        {
            ObjNamePicked = pickedPlayer.gameObject.name;
            Debug.Log(gameObject.name + " touched Hide: " + ObjNamePicked);

            if (IsLocalHuman())
            {
                Debug.Log("I'm touched Hide: " + ObjNamePicked);
            }

            // Check if objToPick is alive
            if (pickedPlayer != null)
            {
                if (pickedPlayer.IsDead())
                {
                    Debug.Log("It was already dead!");
                }
                else
                {
                    if (GameManager.s_gameSingleMultiType == GameSingleMultiType.SingleGame)
                    {
                        if (IsAI && pickedPlayer.m_isStealth == 1) //AI警察不点隐身的躲藏者
                        {
                            return;
                        }
                        //击杀信息
                        if (gameObject.GetComponent <PlayerBase>().IsAI)
                        {
                            //String[] str = gameObject.name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                            //String[] pickedStr = pickedPlayer.gameObject.name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                            UIManager.GetInstance().ShowMiddleTips(gameObject.name + " 找到了: " + pickedPlayer.gameObject.name);
                        }
                        else
                        {
                            String[] str = GlobalUserInfo.getNickName().Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
                            //String[] pickedStr = pickedPlayer.gameObject.name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                            UIManager.GetInstance().ShowMiddleTips(str[0] + " 找到了: " + pickedPlayer.gameObject.name);
                        }

                        // Heal self
                        AddHP();

                        if (m_hnGameManager != null && IsLocalHuman())  //本地玩家找到躲藏者提示
                        {
                            m_hnGameManager.PlaySoundEffect(-1, (int)AudioManager.Sound_Effect_Defines.SOUND_HIDE_BEFOUNDED);
                        }

                        // make pickedPlayer dead and destroy later
                        pickedPlayer.MakeDead();
                        //if (!pickedPlayer.IsAI)
                        //{
                        //    PlayerChairIDOfPickedDead = pickedPlayer.ChairID;
                        //}
                    }
                    else
                    {
                        //Debug.LogWarning("+++++++++++++++++ " + pickedPlayer.m_isStealth + " " + IsAI);
                        if (pickedPlayer.m_isStealth == 1 && IsAI)  //AI警察不点隐身的躲藏者
                        {
                            //Debug.LogWarning("----------玩家隐身中");
                            return;
                        }
                        // Dead event sync
                        PlayerEventItem deadEvent = new PlayerEventItem();
                        deadEvent.cbTeamType  = (byte)pickedPlayer.TeamType;
                        deadEvent.wChairId    = (ushort)pickedPlayer.ChairID;
                        deadEvent.cbAIId      = pickedPlayer.AIId;
                        deadEvent.cbEventKind = (byte)PlayerEventKind.DeadByPicked;
                        //killer
                        deadEvent.nCustomData0 = (Int32)this.TeamType;
                        deadEvent.nCustomData1 = (Int32)this.ChairID;
                        deadEvent.nCustomData2 = (Int32)this.AIId;
                        GameObjectsManager.GetInstance().PlayerEventList.Add(deadEvent);
                    }

                    //警察找到躲藏者加分
                    GameScore += 50;
                }
            }
        }
        else if (strObjToPickTag == "NormalFurniture")
        {
            ObjNamePicked = objToPick.transform.parent.name;
            Debug.Log("touched normal furniture: " + ObjNamePicked);

            UIManager.GetInstance().ShowPickupWrongUI(pickupPos); //hit.point

            if (m_hnGameManager != null && IsLocalHuman())        //本地玩家点击错误物体提示
            {
                m_hnGameManager.PlaySoundEffect(-1, (int)AudioManager.Sound_Effect_Defines.SOUND_EFFECT_PickObj);
            }
            if (IsLocalHuman())
            {
                UIManager.GetInstance().ShowMiddleTips("该物品不是玩家!");
            }
            if (UIManager.TimeLeft <= 45)   //剩余时间小于45秒时,警察无敌
            {
                return;
            }

            // Hurt self
            if (GameManager.s_gameSingleMultiType == GameSingleMultiType.SingleGame)
            {
                DecHP();
            }
            else
            {
                PlayerEventItem decHpEvent = new PlayerEventItem();
                decHpEvent.cbTeamType  = (byte)this.TeamType;
                decHpEvent.wChairId    = (ushort)this.ChairID;
                decHpEvent.cbAIId      = (byte)this.AIId;
                decHpEvent.cbEventKind = (byte)PlayerBase.PlayerEventKind.DecHp;
                GameObjectsManager.GetInstance().PlayerEventList.Add(decHpEvent);
            }
        }
        else if (strObjToPickTag == "Tagger")
        {
            ObjNamePicked = pickedPlayer.gameObject.name;
            Debug.Log("touched Tagger: " + ObjNamePicked);
        }
        else
        {
            Debug.LogError("PickupObject: incorrect objToPickTag=" + strObjToPickTag);
        }


        //判断是否团灭
        int taggerCount = 0;
        int hideCount   = 0;

        for (PlayerTeam.PlayerTeamType teamType = PlayerTeam.PlayerTeamType.TaggerTeam; teamType < PlayerTeam.PlayerTeamType.MaxTeamNum; teamType++)
        {
            PlayerTeam team = GameObjectsManager.GetInstance().GetPlayerTeam(teamType);
            if (team == null)
            {
                continue;
            }
            for (int i = 0; i < team.GetPlayerNum(); i++)
            {
                PlayerBase playerBase = GameObjectsManager.GetInstance().GetPlayer(teamType, i);
                if (playerBase != null && playerBase.Hp != 0)
                {
                    if (teamType == PlayerTeam.PlayerTeamType.TaggerTeam)
                    {
                        taggerCount++;
                    }
                    else if (teamType == PlayerTeam.PlayerTeamType.HideTeam)
                    {
                        hideCount++;
                    }
                }
            }
        }
        if (taggerCount == 0 || hideCount == 0)
        {
            if (GameManager.s_gameSingleMultiType == GameSingleMultiType.SingleGame)
            {
                if (UIManager.GetInstance() != null)
                {
                    UIManager.GetInstance().ShowWinOrLose();
                }
                m_hnGameManager.StopSingleGame();
                m_hnGameManager.PlayAgainSingleGame();
            }
        }
    }
コード例 #18
0
 public void ShowPlayerList()
 {
     for (PlayerTeam.PlayerTeamType teamType = PlayerTeam.PlayerTeamType.TaggerTeam; teamType < PlayerTeam.PlayerTeamType.MaxTeamNum; teamType++)
     {
         PlayerTeam team = GameObjectsManager.GetInstance().GetPlayerTeam(teamType);
         for (int i = 0; i < team.GetPlayerNum(); i++)
         {
             PlayerBase playerBase = GameObjectsManager.GetInstance().GetPlayer(teamType, i);
             if (playerBase != null)
             {
                 if (playerBase.TeamType == PlayerTeam.PlayerTeamType.TaggerTeam)
                 {
                     TaggerList[i].transform.Find("NumInfo").GetComponent <Text>().text = (i + 1).ToString();
                     string name  = "";
                     string state = "";
                     if (playerBase.IsAI)
                     {
                         //String[] str = playerBase.gameObject.name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                         //name = str[0] + "_" + str[1] + "_" + str[2];
                         name = playerBase.gameObject.name;
                     }
                     else
                     {
                         if (GameManager.s_gameSingleMultiType == GameSingleMultiType.SingleGame)
                         {
                             String[] str = GlobalUserInfo.getNickName().Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
                             name = str[0];
                         }
                         else if (GameManager.s_gameSingleMultiType == GameSingleMultiType.MultiGame_WangHu)
                         {
                             var    kernel = (GameScene)CServerItem.get().GetClientKernelSink();
                             string strNN  = kernel.getPlayerByChairID(playerBase.ChairID).GetNickName();
                             if (strNN != "")
                             {
                                 String[] str = strNN.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
                                 name = str[0];
                             }
                             else
                             {
                                 name  = playerBase.gameObject.name;
                                 state = "离开";
                             }
                         }
                     }
                     TaggerList[i].transform.Find("NameInfo").GetComponent <Text>().text = name;
                     if (playerBase.Hp != 0)
                     {
                         TaggerList[i].transform.Find("State").GetComponent <Text>().text = "";
                     }
                     else
                     {
                         TaggerList[i].transform.Find("State").GetComponent <Text>().text = "失败";
                     }
                     if (state == "离开")
                     {
                         TaggerList[i].transform.Find("State").GetComponent <Text>().text = "离开";
                     }
                     TaggerList[i].SetActive(true);
                 }
                 else
                 {
                     HideList[i].transform.Find("NumInfo").GetComponent <Text>().text = (i + 1).ToString();
                     string name  = "";
                     string state = "";
                     if (playerBase.IsAI)
                     {
                         //String[] str = playerBase.gameObject.name.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                         //name = str[0] + "_" + str[1] + "_" + str[2];
                         name = "机器人";
                     }
                     else
                     {
                         if (GameManager.s_gameSingleMultiType == GameSingleMultiType.SingleGame)
                         {
                             String[] str = GlobalUserInfo.getNickName().Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
                             name = str[0];
                         }
                         else if (GameManager.s_gameSingleMultiType == GameSingleMultiType.MultiGame_WangHu)
                         {
                             var    kernel = (GameScene)CServerItem.get().GetClientKernelSink();
                             string strNN  = kernel.getPlayerByChairID(playerBase.ChairID).GetNickName();
                             if (strNN != "")
                             {
                                 String[] str = strNN.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
                                 name = str[0];
                             }
                             else
                             {
                                 name  = playerBase.gameObject.name;
                                 state = "离开";
                             }
                         }
                     }
                     HideList[i].transform.Find("NameInfo").GetComponent <Text>().text = name;
                     if (playerBase.Hp != 0)
                     {
                         HideList[i].transform.Find("State").GetComponent <Text>().text = "";
                     }
                     else
                     {
                         HideList[i].transform.Find("State").GetComponent <Text>().text = "被发现";
                     }
                     if (state == "离开")
                     {
                         HideList[i].transform.Find("State").GetComponent <Text>().text = "离开";
                     }
                     HideList[i].SetActive(true);
                 }
             }
         }
     }
 }