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); } }
protected async ETTask RunAsync(MapUnit mapUnit, C2M_GiveAisatsu message) { await ETTask.CompletedTask; try { M2C_GiveAisatsu m2C_GiveAisatsu = new M2C_GiveAisatsu(); if (mapUnit.Id == message.MapUnitId) { Log.Error("µ¹¦Û¤v«öÆg¬O¤£¦æªº!"); return; } MapUnit target = mapUnit.Room.GetMapUnitById(message.MapUnitId); User user = await UserDataHelper.FindOneUser(mapUnit.Uid); m2C_GiveAisatsu.Name = user?.name; m2C_GiveAisatsu.Content = message.Content; MapMessageHelper.BroadcastTarget(m2C_GiveAisatsu, new List <MapUnit> { target }); } catch (Exception e) { Log.Error(e); } }
protected async ETTask RunAsync(MapUnit mapUnit, C2M_GiveEmoticon message) { await ETTask.CompletedTask; try { M2C_GiveEmoticon m2C_GiveEmoticon = new M2C_GiveEmoticon(); if (mapUnit.Id == message.MapUnitId) { Log.Error("給自己按讚是不行的!"); return; } MapUnit target = mapUnit.Room.GetMapUnitById(message.MapUnitId); User user = await UserDataHelper.FindOneUser(mapUnit.Uid); m2C_GiveEmoticon.Name = user?.name; m2C_GiveEmoticon.EmoticonIndex = message.EmoticonIndex; MapMessageHelper.BroadcastTarget(m2C_GiveEmoticon, new List <MapUnit> { target }); } catch (Exception e) { Log.Error(e); } }
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); }
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); } }
public static async ETTask RemoveMapUnitByUid(this Room self, long uid) { RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); if (!self.UidDict.TryGetValue(uid, out MapUnit mapUnit)) { return; } self.MapUnitList.Remove(mapUnit); self.IdDict.Remove(mapUnit.Id); self.UidDict.Remove(uid); self.info.NowMemberCount = self.MapUnitList.Count; // block var blockComponent = self.GetComponent <RoomBlockComponent>(); blockComponent.Leave(mapUnit); switch (self.Type) { case RoomType.Roaming: // TODO RemoveMapUnit Roaming break; case RoomType.Team: { var teamComponent = self.GetComponent <RoomTeamComponent>(); if (teamComponent != null) { teamComponent.RemoveMember(uid); // (非預約房間)沒有人就自動解散 if (!teamComponent.Data.IsReservation && self.MemberCount <= 0) { await roomComponent.DestroyRoom(self.Id); } } } break; } // 同步房間資訊 await roomComponent.Update(self); // Destroy GlobalInfo self._m2C_MapUnitGlobalDestroy.MapUnitId = mapUnit.Id; MapMessageHelper.BroadcastTarget(self._m2C_MapUnitGlobalDestroy, self.MapUnitList); }
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); } }
private async void RunAsync(Session session, L2M_TeamLose message, Action <M2L_TeamLose> reply) { M2L_TeamLose response = new M2L_TeamLose(); try { var roomComponent = Game.Scene.GetComponent <RoomComponent>(); var room = roomComponent.Get(message.RoomId); if (room == null) { response.Error = ErrorCode.ERR_RoomIdNotFound; reply(response); return; } // 告知失去房間訊息 M2C_TeamLose m2c_TeamLose = new M2C_TeamLose(); m2c_TeamLose.LoseType = TeamLoseType.Disband; List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); MapMessageHelper.BroadcastTarget(m2c_TeamLose, broadcastMapUnits); // 讓隊員清空Map相關訊息 var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var mapUnits = room.GetAll(); for (int i = 0; i < mapUnits?.Count; i++) { // Player移除mapUnitId var targetPlayer = playerSync.Get <Player>(mapUnits[i].Uid); targetPlayer?.LeaveRoom(); await playerSync.Update(targetPlayer); // 中斷指定玩家與Map的連接 mapUnits[i].GetComponent <MapUnitGateComponent>().IsDisconnect = true; // TODO:G2M_TeamDisband抄C2M_TeamDisbandHandler Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnits[i].Id); } // 刪除房間實體 await roomComponent.DestroyRoom(room.Id); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
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); } }
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); } }
public static async ETTask AddMapUnit(this Room self, MapUnit mapUnit) { if (self.UidDict.ContainsKey(mapUnit.Uid)) { return; } self.UidDict.Add(mapUnit.Uid, mapUnit); self.IdDict.Add(mapUnit.Id, mapUnit); self.MapUnitList.Add(mapUnit); self.info.NowMemberCount = self.MapUnitList.Count; // block var blockComponent = self.GetComponent <RoomBlockComponent>(); blockComponent.Enter(mapUnit, mapUnit.Info.DistanceTravelled); switch (self.Type) { case RoomType.Roaming: // TODO AddMapUnit Roaming break; case RoomType.Team: { var teamComponent = self.GetComponent <RoomTeamComponent>(); teamComponent.AddMember(mapUnit); } break; } // 同步房間資訊 RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); await roomComponent.Update(self); // Create GlobalInfo self._m2C_MapUnitGlobalCreate.GlobalInfo = mapUnit.GlobalInfo; MapMessageHelper.BroadcastTarget(self._m2C_MapUnitGlobalCreate, self.MapUnitList); }
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; } } }
private async ETTask RunAsync(Session session, C2G_TeamReservationCancel message, Action <G2C_TeamReservationCancel> reply) { G2C_TeamReservationCancel response = new G2C_TeamReservationCancel(); 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.allData.SenderUid != player.uid) { response.Error = ErrorCode.ERR_ReservationIsNotLeader; reply(response); return; } if (reservation.room != null) { if (reservation.room.State != RoomState.Ready && reservation.room.State != RoomState.Start) { response.Error = ErrorCode.ERR_ReservationRoomStateCanNotToRemove; reply(response); return; } else { //告知失去房間訊息 M2C_TeamLose m2c_TeamLose = new M2C_TeamLose(); m2c_TeamLose.LoseType = TeamLoseType.Disband; List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(reservation.room.GetAll()); MapMessageHelper.BroadcastTarget(m2c_TeamLose, broadcastMapUnits); //讓隊員清空Map相關訊息 var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var mapUnits = reservation.room.GetAll(); for (int i = 0; i < mapUnits?.Count; i++) { //Player移除mapUnitId var targetPlayer = playerSync.Get <Player>(mapUnits[i].Uid); targetPlayer?.LeaveRoom(); //中斷指定玩家與Map的連接 mapUnits[i].GetComponent <MapUnitGateComponent>().IsDisconnect = true; //TODO:G2M_TeamDisband抄C2M_TeamDisbandHandler Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnits[i].Id); } //刪除房間實體 var roomComponent = Game.Scene.GetComponent <RoomComponent>(); await roomComponent.DestroyRoom(reservation.room.Id); } } //刪除預約實體(DB會一起刪除) await reservationComponent.DestroyReservation(message.ReservationId); //回傳資料 response.Error = ErrorCode.ERR_Success; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async ETTask Run(MapUnit mapUnit, C2M_TeamLeave message, Action <M2C_TeamLeave> reply) { await ETTask.CompletedTask; M2C_TeamLeave response = new M2C_TeamLeave(); 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; } //刪除MapUnit訊息 M2C_MapUnitDestroy m2C_MapUnitDestroy = new M2C_MapUnitDestroy(); m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; //廣播刪除MapUnit訊息(不包含自己) List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); for (int i = 0; i < broadcastMapUnits.Count; i++) { //過濾自己 if (broadcastMapUnits[i].Uid == mapUnit.Uid) { broadcastMapUnits.RemoveAt(i); break; } } MapMessageHelper.BroadcastTarget(m2C_MapUnitDestroy, broadcastMapUnits); //對全體廣播離開組隊訊息(不包含自己) M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = mapUnit.Uid; MapMessageHelper.BroadcastTarget(m2c_TeamModifyMember, broadcastMapUnits); //廣播給自己失去房間 M2C_TeamLose m2c_TeamLose = new M2C_TeamLose(); m2c_TeamLose.LoseType = TeamLoseType.Other; MapMessageHelper.BroadcastTarget(m2c_TeamLose, mapUnit); bool isLeader = mapUnit.Uid == roomTeamComponent.Data.LeaderUid; //對全體廣播更換隊長(不包含自己) if (isLeader) { M2C_TeamModifyData m2c_TeamModifyData = new M2C_TeamModifyData(); m2c_TeamModifyData.Data = roomTeamComponent.Data; MapMessageHelper.BroadcastTarget(m2c_TeamModifyData, broadcastMapUnits); } //Player移除mapUnitId var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var player = playerSync.Get <Player>(mapUnit.Uid); player?.LeaveRoom(); await playerSync.Update(player); //先Response才釋放mapUnit reply(response); //中斷指定玩家與Map的連接 mapUnit.GetComponent <MapUnitGateComponent>().IsDisconnect = true; Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnit.Id); } catch (Exception e) { ReplyError(response, e, reply); } }
private void RunAsync(MapUnit mapUnit, L2M_SessionDisconnect message) { try { Room room = mapUnit.Room; if (room != null) { RoomTeamComponent roomTeamComponent = room.GetComponent <RoomTeamComponent>(); // 刪除MapUnit M2C_MapUnitDestroy m2C_MapUnitDestroy = new M2C_MapUnitDestroy(); m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; // 製作廣播列表 List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); for (int i = 0; i < broadcastMapUnits.Count; i++) { // 過濾自己 if (broadcastMapUnits[i].Uid == mapUnit.Uid) { broadcastMapUnits.RemoveAt(i); break; } } MapMessageHelper.BroadcastTarget(m2C_MapUnitDestroy, broadcastMapUnits); switch (room.Type) { case RoomType.Roaming: { } break; case RoomType.Team: { // 廣播成員異動訊息 M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = mapUnit.Uid; MapMessageHelper.BroadcastTarget(m2c_TeamModifyMember, broadcastMapUnits); // 判斷自身是否為隊長 bool isLeader = mapUnit.Uid == roomTeamComponent.Data.LeaderUid; // 廣播替換隊長訊息 if (isLeader) { M2C_TeamModifyData m2c_TeamModifyData = new M2C_TeamModifyData(); m2c_TeamModifyData.Data = roomTeamComponent.Data; MapMessageHelper.BroadcastTarget(m2c_TeamModifyData, broadcastMapUnits); } } break; } } // 中斷指定玩家與Map的連接 mapUnit.GetComponent <MapUnitGateComponent>().IsDisconnect = true; Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnit.Id); } 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); } }
protected override async void Run(Session session, L2M_RoamingLeave message, Action <M2L_RoamingLeave> reply) { M2L_RoamingLeave response = new M2L_RoamingLeave(); try { var mapUnitComponent = Game.Scene.GetComponent <MapUnitComponent>(); MapUnit mapUnit = mapUnitComponent.GetByUid(message.Uid); // 判斷MapUnit是否存在在該Map上 if (mapUnit == null) { response.Error = ErrorCode.ERR_MapUnitMissing; reply(response); return; } //判斷房間是否合法 Room room = mapUnit.Room; if (room == null) { response.Error = ErrorCode.ERR_RoomIdNotFound; reply(response); return; } if (room.Type != RoomType.Roaming) { response.Error = ErrorCode.ERR_RoonTypeError; reply(response); return; } //刪除MapUnit訊息 M2C_MapUnitDestroy m2C_MapUnitDestroy = new M2C_MapUnitDestroy(); m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; //廣播刪除MapUnit訊息(不包含自己) List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); for (int i = 0; i < broadcastMapUnits.Count; i++) { //過濾自己 if (broadcastMapUnits[i].Uid == mapUnit.Uid) { broadcastMapUnits.RemoveAt(i); break; } } MapMessageHelper.BroadcastTarget(m2C_MapUnitDestroy, broadcastMapUnits); //Player移除mapUnitId var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var player = playerSync.Get <Player>(mapUnit.Uid); player?.LeaveRoom(); await playerSync.Update(player); //先Response才釋放mapUnit reply(response); //中斷指定玩家與Map的連接 mapUnit.GetComponent <MapUnitGateComponent>().IsDisconnect = true; Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnit.Id); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override void Run(MapUnit mapUnit, G2M_SessionDisconnect message) { //先Player離開地圖再移除mapUnit var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); var player = playerSync.Get <Player>(mapUnit.Uid); player?.LeaveRoom(); Room room = mapUnit.Room; if (room != null) { RoomTeamComponent roomTeamComponent = room.GetComponent <RoomTeamComponent>(); //刪除MapUnit M2C_MapUnitDestroy m2C_MapUnitDestroy = new M2C_MapUnitDestroy(); m2C_MapUnitDestroy.MapUnitId = mapUnit.Id; //製作廣播列表 List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); for (int i = 0; i < broadcastMapUnits.Count; i++) { //過濾自己 if (broadcastMapUnits[i].Uid == mapUnit.Uid) { broadcastMapUnits.RemoveAt(i); break; } } MapMessageHelper.BroadcastTarget(m2C_MapUnitDestroy, broadcastMapUnits); switch (room.Type) { case RoomType.Roaming: { } break; case RoomType.Team: { //廣播成員異動訊息 M2C_TeamModifyMember m2c_TeamModifyMember = new M2C_TeamModifyMember(); m2c_TeamModifyMember.Uid = mapUnit.Uid; MapMessageHelper.BroadcastTarget(m2c_TeamModifyMember, broadcastMapUnits); //判斷自身是否為隊長 bool isLeader = mapUnit.Uid == roomTeamComponent.Data.LeaderUid; //廣播替換隊長訊息 if (isLeader) { M2C_TeamModifyData m2c_TeamModifyData = new M2C_TeamModifyData(); m2c_TeamModifyData.Data = roomTeamComponent.Data; MapMessageHelper.BroadcastTarget(m2c_TeamModifyData, broadcastMapUnits); } } break; } } //中斷指定玩家與Map的連接 mapUnit.GetComponent <MapUnitGateComponent>().IsDisconnect = true; Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnit.Id); }
protected override async ETTask Run(MapUnit mapUnit, C2M_TeamDisband message, Action <M2C_TeamDisband> reply) { await ETTask.CompletedTask; M2C_TeamDisband response = new M2C_TeamDisband(); 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; } if (roomTeamComponent.Data?.LeaderUid != mapUnit.Uid) { response.Error = ErrorCode.ERR_RoomTeamIsNotLeader; reply(response); return; } response.Error = 0; reply(response); //告知失去房間訊息 M2C_TeamLose m2c_TeamLose = new M2C_TeamLose(); m2c_TeamLose.LoseType = TeamLoseType.Disband; List <MapUnit> broadcastMapUnits = new List <MapUnit>(); broadcastMapUnits.AddRange(room.GetAll()); MapMessageHelper.BroadcastTarget(m2c_TeamLose, broadcastMapUnits); //讓隊員清空Map相關訊息 var mapUnits = room.GetAll(); var proxy = Game.Scene.GetComponent <CacheProxyComponent>(); var playerSync = proxy.GetMemorySyncSolver <Player>(); for (int i = 0; i < mapUnits?.Count; i++) { //Player移除mapUnitId var player = playerSync.Get <Player>(mapUnits[i].Uid); player?.LeaveRoom(); await playerSync.Update(player); //中斷指定玩家與Map的連接 mapUnits[i].GetComponent <MapUnitGateComponent>().IsDisconnect = true; Game.Scene.GetComponent <MapUnitComponent>().Remove(mapUnits[i].Id); } //刪除房間實體 var roomComponent = Game.Scene.GetComponent <RoomComponent>(); await roomComponent.DestroyRoom(room.Id); } catch (Exception e) { ReplyError(response, e, reply); } }
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); } }