/// <summary> /// 发牌(生成牌) /// </summary> /// <param name="toSeatPos"></param> /// <param name="poker"></param> /// <param name="isPlayer"></param> /// <param name="isSort"></param> /// <returns></returns> public PokerCtrl DrawPoker(int toSeatPos, Poker poker, bool isPlayer, bool isSort) { if (isPlayer && poker.color == 0) { AppDebug.ThrowError("生成了一张空牌 1"); } PokerCtrl ctrl = SpawnPoker(toSeatPos, poker, (isPlayer && (RoomPaoDeKuaiProxy.Instance.CurrentRoom.Status != RoomEntity.RoomStatus.Replay)) ? "PlayerHand" : "Hand"); if (!m_DicHand.ContainsKey(toSeatPos)) { m_DicHand.Add(toSeatPos, new List <PokerCtrl>()); } m_DicHand[toSeatPos].Add(ctrl); //if (isSort) //{ // Sort(m_DicHand[toSeatPos], RoomMaJiangProxy.Instance.GetSeatBySeatId(toSeatPos).UniversalList); //} if (isPlayer && (ctrl.Poker == null || ctrl.Poker.color == 0)) { AppDebug.ThrowError("生成了一张空牌 2"); } return(ctrl); }
//摸牌 public MaJiangCtrl_PaiJiu DrawMaJiang(int toSeatPos, Poker poker /*, bool isInitPoker, bool isLast = false*/) { if (m_ListWall == null || m_ListWall.Count <= 0) { AppDebug.ThrowError("摸的牌墙木有牌了阿!!!!"); return(null); } //MaJiangCtrl_PaiJiu majiang = null; MaJiangCtrl_PaiJiu ctrl = SpawnMaJiang(toSeatPos, poker, "Hand"); //ctrl.transform.SetParent(majiang.transform.parent); //ctrl.transform.position = majiang.transform.position; //ctrl.transform.rotation = majiang.transform.rotation; //m_WallPool.Despawn(majiang.transform); if (!m_DicHand.ContainsKey(toSeatPos)) { m_DicHand.Add(toSeatPos, new List <MaJiangCtrl_PaiJiu>()); } m_DicHand[toSeatPos].Add(ctrl); //--OverplusWallCount; //m_ListWall[0].transform.GetComponent<MeshRenderer>().enabled = false; PushMaJiangToPool(m_ListWall[0].gameObject); m_ListWall.RemoveAt(0); return(ctrl); }
/// <summary> /// 打牌 /// </summary> /// <returns></returns> public MaJiangCtrl PlayMaJiang(int seatPos, Poker poker, bool isReplay = false) { //从手牌里找牌 MaJiangCtrl majiang = null; if (m_DicHand.ContainsKey(seatPos)) { List <MaJiangCtrl> lst = m_DicHand[seatPos]; if (poker.color == 0) { AppDebug.ThrowError("生成了一张空牌 3:" + poker.ToLog()); } for (int i = 0; i < lst.Count; ++i) { if (lst[i].Poker.index == poker.index) { majiang = lst[i]; lst.RemoveAt(i); break; } } Sort(lst, RoomMaJiangProxy.Instance.GetSeatBySeatId(seatPos).UniversalList); } if (majiang == null) { string str = string.Format("没找到要打的牌!!!!!!{0}", poker.ToString("{0}_{1}_{2}_{3}")); AppDebug.ThrowError(str); } MaJiangCtrl ctrl = SpawnMaJiang(seatPos, poker, "Table"); if (majiang != null) { ctrl.transform.position = majiang.transform.position; ctrl.transform.rotation = majiang.transform.rotation; DespawnMaJiang(majiang); } if (!m_DicTable.ContainsKey(seatPos)) { m_DicTable.Add(seatPos, new List <MaJiangCtrl>()); } m_DicTable[seatPos].Add(ctrl); if (ctrl.Poker == null || ctrl.Poker.color == 0) { AppDebug.ThrowError("生成了一张空牌"); } return(ctrl); }
/// <summary> /// 摸牌动作(替换牌) /// </summary> /// <param name="fromSeatIndex">从哪摸</param> /// <param name="toSeatPos">摸到哪</param> /// <param name="poker">摸啥牌</param> /// <returns></returns> public PokerCtrl DrawPoker(int toSeatPos, PokerCtrl poker, bool isPlayer) { if (isPlayer && poker == null) { AppDebug.ThrowError("摸牌动作是一张空牌"); } PokerCtrl pokerInWall = null; pokerInWall = m_ListWall[0]; m_ListWall.Remove(pokerInWall); poker.transform.SetParent(pokerInWall.transform.parent); poker.transform.position = pokerInWall.transform.position; poker.transform.rotation = pokerInWall.transform.rotation; DespawnPoker(pokerInWall); return(poker); }
private void ClearPokerList(List <MaJiangCtrl_JuYou> lst) { MaJiangCtrl_JuYou majiang = null; for (int i = lst.Count - 1; i >= 0; --i) { majiang = lst[i]; lst.Remove(majiang); if (majiang != null) { m_WallPool.Despawn(majiang.transform); } else { AppDebug.ThrowError("没找到要丢弃的牌!!!!!!" + lst[i].ToString()); } } }
//弃牌 由座位一个一个弃牌 public MaJiangCtrl_PaiJiu ClearHandPoker(int seatPos, Poker poker) { List <MaJiangCtrl_PaiJiu> lst = m_DicHand[seatPos]; //从手牌里找牌 MaJiangCtrl_PaiJiu majiang = null; for (int i = 0; i < lst.Count; ++i) { if (lst[i].Poker.size == poker.size && lst[i].Poker.type == poker.type) { majiang = lst[i]; lst.Remove(lst[i]); //lst.RemoveAt(i); break; } } if (majiang == null) { AppDebug.ThrowError("没找到要打的牌!!!!!!" + poker.ToString()); } MaJiangCtrl_PaiJiu ctrl = SpawnMaJiang(seatPos, poker, "Table"); if (majiang != null) { ctrl.transform.position = majiang.transform.position; ctrl.transform.rotation = majiang.transform.rotation; PushMaJiangToPool(majiang.gameObject);//删除 //m_WallPool.Despawn(majiang.transform);//删除 } //把牌放桌面上 if (!m_DicTable.ContainsKey(seatPos)) { m_DicTable.Add(seatPos, new List <MaJiangCtrl_PaiJiu>()); } m_DicTable[seatPos].Add(ctrl); return(ctrl); }
/// <summary> /// 生成 /// </summary> /// <param name="prefabName"></param> public Transform Spawn(string prefabName) { if (!m_Pool.prefabPools.ContainsKey(prefabName)) { GameObject go = UIViewManager.Instance.LoadItem(prefabName); if (go == null) { AppDebug.ThrowError("没有该预制体:" + prefabName); } Transform prefab = go.transform; PrefabPool pool = new PrefabPool(prefab); pool.PreloadAmount = 5; pool.IsCullDespawned = true; pool.CullAbove = 20; pool.CullDelay = 20; pool.CullMaxPerPass = 1; m_Pool.CreatePrefabPool(pool); } return(m_Pool.Spawn(prefabName)); }
/// <summary> /// 丢弃手牌 /// </summary> /// <param name="seatIndex"></param> public MaJiangCtrl_JuYou ClearHandPoker(int seatIndex, Poker poker) { List <MaJiangCtrl_JuYou> lst = m_DicHand[seatIndex]; //从手牌里找牌 MaJiangCtrl_JuYou majiang = null; for (int i = 0; i < lst.Count; ++i) { if (lst[i].Poker.index == poker.index) { majiang = lst[i]; lst.Remove(lst[i]); //lst.RemoveAt(i); break; } } if (majiang == null) { AppDebug.ThrowError("没找到要打的牌!!!!!!" + poker.ToString()); } MaJiangCtrl_JuYou ctrl = SpawnMaJiang(seatIndex, poker, "Table"); if (majiang != null) { ctrl.transform.position = majiang.transform.position; ctrl.transform.rotation = majiang.transform.rotation; m_WallPool.Despawn(majiang.transform);//删除 } //把牌放桌面上 if (!m_DicTable.ContainsKey(seatIndex)) { m_DicTable.Add(seatIndex, new List <MaJiangCtrl_JuYou>()); } m_DicTable[seatIndex].Add(ctrl); return(ctrl); }
public void SetPos(int playerSeatId, int seatCount) { int index = playerSeatId - 1; if (index < 0) { AppDebug.ThrowError("座位Id是0"); index = 0; } if (seatCount == 2) { if (index == 1) { index = 2; } } for (int i = 0; i < m_Pos.Length; ++i) { m_Pos[i].gameObject.SetActive(index == i); } gameObject.SetParent(m_Pos[index]); }
public void SetPos(int seatId, Action onComplete) { int index = seatId - 1; if (index < 0) { AppDebug.ThrowError("座位Id是0"); index = 0; } for (int i = 0; i < m_Pos.Length; ++i) { m_Pos[i].gameObject.SetActive(index == i); } transform.SetParent(m_Pos[index]); transform.DOLocalMove(Vector3.zero, 1f).SetEase(Ease.Linear).OnComplete(() => { if (onComplete != null) { onComplete(); } }); transform.DOLocalRotate(Vector3.zero, 1f).SetEase(Ease.Linear); }
/// <summary> /// 摸牌 /// </summary> /// <param name="fromSeatIndex">从哪摸</param> /// <param name="toSeatIndex">摸到哪</param> /// <param name="poker">摸啥牌</param> /// <returns></returns> public MaJiangCtrl_JuYou DrawMaJiang(int toSeatIndex, Poker poker) { if (CurrentWallIndex >= m_ListWall.Count) { CurrentWallIndex = 0; } if (m_ListWall == null || m_ListWall.Count <= CurrentWallIndex) { AppDebug.ThrowError("摸的牌墙木有牌了阿!!!!"); return(null); } MaJiangCtrl_JuYou majiang = null; //MaJiangCtrl majiang = null; majiang = m_ListWall[CurrentWallIndex++]; MaJiangCtrl_JuYou ctrl = SpawnMaJiang(toSeatIndex, poker, toSeatIndex == 0? "PlayerHand" : "Hand"); ctrl.transform.SetParent(majiang.transform.parent); ctrl.transform.position = majiang.transform.position; ctrl.transform.rotation = majiang.transform.rotation; //m_ListWall.Remove(majiang); m_WallPool.Despawn(majiang.transform); if (!m_DicHand.ContainsKey(toSeatIndex)) { m_DicHand.Add(toSeatIndex, new List <MaJiangCtrl_JuYou>()); } m_DicHand[toSeatIndex].Add(ctrl); --OverplusWallCount; return(ctrl); }
/// <summary> /// 吃碰杠 /// </summary> public Combination3D Operate(int seatPos, OperatorType operateId, int subTypeId, List <Poker> pokers) { List <MaJiangCtrl> lst = new List <MaJiangCtrl>(); Combination3D combination = null; if (operateId == OperatorType.Gang) { if (m_DicPeng.ContainsKey(seatPos)) { List <Combination3D> usedList = m_DicPeng[seatPos]; for (int i = 0; i < usedList.Count; ++i) { if (usedList[i].OperatorType == OperatorType.Peng || usedList[i].OperatorType == OperatorType.Kou) { for (int j = 0; j < pokers.Count; ++j) { if (usedList[i].PokerList[0].Poker.index == pokers[j].index) { combination = usedList[i]; for (int k = 0; k < combination.PokerList.Count; ++k) { lst.Add(combination.PokerList[k]); } usedList.Remove(combination); break; } } } } } } List <MaJiangCtrl> handList = m_DicHand[seatPos]; Dictionary <int, List <MaJiangCtrl> > deskDic = m_DicTable; for (int i = 0; i < pokers.Count; ++i) { foreach (var pair in deskDic) { for (int j = 0; j < pair.Value.Count; ++j) { if (pair.Value[j].Poker.index == pokers[i].index) { lst.Add(pair.Value[j]); pair.Value.RemoveAt(j); break; } } } foreach (var pair in m_DicHand) { if (pair.Value == null) { continue; } for (int j = 0; j < pair.Value.Count; ++j) { if (pair.Value[j].Poker.index == pokers[i].index) { lst.Add(pair.Value[j]); pair.Value.RemoveAt(j); break; } } } } if (operateId != OperatorType.Gang) { Sort(handList, RoomMaJiangProxy.Instance.GetSeatBySeatId(seatPos).UniversalList); } if (!m_DicPeng.ContainsKey(seatPos)) { m_DicPeng.Add(seatPos, new List <Combination3D>()); } if (lst.Count != pokers.Count) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("客户端找到牌的数量:{0},有", lst.Count); for (int i = 0; i < lst.Count; ++i) { sb.Append(lst[i].Poker.ToString(true, true)); sb.Append(" "); } sb.AppendFormat(",服务器的数量:{0},有", pokers.Count); for (int i = 0; i < pokers.Count; ++i) { sb.Append(pokers[i].ToString(true, true)); sb.Append(" "); } sb.AppendLine(); sb.Append("客户端所有的手牌数据:"); SeatEntity seat = RoomMaJiangProxy.Instance.GetSeatBySeatId(seatPos); if (seat != null) { for (int i = 0; i < seat.PokerList.Count; ++i) { sb.Append(seat.PokerList[i].ToString(true, true)); sb.Append(" "); } sb.AppendLine(); sb.Append("客户端所有的模型:"); } for (int i = 0; i < handList.Count; ++i) { sb.Append(handList[i].Poker.ToString(true, true)); sb.Append(" "); } AppDebug.ThrowError(sb.ToString()); } List <MaJiangCtrl> newList = new List <MaJiangCtrl>(); for (int i = 0; i < pokers.Count; ++i) { MaJiangCtrl ctrl = SpawnMaJiang(seatPos, pokers[i], "Table"); if (pokers[i].pos != seatPos && (operateId == OperatorType.Chi || operateId == OperatorType.ChiTing)) { ctrl.isGray = true; } if (operateId == OperatorType.LiangXi) { ctrl.isGray = true; } if (lst.Count == pokers.Count) { ctrl.transform.position = lst[i].transform.position; ctrl.transform.rotation = lst[i].transform.rotation; } newList.Add(ctrl); } if (combination == null) { combination = new Combination3D((int)operateId, subTypeId, newList); } else { combination.BuGang(newList); } for (int i = 0; i < lst.Count; ++i) { DespawnMaJiang(lst[i]); } m_DicPeng[seatPos].Add(combination); return(combination); }
/// <summary> /// 摸牌 /// </summary> /// <param name="fromSeatIndex">从哪摸</param> /// <param name="toSeatPos">摸到哪</param> /// <param name="poker">摸啥牌</param> /// <returns></returns> public MaJiangCtrl DrawMaJiang(int toSeatPos, Poker poker, bool isPlayer, bool isLast, bool isSort) { if (isPlayer && poker.color == 0) { AppDebug.ThrowError("生成了一张空牌 1:" + poker.ToLog()); } MaJiangCtrl majiang = null; if (isLast) { #if IS_LEPING MaJiangCtrl temp = m_ListWall[34]; if (m_LuckPoker != null) { m_LuckPoker.transform.SetParent(temp.transform.parent); m_LuckPoker.transform.position = temp.transform.position; m_LuckPoker.transform.localEulerAngles = temp.transform.localEulerAngles + new Vector3(0f, 0f, 180f); m_LuckPoker.transform.localScale = temp.transform.localScale; } m_ListWall.Remove(temp); m_ListWallInverse.Remove(temp); DespawnMaJiang(temp); majiang = m_ListWall[34]; #elif IS_TAILAI majiang = m_ListWallInverse[12]; #else majiang = m_ListWallInverse[0]; #endif } else { majiang = m_ListWall[0]; } m_ListWall.Remove(majiang); m_ListWallInverse.Remove(majiang); MaJiangCtrl ctrl = SpawnMaJiang(toSeatPos, poker, ((isPlayer && RoomMaJiangProxy.Instance.CurrentRoom.isReplay) ? "PlayerHand" : "Hand")); ctrl.transform.SetParent(majiang.transform.parent); ctrl.transform.position = majiang.transform.position; ctrl.transform.rotation = majiang.transform.rotation; DespawnMaJiang(majiang); if (!m_DicHand.ContainsKey(toSeatPos)) { m_DicHand.Add(toSeatPos, new List <MaJiangCtrl>()); } m_DicHand[toSeatPos].Add(ctrl); SeatEntity seat = RoomMaJiangProxy.Instance.GetSeatBySeatId(toSeatPos); if (seat != null) { if (seat.LackColor != 0) { if (ctrl.Poker.color == seat.LackColor) { ctrl.isGray = true; } } } if (isSort) { Sort(m_DicHand[toSeatPos], RoomMaJiangProxy.Instance.GetSeatBySeatId(toSeatPos).UniversalList); } if (isPlayer && (ctrl.Poker == null || ctrl.Poker.color == 0)) { AppDebug.ThrowError("生成了一张空牌 2:" + poker.ToLog()); } return(ctrl); }
/// <summary> /// 显示吃碰杠胡 /// </summary> /// <param name="pbGroup"></param> public void ShowOperate(List <PokerCombinationEntity> pbGroup) { if (pbGroup == null) { throw new Exception("服务器询问吃碰杠的列表是空的"); } RoomMaJiangProxy.Instance.AskPokerGroup = pbGroup; bool canHu = false; bool isZiMo = false; List <Poker> lstPeng = null; List <List <Poker> > lstGangs = null; List <List <Poker> > lstChi = null; List <List <Poker> > lstZhiDui = null; List <List <Poker> > lstChiTing = null; List <Poker> lstPengTing = null; List <List <Poker> > lstLiangXi = null; bool isMustZhiDui = false; bool canDingZhang = false; bool canDingJiang = false; List <List <Poker> > lstKou = null; List <Poker> lstBuXi = null; bool canPiaoTing = false; bool isPao = false; bool isJiao = false; bool isMingTi = false; for (int i = 0; i < pbGroup.Count; ++i) { OperatorType type = pbGroup[i].CombinationType; Debug.Log("客户端可以" + type); Poker poker = null; if (pbGroup[i].PokerList.Count > 0) { poker = pbGroup[i].PokerList[0]; Debug.Log(poker.ToString("{0}_{1}_{2}")); } switch (type) { case OperatorType.Peng: lstPeng = RoomMaJiangProxy.Instance.GetPeng(poker); if (lstPeng == null || lstPeng.Count == 0) { AppDebug.ThrowError("没检测出来可以碰"); } break; case OperatorType.Gang: if (poker == null) { lstGangs = RoomMaJiangProxy.Instance.GetAnGang(); List <Poker> lstBuGangs = RoomMaJiangProxy.Instance.GetBuGang(); for (int j = 0; j < lstBuGangs.Count; ++j) { lstGangs.Add(new List <Poker> { lstBuGangs[j] }); } } else { lstGangs = RoomMaJiangProxy.Instance.GetMingGang(poker); } if (lstGangs == null || lstGangs.Count == 0) { AppDebug.ThrowError("没检测出来可以杠,服务器发送的poker是" + (poker == null ? "空的" : poker.ToString())); } break; case OperatorType.Chi: lstChi = RoomMaJiangProxy.Instance.GetChi(poker); if (lstChi == null || lstChi.Count == 0) { AppDebug.ThrowError("没检测出来可以吃"); } break; case OperatorType.Hu: canHu = true; isZiMo = pbGroup[i].SubTypeId == 2; break; case OperatorType.ZhiDui: lstZhiDui = RoomMaJiangProxy.Instance.GetZhiDui(out isMustZhiDui); break; case OperatorType.ChiTing: lstChiTing = RoomMaJiangProxy.Instance.GetChiTing(poker); if (lstChiTing == null || lstChiTing.Count == 0) { AppDebug.ThrowError("没检测出来可以吃听"); } break; case OperatorType.PengTing: lstPengTing = RoomMaJiangProxy.Instance.GetPengTing(poker); if (lstPengTing == null || lstPengTing.Count == 0) { AppDebug.ThrowError("没检测出来可以碰听"); } break; case OperatorType.LiangXi: lstLiangXi = RoomMaJiangProxy.Instance.GetLiangXi(); if (lstLiangXi == null || lstLiangXi.Count == 0) { AppDebug.ThrowError("没检测出来可以亮喜"); } break; case OperatorType.DingZhang: canDingZhang = true; break; case OperatorType.FengGang: List <Poker> lstFengGang = RoomMaJiangProxy.Instance.GetFengGang(); if (lstFengGang != null) { if (lstGangs == null) { lstGangs = new List <List <Poker> >(); } lstGangs.Add(lstFengGang); } break; case OperatorType.DingJiang: Poker dingjiang = RoomMaJiangProxy.Instance.GetDingJiang(poker); if (dingjiang != null) { canDingJiang = true; } break; case OperatorType.Kou: lstKou = RoomMaJiangProxy.Instance.GetKou(); break; case OperatorType.BuXi: lstBuXi = RoomMaJiangProxy.Instance.GetBuXi(); if (lstBuXi == null || lstBuXi.Count == 0) { AppDebug.ThrowError("没检测出来可以补喜"); } break; case OperatorType.PiaoTing: canPiaoTing = true; break; case OperatorType.Pao: isPao = true; break; case OperatorType.Jiao: isJiao = true; break; case OperatorType.MingTi: isMingTi = true; break; } } if (UIViewManager.Instance.CurrentUIScene is UISceneMaJiangView) { if (lstZhiDui != null) { UIItemOperator.Instance.ShowZhiDui(lstZhiDui, !isMustZhiDui); } else { UIItemOperator.Instance.Show(lstChi, lstPeng, lstGangs, canHu, isZiMo, lstChiTing, lstPengTing, lstLiangXi, canDingZhang, canDingJiang, lstKou, lstBuXi, canPiaoTing, isPao, isJiao, isMingTi); } } }