/// <summary> /// 游戏结束 /// </summary> /// <param name="self"></param> public static async void GameOver(this GameControllerComponent self, Dictionary <long, long> gamersSorce) { Room room = self.GetEntity <Room>(); //清理所有卡牌 self.BackToDeck(); room.GetComponent <DeskCardsCacheComponent>().Clear(); //同步匹配服务器结束游戏 room.State = RoomState.Ready; MapHelper.SendMessage(new SyncRoomState() { RoomID = room.Id, State = room.State }); Gamer[] gamers = room.GetAll(); for (int i = 0; i < gamers.Length; i++) { long gamerMoney = await self.StatisticalIntegral(gamers[i], gamersSorce[gamers[i].Id]); bool isKickOut = gamers[i].isOffline; //玩家余额低于最低门槛 if (gamerMoney < self.MinThreshold) { ActorProxy actorProxy = gamers[i].GetComponent <UnitGateComponent>().GetActorProxy(); actorProxy.Send(new GamerMoneyLess() { PlayerID = gamers[i].Id }); isKickOut = true; } //踢出玩家 if (isKickOut) { ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(self.Entity.Id); actorProxy.Send(new PlayerQuit() { PlayerID = gamers[i].Id }); } } }
protected override Task Run(Room entity, PlayerQuit message) { Gamer gamer = entity.Get(message.PlayerID); if (gamer != null) { if (entity.State == RoomState.Game) { //玩家操作设置为自动 Log.Info($"游戏中,玩家{message.PlayerID}退出房间,切换为自动模式"); gamer.isOffline = true; if (gamer.GetComponent <AutoPlayCardsComponent>() == null) { gamer.AddComponent <AutoPlayCardsComponent, Room>(entity); } } else { //房间移除玩家 entity.Remove(gamer.Id); //同步匹配服务器移除玩家 MapHelper.SendMessage(new GamerQuitRoom() { PlayerID = message.PlayerID, RoomID = entity.Id }); //消息广播给其他人 entity.Broadcast(new GamerOut() { PlayerID = message.PlayerID }); Log.Info($"准备中,玩家{message.PlayerID}退出房间"); } } return(Task.CompletedTask); }
protected override Task Run(Room entity, PlayerReady message) { Gamer gamer = entity.Get(message.PlayerID); if (gamer != null) { gamer.IsReady = true; Gamer[] gamers = entity.GetAll(); //转发玩家准备消息 entity.Broadcast(message); Log.Info($"玩家{gamer.Id}准备"); //房间内有3名玩家且全部准备则开始游戏 if (entity.Count == 3 && gamers.Where(g => g.IsReady).Count() == 3) { //同步匹配服务器开始游戏 entity.State = RoomState.Game; MapHelper.SendMessage(new SyncRoomState() { RoomID = entity.Id, State = entity.State }); //初始玩家开始状态 foreach (var _gamer in gamers) { if (_gamer.GetComponent <HandCardsComponent>() == null) { _gamer.AddComponent <HandCardsComponent>(); } _gamer.IsReady = false; } GameControllerComponent gameController = entity.GetComponent <GameControllerComponent>(); //洗牌发牌 gameController.DealCards(); Dictionary <long, int> gamerCardsNum = new Dictionary <long, int>(); Array.ForEach(gamers, (g) => { HandCardsComponent handCards = g.GetComponent <HandCardsComponent>(); //重置玩家身份 handCards.AccessIdentity = Identity.None; //记录玩家手牌数 gamerCardsNum.Add(g.Id, handCards.CardsCount); }); //发送玩家手牌和其他玩家手牌数 foreach (var _gamer in gamers) { ActorProxy actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorProxy(); actorProxy.Send(new GameStart() { GamerCards = _gamer.GetComponent <HandCardsComponent>().GetAll(), GamerCardsNum = gamerCardsNum }); } //随机先手玩家 gameController.RandomFirstAuthority(); Log.Info($"房间{entity.Id}开始游戏"); } } return(Task.CompletedTask); }