/// <summary> /// 收到补花 /// </summary> /// <param name="mahjongInfo"></param> /// <param name="b"></param> public async void BuHua(MahjongInfo mahjongInfo, bool isSelf) { //补花数量 try { faceCards.Add(mahjongInfo); SetFaceCards(faceCards); // await ETModel.Game.Scene.GetComponent<TimerComponent>().WaitAsync(100); //删除花牌 if (isSelf) { // GameObject gameObject = this.GetSprite(grabIndex); // GameObject.Destroy(gameObject); // handCards.RemoveAt(grabIndex); // ItemCards.RemoveAt(grabIndex); // UpdateCards(); } else { // grabObj.SetActive(false); grabObj.transform.localScale = Vector3.zero; } } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 玩家出牌 /// </summary> /// <param name="mahjong"></param> /// <param name="messageIndex"></param> /// <param name="messageWeight"></param> public async void PlayCard(MahjongInfo mahjong, int index, GameObject currentItem) { try { for (int i = 0; i < handCards.Count; i++) { if (handCards[i].weight == mahjong.weight) { GameObject gameObject = this.GetSprite(i); GameObject.Destroy(gameObject); handCards.RemoveAt(i); playCards.Add(mahjong); ItemCards.RemoveAt(i); break; } } UpdateCards(); //显示出牌 GameObject obj = (GameObject)this.resourcesComponent.GetAsset("Item_Vertical_Card.unity3d", "Item_Vertical_Card"); GameObject obj2 = (GameObject)this.resourcesComponent.GetAsset("Image_Top_Card.unity3d", "Image_Top_Card"); this.currentPlayCardObj = GameObject.Instantiate(obj, this.cardDisplay.transform); currentPlayCardObj.GetComponent <Image>().sprite = obj2.Get <Sprite>("card_" + mahjong.weight); currentPlayCardObj.layer = LayerMask.NameToLayer("UI"); currentItem = currentPlayCardObj; ShowCard(mahjong.weight); //出了几张一样的牌 int playCount = 0; foreach (var card in playCards) { if (card.weight == mahjong.weight) { playCount++; } } if (playCount == 3) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>(); uiRoomComponent.tip.SetActive(true); uiRoomComponent.tip.GetComponentInChildren <Image>().sprite = CommonUtil.getSpriteByBundle("Image_Desk_Card", "foursame_tip"); await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(3000); if (this.IsDisposed) { return; } uiRoomComponent?.tip?.SetActive(false); } } catch (Exception e) { Log.Error(e); } }
// 供外部调用:检查听的牌,为空则没听牌 public List <MahjongInfo> checkTingPaiList(List <MahjongInfo> list) { List <MahjongInfo> tingpaiList = new List <MahjongInfo>(); try { for (int i = 0; i < m_differenceMahjongList.Count; i++) { List <MahjongInfo> temp = new List <MahjongInfo>(); for (int j = 0; j < list.Count; j++) { temp.Add(list[j]); } MahjongInfo mahjongInfoTemp = m_differenceMahjongList[i]; temp.Add(mahjongInfoTemp); if (isHuPai(temp)) { tingpaiList.Add(mahjongInfoTemp); } } } catch (Exception e) { Log.Error("听牌:" + e); } return(tingpaiList); }
/// <summary> /// 碰刚 /// </summary> /// <param name="messageOperationType"></param> /// <param name="mahjong"></param> public void SetPengGang(int messageOperationType, MahjongInfo mahjong) { Log.Debug("显示碰后杠"); GameObject obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong); this.RemoveCard(index); UpdateCards(); //显示碰 GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform); for (int i = 0; i < 2; i++) { gameObject.transform.GetChild(i).GetComponent <Image>().sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_" + mahjong.weight); } GameObject lastPengObj = null; if (pengDic.TryGetValue(mahjong.weight, out lastPengObj)) { gameObject.transform.SetSiblingIndex(lastPengObj.transform.GetSiblingIndex()); gameObject.transform.localPosition = lastPengObj.transform.localPosition; GameObject.Destroy(lastPengObj); pengDic.Remove(mahjong.weight); } }
public void RemoveCard(List <MahjongInfo> mahjongInfos, MahjongInfo mahjongInfo) { int index = GetIndex(mahjongInfos, mahjongInfo); if (index >= 0) { mahjongInfos.RemoveAt(index); } }
private void AddCard(MahjongInfo mahjong, int postionX, int postionY, int index) { GameObject cardSprite = this.CreateCardSprite($"{Direction}_" + mahjong.weight, postionX, postionY); ItemCards.Add(cardSprite); //设置item cardSprite.GetComponent <ItemCardScipt>().weight = mahjong.weight; cardSprite.GetComponent <ItemCardScipt>().index = index; }
public bool Operate(List <MahjongInfo> allCards, MahjongInfo mahjongInfo) { if (CanPeng(allCards, mahjongInfo) || CanGang(allCards, mahjongInfo) || CanHu(allCards, mahjongInfo)) { giveUpBtn.gameObject.SetActive(true); return(true); } return(false); }
public bool CanGang(List <MahjongInfo> list, MahjongInfo mahjongInfo) { if (Logic_NJMJ.getInstance().isCanGang(mahjongInfo, list)) { gangBtn.gameObject.SetActive(true); return(true); } return(false); }
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 bool CanHu(List <MahjongInfo> list, MahjongInfo mahjongInfo) { List <MahjongInfo> temp = new List <MahjongInfo>(list); temp.Add(mahjongInfo); if (Logic_NJMJ.getInstance().isHuPai(temp)) { gangBtn.gameObject.SetActive(true); return(true); } return(false); }
// 供外部调用:排序:从左到右显示 public void SortMahjong(List <MahjongInfo> list) { for (int i = 0; i < list.Count - 1; i++) { for (int j = list.Count - 1; j >= 1; j--) { if (list[j].m_weight < list[j - 1].m_weight) { MahjongInfo temp = list[j]; list[j] = list[j - 1]; list[j - 1] = temp; } } } }
public int GetIndex(List <MahjongInfo> mahjongInfos, MahjongInfo mahjongInfo) { int index = -1; for (int i = 0; i < mahjongInfos.Count; i++) { if (mahjongInfos[i].m_weight == mahjongInfo.m_weight) { index = i; break; } } return(index); }
private void AddCard(MahjongInfo mahjong, int postionX, int postionY, int index) { GameObject cardSprite = this.CreateCardSprite($"{Direction}_" + mahjong.weight, postionX, postionY); //更换玩家牌的点击事件 // UI ui = ComponentFactory.Create<UI, GameObject>(cardSprite); // ui.AddComponent<ItemCardComponent>(); ItemCards.Add(cardSprite); //设置item cardSprite.GetComponent <ItemCardScipt>().weight = mahjong.weight; cardSprite.GetComponent <ItemCardScipt>().index = index; //更换玩家牌的点击事件 AddCardListener(cardSprite); }
/// <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); }
// 供外部调用:是否可以杠 // mahjongInfo:如果是别人出的牌,则为明杠,如果是自己新抓的牌,则为暗杠 // list:我的手牌 public bool isCanGang(MahjongInfo mahjongInfo, List <MahjongInfo> list) { int findCount = 0; for (int i = 0; i < list.Count; i++) { if (list[i].m_weight == mahjongInfo.m_weight) { ++findCount; } } if (findCount >= 3) { return(true); } return(false); }
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="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); } }
public static bool CanHu(this Room self, MahjongInfo mahjongInfo, List <MahjongInfo> list) { List <MahjongInfo> temp = new List <MahjongInfo>(list); temp.Add(mahjongInfo); try { if (Logic_NJMJ.getInstance().isHuPai(temp)) { return(true); } } catch (Exception e) { Log.Error("胡牌错误:" + e); Log.Info(JsonHelper.ToJson(temp)); } return(false); }
// 根据牌的权重获取它的类型 public MahjongType getMahjongType(MahjongInfo mahjongInfo) { if (mahjongInfo.m_weight <= MahjongWeight.Wan_9) { return(MahjongType.Wan); } else if (mahjongInfo.m_weight <= MahjongWeight.Tiao_9) { return(MahjongType.Tiao); } else if (mahjongInfo.m_weight <= MahjongWeight.Tong_9) { return(MahjongType.Tong); } else if (mahjongInfo.m_weight <= MahjongWeight.Feng_Bei) { return(MahjongType.Feng); } else { return(MahjongType.Hua); } }
/// <summary> /// 其他人碰刚 /// </summary> /// <param name="type"></param> /// <param name="mahjongInfo"></param> /// <param name="operatedUid"></param> /// <param name="messageUid"></param> /// <param name="messageOperatedUid"></param> public void SetOtherPeng(int type, MahjongInfo mahjongInfo, long operatedUid, long uid) { GameObject obj = null; int temp = 0; if (type == 0) { if (Index == 2) { obj = CommonUtil.getGameObjByBundle("Item_Peng_Card"); } else { obj = CommonUtil.getGameObjByBundle("Item_Right_Peng_Card"); } temp = 3; } else if (type == 1 || type == 4) { if (Index == 2) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); } else { obj = CommonUtil.getGameObjByBundle("Item_Right_Gang_Card"); } temp = 3; } else { if (Index == 2) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); } else { obj = CommonUtil.getGameObjByBundle("Item_Right_Gang_Card"); } temp = 4; } //设置谁碰刚 UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); int gamerSeat = gamerComponent.GetGamerSeat(operatedUid); int mySeat = gamerComponent.GetGamerSeat(uid); int offset = gamerSeat - mySeat; if (offset < 0) { offset += 4; } if (Index == 1) { if (offset == 1) { offset = 3; } else if (offset == 3) { offset = 1; } } else if (Index == 2) { } else if (Index == 3) { } //设置碰杠位置 GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform); int count = this.pengObj.transform.childCount; if (Index == 1) { gameObject.transform.localPosition = new Vector3(0, (count - 1) * 115, 0); } else if (Index == 2) { gameObject.transform.localPosition = new Vector3((count - 1) * (-160.93f), 0, 0); } else { gameObject.transform.localPosition = new Vector3(count * (postionX) * 3.5f, count * (postionY) * 3.5f, 0); } if (type == 0) { pengDic.Add(mahjongInfo.weight, gameObject); } //显示出牌 string item1 = null; string item2 = null; string item3 = null; string itemBack = null; if (Index == 1) { item1 = "Item_Horizontal_Card"; item2 = "Image_Right_Card"; item3 = "right_" + mahjongInfo.weight; itemBack = "right_back"; } else if (Index == 2) { item1 = "Item_Vertical_Card"; item2 = "Image_Top_Card"; item3 = "card_" + mahjongInfo.weight; itemBack = "card_back"; } else if (Index == 3) { item1 = "Item_Horizontal_Card"; item2 = "Image_Left_Card"; item3 = "left_" + mahjongInfo.weight; itemBack = "left_back"; } for (int i = 1; i < 4; i++) { Image image = gameObject.transform.Find("Item_" + i).GetComponent <Image>(); //暗杠显示 if (type == 4) { if (i == 2) { image.sprite = CommonUtil.getSpriteByBundle(item2, item3); } else { image.sprite = CommonUtil.getSpriteByBundle(item2, itemBack); } } else { if (i == offset) { image.sprite = CommonUtil.getSpriteByBundle(item2, itemBack); } else { image.sprite = CommonUtil.getSpriteByBundle(item2, item3); } } } num++; if (Index == 3) { for (int i = 0; i < temp; i++) { GameObject.Destroy(CardBottom.transform.GetChild(i).gameObject); } } else { for (int i = 0; i < temp; i++) { int childCount = this.CardBottom.transform.childCount; Log.Debug("销毁childCount:" + (childCount)); GameObject.DestroyImmediate(CardBottom.transform.GetChild(childCount - 1).gameObject); } Vector3 localPosition = this.CardBottom.transform.localPosition; float x = localPosition.x - postionX * 0.2f; float y = localPosition.y - postionY * 0.2f; this.CardBottom.transform.localPosition = new Vector3(x, y, localPosition.z); } }
/// <summary> /// 向牌库中添加牌 /// </summary> /// <param name="card"></param> public static void AddCard(this HandCardsComponent self, MahjongInfo card) { self.library.Add(card); }
public static async Task GamerReady(Gamer gamer, Actor_GamerReady message) { try { Log.Info($"收到玩家{gamer.UserID}准备"); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null || gamer == null || gamer.IsReady || room.State == RoomState.Game) { return; } gamer.IsReady = true; //消息广播给其他人 room?.Broadcast(new Actor_GamerReady() { Uid = gamer.UserID }); Gamer[] gamers = room.GetAll(); //房间内有4名玩家且全部准备则开始游戏 if (room.Count == 4 && gamers.Where(g => g.IsReady).Count() == 4) { room.State = RoomState.Game; room.CurrentJuCount++; room.IsGameOver = false; room.RoomDispose(); #region 好友房扣钥匙 if (room.IsFriendRoom && room.CurrentJuCount == 1) { RoomConfig roomConfig = room.GetComponent <GameControllerComponent>().RoomConfig; await DBCommonUtil.DeleteFriendKey(roomConfig.MasterUserId, roomConfig.KeyCount, "好友房房主扣除钥匙"); } #endregion //设置比下胡 if (room.LastBiXiaHu) { room.IsBiXiaHu = true; } else { room.IsBiXiaHu = false; } room.LastBiXiaHu = false; if (roomComponent.gameRooms.TryGetValue(room.Id, out var itemRoom)) { roomComponent.gameRooms.Remove(room.Id); } roomComponent.gameRooms.Add(room.Id, room); roomComponent.idleRooms.Remove(room.Id); //添加用户 room.UserIds.Clear(); //初始玩家开始状态 foreach (var _gamer in gamers) { room.UserIds.Add(_gamer.UserID); if (_gamer.GetComponent <HandCardsComponent>() == null) { _gamer.AddComponent <HandCardsComponent>(); } _gamer.IsReady = false; } Log.Info($"{room.Id}房间开始,玩家:{JsonHelper.ToJson(room.UserIds)}"); GameControllerComponent gameController = room.GetComponent <GameControllerComponent>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); DeskComponent deskComponent = room.GetComponent <DeskComponent>(); Gamer bankerGamer = null; HandCardsComponent bankerHandCards = null; if (room.IsLianZhuang) { if (room.huPaiUid != 0 && room.huPaiUid == room.BankerGamer?.UserID) { bankerGamer = room.Get(room.huPaiUid); bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; //连庄 room.LastBiXiaHu = true; } else { int gamerSeat = room.GetGamerSeat(room.BankerGamer.UserID); int currentSeat; if (gamerSeat == 3) { currentSeat = 0; } else { currentSeat = ++gamerSeat; } bankerGamer = room.gamers[currentSeat]; bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; } } else { if (room.IsFriendRoom) { GameControllerComponent controllerComponent = room.GetComponent <GameControllerComponent>(); long masterUserId = controllerComponent.RoomConfig.MasterUserId; bankerGamer = room.Get(masterUserId); } else { //随机庄家 int number = RandomHelper.RandomNumber(0, 12); int i = number % 4; bankerGamer = room.gamers[i]; } bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; } //发牌 gameController.DealCards(); orderController.Start(bankerGamer.UserID); //去除花牌 foreach (var _gamer in gamers) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); List <MahjongInfo> handCards = handCardsComponent.GetAll(); for (int j = handCards.Count - 1; j >= 0; j--) { MahjongInfo mahjongInfo = handCards[j]; if (mahjongInfo.m_weight >= Consts.MahjongWeight.Hua_HongZhong) { handCards.RemoveAt(j); mahjongInfo.weight = (byte)mahjongInfo.m_weight; handCardsComponent.FaceCards.Add(mahjongInfo); handCardsComponent.FaceGangCards.Add(mahjongInfo); } } //加牌 int handCardsCount = handCards.Count; for (int j = 0; j < 13 - handCardsCount; j++) { GetCardNotFace(deskComponent, handCardsComponent); } } //庄家多发一张牌 GetCardNotFace(deskComponent, bankerHandCards); // List<MahjongInfo> infos = bankerHandCards.GetAll(); // bankerHandCards.library = new List<MahjongInfo>(list); //给客户端传送数据 Actor_StartGame actorStartGame = new Actor_StartGame(); foreach (var itemGame in gamers) { GamerData gamerData = new GamerData(); HandCardsComponent handCardsComponent = itemGame.GetComponent <HandCardsComponent>(); List <MahjongInfo> mahjongInfos = handCardsComponent.library; foreach (var mahjongInfo in mahjongInfos) { mahjongInfo.weight = (byte)mahjongInfo.m_weight; } gamerData.UserID = itemGame.UserID; gamerData.handCards = mahjongInfos; gamerData.faceCards = handCardsComponent.FaceCards; if (handCardsComponent.IsBanker) { gamerData.IsBanker = true; } gamerData.SeatIndex = room.seats[itemGame.UserID]; gamerData.OnlineSeconds = await DBCommonUtil.GetRestOnlineSeconds(itemGame.UserID); actorStartGame.GamerDatas.Add(gamerData); } actorStartGame.restCount = deskComponent.RestLibrary.Count; GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); if (room.IsFriendRoom) { actorStartGame.RoomType = 3; actorStartGame.CurrentJuCount = room.CurrentJuCount; } else { actorStartGame.RoomType = (int)gameControllerComponent.RoomConfig.Id; } //发送消息 room.Broadcast(actorStartGame); // Log.Debug("发送开始:" + JsonHelper.ToJson(actorStartGame)); //排序 var startTime = DateTime.Now; foreach (var _gamer in gamers) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); //排序 handCardsComponent.Sort(); handCardsComponent.GrabCard = handCardsComponent.GetAll()[handCardsComponent.GetAll().Count - 1]; //设置玩家在线开始时间 _gamer.StartTime = startTime; //await DBCommonUtil.RecordGamerTime(startTime, true, _gamer.UserID); } foreach (var _gamer in room.GetAll()) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); List <MahjongInfo> cards = handCardsComponent.GetAll(); if (handCardsComponent.IsBanker) { if (Logic_NJMJ.getInstance().isHuPai(cards)) { //ToDo 胡牌 Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; _gamer.IsCanHu = true; canOperation.OperationType = 2; room.GamerBroadcast(_gamer, canOperation); _gamer.isGangFaWanPai = true; } } else { //检查听牌 List <MahjongInfo> checkTingPaiList = Logic_NJMJ.getInstance().checkTingPaiList(cards); if (checkTingPaiList.Count > 0) { Log.Info($"{_gamer.UserID}听牌:"); _gamer.isFaWanPaiTingPai = true; } } } //等客户端掷骰子 //是否超时 await Game.Scene.GetComponent <TimerComponent>().WaitAsync(10 * 1000); room.StartTime(); //扣服务费 if (!room.IsFriendRoom) { //不要动画 GameHelp.CostServiceCharge(room, false); } } } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
/// <summary> /// 其他人碰刚 /// </summary> /// <param name="type"></param> /// <param name="mahjongInfo"></param> public void SetOtherPeng(int type, MahjongInfo mahjongInfo) { GameObject obj = null; int temp = 0; if (type == 0) { if (Index == 2) { obj = CommonUtil.getGameObjByBundle("Item_Peng_Card"); } else { obj = CommonUtil.getGameObjByBundle("Item_Right_Peng_Card"); } temp = 3; } else if (type == 1) { if (Index == 2) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); } else { obj = CommonUtil.getGameObjByBundle("Item_Right_Gang_Card"); } temp = 3; } //暗杆 // else if (type == 4) else { if (Index == 2) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); } else { obj = CommonUtil.getGameObjByBundle("Item_Right_Gang_Card"); } temp = 4; } //设置碰杠位置 GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform); int count = this.pengObj.transform.childCount; if (Index == 1) { gameObject.transform.localPosition = new Vector3(0, (count - 1) * 115, 0); } else if (Index == 2) { gameObject.transform.localPosition = new Vector3((count - 1) * (-160.93f), 0, 0); } else { gameObject.transform.localPosition = new Vector3(count * (postionX) * 3.5f, count * (postionY) * 3.5f, 0); } if (type == 0) { pengDic.Add(mahjongInfo.weight, gameObject); } //显示出牌 string item1 = null; string item2 = null; string item3 = null; if (Index == 1) { item1 = "Item_Horizontal_Card"; item2 = "Image_Right_Card"; item3 = "right_" + mahjongInfo.weight; } else if (Index == 2) { item1 = "Item_Vertical_Card"; item2 = "Image_Top_Card"; item3 = "card_" + mahjongInfo.weight; } else if (Index == 3) { item1 = "Item_Horizontal_Card"; item2 = "Image_Left_Card"; item3 = "left_" + mahjongInfo.weight; } for (int i = 1; i < 3; i++) { gameObject.transform.Find("Item_" + i).GetComponent <Image>().sprite = CommonUtil.getSpriteByBundle(item2, item3); } num++; if (Index == 3) { for (int i = 0; i < temp; i++) { GameObject.Destroy(CardBottom.transform.GetChild(i).gameObject); } } else { for (int i = 0; i < temp; i++) { int childCount = this.CardBottom.transform.childCount; Log.Debug("销毁childCount:" + (childCount)); GameObject.DestroyImmediate(CardBottom.transform.GetChild(childCount - 1).gameObject); } Vector3 localPosition = this.CardBottom.transform.localPosition; float x = localPosition.x - postionX * 0.2f; float y = localPosition.y - postionY * 0.2f; this.CardBottom.transform.localPosition = new Vector3(x, y, localPosition.z); } }
public void SetOtherPengGang(int messageOperationType, MahjongInfo mahjong) { GameObject obj = null; if (Index == 2) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); } else { obj = CommonUtil.getGameObjByBundle("Item_Right_Gang_Card"); } //显示碰 GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform); GameObject lastPengObj = null; if (pengDic.TryGetValue(mahjong.weight, out lastPengObj)) { gameObject.transform.SetSiblingIndex(lastPengObj.transform.GetSiblingIndex()); gameObject.transform.localPosition = lastPengObj.transform.localPosition; GameObject.Destroy(lastPengObj); pengDic.Remove(mahjong.weight); } //显示出牌 string item1 = null; string item2 = null; string item3 = null; if (Index == 1) { item1 = "Item_Horizontal_Card"; item2 = "Image_Right_Card"; item3 = "right_" + mahjong.weight; } else if (Index == 2) { item1 = "Item_Vertical_Card"; item2 = "Image_Top_Card"; item3 = "card_" + mahjong.weight; } else if (Index == 3) { item1 = "Item_Horizontal_Card"; item2 = "Image_Left_Card"; item3 = "left_" + mahjong.weight; } for (int i = 1; i < 3; i++) { gameObject.transform.Find("Item_" + i).GetComponent <Image>().sprite = CommonUtil.getSpriteByBundle(item2, item3); } if (Index == 3) { // for (int i = 0; i < 1; i++) // { // GameObject.Destroy(CardBottom.transform.GetChild(i).gameObject); // } } else { // for (int i = 0; i < 1; i++) // { // int childCount = this.CardBottom.transform.childCount; // GameObject.Destroy(CardBottom.transform.GetChild(childCount - 1 - i).gameObject); // } // // Vector3 localPosition = this.CardBottom.transform.localPosition; // float x = localPosition.x - postionX * 1f; // float y = localPosition.y - postionY * 1f; // // this.CardBottom.transform.localPosition = new Vector3(x, y, localPosition.z); } }
public void SetPeng(int type, MahjongInfo mahjong, long operatedUid) { GameObject obj = null; if (type == 0) { obj = CommonUtil.getGameObjByBundle("Item_Peng_Card"); //更新手牌 for (int i = 0; i < 2; i++) { int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong); this.RemoveCard(index); } } //明杠 else if (type == 1) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); //更新手牌 for (int i = 0; i < 3; i++) { int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong); this.RemoveCard(index); } } //暗杆 else if (type == 4) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); for (int i = 0; i < 4; i++) { int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong); this.RemoveCard(index); } } //碰刚 else if (type == 5) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); for (int i = 0; i < 1; i++) { int index = Logic_NJMJ.getInstance().GetIndex(this.handCards, mahjong); this.RemoveCard(index); } } UpdateCards(); //设置谁碰刚 UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); Log.Info("operatedUid:" + operatedUid); int gamerSeat = gamerComponent.Get(operatedUid).GetComponent <HandCardsComponent>().SeatIndex; int mySeat = SeatIndex; int offset = gamerSeat - mySeat; if (offset < 0) { offset += 4; } if (offset == 1) { offset = 3; } else if (offset == 3) { offset = 1; } Log.Info("offset:" + offset); //显示碰 GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform); for (int i = 1; i < 4; i++) { Image image = gameObject.transform.Find("Item_" + i).GetComponent <Image>(); //暗杠显示 if (type == 4) { if (i == 2) { image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_" + mahjong.weight); } else { image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_back"); } } else { if (i == offset) { image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_back"); } else { image.sprite = CommonUtil.getSpriteByBundle("Image_Top_Card", "card_" + mahjong.weight); } } } if (type == 0) { pengDic.Add(mahjong.weight, gameObject); } Vector3 localPosition = this.CardBottom.transform.localPosition; this.CardBottom.transform.localPosition = new Vector3(localPosition.x + (postionX) * 2f, localPosition.y + (postionY) * 2f, localPosition.z); }
public void PlayOtherCard(MahjongInfo mahjongInfo, GameObject currentItem) { try { //grabObj.SetActive(false); grabObj.transform.localScale = Vector3.zero; //显示出牌 //显示出牌 string item1 = null; string item2 = null; string item3 = null; if (Index == 1) { item1 = "Item_Horizontal_Card"; item2 = "Image_Right_Card"; item3 = "right_" + mahjongInfo.weight; } else if (Index == 2) { item1 = "Item_Vertical_Card"; item2 = "Image_Top_Card"; item3 = "card_" + mahjongInfo.weight; } else if (Index == 3) { item1 = "Item_Horizontal_Card"; item2 = "Image_Left_Card"; item3 = "left_" + mahjongInfo.weight; } GameObject obj = (GameObject)this.resourcesComponent.GetAsset($"{item1}.unity3d", item1); GameObject obj2 = (GameObject)this.resourcesComponent.GetAsset($"{item2}.unity3d", item2); this.currentPlayCardObj = GameObject.Instantiate(obj, this.cardDisplay.transform); this.currentPlayCardObj.GetComponent <Image>().sprite = obj2.Get <Sprite>(item3); this.currentPlayCardObj.layer = LayerMask.NameToLayer("UI"); currentPlayCardObj.name = item3; cardDisplayObjs.Add(this.currentPlayCardObj); if (Index == 1) { this.currentPlayCardObj.transform.SetAsFirstSibling(); int count = this.cardDisplayObjs.Count; // Log.Info("cardDisplayObjs:" + count); int x = -107; int y = -192; int i = count / 10; int i1 = count % 10; if (i1 == 0) { i1 = 10; i--; } this.currentPlayCardObj.transform.localPosition = new Vector3(-107 + (i * 53), 34 * (i1 - 1) - 192, 0); } currentItem = currentPlayCardObj; // Log.Info("别人出的牌:" + currentItem.name); ShowCard(mahjongInfo.weight); } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 抓牌 /// </summary> /// <param name="mahjong"></param> public async void GrabCard(MahjongInfo mahjong) { GameObject cardSprite = this.CreateCardSprite($"{Direction}_" + mahjong.weight, 0, 0); SetPosition(cardSprite, (handCards.Count) * postionX + 30, 0); //查询插入的index int index = -1; for (int i = 0; i < handCards.Count - 1; i++) { if (mahjong.m_weight < handCards[0].m_weight) { index = -1; break; } if (mahjong.m_weight >= handCards[handCards.Count - 1].m_weight) { index = handCards.Count - 1; break; } MahjongInfo mahjongInfo1 = this.handCards[i]; MahjongInfo mahjongInfo2 = this.handCards[i + 1]; if (mahjongInfo1.m_weight <= mahjong.m_weight && mahjongInfo2.m_weight > mahjong.m_weight) { index = i; break; } } index++; handCards.Insert(index, mahjong); ItemCards.Insert(index, cardSprite); //大于index的item本身的index需要加1 for (int i = 0; i < ItemCards.Count; i++) { if (i > index) { ItemCards[i].GetComponent <ItemCardScipt>().index = i; } } //设置item cardSprite.GetComponent <ItemCardScipt>().weight = mahjong.weight; cardSprite.GetComponent <ItemCardScipt>().index = index; //添加点击事件 Button cardBtn = cardSprite.GetComponent <Button>(); cardBtn.onClick.RemoveAllListeners(); // cardBtn.onClick.Add(() => // { // if (IsSelect) // { // // } // else // { // IsSelect = true; // Vector3 localPosition = this._rectTransform.localPosition; // this._rectTransform.localPosition = new Vector3(localPosition.x, localPosition.y + 20, localPosition.z); // } // }) grabIndex = index; //第4张显示门清提示 if (playCards.Count == 3) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); UIRoomComponent uiRoomComponent = uiRoom.GetComponent <UIRoomComponent>(); uiRoomComponent.tip.SetActive(true); uiRoomComponent.tip.GetComponentInChildren <Image>().sprite = CommonUtil.getSpriteByBundle("Image_Desk_Card", "menqing_tip"); await ETModel.Game.Scene.GetComponent <TimerComponent>().WaitAsync(3000); if (this.IsDisposed) { return; } uiRoomComponent?.tip?.SetActive(false); } }
public void StartDealCardAnim(bool isSelf) { dealObjs.Clear(); int myCardCount = myCard.Count; int temp = 0; int x = 0; int y = 0; temp = myCardCount >= 4? 4 : myCardCount; for (int i = 0; i < temp; i++) { MahjongInfo mahjongInfo = myCard[i]; GameObject ItemCard = null; if (Index == 0) { string cardName = $"{Direction}_{mahjongInfo.weight}"; ItemCard = this.CreateSprite(cardName); x = 0; y = 90; SetPosition(ItemCard, dealNum * postionX, y); } else if (Index == 1) { string cardName = $"{Direction}_back1"; ItemCard = this.CreateSprite(cardName); ItemCard.transform.SetAsFirstSibling(); x = -78; y = 0; SetPosition(ItemCard, x, -420 - (dealNum * postionY)); } else if (Index == 2) { string cardName = $"{Direction}_back1"; ItemCard = this.CreateSprite(cardName); x = 0; y = -90; SetPosition(ItemCard, 563 - (dealNum * (postionX + 1)), y); } else if (Index == 3) { string cardName = $"{Direction}_back1"; ItemCard = this.CreateSprite(cardName); x = 78; y = 0; SetPosition(ItemCard, x, dealNum * postionY); } dealObjs.Add(ItemCard); dealNum++; } foreach (var gameObject in dealObjs) { Vector3 localPosition = gameObject.transform.localPosition; gameObject.GetComponent <RectTransform>().DOAnchorPos(new Vector2(localPosition.x - x, localPosition.y - y), 0.4f, false).OnComplete(() => { // gameObject.transform.localPosition = localPosition; // DeleteAllItem(gameObject); }); } myCard.RemoveRange(0, temp); }
public void SetOtherPengGang(int messageOperationType, MahjongInfo mahjong, long operatedUid, long uid) { GameObject obj = null; if (Index == 2) { obj = CommonUtil.getGameObjByBundle("Item_Gang_Card"); } else { obj = CommonUtil.getGameObjByBundle("Item_Right_Gang_Card"); } //显示碰 GameObject gameObject = GameObject.Instantiate(obj, this.pengObj.transform); GameObject lastPengObj = null; if (pengDic.TryGetValue(mahjong.weight, out lastPengObj)) { gameObject.transform.SetSiblingIndex(lastPengObj.transform.GetSiblingIndex()); gameObject.transform.localPosition = lastPengObj.transform.localPosition; GameObject.Destroy(lastPengObj); pengDic.Remove(mahjong.weight); } //显示出牌 string item1 = null; string item2 = null; string item3 = null; string itemBack = null; if (Index == 1) { item1 = "Item_Horizontal_Card"; item2 = "Image_Right_Card"; item3 = "right_" + mahjong.weight; itemBack = "right_back"; } else if (Index == 2) { item1 = "Item_Vertical_Card"; item2 = "Image_Top_Card"; item3 = "card_" + mahjong.weight; itemBack = "card_back"; } else if (Index == 3) { item1 = "Item_Horizontal_Card"; item2 = "Image_Left_Card"; item3 = "left_" + mahjong.weight; itemBack = "left_back"; } UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); int gamerSeat = gamerComponent.GetGamerSeat(operatedUid); int mySeat = gamerComponent.GetGamerSeat(uid); int offset = gamerSeat - mySeat; if (offset < 0) { offset += 4; } if (Index == 1) { if (offset == 1) { offset = 3; } else if (offset == 3) { offset = 1; } } else if (Index == 2) { } else if (Index == 3) { } for (int i = 1; i < 4; i++) { Image image = gameObject.transform.Find("Item_" + i).GetComponent <Image>(); if (i == offset) { image.sprite = CommonUtil.getSpriteByBundle(item2, itemBack); } else { image.sprite = CommonUtil.getSpriteByBundle(item2, item3); } } if (Index == 3) { // for (int i = 0; i < 1; i++) // { // GameObject.Destroy(CardBottom.transform.GetChild(i).gameObject); // } } else { // for (int i = 0; i < 1; i++) // { // int childCount = this.CardBottom.transform.childCount; // GameObject.Destroy(CardBottom.transform.GetChild(childCount - 1 - i).gameObject); // } // // Vector3 localPosition = this.CardBottom.transform.localPosition; // float x = localPosition.x - postionX * 1f; // float y = localPosition.y - postionY * 1f; // // this.CardBottom.transform.localPosition = new Vector3(x, y, localPosition.z); } }