List <MaJangModel> GetLightMj(List <Mj> mjs) { List <MaJangModel> lightMjs = new List <MaJangModel>(); for (int i = 0; i < mjs.Count; i++) { Mj mj = mjs[i]; if (MaJangPage.Instance.lastOutMj && !lightMjs.Contains(MaJangPage.Instance.lastOutMj) && mj.type * 10 + mj.point == MaJangPage.Instance.lastOutMj.mjNo) { lightMjs.Add(MaJangPage.Instance.lastOutMj); } else { handMjList[i].Init(mjs[i], this); lightMjs.Add(handMjList[i]); } } if (lightMjs.Count < 4) { var lastMj = lightMjs[lightMjs.Count - 1]; lightMjs.RemoveAt(lightMjs.Count - 1); lightMjs.Insert(1, lastMj); } return(lightMjs); }
int columnMax = 6;//出牌堆每行最大牌数 2人玩法每行15张牌,起始位置x=-5.8 public void OutMj(MaJangModel mjm = null, Mj mj = null, bool playAnimation = true) { if (mjm || mj != null) { #region 打牌音效 //point // 点数 1- 9 //type // 类型 0万,1筒,2条 3中 //0男1女 if (mjm) { string soundString = (sex == 0 ? "boy" : "girl") + mjm.mj.type + mjm.mj.point; AudioManager.AudioSoundType audioType = GetSoundType(soundString); PlaySound(audioType); } else if (mj != null) { string soundString = (sex == 0 ? "boy" : "girl") + mj.type + mj.point; AudioManager.AudioSoundType audioType = GetSoundType(soundString); PlaySound(audioType); } #endregion if (!mjm) { mjm = handMjList[tingIcon.activeInHierarchy ? handMjList.Count - 1 : Random.Range(0, handMjList.Count)]; mjm.Init(mj, this); } int index = handMjList.IndexOf(mjm); int row = Mathf.CeilToInt((outParent.childCount + 1f) / columnMax) - 1; int column = outParent.childCount % columnMax; mjm.transform.SetParent(outParent); mjm.transform.localPosition = new Vector3(column * MaJangScene.mjSize.x, 0, -row * MaJangScene.mjSize.y); mjm.transform.localEulerAngles = Vector3.right * ConstantUtils.const90; StartCoroutine(ShowMj(mjm.mjNo.ToString()));//显示打出的牌 isOutNewCard = false; handMjList.Remove(mjm); MaJangPage.Instance.SetLastOutMj(mjm); PlaySound(AudioManager.AudioSoundType.mjoutcard); if (isCurrentPlayer) { UIUtils.SetAllChildrenLayer(mjm.transform, ConstantUtils.modelLayer); if (statu == 1) { for (int i = 0; i < handMjList.Count; i++) { handMjList[i].SetStatu(false); } statu = 2; } } if (playAnimation && index < handMjList.Count) { MjMoveAnimation(index); } isFinishAction = true; } }
public void Init(Mj mj, MaJangPlayer mjp = null) { this.mj = mj; this.mjp = mjp; if (mj != null) { mjNo = mj.type * 10 + mj.point; transform.GetChild(0).GetComponent <MeshRenderer>().material.mainTexture = BundleManager.Instance.GetSprite(mjNo.ToString(), MaJangPage.Instance.majangBundle).texture; } SetStatu(true); canSelect = true; }
/// <summary> /// 自动发牌 /// </summary> /// <param name="diceNum"></param> /// <returns></returns> IEnumerator AutoDeal(int playerCount) { int touchNum = 4, touchMoundCount = 3, touchCount = playerCount * (touchMoundCount + 1) + 1, currentTouchUserIndex = hostPos; MaJangPlayer mjp; Mj mj = null; bool isCurrentPlayer; for (int i = 0; i < touchCount; i++) { mjp = MaJangPage.Instance.GetPlayerFromSeatNo(currentTouchUserIndex); isCurrentPlayer = mjp == MaJangPage.Instance.currentPlayer; int group = i / playerCount; if (i < playerCount * touchMoundCount) { for (int j = 0; j < touchNum; j++) { if (isCurrentPlayer) { mj = mjp.mjList[group * touchNum + j]; } else { mj = null; } mjp.GetMj(mj); } mjp.isTurn = false; } else { if (isCurrentPlayer) { mj = mjp.mjList[touchNum * touchMoundCount + group - touchMoundCount]; } else { mj = null; } if (i == touchCount - 1) { if (isCurrentPlayer) { mjp.SortMj(); } mjp.GetMj(mj, true); SocketClient.Instance.AddSendMessageQueue(new C2GMessage() { msgid = MessageId.C2G_FaiPaiAllOk }); mjp.isTurn = true; } else { mjp.GetMj(mj); mjp.isTurn = false; } } currentTouchUserIndex++; if (currentTouchUserIndex > playerCount - 1) { currentTouchUserIndex -= playerCount; } yield return(new WaitForSecondsRealtime(0.1f)); } //如果操作菜单中有按钮处于显示状态,则说明可听、杠、胡 //foreach (Transform tf in MaJangPage.Instance.gameMenu.transform) // if (tf.gameObject.activeSelf) // { // MaJangPage.Instance.gameMenu.SetActive(true); // break; // } }
IEnumerator GetMjAc(Mj mj, bool isNewMj, bool isFenZhang, bool canHu, bool isXjxd) { MaJangPage.Instance.lastOutMj = null; MaJangPage.Instance.RefreshSurplusCount(); List <Transform> stackMaJongList = MaJangScene.Instance.stackMaJong; if (stackMaJongList.Count > 0) { int targetIndex = 0; if (isGang) { if (MaJangPage.Instance.gangCount % 2 == 0) { targetIndex = stackMaJongList.Count - 2; } else { targetIndex = stackMaJongList.Count - 1; } isGang = false; MaJangPage.Instance.gangCount++; } Transform maJong = this.transform; //如果有要出的牌且没有mj就取手牌最后一个 if (isCurrentPlayer && mj == null && isNewMj) { MaJangModel majangmodel = handMjList[handMjList.Count - 1]; maJong = majangmodel.transform; mj = majangmodel.mj; UIUtils.SetAllChildrenLayer(maJong, ConstantUtils.mjLayer); } else { maJong = stackMaJongList[targetIndex]; stackMaJongList.RemoveAt(targetIndex); MaJangModel mjm = maJong.GetComponent <MaJangModel>(); if (isCurrentPlayer) { mjm.Init(mj, this); UIUtils.SetAllChildrenLayer(maJong, ConstantUtils.mjLayer); } handMjList.Add(mjm); maJong.SetParent(handParent); maJong.localEulerAngles = Vector3.zero; } if (isNewMj) { SortMj(null, false); MaJangScene.Instance.SetOperator(seatNo); maJong.localPosition = Vector3.right * (handParent.childCount - MaJangPage.mj_interval) * MaJangScene.mjSize.x; if (isXjxd) { if (!isCurrentPlayer) { maJong.localEulerAngles = Vector3.right * ConstantUtils.const90; } yield return(new WaitForSecondsRealtime(1)); maJong.localEulerAngles = Vector3.zero; } if (isCurrentPlayer) { if (statu == 2) { if (canHu) { Hu(true); } else if (!isFenZhang) { StartCoroutine(DelayOutMj()); } } else if (statu == 0) { if (!isFenZhang) { if (atTrusteeship) { StartCoroutine(DelayOutMj()); MaJangPage.Instance.FinishAction(); } else { if (HasSame() > 3) { MaJangPage.Instance.EnableActionBtn(MaJangPage.Instance.btnGang, false); } isTurn = true; } } } } } else { maJong.localPosition = Vector3.right * (handParent.childCount - 1) * MaJangScene.mjSize.x; } } }
public void GetMj(Mj mj, bool isNewMj = false, bool isFenZhang = false, bool canHu = false, bool isXjxd = false) { MaJangPage.Instance.StartCoroutine(GetMjAc(mj, isNewMj, isFenZhang, canHu, isXjxd)); }