Exemplo n.º 1
0
 public void Setup(RoomPlayerInfo data)
 {
     RawData = data;
     SetIsSelected(false);
     TextName.text = data.Name;
     SetReady(RawData.Status == 1);
 }
Exemplo n.º 2
0
        public void Serialize(RoomPlayerInfo playerInfo)
        {
            mRoleID           = playerInfo.m_nRoleID;
            mRoleName         = playerInfo.m_strRoleName;
            mIsHost           = playerInfo.m_bIsHost;
            mRoleType         = (RoleRoomType)playerInfo.m_nRoleType;
            m_bIsBoss         = playerInfo.m_bIsBoss;
            mRolePos          = playerInfo.m_nRolePos;
            mRoleState        = (RoleRoomState)playerInfo.m_nRoleState;
            mRoleSex          = (Sex_Type)playerInfo.m_nRoleSex;
            mRoleSkin         = playerInfo.m_nRoleSkin;
            mDanceGroup       = playerInfo.m_strDanceGroup;
            mDanceGroupPos    = playerInfo.m_nDanceGroupPos;
            mDanceGroupBadge  = playerInfo.m_nDanceGroupBadge;
            mDanceGroupEffect = playerInfo.m_nDanceGroupEffect;

            m_bIsVIP          = playerInfo.m_bIsVIP;
            m_nVIPLevel       = playerInfo.m_nVIPLevel;
            m_nTransformId    = playerInfo.m_nTransformId;
            m_nSkinCandyColor = playerInfo.m_nSkinCandyColor;

            m_nCurVehicleID      = playerInfo.m_nCurVehicleID;
            m_nCurVehicleOwnerID = playerInfo.m_nCurVehicleOwnerID;
            m_nCurVehiclePos     = playerInfo.m_nCurVehiclePos;
        }
Exemplo n.º 3
0
        public void doDecode(NetReadBuffer DataIn)
        {
            m_nRoomID                = DataIn.GetUInt();
            m_strRoomName            = DataIn.GetPerfixString();
            m_nRoomColor             = DataIn.GetByte();
            m_strRoomPwd             = DataIn.GetPerfixString();
            m_bHasPwd                = DataIn.GetBool();
            m_bIsHost                = DataIn.GetBool();
            m_nScene                 = DataIn.GetByte();
            m_nMusic                 = DataIn.GetShort();
            m_nMode                  = DataIn.GetByte();
            m_nRoomDanceMode         = DataIn.GetByte();
            m_ClothEffectTransformID = DataIn.GetUInt();

            for (int i = 0; i < CommonDef.MAX_ROOM_PLAYER; ++i)
            {
                m_szPosDancer[i] = DataIn.GetByte();
            }

            for (int i = 0; i < CommonDef.MAX_ROOM_AUDIENCE; ++i)
            {
                m_szPosAudience[i] = DataIn.GetByte();
            }

            ushort nDancerCount = DataIn.GetUShort();

            for (int i = 0; i < nDancerCount; ++i)
            {
                RoomPlayerInfo playerInfo = new RoomPlayerInfo();
                playerInfo.doDecode(DataIn);

                m_lstDancer.Add(playerInfo);
            }
        }
Exemplo n.º 4
0
        private static void SerializeRoomPlayer(List <RoomPlayerInfo> dancerList)
        {
            for (int i = 0; i < dancerList.Count; ++i)
            {
                RoomPlayerInfo playerInfo = dancerList[i];
                RoomPlayer     dancerInfo = new RoomPlayer();
                dancerInfo.Serialize(playerInfo);

                if (CommonLogicData.MainPlayerID > 0 && CommonLogicData.IsMainPlayer(dancerInfo.RoleID))
                {
                    mMeInfo = dancerInfo;
                }

                int tempIndex = dancerInfo.RolePos;
                if (tempIndex < CommonDef.MAX_ROOM_PLAYER && tempIndex >= 0 && tempIndex < mRoomPlayer.Length)
                {
                    AddDancer(dancerInfo.RoleID, dancerInfo);
                    if (dancerInfo == mMeInfo)
                    {
                        mRoomPlayer[tempIndex] = CommonLogicData.MainPlayer;
                    }
                    else
                    {
                        mRoomPlayer[tempIndex] = PlayerManager.CreateLogic(dancerInfo.GetBriefAttr(), true, playerInfo.m_ItemPacket, playerInfo.m_GenePacket);
                    }
                    mRoomPlayer[tempIndex].PlayerMoveType = (PlayerMoveType)playerInfo.m_nMoveType;
                }
            }
        }
Exemplo n.º 5
0
    //监听客户端发来的请求
    static void watchconnecting()
    {
        if (clientConnectionItems.Count >= maxSocketNum)
        {
            Debug.Log("房间人数达到上限");
            return;
        }

        Socket connection = null;

        //持续不断监听客户端发来的请求
        while (true)
        {
            try
            {
                connection = socketwatch.Accept();
            }
            catch (Exception ex)
            {
                //提示套接字监听异常
                Console.WriteLine(ex.Message);
                break;
            }

            //获取客户端的IP和端口号
            IPAddress clientIP   = (connection.RemoteEndPoint as IPEndPoint).Address;
            int       clientPort = (connection.RemoteEndPoint as IPEndPoint).Port;

            //让客户显示"连接成功的"的信息
            //string sendmsg = "连接服务端成功!\r\n" + "本地IP:" + clientIP + ",本地端口" + clientPort.ToString();
            //byte[] arrSendMsg = Encoding.UTF8.GetBytes(sendmsg);
            //connection.Send(arrSendMsg);

            //客户端网络结点号
            string remoteEndPoint = connection.RemoteEndPoint.ToString();
            //显示与客户端连接情况
            Debug.Log("成功与" + remoteEndPoint + "客户端建立连接!");
            //添加客户端信息
            clientConnectionItems.Add(remoteEndPoint, connection);
            RoomPlayerInfo _info = new RoomPlayerInfo();
            _info.Uid         = remoteEndPoint;
            _info.XInitialPos = xPos[clientConnectionItems.Count];
            _info.ZInitialPos = zPos[clientConnectionItems.Count];
            roomInfoList.Add(_info);

            //IPEndPoint netpoint = new IPEndPoint(clientIP,clientPort);
            IPEndPoint netpoint = connection.RemoteEndPoint as IPEndPoint;

            //创建一个通信线程
            ParameterizedThreadStart pts = new ParameterizedThreadStart(recv);
            Thread thread = new Thread(pts);
            //设置为后台线程,随着主线程退出而退出
            thread.IsBackground = true;
            //启动线程
            thread.Start(connection);
        }
    }
 public void RemoveAiPlayer(long aiPlayerId)
 {
     if (_playersAi.ContainsKey(aiPlayerId))
     {
         RoomLogic.ActorManager.SetAiRights(aiPlayerId, false);
         RoomPlayerInfo rpi = GetAiPlayer(aiPlayerId);
         _playersAi.Remove(aiPlayerId);
         Destroy(rpi);
     }
 }
Exemplo n.º 7
0
 public void ResetPlayer()
 {
     this.PlayerNameLabel.text = "";
     this.DelayLabel.text      = "";
     this.StateLabel.text      = "";
     this.UpdateExitBtnState(false);
     this.RoomMasterMarkSprite.enabled = false;
     this.m_PlayerInfo           = null;
     this.CanJoinCountLabel.text = "";
     this.CanJoinCountLabel.gameObject.SetActive(false);
     this.UpdateSelect(false);
 }
Exemplo n.º 8
0
        public bool AddPlayer(Player player)
        {
            if (mPlayers.Count >= mMaxCount)
            {
                return(true);
            }

            mPlayers.Add(player);
            mNotReady.Add(player);
            player.mRoom = this;

            NotifyRoomAddPlayer addPlayer = new NotifyRoomAddPlayer();

            addPlayer.NewPlayer          = new RoomPlayerInfo();
            addPlayer.NewPlayer.UserID   = player.mUserID;
            addPlayer.NewPlayer.Name     = player.mPlayerInfo.NickName;
            addPlayer.NewPlayer.Portrait = null;

            NotifyRoomInfo roomInfo = new NotifyRoomInfo();

            roomInfo.Players = new List <RoomPlayerInfo>();
            for (int i = 0; i < mPlayers.Count; ++i)
            {
                Player         p          = mPlayers[i];
                RoomPlayerInfo playerInfo = new RoomPlayerInfo();
                playerInfo.UserID   = p.mUserID;
                playerInfo.Name     = p.mPlayerInfo.NickName;
                playerInfo.Portrait = null;
                roomInfo.Players.Add(playerInfo);
            }
            float life = Time.ElapsedSeconds - mStartTime;

            roomInfo.RestTime = mTime - life;

            for (int i = 0; i < mPlayers.Count; ++i)
            {
                Player p = mPlayers[i];
                if (p == player)
                {
                    // 如果添加的玩家是自己,则通知自己所有角色数据;
                    NetWork.NotifyMessage <NotifyRoomInfo>(p.mUserID, STC.STC_RoomInfo, roomInfo);
                }
                else
                {
                    // 如果添加的玩家不是自己,则把添加的玩家数据通知自己;
                    NetWork.NotifyMessage <NotifyRoomAddPlayer>(p.mUserID, STC.STC_RoomAddPlayer, addPlayer);
                }
            }

            return(mPlayers.Count >= mMaxCount);
        }
        public IEnumerator clientQuitRoomTest()
        {
            UnityLogger logger = new UnityLogger();
            HostManager host   = new GameObject(nameof(HostManager)).AddComponent <HostManager>();

            host.logger = logger;
            host.start();

            ClientManager client = new GameObject(nameof(ClientManager)).AddComponent <ClientManager>();

            client.logger = logger;
            client.start();

            RoomPlayerInfo playerInfo = new RoomPlayerInfo()
            {
                name = "测试名字"
            };
            RoomInfo roomInfo = new RoomInfo()
            {
                ip = "127.0.0.1", port = host.port
            };

            Task <RoomInfo> roomTask = host.openRoom(roomInfo);

            yield return(roomTask.wait());

            roomInfo = roomTask.Result;

            roomTask = client.joinRoom(roomInfo, playerInfo);
            yield return(roomTask.wait());

            bool quitHost = false, quitClient = false;

            client.onQuitRoom += () =>
            {
                quitClient = true;
            };
            host.onPlayerQuit += (p) =>
            {
                Assert.AreEqual(p.name, playerInfo.name);
                quitHost = true;
            };
            client.quitRoom();

            yield return(new WaitForSeconds(1));

            Assert.True(quitClient);
            Assert.True(quitHost);
        }
Exemplo n.º 10
0
        public async Task joinRoom(RoomInfo roomInfo)
        {
            if (roomInfo == null)
            {
                throw new ArgumentNullException(nameof(roomInfo));
            }
            displayLoadingPanel();
            RoomPlayerInfo playerInfo = new RoomPlayerInfo();

            playerInfo.setProp(RoomPlayerInfoName.DECK_INTARRAY, getManager <GameManager>().deck);
            await client.joinRoom(roomInfo, playerInfo);

            ui.RoomButton.interactable = true;
            ui.RoomButton.image.color  = Color.white;
        }
Exemplo n.º 11
0
 public void SetPlayer(RoomPlayerInfo playerinfo, bool isRoomMaster)    //curIsMasterUI can operation all player
 {
     this.ResetPlayer();
     this.m_PlayerInfo   = playerinfo;
     this.m_IsRoomMaster = isRoomMaster;
     if (null != this.m_PlayerInfo)
     {
         this.UpdatePlayerName(this.m_PlayerInfo.mPlayerInfo.mName);
         this.UpdateDelay(this.m_PlayerInfo.mDelay);
         this.UpdateState(this.m_PlayerInfo.mState);
         this.UpdateRoomMasterMark(this.m_PlayerInfo.mRoomMaster);
         this.UpdateExitBtnState(isRoomMaster && this.m_PlayerInfo.mId != BaseNetwork.MainPlayer.Id);
         this.UpdateSelect(playerinfo.mId == BaseNetwork.MainPlayer.Id);
     }
 }
Exemplo n.º 12
0
    public void AddAiPlayer(long aiPlayerId, string account)
    {
        if (_playersAi.ContainsKey(aiPlayerId))
        {
            Log($"GameRoomManager AddAiPlayer Error - Duplicated Ai Player! - {account} - {aiPlayerId}");
        }
        RoomPlayerInfo rpi = gameObject.AddComponent <RoomPlayerInfo>();

        if (rpi)
        {
            rpi.Init(account, aiPlayerId);
            RoomLogic.ActorManager.SetAiRights(aiPlayerId, true);
            _playersAi[aiPlayerId] = rpi;
        }
    }
Exemplo n.º 13
0
        /// <summary>
        /// 创建一个房间
        /// </summary>
        /// <returns></returns>
        public void createRoom()
        {
            host.start(_port);
            RoomInfo room = host.openRoom(new RoomInfo());

            room.setOption(new GameOption()
            {
                randomSeed = (int)DateTime.Now.ToBinary()
            });
            displayLoadingPanel();
            RoomPlayerInfo playerInfo = new RoomPlayerInfo();

            playerInfo.setProp(RoomPlayerInfoName.DECK_INTARRAY, getManager <GameManager>().deck);
            Task.Run(async() => { await client.joinRoom(room, playerInfo); });
            ui.RoomButton.interactable = true;
            ui.RoomButton.image.color  = Color.white;
        }
Exemplo n.º 14
0
    private void AddForcePlayerItem(RoomPlayerInfo playerInfo)
    {
        ForcePlayerItem_N forcePlayerItem_N = null;

        if (this.m_CurForcePlayerItems != null)
        {
            forcePlayerItem_N = this.m_CurForcePlayerItems.FirstOrDefault(a => a.GetRoleID() == playerInfo.mRoleID && a.GetPlayerID() == -1);
        }
        if (null == forcePlayerItem_N)
        {
            forcePlayerItem_N = this.GetNewForcePlayerItem();
        }
        forcePlayerItem_N.SetPlayer(playerInfo, this.m_IsRoomMaster);
        this.TryAddNullItem();
        this.UpdateForcePlayerCount();
        this.RepostionForce();
    }
Exemplo n.º 15
0
        private static void createRoomPlayer12(HostManager host, out RoomPlayerInfo playerInfo1, out RoomPlayerInfo playerInfo2, out RoomInfo roomInfo)
        {
            playerInfo1 = new RoomPlayerInfo()
            {
                name = "测试名字1"
            };
            playerInfo2 = new RoomPlayerInfo()
            {
                name = "测试名字2"
            };
            playerInfo2.PlayerID = playerInfo1.PlayerID + 1;

            roomInfo = new RoomInfo()
            {
                ip = "127.0.0.1", port = host.port, OwnerID = playerInfo1.PlayerID
            };
        }
Exemplo n.º 16
0
 //log:lz-2016.05.09  1.玩家存在于某个的阵营就是改变阵营,先从原来的阵营移除,然后加入新的阵营,  2.否者 就直接加入
 public static void ChangeRoomPlayerByNet(RoomPlayerInfo playerInfo)
 {
     if (null == Instance)
     {
         return;
     }
     Instance.TryRemovePlayer(playerInfo.mId);
     if (Instance.m_ForceDic != null && Instance.m_ForceDic.Count() > 0)
     {
         ForceItem_N newForceItem = Instance.m_ForceItemList.FirstOrDefault(item => item.GetForceID() == playerInfo.mFocreID);
         if (null != newForceItem)
         {
             newForceItem.JoinForceByNet(playerInfo, Instance.m_IsRoomMaster);
             Instance.m_ForceDic[playerInfo.mFocreID].Add(playerInfo.mId, playerInfo.mRoleID);
             Instance.ActiveStartBtn();
         }
     }
 }
Exemplo n.º 17
0
    void RPC_S2C_TeamChange(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        int index  = stream.Read <int>();
        int descId = stream.Read <int>();

        if (!Pathea.PeGameMgr.IsMultiCustom)
        {
            if (TeamId == index)
            {
                return;
            }
        }

        _teamId = index;
        _descId = descId;
        RoomPlayerInfo rpi;

        if (!RolesInRoom.ContainsKey(Id))
        {
            rpi     = new RoomPlayerInfo();
            rpi.mId = Id;
            rpi.mPlayerInfo.mName = Role.name;
            rpi.mPlayerInfo.mSex  = Role.sex;
            RolesInRoom[Id]       = rpi;
        }
        else
        {
            rpi = RolesInRoom[Id];
        }

        rpi.mPlayerInfo.mLevel    = Role.level;
        rpi.mPlayerInfo.mWinnRate = Role.winrate;
        rpi.mFocreID = Pathea.PeGameMgr.IsSurvive && !Pathea.PeGameMgr.IsCustom ? -1 : TeamId;
        rpi.mRoleID  = _descId;
        rpi.mState   = (int)NetworkState;

        _steamID = SteamMgr.steamId;

        if (null != RoomGui_N.Instance && RoomGui_N.Instance.isShow)
        {
            RoomGui_N.ChangeRoomPlayerByNet(rpi);
        }
    }
Exemplo n.º 18
0
    void RPC_S2C_InitData(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        _networkState = stream.Read <ENetworkState>();
        _teamId       = stream.Read <int>();
        _colorIndex   = stream.Read <int>();
        _descId       = stream.Read <int>();

        RoomPlayerInfo rpi = new RoomPlayerInfo();

        rpi.mId = Id;
        rpi.mPlayerInfo.mName     = Role.name;
        rpi.mPlayerInfo.mSex      = Role.sex;
        rpi.mPlayerInfo.mLevel    = Role.level;
        rpi.mPlayerInfo.mWinnRate = Role.winrate;
        rpi.mFocreID = Pathea.PeGameMgr.IsSurvive && !Pathea.PeGameMgr.IsCustom ? -1 : TeamId;
        rpi.mRoleID  = _descId;
        rpi.mState   = (int)NetworkState;
        RoomGui_N.InitRoomPlayerByNet(rpi);
    }
Exemplo n.º 19
0
    void NotifyRoomInfo(byte[] data)
    {
        NotifyRoomInfo roomInfo = ProtoBufUtils.Deserialize <NotifyRoomInfo>(data);

        for (int i = 0; i < roomInfo.Players.Count; ++i)
        {
            RoomPlayerInfo roomPlayerInfo = roomInfo.Players[i];
            if (roomPlayerInfo == null)
            {
                continue;
            }
            texPlayerNames[i].text = roomPlayerInfo.Name;
            playerIDs[i]           = roomPlayerInfo.UserID;
            ++playerCount;
        }
        restTime = roomInfo.RestTime;
        endTime  = Time.realtimeSinceStartup + roomInfo.RestTime;

        mainMenuRoot.SetActive(false);
        matchRoot.SetActive(true);
    }
Exemplo n.º 20
0
 public static void InitRoomPlayerByNet(RoomPlayerInfo playerInfo)
 {
     if (null == Instance)
     {
         return;
     }
     InitRoomForceByNet();
     Instance.m_IsRoomMaster = GameClientNetwork.MasterId == BaseNetwork.MainPlayer.Id;
     if (playerInfo.mId != -1 /* && playerInfo.mFocreID != -1*/)
     {
         if (Instance.m_ForceDic.ContainsKey(playerInfo.mFocreID))
         {
             var playerDic = Instance.m_ForceDic[playerInfo.mFocreID];
             playerDic[playerInfo.mId] = playerInfo.mRoleID;
             ChangeRoomPlayerByNet(playerInfo);
         }
         else
         {
             Debug.Log("Find Not contains ForceID: " + playerInfo.mFocreID + "  PlayerID: " + playerInfo.mId + "  RoleID: " + playerInfo.mRoleID);
         }
     }
 }
Exemplo n.º 21
0
        public IEnumerator hostCloseRoomTest()
        {
            HostManager   host;
            ClientManager client;

            createHostClient(out host, out client);

            RoomPlayerInfo playerInfo = new RoomPlayerInfo()
            {
                name = "测试名字"
            };
            RoomInfo roomInfo = new RoomInfo()
            {
                ip = "127.0.0.1", port = host.port
            };

            host.openRoom(roomInfo);
            yield return(new WaitForSeconds(0.5f));

            var task = client.joinRoom(roomInfo, playerInfo);

            yield return(new WaitUntil(() => task.IsCompleted));

            bool quitClient = false;

            client.onQuitRoom += () =>
            {
                quitClient = true;
            };

            host.closeRoom();
            yield return(new WaitForSeconds(1));

            if (!quitClient)
            {
                throw new TimeoutException("客户端退出超时。");
            }
        }
Exemplo n.º 22
0
 private void ServerConnection_OtherLeftRoom(object sender, RoomPlayerInfo player)
 {
     _updateList = true;
 }
Exemplo n.º 23
0
        public IEnumerator checkRoomInfoTest()
        {
            UnityLogger logger = new UnityLogger();
            HostManager host   = new GameObject(nameof(HostManager) + "1").AddComponent <HostManager>();

            host.logger = logger;
            host.start();
            ClientManager client1 = new GameObject(nameof(ClientManager) + "1").AddComponent <ClientManager>();

            client1.logger = logger;
            client1.start();
            ClientManager client2 = new GameObject(nameof(ClientManager) + "2").AddComponent <ClientManager>();

            client2.logger = logger;
            client2.start();

            RoomPlayerInfo playerInfo1 = new RoomPlayerInfo()
            {
                name = "测试名字1"
            };
            RoomPlayerInfo playerInfo2 = new RoomPlayerInfo()
            {
                name = "测试名字2"
            };
            RoomInfo roomInfo = new RoomInfo()
            {
                ip = "127.0.0.1", port = host.port
            };
            RoomInfo roomInfo2 = new RoomInfo()
            {
                ip = "127.0.0.1", port = host.port
            };

            host.openRoom(roomInfo);
            yield return(new WaitForSeconds(0.5f));

            bool     roomFoundFlag = false;
            RoomInfo questRoomInfo = null;

            client1.onRoomFound += (info) =>
            {
                if (!roomFoundFlag)
                {
                    roomFoundFlag = true;
                    questRoomInfo = info;
                }
            };
            client1.findRoom(host.port);
            yield return(new WaitForSeconds(0.5f));

            Assert.AreEqual(roomFoundFlag, true);

            var task = client1.checkRoomInfo(questRoomInfo);

            yield return(new WaitUntil(() => task.IsCompleted));

            Assert.NotNull(task.Result);
            Assert.AreEqual(questRoomInfo.playerList.Count, task.Result.playerList.Count);
            Assert.AreEqual(questRoomInfo.ip, task.Result.ip);
            Assert.AreEqual(questRoomInfo.port, task.Result.port);

            yield return(new WaitForSeconds(0.5f));

            var task2 = client2.joinRoom(roomInfo2, playerInfo2);

            yield return(new WaitUntil(() => task2.IsCompleted));

            yield return(new WaitForSeconds(0.5f));

            Assert.AreEqual(1, host.room.playerList.Count);

            task = client1.checkRoomInfo(questRoomInfo);
            yield return(new WaitUntil(() => task.IsCompleted));

            Assert.NotNull(task.Result);
            Assert.AreEqual(1, task.Result.playerList.Count);
            Assert.AreEqual(playerInfo2.name, task.Result.playerList[0].name);

            host.closeRoom();
            yield return(new WaitForSeconds(0.5f));

            task = client1.checkRoomInfo(questRoomInfo);
            yield return(new WaitUntil(() => task.IsCompleted));

            Assert.Null(task.Result);
        }
Exemplo n.º 24
0
 public static void setDeck(this RoomPlayerInfo playerInfo, int[] value)
 {
     playerInfo.setProp(DECK_INTARRAY, value);
 }
Exemplo n.º 25
0
 public virtual void OnPlayerJoinRoom(RoomPlayerInfo info)
 {
 }
Exemplo n.º 26
0
    public void FromBytes(byte[] data, ref int offset)
    {
        int id = (int)data[offset++];

        int nameLength = (int)data[offset++];
        string name = Encoding.UTF8.GetString(data, offset, nameLength);
        offset += nameLength;

        int spawnPointID = (int)data[offset++];

        PlayerSetupData setup = new PlayerSetupData(data, ref offset);
        Player = new RoomPlayerInfo(id, name, spawnPointID, setup.Setup);
    }
Exemplo n.º 27
0
    public void FromBytes(byte[] data, ref int offset)
    {
        int roomID = BitConverter.ToInt32(data, offset);
        offset += 4;

        int nameLength = (int)data[offset++];
        string name = Encoding.UTF8.GetString(data, offset, nameLength);
        offset += nameLength;

        int maxPlayers = (int)data[offset++];
        int mapID = (int)data[offset++];
        int creatorID = (int)data[offset++];

        int playerAmount = (int)data[offset++];
        RoomPlayerInfo[] players = new RoomPlayerInfo[playerAmount];
        for (int i = 0; i < playerAmount; i++)
        {
            players[i] = new RoomPlayerData(data, ref offset).Player;
        }

        Room = new GameRoom(roomID, name, maxPlayers, mapID, creatorID);
        Room.Players.AddRange(players);
    }
Exemplo n.º 28
0
 public override void OnPlayerJoinRoom(RoomPlayerInfo info)
 {
     EventHelper.Trigger(EEvent.OnPlayerJoinRoom, info);
 }
Exemplo n.º 29
0
 //server backcall
 public void JoinForceByNet(RoomPlayerInfo playerInfo, bool isRoomMaster)
 {
     this.m_IsRoomMaster = isRoomMaster;
     this.AddForcePlayerItem(playerInfo);
 }
Exemplo n.º 30
0
 public static int[] getDeck(this RoomPlayerInfo playerInfo)
 {
     return(playerInfo.getProp <int[]>(DECK_INTARRAY));
 }
Exemplo n.º 31
0
 private void AddPlayerRow(RoomPlayerInfo playerInfo)
 {
     _playerListView.AddRow(new string[] { playerInfo.PlayerName, playerInfo.Setup.BoatID.ToString(), playerInfo.Setup.FlagColorID.ToString(), playerInfo.Setup.Ready.ToString() });
 }
Exemplo n.º 32
0
        public IEnumerator remotePVPSimulTest()
        {
            UnityLogger logger = new UnityLogger();
            HostManager host   = new GameObject(nameof(HostManager)).AddComponent <HostManager>();

            host.logger = logger;
            ClientManager local = new GameObject(nameof(ClientManager)).AddComponent <ClientManager>();

            local.logger = logger;
            //开房,打开Host,自己加入自己,房间应该有Option
            RoomInfo roomInfo = new RoomInfo();

            roomInfo.setOption(new GameOption());
            THHGame localGame = null;

            local.onConnected += () =>
            {
                //发送玩家信息
                RoomPlayerInfo playerInfo = new RoomPlayerInfo()
                {
                    id   = local.id,
                    name = "玩家" + local.id,
                };
                playerInfo.setDeck(new int[] { Reimu.ID }.Concat(Enumerable.Repeat(DrizzleFairy.ID, 30)).ToArray());
                return(local.send(playerInfo));
            };
            local.onReceive += (id, obj) =>
            {
                if (obj is RoomPlayerInfo newPlayerInfo)
                {
                    //收到玩家信息
                    RoomInfo newRoomInfo = new RoomInfo()
                    {
                        playerList = new List <RoomPlayerInfo>(roomInfo.playerList)
                    };
                    newRoomInfo.setOption(roomInfo.getOption());
                    newRoomInfo.playerList.Add(newPlayerInfo);
                    //发送房间信息
                    return(local.send(newRoomInfo));
                }
                else if (obj is RoomInfo newRoomInfo)
                {
                    roomInfo = newRoomInfo;
                    //收到房间信息
                    if (newRoomInfo.playerList.Count > 1)
                    {
                        localGame = TestGameflow.initGameWithoutPlayers("本地游戏", newRoomInfo.getOption());
                        (localGame.answers as AnswerManager).client = local;
                        foreach (var playerInfo in newRoomInfo.playerList)
                        {
                            localGame.createPlayer(playerInfo.id, "玩家" + playerInfo.id, localGame.getCardDefine <MasterCardDefine>(playerInfo.getDeck()[0]), playerInfo.getDeck().Skip(1).Select(did => localGame.getCardDefine(did)));
                        }
                        localGame.run();
                    }
                }
                return(Task.CompletedTask);
            };
            host.start();
            local.start();
            yield return(local.join(host.ip, host.port).wait());

            Assert.AreEqual(1, roomInfo.playerList.Count);

            ClientManager remote = new GameObject(nameof(ClientManager)).AddComponent <ClientManager>();

            remote.logger = logger;
            THHGame remoteGame = null;

            remote.onConnected += () =>
            {
                //发送玩家信息
                RoomPlayerInfo playerInfo = new RoomPlayerInfo()
                {
                    id   = remote.id,
                    name = "玩家" + remote.id
                };
                playerInfo.setDeck(new int[] { Reimu.ID }.Concat(Enumerable.Repeat(DrizzleFairy.ID, 30)).ToArray());
                return(remote.send(playerInfo));
            };
            remote.onReceive += (id, obj) =>
            {
                if (obj is RoomInfo newRoomInfo)
                {
                    //收到房间信息
                    if (newRoomInfo.playerList.Count > 1)
                    {
                        remoteGame = TestGameflow.initGameWithoutPlayers("远端游戏", newRoomInfo.getOption());
                        (remoteGame.answers as AnswerManager).client = remote;
                        foreach (var playerInfo in newRoomInfo.playerList)
                        {
                            remoteGame.createPlayer(playerInfo.id, "玩家" + playerInfo.id, remoteGame.getCardDefine <MasterCardDefine>(playerInfo.getDeck()[0]), playerInfo.getDeck().Skip(1).Select(did => remoteGame.getCardDefine(did)));
                        }
                        remoteGame.run();
                    }
                }
                return(Task.CompletedTask);
            };
            //加入房间
            remote.start();
            yield return(remote.join(host.ip, host.port).wait());

            //连接了,远程玩家把玩家信息发给本地,本地更新房间信息发给远端和开始游戏。
            yield return(new WaitUntil(() => localGame != null && remoteGame != null));

            Assert.True(localGame.isRunning);
            Assert.AreEqual(local.id, localGame.players[0].id);
            Assert.AreEqual(remote.id, localGame.players[1].id);
            Assert.True(remoteGame.isRunning);
            Assert.AreEqual(local.id, remoteGame.players[0].id);
            Assert.AreEqual(remote.id, remoteGame.players[1].id);

            THHPlayer localPlayer = localGame.getPlayer(local.id);

            Assert.AreEqual(0, localPlayer.id);
            yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is InitReplaceRequest));

            Assert.Greater(localPlayer.init.count, 0);
            localPlayer.cmdInitReplace(localGame);
            yield return(new WaitUntil(() => localGame.answers.getResponse(localPlayer.id, localGame.answers.getRequests(localPlayer.id).FirstOrDefault()) is InitReplaceResponse));

            THHPlayer remotePlayer = remoteGame.getPlayer(remote.id);

            Assert.AreEqual(1, remotePlayer.id);
            yield return(new WaitUntil(() => remoteGame.answers.getRequests(remotePlayer.id).FirstOrDefault() is InitReplaceRequest));

            Assert.Greater(remotePlayer.init.count, 0);
            remotePlayer.cmdInitReplace(remoteGame);
            yield return(new WaitUntil(() => remoteGame.triggers.getRecordedEvents().Any(e => e is THHGame.StartEventArg)));

            //拍怪
            if (localGame.sortedPlayers[0] == localPlayer)
            {
                yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is FreeActRequest));

                localPlayer.cmdUse(localGame, localPlayer.hand[0], 0);
                yield return(new WaitUntil(() => localPlayer.field.count > 0));

                localPlayer.cmdTurnEnd(localGame);
                yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer));
            }
            yield return(new WaitUntil(() => remoteGame.answers.getRequests(remotePlayer.id).FirstOrDefault() is FreeActRequest));

            remotePlayer.cmdUse(remoteGame, remotePlayer.hand[0], 0);
            yield return(new WaitUntil(() => remotePlayer.field.count > 0));

            remotePlayer.cmdTurnEnd(remoteGame);
            yield return(new WaitUntil(() => remoteGame.currentPlayer != remotePlayer));

            if (localGame.sortedPlayers[0] != localPlayer)
            {
                yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is FreeActRequest));

                localPlayer.cmdUse(localGame, localPlayer.hand[0], 0);
                yield return(new WaitUntil(() => localPlayer.field.count > 0));

                localPlayer.cmdTurnEnd(localGame);
                yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer));
            }
            do
            {
                yield return(new WaitUntil(() => localGame.currentPlayer == localPlayer || remoteGame.currentPlayer == remotePlayer));

                if (localGame.currentPlayer == localPlayer)
                {
                    localPlayer.cmdAttack(localGame, localPlayer.field[0], localGame.getOpponent(localPlayer).master);
                    yield return(new WaitUntil(() => localPlayer.field[0].getAttackTimes(localGame) > 0));

                    localPlayer.cmdTurnEnd(localGame);
                    yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer));
                }
                else if (remoteGame.currentPlayer == remotePlayer)
                {
                    remotePlayer.cmdAttack(remoteGame, remotePlayer.field[0], remoteGame.getOpponent(remotePlayer).master);
                    yield return(new WaitUntil(() => remotePlayer.field[0].getAttackTimes(remoteGame) > 0));

                    remotePlayer.cmdTurnEnd(remoteGame);
                    yield return(new WaitUntil(() => remoteGame.currentPlayer != remotePlayer));
                }
            }while (localGame.isRunning && remoteGame.isRunning);

            local.disconnect();
            remote.disconnect();
            yield break;
        }
Exemplo n.º 33
0
 private void ServerConnection_OtherChangedSetup(object sender, RoomPlayerInfo player)
 {
     _updateList = true;
 }
Exemplo n.º 34
0
 public SpawnedPlayer(GameObject boat, RoomPlayerInfo info)
 {
     Boat = boat;
     Manager = boat.GetComponent<BoatManager>();
     Positioning = new PositioningData(Boat.transform.position, Boat.transform.eulerAngles);
     ShootBuffer = new ShootingData();
     HitBuffer = new List<HealthData>();
     Info = info;
     Updated = true;
 }
Exemplo n.º 35
0
 public override void OnPlayerJoinRoom(RoomPlayerInfo info)
 {
     Log("OnPlayerJoinRoom  " + info);
     Log("SomeOne joined so: StartGame  ");
     _loginMgr.StartGame();
 }
 private void OnOtherLeftRoom(RoomPlayerInfo playerInfo)
 {
     if (OtherLeftRoom != null) OtherLeftRoom(this, playerInfo);
 }