/// <summary> /// 向客户端发地主牌 /// </summary> public static void CardsOnTable(this GameControllerComponent self, long id) { Room room = self.GetParent <Room>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); HandCardsComponent handCards = room.GetGamerFromUserID(id).GetComponent <HandCardsComponent>(); orderController.Start(id); for (int i = 0; i < 3; i++) { Card card = self.DealLord(room); handCards.AddCard(card); } //更新玩家身份 foreach (var gamer in room.gamers) { Identity gamerIdentity = gamer.UserID == id ? Identity.Landlord : Identity.Farmer; self.UpdateInIdentity(gamer, gamerIdentity); } //广播地主消息 room.Broadcast(new Actor_SetLandlord_Ntt() { UserID = id, LordCards = To.RepeatedField(room.LordCards) }); //广播地主先手出牌消息 room.Broadcast(new Actor_AuthorityPlayCard_Ntt() { UserID = id, IsFirst = true }); }
/// <summary> /// 排序,得到牛型 /// </summary> /// <param name="self"></param> /// <returns></returns> public static byte Sort(this HandCardsComponent self) { //手牌排序 . 牛数算法 TODO Arithmetic(self); return(self.CardType); }
protected override void Run(ETModel.Session session, Actor_GamerCheat message) { try { Log.Debug("收到作弊"); UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>(); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); Gamer gamer = gamerComponent.Get(PlayerInfoComponent.Instance.uid); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); if (handCardsComponent == null) { return; } handCardsComponent.DeleteAllItem(handCardsComponent.CardBottom); foreach (var card in message.handCards) { card.m_weight = (Consts.MahjongWeight)card.weight; } handCardsComponent.AddCards(message.handCards); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 准备开始游戏 /// </summary> /// <param name="self"></param> public static void ReadyStartGame(this GameControllerComponent self) { Room room = self.GetParent <Room>(); Gamer[] gamers = room.GetAll(); //房间内有3名玩家且全部准备则开始游戏 if (room.Count == 3 && gamers.Where(g => g.IsReady).Count() == 3) { //同步匹配服务器开始游戏 room.State = RoomState.Game; MapHelper.SendMessage(new MP2MH_SyncRoomState_Ntt() { RoomID = room.InstanceId, State = room.State }); //初始玩家开始状态 foreach (var _gamer in gamers) { if (_gamer.GetComponent <HandCardsComponent>() == null) { _gamer.AddComponent <HandCardsComponent>(); } _gamer.IsReady = false; } 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) { ActorMessageSender actorProxy = _gamer.GetComponent <UnitGateComponent>().GetActorMessageSender(); Actor_GameStart_Ntt gameStartMessage = new Actor_GameStart_Ntt(); gameStartMessage.HandCards.AddRange(_gamer.GetComponent <HandCardsComponent>().GetAll()); gameStartMessage.GamersCardNum.AddRange(gamersCardNum); actorProxy.Send(gameStartMessage); } //随机先手玩家 gameController.RandomFirstAuthority(); Log.Info($"房间{room.InstanceId}开始游戏"); } }
protected override void Run(ETModel.Session session, Actor_GamerPlayCard_Ntt message) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom); LandlordsRoomComponent room = uiRoom.GetComponent <LandlordsRoomComponent>(); Gamer gamer = room.GetGamer(message.UserID); if (gamer != null) { gamer.GetComponent <LandlordsGamerPanelComponent>().ResetPrompt(); //本地玩家清空选中牌 关闭出牌按钮 if (gamer.UserID == LandlordsRoomComponent.LocalGamer.UserID) { LandlordsInteractionComponent interaction = uiRoom.GetComponent <LandlordsRoomComponent>().Interaction; interaction.Clear(); interaction.EndPlay(); } //出牌后更新玩家手牌 HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); Card[] Tcards = new Card[message.Cards.Count]; for (int i = 0; i < message.Cards.Count; i++) { Tcards[i] = message.Cards[i]; } handCards.PopCards(Tcards); } }
public void ShowOperation(int operationType) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); Gamer gamer = gamerComponent.Get(PlayerInfoComponent.Instance.uid); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); switch (operationType) { case 0: pengBtn.gameObject.SetActive(true); handCardsComponent.ShowHandCardCanPeng(CurrentMahjong.weight); break; case 1: case 4: case 5: gangBtn.gameObject.SetActive(true); handCardsComponent.ShowHandCardCanPeng(CurrentMahjong.weight); break; case 2: huBtn.gameObject.SetActive(true); break; case 3: break; } giveUpBtn.gameObject.SetActive(true); }
/// <summary> /// 发地主牌 /// </summary> /// <param name="self"></param> /// <param name="id"></param> public static void CardsOnTable(this GameControllerComponent self, long id) { Room room = self.GetParent <Room>(); DeskCardsCacheComponent deskCardsCache = room.GetComponent <DeskCardsCacheComponent>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); HandCardsComponent handCards = room.Get(id).GetComponent <HandCardsComponent>(); orderController.Start(id); for (int i = 0; i < 3; i++) { Card card = deskCardsCache.Deal(); handCards.AddCard(card); } //更新玩家身份 foreach (var gamer in room.GetAll()) { Identity gamerIdentity = gamer.UserID == id ? Identity.Landlord : Identity.Farmer; self.UpdateInIdentity(gamer, gamerIdentity); } //广播地主消息 room.Broadcast(new M2C_SetLandlord() { UserID = id, LordCards = deskCardsCache.LordCards.ToArray() }); //广播地主先手出牌消息 room.Broadcast(new M2C_AuthorityPlayCard() { UserID = id, IsFirst = true }); }
private static void Arithmetic(this HandCardsComponent self) { byte[] Cards = self.GetAll(); List <byte> NewList = new List <byte>(); int RemainNumber = 0; int NiuNumber = -1; bool IsHaveNiu = false; for (int i = 0; i <= 2; i++) { if (IsHaveNiu) { break; } for (int j = i + 1; j <= 3; j++) { if (IsHaveNiu) { break; } for (int k = j + 1; k <= 4; k++) { if (IsHaveNiu) { break; } byte NumberA = GetCardValue(Cards[i]); byte NumberB = GetCardValue(Cards[j]); byte NumberC = GetCardValue(Cards[k]); int Numbers = NumberA + NumberB + NumberC; if (Numbers % 10 == 0) { IsHaveNiu = true; self.library.Clear(); NewList.Clear(); NewList.Add(Cards[i]); NewList.Add(Cards[j]); NewList.Add(Cards[k]); for (int l = 0; l <= 4; l++) { if (l != i && l != j && l != k) { NewList.Add(Cards[l]); RemainNumber += GetCardValue(Cards[l]); } } //判断牛型 self.CardType = (byte)(RemainNumber % 10); //if (NiuNumber<temp||temp==0) //{ // NiuNumber = temp; //} self.library.AddRange(NewList); } } } } }
protected override void Run(ETModel.Session session, Actor_GamerReconnect_Ntt message) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom); LandlordsRoomComponent room = uiRoom.GetComponent <LandlordsRoomComponent>(); //关闭准备按钮 uiRoom.GameObject.Get <GameObject>("ReadyButton").SetActive(false); foreach (GamerState gamerState in message.GamersState) { //遍历玩家状态 设置地主身份和头像 Gamer gamer = room.GetGamer(gamerState.UserID); HandCardsComponent gamerHandCards = gamer.GetComponent <HandCardsComponent>(); LandlordsGamerPanelComponent gamerUI = gamer.GetComponent <LandlordsGamerPanelComponent>(); Identity gamerIdentity = (Identity)gamerState.Identity; gamerHandCards.AccessIdentity = gamerIdentity; gamerUI.SetIdentity(gamerIdentity); //如果在牌局中 恢复上一个玩家的出牌行为(牌最大的玩家) //ID用于确认玩家 身份状态用于确认是否开始了牌局 if (message.BiggstGamer == gamer.UserID && gamerIdentity != Identity.None) { Card[] Tcards = new Card[message.DeskCards.Count]; for (int i = 0; i < message.DeskCards.Count; i++) { Tcards[i] = message.DeskCards[i]; } if (Tcards != null) { gamerHandCards.PopCards(Tcards); //本地出牌画面更新 } } else if (message.LordCards.Count == 0 && gamerState.GrabLandlordState) { //如果牌局在抢地主阶段 恢复抢地主状态 gamerUI.SetGrab(gamerState.GrabLandlordState); } } //初始化界面 room.SetMultiples(message.Multiples); //当抢完地主时才能显示托管按钮 if (message.LordCards.Count != 0) { room.Interaction.GameStart(); } //初始化地主牌 if (message.LordCards != null) { GameObject lordPokers = uiRoom.GameObject.Get <GameObject>("Desk").Get <GameObject>("LordPokers"); for (int i = 0; i < lordPokers.transform.childCount; i++) { Sprite lordCardSprite = CardHelper.GetCardSprite(message.LordCards[i].GetName()); lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordCardSprite; } } }
protected override void Run(ETModel.Session session, Actor_GameStart_Ntt message) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); //初始化玩家UI foreach (GamerCardNum gamerCardNum in message.GamersCardNum) { Gamer gamer = uiRoom.GetComponent <GamerComponent>().Get(gamerCardNum.UserID); GamerUIComponent gamerUI = gamer.GetComponent <GamerUIComponent>(); gamerUI.GameStart(); HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); if (handCards != null) { handCards.Reset(); } else { handCards = gamer.AddComponent <HandCardsComponent, GameObject>(gamerUI.Panel); } handCards.Appear(); if (gamer.UserID == gamerComponent.LocalGamer.UserID) { //本地玩家添加手牌 handCards.AddCards(message.HandCards); } else { //设置其他玩家手牌数 handCards.SetHandCardsNum(gamerCardNum.Num); } } //显示牌桌UI GameObject desk = uiRoom.GameObject.Get <GameObject>("Desk"); desk.SetActive(true); GameObject lordPokers = desk.Get <GameObject>("LordPokers"); //重置地主牌 Sprite lordSprite = CardHelper.GetCardSprite("None"); for (int i = 0; i < lordPokers.transform.childCount; i++) { lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordSprite; } LandlordsRoomComponent uiRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>(); //清空选中牌 uiRoomComponent.Interaction.Clear(); //设置初始倍率 uiRoomComponent.SetMultiples(1); }
/// <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}开始游戏"); }
protected override async Task Run(Gamer gamer, Actor_GamerCheat message) { try { Log.Info("收到作弊:" + JsonHelper.ToJson(message)); if (string.IsNullOrEmpty(message.Info)) { return; } string[] split = message.Info.Split(' '); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); if (handCardsComponent == null) { handCardsComponent = gamer.AddComponent <HandCardsComponent>(); } if (split.Length == 13) { List <MahjongInfo> mahjongInfos = new List <MahjongInfo>(); foreach (var item in split) { mahjongInfos.Add(new MahjongInfo() { m_weight = (Consts.MahjongWeight)Convert.ToInt32(item), weight = (byte)Convert.ToInt32(item) }); } handCardsComponent.library = mahjongInfos; Logic_NJMJ.getInstance().SortMahjong(handCardsComponent.library); Actor_GamerCheat actorCheat = new Actor_GamerCheat(); actorCheat.handCards = mahjongInfos; room.GamerBroadcast(gamer, actorCheat); } else if (split.Length == 1) { int num = Convert.ToInt32(split[0]); room.NextGrabCard = new MahjongInfo() { m_weight = (Consts.MahjongWeight)num, weight = (byte)num }; } } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
/// <summary> /// 打印所有的手牌 /// </summary> /// <param name="self"></param> /// <returns></returns> public static string ShowAllCard(this HandCardsComponent self) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < self.CardsCount; i++) { sb.Append($"{self.library[i]} |"); } return(sb.ToString()); }
protected override void Run(Session session, M2C_SetLandlord message) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); Gamer gamer = gamerComponent.Get(message.UserID); if (gamer != null) { HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); if (gamer.UserID == gamerComponent.LocalGamer.UserID) { //本地玩家添加手牌 handCards.AddCards(message.LordCards); } else { //其他玩家设置手牌数 handCards.SetHandCardsNum(20); } } foreach (var _gamer in gamerComponent.GetAll()) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); GamerUIComponent gamerUIComponent = _gamer.GetComponent <GamerUIComponent>(); if (_gamer.UserID == message.UserID) { handCardsComponent.AccessIdentity = Identity.Landlord; gamerUIComponent.SetIdentity(Identity.Landlord); } else { handCardsComponent.AccessIdentity = Identity.Farmer; gamerUIComponent.SetIdentity(Identity.Farmer); } } //重置玩家UI提示 foreach (var _gamer in gamerComponent.GetAll()) { _gamer.GetComponent <GamerUIComponent>().ResetPrompt(); } //切换地主牌精灵 GameObject lordPokers = uiRoom.GameObject.Get <GameObject>("Desk").Get <GameObject>("LordPokers"); for (int i = 0; i < lordPokers.transform.childCount; i++) { Sprite lordCardSprite = CardHelper.GetCardSprite(message.LordCards[i].GetName()); lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordCardSprite; } //显示切换游戏模式按钮 uiRoom.GetComponent <UIRoomComponent>().Interaction.GameStart(); }
protected override async void Run(ETModel.Session session, Actor_GamerGrabCard message) { try { Log.Info($"收到抓拍"); MahjongInfo mahjongInfo = new MahjongInfo() { weight = (byte)message.weight, m_weight = (Consts.MahjongWeight)message.weight }; UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); if (uiRoom == null) { return; } GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>(); Gamer gamer = gamerComponent.Get(message.Uid); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); if (PlayerInfoComponent.Instance.uid == message.Uid) { handCardsComponent.GrabCard(mahjongInfo); } else { handCardsComponent.GrabOtherCard(); } //当前出牌玩家 gamerComponent.CurrentPlayUid = message.Uid; gamerComponent.IsPlayed = false; //剩下的牌 uiRoomComponent.SetRestCount(); //显示黄色bg uiRoomComponent.ShowTurn(message.Uid); uiRoomComponent.ClosePropmtBtn(); SoundsHelp.Instance.playSound_MoPai(); uiRoomComponent.CurrentMahjong = mahjongInfo; Gamer currentGamer = gamerComponent.Get(PlayerInfoComponent.Instance.uid); HandCardsComponent currentGamerCard = currentGamer.GetComponent <HandCardsComponent>(); currentGamerCard.CloseHandCardCanPeng(); } catch (Exception e) { Log.Error(e); } }
public void Awake() { this.ItemCard = this.GetParent <UI>().GameObject; Button button = this.ItemCard.GetComponent <Button>(); UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); this.handCardsComponent = gamerComponent.LocalGamer.GetComponent <HandCardsComponent>(); button.onClick.RemoveAllListeners(); button.onClick.Add(() => { OnClick(); }); CommonUtil.SetTextFont(this.GetParent <UI>().GameObject); }
protected override void Run(ETModel.Session session, Actor_GamerReconnect_Ntt message) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); foreach (GamerState gamerState in message.GamersState) { Gamer gamer = gamerComponent.Get(gamerState.UserID); HandCardsComponent gamerHandCards = gamer.GetComponent <HandCardsComponent>(); GamerUIComponent gamerUI = gamer.GetComponent <GamerUIComponent>(); Identity gamerIdentity = gamerState.UserIdentity; gamerHandCards.AccessIdentity = gamerIdentity; gamerUI.SetIdentity(gamerIdentity); //初始化出牌 if (message.UserId == gamer.UserID && gamerIdentity != Identity.None) { if (message.Cards != null) { gamerHandCards.PopCards(message.Cards); } } else if (message.LordCards.count == 0) { gamer.GetComponent <GamerUIComponent>().SetGrab(gamerState.State); } } //初始化界面 LandlordsRoomComponent uiRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>(); //隐藏准备按钮,避免重连时还显示准备按钮 uiRoom.GameObject.Get <GameObject>("ReadyButton").SetActive(false); //设置倍率 uiRoomComponent.SetMultiples(message.Multiples); //当抢完地主时才能显示托管按钮 if (message.LordCards.count > 0) { uiRoomComponent.Interaction.GameStart(); } //初始化地主牌 if (message.LordCards.count > 0) { GameObject lordPokers = uiRoom.GameObject.Get <GameObject>("Desk").Get <GameObject>("LordPokers"); for (int i = 0; i < lordPokers.transform.childCount; i++) { Sprite lordCardSprite = CardHelper.GetCardSprite(message.LordCards[i].GetName()); lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordCardSprite; } } }
/// <summary> /// 计算玩家积分 /// </summary> /// <param name="self"></param> /// <param name="gamer"></param> /// <param name="winnerIdentity"></param> /// <returns></returns> public static long GetGamerScore(this GameControllerComponent self, Gamer gamer, Identity winnerIdentity) { HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); //积分计算公式:全场底分 * 全场倍率 * 身份倍率 long integration = self.BasePointPerMatch * self.Multiples * (int)handCards.AccessIdentity; //当玩家不是胜者,结算积分为负 if (handCards.AccessIdentity != winnerIdentity) { integration = -integration; } return(integration); }
protected override void Run(Session session, M2C_GamerReconnect_ANtt message) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); uiRoom.GameObject.Get <GameObject>("ReadyButton").SetActive(false); foreach (var gamer in gamerComponent.GetAll()) { //初始化玩家身份 Identity gamerIdentity = message.GamersIdentity[gamer.UserID]; HandCardsComponent gamerHandCards = gamer.GetComponent <HandCardsComponent>(); GamerUIComponent gamerUI = gamer.GetComponent <GamerUIComponent>(); gamerHandCards.AccessIdentity = gamerIdentity; gamerUI.SetIdentity(gamerIdentity); //初始化出牌 if (message.DeskCards.Key == gamer.UserID && gamerIdentity != Identity.None) { Card[] deskCards = message.DeskCards.Value; if (deskCards != null) { gamerHandCards.PopCards(deskCards); } } else if (message.LordCards == null && message.GamerGrabLandlordState.ContainsKey(gamer.UserID)) { gamer.GetComponent <GamerUIComponent>().SetGrab(message.GamerGrabLandlordState[gamer.UserID]); } } //初始化界面 UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>(); uiRoomComponent.SetMultiples(message.Multiples); //当抢完地主时才能显示托管按钮 if (message.LordCards != null) { uiRoomComponent.Interaction.GameStart(); } //初始化地主牌 if (message.LordCards != null) { GameObject lordPokers = uiRoom.GameObject.Get <GameObject>("Desk").Get <GameObject>("LordPokers"); for (int i = 0; i < lordPokers.transform.childCount; i++) { Sprite lordCardSprite = CardHelper.GetCardSprite(message.LordCards[i].GetName()); lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordCardSprite; } } }
/// <summary> /// 场上所有牌回收到牌库中 /// </summary> /// <param name="self"></param> public static void BackToDeck(this GameControllerComponent self) { Room room = self.GetParent <Room>(); DeckComponent deckComponent = room.GetComponent <DeckComponent>(); foreach (var gamer in room.GetAll()) { HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); while (handCards.CardsCount > 0) { byte card = handCards.library[handCards.CardsCount - 1]; handCards.PopCard(card); deckComponent.AddCard(card); } } }
/// <summary> /// 出牌 /// </summary> /// <param name="self"></param> public static async Task <MahjongInfo> PopCard(this HandCardsComponent self) { if (self == null) { return(null); } Gamer gamer = self.GetParent <Gamer>(); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); List <MahjongInfo> mahjongInfos = self.GetAll(); MahjongInfo mahjongInfo = handCardsComponent.GrabCard; int index = -1; for (int i = 0; i < handCardsComponent.GetAll().Count; i++) { MahjongInfo info = handCardsComponent.GetAll()[i]; if (info.m_weight == mahjongInfo.m_weight) { index = i; break; } } //最右边的一张 if (index < 0) { mahjongInfo = handCardsComponent.GetAll()[handCardsComponent.GetAll().Count - 1]; index = handCardsComponent.GetAll().Count - 1; } // int randomNumber = RandomHelper.RandomNumber(0, mahjongInfos.Count); // // MahjongInfo mahjongInfo = mahjongInfos[randomNumber]; //Log.Info("超时自动出牌"); await Actor_GamerPlayCardHandler.PlayCard(gamer, new Actor_GamerPlayCard() { Uid = gamer.UserID, weight = (int)mahjongInfo.m_weight, index = index }); return(mahjongInfo); }
/// <summary> /// 显示中间的指针 /// </summary> /// <param name="userId"></param> public void ShowTurn(long userId) { GamerComponent gamerComponent = this.GetParent <UI>().GetComponent <GamerComponent>(); foreach (var _gamer in gamerComponent.GetAll()) { HandCardsComponent cardsComponent = _gamer.GetComponent <HandCardsComponent>(); if (_gamer.UserID == userId) { cardsComponent.ShowBg(); } else { cardsComponent.CloseBg(); } } //时间重新开始 StartTime(); }
protected override void Run(ETModel.Session session, Actor_GamerPlayCard_Ntt message) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); Gamer gamer = gamerComponent.Get(message.UserID); if (gamer != null) { gamer.GetComponent <GamerUIComponent>().ResetPrompt(); if (gamer.UserID == gamerComponent.LocalGamer.UserID) { LandlordsInteractionComponent interaction = uiRoom.GetComponent <LandlordsRoomComponent>().Interaction; interaction.Clear(); interaction.EndPlay(); } HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); handCards.PopCards(message.Cards); } }
protected override async void Run(ETModel.Session session, Actor_GamerBuHua message) { try { Log.Info($"收到补花:{message.weight}"); MahjongInfo mahjongInfo = new MahjongInfo() { weight = (byte)message.weight, m_weight = (Consts.MahjongWeight)message.weight }; UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>(); Gamer gamer = gamerComponent.Get(message.Uid); GamerUIComponent gamerUiComponent = gamer.GetComponent <GamerUIComponent>(); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); if (PlayerInfoComponent.Instance.uid == message.Uid) { handCardsComponent.BuHua(mahjongInfo, true); SoundsHelp.Instance.PlayBuHua(PlayerInfoComponent.Instance.GetPlayerInfo().PlayerSound); } else { handCardsComponent.BuHua(mahjongInfo, false); SoundsHelp.Instance.PlayBuHua(gamer.PlayerInfo.PlayerSound); } //补花显示 gamerUiComponent.SetBuHua(message.weight); gamerUiComponent.ShowBuHua(); //剩下的牌 uiRoomComponent.SetRestCount(); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 发牌 /// </summary> /// <param name="self"></param> public static void DealCards(this GameControllerComponent self) { if (self == null) { Log.Error("当前为null:GameControllerComponent.DealCards"); return; } temp.Clear(); Room room = self.GetParent <Room>(); Gamer[] gamers = room.GetAll(); DeskComponent deskComponent = room.GetComponent <DeskComponent>(); foreach (var gamer in gamers) { HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); //发牌前有拍了 if (handCardsComponent.GetAll().Count > 0) { // Log.Debug("发牌前有牌了:" + handCardsComponent.GetAll().Count); temp.Add(null); } else { // Log.Debug("发牌前没有拍"); temp.Add(handCardsComponent.GetAll()); } } Logic_NJMJ.getInstance().FaMahjong(temp, deskComponent.RestLibrary); foreach (var card in deskComponent.RestLibrary) { card.weight = (byte)card.m_weight; } }
/// <summary> /// 发牌(不包括花牌) /// </summary> /// <param name="deskComponent"></param> /// <param name="handCardsComponent"></param> private static void GetCardNotFace(DeskComponent deskComponent, HandCardsComponent handCardsComponent) { while (true) { int cardIndex = RandomHelper.RandomNumber(0, deskComponent.RestLibrary.Count); MahjongInfo grabMahjong = deskComponent.RestLibrary[cardIndex]; deskComponent.RestLibrary.RemoveAt(cardIndex); //花牌 if (grabMahjong.m_weight >= Consts.MahjongWeight.Hua_HongZhong) { handCardsComponent.FaceCards.Add(grabMahjong); handCardsComponent.FaceGangCards.Add(grabMahjong); } else { handCardsComponent.GetAll().Add(grabMahjong); break; } } }
public static void PlayCard(Actor_GamerPlayCard message) { try { Log.Info($"收到出牌"); MahjongInfo mahjongInfo = new MahjongInfo() { weight = (byte)message.weight, m_weight = (Consts.MahjongWeight)message.weight }; UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>(); Gamer gamer = gamerComponent.Get(message.Uid); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); HandCardsComponent cardsComponent = gamerComponent.LocalGamer.GetComponent <HandCardsComponent>(); if (PlayerInfoComponent.Instance.uid == message.Uid) { handCardsComponent.PlayCard(mahjongInfo, message.index, uiRoomComponent.currentItem); SoundsHelp.Instance.PlayCardSound(PlayerInfoComponent.Instance.GetPlayerInfo().PlayerSound, message.weight); } else { handCardsComponent.PlayOtherCard(mahjongInfo, uiRoomComponent.currentItem); SoundsHelp.Instance.PlayCardSound(gamer.PlayerInfo.PlayerSound, message.weight); } gamerComponent.LastPlayUid = message.Uid; SoundsHelp.Instance.playSound_ChuPai(); uiRoomComponent.CurrentMahjong = mahjongInfo; } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 场上的所有牌回到牌库中 /// </summary> /// <param name="self"></param> public static void BackToDeck(this GameControllerComponent self) { Room room = self.GetParent <Room>(); DeckComponent deckComponent = room.GetComponent <DeckComponent>(); DeskCardsCacheComponent deskCardsCache = room.GetComponent <DeskCardsCacheComponent>(); //回收牌桌卡牌 deskCardsCache.Clear(); deskCardsCache.LordCards.Clear(); //回收玩家手牌 foreach (var gamer in room.GetAll()) { HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>(); while (handCards.CardsCount > 0) { Card card = handCards.library[handCards.CardsCount - 1]; handCards.PopCard(card); deckComponent.AddCard(card); } } }
protected override async void Run(ETModel.Session session, Actor_GamerChangeGold message) { try { Log.Info($"收到改变金币:" + message.Uid + "GoldAmount," + message.GoldAmount); UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); if (uiRoom == null) { Log.Warning("uiroom null"); return; } UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>(); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); Gamer gamer = gamerComponent.Get(message.Uid); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); handCardsComponent.ChangeGold(message.GoldAmount); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 提示 /// </summary> private async void OnPrompt() { Actor_GamerPrompt_Req request = new Actor_GamerPrompt_Req(); Actor_GamerPrompt_Back response = (Actor_GamerPrompt_Back)await SessionComponent.Instance.Session.Call(request); HandCardsComponent handCards = LandlordsRoomComponent.LocalGamer.GetComponent <HandCardsComponent>(); //清空当前选中 while (currentSelectCards.Count > 0) { Card selectCard = currentSelectCards[currentSelectCards.Count - 1]; handCards.GetSprite(selectCard).GetComponent <HandCardSprite>().OnClick(null); } //自动选中提示出牌 if (response.Cards != null) { for (int i = 0; i < response.Cards.Count; i++) { handCards.GetSprite(response.Cards[i]).GetComponent <HandCardSprite>().OnClick(null); } } }