using System.Collections.Generic; using System.Linq; using GameMessage; namespace GameFix.Poker { /// /// 手牌组相关逻辑 /// public class CardGroup : CardBaseGroup { public CardGroup(IEnumerable cards, Deck deck) : base(cards, deck) { } /// /// 拆解牌组 /// public List Decompose() { List ret = new List(); var cardGroup = mDeck.CreateCardGroup(mCards); foreach (var helper in mCardStyleBaseHelpers) { var styleCards = helper.GetAllStyleCards(cardGroup, false); ret.AddRange(styleCards); cardGroup.RemoveCards(styleCards); } if (cardGroup.mCards.Count > 0) { // 还有未知牌型没有拆解完? (理论不存在) ret.Add(new CardGroupList(cardGroup.mCards)); } return ret; } /// /// 获取吃牌提示 /// public List GetEatTip(CardStyleInfo targetStyle) { List ret = new List(); if (targetStyle == null) { // 没有提供对方牌型,先判断自己手牌是否符合一种牌型可以一次性出完 var styleInfo = GetCardStyleInfo(); bool isCanOutImmediate = false; if (styleInfo.CardStyle != DataCardConst.CardStyle0) { var cardGroupList = new CardGroupList(mCards); cardGroupList.CardStyleInfo = styleInfo; ret.Add(cardGroupList); isCanOutImmediate = true; } if (!isCanOutImmediate) { foreach (var helper in mCardStyleBaseHelpers) { ret.AddRange(helper.GetAllEatTipGroup(this, null)); if (ret.Count > 0) break; } } } else { foreach (var helper in mCardStyleBaseHelpers) { if (mStyleComparer.Greater(helper.CardStyle, targetStyle.CardStyle)) { ret.AddRange(helper.GetAllEatTipGroup(this, targetStyle)); } } // 没找到再尝试有用癞子去匹配 if (ret.Count == 0 && mLZCards.Count > 0) { foreach (var helper in mCardStyleBaseHelpers) { if (mStyleComparer.Greater(helper.CardStyle, targetStyle.CardStyle)) { ret.AddRange(helper.GetAllEatTipGroupWithLZ(this, targetStyle)); } } } } // 牌类型赋值 foreach (var cardList in ret) { if (cardList.CardStyleInfo != null) continue; var group = mDeck.CreateCardGroup(cardList); cardList.CardStyleInfo = group.GetCardStyleInfo(); } return ret; } public List GetShunTip(CardStyleInfo targetStyle, byte[] tipHelpers) { List ret = new List(); for (int i = 0; i < tipHelpers.Length; i++) { var helper = GetHelper(tipHelpers[i]); var tipCardList = helper?.GetAllEatTipGroup(this, targetStyle); if (tipCardList != null && tipCardList.Count > 0) { ret.AddRange(tipCardList.OrderByDescending(x=>x.Count)); return ret; } } return ret; } public List GetEatTip(int styleId) { List ret = new List(); var helper = GetHelper(styleId); if (helper != null) { ret.AddRange(helper.GetAllEatTipGroup(this, null)); if (ret.Count == 0 && mLZCards.Count > 0) { ret.AddRange(helper.GetAllEatTipGroupWithLZ(this, null)); } } return ret; } /// /// 获取当前牌组得牌型 /// public CardStyleInfo GetCardStyleInfo() { if (this.mLZCards.Count > 0) { foreach (var helper in mCardStyleBaseHelpers) { if (helper.CheckStyleWithLZ(this, out var chekStyleInfo)) { return chekStyleInfo; } } } else { foreach (var helper in mCardStyleBaseHelpers) { if (helper.CheckStyleNormal(this, out var chekStyleInfo)) { return chekStyleInfo; } } } CardStyleInfo cardStyleInfo = new CardStyleInfo(); cardStyleInfo.CardStyle = DataCardConst.CardStyle0; return cardStyleInfo; } /// /// 获取当前牌组得所有符合条件牌型 /// public List GetCardStyleInfos() { List cardStyleInfos = new List(); if (this.mLZCards.Count > 0) { foreach (var helper in mCardStyleBaseHelpers) { if (helper.CheckStyleWithLZ(this, out var chekStyleInfo)) { cardStyleInfos.Add(chekStyleInfo); } } } else { foreach (var helper in mCardStyleBaseHelpers) { if (helper.CheckStyleNormal(this, out var chekStyleInfo)) { cardStyleInfos.Add(chekStyleInfo); } } } return cardStyleInfos; } public bool CheckCardStyleInfoValidate(CardStyleInfo cardStyleInfo, out CardStyleInfo chkStyleInfo) { chkStyleInfo = new CardStyleInfo(); foreach (var helper in mCardStyleBaseHelpers) { if (helper.CardStyle == cardStyleInfo.CardStyle) { // 先检测是否符合普通牌型 if (helper.CheckStyleNormal(this, out chkStyleInfo)) { return true; } if (this.mLZCards.Count > 0) { return helper.CheckStyleWithLZ(this, out chkStyleInfo); } } } return false; } } }