protected override void Run(Gamer gamer, Actor_GamerDontPlay_Ntt message) { Room room = Game.Scene.GetComponent <RoomComponent>().Get(gamer.RoomID); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); if (orderController.CurrentAuthority == gamer.UserID) { //转发玩家不出牌消息 Actor_GamerDontPlay_Ntt transpond = new Actor_GamerDontPlay_Ntt(); transpond.UserID = gamer.UserID; room.Broadcast(transpond); //轮到下位玩家出牌 orderController.Turn(); //判断是否先手 bool isFirst = orderController.CurrentAuthority == orderController.Biggest; if (isFirst) { room.GetComponent <DeskCardsCacheComponent>().Clear(); } room.Broadcast(new Actor_AuthorityPlayCard_Ntt() { UserID = orderController.CurrentAuthority, IsFirst = isFirst }); } }
protected override async Task Run(Gamer gamer, C2M_GamerDontPlay message) { Room room = Game.Scene.GetComponent <RoomComponent>().Get(gamer.RoomID); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); if (orderController.CurrentAuthority == gamer.UserID) { //转发玩家不出牌消息 C2M_GamerDontPlay transpond = new C2M_GamerDontPlay(); transpond.UserID = gamer.UserID; room.Broadcast(transpond); //轮到下位玩家出牌 orderController.Turn(false); //判断是否先手 bool isFirst = orderController.CurrentAuthority == orderController.Biggest; if (isFirst) { room.GetComponent <DeskCardsCacheComponent>().Clear(); } room.Broadcast(new M2C_AuthorityPlayCard() { UserID = orderController.CurrentAuthority, IsFirst = isFirst }); } await Task.CompletedTask; }
protected override Task Run(Room entity, Discard message) { OrderControllerComponent orderController = entity.GetComponent <OrderControllerComponent>(); Gamer gamer = entity.Get(message.PlayerId); if (gamer != null) { if (orderController.CurrentAuthority == gamer.Id) { //转发玩家不出消息 entity.Broadcast(message); //轮到下位玩家出牌 orderController.Turn(); //判断是否先手 bool isFirst = orderController.CurrentAuthority == orderController.Biggest; if (isFirst) { entity.GetComponent <DeskCardsCacheComponent>().Clear(); } entity.Broadcast(new AuthorityPlayCard() { PlayerId = orderController.CurrentAuthority, IsFirst = isFirst }); } } return(Task.CompletedTask); }
/// <summary> /// 游戏继续 /// </summary> /// <param name="self"></param> /// <param name="lastGamer"></param> public static void Continue(this GameControllerComponent self, Gamer lastGamer) { Room room = self.GetParent <Room>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); //是否结束,当前出牌者手牌数为0时游戏结束 bool isEnd = lastGamer.GetComponent <HandCardsComponent>().CardsCount == 0; if (isEnd) { //当前最大出牌者为赢家 Identity winnerIdentity = room.Get(orderController.Biggest).GetComponent <HandCardsComponent>().AccessIdentity; List <GamerScore> gamersScore = new List <GamerScore>(); //游戏结束所有玩家摊牌 foreach (var gamer in room.GetAll()) { //取消托管 gamer.RemoveComponent <TrusteeshipComponent>(); //计算玩家积分 gamersScore.Add(new GamerScore() { UserID = gamer.UserID, Score = self.GetGamerScore(gamer, winnerIdentity) }); if (gamer.UserID != lastGamer.UserID) { //剩余玩家摊牌 Card[] _gamerCards = gamer.GetComponent <HandCardsComponent>().GetAll(); Actor_GamerPlayCard_Ntt gamerPlayCardMessage = new Actor_GamerPlayCard_Ntt() { UserID = gamer.UserID }; gamerPlayCardMessage.Cards.AddRange(gamer.GetComponent <HandCardsComponent>().GetAll()); room.Broadcast(gamerPlayCardMessage); } } self.GameOver(gamersScore, winnerIdentity); } else { //轮到下位玩家出牌 orderController.Biggest = lastGamer.UserID; orderController.Turn(); room.Broadcast(new Actor_AuthorityPlayCard_Ntt() { UserID = orderController.CurrentAuthority, IsFirst = false }); } }
/// <summary> /// 游戏继续 /// </summary> /// <param name="self"></param> /// <param name="lastGamer"></param> public static void Continue(this GameControllerComponent self, Gamer lastGamer) { Room room = self.GetParent <Room>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); //是否结束,当前出牌者手牌数为0时游戏结束 bool isEnd = lastGamer.GetComponent <HandCardsComponent>().CardsCount == 0; if (isEnd) { //当前最大出牌者为赢家 Identity winnerIdentity = room.Get(orderController.Biggest).GetComponent <HandCardsComponent>().AccessIdentity; Dictionary <long, long> gamersScore = new Dictionary <long, long>(); //游戏结束所有玩家摊牌 foreach (var gamer in room.GetAll()) { //取消托管 gamer.RemoveComponent <TrusteeshipComponent>(); //计算玩家积分 gamersScore.Add(gamer.UserID, self.GetGamerScore(gamer, winnerIdentity)); if (gamer.UserID != lastGamer.UserID) { //剩余玩家摊牌 Card[] _gamerCards = gamer.GetComponent <HandCardsComponent>().GetAll(); room.Broadcast(new M2C_GamerPlayCard_Ntt() { UserID = gamer.UserID, Cards = _gamerCards }); } } self.GameOver(gamersScore, winnerIdentity); } else { //轮到下位玩家出牌 orderController.Biggest = lastGamer.UserID; orderController.Turn(true); } }
/// <summary> /// 发牌,包含抓牌和补花 /// </summary> /// <param name="room"></param> public static async void GamerGrabCard(this Room room) { foreach (var gamer in room.GetAll()) { if (gamer == null) { Log.Error("发牌的时候gamer为null:" + JsonHelper.ToJson(room.UserIds) + "\n------:" + JsonHelper.ToJson(room.GetAll())); continue; } gamer.isGangFaWanPai = false; } OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); orderController.Turn(); var currentGamer = room.Get(orderController.CurrentAuthority); currentGamer.isGangEndBuPai = false; currentGamer.isGetYingHuaBuPai = false; await room.GrabMahjongNoHua(currentGamer); }
protected override void Run(Gamer gamer, Actor_GamerGrabLandlordSelect_Ntt message) { Room room = Game.Scene.GetComponent <RoomComponent>().Get(gamer.RoomID); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); GameControllerComponent gameController = room.GetComponent <GameControllerComponent>(); if (orderController.CurrentAuthority == gamer.UserID) { //保存抢地主状态 orderController.GamerLandlordState[gamer.UserID] = message.IsGrab; if (message.IsGrab) { orderController.Biggest = gamer.UserID; gameController.Multiples *= 2; room.Broadcast(new Actor_SetMultiples_Ntt() { Multiples = gameController.Multiples }); } //转发消息 Actor_GamerGrabLandlordSelect_Ntt transpond = new Actor_GamerGrabLandlordSelect_Ntt(); transpond.IsGrab = message.IsGrab; transpond.UserID = gamer.UserID; room.Broadcast(transpond); if (orderController.SelectLordIndex >= room.Count) { /* * 地主:√ 农民1:× 农民2:× * 地主:× 农民1:√ 农民2:√ * 地主:√ 农民1:√ 农民2:√ 地主:√ * * */ if (orderController.Biggest == 0) { //没人抢地主则重新发牌 gameController.BackToDeck(); gameController.DealCards(); //发送玩家手牌 Gamer[] gamers = room.GetAll(); List <GamerCardNum> gamersCardNum = new List <GamerCardNum>(); Array.ForEach(gamers, _gamer => gamersCardNum.Add(new GamerCardNum() { UserID = _gamer.UserID, Num = _gamer.GetComponent <HandCardsComponent>().GetAll().Length })); Array.ForEach(gamers, _gamer => { ActorMessageSender actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorMessageSender(); Actor_GameStart_Ntt actorMessage = new Actor_GameStart_Ntt(); actorMessage.HandCards.AddRange(_gamer.GetComponent <HandCardsComponent>().GetAll()); actorMessage.GamersCardNum.AddRange(gamersCardNum); }); //随机先手玩家 gameController.RandomFirstAuthority(); return; } else if ((orderController.SelectLordIndex == room.Count && ((orderController.Biggest != orderController.FirstAuthority.Key && !orderController.FirstAuthority.Value) || orderController.Biggest == orderController.FirstAuthority.Key)) || orderController.SelectLordIndex > room.Count) { gameController.CardsOnTable(orderController.Biggest); return; } } //当所有玩家都抢地主时先手玩家还有一次抢地主的机会 if (gamer.UserID == orderController.FirstAuthority.Key && message.IsGrab) { orderController.FirstAuthority = new KeyValuePair <long, bool>(gamer.UserID, true); } orderController.Turn(); orderController.SelectLordIndex++; room.Broadcast(new Actor_AuthorityGrabLandlord_Ntt() { UserID = orderController.CurrentAuthority }); } }
protected override Task Run(Room unit, PlayCards_RT message, Action <PlayCards_RE> reply) { PlayCards_RE response = new PlayCards_RE(); try { Gamer gamer = unit.Get(message.PlayerID); if (gamer == null) { response.Error = ErrorCode.ERR_PlayCardError; reply(response); return(Task.CompletedTask); } GameControllerComponent gameController = unit.GetComponent <GameControllerComponent>(); DeskCardsCacheComponent deskCardsCache = unit.GetComponent <DeskCardsCacheComponent>(); OrderControllerComponent orderController = unit.GetComponent <OrderControllerComponent>(); //检测是否符合出牌规则 if (CardsHelper.PopEnable(message.Cards, out CardsType type)) { if (orderController.Biggest == orderController.CurrentAuthority || type == CardsType.JokerBoom || type == CardsType.Boom && CardsHelper.GetWeight(message.Cards, type) > deskCardsCache.GetTotalWeight() || (deskCardsCache.Rule == CardsType.Straight || deskCardsCache.Rule == CardsType.DoubleStraight || deskCardsCache.Rule == CardsType.TripleStraight) && type == deskCardsCache.Rule && message.Cards.Length == deskCardsCache.GetAll().Length&& CardsHelper.GetWeight(message.Cards, type) > deskCardsCache.GetTotalWeight() || type == deskCardsCache.Rule && CardsHelper.GetWeight(message.Cards, type) > deskCardsCache.GetTotalWeight()) { if (type == CardsType.JokerBoom) { gameController.Multiples *= 4; unit.Broadcast(new GameMultiples() { Multiples = gameController.Multiples }); } else if (type == CardsType.Boom) { gameController.Multiples *= 2; unit.Broadcast(new GameMultiples() { Multiples = gameController.Multiples }); } } else { response.Error = ErrorCode.ERR_PlayCardError; reply(response); return(Task.CompletedTask); } } else { response.Error = ErrorCode.ERR_PlayCardError; reply(response); return(Task.CompletedTask); } //如果符合将牌从手牌移到出牌缓存区 deskCardsCache.Clear(); deskCardsCache.Rule = type; HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); foreach (var card in message.Cards) { handCards.PopCard(card); deskCardsCache.AddCard(card); } //转发玩家出牌消息 unit.Broadcast(new GamerPlayCards() { PlayerID = gamer.Id, Cards = message.Cards }); if (handCards.CardsCount == 0) { Identity winnerIdentity = unit.Get(orderController.Biggest).GetComponent <HandCardsComponent>().AccessIdentity; Dictionary <long, long> gamersScore = new Dictionary <long, long>(); foreach (var _gamer in unit.GetAll()) { _gamer.RemoveComponent <AutoPlayCardsComponent>(); gamersScore.Add(_gamer.Id, gameController.GetScore(_gamer, winnerIdentity)); //玩家剩余出牌 if (_gamer.Id != message.PlayerID) { Card[] _gamerCards = _gamer.GetComponent <HandCardsComponent>().GetAll(); unit.Broadcast(new GamerPlayCards() { PlayerID = _gamer.Id, Cards = _gamerCards }); } } //游戏结束结算 gameController.GameOver(gamersScore); //广播游戏结束消息 unit.Broadcast(new Gameover() { Winner = winnerIdentity, BasePointPerMatch = gameController.BasePointPerMatch, Multiples = gameController.Multiples, GamersScore = gamersScore }); } else { //轮到下位玩家出牌 orderController.Biggest = gamer.Id; orderController.Turn(); unit.Broadcast(new AuthorityPlayCard() { PlayerID = orderController.CurrentAuthority, IsFirst = false }); } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } return(Task.CompletedTask); }
protected override async Task Run(Gamer gamer, C2M_GamerGrabLandlordSelect message) { Room room = Game.Scene.GetComponent <RoomComponent>().Get(gamer.RoomID); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); GameControllerComponent gameController = room.GetComponent <GameControllerComponent>(); if (orderController.CurrentAuthority == gamer.UserID) { //保存抢地主状态 orderController.GamerLandlordState[gamer.UserID] = message.IsGrab; if (message.IsGrab) { orderController.Biggest = gamer.UserID; gameController.Multiples *= 2; room.Broadcast(new M2C_SetMultiples() { Multiples = gameController.Multiples }); } //转发消息 C2M_GamerGrabLandlordSelect transpond = new C2M_GamerGrabLandlordSelect(); transpond.IsGrab = message.IsGrab; transpond.UserID = gamer.UserID; room.Broadcast(transpond); if (orderController.SelectLordIndex >= room.Count) { /* * 地主:√ 农民1:× 农民2:× * 地主:× 农民1:√ 农民2:√ * 地主:√ 农民1:√ 农民2:√ 地主:√ * * */ if (orderController.Biggest == 0) { //没人抢地主则重新发牌 gameController.BackToDeck(); gameController.DealCards(); //发送玩家手牌 Gamer[] gamers = room.GetAll(); Dictionary <long, int> gamerCardsNum = new Dictionary <long, int>(); Array.ForEach(gamers, _gamer => gamerCardsNum.Add(_gamer.UserID, _gamer.GetComponent <HandCardsComponent>().GetAll().Length)); Array.ForEach(gamers, _gamer => { ActorProxy actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorProxy(); actorProxy.Send(new M2C_GameStart() { GamerCards = _gamer.GetComponent <HandCardsComponent>().GetAll(), GamerCardsNum = gamerCardsNum }); }); //随机先手玩家 gameController.RandomFirstAuthority(); return; } else if ((orderController.SelectLordIndex == room.Count && ((orderController.Biggest != orderController.FirstAuthority.Key && !orderController.FirstAuthority.Value) || orderController.Biggest == orderController.FirstAuthority.Key)) || orderController.SelectLordIndex > room.Count) { gameController.CardsOnTable(orderController.Biggest); return; } } //当所有玩家都抢地主时先手玩家还有一次抢地主的机会 if (gamer.UserID == orderController.FirstAuthority.Key && message.IsGrab) { orderController.FirstAuthority = new KeyValuePair <long, bool>(gamer.UserID, true); } orderController.Turn(false); orderController.SelectLordIndex++; room.Broadcast(new M2C_AuthorityGrabLandlord() { UserID = orderController.CurrentAuthority }); } await Task.CompletedTask; }
protected override Task Run(Room entity, GrabLordSelect message) { OrderControllerComponent orderController = entity.GetComponent <OrderControllerComponent>(); GameControllerComponent gameController = entity.GetComponent <GameControllerComponent>(); if (orderController.CurrentAuthority == message.PlayerId) { if (message.IsGrab) { orderController.Biggest = message.PlayerId; gameController.Multiples *= 2; entity.Broadcast(new GameMultiples() { Multiples = gameController.Multiples }); } //转发消息 entity.Broadcast(message); if (orderController.SelectLordIndex >= entity.Count) { /* * 地主:√ 农民1:× 农民2:× * 地主:× 农民1:√ 农民2:√ * 地主:√ 农民1:√ 农民2:√ 地主2:√ * * */ if (orderController.Biggest == 0) { //没人抢地主则重新发牌 gameController.BackToDeck(); gameController.DealCards(); //发送玩家手牌 Gamer[] gamers = entity.GetAll(); Dictionary <long, int> gamerCardsNum = new Dictionary <long, int>(); Array.ForEach(gamers, gamer => gamerCardsNum.Add(gamer.Id, gamer.GetComponent <HandCardsComponent>().GetAll().Length)); Array.ForEach(gamers, gamer => { ActorProxy actorProxy = gamer.GetComponent <UnitGateComponent>().GetActorProxy(); actorProxy.Send(new GameStart() { GamerCards = gamer.GetComponent <HandCardsComponent>().GetAll(), GamerCardsNum = gamerCardsNum }); }); //随机先手玩家 gameController.RandomFirstAuthority(); return(Task.CompletedTask); } else if ((orderController.SelectLordIndex == entity.Count && ((orderController.Biggest != orderController.FirstAuthority.Key && !orderController.FirstAuthority.Value) || orderController.Biggest == orderController.FirstAuthority.Key)) || orderController.SelectLordIndex > entity.Count) { gameController.CardsOnTable(orderController.Biggest); return(Task.CompletedTask); } } //当所有玩家都抢地主时先手玩家还有一次抢地主的机会 if (message.PlayerId == orderController.FirstAuthority.Key && message.IsGrab) { orderController.FirstAuthority = new KeyValuePair <long, bool>(message.PlayerId, true); } orderController.Turn(); orderController.SelectLordIndex++; entity.Broadcast(new SelectAuthority() { PlayerId = orderController.CurrentAuthority }); } return(Task.CompletedTask); }