Esempio n. 1
0
        private void RunAsync(Session session, L2M_TeamModifyMember message, Action <M2L_TeamModifyMember> reply)
        {
            M2L_TeamModifyMember response = new M2L_TeamModifyMember();

            try
            {
                var roomComponent = Game.Scene.GetComponent <RoomComponent>();
                var room          = roomComponent.Get(message.RoomId);
                if (room == null)
                {
                    response.Error = ErrorCode.ERR_RoomIdNotFound;
                    reply(response);
                    return;
                }
                var roomTeamComponent = room.GetComponent <RoomTeamComponent>();
                if (roomTeamComponent == null)
                {
                    response.Error = ErrorCode.ERR_RoomTeamComponentNull;
                    reply(response);
                    return;
                }
                TeamMemberData       selfMemberData       = roomTeamComponent.GetMember(message.Uid);
                M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember();
                m2c_TeamModifyMember.Uid        = message.Uid;
                m2c_TeamModifyMember.MemberData = selfMemberData;
                MapMessageHelper.BroadcastRoom(room.Id, m2c_TeamModifyMember, message.Uid);
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public static async void LoadingFinish(RoomTeamComponent roomTeamComponent)
        {
            if (roomTeamComponent.DataIsLoaded)
            {
                return;
            }

            roomTeamComponent.DataIsLoaded = true;

            //等3秒給Client Lerp
            await Game.Scene.GetComponent <TimerComponent>().WaitForSecondAsync(3.0f);

            //設定比賽開始結束時間
            var roadSetting = Game.Scene.GetComponent <ConfigComponent>().Get
                                  (typeof(RoadSetting), roomTeamComponent.RoomEntity.info.RoadSettingId) as RoadSetting;

            if (roadSetting != null)
            {
                var timerComponent = Game.Scene.GetComponent <TimerComponent>();
                roomTeamComponent.RoomRunStartTimeMs = TimeHelper.ClientNowMilliSeconds();
                roomTeamComponent.RoadDistance_km    = RoadHelper.GetDistance_km(roadSetting);
                roomTeamComponent.RoadDistance_m     = RoadHelper.GetDistance_m(roadSetting);
            }
            else
            {
                Log.Error($"找不到該路徑資料, RoadSettingId:{roomTeamComponent.RoomEntity.info.RoadSettingId}");
            }

            //設定所有Player StartRoom
            List <MapUnit> mapUnits   = roomTeamComponent.RoomEntity.GetAll();
            var            proxy      = Game.Scene.GetComponent <CacheProxyComponent>();
            var            playerSync = proxy.GetMemorySyncSolver <Player>();

            for (int i = 0; i < mapUnits.Count; i++)
            {
                Player target = playerSync.Get <Player>(mapUnits[i].Uid);
                if (target != null)
                {
                    target.StartRoom();
                    await playerSync.Update(target);
                }
            }

            //廣播給所有玩家 所有人載入完成
            M2C_TeamGoBattleProgressAllDone m2c_TeamGoBattleProgressAllDone = new M2C_TeamGoBattleProgressAllDone()
            {
                StartUTCTick = DateTime.UtcNow.Ticks
            };

            MapMessageHelper.BroadcastRoom(roomTeamComponent.RoomEntity.Id, m2c_TeamGoBattleProgressAllDone);
        }
Esempio n. 3
0
        protected override async ETTask Run(MapUnit mapUnit, C2M_TeamDeliveryLeader message, Action <M2C_TeamDeliveryLeader> reply)
        {
            await ETTask.CompletedTask;

            M2C_TeamDeliveryLeader response = new M2C_TeamDeliveryLeader();

            try
            {
                if (mapUnit.Room == null)
                {
                    response.Error = ErrorCode.ERR_RoomIdNotFound;
                    reply(response);
                    return;
                }

                if (mapUnit.Room.Type != RoomType.Team)
                {
                    response.Error = ErrorCode.ERR_RoonTypeError;
                    reply(response);
                    return;
                }

                var roomTeamComponent = mapUnit.Room.GetComponent <RoomTeamComponent>();
                if (roomTeamComponent == null)
                {
                    response.Error = ErrorCode.ERR_RoomTeamComponentNull;
                    reply(response);
                    return;
                }

                if (roomTeamComponent.Data?.LeaderUid != mapUnit.Uid)
                {
                    response.Error = ErrorCode.ERR_RoomTeamIsNotLeader;
                    reply(response);
                    return;
                }

                roomTeamComponent.Data.LeaderUid = message.Uid;
                response.Error = 0;
                reply(response);

                M2C_TeamModifyData m2c_TeamModifyData = new M2C_TeamModifyData();
                m2c_TeamModifyData.Data = roomTeamComponent.Data;
                MapMessageHelper.BroadcastRoom(mapUnit.RoomId, m2c_TeamModifyData);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        protected override async ETTask Run(MapUnit mapUnit, C2M_TeamReady message, Action <M2C_TeamReady> reply)
        {
            await ETTask.CompletedTask;

            M2C_TeamReady response = new M2C_TeamReady();

            try
            {
                // 判斷房間是否合法
                Room room = mapUnit.Room;
                if (room == null)
                {
                    response.Error = ErrorCode.ERR_RoomIdNotFound;
                    reply(response);
                    return;
                }

                if (room.Type != RoomType.Team)
                {
                    response.Error = ErrorCode.ERR_RoonTypeError;
                    reply(response);
                    return;
                }

                var roomTeamComponent = room.GetComponent <RoomTeamComponent>();
                if (roomTeamComponent == null)
                {
                    response.Error = ErrorCode.ERR_RoomTeamComponentNull;
                    reply(response);
                    return;
                }

                // 設置IsReady
                roomTeamComponent.SetReady(mapUnit.Uid, message.IsReady);

                // 廣播給所有玩家 更新該玩家進度
                M2C_TeamReadyModify m2c_TeamReadyModify = new M2C_TeamReadyModify();
                m2c_TeamReadyModify.Uid     = mapUnit.Uid;
                m2c_TeamReadyModify.IsReady = message.IsReady;
                MapMessageHelper.BroadcastRoom(mapUnit.Room.Id, m2c_TeamReadyModify);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public static async void KickMember(RoomTeamComponent roomTeamComponent, MapUnit kickMember, TeamLoseType loseType)
        {
            if (kickMember == null)
            {
                return;
            }

            //廣播給指定玩家失去房間
            M2C_TeamLose m2c_TeamLose = new M2C_TeamLose();

            m2c_TeamLose.LoseType = loseType;
            List <MapUnit> broadcastMapUnits = new List <MapUnit>();

            broadcastMapUnits.Add(kickMember);
            MapMessageHelper.BroadcastTarget(m2c_TeamLose, broadcastMapUnits);

            //Player移除mapUnitId
            var proxy      = Game.Scene.GetComponent <CacheProxyComponent>();
            var playerSync = proxy.GetMemorySyncSolver <Player>();
            var player     = playerSync.Get <Player>(kickMember.Uid);

            player?.LeaveRoom();
            await playerSync.Update(player);

            //中斷指定玩家與Map的連接
            var mapUnitGateComponent = kickMember?.GetComponent <MapUnitGateComponent>();

            if (mapUnitGateComponent != null)
            {
                mapUnitGateComponent.IsDisconnect = true;
            }
            Game.Scene.GetComponent <MapUnitComponent>().Remove(kickMember.Id);

            if (m2c_TeamLose.LoseType != TeamLoseType.LoadingTimeOut)
            {
                //廣播給離開玩家外的玩家 成員異動
                M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember();
                m2c_TeamModifyMember.Uid = kickMember.Uid;
                MapMessageHelper.BroadcastRoom(roomTeamComponent.RoomEntity.Id, m2c_TeamModifyMember, kickMember.Uid);
            }
        }
Esempio n. 6
0
        protected void RunAsync(MapUnit mapUnit, C2M_TeamGoBattleProgress message)
        {
            try
            {
                if (mapUnit.Room == null)
                {
                    return;
                }

                if (mapUnit.Room.Type != RoomType.Team)
                {
                    return;
                }

                var roomTeamComponent = mapUnit.Room.GetComponent <RoomTeamComponent>();
                if (roomTeamComponent == null)
                {
                    return;
                }

                //設置目前進度
                message.Progress = Math.Clamp(message.Progress, 0, 1);
                roomTeamComponent.SetProgress(mapUnit.Uid, message.Progress);

                //廣播給所有玩家 更新該玩家進度
                M2C_TeamGoBattleProgressReceiver m2c_TeamGoBattleProgressReceiver = new M2C_TeamGoBattleProgressReceiver();
                m2c_TeamGoBattleProgressReceiver.Uid      = mapUnit.Uid;
                m2c_TeamGoBattleProgressReceiver.Progress = message.Progress;
                MapMessageHelper.BroadcastRoom(mapUnit.Room.Id, m2c_TeamGoBattleProgressReceiver);

                //判斷是否全部載入完畢
                if (roomTeamComponent.IsAllLoadingDone())
                {
                    RoomTeamHelper.LoadingFinish(roomTeamComponent);
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
        protected async ETTask RunAsync(Session session, C2G_TeamInviteAccept message, Action <G2C_TeamInviteAccept> reply)
        {
            G2C_TeamInviteAccept response = new G2C_TeamInviteAccept();

            try
            {
                //取得自身資料
                Player player = session.GetComponent <SessionPlayerComponent>().Player;
                User   user   = await UserDataHelper.FindOneUser((player?.uid).GetValueOrDefault(0));

                if (user == null)
                {
                    response.Error = ErrorCode.ERR_AccountDoesntExist;
                    reply(response);
                    return;
                }

                //判斷邀請是否合法
                var inviteComponent = Game.Scene.GetComponent <InviteComponent>();
                var invite          = inviteComponent.GetByInviteId(message.InviteId);

                if (invite == null)
                {
                    response.Error = ErrorCode.ERR_InviteIdNotFind;
                    reply(response);
                    return;
                }

                if (invite.data.ReceiverUid != player?.uid)
                {
                    response.Error = ErrorCode.ERR_InviteNotSelf;
                    reply(response);
                    return;
                }

                //刪除該邀請
                await inviteComponent.DestroyByInviteId(message.InviteId);

                //判斷房間是否合法
                var room = Game.Scene.GetComponent <RoomComponent>().Get(invite.data.TeamRoomId);
                if (room == null)
                {
                    response.Error = ErrorCode.ERR_RoomIdNotFound;
                    reply(response);
                    return;
                }

                if (room.Type != RoomType.Team)
                {
                    response.Error = ErrorCode.ERR_RoonTypeError;
                    reply(response);
                    return;
                }

                if (room.State != RoomState.Start)
                {
                    response.Error = ErrorCode.ERR_RoomTeamStateCanNotEnter;
                    reply(response);
                    return;
                }

                var roomTeamComponent = room.GetComponent <RoomTeamComponent>();
                if (roomTeamComponent == null)
                {
                    response.Error = ErrorCode.ERR_RoomTeamComponentNull;
                    reply(response);
                    return;
                }

                if (room.info.NowMemberCount >= room.info.MaxMemberCount)
                {
                    response.Error = ErrorCode.ERR_RoomTeamMemberIsFull;
                    reply(response);
                    return;
                }

                // 連接到Map伺服器,並創建Unit實體
                IPEndPoint mapAddress = StartConfigComponent.Instance.Get(player.mapAppId).GetComponent <InnerConfig>().IPEndPoint;
                Session    mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);

                //建立Map實體並進入房間
                G2M_MapUnitCreate g2M_MapUnitCreate = new G2M_MapUnitCreate();
                g2M_MapUnitCreate.Uid           = player.uid;
                g2M_MapUnitCreate.GateSessionId = session.InstanceId;
                g2M_MapUnitCreate.MapUnitInfo   = new MapUnitInfo()
                {
                    Name              = user.name,
                    Location          = user.location,
                    RoomId            = room.Id,
                    DistanceTravelled = 0,
                    CharSetting       = user.playerCharSetting,
                    //PathId 一般組隊入場再決定
                };

                //建立自身MapUnit
                M2G_MapUnitCreate createUnit = (M2G_MapUnitCreate)await mapSession.Call(g2M_MapUnitCreate);

                g2M_MapUnitCreate.MapUnitInfo.MapUnitId = createUnit.MapUnitId;
                player.EnterRoom(createUnit.MapUnitId, room);

                //對全體廣播自己剛建立的MapUnitInfo(不包含自己)
                TeamMemberData       selfMemberData       = roomTeamComponent.GetMember(player.uid);
                M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember();
                m2c_TeamModifyMember.Uid        = player.uid;
                m2c_TeamModifyMember.MemberData = selfMemberData;
                MapMessageHelper.BroadcastRoom(room.Id, m2c_TeamModifyMember, player.uid);

                //回傳資料
                response.Info = room.info;
                response.Data = roomTeamComponent.Data;
                for (int i = 0; i < roomTeamComponent.MemberDatas.Length; i++)
                {
                    if (roomTeamComponent.MemberDatas[i] != null)
                    {
                        response.MemberDatas.Add(roomTeamComponent.MemberDatas[i]);
                    }
                }
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Esempio n. 8
0
        public override void Update(RoomTeamComponent self)
        {
            if (self.RoomEntity != null)
            {
                switch (self.RoomEntity.State)
                {
                case RoomState.Run:
                {
                    //判斷是否正在載入比賽
                    if (!self.DataIsLoaded)
                    {
                        if (TimeHelper.ClientNowMilliSeconds() > self.RoomRunLoadingOutTimeMs)
                        {
                            //踢掉還沒載入的
                            for (int i = 0; i < RoomTeamComponent.MEMBER_MAX; i++)
                            {
                                if (self.MemberDatas[i] == null)
                                {
                                    continue;
                                }

                                if (!self.MemberDatas[i].LoadingDone)
                                {
                                    MapUnit kickMember = self.RoomEntity.GetMapUnitByUid(self.MemberDatas[i].Uid);
                                    RoomTeamHelper.KickMember(self, kickMember, TeamLoseType.LoadingTimeOut);
                                }
                            }
                            //讓隊伍進入比賽
                            RoomTeamHelper.LoadingFinish(self);
                        }
                    }

                    //判斷是否結束比賽
                    if (self.IsEnd())
                    {
                        for (int i = 0; i < self.RoomEntity.MapUnitList.Count; i++)
                        {
                            self.BattleLeaderboardUnitInfos.Add(new BattleLeaderboardUnitInfo()
                                {
                                    Uid  = self.RoomEntity.MapUnitList[i].Uid,
                                    Name = self.RoomEntity.MapUnitList[i].Info.Name,
                                    DistanceTravelledTarget = self.RoomEntity.MapUnitList[i].Info.DistanceTravelled,
                                    Location = self.RoomEntity.MapUnitList[i].Info.Location,
                                });

                            //設定結束騎乘時間
                            self.RoomEntity.MapUnitList[i].TrySetEndTime();
                        }

                        //排序 依照DistanceTravelledTarget(大到小)
                        for (int i = 0; i < self.BattleLeaderboardUnitInfos.Count; i++)
                        {
                            for (int m = i + 1; m < self.BattleLeaderboardUnitInfos.Count; m++)
                            {
                                if (self.BattleLeaderboardUnitInfos[m].DistanceTravelledTarget >
                                    self.BattleLeaderboardUnitInfos[i].DistanceTravelledTarget)
                                {
                                    var temp = self.BattleLeaderboardUnitInfos[i];
                                    self.BattleLeaderboardUnitInfos[i] = self.BattleLeaderboardUnitInfos[m];
                                    self.BattleLeaderboardUnitInfos[m] = temp;
                                }
                            }
                        }

                        //寫入排名
                        for (int i = 0; i < self.BattleLeaderboardUnitInfos.Count; i++)
                        {
                            for (int m = 0; m < self.RoomEntity.MapUnitList.Count; m++)
                            {
                                if (self.RoomEntity.MapUnitList[m].Uid == self.BattleLeaderboardUnitInfos[i].Uid)
                                {
                                    self.RoomEntity.MapUnitList[m].SetRank(i + 1);
                                    break;
                                }
                            }
                        }

                        // 紀錄隊伍資訊
                        var teamId = RideInfoHelper.SaveRideTeamRecord(self.BattleLeaderboardUnitInfos);

                        // 紀錄騎乘資訊
                        for (int i = 0; i < self.RoomEntity.MapUnitList.Count; i++)
                        {
                            RideInfoHelper.SaveRoadAllInfo(self.RoomEntity.MapUnitList[i], teamId);
                        }

                        //傳送排行榜
                        var m2c_BattleLeaderboard = new M2C_BattleLeaderboard();
                        m2c_BattleLeaderboard.BattleLeaderboardUnitInfos.AddRange(self.BattleLeaderboardUnitInfos);
                        MapMessageHelper.BroadcastRoom(self.RoomEntity.info.RoomId, m2c_BattleLeaderboard);

                        //結束
                        self.RoomEntity.SwitchState(RoomState.End);

                        Game.Scene.GetComponent <RoomComponent>().Update(self.RoomEntity).Coroutine();
                    }
                }
                break;
                }
            }
        }
Esempio n. 9
0
        private async ETVoid RunAsync(Session session, C2G_TeamReservationJoin message, Action <G2C_TeamReservationJoin> reply)
        {
            G2C_TeamReservationJoin response = new G2C_TeamReservationJoin();

            try
            {
                //取得自身資料
                Player player = session.GetComponent <SessionPlayerComponent>().Player;
                User   user   = await UserDataHelper.FindOneUser((player?.uid).GetValueOrDefault());

                if (user == null)
                {
                    response.Error = ErrorCode.ERR_AccountDoesntExist;
                    reply(response);
                    return;
                }

                //取得預約資料
                var reservationComponent = Game.Scene.GetComponent <ReservationComponent>();
                var reservation          = reservationComponent.GetByReservationId(message.ReservationId);

                //判斷是否有該預約
                if (reservation == null)
                {
                    response.Error = ErrorCode.ERR_ReservationIdNotFind;
                    reply(response);
                    return;
                }

                //判斷是否為被邀請者
                if (!reservation.allData.MemberUid.Contains(player.uid))
                {
                    response.Error = ErrorCode.ERR_ReservationNotTheOwner;
                    reply(response);
                    return;
                }

                //判斷是否有該房間
                if (reservation.room == null)
                {
                    response.Error = ErrorCode.ERR_ReservationRoomNotFind;
                    reply(response);
                    return;
                }

                //判斷該房間是否可以進入
                if (reservation.room.State != RoomState.Start)
                {
                    response.Error = ErrorCode.ERR_RoomTeamStateCanNotEnter;
                    reply(response);
                    return;
                }

                //判斷是否人滿
                if (reservation.room.info.NowMemberCount >= reservation.room.info.MaxMemberCount)
                {
                    response.Error = ErrorCode.ERR_RoomTeamMemberIsFull;
                    reply(response);
                    return;
                }

                //判斷房間資料是否正確
                var roomTeamComponent = reservation.room.GetComponent <RoomTeamComponent>();
                if (roomTeamComponent == null)
                {
                    response.Error = ErrorCode.ERR_RoomTeamComponentNull;
                    reply(response);
                    return;
                }

                // 連接到Map伺服器,並創建Unit實體
                IPEndPoint mapAddress = StartConfigComponent.Instance.Get(player.mapAppId).GetComponent <InnerConfig>().IPEndPoint;
                Session    mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);

                //建立Map實體並進入房間
                G2M_MapUnitCreate g2M_MapUnitCreate = new G2M_MapUnitCreate();
                g2M_MapUnitCreate.Uid           = player.uid;
                g2M_MapUnitCreate.GateSessionId = session.InstanceId;
                g2M_MapUnitCreate.MapUnitInfo   = new MapUnitInfo()
                {
                    Name              = user.name,
                    Location          = user.location,
                    RoomId            = reservation.room.Id,
                    DistanceTravelled = 0,
                    CharSetting       = user.playerCharSetting,
                    //PathId 一般組隊入場再決定
                };

                //建立自身MapUnit
                M2G_MapUnitCreate createUnit = (M2G_MapUnitCreate)await mapSession.Call(g2M_MapUnitCreate);

                g2M_MapUnitCreate.MapUnitInfo.MapUnitId = createUnit.MapUnitId;
                player.EnterRoom(createUnit.MapUnitId, reservation.room);

                //對全體廣播自己剛建立的MapUnitInfo(不包含自己)
                TeamMemberData       selfMemberData       = roomTeamComponent.GetMember(player.uid);
                M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember();
                m2c_TeamModifyMember.Uid        = player.uid;
                m2c_TeamModifyMember.MemberData = selfMemberData;
                MapMessageHelper.BroadcastRoom(reservation.room.Id, m2c_TeamModifyMember, player.uid);

                //回傳資料
                response.Error = ErrorCode.ERR_Success;
                response.Info  = reservation.room.info;
                response.Data  = roomTeamComponent.Data;
                for (int i = 0; i < roomTeamComponent.MemberDatas.Length; i++)
                {
                    if (roomTeamComponent.MemberDatas[i] != null)
                    {
                        response.MemberDatas.Add(roomTeamComponent.MemberDatas[i]);
                    }
                }
                for (int i = 0; i < roomTeamComponent.ReservationMembers.Count; i++)
                {
                    if (roomTeamComponent.ReservationMembers[i] != null)
                    {
                        response.ReservationMemberDatas.Add(roomTeamComponent.ReservationMembers[i]);
                    }
                }
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }