/// <summary> /// 开启等待复活 /// </summary> public async ETVoid UpDateNetSync(long ResurrectionTime, int ResurrectionAccount) { int Account = ResurrectionAccount; await Game.Scene.GetComponent <TimerComponent>().WaitAsync(ResurrectionTime); UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>(); if (unitComponent.UnitHaveBeCreated(Account)) { Unit ResurrectionUnit = unitComponent.getUnitByAccount(Account); ResurrectionUnit.ReviveHealth(); List <Unit> units = unitComponent.getCountUnits(0); ActorMessageSenderComponent actorSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); for (int i = 0; i < units.Count; i++) { ActorMessageSender actorMessageSender = actorSenderComponent.Get(units[i].GateInstanceId); actorMessageSender.Send(new Actor_PlayerResurrection() { ResurrectionPlayerAccount = ResurrectionUnit.Account, PositionX = 0, PositionY = 0, PositionZ = 0, }); } } else { Log.Info("玩家:" + Account + " 可能已经离线了"); } }
private async void RunAsync(Session session, L2M_RunRoomOnTeam message, Action <M2L_RunRoomOnTeam> reply) { M2L_RunRoomOnTeam response = new M2L_RunRoomOnTeam(); 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; } roomTeamComponent.TeamLeaderRun(); await roomComponent.Update(room); RepeatedField <MapUnitInfo> mapUnitInfos = new RepeatedField <MapUnitInfo>(); List <MapUnit> mapUnits = room.GetAll(); for (int i = 0; i < mapUnits.Count; i++) { mapUnits[i].Info.PathId = i % 4; mapUnitInfos.Add(mapUnits[i].Info); } ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); for (int i = 0; i < mapUnits.Count; i++) { if (mapUnits[i].MapUnitType == MapUnitType.Npc) { continue; } if (mapUnits[i].GetComponent <MapUnitGateComponent>().IsDisconnect) { continue; } M2C_TeamGoBattle m2c_TeamGoBattle = new M2C_TeamGoBattle(); m2c_TeamGoBattle.MapUnitInfos = mapUnitInfos; m2c_TeamGoBattle.MapUnitId = mapUnits[i].Id; ActorMessageSender actorMessageSender = actorLocationSenderComponent.Get(mapUnits[i].GetComponent <MapUnitGateComponent>().GateSessionActorId); actorMessageSender.Send(m2c_TeamGoBattle); } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public override void Destroy(SessionUserComponent self) { try { //释放User对象时将User对象从管理组件中移除 Log.Info($"销毁User和Session{self.User.UserId}"); Game.Scene.GetComponent <UserComponent>().Remove(self.User.UserId); StartConfigComponent config = Game.Scene.GetComponent <StartConfigComponent>(); ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); //向登录服务器发送玩家下线消息 IPEndPoint realmIPEndPoint = config.RealmConfig.GetComponent <InnerConfig>().IPEndPoint; Session realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmIPEndPoint); realmSession.Send(new PlayerOffline_G2R() { UserId = self.User.UserId }); //服务端主动断开客户端连接 Game.Scene.GetComponent <NetOuterComponent>().Remove(self.User.GateSessionId); //Log.Info($"将玩家{message.UserID}连接断开"); self.User.Dispose(); self.User = null; } catch (System.Exception e) { Log.Trace(e.ToString()); } }
public static ETTask <IActorResponse> Call(this ActorMessageSenderComponent self, long actorId, IActorRequest message) { if (actorId == 0) { throw new Exception($"actor id is 0: {MongoHelper.ToJson(message)}"); } string address = StartConfigComponent.Instance.GetProcessInnerAddress(IdGenerater.GetProcessId(actorId)); Session session = NetInnerComponent.Instance.Get(address); message.ActorId = actorId & IdGenerater.HeadMask | IdGenerater.Head; message.RpcId = ++self.RpcId; var tcs = new ETTaskCompletionSource <IActorResponse>(); self.requestCallback.Add(message.RpcId, new ActorMessageSender((response) => { if (ErrorCode.IsRpcNeedThrowException(response.Error)) { tcs.SetException(new Exception($"Rpc error: {MongoHelper.ToJson(response)}")); return; } tcs.SetResult(response); })); session.Send(message); return(tcs.Task); }
protected override async void Run(Session session, C2G_ReturnLobby_Ntt message) { //验证Session if (!GateHelper.SignSession(session)) { return; } User user = session.GetComponent <SessionUserComponent>().User; //StartConfigComponent config = Game.Scene.GetComponent<StartConfigComponent>(); ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); //正在匹配中发送玩家退出匹配请求 //if (user.IsMatching) //{ // IPEndPoint matchIPEndPoint = config.MatchConfig.GetComponent<InnerConfig>().IPEndPoint; // Session matchSession = Game.Scene.GetComponent<NetInnerComponent>().Get(matchIPEndPoint); // await matchSession.Call(new G2M_PlayerExitMatch_Req() { UserID = user.UserID }); // user.IsMatching = false; //} //正在游戏中发送玩家退出房间请求 if (user.ActorID != 0) { ActorMessageSender actorProxy = actorProxyComponent.Get(user.ActorID); await actorProxy.Call(new Actor_PlayerExitRoom_Req() { UserID = user.UserID }); user.ActorID = 0; } }
public static void Broadcast(IActorMessage message) { Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); //actor位置发送组件 ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); //遍历每一个单位 foreach (Unit unit in units) { //获取到它们的网关组件 里面存储的是网关服务器里的Session Id 用于跟客户端进行通信的 UnitGateComponent unitGateComponent = unit.GetComponent <UnitGateComponent>(); if (unitGateComponent.IsDisconnect) { continue; } //通过网关sessionID找到 玩家是在哪个网关服务器(进程) ActorMessageSender actorMessageSender = actorLocationSenderComponent.Get(unitGateComponent.GateSessionActorId); //内部就去进行创建会话实体 连接到网关.. 将消息发送给网关 网关那边去处理一下就好了.. //不过demo里并没有看到网关有处理这条协议 actorMessageSender.Send(message); //建议:其实进程之间的通信,是通过socket来实现的,那维护好对应的socket不就行了 //最好省去各种由Id找到另一个Id的逻辑,不利于应对后续的变化 } }
public static ETTask <IActorResponse> Call(this ActorMessageSenderComponent self, long actorId, IActorRequest message, bool exception = true) { if (actorId == 0) { throw new Exception($"actor id is 0: {MongoHelper.ToJson(message)}"); } var tcs = new ETTaskCompletionSource <IActorResponse>(); int process = IdGenerater.GetProcess(actorId); string address = StartProcessConfigCategory.Instance.Get(process).InnerAddress; Session session = NetInnerComponent.Instance.Get(address); InstanceIdStruct instanceIdStruct = new InstanceIdStruct(actorId); instanceIdStruct.Process = IdGenerater.Process; message.ActorId = instanceIdStruct.ToLong(); message.RpcId = ++self.RpcId; self.requestCallback.Add(message.RpcId, new ActorMessageSender((response) => { if (exception && ErrorCode.IsRpcNeedThrowException(response.Error)) { tcs.SetException(new Exception($"Rpc error: {MongoHelper.ToJson(response)}")); return; } tcs.SetResult(response); })); session.Send(message); return(tcs.Task); }
public static void Check(this ActorMessageSenderComponent self) { long timeNow = TimeHelper.Now(); foreach ((int key, ActorMessageSender value) in self.requestCallback) { if (timeNow < value.CreateTime + ActorMessageSenderComponent.TIMEOUT_TIME) { continue; } self.TimeoutActorMessageSenders.Add(key); } foreach (int rpcId in self.TimeoutActorMessageSenders) { ActorMessageSender actorMessageSender = self.requestCallback[rpcId]; self.requestCallback.Remove(rpcId); Log.Error($"actor request timeout: {rpcId}"); actorMessageSender.Callback.Invoke(new ActorResponse() { Error = ErrorCode.ERR_ActorTimeout }); } self.TimeoutActorMessageSenders.Clear(); }
public static void Broadcast(IActorMessage message) { //广播事件 Ship[] ships = Game.Scene.GetComponent <ShipComponent>().GetAll(); ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); foreach (Ship ship in ships) { ShipGateComponent shipGateComponent = ship.GetComponent <ShipGateComponent>(); if (shipGateComponent.IsDisconnect) { continue; } ActorMessageSender actorMessageSender = actorLocationSenderComponent.Get(shipGateComponent.GateSessionActorId); actorMessageSender.Send(message); } //Unit[] units = Game.Scene.GetComponent<UnitComponent>().GetAll(); //ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent<ActorMessageSenderComponent>(); //foreach (Unit unit in units) //{ // UnitGateComponent unitGateComponent = unit.GetComponent<UnitGateComponent>(); // if (unitGateComponent.IsDisconnect) // { // continue; // } // ActorMessageSender actorMessageSender = actorLocationSenderComponent.Get(unitGateComponent.GateSessionActorId); // actorMessageSender.Send(message); //} }
/// <summary> /// 加入房间 /// </summary> /// <param name="self"></param> /// <param name="room"></param> /// <param name="matcher"></param> public static void JoinRoom(this Moba5V5Component self, Moba5V5Room room, Gamer gamer) { //玩家可能掉线 if (gamer == null) { return; } //玩家绑定待机房间 机器人不用绑定房间 if (gamer.UserID != 0) { self.Waiting.Add(gamer.UserID, room); } //为玩家添加座位 机器人也有座位 room.Add(gamer); //通知Gate服务器玩家匹配成功 参数:Gamer的InstanceId //Gate服务器将Actor类消息转发给Gamer if (gamer.UserID != 0) { ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender gamerActorProxy = actorProxyComponent.Get(gamer.ActorIDofUser); gamerActorProxy.Send(new B1002_Match5V5Sucess_M2G() { ActorIDofGamer = gamer.InstanceId }); } }
/// <summary> /// 加入房间 /// </summary> /// <param name="self"></param> /// <param name="room"></param> /// <param name="matcher"></param> public static async void JoinRoom(this MatchComponent self, Room room, Matcher matcher) { //玩家加入房间,移除匹配队列 self.Playing[matcher.UserID] = room.Id; self.MatchSuccessQueue.Enqueue(matcher); //向房间服务器发送玩家进入请求 ActorMessageSender actorProxy = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(room.Id); Actor_PlayerEnterRoom_Ack actor_PlayerEnterRoom_Ack = await actorProxy.Call(new Actor_PlayerEnterRoom_Req() { PlayerID = matcher.PlayerID, UserID = matcher.UserID, SessionID = matcher.GateSessionID }) as Actor_PlayerEnterRoom_Ack; Gamer gamer = GamerFactory.Create(matcher.PlayerID, matcher.UserID, actor_PlayerEnterRoom_Ack.GamerID); room.Add(gamer); //向玩家发送匹配成功消息 ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender gamerActorProxy = actorProxyComponent.Get(gamer.PlayerID); gamerActorProxy.Send(new Actor_MatchSucess_Ntt() { GamerID = gamer.Id }); }
/// <summary> /// 准备开始游戏 /// </summary> /// <param name="self"></param> public static void StartGame(this GameControllerComponent self) { LandlordsRoom room = self.GetParent <LandlordsRoom>(); Gamer[] gamers = room.gamers; //房间内有3名玩家且全部准备则开始游戏 //if(room.Count == 3 && gamers.Where(g => g.IsReady).Count() == 3){} //初始玩家开始状态 foreach (var _gamer in gamers) { if (_gamer.GetComponent <HandCardsComponent>() == null) { _gamer.AddComponent <HandCardsComponent>(); } } GameControllerComponent gameController = room.GetComponent <GameControllerComponent>(); //洗牌发牌 gameController.DealCards(); List <GamerCardNum> gamersCardNum = new List <GamerCardNum>(); Array.ForEach(gamers, (g) => { HandCardsComponent handCards = g.GetComponent <HandCardsComponent>(); //重置玩家身份 handCards.AccessIdentity = Identity.None; //记录玩家手牌数 gamersCardNum.Add(new GamerCardNum() { UserID = g.UserID, Num = g.GetComponent <HandCardsComponent>().GetAll().Length }); }); //发送玩家手牌和其他玩家手牌数 foreach (var _gamer in gamers) { ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorProxy = actorProxyComponent.Get(_gamer.ActorIDofClient); actorProxy.Send(new Actor_GameStart_Ntt() { HandCards = To.RepeatedField(_gamer.GetComponent <HandCardsComponent>().GetAll()), GamersCardNum = To.RepeatedField(gamersCardNum) }); } //随机先手玩家 gameController.RandomFirstAuthority(); Log.Info($"房间{room.Id}开始游戏"); }
public static void BroadCast(this UserComponent self, IActorMessage message) { User[] users = Game.Scene.GetComponent <UserComponent>().GetAll(); ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); foreach (var _user in users) { UnitGateComponent unitGateComponent = _user.GetComponent <UnitGateComponent>(); actorMessageSenderComponent.GetWithActorId(unitGateComponent.GateSessionActorId).Send(message); } }
protected override async ETTask Run(Session session, C2G_PlayerRoleNetwork message) { //Log.Info("玩家[" + message.Account + "]传来坐标信息:" + message.RotationX + " | " + message.RotationY + " | " + message.RotationZ + " | " + message.RotationW); //获取玩家 Player player = Game.Scene.GetComponent <PlayerComponent>().getPlayerByAccount(message.Account); if (player != null) { //Actor发送组件 ActorMessageSenderComponent actorSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorMessageSender = actorSenderComponent.Get(player.MapInstanceId); List <BulletInfo> bulletInfos = new List <BulletInfo>(); for (int i = 0; i < message.Bullets.Count; i++) { BulletInfo bulletInfo = new BulletInfo(); bulletInfo.Account = message.Bullets[i].Account; bulletInfo.PositionX = message.Bullets[i].PositionX; bulletInfo.PositionY = message.Bullets[i].PositionY; bulletInfo.PositionZ = message.Bullets[i].PositionZ; bulletInfo.RotationX = message.Bullets[i].RotationX; bulletInfo.RotationY = message.Bullets[i].RotationY; bulletInfo.RotationZ = message.Bullets[i].RotationZ; bulletInfo.RotationW = message.Bullets[i].RotationW; bulletInfo.VelocityX = message.Bullets[i].VelocityX; bulletInfo.VelocityY = message.Bullets[i].VelocityY; bulletInfo.VelocityZ = message.Bullets[i].VelocityZ; bulletInfos.Add(bulletInfo); } actorMessageSender.Send(new Actor_PlayerInitPositionUpDate() { PositionX = message.PositionX, PositionY = message.PositionY, PositionZ = message.PositionZ, RotationX = message.RotationX, RotationY = message.RotationY, RotationZ = message.RotationZ, RotationW = message.RotationW, VelocityX = message.VelocityX, VelocityY = message.VelocityY, VelocityZ = message.VelocityZ, Fire = message.Fire, Bullets = bulletInfos, }); } await ETTask.CompletedTask; }
public static void Broadcast(IActorMessage message) { Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); foreach (Unit unit in units) { long gateSessionActorId = unit.GetComponent <UnitGateComponent>().GateSessionActorId; actorMessageSenderComponent.GetWithActorId(gateSessionActorId).Send(message); } }
public static void Broadcast(IActorMessage message) { Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); foreach (Unit unit in units) { ActorMessageSender actorMessageSender = actorLocationSenderComponent.Get(unit.player.GActorId); actorMessageSender.Send(message); } }
/// <summary> /// 匹配队列广播 /// </summary> /// <param name="self"></param> /// <param name="message"></param> public static void Broadcast(this LandlordsComponent self, IActorMessage message) { foreach (Gamer gamer in self.MatchingQueue) { //像Gate服务器中User绑定的Seesion发送Actor消息 ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorProxy = actorProxyComponent.Get(gamer.ActorIDofClient); //转发给客户端的Acror消息要写在Hotfix.proto里面 Log.Debug("转发给了客户端一条消息,客户端Session:" + gamer.ActorIDofClient.ToString()); actorProxy.Send(message); } }
public static void GamerBroadcast(this Room self, Gamer gamer, IActorMessage message) { if (gamer == null || gamer.isOffline) { return; } ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); UnitGateComponent unitGateComponent = gamer.GetComponent <UnitGateComponent>(); actorMessageSenderComponent.GetWithActorId(unitGateComponent.GateSessionActorId).Send(message); }
/// <summary> /// 匹配队列广播 /// </summary> public static void Broadcast(this LandMatchComponent self, IActorMessage message) { foreach (Gamer gamer in self.MatchingQueue) { //向客户端User发送Actor消息 ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorProxy = actorProxyComponent.Get(gamer.CActorID); Log.Debug("转发给了客户端一条消息,客户端Session:" + gamer.CActorID.ToString()); actorProxy.Send(message); } }
public static void Send(this ActorMessageSenderComponent self, long actorId, IActorMessage message) { if (actorId == 0) { throw new Exception($"actor id is 0: {MongoHelper.ToJson(message)}"); } string address = StartConfigComponent.Instance.GetProcessInnerAddress(IdGenerater.GetProcessId(actorId)); Session session = NetInnerComponent.Instance.Get(address); message.ActorId = actorId; session.Send(message); }
public static void RunMessage(this ActorMessageSenderComponent self, IActorResponse response) { ActorMessageSender actorMessageSender; if (!self.requestCallback.TryGetValue(response.RpcId, out actorMessageSender)) { Log.Error($"not found rpc, maybe request timeout, response message: {StringHelper.MessageToStr(response)}"); return; } self.requestCallback.Remove(response.RpcId); actorMessageSender.Callback(response); }
/// <summary> /// 广播消息 通知客户端 /// </summary> /// <param name="message"></param> public static void Broadcast(this Moba5V5Room self, IActorMessage message) { foreach (Gamer gamer in self.gamers) { //如果玩家不存在或者不在线 if (gamer == null || gamer.isOffline || gamer.UserID == 0) { continue; } ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorProxy = actorProxyComponent.Get(gamer.ActorIDofClient); actorProxy.Send(message); } }
public static void Broadcast(IActorMessage message) { Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); ActorMessageSenderComponent actorLocationSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); foreach (Unit unit in units) { UnitGateComponent unitGateComponent = unit.GetComponent <UnitGateComponent>(); if (unitGateComponent.IsDisconnect) { continue; } ActorHelp.SendeActor(unitGateComponent.GateSessionActorId, message); } }
/// <summary> /// 广播消息 /// </summary> public static void Broadcast(this Room self, IActorMessage message) { foreach (Gamer gamer in self.gamers) { //如果玩家不存在或者不在线 if (gamer == null || gamer.isOffline) { continue; } //向客户端User发送Actor消息 ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorProxy = actorProxyComponent.Get(gamer.CActorID); actorProxy.Send(message); } }
/// <summary> /// 广播消息 /// </summary> /// <param name="self"></param> /// <param name="message"></param> private static void Broadcast(this Room self, IActorMessage message) { ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); foreach (Unit unit in self.Units.Values) { UnitGateComponent unitGateComponent = unit.GetComponent <UnitGateComponent>(); if (unitGateComponent.IsDisconnect) { continue; } actorMessageSenderComponent.GetWithActorId(unitGateComponent.GateSessionActorId).Send(message); } }
/// <summary> /// 匹配队列广播 /// </summary> /// <param name="self"></param> /// <param name="message"></param> public static void Broadcast(this Moba5V5Component self, IActorMessage message) { foreach (Gamer gamer in self.MatchingQueue) { if (gamer.UserID == 0) { continue; } //像Gate服务器中User绑定的Seesion发送Actor消息 ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorProxy = actorProxyComponent.Get(gamer.ActorIDofClient); actorProxy.Send(message); } }
protected override async void Run(Session session, G2M_PlayerEnterMatch_Req message, Action <M2G_PlayerEnterMatch_Ack> reply) { M2G_PlayerEnterMatch_Ack response = new M2G_PlayerEnterMatch_Ack(); try { MatchComponent matchComponent = Game.Scene.GetComponent <MatchComponent>(); ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); if (matchComponent.Playing.ContainsKey(message.UserID)) { MatchRoomComponent matchRoomComponent = Game.Scene.GetComponent <MatchRoomComponent>(); long roomId = matchComponent.Playing[message.UserID]; Room room = matchRoomComponent.Get(roomId); Gamer gamer = room.Get(message.UserID); //重置GateActorID gamer.PlayerID = message.PlayerID; //重连房间 ActorMessageSender actorProxy = actorProxyComponent.Get(roomId); await actorProxy.Call(new Actor_PlayerEnterRoom_Req() { PlayerID = message.PlayerID, UserID = message.UserID, SessionID = message.SessionID }); //向玩家发送匹配成功消息 ActorMessageSender gamerActorProxy = actorProxyComponent.Get(gamer.PlayerID); gamerActorProxy.Send(new Actor_MatchSucess_Ntt() { GamerID = gamer.Id }); } else { //创建匹配玩家 Matcher matcher = MatcherFactory.Create(message.PlayerID, message.UserID, message.SessionID); } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
protected override async ETTask Run(Unit unit, Actor_PlayerToUnitSubHealthRequest request, Actor_PlayerToUnitSubHealthResponse response, Action reply) { //是否攻击了已经死亡的玩家 response.AttackDiePlayer = false; if (unit.Die) { response.AttackDiePlayer = true; } else { int newHealth = unit.SubHealth(request.SubHealth); response.UnitHealth = newHealth; response.Die = unit.Die; //这个玩家被打死了需要广播给其它玩家 if (unit.Die) { List <Unit> units = Game.Scene.GetComponent <UnitComponent>().getCountUnits(0); if (units != null) { ActorMessageSenderComponent actorSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); for (int i = 0; i < units.Count; i++) { if (units[i].Account != unit.Account) { ActorMessageSender actorMessageSender = actorSenderComponent.Get(units[i].GateInstanceId); actorMessageSender.Send(new Actor_OtherPlayerDie() { DiePlayerAccount = unit.Account }); } } } //需要开启复活倒计时 UpDateNetSync(3000, unit.Account).Coroutine(); Log.Info("玩家:" + request.KillerAccount + " 打死了玩家 " + unit.Account); RecordKillDataSendPackge(request.KillerAccount, unit.Account); } } reply(); await ETTask.CompletedTask; }
public static void Broadcast(IActorMessage message) { Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); ActorMessageSenderComponent actorMessageSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); foreach (Unit unit in units) { UnitGateComponent unitGateComponent = unit.GetComponent <UnitGateComponent>(); //if (unitGateComponent.IsDisconnect) //{ // continue; //} actorMessageSenderComponent.GetWithActorId(unitGateComponent.GateSessionActorId).Send(message); } }
/// <summary> /// 加入房间 /// </summary> /// <param name="self"></param> /// <param name="room"></param> /// <param name="matcher"></param> public static void JoinRoom(this LandlordsComponent self, LandlordsRoom room, Gamer gamer) { //玩家可能掉线 if (gamer == null) { return; } //玩家加入房间 成为已经进入房间的玩家 //绑定玩家与房间 以后可以通过玩家UserID找到所在房间 self.Waiting[gamer.UserID] = room; //为玩家添加座位 room.Add(gamer); //房间广播 Log.Info($"玩家{gamer.UserID}进入房间"); Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt(); foreach (Gamer _gamer in room.gamers) { if (_gamer == null) { //添加空位 broadcastMessage.Gamers.Add(new GamerInfo()); continue; } //添加玩家信息 //GamerInfo info = new GamerInfo() { UserID = _gamer.UserID, IsReady = room.IsGamerReady(gamer) }; GamerInfo info = new GamerInfo() { UserID = _gamer.UserID }; broadcastMessage.Gamers.Add(info); } //广播房间内玩家消息 每次有人进入房间都会收到一次广播 room.Broadcast(broadcastMessage); //通知Gate服务器玩家匹配成功 参数:Gamer的InstanceId //Gate服务器将Actor类消息转发给Gamer ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender gamerActorProxy = actorProxyComponent.Get(gamer.ActorIDofUser); gamerActorProxy.Send(new Actor_LandlordsMatchSucess() { ActorIDofGamer = gamer.InstanceId }); }