Exemplo n.º 1
0
    public void EnterRoomReq()
    {
        EnterRoom req = new EnterRoom();

        string[] str = transform.Find("ID").GetComponent <Text>().text.Split(':');
        req.room_id = Convert.ToInt32(str[1]);
        NetWorkManagement.Instance.SendProtobufCmd((int)Stype.game_server, (int)Cmd.eEnterRoom, req);
    }
    public static void EnterRoomRequest(string roomId)
    {
        EnterRoom request = new EnterRoom();

        request.RoomId = roomId;
        byte[] data = NetworkUtils.Serialize(request);
        Enqueue(MessageType.EnterRoomRequest, data);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 加入房间
    /// </summary>
    public void EnterRoomRequest(int roomId)
    {
        EnterRoom request = new EnterRoom();

        request.roomId = roomId;
        byte[] data = NetworkUtils.Serialize(request);
        NetworkClient.Enqueue(MessageType.EnterRoom, data);
    }
Exemplo n.º 4
0
    private void _EnterRoom(Player player, byte[] data)
    {
        //结果
        EnterRoom result = new EnterRoom();

        EnterRoom receive = NetworkUtils.Deserialize <EnterRoom>(data);

        //逻辑检测(玩家不在任何房间中 并且 存在该房间)
        if (!player.InRoom && Server.Rooms.ContainsKey(receive.RoomId))
        {
            Room room = Server.Rooms[receive.RoomId];
            //加入玩家
            if (room.Players.Count < Room.MAX_PLAYER_AMOUNT && !room.Players.Contains(player))
            {
                room.Players.Add(player);
                player.EnterRoom(receive.RoomId);

                Console.WriteLine($"玩家:{player.Name}成为了房间:{receive.RoomId}的玩家");

                //向玩家发送成功操作结果
                result.RoomId = receive.RoomId;
                result.result = EnterRoom.Result.Player;
                data          = NetworkUtils.Serialize(result);
                player.Send(MessageType.EnterRoom, data);
            }
            //加入观察者
            else if (room.OBs.Count < Room.MAX_OBSERVER_AMOUNT && !room.OBs.Contains(player))
            {
                room.OBs.Add(player);
                player.EnterRoom(receive.RoomId);

                Console.WriteLine($"玩家:{player.Name}成为了房间:{receive.RoomId}的观察者");

                //向玩家发送成功操作结果
                result.RoomId = receive.RoomId;
                result.result = EnterRoom.Result.Observer;
                data          = NetworkUtils.Serialize(result);
                player.Send(MessageType.EnterRoom, data);
            }
            //加入房间失败
            else
            {
                Console.WriteLine($"玩家:{player.Name}加入房间失败");

                result.result = EnterRoom.Result.None;
                data          = NetworkUtils.Serialize(result);
                player.Send(MessageType.EnterRoom, data);
            }
        }
        else
        {
            Console.WriteLine($"玩家:{player.Name}进入房间失败");
            //向玩家发送失败操作结果
            data = NetworkUtils.Serialize(result);
            player.Send(MessageType.EnterRoom, data);
        }
    }
    public void CreateJoinRoom(EnterRoomData roomData)
    {
        Debug.Log("GameRoomManager CreateJoinRoom() Begin...");
        if (roomData.IsCreatingRoom)
        {// 创建房间流程
            Log($"MSG: CreateJoinRoom - 创建房间:{roomData.RoomName}");

            // 把地图数据上传到房间服务器保存。后面的和加入房间一样了。
            BinaryReader reader = HexmapHelper.BeginLoadBuffer(roomData.RoomName);
            if (reader != null)
            {
                const int CHUNK_SIZE = 900;
                byte[]    bytes      = new byte[CHUNK_SIZE];
                int       size       = CHUNK_SIZE;
                bool      isFileEnd  = false;
                int       index      = 0;
                while (!isFileEnd)
                {
                    if (!HexmapHelper.LoadBuffer(reader, out bytes, ref size, ref isFileEnd))
                    {
                        Log($"Load Buffer Failed - {roomData.RoomName}");
                    }

                    UploadMap output = new UploadMap()
                    {
                        RoomName       = roomData.RoomName,
                        MaxPlayerCount = roomData.MaxPlayerCount,
                        MapData        = ByteString.CopyFrom(bytes),
                        PackageIndex   = index++,
                        IsLastPackage  = isFileEnd,
                    };

                    SendMsg(ROOM.UploadMap, output.ToByteArray());
                }

                Log($"MSG: 发送地图数据 - 地图名:{roomData.RoomName} - Total Size:{reader.BaseStream.Length}");
                HexmapHelper.EndLoadBuffer(ref reader);
            }
        }
        else
        {// 直接申请进入房间
            // 发出EnterRoom消息,进入房间
            EnterRoom output = new EnterRoom()
            {
                RoomId = roomData.RoomId,
            };
            SendMsg(ROOM.EnterRoom, output.ToByteArray());
            Log($"MSG: CreateJoinRoom - 申请进入房间:{roomData.RoomName}");
        }
    }
    private static void _EnterRoom(byte[] data)
    {
        EnterRoom result = NetworkUtils.Deserialize <EnterRoom>(data);

        if (result.Suc)
        {
            NetworkPlayer.Instance.OnRoomIdChange(result.RoomId);
            NetworkPlayer.Instance.OnGUIDChange(result.GUID);
        }
        else
        {
            NetworkPlayer.Instance.RoomId = "-2";
            Debug.Log("加入房间失败");
        }
    }
Exemplo n.º 7
0
        public void EndAll()
        {
            Bg.Dispose();
            gold.Dispose();
            EncWumpus.Dispose();
            EncPit.Dispose();
            EnterRoom.Dispose();
            LeaveRoom.Dispose();
            Trivia.Dispose();
            ArrowShot.Dispose();
            Shoots.Dispose();
            highscore.Dispose();
            Menu.Dispose();
            bats.Dispose();

            Attack.Dispose();
        }
        private void _EnterRoom(Player player, byte[] data)
        {
            //结果
            EnterRoom result = new EnterRoom();

            EnterRoom receive = NetworkUtils.Deserialize <EnterRoom>(data);

            //逻辑检测(玩家不在任何房间中 并且 存在该房间)
            if (!player.InRoom && Server.Rooms.ContainsKey(receive.RoomId))
            {
                Room room = Server.Rooms[receive.RoomId];
                //加入玩家
                if (room.Players.Count < Room.MAX_PLAYER_AMOUNT && !room.Players.Contains(player))
                {
                    room.Players.Add(player);
                    player.EnterRoom(receive.RoomId);



                    //向玩家发送成功操作结果
                    result.RoomId = receive.RoomId;
                    result.Suc    = true;
                    result.GUID   = room.Players.Count;
                    player.GUID   = result.GUID;
                    Console.WriteLine($"玩家:{player.NickName}成为了房间:{receive.RoomId}的玩家, GUID为{player.GUID}");
                    data = NetworkUtils.Serialize(result);
                    player.Send(MessageType.EnterRoomRequest, data);
                }

                else
                {
                    Console.WriteLine($"玩家:{player.NickName}加入房间失败");

                    result.Suc = false;
                    data       = NetworkUtils.Serialize(result);
                    player.Send(MessageType.EnterRoomRequest, data);
                }
            }
            else
            {
                Console.WriteLine($"玩家:{player.NickName}进入房间失败");
                //向玩家发送失败操作结果
                data = NetworkUtils.Serialize(result);
                player.Send(MessageType.EnterRoomRequest, data);
            }
        }
Exemplo n.º 9
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.tag.Equals ("PlayerShip"))
        {
            EnterRoom enterRoomEvent = new EnterRoom (transform, isFirstTime);
            GameEvents.GameEventManager.post (enterRoomEvent);

            if(isFirstTime)
            {
                blockRoom();
            }

            isFirstTime = false;

            for(int i=0; i<transform.childCount; i++)
            {
                transform.GetChild(i).gameObject.SetActive(true);
            }
        }
    }
Exemplo n.º 10
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.tag.Equals("PlayerShip"))
        {
            EnterRoom enterRoomEvent = new EnterRoom(transform, isFirstTime);
            GameEvents.GameEventManager.post(enterRoomEvent);

            if (isFirstTime)
            {
                blockRoom();
            }

            isFirstTime = false;

            for (int i = 0; i < transform.childCount; i++)
            {
                transform.GetChild(i).gameObject.SetActive(true);
            }
        }
    }
Exemplo n.º 11
0
    private void _EnterRoom(byte[] data)
    {
        EnterRoom result = NetworkUtils.Deserialize <EnterRoom>(data);

        if (result.result == EnterRoom.Result.Player)
        {
            Info.Instance.Print("加入房间成功, 你是一名玩家");
        }
        else if (result.result == EnterRoom.Result.Observer)
        {
            Info.Instance.Print("加入房间成功, 你是一名观察者");
        }
        else
        {
            Info.Instance.Print("加入房间失败");
            return;
        }

        //进入房间
        NetworkPlayer.Instance.OnRoomIdChange(result.roomId);
    }
Exemplo n.º 12
0
    private static void UPLOAD_MAP_REPLY(byte[] bytes)
    {
        UploadMapReply input = UploadMapReply.Parser.ParseFrom(bytes);

        if (!input.Ret)
        {
            string msg = "上传地图失败!";
            UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error);
            GameRoomManager.Instance.Log("MSG: UPLOAD_MAP_REPLY Error - " + msg);
            return;
        }

        if (input.IsLastPackage)
        {
            GameRoomManager.Instance.Log($"MSG: UPLOAD_MAP_REPLY OK - 上传地图成功!RoomID:{input.RoomId}");
            // 发出EnterRoom消息,进入房间
            EnterRoom output = new EnterRoom()
            {
                RoomId = input.RoomId,
            };
            GameRoomManager.Instance.SendMsg(ROOM.EnterRoom, output.ToByteArray());
            GameRoomManager.Instance.Log($"MSG: UPLOAD_MAP_REPLY OK - 申请进入战场:{input.RoomName}");
        }
    }
Exemplo n.º 13
0
    //ゲーム開始時に一度
    void Start()
    {
        hp_manager_ = GetComponent<HPManager>();
        enemy_stater_ = GetComponent<EnemyStater>();

        //Playerオブジェクトを検索し、参照を代入
        player = GameObject.FindGameObjectWithTag("Player").transform;
        distance_state = DISTANCE_STATE.LONG;
        attack_state = ATTACK_STATE.WAIT;

        right_weapon_ = right_weapon_object_.GetComponentInChildren<Weapon>();
        left_weapon_ = left_weapon_object_.GetComponentInChildren<Weapon>();

        var id = GetComponent<Identificationer>().id;
        var air_frame_parameter = FindObjectOfType<AirFrameParameter>();
        speed = air_frame_parameter.GetMoveSpeed(id);
        JUMP_POWER = air_frame_parameter.GetJumpPower(id);
        BOOST_POWER = air_frame_parameter.GetBoostPower(id);

        foreach (var room in FindObjectsOfType<EnterRoom>())
        {
            if (room.transform.parent.name.GetHashCode() != roomName.GetHashCode()) continue;
            enter_room_ = room;
            Debug.Log(gameObject.name);
        }
    }
Exemplo n.º 14
0
    private static void ENTER_ROOM(byte[] bytes)
    {
        bool      ret       = false;
        string    errMsg    = "";
        EnterRoom input     = EnterRoom.Parser.ParseFrom(bytes);
        RoomLogic roomLogic = ServerRoomManager.Instance.GetRoomLogic(input.RoomId);

        if (roomLogic == null)
        { // 房间没有开启,需要开启并进入
            roomLogic = new RoomLogic();
            if (roomLogic != null)
            {
                string tableName = $"MAP:{input.RoomId}";
                if (ServerRoomManager.Instance.Redis.CSRedis.Exists(tableName))
                {
                    long        createrId = ServerRoomManager.Instance.Redis.CSRedis.HGet <long>(tableName, "Creator");
                    NetRoomInfo roomInfo  = new NetRoomInfo()
                    {
                        RoomId         = ServerRoomManager.Instance.Redis.CSRedis.HGet <long>(tableName, "RoomId"),
                        MaxPlayerCount =
                            ServerRoomManager.Instance.Redis.CSRedis.HGet <int>(tableName, "MaxPlayerCount"),
                        RoomName = ServerRoomManager.Instance.Redis.CSRedis.HGet <string>(tableName, "RoomName"),
                        Creator  = createrId,
                    };
                    // 初始化
                    roomLogic.Init(roomInfo);
                    ServerRoomManager.Instance.AddRoomLogic(roomInfo.RoomId, roomLogic);
                }
                else
                {// 房间地图数据没有找到,等于没有创建房间
                    roomLogic = null;
                }
            }
        }

        PlayerInfo       pi   = null;
        PlayerInfoInRoom piir = null;

        if (roomLogic == null)
        {
            errMsg = $"Battlefield is not found! RoomId:{input.RoomId}"; // 战场没有找到!
        }
        else
        {
            pi = ServerRoomManager.Instance.GetPlayer(_args);
            if (pi == null)
            {
                errMsg = "PlayerInfo is not found!"; // 玩家没有找到!
            }
            else
            {
                pi.RoomId = input.RoomId;
                piir      = roomLogic.GetPlayerInRoom(pi.Enter.TokenId);
                if (piir == null)
                {
                    errMsg = "PlayerInfoInRoom is not found!"; // 玩家没有找到!
                    roomLogic.Online(_args, pi.Enter, pi.RoomId);
                    piir = roomLogic.GetPlayerInRoom(pi.Enter.TokenId);
                }
            }
        }

        if (piir != null)
        {
            // 把当前玩家设置为在线(所有玩家信息在房间创建的时候(RoomLogic.Init)就存在了, 只是不在线)
            roomLogic.Online(_args, pi.Enter, input.RoomId);

            // 通知大厅
            ServerRoomManager.Instance.UpdateRoomInfoToLobby(roomLogic);

            // 返回成功
            EnterRoomReply output = new EnterRoomReply()
            {
                Ret      = true,
                RoomId   = roomLogic.RoomId,
                RoomName = roomLogic.RoomName,
            };
            ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.EnterRoomReply, output.ToByteArray());
            ServerRoomManager.Instance.Log($"MSG: ENTER_ROOM OK - Player enters the battlefield! Account:{pi.Enter.Account} - Room:{roomLogic.RoomName}"); // 玩家进入战场!
        }
        else
        {   // 返回失败
            EnterRoomReply output = new EnterRoomReply()
            {
                Ret    = false,
                ErrMsg = errMsg,
            };
            ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.EnterRoomReply, output.ToByteArray());
            ServerRoomManager.Instance.Log("MSG: ENTER_ROOM Error - " + errMsg);
        }
    }