//发起行为,出牌碰、吃、杠等 public void CreateAction(MjActionType type, MaJangModel mjm = null, MaJangModel otherMjm = null) { UserMjAction uma = new UserMjAction(); uma.type = (int)type; if (type != MjActionType.Guo) { if (type == MjActionType.AGang) { uma.mj = sameMj[0].mj; } else { uma.mj = mjm.mj; } } if (otherMjm) { uma.mjOther = otherMjm.mj; } if (statu == 1) { uma.isTing = true; } if (type == MjActionType.OutMj) { OutMj(mjm); } SocketClient.Instance.AddSendMessageQueue(new C2GMessage() { msgid = MessageId.C2G_UserMjAction, UserMjAction = uma }); isTurn = false; }
void Update() { SetSelfCameraSize(); if (InputUtils.OnReleased()) { Ray ray = selfCamera.ScreenPointToRay(InputUtils.GetTouchPosition()); RaycastHit rh; if (Physics.Raycast(ray, out rh)) { MaJangModel mjmTemp = rh.collider.GetComponent <MaJangModel>(); if (mjmTemp && mjmTemp.gameObject.layer == ConstantUtils.mjLayer) { if (lastSelectMj && lastSelectMj.gameObject.layer == ConstantUtils.mjLayer && !mjmTemp.Equals(lastSelectMj)) { lastSelectMj.Select(false); } mjmTemp.Select(true); lastSelectMj = mjmTemp; } else { if (lastSelectMj) { lastSelectMj.Select(false); lastSelectMj = null; } } } } }
public void Chi(List <Mj> mjs = null) { if (mjs == null) { if (chiMj.Count > 3)//多组吃 { EnableChiPanel(true); } else { MaJangModel mjm1 = null, mjm2; mjm1 = chiMj.Find((m) => { return(m != MaJangPage.Instance.lastOutMj); }); mjm2 = chiMj.Find((m) => { return(m != MaJangPage.Instance.lastOutMj && m != mjm1); }); CreateAction(MjActionType.Chi, mjm1, mjm2); //0男1女 PlaySound(sex == 0 ? AudioManager.AudioSoundType.boychi : AudioManager.AudioSoundType.girlchi); } } else { LightMj(GetLightMj(mjs)); ActionAnimation(MjActionType.Chi); PlaySound(sex == 0 ? AudioManager.AudioSoundType.boychi : AudioManager.AudioSoundType.girlchi); } }
//巴杠专用 void LightMj(MaJangModel mjm) { if (isCurrentPlayer) { UIUtils.SetAllChildrenLayer(mjm.transform, ConstantUtils.modelLayer); } MaJangScene.Instance.SetOperator(seatNo); isFinishAction = true; LightAnGang(); for (int i = 0; i < lightMjList.Count; i++) { if (lightMjList[i][0].mjNo == lightMjList[i][1].mjNo && lightMjList[i][0].mjNo == mjm.mjNo) { mjm.transform.SetParent(lightParent); mjm.transform.localPosition = new Vector3(lightMjList[i][1].transform.localPosition.x, MaJangScene.mjSize.z); mjm.transform.localEulerAngles = Vector3.right * ConstantUtils.const90; handMjList.Remove(mjm); SortMj(); List <MaJangModel> tempMjm = new List <MaJangModel>(); tempMjm.AddRange(lightMjList[i]); tempMjm.Insert(1, mjm); lightMjList[i] = tempMjm.ToArray(); break; } } }
public void ChiTing(List <Mj> mjs = null) { if (mjs == null) { #region ...吃听处理 //if (chiMj.Count > 3) //{ // List<MaJangModel> mjms = new List<MaJangModel>(); // for (int i = chiMj.Count - 1; i >= 0; i -= 3) // { // mjms.Clear(); // mjms.AddRange(chiMj); // for (int j = i; j > i - 3; j--) // if (!chiMj[j].Equals(MaJangPage.Instance.lastOutMj)) // mjms.RemoveAt(j); // MaJangModel m = mjms.Find((mj) => // { // bool has = false; // foreach (Mj mTemp in tingOutList) // if (mj.mjNo == mTemp.type * 10 + mTemp.point) // { // has = true; // break; // } // return has; // }); // if (m == null) // { // mjms.RemoveAt(mjms.Count - 1); // chiMj.Clear(); // chiMj.AddRange(mjms); // } // } //} #endregion if (chiTingMj.Count > 3) { statu = 1; EnableChiPanel(false); } else { MaJangModel mjm1 = null, mjm2; mjm1 = chiTingMj.Find((m) => { return(m != MaJangPage.Instance.lastOutMj); }); mjm2 = chiTingMj.Find((m) => { return(m != MaJangPage.Instance.lastOutMj && m != mjm1); }); CreateAction(MjActionType.ChiTing, mjm1, mjm2); //0男1女 PlaySound(sex == 0 ? AudioManager.AudioSoundType.boyting : AudioManager.AudioSoundType.girlting); } } else { LightMj(GetLightMj(mjs)); ActionAnimation(MjActionType.ChiTing); PlaySound(sex == 0 ? AudioManager.AudioSoundType.boyting : AudioManager.AudioSoundType.girlting); } }
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; } }
/// <summary> /// 亮牌,吃碰杠钉 /// </summary> /// <param name="mjms"></param> /// <param name="isCover">是否为暗杠</param> public void LightMj(List <MaJangModel> mjms, bool isCover = false, bool isTing = true) { SortMj(mjms, false); MaJangScene.Instance.SetOperator(seatNo); float startPoint = lightMjList.Count * 3.5f * MaJangScene.mjSize.x;//3.5 = 3张牌 + 半张牌空隙 for (int i = 0; i < mjms.Count; i++) { MaJangModel mjmTemp = mjms[i]; mjmTemp.transform.SetParent(lightParent); if (mjms.Count == 4 && i == 1) { mjmTemp.transform.localPosition = new Vector3(startPoint, MaJangScene.mjSize.z); } else { mjmTemp.transform.localPosition = Vector3.right * startPoint; startPoint += MaJangScene.mjSize.x; } if (isCover) { mjmTemp.transform.localEulerAngles = Vector3.left * ConstantUtils.const90; } else { mjmTemp.transform.localEulerAngles = Vector3.right * ConstantUtils.const90; } UIUtils.SetAllChildrenLayer(mjmTemp.transform, ConstantUtils.modelLayer); handMjList.Remove(mjmTemp); } handParent.localPosition += Vector3.right * 2 * MaJangScene.mjSize.x; lightMjList.Add(mjms.ToArray()); SortMj(); if (isOutNewCard) { handMjList[handMjList.Count - 1].transform.localPosition = Vector3.right * (handParent.childCount - MaJangPage.mj_interval) * MaJangScene.mjSize.x; } if (lightMjList.Count > 1) { LightAnGang(); } if (!isCover) { MaJangPage.Instance.SetLastOutMj(); } if (isTing) { if (atTrusteeship && isCurrentPlayer) { TrusteeshipMethods(); } } }
//麻将移动动画 void MjMoveAnimation(int vacancyIndex) { int targetIndex = 0; MaJangModel lastMj = handMjList[handMjList.Count - 1]; if (isCurrentPlayer) { for (int i = 0; i < handMjList.Count - 1; i++) { if (lastMj.mj.type < handMjList[i].mj.type || (lastMj.mj.type == handMjList[i].mj.type && lastMj.mj.point < handMjList[i].mj.point)) { targetIndex = i; break; } else if (i == handMjList.Count - 2) { targetIndex = handMjList.Count - 1; } } } else { targetIndex = Random.Range(0, handMjList.Count - 1); } bool toLeft = targetIndex >= vacancyIndex; lastMj.Move(Vector3.right * targetIndex * MaJangScene.mjSize.x); for (int i = Mathf.Min(vacancyIndex, targetIndex); i < Mathf.Max(vacancyIndex, targetIndex); i++) { handMjList[i].Move(toLeft); } handMjList.Remove(lastMj); handMjList.Insert(targetIndex, lastMj); if (isCurrentPlayer && targetIndex != handMjList.Count - 1) { lastMj.transform.SetSiblingIndex(targetIndex); } }
public void Hu(bool isZiMo = false) { if (isZiMo) { PlaySound(sex == 0 ? AudioManager.AudioSoundType.boyzimo : AudioManager.AudioSoundType.girlzimo); PlaySound(AudioManager.AudioSoundType.mjaudiozimo); } else { PlaySound(sex == 0 ? AudioManager.AudioSoundType.boyhu : AudioManager.AudioSoundType.girlhu); PlaySound(AudioManager.AudioSoundType.mjaudiohu); MaJangModel mjmHu = MaJangPage.Instance.lastOutMj; mjmHu.transform.SetParent(handParent); handMjList.Add(mjmHu); mjmHu.transform.localEulerAngles = Vector3.right * 90; SortMj(null, false); mjmHu.transform.localPosition = Vector3.right * (handParent.childCount - MaJangPage.mj_interval) * MaJangScene.mjSize.x; } statu = 3; MaJangPage.Instance.timer.gameObject.SetActive(false); MaJangPage.Instance.RequestTrusteeship(false); MaJangPage.Instance.FinishAction(); Debug.Log(seatNo + "胡了"); }
public void Init(MaJangPlayer player) { mPlayer = player; if (itemName) { itemName.text = player.nickName.text; } if (score) { score.text = player.win.ToString(); } #region 吃 碰 杠 List <MaJangModel[]> altList = player.lightMjList; if (altList.Count > 0) { for (int i = 0; i < altList.Count; i++) { MaJangModel[] mjModel = altList[i]; GameObject mjAlt = Instantiate(altPrefab, horizontal); mjAlt.SetActive(true); for (int j = 0; j < mjAlt.transform.childCount; j++) { if (mjModel.Length > j) { mjAlt.transform.GetChild(j).GetComponent <MaJangResultMj>().Init(mjModel[j].mjNo.ToString()); } else { mjAlt.transform.GetChild(j).gameObject.SetActive(false); } } mjAlt.transform.SetParent(horizontal); } } #endregion #region 手牌 List <MaJangModel> handList = player.handMjList; int handCount = player.win > 0 ? handList.Count - 1 : handList.Count; for (int i = 0; i < handCount; i++) { MaJangResultMj mj = Instantiate(mjPrefab, handParent); mj.gameObject.SetActive(true); mj.Init(handList[i].mjNo.ToString()); mj.transform.SetParent(handParent); } handParent.gameObject.SetActive(false); handParent.GetComponent <HorizontalLayoutGroup>().enabled = false; handParent.GetComponent <HorizontalLayoutGroup>().enabled = true; handParent.SetParent(horizontal); if (player.win > 0) { MaJangModel last = player.handMjList[handList.Count - 1]; mjPrefab.Init(last.mjNo.ToString()); mjPrefab.transform.SetParent(horizontal); } else { mjPrefab.gameObject.SetActive(false); } #endregion gameObject.SetActive(true); horizontal.GetComponent <HorizontalLayoutGroup>().enabled = false; horizontal.GetComponent <HorizontalLayoutGroup>().enabled = true; SetTimeout.add(0.1f, () => { handParent.gameObject.SetActive(false); horizontal.gameObject.SetActive(false); handParent.gameObject.SetActive(true); horizontal.gameObject.SetActive(true); }); }
public int HasSame(MaJangModel mjm = null) { sameMj.Clear(); if (mjm)//检测是否存在点杠、碰 { for (int i = 0; i < handMjList.Count; i++) { if (handMjList[i].mjNo == mjm.mjNo) { sameMj.Add(handMjList[i]); } } if (sameMj.Count > 1 && mjm == MaJangPage.Instance.lastOutMj) { sameMj.Add(mjm); } else { sameMj.Clear(); } } else { List <MaJangModel> mjmTemp = new List <MaJangModel>(); for (int i = 0; i < handMjList.Count; i++)//检测是否存在暗杠 { MaJangModel mjmi = handMjList[i]; mjmTemp.Clear(); if (sameMj.Contains(mjmi)) { continue; } mjmTemp.Add(mjmi); for (int j = 0; j < handMjList.Count; j++) { MaJangModel mjmj = handMjList[j]; if (i == j || sameMj.Contains(mjmj)) { continue; } if (mjmi.mjNo == mjmj.mjNo) { mjmTemp.Add(mjmj); } } if (mjmTemp.Count == 4) { sameMj.AddRange(mjmTemp); } } for (int i = 0; i < lightMjList.Count; i++)//检测是否存在巴杠 { if (lightMjList[i][0].mjNo != lightMjList[i][1].mjNo) { continue; } for (int j = 0; j < handMjList.Count; j++) { if (lightMjList[i][0].mjNo == handMjList[j].mjNo) { sameMj.AddRange(lightMjList[i]); sameMj.Add(handMjList[j]); break; } } } } return(sameMj.Count); }
public int HasChi(List <Mj> mjs = null) { MaJangModel lastMjm = MaJangPage.Instance.lastOutMj; if (mjs == null) { chiMj.Clear(); MaJangModel hasSmall2 = null, hasSmall1 = null, hasLarge1 = null, hasLarge2 = null; for (int i = 0; i < handMjList.Count; i++) { if (handMjList[i].mjNo / 10 == lastMjm.mjNo / 10) { switch (handMjList[i].mjNo - lastMjm.mjNo) { case -2: hasSmall2 = handMjList[i]; break; case -1: hasSmall1 = handMjList[i]; break; case 1: hasLarge1 = handMjList[i]; break; case 2: hasLarge2 = handMjList[i]; break; } } } if (hasSmall2 && hasSmall1) { chiMj.Add(hasSmall2); chiMj.Add(lastMjm); chiMj.Add(hasSmall1); } if (hasSmall1 && hasLarge1) { chiMj.Add(hasSmall1); chiMj.Add(lastMjm); chiMj.Add(hasLarge1); } if (hasLarge1 && hasLarge2) { chiMj.Add(hasLarge1); chiMj.Add(lastMjm); chiMj.Add(hasLarge2); } } else { chiTingMj.Clear(); for (int i = 0; i < mjs.Count; i++) { int mjNo = mjs[i].type * 10 + mjs[i].point; if (mjNo == lastMjm.mjNo) { chiTingMj.Add(lastMjm); } else { chiTingMj.Add(handMjList.Find((m) => { return(m.mjNo == mjNo); })); } } } return(chiMj.Count); }
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; } } }