public void GuoHaidi(string uid) { this.OutCardState = OutCardState.haidi; this.SetAllResetEvent(); LinkedListNode <CsGamePlayer> node = FindPlayer(uid); this.haiGuoNumber++; //都没人要留局 if (this.haiGuoNumber == this.Players.Count) { A1018Response.Builder rep1018 = A1018Response.CreateBuilder(); rep1018.Card = this.cardArray[this.CardIndex];; var rep1018Array = rep1018.Build().ToByteArray(); foreach (var row in Players) { WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1018, rep1018Array); } this.EndGame(); } else { A1016Response.Builder rep1016 = A1016Response.CreateBuilder(); rep1016.Uid = node.NextOrFirst().Value.PlayerUser.Uid; var rep1016Array = rep1016.Build().ToByteArray(); foreach (var row in Players) { WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1016, rep1016Array); } } }
/// <summary> /// 打牌 /// </summary> /// <param name="uid"></param> /// <param name="card"></param> public void Da(string uid, int card) { if (uid != this.Player.Value.PlayerUser.Uid) { LogManager.Log.Debug("没有轮到" + uid + "打牌"); return; } if (this.IsFrist) { foreach (var row in Players) { if ((row.CheckKaiJuHu()) && row.PlayerUser.Uid != uid) { LogManager.Log.Debug("开局胡等待" + row.PlayerUser.Uid + "wait"); row.ResetEvent.WaitOne(); LogManager.Log.Debug("开局胡等待处理完毕" + row.PlayerUser.Uid + "wait"); } } } LogManager.Log.Debug("通过开局胡检查"); this.IsFrist = false; this.Player.Value.DaCard(card); actionStorage.PushDa(uid, card); //为了记录打出的最后牌,为了断线重连状态保存 this.CurrentCard.Clear(); this.CurrentCard.Add(card); this.OutCardState = OutCardState.Normal; A1007Response.Builder response = A1007Response.CreateBuilder(); response.Card = card; response.Uid = uid; byte[] responseArray = response.Build().ToByteArray(); foreach (var row in Players) { row.ResetEvent.Reset(); WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1007, responseArray); } LogManager.Log.Debug("当前玩家" + this.Player.Value.PlayerUser.Uid + "后续玩家" + this.Player.NextOrFirst().Value.PlayerUser.Uid); var prePlayer = this.Player.NextOrFirst(); LogManager.Log.Debug("检查吃" + prePlayer.Value.PlayerUser.Uid + "是否可以吃" + card.GetItemValue() + "类型" + card.GetItemType()); if (prePlayer.Value.CheckChi(card)) { LogManager.Log.Debug(prePlayer.Value.PlayerUser.Uid + "手上的牌" + prePlayer.Value.PrintCards()); LogManager.Log.Debug("吃" + prePlayer.Value.PlayerUser.Uid); prePlayer.Value.ResetEvent.WaitOne(); if (this.OutCardState != OutCardState.Normal) { return; } } foreach (var row in Players) { LogManager.Log.Debug(row.PlayerUser.Uid + "手上的牌" + row.PrintCards()); if (row.PlayerUser.Uid != this.Player.Value.PlayerUser.Uid) { if (row.CheckGang(card) || row.CheckPeng(card) || row.CheckHu(card)) { LogManager.Log.Debug("等待玩家操作" + row.PlayerUser.Uid + "牌:" + card.GetItemValue()); row.ResetEvent.WaitOne(); LogManager.Log.Debug("等待玩家操作完毕" + row.PlayerUser.Uid + "牌:" + card.GetItemValue()); if (this.OutCardState != OutCardState.Normal) { return; } continue; } } } this.Player = this.Player.NextOrFirst(); //是最后一张牌发送海底命令 if (this.CardIndex == cardArray.Length - 1) { A1016Response.Builder rep1016 = A1016Response.CreateBuilder(); rep1016.Uid = this.Player.Value.PlayerUser.Uid; var rep1016Array = rep1016.Build().ToByteArray(); foreach (var row in Players) { WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1016, rep1016Array); } } else { Mo(this.Player.Value.PlayerUser.Uid); } }
/// <summary> /// 杠打牌 /// </summary> /// <param name="uid"></param> /// <param name="card1"></param> /// <param name="card2"></param> public void GangDaPai(string uid, int card1, int card2) { LinkedListNode <CsGamePlayer> node = FindPlayer(uid); this.Player = node; this.OutCardState = OutCardState.Normal; if (card1 != -1 && card2 != -1) { A1020Response.Builder response = A1020Response.CreateBuilder(); response.Card1 = card1; response.Card2 = card2; response.Uid = uid; byte[] responseArray = response.Build().ToByteArray(); node.Value.zhuoCards.Add(card1); node.Value.zhuoCards.Add(card2); node.Value.NeedGangDaPai.Clear(); this.CurrentCard.Clear(); this.CurrentCard.Add(card1); this.CurrentCard.Add(card2); foreach (var row in Players) { row.ResetEvent.Reset(); WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1020, responseArray); } var prePlayer = this.Player.NextOrFirst(); if (prePlayer.Value.CheckChi(card1) || prePlayer.Value.CheckChi(card2)) { prePlayer.Value.ResetEvent.WaitOne(); if (this.OutCardState != OutCardState.Normal) { return; } } foreach (var row in Players) { if (row.PlayerUser.Uid != this.Player.Value.PlayerUser.Uid) { if (row.CheckGang(card1) || row.CheckPeng(card1) || row.CheckHu(card1) || row.CheckGang(card2) || row.CheckPeng(card2) || row.CheckHu(card2)) { row.ResetEvent.WaitOne(); if (this.OutCardState != OutCardState.Normal) { return; } continue; } } } } this.Player = this.Player.NextOrFirst(); //是最后一张牌发送海底命令 if (this.CardIndex == cardArray.Length - 1) { A1016Response.Builder rep1016 = A1016Response.CreateBuilder(); rep1016.Uid = this.Player.Value.PlayerUser.Uid; var rep1016Array = rep1016.Build().ToByteArray(); foreach (var row in Players) { WebSocketServerWrappe.SendPackgeWithUser(row.PlayerUser.Uid, 1016, rep1016Array); } } else { Mo(this.Player.Value.PlayerUser.Uid); } }