|
- #include "StdAfx.h"
- #include "TableFrameSink_tdh.h"
-
- #include <algorithm>
- #include "../俱乐部/Source/MessageDef/Pb_SparrowMaJiang.pb.h"
- #include "../俱乐部/Source/MessageDef/Pb_RecordPacket.pb.h"
- //#include "../俱乐部/Source/GlobalDef/Util.h"
-
- //构造函数
- CTableFrameSink_tdh::CTableFrameSink_tdh() :m_GameLogic(this)
- {
- //游戏变量
- m_startTime = 0;
- mPlayGameUserCount = 4;
- m_lSiceCount = 0;
- m_wBankerUser = INVALID_CHAIR;
- ZeroMemory(m_cbCardIndex, sizeof(m_cbCardIndex));
- ZeroMemory(m_bTrustee, sizeof(m_bTrustee));
-
- ZeroMemory(m_PaiQuan, sizeof(m_PaiQuan));
- ZeroMemory(m_bPlayStatus, sizeof(m_bPlayStatus));
- ZeroMemory(m_lGameScore, sizeof(m_lGameScore));
- ZeroMemory(m_lGameTatolScore, sizeof(m_lGameTatolScore));
- ZeroMemory(m_HuPai, sizeof(m_HuPai));
-
- ZeroMemory(m_TabbOutCardCout, sizeof(m_TabbOutCardCout)); //可以打出的牌就听牌的个数
- ZeroMemory(m_TabbOutCardData, sizeof(m_TabbOutCardData)); //具体打哪几张牌
- ZeroMemory(m_TabbTingCardCount, sizeof(m_TabbTingCardCount)); //相对应打出牌可听牌个数,索引表示第几张,值是对应对应的听牌个数
- ZeroMemory(m_TabbTingCardData, sizeof(m_TabbTingCardData)); //具体听牌数据,一维索引表示打出牌的第几个,二维索引表示听牌的第几个,值表示牌数据
-
- //出牌信息
- m_cbOutCardData = 0;
- m_cbOutCardCount = 0;
- m_wOutCardUser = INVALID_CHAIR;
- ZeroMemory(m_cbDiscardCard, sizeof(m_cbDiscardCard));
- ZeroMemory(m_cbDiscardCount, sizeof(m_cbDiscardCount));
- ZeroMemory(m_cbLastDisCardData, sizeof(m_cbLastDisCardData));
- ZeroMemory(m_cbLastDisCount, sizeof(m_cbLastDisCount));
- ZeroMemory(LianXuHuPai, sizeof(LianXuHuPai));
-
- //发牌信息
- m_cbSendCardData = 0;
- m_cbSendCardCount = 0;
- m_cbLeftCardCount = 0;
- m_cbShiJiLeftCardCount = 0;
- ZeroMemory(m_cbRepertoryCard, sizeof(m_cbRepertoryCard));
- m_cbGangCount = 0;//打了几个杠
-
- //运行变量
- m_cbProvideCard = 0;
- m_wResumeUser = INVALID_CHAIR;
- m_wCurrentUser = INVALID_CHAIR;
- m_wProvideUser = INVALID_CHAIR;
-
- //状态变量
- //m_bSendStatus=false;
- //m_bGangStatus = false;
- m_GangPrivedUserID = -1;
- m_bGangOption = 0;
- //m_OutLastLaiZiData = 0; //最后杠牌数据,断线重连用的着
- m_bQiangGang = false;
-
-
- //用户状态
- ZeroMemory(m_bResponse, sizeof(m_bResponse));
- ZeroMemory(m_cbUserAction, sizeof(m_cbUserAction));
- ZeroMemory(m_cbOperateCard, sizeof(m_cbOperateCard));
- ZeroMemory(m_cbPerformAction, sizeof(m_cbPerformAction));
- ZeroMemory(m_cbOperateCaiCard, sizeof(m_cbOperateCaiCard));
- //组合扑克
- ZeroMemory(m_WeaveItemArray, sizeof(m_WeaveItemArray));
- ZeroMemory(m_cbWeaveItemCount, sizeof(m_cbWeaveItemCount));
-
- //结束信息
- ZeroMemory(m_HuPai, sizeof(m_HuPai));
- ZeroMemory(m_HuPaiLiuShui, sizeof(m_HuPaiLiuShui));
- //组件变量
- m_pITableFrame = NULL;
- m_pGameServiceOption = NULL;
- bIsHuang = false;
- mMaxTaiNum = 5;
-
- ZeroMemory(m_cbOptCard, sizeof(m_cbOptCard));
- m_cbLastGangCard = 0;
- ZeroMemory(m_bUsersGangStatus, GAME_PLAYER);
- m_bTwoPlayerFlag = false;
- return;
- }
-
- //析构函数
- CTableFrameSink_tdh::~CTableFrameSink_tdh(void)
- {
- }
-
- //接口查询
- void * CTableFrameSink_tdh::QueryInterface(const IID & Guid, DWORD dwQueryVer)
- {
- // QUERYINTERFACE(ITableFrameSink, Guid, dwQueryVer);
- // QUERYINTERFACE(ITableUserAction, Guid, dwQueryVer);
- // QUERYINTERFACE_IUNKNOWNEX(ITableFrameSink, Guid, dwQueryVer);
- if ((Guid == IID_ITableFrameSink) && (InterfaceVersionCompare(dwQueryVer, VER_ITableFrameSinkOther)))
- return static_cast<ITableFrameSink *>(this);
- QUERYINTERFACE(ITableUserAction, Guid, dwQueryVer);
- if ((Guid == IID_IUnknownEx) && (InterfaceVersionCompare(dwQueryVer, VER_IUnknownEx)))
- return static_cast<IUnknownEx *>(static_cast<ITableFrameSink *>(this));
-
-
- return NULL;
- }
-
- //初始化
- bool CTableFrameSink_tdh::Initialization(IUnknownEx * pIUnknownEx)
- {
- //查询接口
- ASSERT(pIUnknownEx != NULL);
- m_pITableFrame = QUERY_OBJECT_PTR_INTERFACE(pIUnknownEx, ITableFrame);
- if (m_pITableFrame == NULL)
- return false;
-
- //获取参数
- m_pGameServiceOption = m_pITableFrame->GetGameServiceOption();
- ASSERT(m_pGameServiceOption != NULL);
-
- //开始模式
- m_pITableFrame->SetStartMode(START_MODE_FULL_READY);
-
- return true;
- }
-
- //复位桌子
- VOID CTableFrameSink_tdh::RepositionSink()
- {
- //游戏变量
- m_startTime = 0;
- ZeroMemory(m_PaiQuan, sizeof(m_PaiQuan));
- ZeroMemory(m_cbCardIndex, sizeof(m_cbCardIndex));
- ZeroMemory(m_bTrustee, sizeof(m_bTrustee));
- //ZeroMemory( m_cbGenCount,sizeof(m_cbGenCount) );
- ZeroMemory(m_bPlayStatus, sizeof(m_bPlayStatus));
- //m_cbWinCount = 0;
- //memset( m_wWinOrder,INVALID_CHAIR,sizeof(m_wWinOrder) );
- //ZeroMemory( m_lGameTax,sizeof(m_lGameTax) );
-
- ZeroMemory(m_PaiQuan, sizeof(m_PaiQuan));
- ZeroMemory(m_TabbOutCardCout, sizeof(m_TabbOutCardCout)); //可以打出的牌就听牌的个数
- ZeroMemory(m_TabbOutCardData, sizeof(m_TabbOutCardData)); //具体打哪几张牌
- ZeroMemory(m_TabbTingCardCount, sizeof(m_TabbTingCardCount)); //相对应打出牌可听牌个数,索引表示第几张,值是对应对应的听牌个数
- ZeroMemory(m_TabbTingCardData, sizeof(m_TabbTingCardData)); //具体听牌数据,一维索引表示打出牌的第几个,二维索引表示听牌的第几个,值表示牌数据
-
- //出牌信息
- m_cbOutCardData = 0;
- m_cbOutCardCount = 0;
- m_wOutCardUser = INVALID_CHAIR;
- ZeroMemory(m_cbDiscardCard, sizeof(m_cbDiscardCard));
- ZeroMemory(m_cbDiscardCount, sizeof(m_cbDiscardCount));
- ZeroMemory(m_cbLastDisCardData, sizeof(m_cbLastDisCardData));
- ZeroMemory(m_cbLastDisCount, sizeof(m_cbLastDisCount));
-
- //发牌信息
- m_cbSendCardData = 0;
- m_cbSendCardCount = 0;
- m_cbLeftCardCount = 0;
- m_cbShiJiLeftCardCount = 0;
- ZeroMemory(m_cbRepertoryCard, sizeof(m_cbRepertoryCard));
- m_cbGangCount = 0;//打了几个杠
- //运行变量
- m_cbProvideCard = 0;
- m_wResumeUser = INVALID_CHAIR;
- m_wCurrentUser = INVALID_CHAIR;
- m_wProvideUser = INVALID_CHAIR;
- //m_wBankerUser = INVALID_CHAIR;
-
- //状态变量
- //m_bSendStatus=false;
- //m_bGangStatus = false;
- m_GangPrivedUserID = -1;
- m_bGangOption = 0;
- //m_OutLastLaiZiData = 0; //最后杠牌数据,断线重连用的着
- m_bQiangGang = false;
-
- //用户状态
- ZeroMemory(m_bResponse, sizeof(m_bResponse));
- ZeroMemory(m_cbUserAction, sizeof(m_cbUserAction));
- ZeroMemory(m_cbOperateCard, sizeof(m_cbOperateCard));
- ZeroMemory(m_cbPerformAction, sizeof(m_cbPerformAction));
- ZeroMemory(m_cbOperateCaiCard, sizeof(m_cbOperateCaiCard));
- //组合扑克
- ZeroMemory(m_WeaveItemArray, sizeof(m_WeaveItemArray));
- ZeroMemory(m_cbWeaveItemCount, sizeof(m_cbWeaveItemCount));
-
- //结束信息
- m_cbMagicFirstData = 0;
- m_cbMagicSecondData = 0;
- bIsHuang = false;
-
- ZeroMemory(m_cbOptCard, sizeof(m_cbOptCard));
- ZeroMemory(m_bUsersGangStatus, GAME_PLAYER);
- return;
- }
-
- bool CTableFrameSink_tdh::RepayRecordStart()
- {
- m_bReplayRecordStart = true;
-
-
- m_UserReplayRecord.clear();
- return true;
- }
- bool CTableFrameSink_tdh::RepayRecordEnd()
- {
- if (!m_bReplayRecordStart)
- return false;
-
- m_bReplayRecordStart = false;
- CMD_GR_ReplayRecordResp urr;
- ZeroMemory(&urr, sizeof(CMD_GR_ReplayRecordResp));
-
- urr.m_UUID = 0;
- urr.m_UserId = 0;
- urr.m_startTime = m_startTime;
- urr.m_endTime = time(0);
- urr.m_gameconfig = m_gameConfig;
- //urr.m_UserId = pIServerUserItem->GetUserID();
-
- for (int j = 0; j < mPlayGameUserCount; ++j)
- {
- if (m_bTwoPlayerFlag&&j == TowMjNullseat)
- {
- continue;
- }
- IServerUserItem * pIServerUserItem = m_pITableFrame->GetTableUserItem(j);
- if ((pIServerUserItem == NULL) /*|| (pIServerUserItem->IsClientReady() == false)*/)
- continue;
- auto& chairInfo = urr.m_chairList[j];
- chairInfo.dwUserId = pIServerUserItem->GetUserID();
- chairInfo.wChairId = pIServerUserItem->GetChairID();
- lstrcpy(chairInfo.userName, pIServerUserItem->GetNickName());
- lstrcpy(chairInfo.headUrl, pIServerUserItem->GetUserInfo()->szHeadUrl);
- }
- urr.m_recordCount = m_UserReplayRecord.size();
-
- RecordPacket::PB_CS_S_ReplayRecordResp RecordResp;
- RecordResp.set_m_uuid(urr.m_UUID);
- RecordResp.set_m_userid(urr.m_UserId);
- RecordResp.set_m_starttime(urr.m_startTime);
- RecordResp.set_m_endtime(urr.m_endTime);
- RecordResp.mutable_m_gameconfig()->set_bduolai(m_gameConfig.bDuoLai);
- RecordResp.mutable_m_gameconfig()->set_isowner(m_gameConfig.IsOwner);
- RecordResp.mutable_m_gameconfig()->set_roomid(m_gameConfig.RoomId);
- std::string sPrivateTableID = CW2AEX<1024>(m_gameConfig.sPrivateTableID, CP_UTF8).m_psz;
- RecordResp.mutable_m_gameconfig()->set_sprivatetableid(sPrivateTableID);
- RecordResp.mutable_m_gameconfig()->set_tmp1(m_gameConfig.tmp1);
- RecordResp.mutable_m_gameconfig()->set_tmp2(m_gameConfig.tmp2);
- RecordResp.mutable_m_gameconfig()->set_wdiscore(m_gameConfig.wDiScore);
- RecordResp.mutable_m_gameconfig()->set_wfanfei(m_gameConfig.wFanFei);
- RecordResp.mutable_m_gameconfig()->set_wfengding(m_gameConfig.wFengDing);
- RecordResp.mutable_m_gameconfig()->set_whadplaycount(m_gameConfig.wHadPlayCount);
- RecordResp.mutable_m_gameconfig()->set_wiplimit(m_gameConfig.wIpLimit);
- RecordResp.mutable_m_gameconfig()->set_wplaycountrule(m_gameConfig.wPlayCountRule);
- RecordResp.mutable_m_gameconfig()->set_wsubgameid(m_gameConfig.wSubGameID);
- for (WORD i = 0; i < mPlayGameUserCount; i++)
- {
- RecordPacket::pb_ChairRecord* Record = RecordResp.add_m_chairlist();
- Record->set_wchairid(urr.m_chairList[i].wChairId);
- Record->set_dwuserid(urr.m_chairList[i].dwUserId);
- std::string userName = CW2AEX<1024>(urr.m_chairList[i].userName, CP_UTF8).m_psz;
- std::string headUrl = CW2AEX<1024>(urr.m_chairList[i].headUrl, CP_UTF8).m_psz;
- Record->set_username(userName);
- Record->set_headurl(headUrl);
- }
- for (auto& grp : m_UserReplayRecord)
- {
- RecordPacket::pb_GameRecordPacket* Packet = RecordResp.add_precordpacket();
- Packet->set_wchairid(grp.wchairid());
- Packet->set_wsubcmdid(grp.wsubcmdid());
- Packet->set_wmaincmdid(grp.wmaincmdid());
- Packet->set_pdata(grp.pdata());
-
- }
- std::string pbresp = RecordResp.SerializePartialAsString();
-
- m_pITableFrame->SaveReplayRecord((void*)pbresp.c_str(), pbresp.length());
-
-
- //for (GameRecordPacket grp : m_UserReplayRecord)
- //{
- // if (grp.pData != NULL)
- // {
- // delete[] grp.pData;
- // grp.pData = NULL;
- // }
- //}
- m_UserReplayRecord.clear();
-
-
-
-
- //delete replyRecordData;不能删除,已托管给SaveReplayRecord函数
- return true;
- }
-
- bool CTableFrameSink_tdh::RepayRecord(WORD wChairID, WORD wSubCmdId, void* pData, WORD wSize)
- {
- RecordPacket::pb_GameRecordPacket pRecordPacket;
- pRecordPacket.set_wchairid(wChairID);
- pRecordPacket.set_wsubcmdid(wSubCmdId);
- pRecordPacket.set_wmaincmdid(MDM_GF_GAME);
- pRecordPacket.set_pdata((char*)pData, wSize);
- m_UserReplayRecord.push_back(pRecordPacket);
- return true;
- }
-
- //游戏开始
- bool CTableFrameSink_tdh::OnEventGameStart()
- {
- m_startTime = time(0);
- ZeroMemory(m_lGameScore, sizeof(m_lGameScore));
- srand((unsigned)time(NULL)*mGameTableId);
- m_cbMagicFirstData = 0;
- m_cbMagicSecondData = 0;
- //椅子数量
- WORD wChairCount = m_pITableFrame->GetChairCount();
-
- //开始记录回放数据
- RepayRecordStart();
- //重置发牌状态
- m_isCanOutCard = false;
- //重置掉线玩家列表
- m_offlineUsers.clear();
- //设置状态
- m_pITableFrame->SetGameStatus(GS_MJ_PLAY);
- //打印时间
- DWORD timet = GetTickCount();
- m_gameConfig.wHadPlayCount++;
- //混乱扑克,
- m_lSiceCount = MAKELONG(MAKEWORD(rand() % 6 + 1, rand() % 6 + 1), MAKEWORD(rand() % 6 + 1, rand() % 6 + 1));
- if (m_gameConfig.wHadPlayCount == 1)
- {
- m_lSiceCountCheckBank = MAKELONG(MAKEWORD(rand() % 6 + 1, rand() % 6 + 1), MAKEWORD(rand() % 6 + 1, rand() % 6 + 1));
- }
- else
- {
- m_lSiceCountCheckBank = 0;
- }
- if (m_bTwoPlayerFlag)
- {
- m_cbLeftCardCount = m_GameLogic.RandCardData_Two(m_cbRepertoryCard);
- }
- else
- {
- m_cbLeftCardCount = m_GameLogic.RandCardData(m_cbRepertoryCard);
- }
-
-
- WritePaiCardData(m_gameConfig.sPrivateTableID, m_gameConfig.wHadPlayCount);
-
-
- if (1 == m_gameConfig.wHadPlayCount )
- {
-
- WORD wSice = WORD(m_lSiceCountCheckBank & 0xffff);
- int slice1 = HIBYTE(wSice);
- int slice2 = LOBYTE(wSice);
- int nAll = slice1 + slice2;
- /*
- 计算庄家
- */
-
- if (m_bTwoPlayerFlag)
- {
- if (nAll%2==0)
- {
- m_wBankerUser = 2;
- }
- else
- {
- m_wBankerUser = 0;
- }
- }
- else
- {
- m_wBankerUser = (nAll%mPlayGameUserCount + (mPlayGameUserCount - 1)) % mPlayGameUserCount;
- }
- /*CString str;
- str.Format(_T("num1=%d num2=%d all=%d 方向=%d 庄=%d"), slice1, slice2, nAll, m_wBankerUser);
- OutputDebugString(str);*/
-
-
- }
- else
- {
- if ( m_wNextBankerUser == INVALID_CHAIR)
- {
- m_wBankerUser = m_wBankerUser;
- }
- else
- {
- m_wBankerUser = m_wNextBankerUser;
- }
-
-
- //CString str;
- //str.Format(_T("庄=%d"), m_wBankerUser);
- //OutputDebugString(str);
-
- }
- m_wNextBankerUser = INVALID_CHAIR;
-
- //BYTE byTest[] = {
- // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //万子
- // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //万子
- // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //万子
- // 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, //万子
- // 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, //索子
- // 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, //索子
- // 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, //索子
- // 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, //索子
- // 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, //同子
- // 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, //同子
- // 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, //同子
- // 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, //同子
- // 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //风东南西北
- // 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //风东南西北
- // 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //风东南西北
- // 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, //风东南西北 中发白
- //};
- //if (m_GameLogic.PeiPai(byTest))
- // CopyMemory(m_cbRepertoryCard, byTest, sizeof(byTest));
-
- //配牌状态 默认每次都是东家为装
- /* if (ReadGameData())
- {
- m_wBankerUser = 0;
- }*/
- ReadGameData();
- //////////////////////////////////////////////////////////////////////////
- //调试使用
- //m_wBankerUser = 0;
-
- //////////////////////////////////////////////////////////////////////////
-
-
-
-
- //分发扑克
- for (WORD i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i==TowMjNullseat)
- {
- continue;
- }
- m_bPlayStatus[i] = true;
- m_cbLeftCardCount -= (MAX_COUNT - 1);//每一个玩家都发出去13张牌,还剩多少
- m_cbSendCardCount += (MAX_COUNT - 1);//每个玩家加13张牌
- m_GameLogic.SwitchToCardIndex(&m_cbRepertoryCard[m_cbLeftCardCount], MAX_COUNT - 1, m_cbCardIndex[i]);
- }
-
- //
- m_cbSendCardCount++;
- //取一张财神牌
- m_cbMagicFirstData = m_cbRepertoryCard[--m_cbLeftCardCount];
- //获取下一张财神
- m_cbMagicSecondData = GetNextMagicCardData(m_cbMagicFirstData);
-
-
- //发送扑克,庄家摸牌
- m_cbSendCardCount++;//第十四张牌
- m_cbSendCardData = m_cbRepertoryCard[--m_cbLeftCardCount];
-
- //设置变量
- m_cbProvideCard = 0;
- m_wProvideUser = m_wBankerUser & 0x000F;
- m_wCurrentUser = m_wBankerUser & 0x000F;
- WORD ActionCard[6] = { 0 };
-
- m_GameLogic.SetMagicIndex(m_GameLogic.SwitchToCardIndex(m_cbMagicSecondData), MAX_INDEX);
-
- // 胡牌判断
- CChiHuRight chr;
- BYTE TaiShu = 0;
- m_cbUserAction[m_wCurrentUser] |= m_GameLogic.AnalyseChiHuCard(m_cbCardIndex[m_wCurrentUser], NULL, 0, m_cbSendCardData, chr, TaiShu);
- m_cbCardIndex[m_wCurrentUser][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)]++;
- //if (m_cbUserAction[m_wCurrentUser] & WIK_ZI_MO)
- //{
- // m_cbUserAction[m_wCurrentUser] = WIK_TIAN_ZI_MO;
- //}
-
- //杠牌判断
- tagGangCardResult GangCardResult;
- ZeroMemory(&GangCardResult, sizeof(GangCardResult));
- m_cbUserAction[m_wCurrentUser] |= m_GameLogic.AnalyseGangCard(m_cbCardIndex[m_wCurrentUser], NULL, 0, GangCardResult);
-
- for (BYTE i = 0; i < GangCardResult.cbCardCount; i++)
- {
- ActionCard[i] = GangCardResult.cbCardData[i];
- }
-
-
-
- m_cbProvideCard = m_cbSendCardData;
- m_wResumeUser = m_wCurrentUser;
-
-
- //保存实际剩余的牌
- m_cbShiJiLeftCardCount = m_cbLeftCardCount;
-
- //牌位第十三顿 截止 倒数第十四牌打完 没人胡牌 流局
- //根据这个规则 删除26张牌 剩余的牌出完 没人胡牌 就是 流局
- m_cbLeftCardCount -= 26;//
-
- //构造数据
- CMD_S_GameStart GameStart;
- GameStart.wBankerUser = m_wBankerUser;
- GameStart.cbLeftCardCount = m_cbLeftCardCount;
-
- WORD wSice = WORD(m_lSiceCount & 0xffff);
- GameStart.cbSiceLaiZi[0] = HIBYTE(wSice);//骰子 第一次
- GameStart.cbSiceLaiZi[1] = LOBYTE(wSice);//骰子
-
- GameStart.cbSiceLaiZi[2] = m_cbMagicFirstData;//真实展示的牌
- GameStart.cbSiceLaiZi[3] = m_cbMagicSecondData;//财神显示的牌
-
-
- if (1 == m_gameConfig.wHadPlayCount)
- {
- WORD wSice = WORD(m_lSiceCountCheckBank & 0xffff);
- GameStart.cbSliceCheckBankUser[0] = HIBYTE(wSice);
- GameStart.cbSliceCheckBankUser[1] = LOBYTE(wSice);
- //////////////////////////////////////////////////////////////////////////
- //调试
- /*GameStart.cbSliceCheckBankUser[0] = 2;
- GameStart.cbSliceCheckBankUser[1] = 3;*/
- //////////////////////////////////////////////////////////////////////////
-
- }
- else
- {
- GameStart.cbSliceCheckBankUser[0] = 0;
- GameStart.cbSliceCheckBankUser[1] = 0;
- }
- //设置庄家 相关。
-
- //CString strShaizi;
- //strShaizi.Format(_T("[%d %d] , [%d %d]"), GameStart.cbSiceLaiZi[0], GameStart.cbSiceLaiZi[1], GameStart.cbSliceCheckBankUser[0], GameStart.cbSliceCheckBankUser[1]);
- //OutputDebugString(strShaizi);
-
-
- if (m_bTwoPlayerFlag)
- {
- GameStart.cbTotalCardCount = MAX_REPERTORY_ZJ_Two; //麻将总数
- }else
- {
- GameStart.cbTotalCardCount = MAX_REPERTORY_ZJ; //麻将总数
- }
- GameStart.cbCurrPlay = m_gameConfig.wHadPlayCount;//当前局数
- GameStart.cbOptTime = GAME_TIMEOUT;//出牌超时时间
- ZeroMemory(GameStart.ActionCard, sizeof(GameStart.ActionCard));
- CopyMemory(GameStart.ActionCard, ActionCard, sizeof(ActionCard));
- TingCard(m_wCurrentUser);
-
-
- //打印时间
- //DWORD t2 = GetTickCount();
- //DWORD hh = t2 - timet;
- //CString csTemp;
- //csTemp.Format(L"时间:%d \r\n", hh);
- //OutputDebugString(csTemp);
- //发送数据
-
- SparrowMaJiang::PB_CS_S_GameStart GameStarts;
- GameStarts.set_wbankeruser(GameStart.wBankerUser);
- GameStarts.set_cbleftcardcount(GameStart.cbLeftCardCount);
- GameStarts.set_cbtotalcardcount(GameStart.cbTotalCardCount);
- GameStarts.set_cbopttime(GameStart.cbOptTime);
- GameStarts.set_cbcurrplay(GameStart.cbCurrPlay);
- for (WORD j = 0; j < 4; j++)
- {
- GameStarts.add_cbsicelaizi(GameStart.cbSiceLaiZi[j]);
- }
- for (WORD j = 0; j < 6; j++)
- {
- GameStarts.add_actioncard(GameStart.ActionCard[j]);
- }
- for (WORD j = 0; j < 2; j++)
- {
- GameStarts.add_cbslicecheckbankuser(GameStart.cbSliceCheckBankUser[j]);
- }
- //发送数据
- for (WORD i = 0; i<wChairCount; i++)
- {
- //设置变量
- GameStart.wCurrentUser = i;
- GameStart.cbUserAction = m_cbUserAction[i];
-
-
- //把庄家 刚刚放入手里的牌剪掉 然后统一 发送数据
- if (i == m_wCurrentUser)
- {
- if (m_cbCardIndex[m_wCurrentUser][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)] > 0 && m_wCurrentUser == i)
- {
- m_cbCardIndex[m_wCurrentUser][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)]--;//从手上去掉抓的牌
- }
- else
- {
- return false;
- }
- }
-
- ZeroMemory(GameStart.cbCardData, sizeof(GameStart.cbCardData));
- m_GameLogic.SwitchToCardData(m_cbCardIndex[i], &GameStart.cbCardData[MAX_COUNT*i]);
-
- if (i == m_wCurrentUser)
- {
-
- GameStart.cbCardData[i * 14 + 13] = m_cbSendCardData;//把去掉的牌加到数组末尾,
- m_cbCardIndex[m_wCurrentUser][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)]++;//把去掉的加进来
- }
-
- GameStarts.set_wcurrentuser(GameStart.wCurrentUser);
-
- for (WORD j = 0; j < MAX_COUNT * GAME_PLAYER; j++)
- {
- if (i == 0)
- {
- GameStarts.add_cbcarddata(GameStart.cbCardData[j]);
- }
- else
- {
- GameStarts.set_cbcarddata(j, GameStart.cbCardData[j]);
- }
- }
- GameStarts.set_cbuseraction(GameStart.cbUserAction);
- //发送数据
- std::string pbdata = GameStarts.SerializePartialAsString();
- //发送数据
- m_pITableFrame->SendTableData(i, SUB_S_GAME_START, (void*)pbdata.c_str(), pbdata.length());
- }
-
-
-
- //用户回放
- ZeroMemory(GameStart.cbCardData, sizeof(GameStart.cbCardData));
- for (WORD i = 0; i < MAX_COUNT * GAME_PLAYER; i++)
- {
- GameStarts.set_cbcarddata(i, GameStart.cbCardData[i]);
- }
- //清手牌 旁观只能发一次
- std::string pbdata = GameStarts.SerializePartialAsString();
- //发送数据
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GAME_START, (void*)pbdata.c_str(), pbdata.length());
-
- for (WORD i = 0; i < wChairCount; i++)
- m_GameLogic.SwitchToCardData(m_cbCardIndex[i], &GameStart.cbCardData[MAX_COUNT * i]);
- for (WORD i = 0; i < MAX_COUNT * GAME_PLAYER; i++)
- {
- GameStarts.set_cbcarddata(i, GameStart.cbCardData[i]);
- }
- std::string pbrecord = GameStarts.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_GAME_START, (void*)pbrecord.c_str(), pbrecord.length());
-
- if (m_TabbOutCardCout[m_wCurrentUser] > 0)
- HttpTingCard(m_wCurrentUser);
- return true;
-
-
- return true;
- }
-
- void CTableFrameSink_tdh::DeletePrivateTable(bool bSendState)
- {
- tagScoreInfo ScoreInfoArray[GAME_PLAYER];
- ZeroMemory(&ScoreInfoArray, sizeof(ScoreInfoArray));
-
- WORD wChairCount = m_pITableFrame->GetChairCount();
- for (int i = 0; i < wChairCount; ++i)
- {
- IServerUserItem *pIUserItem = m_pITableFrame->GetTableUserItem(i);
- if (pIUserItem == NULL)
- continue;
- ScoreInfoArray[i].cbType = SCORE_TYPE_END;
- ScoreInfoArray[i].lScore = 0;// m_lUserTmpScore[i] - TEMP_MAX_SCORE; //记录临时分
- }
- m_pITableFrame->WriteTableScore(ScoreInfoArray, CountArray(ScoreInfoArray));
-
- ConcludeGame(GAME_STATUS_DELETE, bSendState);
- m_pITableFrame->DeletePrivateTableNow();
- }
-
- //游戏结束
- bool CTableFrameSink_tdh::OnEventGameConclude(WORD wChairID, IServerUserItem * pIServerUserItem, BYTE cbReason, bool bSendState)
- {
- bool bFinish = (m_gameConfig.wHadPlayCount >= m_gameConfig.wPlayCountRule) ? 1 : 0;
- switch (cbReason)
- {
- case GER_DELETE_PRIVATE:
- {
- ConcludeGame(GS_MJ_FREE);
- DeletePrivateTable(bSendState);
- return true;
- }
- case GER_NORMAL: //常规结束
- {
-
-
- //变量定义
- CMD_S_GameEnd GameEnd;
- ZeroMemory(&GameEnd, sizeof(GameEnd));
- GameEnd.bFinish = bFinish;//1……
- if (m_cbLeftCardCount <= 0 && bIsHuang)//荒庄了
- {
- {
- GameEnd.bOptType = 2;
- //黄庄了
- //积分变动
- CMD_S_GangScore gs;
- ZeroMemory(&gs, sizeof(gs));
- gs.wChairId = WIK_NULL;
- gs.cbOperateCode = WIK_NULL;
- CaculationHuangZhuang(gs);
- SparrowMaJiang::PB_CS_S_GangScore GangScore;
- GangScore.set_cboperatecode(gs.cbOperateCode);
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- GangScore.add_cbwanjiascore(gs.cbWanJiaScore[j]);
- GangScore.add_lgangscore(gs.lGangScore[j]);
- }
- GangScore.set_wchairid(gs.wChairId);
- std::string pbscore = GangScore.SerializePartialAsString();
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
-
- //统计玩家积分,牌值
- for (WORD i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- GameEnd.cbWanJiaScore[i] = m_lGameTatolScore[i];//各玩家积分4…………
-
- m_GameLogic.SwitchToCardData(m_cbCardIndex[i], GameEnd.cbCardData[i]);
- }
-
- //黄装了
- if (m_gameConfig.wHadPlayCount > 1)
- {
- m_wNextBankerUser = m_wBankerUser;
- m_wNextBankerUser = m_wNextBankerUser | 0x0100;
- int userID;
- if (m_wBankerUser > 4)
- {
- userID = m_wBankerUser & 0x00ff;
- }
- else
- {
- userID = m_wBankerUser;
- }
- LianXuHuPai[userID]++;
- }
- else
- {
- LianXuHuPai[m_wBankerUser & 0x00ff]++;
- }
-
- }
- }
- else
- {
- GameEnd.bOptType = 1;
- GameEnd.HuPaiCard = m_cbProvideCard;
- GameEnd.wDianpao = m_wProvideUser;
-
- BYTE TempWanJiaCardCount = 0;
- m_wNextBankerUser = wChairID; //得到下一个坐庄的玩家
-
- if (LianXuHuPai[wChairID] > 1)
- m_wNextBankerUser = m_wNextBankerUser | 0x0100;
-
- //统计积分,胡牌得分,玩家牌值
- //保存本局所有用户的积分变动 除了胡牌玩家的
- for (WORD i = 0; i < mPlayGameUserCount; i++)
- {
- //m_lGameTatolScore[i] += m_lGameScore[i];
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- GameEnd.cbWanJiaScore[i] = m_lGameTatolScore[i];//各玩家积分3…………
- if (i == wChairID && m_wProvideUser == wChairID)continue;
- m_GameLogic.SwitchToCardData(m_cbCardIndex[i], GameEnd.cbCardData[i]);
- }
- //
- if (m_wProvideUser == wChairID)
- {
- //先减去 胡的这张牌
- m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(m_cbProvideCard)]--;
- //把剩下的手牌保存到cbCardData
- m_GameLogic.SwitchToCardData(m_cbCardIndex[wChairID], GameEnd.cbCardData[wChairID]);
- //保存手牌数目
- TempWanJiaCardCount = m_GameLogic.GetCardCount(m_cbCardIndex[wChairID]);
- //最后一张牌 加上刚刚减去的牌
- GameEnd.cbCardData[wChairID][TempWanJiaCardCount] = m_cbProvideCard;//手牌数据4……
- //还原减去的牌
- m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(m_cbProvideCard)]++;
- }
- }
- GameEnd.bWanJiaId = wChairID;//玩家座位号 5……
- //保存实际桌子剩下多少能够抓的牌
- GameEnd.bLeftCardCount = m_cbShiJiLeftCardCount;//m_cbLeftCardCount + 26 + m_cbGangCount * 6;//剩余牌输量6…………
- CopyMemory(GameEnd.bLeftCardDada, m_cbRepertoryCard, GameEnd.bLeftCardCount);//剩余牌值7………………
- //保存每个玩家的胡牌次数
- CopyMemory(GameEnd.bZimo, m_HuPai, sizeof(m_HuPai));//玩家胡牌次数8…………
- //本次胡牌玩家的id
- GameEnd.dwOwnerID = m_pITableFrame->GetPrivateTableOwnerID();//获取房间ID,9……//胡牌玩家id
- GameEnd.playGameNum = m_gameConfig.wHadPlayCount;//得到第几局了,10…………
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- //保存16局 胡牌积分流水
- m_HuPaiLiuShui[(m_gameConfig.wHadPlayCount - 1) * 4 + i] = m_lGameScore[i];
- }
- CopyMemory(GameEnd.lGameScoreDetail, m_HuPaiLiuShui, sizeof(m_HuPaiLiuShui));//游戏流水,10…………
-
- for (int i = 0; i < m_gameConfig.wHadPlayCount; i++)
- {
- CString strTmp;
- strTmp.Format(_T("胡牌流水->第%d局 %d,%d,%d,%d"), i, m_HuPaiLiuShui[i * 4 + 0], m_HuPaiLiuShui[i * 4 + 1], m_HuPaiLiuShui[i * 4 + 2], m_HuPaiLiuShui[i * 4 + 3]);
- //OutputDebugString(strTmp);
- }
-
- SparrowMaJiang::PB_CS_S_GameEnd pGameEnd;
- pGameEnd.set_bopttype(GameEnd.bOptType);
- pGameEnd.set_bwanjiaid(GameEnd.bWanJiaId);
- pGameEnd.set_wdianpao(GameEnd.wDianpao);
- pGameEnd.set_hupaicard(GameEnd.HuPaiCard);
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- pGameEnd.add_cbwanjiascore(GameEnd.cbWanJiaScore[i]);
- pGameEnd.add_bzimo(GameEnd.bZimo[i]);
- }
- pGameEnd.set_bfinish(GameEnd.bFinish);
- pGameEnd.set_dwownerid(GameEnd.dwOwnerID);
- pGameEnd.set_bleftcardcount(GameEnd.bLeftCardCount);
- for (BYTE i = 0; i < GameEnd.bLeftCardCount; i++)
- {
- pGameEnd.add_bleftcarddada(GameEnd.bLeftCardDada[i]);
- }
- pGameEnd.set_playgamenum(GameEnd.playGameNum);
- for (BYTE i = 0; i < mPlayGameUserCount * 16; i++)
- {
- pGameEnd.add_lgamescoredetail(GameEnd.lGameScoreDetail[i]);
- }
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- SparrowMaJiang::pb_cbCardData* CardData = pGameEnd.add_cbcarddata();
- for (BYTE j = 0; j < 14; j++)
- {
- CardData->add_cbcarddatas(GameEnd.cbCardData[i][j]);
- }
- }
- std::string pbdata = pGameEnd.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_GAME_END, (void*)pbdata.c_str(), pbdata.length());
- //发送结束信息
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_GAME_END, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GAME_END, (void*)pbdata.c_str(), pbdata.length());
-
- tagScoreInfo ScoreInfoArray[GAME_PLAYER];
- ZeroMemory(&ScoreInfoArray, sizeof(ScoreInfoArray));
- for (WORD i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- IServerUserItem *pUserItem = m_pITableFrame->GetTableUserItem(i);
- if (NULL == pUserItem) continue;
-
- BYTE ScoreKind;
- if (m_lGameScore[i] > 0L) ScoreKind = SCORE_TYPE_WIN;
- else if (m_lGameScore[i] < 0L) ScoreKind = SCORE_TYPE_LOSE;
- else ScoreKind = SCORE_TYPE_DRAW;
-
- ScoreInfoArray[i].lScore = m_lGameScore[i];
- ScoreInfoArray[i].cbType = ScoreKind;
-
- //if (i == wChairID)continue;
- //m_GameLogic.SwitchToCardData(m_cbCardIndex[i], GameEnd.cbCardData[i]);
- }
- m_pITableFrame->WriteTableScore(ScoreInfoArray, CountArray(ScoreInfoArray));
-
- ConcludeGame(GS_MJ_FREE);
- if (bFinish)
- {
- DeletePrivateTable(true);
- }
-
-
- return true;
- }
- case GER_DISMISS: //游戏解散
- {
- //变量定义
- CMD_S_GameEnd GameEnd;
- ZeroMemory(&GameEnd, sizeof(GameEnd));
- GameEnd.bFinish = 1;
- GameEnd.bOptType = 3;
- CopyMemory(GameEnd.cbWanJiaScore, m_lGameTatolScore, sizeof(m_lGameTatolScore));
-
- GameEnd.bWanJiaId = wChairID;//玩家座位号 5……
- //保存实际桌子剩下多少能够抓的牌
- GameEnd.bLeftCardCount = m_cbShiJiLeftCardCount;//m_cbLeftCardCount + 26 + m_cbGangCount * 6;//剩余牌输量6…………
- CopyMemory(GameEnd.bLeftCardDada, m_cbRepertoryCard, GameEnd.bLeftCardCount);//剩余牌值7………………
- //保存每个玩家的胡牌次数
- CopyMemory(GameEnd.bZimo, m_HuPai, sizeof(m_HuPai));//玩家胡牌次数8…………
- //本次胡牌玩家的id
- GameEnd.dwOwnerID = m_pITableFrame->GetPrivateTableOwnerID();//获取房间ID,9……//胡牌玩家id
- GameEnd.playGameNum = m_gameConfig.wHadPlayCount;//得到第几局了,10…………
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- m_GameLogic.SwitchToCardData(m_cbCardIndex[i], GameEnd.cbCardData[i]);
- //保存16局 胡牌积分流水
- m_HuPaiLiuShui[(m_gameConfig.wHadPlayCount - 1) * 4 + i] = m_lGameScore[i];
- }
- CopyMemory(GameEnd.lGameScoreDetail, m_HuPaiLiuShui, sizeof(m_HuPaiLiuShui));//游戏流水,10…………
- //统计积分,胡牌得分,玩家牌值
- //保存本局所有用户的积分变动 除了胡牌玩家的
- for (WORD i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- GameEnd.cbWanJiaScore[i] = m_lGameTatolScore[i];//各玩家积分3…………
- }
- SparrowMaJiang::PB_CS_S_GameEnd pGameEnd;
- pGameEnd.set_bopttype(GameEnd.bOptType);
- pGameEnd.set_bwanjiaid(GameEnd.bWanJiaId);
- pGameEnd.set_wdianpao(GameEnd.wDianpao);
- pGameEnd.set_hupaicard(GameEnd.HuPaiCard);
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- pGameEnd.add_cbwanjiascore(GameEnd.cbWanJiaScore[i]);
- pGameEnd.add_bzimo(GameEnd.bZimo[i]);
- }
- pGameEnd.set_bfinish(GameEnd.bFinish);
- pGameEnd.set_dwownerid(GameEnd.dwOwnerID);
- pGameEnd.set_bleftcardcount(GameEnd.bLeftCardCount);
- for (BYTE i = 0; i < GameEnd.bLeftCardCount; i++)
- {
- pGameEnd.add_bleftcarddada(GameEnd.bLeftCardDada[i]);
- }
- pGameEnd.set_playgamenum(GameEnd.playGameNum);
- for (BYTE i = 0; i < mPlayGameUserCount * 16; i++)
- {
- pGameEnd.add_lgamescoredetail(GameEnd.lGameScoreDetail[i]);
- }
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- SparrowMaJiang::pb_cbCardData* CardData = pGameEnd.add_cbcarddata();
- for (BYTE j = 0; j < 14; j++)
- {
- CardData->add_cbcarddatas(GameEnd.cbCardData[i][j]);
- }
- }
- std::string pbdata = pGameEnd.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_GAME_END, (void*)pbdata.c_str(), pbdata.length());
- //发送结束信息
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_GAME_END, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GAME_END, (void*)pbdata.c_str(), pbdata.length());
- if (m_pITableFrame->GetGameStatus() == GS_MJ_FREE)
- {
- DeletePrivateTable(true);
- return true;
- }
- tagScoreInfo ScoreInfoArray[GAME_PLAYER];
- ZeroMemory(&ScoreInfoArray, sizeof(ScoreInfoArray));
- for (WORD i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- IServerUserItem *pUserItem = m_pITableFrame->GetTableUserItem(i);
- if (NULL == pUserItem) continue;
-
- BYTE ScoreKind;
- if (m_lGameScore[i] > 0L) ScoreKind = SCORE_TYPE_WIN;
- else if (m_lGameScore[i] < 0L) ScoreKind = SCORE_TYPE_LOSE;
- else ScoreKind = SCORE_TYPE_DRAW;
-
- ScoreInfoArray[i].lScore = m_lGameScore[i];
- ScoreInfoArray[i].cbType = ScoreKind;
-
- }
- m_pITableFrame->WriteTableScore(ScoreInfoArray, CountArray(ScoreInfoArray));
-
- ConcludeGame(GS_MJ_FREE);
- DeletePrivateTable(true);
-
- return true;
- return true;
- }
- case GER_NETWORK_ERROR: //网络错误
- case GER_USER_LEAVE: //用户强退
- {
- if (pIServerUserItem != NULL){
- DWORD dwUserID = pIServerUserItem->GetUserID();
- m_offlineUsers.push_back(dwUserID);
- }
- return true;
- }
- }
-
- //错误断言
- ASSERT(FALSE);
- return false;
- }
-
- //发送场景duanxian用户断线重连
- bool CTableFrameSink_tdh::OnEventSendGameScene(WORD wChiarID, IServerUserItem * pIServerUserItem, BYTE cbGameStatus, bool bSendSecret)
- {
- switch (cbGameStatus)
- {
- case GS_MJ_FREE: //空闲状态
- {
- //变量定义
- CMD_S_StatusFree StatusFree;
- memset(&StatusFree, 0, sizeof(StatusFree));
-
- //游戏房主基础配置
- CopyMemory(&StatusFree.gameConfig, &m_gameConfig, sizeof(CMD_S_GameConfig));
-
- for (int i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- StatusFree.lUserTmpScore[i] = (INT)m_lGameTatolScore[i];
- }
-
- StatusFree.gameConfig.IsOwner = m_pITableFrame->GetPrivateTableOwnerID() == pIServerUserItem->GetUserID() ? 1 : 0;
- //构造数据
- StatusFree.UserStat = pIServerUserItem->GetUserInfo()->cbUserStatus;
-
- //发送场景
- return m_pITableFrame->SendGameScene(pIServerUserItem, &StatusFree, sizeof(StatusFree));
- }
- case GS_MJ_PLAY: //游戏状态
- {
- //变量定义
- CMD_S_StatusPlay StatusPlay;
- memset(&StatusPlay, 0, sizeof(StatusPlay));
-
- //游戏房主基础配置
- CopyMemory(&StatusPlay.gameConfig, &m_gameConfig, sizeof(CMD_S_GameConfig));
- CopyMemory(StatusPlay.lUserTmpScore, m_lGameTatolScore, sizeof(m_lGameTatolScore));
- StatusPlay.cbTotalCardCount = m_cbTotalCardCount;
- StatusPlay.cbLeftCardCount = m_cbLeftCardCount;
- StatusPlay.gameConfig.IsOwner = m_pITableFrame->GetPrivateTableOwnerID() == pIServerUserItem->GetUserID() ? 1 : 0;
-
- //游戏变量
- StatusPlay.wBankerUser = m_wBankerUser;
- WORD wSice = WORD(m_lSiceCount & 0xffff);
- StatusPlay.lSiZi[0] = HIBYTE(wSice);
- StatusPlay.lSiZi[1] = LOBYTE(wSice);
- StatusPlay.lSiZi[2] = m_cbMagicFirstData;
- StatusPlay.lSiZi[3] = m_cbMagicSecondData;
-
-
- StatusPlay.dwOwnerID = m_pITableFrame->GetPrivateTableOwnerID();
-
-
- CopyMemory(StatusPlay.cbDiscardCard, m_cbDiscardCard, sizeof(StatusPlay.cbDiscardCard));
- CopyMemory(StatusPlay.cbDiscardCount, m_cbDiscardCount, sizeof(StatusPlay.cbDiscardCount));
- StatusPlay.totalOptTime = 10;
- StatusPlay.leftOptTime = 0;
- //组合扑克
- CopyMemory(StatusPlay.WeaveItemArray, m_WeaveItemArray, sizeof(m_WeaveItemArray));
- CopyMemory(StatusPlay.cbWeaveCount, m_cbWeaveItemCount, sizeof(m_cbWeaveItemCount));
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- //StatusPlay.bWanLaiZi[i] = m_OutLaiZi[i];
- //StatusPlay.bWanLaiZi[i] |= (m_OutHongZhongGang[i] << 4);
- //StatusPlay.bWanLaiZi[i] |= (m_OutFaCaiGang[i] << 8);
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- StatusPlay.cbCardCount[i] = m_GameLogic.GetCardCount(m_cbCardIndex[i]);
- }
- m_GameLogic.SwitchToCardData(m_cbCardIndex[wChiarID], StatusPlay.cbCardData);//手牌数据
- StatusPlay.cbActionMask = m_cbUserAction[wChiarID]; //需要用到操作码
- if (m_cbUserAction[wChiarID] & (WIK_AN_GANG | WIK_BU_GANG | WIK_DAN_BU_GANG | WIK_DAN_AN_GANG | WIK_SHUANG_AN_GANG | WIK_SAN_AN_GANG | WIK_QUANG_AN_GANG))
- {
- tagGangCardResult GangCardResult;
- ZeroMemory(&GangCardResult, sizeof(GangCardResult));
- m_GameLogic.AnalyseGangCard(m_cbCardIndex[wChiarID], m_WeaveItemArray[wChiarID], m_cbWeaveItemCount[wChiarID], GangCardResult);
- for (BYTE i = 0; i < GangCardResult.cbCardCount; i++)
- {
- StatusPlay.gangCards[i] = GangCardResult.cbCardData[i];
- }
- }
- ASSERT(m_wProvideUser >= 0 && m_wProvideUser <= 3);
- //当前到谁家
- StatusPlay.wCurrentUser = (m_wCurrentUser == INVALID_CHAIR ? m_wProvideUser : m_wCurrentUser);
- BYTE OldUser = 0;//定义一个最后出牌用户
- if ((m_wProvideUser == m_wCurrentUser&&m_wOutCardUser == INVALID_CHAIR) || (m_wProvideUser == m_wCurrentUser&&m_wResumeUser == m_wCurrentUser && m_cbProvideCard == 0))//牌权是摸牌得且没出牌
- {
- if (m_bTwoPlayerFlag)
- {
- OldUser = (m_wProvideUser - 2 + GAME_PLAYER) % GAME_PLAYER;
- }
- else
- {
- OldUser = (m_wProvideUser - 1 + mPlayGameUserCount) % mPlayGameUserCount;
- }
-
- BYTE TempIndex = 0;
- BYTE bDiscardCount = (m_cbDiscardCount[OldUser] - 1) >= 0 ? (m_cbDiscardCount[OldUser] - 1) : 0;
- for (BYTE i = bDiscardCount; i < 40; i++)
-
- {
- if (m_cbDiscardCard[OldUser][i] == 0)
- {
- TempIndex = i - 1;
- break;
- }
- }
- TempIndex = (TempIndex == 255) ? 0 : TempIndex;
- StatusPlay.bPutCardData[OldUser] = m_cbDiscardCard[OldUser][TempIndex];
- //}
- }
- if (m_wProvideUser == m_wOutCardUser && m_wCurrentUser == INVALID_CHAIR)//当有人可以碰且没有碰时候
- {
- StatusPlay.bPutCardData[m_wProvideUser] = m_cbProvideCard;
- StatusPlay.cbDiscardCard[m_wProvideUser][StatusPlay.cbDiscardCount[m_wProvideUser]++] = m_cbProvideCard;
- }
- if (wChiarID == StatusPlay.wCurrentUser&&m_wCurrentUser != INVALID_CHAIR&&m_wCurrentUser != m_wProvideUser)//表示当前牌权就在断线玩家手里,且是轮到他出牌(牌权碰来得)
- {
- ZeroMemory(StatusPlay.cbCardData, sizeof(StatusPlay.cbCardData));
- BYTE TempCardData[MAX_INDEX];
- CopyMemory(TempCardData, m_cbCardIndex[wChiarID], sizeof(TempCardData));
-
- BYTE TempEndCardData = m_GameLogic.GetEndCard(TempCardData);
- BYTE TempCardIndex = m_GameLogic.SwitchToCardIndex(TempEndCardData);
- if (TempCardData[TempCardIndex] == 0){ ASSERT(false); return false; }
- TempCardData[TempCardIndex]--;
- BYTE cardNum = m_GameLogic.SwitchToCardData(TempCardData, StatusPlay.cbCardData);
- StatusPlay.cbCardData[cardNum] = TempEndCardData;
- }
- if (wChiarID == StatusPlay.wCurrentUser && m_wCurrentUser != INVALID_CHAIR && m_wCurrentUser == m_wProvideUser)//牌权是轮到他抓牌,未打出
- {
- ZeroMemory(StatusPlay.cbCardData, sizeof(StatusPlay.cbCardData));
- BYTE TempCardData[MAX_INDEX];
- CopyMemory(TempCardData, m_cbCardIndex[wChiarID], sizeof(TempCardData));
- BYTE TempCardIndex = m_GameLogic.SwitchToCardIndex(m_cbProvideCard);
- if (m_cbCardIndex[wChiarID][TempCardIndex] == 0)ASSERT(false);
- TempCardData[TempCardIndex]--;
- BYTE cardNum = m_GameLogic.SwitchToCardData(TempCardData, StatusPlay.cbCardData);
- StatusPlay.cbCardData[cardNum] = m_GameLogic.SwitchToCardData(TempCardIndex);//处理得到最后一张牌数据放最后
- }
- //////////////////////////////////////////////////////////////////////////
-
- //发送场景
- return m_pITableFrame->SendGameScene(pIServerUserItem, &StatusPlay, sizeof(StatusPlay));
- }
-
- }
- return false;
- }
-
- //定时器事件
- bool CTableFrameSink_tdh::OnTimerMessage(DWORD wTimerID, WPARAM wBindParam)
- {
- return false;
- }
-
- //游戏消息处理
- void CTableFrameSink_tdh::SetGameConfig(VOID * pDataBuffer, WORD wDataSize, std::wstring sPrivateRoomId)
- {
- tagGameConfig* ppConfig = (tagGameConfig*)pDataBuffer;
- m_gameConfig.wSubGameID = ppConfig->wSubGameID;
- m_gameConfig.wDiScore = ppConfig->wPlayRule;
- m_gameConfig.wFanFei = ppConfig->wMaxFanRule;
- m_gameConfig.wIpLimit = ppConfig->wMaxScore;
- m_gameConfig.wPlayCountRule = ppConfig->wPlayCountRule;
- m_gameConfig.RoomId = ppConfig->wHadPlayCount;
- m_gameConfig.wHadPlayCount = 0;
- m_gameConfig.bDuoLai = ppConfig->bDuoLai;
- m_gameConfig.wFengDing = ppConfig->wFengDing;
- m_gameConfig.tmp1 = ppConfig->tmp1;
- if (m_gameConfig.wFengDing == 0 || m_gameConfig.wFengDing == 5)
- {
- mMaxTaiNum = 5;
- }
- else if (m_gameConfig.wFengDing == 6 || m_gameConfig.wFengDing == 7)
- {
- mMaxTaiNum = m_gameConfig.wFengDing;
- }
- else
- {
- mMaxTaiNum = 20;
- }
-
- lstrcpy(m_gameConfig.sPrivateTableID, sPrivateRoomId.c_str());
- m_cbTotalCardCount = MAX_REPERTORY_ZJ;
- //协议修改为 4 3 2
- if (m_gameConfig.tmp1 == 0)
- {
- mPlayGameUserCount = 4;
- }
- else
- {
- if (m_gameConfig.tmp1 == 2)
- {
- m_bTwoPlayerFlag = TRUE;
- mPlayGameUserCount = 3;
- m_cbTotalCardCount = MAX_REPERTORY_ZJ_Two;
- m_pITableFrame->SetStartMode(START_MODE_ALL_READY);
- }
- else
- {
- mPlayGameUserCount = m_gameConfig.tmp1;
- }
-
- }
-
- m_pITableFrame->SetChairCount(mPlayGameUserCount);
- ASSERT(m_gameConfig.wSubGameID >= 0 && m_gameConfig.wSubGameID < MahJongType::count);
-
- if (!sPrivateRoomId.empty())
- {
- mGameTableId = _wtoi(sPrivateRoomId.c_str());
- }
- else
- {
- mGameTableId = 1;
- }
- //1 不能放冲 0 能放冲胡吧
- CString strTmp;
- strTmp.Format(_T("bDuoLai=%d"), m_gameConfig.bDuoLai);
- OutputDebugString(strTmp);
- if (m_gameConfig.bDuoLai==1)
- {
- mCanFangChong = TRUE;
- }
- else
- {
- mCanFangChong = FALSE;
- }
- }
-
- //游戏消息处理
- bool CTableFrameSink_tdh::OnGameMessage(WORD wSubCmdID, VOID* pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem)
- {
-
-
- switch (wSubCmdID)
- {
- case SUB_C_OUT_CARD: //出牌消息
- {
- //定义变量
- SparrowMaJiang::PB_CS_C_OutCard OutCard;
- OutCard.ParseFromArray(pDataBuffer, wDataSize);
- //用户效验
- if (pIServerUserItem->GetUserStatus() != US_PLAYING) return true;
- //用户效验
- if (pIServerUserItem->GetUserStatus() != US_PLAYING) return true;
- bool bRet = OnUserOutCard(pIServerUserItem->GetChairID(), OutCard.cbcarddata());
- return bRet;
- }
- case SUB_C_OPERATE_CARD: //操作消息
- {
- SparrowMaJiang::PB_CS_C_OperateCard OperateCard;
- OperateCard.ParseFromArray(pDataBuffer, wDataSize);
-
- //用户效验
- if (pIServerUserItem->GetUserStatus() != US_PLAYING) return true;
- CMD_C_OperateCard pOperateCard;
- for (WORD i = 0; i < 4; i++)
- {
- pOperateCard.cbCaiShenCard[i] = OperateCard.cbcaishencard(i);
- }
- pOperateCard.cbOperateCard = OperateCard.cboperatecard();
- pOperateCard.cbOperateCode = OperateCard.cboperatecode();
- return OnUserOperateCard(pIServerUserItem->GetChairID(), pOperateCard.cbOperateCode, pOperateCard.cbOperateCard, pOperateCard.cbCaiShenCard);
- }
- case SUB_C_TRUSTEE: //托管
- {
- SparrowMaJiang::PB_CS_C_Trustee pTrustee;
- pTrustee.ParseFromArray(pDataBuffer, wDataSize);
- m_bTrustee[pIServerUserItem->GetChairID()] = pTrustee.btrustee();
- CMD_S_Trustee Trustee;
- Trustee.bTrustee = pTrustee.btrustee();
- Trustee.wChairID = pIServerUserItem->GetChairID();
-
- SparrowMaJiang::PB_CS_S_Trustee Trustees;
- Trustees.set_btrustee(Trustee.bTrustee);
- Trustees.set_wchairid(Trustee.wChairID);
- std::string pbdata = Trustees.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_TRUSTEE, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_TRUSTEE, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_TRUSTEE, (void*)pbdata.c_str(), pbdata.length());
-
- return true;
- }
- //case SUB_C_SELECT_BAO:{
- // CMD_C_BAO *pBaoTai = (CMD_C_BAO *)pDataBuffer;
- // SelectBaoTaiNum(pIServerUserItem->GetChairID(), pBaoTai->cbTaiNum);
- // return true;
- //}
- //case SUB_C_SELECT_CAI:{
- // CMD_C_Magic *pMagic = (CMD_C_Magic*)pDataBuffer;
- // SelectBaoMagic(pIServerUserItem->GetChairID(), pMagic->cbMagicFirst, pMagic->cbMagicSenced);
- // return true;
- //}
- default:
- return false;
- }
-
- return false;
- }
- //框架消息处理
- bool CTableFrameSink_tdh::OnFrameMessage(WORD wSubCmdID, VOID * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem)
- {
- return false;
- }
-
- //用户断线重连
- bool CTableFrameSink_tdh::OnActionUserConnect(WORD wChairID, IServerUserItem * pIServerUserItem)
- {
- auto dwUserID = pIServerUserItem->GetUserID();
-
- auto iter = std::find(m_offlineUsers.begin(), m_offlineUsers.end(), dwUserID);
- if (m_TabbOutCardCout[wChairID] > 0)
- HttpTingCard(wChairID);
- if (iter != end(m_offlineUsers))
- {
- m_offlineUsers.erase(iter); //玩家重新上线
- return true;
- }
- return true;
- }
-
- //用户坐下
- bool CTableFrameSink_tdh::OnActionUserSitDown(WORD wChairID, IServerUserItem * pIServerUserItem, bool bLookonUser)
- {
- // CString str;
- // str.Format(_T("椅子ID=%d 用户id=%d"),wChairID,pIServerUserItem->GetUserID());
- // OutputDebugString(str);
- return true;
- }
-
- //游戏中途旁观进入
- bool CTableFrameSink_tdh::PerformLookonLogin(IServerUserItem * pIServerUserItem)
- {
- CMD_S_PangGuan StatusPlay;
- memset(&StatusPlay, 0, sizeof(StatusPlay));
-
- //游戏房主基础配置
- CopyMemory(&StatusPlay.gameConfig, &m_gameConfig, sizeof(CMD_S_GameConfig));
- CopyMemory(StatusPlay.lUserTmpScore, m_lGameTatolScore, sizeof(m_lGameTatolScore));
- StatusPlay.cbTotalCardCount = m_cbTotalCardCount;
- StatusPlay.cbLeftCardCount = m_cbLeftCardCount;
- StatusPlay.gameConfig.IsOwner = m_pITableFrame->GetPrivateTableOwnerID() == pIServerUserItem->GetUserID() ? 1 : 0;
- StatusPlay.GameStatus = m_pITableFrame->IsDrawStarted();
- if (StatusPlay.GameStatus)
- {
- //游戏变量
- StatusPlay.wBankerUser = m_wBankerUser;
- WORD wSice = WORD(m_lSiceCount & 0xffff);
- StatusPlay.lSiZi[0] = HIBYTE(wSice);
- StatusPlay.lSiZi[1] = LOBYTE(wSice);
- StatusPlay.lSiZi[2] = m_cbMagicFirstData;
- StatusPlay.lSiZi[3] = m_cbMagicSecondData;
-
- StatusPlay.dwOwnerID = m_pITableFrame->GetPrivateTableOwnerID();
-
-
- CopyMemory(StatusPlay.cbDiscardCard, m_cbDiscardCard, sizeof(StatusPlay.cbDiscardCard));
- CopyMemory(StatusPlay.cbDiscardCount, m_cbDiscardCount, sizeof(StatusPlay.cbDiscardCount));
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- //StatusPlay.bWanLaiZi[i] = m_OutLaiZi[i];
- //StatusPlay.bWanLaiZi[i] |= (m_OutHongZhongGang[i] << 4);
- //StatusPlay.bWanLaiZi[i] |= (m_OutFaCaiGang[i] << 8);
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- StatusPlay.cbCardCount[i] = m_GameLogic.GetCardCount(m_cbCardIndex[i]);
- }
- StatusPlay.totalOptTime = 10;
- StatusPlay.leftOptTime = 0;
- ASSERT(m_wProvideUser >= 0 && m_wProvideUser <= 3);
- //当前到谁家
- StatusPlay.wCurrentUser = (m_wCurrentUser == INVALID_CHAIR ? m_wProvideUser : m_wCurrentUser);
- WORD OldUser = 0;//定义一个最后出牌用户`
-
- if (m_wProvideUser == m_wCurrentUser&&m_wOutCardUser == INVALID_CHAIR)//牌权是摸牌得且没出牌
- {
- //if (m_bGangStatus)
- //{
- // StatusPlay.bPutCardData[m_wProvideUser] = m_OutLastLaiZiData;
- //}
- //else
- //{
- if (m_bTwoPlayerFlag)
- {
- OldUser = (m_wProvideUser - 2 + GAME_PLAYER) % GAME_PLAYER;
- }
- else
- {
- OldUser = (m_wProvideUser - 1 + mPlayGameUserCount) % mPlayGameUserCount;
- }
- BYTE TempIndex = 0;
- BYTE bDiscardCount = (m_cbDiscardCount[OldUser] - 1) >= 0 ? (m_cbDiscardCount[OldUser] - 1) : 0;
- for (BYTE i = bDiscardCount; i < 40; i++)
- {
- if (m_cbDiscardCard[OldUser][i] == 0)
- {
- TempIndex = i - 1;
- break;
- }
- }
- TempIndex = (TempIndex == 255) ? 0 : TempIndex;
- StatusPlay.bPutCardData[OldUser] = m_cbDiscardCard[OldUser][TempIndex];
- //}
- }
- if (m_wProvideUser == m_wOutCardUser&& m_wCurrentUser == INVALID_CHAIR)//当有人可以碰且没有碰时候
- {
- StatusPlay.bPutCardData[m_wProvideUser] = m_cbProvideCard;
- StatusPlay.cbDiscardCard[m_wProvideUser][StatusPlay.cbDiscardCount[m_wProvideUser]++] = m_cbProvideCard;
- }
- //组合扑克
- CopyMemory(StatusPlay.WeaveItemArray, m_WeaveItemArray, sizeof(m_WeaveItemArray));
- CopyMemory(StatusPlay.cbWeaveCount, m_cbWeaveItemCount, sizeof(m_cbWeaveItemCount));
-
-
- }
-
- SparrowMaJiang::PB_CS_S_PangGuan PangGuan;
- PangGuan.mutable_gameconfig()->set_bduolai(StatusPlay.gameConfig.bDuoLai);
- PangGuan.mutable_gameconfig()->set_isowner(StatusPlay.gameConfig.IsOwner);
- PangGuan.mutable_gameconfig()->set_roomid(StatusPlay.gameConfig.RoomId);
- std::string sPrivateTableID = CW2AEX<1024>(StatusPlay.gameConfig.sPrivateTableID, CP_UTF8).m_psz;
- PangGuan.mutable_gameconfig()->set_sprivatetableid(sPrivateTableID);
- PangGuan.mutable_gameconfig()->set_tmp1(StatusPlay.gameConfig.tmp1);
- PangGuan.mutable_gameconfig()->set_tmp2(StatusPlay.gameConfig.tmp2);
- PangGuan.mutable_gameconfig()->set_wdiscore(StatusPlay.gameConfig.wDiScore);
- PangGuan.mutable_gameconfig()->set_wfanfei(StatusPlay.gameConfig.wFanFei);
- PangGuan.mutable_gameconfig()->set_wfengding(StatusPlay.gameConfig.wFengDing);
- PangGuan.mutable_gameconfig()->set_whadplaycount(StatusPlay.gameConfig.wHadPlayCount);
- PangGuan.mutable_gameconfig()->set_wiplimit(StatusPlay.gameConfig.wIpLimit);
- PangGuan.mutable_gameconfig()->set_wplaycountrule(StatusPlay.gameConfig.wPlayCountRule);
- PangGuan.mutable_gameconfig()->set_wsubgameid(StatusPlay.gameConfig.wSubGameID);
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- PangGuan.add_lusertmpscore(StatusPlay.lUserTmpScore[j]);
- PangGuan.add_bputcarddata(StatusPlay.bPutCardData[j]);
- PangGuan.add_cbcardcount(StatusPlay.cbCardCount[j]);
- PangGuan.add_cbweavecount(StatusPlay.cbWeaveCount[j]);
- PangGuan.add_cbdiscardcount(StatusPlay.cbDiscardCount[j]);
- SparrowMaJiang::pb_cbDiscardCard* DiscardCard = PangGuan.add_cbdiscardcard();
- for (BYTE i = 0; i < 40; i++)
- {
- DiscardCard->add_cbdiscardcard(StatusPlay.cbDiscardCard[j][i]);
- }
- SparrowMaJiang::pb_WeaveItemArray* WeaveItemArray = PangGuan.add_weaveitemarray();
- for (BYTE i = 0; i < 4; i++)
- {
- SparrowMaJiang::pb_WeaveItem* WeaveItem = WeaveItemArray->add_weaveitem();
- WeaveItem->set_cbcentercard(StatusPlay.WeaveItemArray[j][i].cbCenterCard);
- WeaveItem->set_cbpubliccard(StatusPlay.WeaveItemArray[j][i].cbPublicCard);
- WeaveItem->set_cbweavekind(StatusPlay.WeaveItemArray[j][i].cbWeaveKind);
- WeaveItem->set_wprovideuser(StatusPlay.WeaveItemArray[j][i].wProvideUser);
- for (BYTE k = 0; k < 4; k++)
- {
- WeaveItem->add_cbmargicoffset(StatusPlay.WeaveItemArray[j][i].cbMargicOffset[k]);
- }
- }
- }
- PangGuan.set_gamestatus(StatusPlay.GameStatus);
- PangGuan.set_cbtotalcardcount(StatusPlay.cbTotalCardCount);
- PangGuan.set_cbleftcardcount(StatusPlay.cbLeftCardCount);
- PangGuan.set_wbankeruser(StatusPlay.wBankerUser);
- for (BYTE j = 0; j < 4; j++)
- {
- PangGuan.add_lsizi(StatusPlay.lSiZi[j]);
- }
- PangGuan.set_dwownerid(StatusPlay.dwOwnerID);
- PangGuan.set_wcurrentuser(StatusPlay.wCurrentUser);
- PangGuan.set_totalopttime(StatusPlay.totalOptTime);
- PangGuan.set_leftopttime(StatusPlay.leftOptTime);
- std::string pbdata = PangGuan.SerializePartialAsString();
- return m_pITableFrame->SendUserItemData(pIServerUserItem, SUB_S_PANGGUAN, (void*)pbdata.c_str(), pbdata.length());
- }
-
- //用户起来
- bool CTableFrameSink_tdh::OnActionUserStandUp(WORD wChairID, IServerUserItem * pIServerUserItem, bool bLookonUser)
- {
- //庄家设置
- if (bLookonUser == false && !QueryUseTemporaryScore())
- {
- m_bTrustee[wChairID] = false;
- CMD_S_Trustee Trustee;
- Trustee.bTrustee = false;
- Trustee.wChairID = wChairID;
-
- SparrowMaJiang::PB_CS_S_Trustee Trustees;
- Trustees.set_btrustee(Trustee.bTrustee);
- Trustees.set_wchairid(Trustee.wChairID);
- std::string pbdata = Trustees.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_TRUSTEE, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_TRUSTEE, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_TRUSTEE, (void*)pbdata.c_str(), pbdata.length());
- }
-
- return true;
- }
-
- //用户出牌
- bool CTableFrameSink_tdh::OnUserOutCard(WORD wChairID, BYTE cbCardData)
- {
- m_cbLastGangCard = 0;
- //if (mMjType == 1 && mbStartBaoTai != 3)
- //{
- // return false;
- //}
- m_bQiangGang = false;
- //效验状态
- ASSERT(m_pITableFrame->GetGameStatus() == GS_MJ_PLAY);
- if (m_pITableFrame->GetGameStatus() != GS_MJ_PLAY) return true;
-
- //错误断言
- ASSERT(wChairID == m_wCurrentUser);
- ASSERT(m_GameLogic.IsValidCard(cbCardData) == true);
-
- //效验参数
- if (wChairID != m_wCurrentUser) return false;
- if (m_GameLogic.IsValidCard(cbCardData) == false) return false;
- if ((m_GameLogic.GetCardCount(m_cbCardIndex[wChairID]) - 2) % 3 != 0)
- {
- return false;
- }
-
-
- //“吃”的不能出(一圈内),特例:大吊车时(即只剩两张牌)
- if (m_cbOptCard[wChairID] == cbCardData)
- {
- return false;
- }
- //删除扑克
- if (m_GameLogic.RemoveCard(m_cbCardIndex[wChairID], cbCardData) == false)
- {
- ASSERT(FALSE);
- return false;
- }
- ZeroMemory(&m_cbOptCard[wChairID], sizeof(m_cbOptCard[wChairID]));
- //清除记忆库
- ZeroMemory(&m_cbLastDisCardData[wChairID], sizeof(m_cbLastDisCardData[wChairID]));
- m_cbLastDisCount[wChairID] = 0;
-
- //for (BYTE i = 0; i < GAME_PLAYER; i++)
- //{
- // if (i == wChairID)continue;
- // m_cbLastDisCardData[i][m_cbLastDisCount[i]++] = cbCardData;//打出得牌,放到其他玩家得记忆库里面
- //}
-
- //m_bSendStatus = true;
- //if (m_bGangStatus)
- //{
- //m_OutLastLaiZiData = 0; //最后杠牌数据,断线重连用的着
- //m_bGangStatus = false;
- ZeroMemory(m_bUsersGangStatus, GAME_PLAYER);
- m_bGangOption = 0;
- m_GangPrivedUserID = -1;
- //m_bGangOutStatus = true;
- //}
- m_cbUserAction[wChairID] = WIK_NULL;
- m_cbPerformAction[wChairID] = WIK_NULL;
-
- //出牌记录
- m_cbOutCardCount++;
- m_wOutCardUser = wChairID; //记录出牌人
- m_cbOutCardData = cbCardData; //记录出牌数据
-
- m_TabbOutCardCout[wChairID] = 0; //可以打出的牌就听牌的个数
- ZeroMemory(m_TabbOutCardData[wChairID], sizeof(m_TabbOutCardData[wChairID])); //具体打哪几张牌
- ZeroMemory(m_TabbTingCardCount[wChairID], sizeof(m_TabbTingCardCount[wChairID])); //相对应打出牌可听牌个数,索引表示第几张,值是对应对应的听牌个数
- ZeroMemory(m_TabbTingCardData[wChairID], sizeof(m_TabbTingCardData[wChairID])); //具体听牌数据,一维索引表示打出牌的第几个,二维索引表示听牌的第几个,值表示牌数据
- BYTE FanHui[MAX_INDEX] = { 0 };
- /*m_GameLogic.IsCanChangCardAndCount(m_cbCardIndex[wChairID], FanHui);
- if (m_GameLogic.IsTingCard(m_cbCardIndex[wChairID], m_WeaveItemArray[wChairID], m_cbWeaveItemCount[wChairID], FanHui))
- {*/
- OutTingCard(wChairID, m_GameLogic.SwitchToCardIndex(m_cbOutCardData));
- //}
- //构造数据
- CMD_S_OutCard OutCard;
- OutCard.wOutCardUser = wChairID;
- OutCard.cbOutCardData = cbCardData;
- OutCard.bOptType = 0;
-
- SparrowMaJiang::PB_CS_S_OutCard Card;
- Card.set_woutcarduser(OutCard.wOutCardUser);
- Card.set_cboutcarddata(OutCard.cbOutCardData);
- Card.set_bopttype(OutCard.bOptType);
- //发送数据
- std::string pbdata = Card.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_OUT_CARD, (void*)pbdata.c_str(), pbdata.length());
- //发送消息
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_OUT_CARD, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_OUT_CARD, (void*)pbdata.c_str(), pbdata.length());
- m_wProvideUser = wChairID;
- m_cbProvideCard = cbCardData;
- //用户切换
-
-
- if (m_bTwoPlayerFlag)
- {
- m_wCurrentUser = (wChairID + 2) % GAME_PLAYER;
- }
- else
- {
- m_wCurrentUser = (wChairID + 1) % mPlayGameUserCount;
- }
- //响应判断
- //推倒胡,增加玩家出的牌如果是最后一张(出牌后无牌可发),此时不允许其他玩家有吃碰杠的操作。直接流局。
- bool bAroseAction = false;
- if (m_cbLeftCardCount==0)
- {
- bAroseAction = false;
- }
- else
- {
- bAroseAction = EstimateUserRespond(wChairID, cbCardData, EstimatKind_OutCard);
- }
- //派发扑克
- if (bAroseAction == false)
- {
- DispatchCardData(m_wCurrentUser);
- }
- return true;
- }
-
- //用户操作
- bool CTableFrameSink_tdh::OnUserOperateCard(WORD wChairID, int cbOperateCode, BYTE cbOperateCard, BYTE cbCaiShenCard[4])
- {
-
- //效验状态
- ASSERT(m_pITableFrame->GetGameStatus() == GS_MJ_PLAY);
- if (m_pITableFrame->GetGameStatus() != GS_MJ_PLAY)
- return true;
-
- //效验用户 注意:机器人有可能发生此断言
- //ASSERT((wChairID==m_wCurrentUser)||(m_wCurrentUser==INVALID_CHAIR));
- if ((wChairID != m_wCurrentUser) && (m_wCurrentUser != INVALID_CHAIR))
- return true;
-
- tagGangCardResult GangCardResult;
- ZeroMemory(&GangCardResult, sizeof(GangCardResult));
- //被动动作
- if (m_wCurrentUser == INVALID_CHAIR&&wChairID != m_wProvideUser)//表示有人出牌后,下一个人还未摸牌这段时间内,有人对上一张出牌有吃胡、杠、碰等操作
- {
- //效验状态
- if (m_bResponse[wChairID] == true)
- return true;
- if ((cbOperateCode != WIK_NULL) && ((m_cbUserAction[wChairID] & cbOperateCode) == 0))
- return true;
- //变量定义
-
-
- WORD wTargetUser = wChairID;
- int cbTargetAction = cbOperateCode;
-
- //设置变量
- m_bResponse[wChairID] = true;
- m_cbPerformAction[wChairID] = cbOperateCode;
- m_cbOperateCard[wChairID] = cbOperateCard;
- CopyMemory(m_cbOperateCaiCard[wChairID], cbCaiShenCard, sizeof(cbCaiShenCard));
-
-
-
- //执行动作的优先级判断, WIK_CHI_HU 大于 WIK_PENG 大于 [WIK_RIGHT or WIK_CENTER or WIK_LEFT]
- WORD TempUser = m_wProvideUser;
- OperatorPriority(TempUser, wTargetUser, cbTargetAction);
-
- if (m_bResponse[wTargetUser] == false)//操作判断
- {
- if (cbOperateCode == WIK_NULL)
- m_cbLastDisCardData[wChairID][m_cbLastDisCount[wChairID]++] = m_cbProvideCard;
- return true;
- }
-
-
-
- //放弃操作
- if (m_bQiangGang&&cbOperateCard == 0 && cbTargetAction &WIK_ZI_MO)//此处if 主要用于解决,用户抢杠胡那一刻,断线重连。客户端不知道用户抢的那张牌。所以必须后台强制处理一下。
- {
- m_cbOperateCard[wTargetUser] = m_cbProvideCard;
-
- }
- else
- {
- m_bQiangGang = false;
- }
-
- if (cbOperateCode == WIK_NULL &&cbTargetAction == WIK_NULL)
- {
- //用户状态
- ZeroMemory(m_bResponse, sizeof(m_bResponse));
- ZeroMemory(m_cbUserAction, sizeof(m_cbUserAction));
- ZeroMemory(m_cbOperateCard, sizeof(m_cbOperateCard));
- ZeroMemory(m_cbPerformAction, sizeof(m_cbPerformAction));
- //当该用户点过时 加入该张牌
- //if(wTargetUser==wChairID)
- //{
- m_cbLastDisCardData[wTargetUser][m_cbLastDisCount[wTargetUser]++] = m_cbProvideCard;
- //}
- if (m_wCurrentUser == INVALID_CHAIR)
- DispatchCardData(m_wResumeUser);
-
-
- return true;
- }
- //变量定义
- BYTE cbTargetCard = m_cbOperateCard[wTargetUser];
- BYTE cbTargetCaiCard[4] = { 0 };
- CopyMemory(cbTargetCaiCard, m_cbOperateCaiCard[wTargetUser], sizeof(cbTargetCaiCard));
-
- if (cbTargetCard != m_cbProvideCard)//校验很重要
- {
- m_bResponse[wTargetUser] = false;
- ASSERT(false);
- return false;
- }
- //出牌变量
- m_cbOutCardData = 0;
- //m_bSendStatus = true;
- m_wOutCardUser = INVALID_CHAIR;
- //m_bEnjoinChiHu[wTargetUser] = true;
-
- //用户状态
- ZeroMemory(m_bResponse, sizeof(m_bResponse));
- ZeroMemory(m_cbUserAction, sizeof(m_cbUserAction));
- ZeroMemory(m_cbOperateCard, sizeof(m_cbOperateCard));
- ZeroMemory(m_cbPerformAction, sizeof(m_cbPerformAction));
-
-
- //组合扑克
- if (cbTargetAction&(WIK_LEFT | WIK_CENTER | WIK_RIGHT | WIK_PENG | WIK_MING_GANG))
- {
- ASSERT(m_cbWeaveItemCount[wTargetUser] < 4);
- if (m_cbWeaveItemCount[wTargetUser] > 4)return false;
- WORD wIndex = m_cbWeaveItemCount[wTargetUser]++;
- m_WeaveItemArray[wTargetUser][wIndex].cbPublicCard = TRUE;
- m_WeaveItemArray[wTargetUser][wIndex].cbCenterCard = cbTargetCard;
- m_WeaveItemArray[wTargetUser][wIndex].cbWeaveKind = cbTargetAction;
- m_WeaveItemArray[wTargetUser][wIndex].wProvideUser = (m_wProvideUser == INVALID_CHAIR) ? wTargetUser : m_wProvideUser;
- //本轮操作后 不允许打该张牌
- m_cbOptCard[wTargetUser] = cbTargetCard;
-
-
- }
- if (cbTargetAction &WIK_ZI_MO)//此动作为抢杠胡才会促发
- {
- m_bQiangGang = true;
- //m_bGangStatus = false;
- ZeroMemory(m_bUsersGangStatus, GAME_PLAYER);
- m_wCurrentUser = wTargetUser;
- m_wProvideUser = m_wProvideUser;
- m_cbSendCardData = m_cbProvideCard;
- m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)]++;
- m_cbUserAction[wTargetUser] = WIK_ZI_MO;
- OnUserOperateCard(wTargetUser, WIK_ZI_MO, m_cbProvideCard, NULL);
- return true;
- }
-
- if (cbTargetAction& WIK_CHI_HU&&mCanFangChong==TRUE)
- {
- int TempAction = 0;
- CChiHuRight chr;
- BYTE TaiShu = 0;
- TempAction |= m_GameLogic.AnalyseChiHuCard(m_cbCardIndex[wTargetUser], m_WeaveItemArray[wTargetUser],
- m_cbWeaveItemCount[wTargetUser], m_cbProvideCard, chr, TaiShu);
- if (TempAction == WIK_NULL)
- {
- ASSERT(false);
- return false;
- }
- m_HuPai[wTargetUser]++;
- CMD_S_OperateResult OperateResult;
- OperateResult.wOperateUser = wTargetUser;
- OperateResult.cbOperateCard = cbOperateCard;
- OperateResult.cbOperateCode = cbOperateCode;
- OperateResult.wProvideUser = (m_wProvideUser == INVALID_CHAIR) ? wTargetUser : m_wProvideUser;
- WORD paitype = bHuPaiType(chr);
-
-
- if (!(chr&ZJ_TAI_CaiDiao).IsEmpty())
- {
- OperateResult.cbOperateCode = WIK_CAIDIAO;
- }
- if (!(chr&ZJ_TAI_SiCaiHu).IsEmpty())
- {
- OperateResult.cbOperateCode = WIK_SI_CAIHU;
- }
-
- OperateResult.cbActionMask = TaiShu | (paitype << 16);
-
-
- ZeroMemory(OperateResult.cbActionCard, sizeof(OperateResult.cbActionCard));
- SparrowMaJiang::PB_CS_S_OperateResult Result;
- Result.set_woperateuser(OperateResult.wOperateUser);
- Result.set_cboperatecard(OperateResult.cbOperateCard);
- Result.set_cboperatecode(OperateResult.cbOperateCode);
- Result.set_wprovideuser(OperateResult.wProvideUser);
- for (BYTE j = 0; j < 4; j++)
- {
- Result.add_cbcaishencard(OperateResult.cbCaiShenCard[j]);
- }
- Result.set_cbactionmask(OperateResult.cbActionMask);
- for (BYTE j = 0; j < 6; j++)
- {
- Result.add_cbactioncard(OperateResult.cbActionCard[j]);
- }
- //发送数据
- std::string pbdata = Result.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- //发送消息
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
-
- //积分变动
- CMD_S_GangScore gs;
- ZeroMemory(&gs, sizeof(gs));
- gs.wChairId = wTargetUser;
- gs.cbOperateCode = WIK_CHI_HU;
-
- int TempInfoScore = 0;
- WORD LaoZhuang = m_wBankerUser & 0x00ff;
-
- if (LianXuHuPai[LaoZhuang] >= 2)
- {
- TaiShu *= 2;
- }
-
- CaculationScore(wTargetUser, TaiShu, Win_FangPao, m_wProvideUser, chr, gs);
-
-
- LianXuHuPai[wTargetUser]++;
-
-
- SparrowMaJiang::PB_CS_S_GangScore GangScore;
- GangScore.set_cboperatecode(gs.cbOperateCode);
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- GangScore.add_cbwanjiascore(gs.cbWanJiaScore[j]);
- GangScore.add_lgangscore(gs.lGangScore[j]);
- }
- GangScore.set_wchairid(gs.wChairId);
- std::string pbscore = GangScore.SerializePartialAsString();
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- gs.cbWanJiaScore[i] = m_lGameScore[i];
- }
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- GangScore.set_cbwanjiascore(j, gs.cbWanJiaScore[j]);
- }
- std::string pbscores = GangScore.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscores.c_str(), pbscores.length());
- OnEventGameConclude(wTargetUser, NULL, GER_NORMAL);
- return true;
- }
-
-
-
-
-
-
-
- DeleteCaiShenCard(wTargetUser, cbTargetCaiCard, cbTargetAction, cbTargetCard);
- //杠牌处理
- if (cbTargetAction & (WIK_MING_GANG | WIK_DAN_MING_GANG | WIK_SHUANG_MING_GANG | WIK_SAN_MING_GANG))
- {
- int cbActionMask = WIK_NULL;
- WORD cbActionCard[6] = { 0 };
- HttpOperateResult(wTargetUser, cbTargetCaiCard, cbTargetAction, cbTargetCard, cbActionMask, cbActionCard);
-
- //设置用户
- m_wCurrentUser = wTargetUser;
- m_bGangOption = cbTargetAction;
- m_GangPrivedUserID = m_wProvideUser;
- //本轮操作后 不允许打该张牌
- m_cbOptCard[wTargetUser] = cbTargetCard;
-
-
- m_cbLastGangCard = cbOperateCard;
- DispatchCardData(wTargetUser, true);
- return true;
- }
- else
- {
- WORD cbActionCard[6] = { 0 };
- int cbActionMask = NULL;
- ZeroMemory(m_TabbTingCardData[wTargetUser], sizeof(m_TabbTingCardData[wTargetUser])); //具体听牌数据,一维索引表示打出牌的第几个,二维索引表示听牌的第几个,值表示牌数据
-
- TingCard(wTargetUser);
- HttpOperateResult(wTargetUser, cbTargetCaiCard, cbTargetAction, cbTargetCard, cbActionMask, cbActionCard);
- //设置用户
- m_wCurrentUser = wTargetUser;
- if (m_TabbOutCardCout[wTargetUser] > 0)//有听牌就发一个听牌协议
- {
- HttpTingCard(wTargetUser);
- }
- return true;
- }
- ASSERT(false);
- return false;
- }
- //主动动作
- if (m_wCurrentUser == wChairID) //如果是摸牌用户的操作,比如自摸或者自杠
- {
- if (cbOperateCode == WIK_NULL)
- {
- //用户状态
- ZeroMemory(m_bResponse, sizeof(m_bResponse));
- ZeroMemory(m_cbUserAction, sizeof(m_cbUserAction));
- ZeroMemory(m_cbOperateCard, sizeof(m_cbOperateCard));
- ZeroMemory(m_cbPerformAction, sizeof(m_cbPerformAction));
- //发送扑克
- return true;
- }
- //效验操作
- if ((cbOperateCode == WIK_NULL) || ((m_cbUserAction[wChairID] & cbOperateCode) == 0))
- return true;
- //设置变量
- //m_bSendStatus = true;
- //m_bEnjoinChiHu[m_wCurrentUser]=true;
- m_cbUserAction[m_wCurrentUser] = WIK_NULL;
- m_cbPerformAction[m_wCurrentUser] = WIK_NULL;
- bool bPublic = false;
- //执行动作
- if (cbOperateCode & (WIK_TIAN_ZI_MO | WIK_ZI_MO))
- {
- BYTE TempCardData = m_cbProvideCard;
- if (m_cbProvideCard != m_cbSendCardData || m_cbProvideCard != cbOperateCard)
- {
- ASSERT(false);
- return false;
- }
- int TempAction = 0;
- CChiHuRight chr;
- BYTE TaiShu = 1;
- m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)]--;
-
- TempAction |= m_GameLogic.AnalyseChiHuCard(m_cbCardIndex[wChairID], m_WeaveItemArray[wChairID],
- m_cbWeaveItemCount[wChairID], m_cbSendCardData, chr, TaiShu, m_bUsersGangStatus[wChairID], m_bQiangGang);
-
- m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)]++;
- if (TempAction == WIK_NULL)
- {
- ASSERT(false);
- return false;
- }
- m_HuPai[wChairID]++;
- CMD_S_OperateResult OperateResult;
- OperateResult.wOperateUser = wChairID;
- OperateResult.cbOperateCard = cbOperateCard;
- OperateResult.cbOperateCode = cbOperateCode;
- OperateResult.wProvideUser = (m_wProvideUser == INVALID_CHAIR) ? wChairID : m_wProvideUser;
- WORD paitype = bHuPaiType(chr);
- if (m_bUsersGangStatus[wChairID] == true)
- {
- paitype |= ZJ_TAI_GangKai;
- chr |= ZJ_TAI_GangKai;
- }
-
- if (m_bQiangGang == true)
- {
- paitype |= ZJ_TAI_QiangGang;
- chr |= ZJ_TAI_QiangGang;
- }
-
- if (!(chr&ZJ_TAI_CaiDiao).IsEmpty())
- {
- OperateResult.cbOperateCode = WIK_CAIDIAO;
- }
- if (!(chr&ZJ_TAI_SiCaiHu).IsEmpty())
- {
- OperateResult.cbOperateCode = WIK_SI_CAIHU;
- }
- if (!(chr&ZJ_TAI_GangKai).IsEmpty())
- {
- OperateResult.cbOperateCode = WIK_GANG_SHANG_KAI;
- }
-
- if (!(chr&ZJ_TAI_QiangGang).IsEmpty())
- {
- OperateResult.cbOperateCode = WIK_Qiang_GANG;
- m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)]--;
- }
-
- OperateResult.cbActionMask = TaiShu | (paitype << 16);
- //OperateResult.cbActionMask = paitype;
-
-
- ZeroMemory(OperateResult.cbActionCard, sizeof(OperateResult.cbActionCard));
- SparrowMaJiang::PB_CS_S_OperateResult Result;
- Result.set_woperateuser(OperateResult.wOperateUser);
- Result.set_cboperatecard(OperateResult.cbOperateCard);
- Result.set_cboperatecode(OperateResult.cbOperateCode);
- Result.set_wprovideuser(OperateResult.wProvideUser);
- for (BYTE j = 0; j < 4; j++)
- {
- Result.add_cbcaishencard(OperateResult.cbCaiShenCard[j]);
- }
- Result.set_cbactionmask(OperateResult.cbActionMask);
- for (BYTE j = 0; j < 6; j++)
- {
- Result.add_cbactioncard(OperateResult.cbActionCard[j]);
- }
- //发送数据
- std::string pbdata = Result.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- //发送消息
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
-
- //积分变动
- CMD_S_GangScore gs;
- ZeroMemory(&gs, sizeof(gs));
- gs.wChairId = wChairID;
- gs.cbOperateCode = WIK_ZI_MO;
- if (m_bQiangGang == true){
- gs.cbOperateCode = WIK_Qiang_GANG;
- }
- else
- {
- gs.cbOperateCode = WIK_ZI_MO;
- }
- int TempInfoScore = 0;
- WORD LaoZhuang = m_wBankerUser & 0x00ff;
-
- if (LianXuHuPai[LaoZhuang] >= 2)
- {
- TaiShu *= 2;
-
- }
-
-
- CaculationScore(wChairID, TaiShu, Win_ZiMo, m_wProvideUser, chr, gs);
-
-
- LianXuHuPai[wChairID]++;
-
-
- SparrowMaJiang::PB_CS_S_GangScore GangScore;
- GangScore.set_cboperatecode(gs.cbOperateCode);
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- GangScore.add_cbwanjiascore(gs.cbWanJiaScore[j]);
- GangScore.add_lgangscore(gs.lGangScore[j]);
- }
- GangScore.set_wchairid(gs.wChairId);
- std::string pbscore = GangScore.SerializePartialAsString();
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- gs.cbWanJiaScore[i] = m_lGameScore[i];
- }
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- GangScore.set_cbwanjiascore(j, gs.cbWanJiaScore[j]);
- }
- std::string pbrecord = GangScore.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbrecord.c_str(), pbrecord.length());
- OnEventGameConclude(wChairID, NULL, GER_NORMAL);
- return true;
- }
- if (cbOperateCode & (WIK_DAN_BU_GANG | WIK_BU_GANG))
- {
- DeleteCard(wChairID, cbCaiShenCard, cbOperateCode, cbOperateCard);
- int cbActionMask = WIK_NULL;
- WORD cbActionCard[6] = { 0 };
- HttpOperateResult(wChairID, cbCaiShenCard, cbOperateCode, cbOperateCard, cbActionMask, cbActionCard);
- m_cbLastGangCard = cbOperateCard;
- //响应判断
- m_wProvideUser = wChairID;
- m_bQiangGang = true;
- m_bUsersGangStatus[wChairID] = true;
- bool bAroseAction = EstimateUserRespond(wChairID, cbOperateCard, EstimatKind_GangCard);//补杠,别人可以抢杠胡
- //派发扑克
- if (bAroseAction == false)
- {
- m_bQiangGang = false;
- m_bGangOption = cbOperateCode;
- m_GangPrivedUserID = m_wCurrentUser;
- DispatchCardData(m_wCurrentUser, true);
- }
- else
- {
- //m_bGangStatus = false;
- m_bQiangGang = true;
- }
- return true;
- }
- if (cbOperateCode&WIK_AN_GANG)
- {
- m_cbLastGangCard = cbOperateCard;
- }
- DeleteCard(wChairID, cbCaiShenCard, cbOperateCode, cbOperateCard);
- int cbActionMask = WIK_NULL;
- WORD cbActionCard[6] = { 0 };
- HttpOperateResult(wChairID, cbCaiShenCard, cbOperateCode, cbOperateCard, cbActionMask, cbActionCard);
- DispatchCardData(wChairID, true);
- return true;
- }
- return true;
- }
-
- //发送操作
- bool CTableFrameSink_tdh::SendOperateNotify()
- {
- //发送提示
- for (WORD i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- if (m_cbUserAction[i] != WIK_NULL)
- {
- //构造数据
- CMD_S_OperateNotify OperateNotify;
- OperateNotify.wResumeUser = m_wResumeUser;
- OperateNotify.cbActionCard = m_cbProvideCard;
- OperateNotify.cbActionMask = m_cbUserAction[i];
-
- SparrowMaJiang::PB_CS_S_OperateNotify Notify;
- Notify.set_wresumeuser(OperateNotify.wResumeUser);
- Notify.set_cbactioncard(OperateNotify.cbActionCard);
- Notify.set_cbactionmask(OperateNotify.cbActionMask);
- std::string pbdata = Notify.SerializePartialAsString();
- //发送数据
- m_pITableFrame->SendTableData(i, SUB_S_OPERATE_NOTIFY, (void*)pbdata.c_str(), pbdata.length());
-
- ////-沙 前端需要展示提示数据
- OperateNotify.wResumeUser = i;
- Notify.set_wresumeuser(OperateNotify.wResumeUser);
- std::string pbdatas = Notify.SerializePartialAsString();
- RepayRecord(i, SUB_S_OPERATE_NOTIFY, (void*)pbdatas.c_str(), pbdatas.length());
-
- }
- }
- //m_pITableFrame->SendLookonData(i, SUB_S_OPERATE_NOTIFY, &OperateNotify, sizeof(OperateNotify));
- return true;
- }
-
- //派发扑克,wCurrentUser表示给哪个用户,bTail表示是末尾拿牌还是不是,true表示末尾,同时标示杠牌抓牌
- bool CTableFrameSink_tdh::DispatchCardData(WORD wCurrentUser, bool bTail)
- {
- //状态效验
- ASSERT(wCurrentUser != INVALID_CHAIR);
- if (wCurrentUser == INVALID_CHAIR)
- return false;
- //丢弃扑克
- if ((m_wOutCardUser != INVALID_CHAIR) && (m_cbOutCardData != 0))
- {
- m_cbDiscardCount[m_wOutCardUser]++;
- m_cbDiscardCard[m_wOutCardUser][m_cbDiscardCount[m_wOutCardUser] - 1] = m_cbOutCardData;
- }
- //清除当前玩家的碰 杠
- ZeroMemory(&m_cbOptCard[wCurrentUser], sizeof(m_cbOptCard[wCurrentUser]));
- //荒庄结束
- if (m_cbLeftCardCount == 0)
- {
- //m_cbChiHuCard = 0;
- m_wProvideUser = INVALID_CHAIR;
- bIsHuang = true;
-
- OnEventGameConclude(m_wProvideUser, NULL, GER_NORMAL);
- return true;
- }
-
- //设置变量
- m_cbOutCardData = 0;
- m_wCurrentUser = wCurrentUser; //记录拿牌人的索引。
- m_wOutCardUser = INVALID_CHAIR; //置空上次出牌用户的索引
- BYTE ActionCard[3] = { 0 }; //操作牌值
- BYTE AnActionCount = 0;
- //发送扑克
- m_cbSendCardCount++;
- --m_cbLeftCardCount;//剩余牌减少
- m_cbSendCardData = m_cbRepertoryCard[--m_cbShiJiLeftCardCount];//实际剩余牌减少
- CChiHuRight chr;
- BYTE TaiShu = 0;
- m_bUsersGangStatus[wCurrentUser] = bTail;
-
- m_cbUserAction[wCurrentUser] |= m_GameLogic.AnalyseChiHuCard(m_cbCardIndex[wCurrentUser], m_WeaveItemArray[wCurrentUser],
- m_cbWeaveItemCount[wCurrentUser], m_cbSendCardData, chr, TaiShu, bTail);
-
- //加牌
- m_cbCardIndex[wCurrentUser][m_GameLogic.SwitchToCardIndex(m_cbSendCardData)]++;
-
- //设置变量
- m_wProvideUser = wCurrentUser;
- m_cbProvideCard = m_cbSendCardData;
-
- //杠牌判断
- tagGangCardResult GangCardResult;
- ZeroMemory(&GangCardResult, sizeof(GangCardResult));
- if (m_cbLeftCardCount > 0)
- {
- bool bCanAnGang = true;//此true表示自己抓牌,false表示表人打得去检验杠,
- m_cbUserAction[wCurrentUser] |= m_GameLogic.AnalyseGangCard(m_cbCardIndex[wCurrentUser],
- m_WeaveItemArray[wCurrentUser], m_cbWeaveItemCount[wCurrentUser], GangCardResult);
- }
- //听牌计算
- // m_TabbOutCardCout[wCurrentUser] = 0; //可以打出的牌就听牌的个数
- // ZeroMemory(m_TabbOutCardData[wCurrentUser], sizeof(m_TabbOutCardData[wCurrentUser])); //具体打哪几张牌
- // ZeroMemory(m_TabbTingCardCount[wCurrentUser], sizeof(m_TabbTingCardCount[wCurrentUser])); //相对应打出牌可听牌个数,索引表示第几张,值是对应对应的听牌个数
- // ZeroMemory(m_TabbTingCardData[wCurrentUser], sizeof(m_TabbTingCardData[wCurrentUser])); //具体听牌数据,一维索引表示打出牌的第几个,二维索引表示听牌的第几个,值表示牌数据
- if (!(m_cbUserAction[wCurrentUser] & WIK_ZI_MO))
- TingCard(m_wCurrentUser);
- //构造数据
- CMD_S_SendCard SendCard;
- ZeroMemory(&SendCard, sizeof(SendCard));
- SendCard.wCurrentUser = wCurrentUser;
- SendCard.bTail = bTail;
- SendCard.bLeftCardCount = m_cbLeftCardCount;
- SendCard.cbActionMask = m_cbUserAction[wCurrentUser];
- SendCard.cbCardData = m_cbSendCardData;
- SparrowMaJiang::PB_CS_S_SendCard Card;
- Card.set_wcurrentuser(SendCard.wCurrentUser);
- Card.set_btail(SendCard.bTail);
- Card.set_bleftcardcount(SendCard.bLeftCardCount);
- Card.set_cbactionmask(SendCard.cbActionMask);
- Card.set_cbcarddata(SendCard.cbCardData);
- std::string pbdatas = Card.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_SEND_CARD, (void*)pbdatas.c_str(), pbdatas.length());
- //发送数据
- for (int i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- if (i == m_wCurrentUser)
- {//发送给摸牌玩家的数据,附带麻将牌面数据
- for (BYTE j = 0; j < GangCardResult.cbCardCount; j++)//先暗杠后补杠牌数据
- SendCard.cbActionCard[j] = GangCardResult.cbCardData[j];
- SendCard.cbCardData = m_cbSendCardData;
- SendCard.cbActionMask = m_cbUserAction[wCurrentUser];
- for (BYTE j = 0; j < GangCardResult.cbCardCount; j++)
- {
- Card.add_cbactioncard(SendCard.cbActionCard[j]);
- }
- Card.set_cbactionmask(SendCard.cbActionMask);
- Card.set_cbcarddata(SendCard.cbCardData);
- std::string pbdata = Card.SerializePartialAsString();
- m_pITableFrame->SendTableData(i, SUB_S_SEND_CARD, (void*)pbdata.c_str(), pbdata.length());
- }
- else
- {//发送给其他玩家的数据,没有麻将牌面数据(防止客户端作弊)
- ZeroMemory(SendCard.cbActionCard, sizeof(SendCard.cbActionCard));
- SendCard.cbCardData = 0x00;
- SendCard.cbActionMask = 0x0000;
- for (BYTE j = 0; j < GangCardResult.cbCardCount; j++)
- {
- Card.add_cbactioncard(SendCard.cbActionCard[j]);
- }
- Card.set_cbactionmask(SendCard.cbActionMask);
- Card.set_cbcarddata(SendCard.cbCardData);
- std::string pbdata = Card.SerializePartialAsString();
- m_pITableFrame->SendTableData(i, SUB_S_SEND_CARD, (void*)pbdata.c_str(), pbdata.length());
- }
- }
- SendCard.cbActionMask = 0;
- SendCard.cbCardData = 0;
- Card.set_cbactionmask(SendCard.cbActionMask);
- Card.set_cbcarddata(SendCard.cbCardData);
- std::string pbdata = Card.SerializePartialAsString();
- //给旁观者的抓牌动作
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_SEND_CARD, (void*)pbdata.c_str(), pbdata.length());
- if (m_TabbOutCardCout[m_wCurrentUser] > 0)//有听牌就发一个听牌协议
- {
- HttpTingCard(m_wCurrentUser);
- }
- return true;
- }
-
- //响应判断
- bool CTableFrameSink_tdh::EstimateUserRespond(WORD wCenterUser, BYTE cbCenterCard, enEstimatKind EstimatKind)
- {
- //财神牌不判断
- if (m_GameLogic.IsMagicCard(cbCenterCard))return false;
- //变量定义
- bool bAroseAction[GAME_PLAYER] = { false };
- bool mbAroseAction = false;
- //吃牌判断,出牌玩家下家位置
- WORD wEatUser = (wCenterUser + 1) % mPlayGameUserCount;
-
- if (m_bTwoPlayerFlag&&wEatUser == TowMjNullseat)
- {
- wEatUser++;
- }
- //用户状态
- ZeroMemory(m_bResponse, sizeof(m_bResponse));
- ZeroMemory(m_cbUserAction, sizeof(m_cbUserAction));
- ZeroMemory(m_cbPerformAction, sizeof(m_cbPerformAction));
-
- //动作判断
- for (WORD nUserIndex = 0; nUserIndex < mPlayGameUserCount; nUserIndex++)
- {
- if (m_bTwoPlayerFlag&&nUserIndex == TowMjNullseat)
- {
- continue;
- }
- //用户过滤
- if (wCenterUser == nUserIndex) continue;
- //出牌类型
- if (EstimatKind == EstimatKind_OutCard)
- {
- CChiHuRight Chr;
- BYTE TaiShu = 0;
-
-
-
- int wAction = 0;
-
-
- if (mCanFangChong)
- {
- wAction = m_GameLogic.AnalyseChiHuCard(m_cbCardIndex[nUserIndex], m_WeaveItemArray[nUserIndex], m_cbWeaveItemCount[nUserIndex], cbCenterCard, Chr, TaiShu);
- if (wAction != WIK_NULL&& (Chr&ZJ_TAI_CaiDiao).IsEmpty())
- {
- m_cbUserAction[nUserIndex] = WIK_CHI_HU;
- // if (m_cbOutCardCount == 1 && (m_wBankerUser & 0xff) != nUserIndex)
- // {
- // m_cbUserAction[nUserIndex] = WIK_DI_CHIHU;
- // }
- }
-
- }
-
-
-
- //确定只有下家才能吃牌
- if (wEatUser == nUserIndex)
- {
- m_cbUserAction[nUserIndex] |= m_GameLogic.EstimateEatCard(m_cbCardIndex[nUserIndex], cbCenterCard);
- }
- //碰牌判断
- m_cbUserAction[nUserIndex] |= m_GameLogic.EstimatePengCard(m_cbCardIndex[nUserIndex], cbCenterCard);
-
- //杠牌判断
- if (m_cbLeftCardCount > 0)
- {
- m_cbUserAction[nUserIndex] |= m_GameLogic.EstimateGangCard(m_cbCardIndex[nUserIndex], cbCenterCard);
- }
-
- }
- if (EstimatKind == EstimatKind_GangCard)
- {
- CChiHuRight Chr;
- BYTE TaiShu = 0;
- int wAction = 0;
-
-
- wAction = m_GameLogic.AnalyseChiHuCard(m_cbCardIndex[nUserIndex], m_WeaveItemArray[nUserIndex], m_cbWeaveItemCount[nUserIndex], cbCenterCard, Chr, TaiShu);
- //财吊玩家,不能抢杠胡,只能自摸
- if (wAction&WIK_ZI_MO && (Chr&ZJ_TAI_CaiDiao).IsEmpty())
- {
- m_cbUserAction[nUserIndex] |= WIK_ZI_MO;
- }
- }
- //结果判断
- if (m_cbUserAction[nUserIndex] != WIK_NULL)
- {
- bAroseAction[nUserIndex] = true;
- if (m_cbUserAction[nUserIndex] & (WIK_PENG | WIK_CHI_HU | WIK_PENG_PENG))
- {
- BYTE bTemp = 0;
- //记忆牌有多少张
- for (BYTE j = 0; j < m_cbLastDisCount[nUserIndex]; j++)
- {
- //如果在一圈中 记忆1个一样的牌 则不能操作
- if (m_cbLastDisCardData[nUserIndex][j] == cbCenterCard)
- {
- m_cbUserAction[nUserIndex] = m_cbUserAction[nUserIndex] & (~(WIK_PENG | WIK_CHI_HU | WIK_PENG_PENG));
- if (m_cbUserAction[nUserIndex] == WIK_NULL)
- bAroseAction[nUserIndex] = false;
- }
- }
- }
- }
- }
- for (int nUserIndex = 0; nUserIndex < mPlayGameUserCount; nUserIndex++)
- {
- if (m_bTwoPlayerFlag&&nUserIndex == TowMjNullseat)
- {
- continue;
- }
- if (bAroseAction[nUserIndex] == true)
- {
- mbAroseAction = true;
- break;
- }
- }
- //结果处理
- if (mbAroseAction == true)
- {
- //设置变量
- m_wProvideUser = wCenterUser;
- m_cbProvideCard = cbCenterCard;
- m_wResumeUser = m_wCurrentUser;
- m_wCurrentUser = INVALID_CHAIR;
- //发送提示
- SendOperateNotify();
- return true;
- }
- return false;
- }
- //胡的这张牌 牌堆里面还有几张
- //计算方式 服务器上剩余里面的牌,+其他三位位玩家手牌= 该胡牌个数
- BYTE CTableFrameSink_tdh::RemainNum(WORD wChairId, const BYTE m_cbCard, BYTE cbOutCardIndex)
- {
- BYTE m_cbNum = 0;
- BYTE mCard[MAX_INDEX] = { 0 }; //把所有当前用户可以看到的牌 都扔到这个数组中
- BYTE TempIndex = m_GameLogic.SwitchToCardIndex(m_cbCard);
-
-
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- for (BYTE j = 0; j < m_cbDiscardCount[i]; j++)//丢弃数
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_cbDiscardCard[i][j])]++;
- }
- for (BYTE k = 0; k < m_cbWeaveItemCount[i]; k++)//摆出来的牌
- {
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_PENG)
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)] += 3;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_LEFT)
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard + 1)]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard + 2)]++;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_RIGHT)
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard - 1)]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard - 2)]++;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_CENTER)
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard - 1)]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard + 1)]++;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_MING_GANG || (i == wChairId&&m_WeaveItemArray[i][k].cbWeaveKind == WIK_AN_GANG))
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)] += 4;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind& (WIK_SHUANG_CAICHI | WIK_SHUANG_PENG | WIK_DAN_CHI))
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[0])]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[1])]++;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_DAN_PENG)
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)] += 2;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[0])]++;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_DAN_MING_GANG || (i == wChairId && m_WeaveItemArray[i][k].cbWeaveKind == WIK_DAN_AN_GANG))
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)] += 3;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[0])]++;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_SHUANG_MING_GANG || (i == wChairId && m_WeaveItemArray[i][k].cbWeaveKind == WIK_SHUANG_AN_GANG))
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)] += 2;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[0])]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[1])]++;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind == WIK_SAN_MING_GANG || (i == wChairId && m_WeaveItemArray[i][k].cbWeaveKind == WIK_SAN_AN_GANG))
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)] += 1;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[0])]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[1])]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[2])]++;
- }
- if (i == wChairId && m_WeaveItemArray[i][k].cbWeaveKind == WIK_QUANG_AN_GANG)
- {
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[0])]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[1])]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[2])]++;
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[3])]++;
- }
- if (m_WeaveItemArray[i][k].cbWeaveKind & (WIK_BU_GANG | WIK_DAN_BU_GANG))
- {
- for (int m = 0; m < 4; m++)
- {
- if (m_WeaveItemArray[i][k].cbMargicOffset[m] != 0)
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbMargicOffset[m])]++;
- else
- mCard[m_GameLogic.SwitchToCardIndex(m_WeaveItemArray[i][k].cbCenterCard)] ++;
- }
- }
- }
- }
- //8个财神变7个 在加回来一个
-
- //非包麻将 需要计算翻财神的那张牌
- //BYTE cbMagicFirstIndex = m_GameLogic.SwitchToCardIndex(m_cbMagicSecondData);
- //if (mCard[cbMagicFirstIndex] < 4)
- //{
- // mCard[cbMagicFirstIndex]++;
- //}
-
- //非包麻将 不需要把财神那张牌加入落地牌
-
-
- //增加自己假设去掉的牌 这样才真正的标示 牌桌加手牌
- mCard[cbOutCardIndex]++;
- for (BYTE i = 0; i < MAX_INDEX; i++)
- {
- mCard[i] += m_cbCardIndex[wChairId][i];
- }
- m_cbNum = 4 - mCard[TempIndex];
- if (m_GameLogic.SwitchToCardData(TempIndex)== m_cbMagicFirstData)
- {
- m_cbNum--;
- }
- ASSERT(m_cbNum >= 0 && m_cbNum <= 4);
- if (m_cbNum < 0)m_cbNum = 0;
- return m_cbNum;
- }
- //对手牌遍历,并把该牌减去,然后分析这13张拍能胡什么
- bool CTableFrameSink_tdh::TingCard(WORD wChairID)
- {
- m_PaiQuan[wChairID] = 0;
- m_TabbOutCardCout[wChairID] = 0; //可以打出的牌就听牌的个数
- ZeroMemory(m_TabbOutCardData[wChairID], sizeof(m_TabbOutCardData[wChairID])); //具体打哪几张牌
- ZeroMemory(m_TabbTingCardCount[wChairID], sizeof(m_TabbTingCardCount[wChairID])); //相对应打出牌可听牌个数,索引表示第几张,值是对应对应的听牌个数
- ZeroMemory(m_TabbTingCardData[wChairID], sizeof(m_TabbTingCardData[wChairID])); //具体听牌数据,一维索引表示打出牌的第几个,二维索引表示听牌的第几个,值表示牌数据
-
- BYTE WilEnumCard[MAX_INDEX] = { 0 };
- m_GameLogic.IsCanChangCardAndCount(m_cbCardIndex[wChairID], WilEnumCard);
-
- for (BYTE i = 0; i < MAX_INDEX; i++)
- {
- if (m_cbCardIndex[wChairID][i] == 0)continue;
- if (--m_cbCardIndex[wChairID][i] < 0){ ASSERT(false); return false; }
- //if (m_GameLogic.IsTingCard(m_cbCardIndex[wChairID], m_WeaveItemArray[wChairID], m_cbWeaveItemCount[wChairID],FanHui))
- //{
- m_TabbOutCardData[wChairID][m_TabbOutCardCout[wChairID]] = m_GameLogic.SwitchToCardData(i);
- BYTE m_cbTingPai[MAX_INDEX] = { 0 };//听牌数组,听哪个牌就把哪个牌设置为1
- BYTE m_cbTingParCount = 0; //听牌数据
-
- int BaoUserID = 0;
- int BaoUserTaiNum = 0;
-
-
- if (m_GameLogic.AnalyseTingCard(m_cbCardIndex[wChairID], m_WeaveItemArray[wChairID], m_cbWeaveItemCount[wChairID], m_cbTingPai, WilEnumCard, wChairID, BaoUserID, BaoUserTaiNum))
- {
- for (BYTE j = 0; j < MAX_INDEX; j++)
- {
- if (m_cbTingPai[j] > 0)
- {
- if (m_cbTingParCount == 19)
- {
- m_cbTingParCount++;
- break;
- }
- m_TabbTingCardData[wChairID][m_TabbOutCardCout[wChairID]][m_cbTingParCount++] = m_GameLogic.SwitchToCardData(j);
- //计算所胡的这张牌 还剩余几张
- BYTE num = RemainNum(wChairID, m_TabbTingCardData[wChairID][m_TabbOutCardCout[wChairID]][m_cbTingParCount - 1], i);
- m_TabbTingCardData[wChairID][m_TabbOutCardCout[wChairID]][m_cbTingParCount - 1] = m_GameLogic.GetValue(num, m_cbTingPai[j], m_TabbTingCardData[wChairID][m_TabbOutCardCout[wChairID]][m_cbTingParCount - 1]);
- }
- }
- if (m_cbTingParCount == 20)
- {
- m_TabbTingCardCount[wChairID][m_TabbOutCardCout[wChairID]] = 255;
- ZeroMemory(m_TabbTingCardData[wChairID][m_TabbOutCardCout[wChairID]], m_cbTingParCount);
- }
- else
- m_TabbTingCardCount[wChairID][m_TabbOutCardCout[wChairID]] = m_cbTingParCount;
- }
- if (m_cbTingParCount > 0)
- m_TabbOutCardCout[wChairID]++;
- else{ m_TabbOutCardData[wChairID][m_TabbOutCardCout[wChairID]] = 0; }
- //}
- m_cbCardIndex[wChairID][i]++;
- }
- return true;
- }
-
- bool CTableFrameSink_tdh::OutTingCard(WORD wChairID, BYTE cardIndex)
- {
- m_PaiQuan[wChairID] = 1;
- m_TabbOutCardCout[wChairID] = 1; //可以打出的牌就听牌的个数,当打出牌已经完成,默认255不存在
- ZeroMemory(m_TabbOutCardData[wChairID], sizeof(m_TabbOutCardData[wChairID])); //具体打哪几张牌
- ZeroMemory(m_TabbTingCardCount[wChairID], sizeof(m_TabbTingCardCount[wChairID])); //相对应打出牌可听牌个数,索引表示第几张,值是对应对应的听牌个数
- ZeroMemory(m_TabbTingCardData[wChairID], sizeof(m_TabbTingCardData[wChairID])); //具体听牌数据,一维索引表示打出牌的第几个,二维索引表示听牌的第几个,值表示牌数据
-
- BYTE m_cbTingPai[MAX_INDEX] = { 0 };//听牌数组,听哪个牌就把哪个牌设置为1
- BYTE m_cbTingParCount = 0;//听牌数据
- BYTE FanHui[MAX_INDEX] = { 0 };
- m_GameLogic.IsCanChangCardAndCount(m_cbCardIndex[wChairID], FanHui);
- if (m_GameLogic.AnalyseTingCard(m_cbCardIndex[wChairID], m_WeaveItemArray[wChairID], m_cbWeaveItemCount[wChairID], m_cbTingPai, FanHui, wChairID))
- {
- for (BYTE j = 0; j < MAX_INDEX; j++)
- {
- if (m_cbTingPai[j] > 0)
- {
- if (m_cbTingParCount == 19)
- {
- m_cbTingParCount++;
- break;
- }
- m_TabbTingCardData[wChairID][0][m_cbTingParCount++] = m_GameLogic.SwitchToCardData(j);
- //用户ID
- BYTE num = RemainNum(wChairID, m_TabbTingCardData[wChairID][0][m_cbTingParCount - 1], cardIndex);
- m_TabbTingCardData[wChairID][0][m_cbTingParCount - 1] = m_GameLogic.GetValue(num, m_cbTingPai[j], m_TabbTingCardData[wChairID][0][m_cbTingParCount - 1]);
- }
- }
- if (m_cbTingParCount == 20)
- {
- m_TabbTingCardCount[wChairID][0] = 255;
- ZeroMemory(m_TabbTingCardData[wChairID][0], m_cbTingParCount);
- }
- else
- {
- m_TabbTingCardCount[wChairID][0] = m_cbTingParCount;
- }
- return true;
- }
- return false;
- }
-
- void CTableFrameSink_tdh::HttpTingCard(WORD wChairID)
- {
- CMD_S_TingCard strTingCard;
- ZeroMemory(&strTingCard, sizeof(strTingCard));
- strTingCard.bPaiQuan = m_PaiQuan[wChairID];
- strTingCard.bOutCardCout = m_TabbOutCardCout[wChairID];
- CopyMemory(strTingCard.bOutCardData, m_TabbOutCardData[wChairID], sizeof(m_TabbOutCardData[wChairID]));
- CopyMemory(strTingCard.bTingCardCount, m_TabbTingCardCount[wChairID], sizeof(m_TabbTingCardCount[wChairID]));
- CopyMemory(strTingCard.bTingCardData, m_TabbTingCardData[wChairID], sizeof(m_TabbTingCardData[wChairID]));
-
- SparrowMaJiang::PB_CS_S_TingCard Card;
- Card.set_bpaiquan(strTingCard.bPaiQuan);
- Card.set_boutcardcout(strTingCard.bOutCardCout);
- for (BYTE j = 0; j < strTingCard.bOutCardCout; j++)
- {
- Card.add_boutcarddata(strTingCard.bOutCardData[j]);
- }
- for (BYTE j = 0; j < strTingCard.bOutCardCout; j++)
- {
- Card.add_btingcardcount(strTingCard.bTingCardCount[j]);
- }
- for (BYTE i = 0; i < strTingCard.bOutCardCout; i++)
- {
- SparrowMaJiang::pb_bTingCardData* CardData = Card.add_btingcarddata();
- for (BYTE j = 0; j < strTingCard.bTingCardCount[i]; j++)
- {
- CardData->add_btingcarddatas(strTingCard.bTingCardData[i][j]);
- }
- }
- std::string pbdata = Card.SerializePartialAsString();
- m_pITableFrame->SendTableData(wChairID, SUB_S_TING_CARD, (void*)pbdata.c_str(), pbdata.length());
- }
-
- void CTableFrameSink_tdh::HttpOperateResult(WORD wChairID, BYTE cbCaiShenCard[4], int cbOperateCode, BYTE cbOperateCard, int cbActionMask, WORD cbActionCard[6])
- {
-
-
- //
- //推倒胡发送及时杠牌积分变动
- //SendGangScore(wChairID, m_wProvideUser, cbOperateCode);
-
- if (cbOperateCode & WIK_GANG_GANG)
- {//构造结果
- CMD_S_OperateResult OperateResult;
- memset(&OperateResult, 0, sizeof(OperateResult));
- OperateResult.wOperateUser = wChairID;
- OperateResult.wProvideUser = wChairID;
- OperateResult.cbOperateCode = cbOperateCode;
- OperateResult.cbOperateCard = cbOperateCard;
- CopyMemory(OperateResult.cbCaiShenCard, cbCaiShenCard, sizeof(OperateResult.cbCaiShenCard));
- OperateResult.cbActionMask = cbActionMask;
- CopyMemory(OperateResult.cbActionCard, cbActionCard, sizeof(OperateResult.cbActionCard));
- SparrowMaJiang::PB_CS_S_OperateResult Result;
- Result.set_woperateuser(OperateResult.wOperateUser);
- Result.set_cboperatecard(OperateResult.cbOperateCard);
- Result.set_cboperatecode(OperateResult.cbOperateCode);
- Result.set_wprovideuser(OperateResult.wProvideUser);
- for (BYTE j = 0; j < 4; j++)
- {
- Result.add_cbcaishencard(OperateResult.cbCaiShenCard[j]);
- }
- Result.set_cbactionmask(OperateResult.cbActionMask);
- for (BYTE j = 0; j < 6; j++)
- {
- Result.add_cbactioncard(OperateResult.cbActionCard[j]);
- }
- //发送数据
- std::string pbdata = Result.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- //发送消息
- m_pITableFrame->SendTableData(wChairID, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- ZeroMemory(OperateResult.cbCaiShenCard, sizeof(OperateResult.cbCaiShenCard));
- for (BYTE j = 0; j < 4; j++)
- {
- Result.add_cbcaishencard(OperateResult.cbCaiShenCard[j]);
- }
- for (BYTE i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- if (i == wChairID)continue;
- //发送消息
- m_pITableFrame->SendTableData(i, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- }
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- }
- else
- {
- CMD_S_OperateResult OperateResult;
- memset(&OperateResult, 0, sizeof(OperateResult));
- OperateResult.wOperateUser = wChairID;
- OperateResult.wProvideUser = m_wProvideUser;
- if (cbOperateCode &(WIK_DAN_BU_GANG | WIK_BU_GANG))
- OperateResult.wProvideUser = wChairID;
- OperateResult.cbOperateCode = cbOperateCode;
- OperateResult.cbOperateCard = cbOperateCard;
- CopyMemory(OperateResult.cbCaiShenCard, cbCaiShenCard, sizeof(OperateResult.cbCaiShenCard));
- OperateResult.cbActionMask = cbActionMask;
- CopyMemory(OperateResult.cbActionCard, cbActionCard, sizeof(OperateResult.cbActionCard));
- SparrowMaJiang::PB_CS_S_OperateResult Result;
- Result.set_woperateuser(OperateResult.wOperateUser);
- Result.set_cboperatecard(OperateResult.cbOperateCard);
- Result.set_cboperatecode(OperateResult.cbOperateCode);
- Result.set_wprovideuser(OperateResult.wProvideUser);
- for (BYTE j = 0; j < 4; j++)
- {
- Result.add_cbcaishencard(OperateResult.cbCaiShenCard[j]);
- }
- Result.set_cbactionmask(OperateResult.cbActionMask);
- for (BYTE j = 0; j < 6; j++)
- {
- Result.add_cbactioncard(OperateResult.cbActionCard[j]);
- }
- //发送数据
- std::string pbdata = Result.SerializePartialAsString();
- RepayRecord(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- //发送消息
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_OPERATE_RESULT, (void*)pbdata.c_str(), pbdata.length());
- }
- }
-
- BYTE CTableFrameSink_tdh::GetNextMagicCardData(BYTE cbMagicCardFirstData)
- {
- BYTE TmpCardData = 0;
- BYTE HuaSe = m_GameLogic.GetCardColor(cbMagicCardFirstData);
- switch (HuaSe)
- {
- case 0:
- case 1:
- case 2:
- {
- if ((cbMagicCardFirstData & MASK_VALUE) == 0x09)
- {
- TmpCardData = (cbMagicCardFirstData & MASK_COLOR) | 0x01;
- }
- else
- {
- TmpCardData = cbMagicCardFirstData + 1;
- }
- break;
- }
- case 3:
- {
- if ((cbMagicCardFirstData & MASK_VALUE) == 0x04)
- {
- TmpCardData = (cbMagicCardFirstData & MASK_COLOR) | 0x01;
- }
- else if ((cbMagicCardFirstData & MASK_VALUE) == 0x07)
- {
- TmpCardData = cbMagicCardFirstData - 2;
- }
- else
- {
- TmpCardData = cbMagicCardFirstData + 1;
- }
- break;
- }
- default:
- {
- ASSERT(false);
- break;
- }
- }
- return TmpCardData;
- }
-
- void CTableFrameSink_tdh::FanMagicCaculation(BYTE WinChairID, BYTE nTai, BYTE WinWay, BYTE provideUserID, CChiHuRight chr, CMD_S_GangScore& cmd_Score)
- {
- switch (WinWay)
- {
-
- case Win_ZiMo:{
- if (!(chr&ZJ_TAI_QiangGang).IsEmpty())
- {
- WinFanMagic_ZiMo_QiangGang_Score(WinChairID, nTai, WinWay, provideUserID, cmd_Score);
- break;
- }
- else
- {
- WinFanMagic_ZiMo_Score(WinChairID, nTai, WinWay, provideUserID, cmd_Score);
- }
-
- break;
- }
- case Win_FangPao:{
- WinFanMagic_FangPao_Score(WinChairID, nTai, WinWay, provideUserID, cmd_Score);
- break;
- }
- default:
- break;
- }
- }
-
-
-
- void CTableFrameSink_tdh::WinFanMagic_FangPao_Score(BYTE WinChairID, BYTE nTai, BYTE WinWay, BYTE provideUserID,CMD_S_GangScore& cmd_Score)
- {
- for (BYTE i = 0; i < mPlayGameUserCount; i++)//各个玩家游戏积分变动
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- if (i == WinChairID)
- {
- //cmd_Score.lGangScore[i] += m_gangScore[i];
- continue;
- }
-
- if (i == provideUserID)
- {
- LianXuHuPai[i] = 0;
-
- cmd_Score.lGangScore[i] -= m_gameConfig.wDiScore * nTai*2;
- // [9/16/2017 Zoro] 计算杠牌影响的分数
- cmd_Score.lGangScore[i] += m_gangScore[i];
-
- m_lGameScore[i] += cmd_Score.lGangScore[i];
- m_lGameTatolScore[i] += cmd_Score.lGangScore[i];
- cmd_Score.cbWanJiaScore[i] = m_lGameTatolScore[i];
-
- }
- else
- {
- LianXuHuPai[i] = 0;
- cmd_Score.lGangScore[i] -= m_gameConfig.wDiScore * nTai;
- cmd_Score.lGangScore[i] += m_gangScore[i];
-
- m_lGameScore[i] += cmd_Score.lGangScore[i];
- m_lGameTatolScore[i] += cmd_Score.lGangScore[i];
- cmd_Score.cbWanJiaScore[i] = m_lGameTatolScore[i];
- }
-
- }
- if (m_bTwoPlayerFlag)
- {
- cmd_Score.lGangScore[WinChairID] = m_gameConfig.wDiScore * 2 * nTai;//2个玩家
- }
- else
- {
- cmd_Score.lGangScore[WinChairID] = m_gameConfig.wDiScore * mPlayGameUserCount * nTai;
- }
-
- cmd_Score.lGangScore[WinChairID] += m_gangScore[WinChairID];
- m_lGameScore[WinChairID] += cmd_Score.lGangScore[WinChairID];
- m_lGameTatolScore[WinChairID] += cmd_Score.lGangScore[WinChairID];
- cmd_Score.cbWanJiaScore[WinChairID] = m_lGameTatolScore[WinChairID];
- }
-
- void CTableFrameSink_tdh::CaculationHuangZhuang(CMD_S_GangScore& cmd_Score)
- {
-
- WORD BankUserID = m_wBankerUser & 0x00ff;
- int FanBei = 1;
- //if (LianXuHuPai[BankUserID] >= 2)
- //{
- // FanBei++;
- //}
-
- ZeroMemory(m_gangScore, sizeof(m_gangScore));
- //计算所有杠牌四家的积分变动。
- for (int i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- int nCount = m_cbWeaveItemCount[i];
-
- for (int nWeaveItem = 0; nWeaveItem < nCount; nWeaveItem++)
- {
- tagWeaveItem tag = m_WeaveItemArray[i][nWeaveItem];
- switch (tag.cbWeaveKind)
- {
- //点杠
- case WIK_MING_GANG:
- {
- m_gangScore[i] += 2 * m_gameConfig.wDiScore*FanBei;
- m_gangScore[tag.wProvideUser] -= 2 * m_gameConfig.wDiScore*FanBei;
- break;
- }
- case WIK_AN_GANG:
- {
- for (int j = 0; j < mPlayGameUserCount; j++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- if (j == i)
- {
- if (m_bTwoPlayerFlag)
- {
- m_gangScore[i] += (mPlayGameUserCount - 2) * 2 * m_gameConfig.wDiScore*FanBei;
- }
- else
- {
- m_gangScore[i] += (mPlayGameUserCount - 1) * 2 * m_gameConfig.wDiScore*FanBei;
- }
-
- continue;
- }
- m_gangScore[j] -= 2 * m_gameConfig.wDiScore*FanBei;
- }
- break;
- }
- case WIK_BU_GANG:{
- for (int j = 0; j < mPlayGameUserCount; j++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- if (j == i)
- {
- if (m_bTwoPlayerFlag)
- {
- m_gangScore[i] += (mPlayGameUserCount - 2) * m_gameConfig.wDiScore*FanBei;
- }
- else
- {
- m_gangScore[i] += (mPlayGameUserCount - 1) * m_gameConfig.wDiScore*FanBei;
- }
-
- continue;
- }
- m_gangScore[j] -= m_gameConfig.wDiScore*FanBei;
- }
- break;
- }
- default:
- break;
- }
-
- }
-
- }
- for (int i = 0; i < mPlayGameUserCount; i++)
- {
- // CString str;
- // str.Format(_T("CaculationHuangZhuang 玩家%d 杠牌分数变动=%d"), i, m_gangScore[i]);
- // OutputDebugString(str);
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- cmd_Score.lGangScore[i] += m_gangScore[i];
- m_lGameScore[i] += cmd_Score.lGangScore[i];
- m_lGameTatolScore[i] += cmd_Score.lGangScore[i];
- cmd_Score.cbWanJiaScore[i] = m_lGameTatolScore[i];
- }
- }
-
- void CTableFrameSink_tdh::WinFanMagic_ZiMo_Score(BYTE WinChairID, BYTE nTai, BYTE WinWay, BYTE provideUserID, CMD_S_GangScore& cmd_Score)
- {
-
- int TempInfoScore = 0;
- for (BYTE i = 0; i < mPlayGameUserCount; i++)//各个玩家游戏积分变动
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- if (i == WinChairID)continue;
- LianXuHuPai[i] = 0;
-
- cmd_Score.lGangScore[i] -= m_gameConfig.wDiScore * nTai;
- // [9/16/2017 Zoro] 计算杠牌影响的分数
- cmd_Score.lGangScore[i] += m_gangScore[i];
-
- m_lGameScore[i] += cmd_Score.lGangScore[i];
- m_lGameTatolScore[i] += cmd_Score.lGangScore[i];
- cmd_Score.cbWanJiaScore[i] = m_lGameTatolScore[i];
-
- //
-
- TempInfoScore -= cmd_Score.lGangScore[i];
- }
- cmd_Score.lGangScore[WinChairID] = TempInfoScore;
- m_lGameScore[WinChairID] += cmd_Score.lGangScore[WinChairID];
- m_lGameTatolScore[WinChairID] += cmd_Score.lGangScore[WinChairID];
- cmd_Score.cbWanJiaScore[WinChairID] = m_lGameTatolScore[WinChairID];
- }
-
- void CTableFrameSink_tdh::WinFanMagic_ZiMo_QiangGang_Score(BYTE WinChairID, BYTE nTai, BYTE WinWay, BYTE provideUserID, CMD_S_GangScore& cmd_Score)
- {
- WORD BankUserID = m_wBankerUser & 0x00ff;
- int FanBei = 1;
- if (LianXuHuPai[BankUserID] >= 2)
- {
- FanBei++;
- }
- int TempInfoScore = 0;
- for (BYTE i = 0; i < mPlayGameUserCount; i++)//各个玩家游戏积分变动
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- if (i == WinChairID)
- {
- //cmd_Score.lGangScore[i] += m_gangScore[i];
- continue;
- }
-
- if (i == provideUserID)
- {
- LianXuHuPai[i] = 0;
- if (m_bTwoPlayerFlag)
- {
- cmd_Score.lGangScore[i] -= m_gameConfig.wDiScore * (mPlayGameUserCount-1) * FanBei;
- }
- else
- {
-
- cmd_Score.lGangScore[i] -= m_gameConfig.wDiScore * mPlayGameUserCount * FanBei;
- }
-
- // [9/16/2017 Zoro] 计算杠牌影响的分数
- cmd_Score.lGangScore[i] += m_gangScore[i];
-
- m_lGameScore[i] += cmd_Score.lGangScore[i];
- m_lGameTatolScore[i] += cmd_Score.lGangScore[i];
- cmd_Score.cbWanJiaScore[i] = m_lGameTatolScore[i];
-
-
- TempInfoScore -= cmd_Score.lGangScore[i];
-
- }
- else
- {
- cmd_Score.lGangScore[i] += m_gangScore[i];
- m_lGameScore[i] += m_gangScore[i];
- m_lGameTatolScore[i] += cmd_Score.lGangScore[i];
- }
-
- }
- if (m_bTwoPlayerFlag)
- {
- cmd_Score.lGangScore[WinChairID] = m_gameConfig.wDiScore * (mPlayGameUserCount-1) * FanBei;
- }
- else
- {
- cmd_Score.lGangScore[WinChairID] = m_gameConfig.wDiScore * mPlayGameUserCount * FanBei;
- }
-
- cmd_Score.lGangScore[WinChairID] += m_gangScore[WinChairID];
- m_lGameScore[WinChairID] += cmd_Score.lGangScore[WinChairID];
- m_lGameTatolScore[WinChairID] += cmd_Score.lGangScore[WinChairID];
- cmd_Score.cbWanJiaScore[WinChairID] = m_lGameTatolScore[WinChairID];
- }
-
-
-
- //由于推倒胡 财神不能落地。所以只有暗杠 明杠 补杠
- void CTableFrameSink_tdh::SendGangScore(BYTE GangUserID, BYTE ProvideUserID, int cbOperateCode)
- {
-
- //积分变动
- //暗杠
- CMD_S_GangScore gs;
- ZeroMemory(&gs, sizeof(gs));
- gs.wChairId = GangUserID;
- gs.cbOperateCode = cbOperateCode;
- CopyMemory(gs.cbWanJiaScore, m_lGameTatolScore,sizeof(m_lGameTatolScore));
- if (cbOperateCode & WIK_GANG_GANG)
- {
-
- for (int j = 0; j < mPlayGameUserCount; j++)
- {
- if (m_bTwoPlayerFlag&&j == TowMjNullseat)
- {
- continue;
- }
- if (j == GangUserID)
- {
- if (m_bTwoPlayerFlag)
- {
- gs.lGangScore[j] += (mPlayGameUserCount - 2) * 2 * m_gameConfig.wDiScore;
- }
- else
- {
- gs.lGangScore[j] += (mPlayGameUserCount - 1) * 2 * m_gameConfig.wDiScore;
- }
-
- continue;
- }
- gs.lGangScore[j] -= 2 * m_gameConfig.wDiScore;
-
- }
- SparrowMaJiang::PB_CS_S_GangScore GangScore;
- GangScore.set_cboperatecode(gs.cbOperateCode);
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- GangScore.add_cbwanjiascore(gs.cbWanJiaScore[j]);
- GangScore.add_lgangscore(gs.lGangScore[j]);
- }
- GangScore.set_wchairid(gs.wChairId);
- std::string pbscore = GangScore.SerializePartialAsString();
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- RepayRecord(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
-
- return;
- }
- //明杠
- if (cbOperateCode & WIK_MING_GANG)
- {
- gs.lGangScore[GangUserID] += 2 * m_gameConfig.wDiScore;
- gs.lGangScore[ProvideUserID] -= 2 * m_gameConfig.wDiScore;
- SparrowMaJiang::PB_CS_S_GangScore GangScore;
- GangScore.set_cboperatecode(gs.cbOperateCode);
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- GangScore.add_cbwanjiascore(gs.cbWanJiaScore[j]);
- GangScore.add_lgangscore(gs.lGangScore[j]);
- }
- GangScore.set_wchairid(gs.wChairId);
- std::string pbscore = GangScore.SerializePartialAsString();
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- RepayRecord(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
-
- return;
- }
- //补杠
- if (cbOperateCode&WIK_BU_GANG)
- {
- for (int j = 0; j < mPlayGameUserCount; j++)
- {
- if (m_bTwoPlayerFlag&&j == TowMjNullseat)
- {
- continue;
- }
- if (j == GangUserID)
- {
- if (m_bTwoPlayerFlag)
- {
- gs.lGangScore[j] += (mPlayGameUserCount - 2) * m_gameConfig.wDiScore;
- }
- else
- {
- gs.lGangScore[j] += (mPlayGameUserCount - 1) * m_gameConfig.wDiScore;
- }
-
- continue;
- }
- gs.lGangScore[j] -= m_gameConfig.wDiScore;
- }
- SparrowMaJiang::PB_CS_S_GangScore GangScore;
- GangScore.set_cboperatecode(gs.cbOperateCode);
- for (BYTE j = 0; j < mPlayGameUserCount; j++)
- {
- GangScore.add_cbwanjiascore(gs.cbWanJiaScore[j]);
- GangScore.add_lgangscore(gs.lGangScore[j]);
- }
- GangScore.set_wchairid(gs.wChairId);
- std::string pbscore = GangScore.SerializePartialAsString();
- m_pITableFrame->SendTableData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- m_pITableFrame->SendLookonData(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- RepayRecord(INVALID_CHAIR, SUB_S_GANG_SCORE, (void*)pbscore.c_str(), pbscore.length());
- return;
- }
- }
-
- void CTableFrameSink_tdh::CaculationScore(BYTE WinChairID, BYTE nTai, BYTE WinWay, BYTE provideUserID, CChiHuRight UserChr, CMD_S_GangScore& cmd_Score)
- {
-
- //int nWinUserItemCount = m_cbWeaveItemCount[WinChairID];
- //if (!(UserChr&ZJ_TAI_GangKai).IsEmpty())
- //{
- // CString str;
- // str.Format(_T("杠开~~~ 玩家id=%d 杠开的牌=%02x"), WinChairID,m_cbLastGangCard);
- // OutputDebugString(str);
- //
- //}
-
- // [10/9/2017 Zoro] 取消老庄 杠牌翻倍,取消杠开不算积分问题(使杠开的杠也算分)。
- //WORD BankUserID = m_wBankerUser & 0x00ff;
- int FanBei = 1;
- //if (LianXuHuPai[BankUserID] >= 2)
- //{
- // FanBei++;
- //}
- ZeroMemory(m_gangScore, sizeof(m_gangScore));
- //计算所有杠牌四家的积分变动。
- for (int i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- int nCount = m_cbWeaveItemCount[i];
-
- for (int nWeaveItem = 0; nWeaveItem <nCount; nWeaveItem++)
- {
-
- if (!(UserChr&ZJ_TAI_QiangGang).IsEmpty()&&i==m_wProvideUser)
- {
- if (m_WeaveItemArray[i][nWeaveItem].cbCenterCard == m_cbSendCardData)
- {
- // CString str;
- // str.Format(_T("抢杠胡,去掉玩家 %d 第%d个落地杠 牌值=%02x\r\n"), i, nWeaveItem, m_cbSendCardData);
- // OutputDebugString(str);
- continue;
- }
- }
- // if (!(UserChr&ZJ_TAI_GangKai).IsEmpty() && i == WinChairID&& m_WeaveItemArray[i][nWeaveItem].cbCenterCard==m_cbLastGangCard)
- // {
- // continue;
- // }
-
- tagWeaveItem tag = m_WeaveItemArray[i][nWeaveItem];
- switch (tag.cbWeaveKind)
- {
- //点杠
- case WIK_MING_GANG:
- {
- m_gangScore[i] += (2 * m_gameConfig.wDiScore*FanBei);
- m_gangScore[tag.wProvideUser] -= (2 * m_gameConfig.wDiScore*FanBei);
- break;
- }
- case WIK_AN_GANG:
- {
- for (int j = 0; j < mPlayGameUserCount;j++)
- {
- if (m_bTwoPlayerFlag&&j == TowMjNullseat)
- {
- continue;
- }
- if (j==i)
- {
- if (m_bTwoPlayerFlag)
- {
- m_gangScore[i] += (mPlayGameUserCount - 2) * 2 * m_gameConfig.wDiScore*FanBei;
- }
- else
- {
- m_gangScore[i] += (mPlayGameUserCount - 1) * 2 * m_gameConfig.wDiScore*FanBei;
- }
- continue;
- }
- m_gangScore[j] -= 2 * m_gameConfig.wDiScore*FanBei;
- }
- break;
- }
- case WIK_BU_GANG:{
- for (int j = 0; j < mPlayGameUserCount; j++)
- {
- if (m_bTwoPlayerFlag&&j == TowMjNullseat)
- {
- continue;
- }
- if (j == i)
- {
- if (m_bTwoPlayerFlag)
- {
- m_gangScore[i] += (mPlayGameUserCount - 2) * m_gameConfig.wDiScore*FanBei;
- }
- else
- {
- m_gangScore[i] += (mPlayGameUserCount - 1) * m_gameConfig.wDiScore*FanBei;
- }
- continue;
- }
- m_gangScore[j] -= m_gameConfig.wDiScore*FanBei;
- }
- break;
- }
- default:
- break;
- }
-
- }
-
- }
- // for (int i = 0; i < GAME_PLAYER;i++)
- // {
- // CString str;
- // str.Format(_T("玩家%d 杠牌分数变动=%d"),i,m_gangScore[i]);
- // OutputDebugString(str);
- // }
-
- FanMagicCaculation(WinChairID, nTai, WinWay, provideUserID, UserChr, cmd_Score);
-
-
-
-
- }
-
- void CTableFrameSink_tdh::WritePaiCardData(TCHAR* TableId, int count)
- {
-
- CString strCfgFile;
- GetModuleFileName(NULL, strCfgFile.GetBufferSetLength(MAX_PATH), MAX_PATH);
- strCfgFile.ReleaseBuffer();
- WCHAR* pTmp = wcsrchr(strCfgFile.GetBuffer(), L'\\');
- if (pTmp)
- {
- *pTmp = 0;
- }
- PathAppend(strCfgFile.GetBufferSetLength(MAX_PATH), _T("cfg.ini"));
- strCfgFile.ReleaseBuffer();
- CString strPath;
- GetPrivateProfileString(_T("datpath"), _T("value"), _T(""), strPath.GetBufferSetLength(MAX_PATH), MAX_PATH, strCfgFile.GetBuffer());
- strPath.ReleaseBuffer();
- CString strFileName;
- if (strPath.IsEmpty())
- {
- strFileName.Format(_T("TableData\\Table_%s_%d.dat"), TableId, count);
- }
- else
- {
- strFileName.Format(_T("%s\\TableData\\Table_%s_%d.dat"), strPath.GetBuffer(), TableId, count);
- }
-
- CString strCreate;
- strCreate = strPath;
- PathAppend(strCreate.GetBufferSetLength(MAX_PATH), _T("\\TableData"));
- strCreate.ReleaseBuffer();
- if (!PathFileExists(strCreate.GetBuffer()))
- {
- CreateDirectory(strCreate.GetBuffer(), NULL);
- }
- HANDLE hFile = CreateFile(strFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_NEW, NULL, NULL);
- if (hFile != INVALID_HANDLE_VALUE)
- {
- DWORD dwWrite;
- WriteFile(hFile, m_cbRepertoryCard, m_cbTotalCardCount, &dwWrite, NULL);
- CloseHandle(hFile);
- }
-
- }
-
- BOOL CTableFrameSink_tdh::ReadGameData()
- {
- CString strFileName;
- strFileName = _T("Table.dat");
- if (!PathFileExists(_T("Table.dat")))
- {
- return FALSE;
- }
-
- HANDLE hFile = CreateFile(strFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, NULL, NULL);
- if (hFile != INVALID_HANDLE_VALUE)
- {
- DWORD dwRead;
- DWORD dwFileSize;
- DWORD fileSize = GetFileSize(hFile, &dwFileSize);
- if (fileSize != m_cbTotalCardCount)
- {
- CloseHandle(hFile);
- return FALSE;
- }
- SetFilePointer(hFile, 0, 0, FILE_BEGIN);
-
- //BYTE tmpCard[MAX_REPERTORY_ZJ] = { 0 };
-
- ReadFile(hFile, m_cbRepertoryCard, m_cbTotalCardCount, &dwRead, NULL);
-
- CloseHandle(hFile);
- }
- return TRUE;
- }
- //打印玩家所有积分
- void CTableFrameSink_tdh::PrintUsersScore(LPCTSTR lpstrInfo)
- {
- //OutputDebugString(lpstrInfo);
- CString strInfo;
- for (int i = 0; i < mPlayGameUserCount; i++)
- {
- if (m_bTwoPlayerFlag&&i == TowMjNullseat)
- {
- continue;
- }
- CString strTmp;
- strTmp.Format(_T("UserID =%d 本次变更积分 %d 本局剩余拥有积分%d"),
- i, m_lGameScore[i], m_lGameTatolScore[i]);
- //OutputDebugString(strTmp);
- }
- }
-
-
-
-
- //被动操作删除手牌
- bool CTableFrameSink_tdh::DeleteCaiShenCard(WORD wTargetUser, BYTE cbTargetCaiCard[4], int cbTargetAction, BYTE cbTargetCard)
- {
- switch (cbTargetAction)
- {
- case WIK_SAN_MING_GANG:
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[0])]--)
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[1])]--)
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[2])]--)
- {
- ASSERT(m_cbWeaveItemCount[wTargetUser] < 4);
- if (m_cbWeaveItemCount[wTargetUser] > 4)return false;
- WORD wIndex = m_cbWeaveItemCount[wTargetUser]++;
- m_WeaveItemArray[wTargetUser][wIndex].cbPublicCard = TRUE;
- m_WeaveItemArray[wTargetUser][wIndex].cbCenterCard = cbTargetCard;
- m_WeaveItemArray[wTargetUser][wIndex].cbWeaveKind = cbTargetAction;
- m_WeaveItemArray[wTargetUser][wIndex].wProvideUser = (m_wProvideUser == INVALID_CHAIR) ? wTargetUser : m_wProvideUser;
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[0] = cbTargetCaiCard[0];
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[1] = cbTargetCaiCard[1];
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[2] = cbTargetCaiCard[2];
-
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
-
-
- m_cbGangCount++;//打了几个杠
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_DAN_CHI:
- case WIK_SHUANG_CAICHI:
- case WIK_SHUANG_PENG:
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[0])]--)
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[1])]--)
- {
- ASSERT(m_cbWeaveItemCount[wTargetUser] < 4);
- if (m_cbWeaveItemCount[wTargetUser] > 4)return false;
- WORD wIndex = m_cbWeaveItemCount[wTargetUser]++;
- m_WeaveItemArray[wTargetUser][wIndex].cbPublicCard = TRUE;
- m_WeaveItemArray[wTargetUser][wIndex].cbCenterCard = cbTargetCard;
- m_WeaveItemArray[wTargetUser][wIndex].cbWeaveKind = cbTargetAction;
- m_WeaveItemArray[wTargetUser][wIndex].wProvideUser = (m_wProvideUser == INVALID_CHAIR) ? wTargetUser : m_wProvideUser;
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[0] = cbTargetCaiCard[0];
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[1] = cbTargetCaiCard[1];
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_SHUANG_MING_GANG:
- {
- BYTE CardIndex = m_GameLogic.SwitchToCardIndex(cbTargetCard);
- if (m_cbCardIndex[wTargetUser][CardIndex]--)
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[0])]--)
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[1])]--)
- {
- ASSERT(m_cbWeaveItemCount[wTargetUser] < 4);
- if (m_cbWeaveItemCount[wTargetUser] > 4)return false;
- WORD wIndex = m_cbWeaveItemCount[wTargetUser]++;
- m_WeaveItemArray[wTargetUser][wIndex].cbPublicCard = TRUE;
- m_WeaveItemArray[wTargetUser][wIndex].cbCenterCard = cbTargetCard;
- m_WeaveItemArray[wTargetUser][wIndex].cbWeaveKind = cbTargetAction;
- m_WeaveItemArray[wTargetUser][wIndex].wProvideUser = (m_wProvideUser == INVALID_CHAIR) ? wTargetUser : m_wProvideUser;
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[0] = cbTargetCaiCard[0];
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[1] = cbTargetCaiCard[1];
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[2] = cbTargetCard;
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
- }
- m_cbGangCount++;//打了几个杠
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_DAN_PENG:
- {
- BYTE CardIndex = m_GameLogic.SwitchToCardIndex(cbTargetCard);
- if (m_cbCardIndex[wTargetUser][CardIndex]--)
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[0])]--)
- {
- ASSERT(m_cbWeaveItemCount[wTargetUser] < 4);
- if (m_cbWeaveItemCount[wTargetUser] > 4)return false;
- WORD wIndex = m_cbWeaveItemCount[wTargetUser]++;
- m_WeaveItemArray[wTargetUser][wIndex].cbPublicCard = TRUE;
- m_WeaveItemArray[wTargetUser][wIndex].cbCenterCard = cbTargetCard;
- m_WeaveItemArray[wTargetUser][wIndex].cbWeaveKind = cbTargetAction;
- m_WeaveItemArray[wTargetUser][wIndex].wProvideUser = (m_wProvideUser == INVALID_CHAIR) ? wTargetUser : m_wProvideUser;
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[0] = cbTargetCaiCard[0];
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_DAN_MING_GANG:
- {
- BYTE CardIndex = m_GameLogic.SwitchToCardIndex(cbTargetCard);
- if (m_cbCardIndex[wTargetUser][CardIndex] - 2 >= 0)
- {
- m_cbCardIndex[wTargetUser][CardIndex] -= 2;
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(cbTargetCaiCard[0])]--)
- {
- ASSERT(m_cbWeaveItemCount[wTargetUser] < 4);
- if (m_cbWeaveItemCount[wTargetUser] > 4)return false;
- WORD wIndex = m_cbWeaveItemCount[wTargetUser]++;
- m_WeaveItemArray[wTargetUser][wIndex].cbPublicCard = TRUE;
- m_WeaveItemArray[wTargetUser][wIndex].cbCenterCard = cbTargetCard;
- m_WeaveItemArray[wTargetUser][wIndex].cbWeaveKind = cbTargetAction;
- m_WeaveItemArray[wTargetUser][wIndex].wProvideUser = (m_wProvideUser == INVALID_CHAIR) ? wTargetUser : m_wProvideUser;
- m_WeaveItemArray[wTargetUser][wIndex].cbMargicOffset[0] = cbTargetCaiCard[0];
-
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
-
- m_cbGangCount++;//打了几个杠
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_LEFT: //上牌操作,左吃
- {
- //删除扑克
- BYTE cbRemoveCard[3];
- BYTE cbMagicCard[4] = { 0 };
- m_GameLogic.GetWeaveCard(WIK_LEFT, cbTargetCard, cbMagicCard, cbRemoveCard);
- VERIFY(m_GameLogic.RemoveCard(cbRemoveCard, 3, &cbTargetCard, 1));
- VERIFY(m_GameLogic.RemoveCard(m_cbCardIndex[wTargetUser], cbRemoveCard, 2));
- return true;
- }
- case WIK_RIGHT: //上牌操作,右吃
- {
- //删除扑克
- BYTE cbRemoveCard[3];
- BYTE cbMagicCard[4] = { 0 };
- m_GameLogic.GetWeaveCard(WIK_RIGHT, cbTargetCard, cbMagicCard, cbRemoveCard);
- VERIFY(m_GameLogic.RemoveCard(cbRemoveCard, 3, &cbTargetCard, 1));
- VERIFY(m_GameLogic.RemoveCard(m_cbCardIndex[wTargetUser], cbRemoveCard, 2));
- return true;
- }
- case WIK_CENTER: //上牌操作,中吃
- {
- //删除扑克
- BYTE cbRemoveCard[3];
- BYTE cbMagicCard[4] = { 0 };
- m_GameLogic.GetWeaveCard(WIK_CENTER, cbTargetCard, cbMagicCard, cbRemoveCard);
- VERIFY(m_GameLogic.RemoveCard(cbRemoveCard, 3, &cbTargetCard, 1));
- VERIFY(m_GameLogic.RemoveCard(m_cbCardIndex[wTargetUser], cbRemoveCard, 2));
- return true;
- }
- case WIK_PENG: //碰牌操作
- {
- //删除扑克
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(m_cbProvideCard)] < 2)
- {
- ASSERT(false);
- return false;
- }
- BYTE cbRemoveCard[] = { cbTargetCard, cbTargetCard };
- VERIFY(m_GameLogic.RemoveCard(m_cbCardIndex[wTargetUser], cbRemoveCard, 2));
- return true;
- }
- case WIK_MING_GANG: //明杠牌操作
- {
- if (m_cbCardIndex[wTargetUser][m_GameLogic.SwitchToCardIndex(m_cbProvideCard)] != 3)
- {
- ASSERT(false);
- return false;
- }
- BYTE cbRemoveCard[] = { cbTargetCard, cbTargetCard, cbTargetCard };
- VERIFY(m_GameLogic.RemoveCard(m_cbCardIndex[wTargetUser], cbRemoveCard, CountArray(cbRemoveCard)));
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
- m_cbGangCount++;//打了几个杠
- return true;
- }
- default:
- {
- ASSERT(false);
- return false;
- }
- }
- }
- //自主操作删除手牌
- bool CTableFrameSink_tdh::DeleteCard(WORD wChairID, BYTE cbCaiShenCard[4], int cbOperateCode, BYTE cbOperateCard)
- {
- switch (cbOperateCode)
- {
- case WIK_QUANG_AN_GANG:
- {
- //变量定义
- BYTE cbWeaveIndex = 0xFF;
- BYTE cbCardIndex = m_GameLogic.SwitchToCardIndex(cbOperateCard);
- BYTE CaiShenCount = m_GameLogic.GetMaigcCardCount(m_cbCardIndex[wChairID]);
- if (CaiShenCount > 3)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[0])]--)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[1])]--)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[2])]--)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[3])]--)
- {
- cbWeaveIndex = m_cbWeaveItemCount[wChairID]++;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = FALSE;
- m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[0] = cbCaiShenCard[0];
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[1] = cbCaiShenCard[1];
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[2] = cbCaiShenCard[2];
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[3] = cbCaiShenCard[3];
-
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
- m_cbGangCount++;//打了几个杠
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_SAN_AN_GANG:
- {
- //变量定义
- BYTE cbWeaveIndex = 0xFF;
- BYTE cbCardIndex = m_GameLogic.SwitchToCardIndex(cbOperateCard);
- BYTE CaiShenCount = m_GameLogic.GetMaigcCardCount(m_cbCardIndex[wChairID]);
- if (CaiShenCount > 2)
- {
- if (m_cbCardIndex[wChairID][cbCardIndex]--)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[0])]--)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[1])]--)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[2])]--)
- {
- cbWeaveIndex = m_cbWeaveItemCount[wChairID]++;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = FALSE;
- m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[0] = cbCaiShenCard[0];
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[1] = cbCaiShenCard[1];
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[2] = cbCaiShenCard[2];
-
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
-
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_SHUANG_AN_GANG:
- {
- //变量定义
- BYTE cbWeaveIndex = 0xFF;
- BYTE cbCardIndex = m_GameLogic.SwitchToCardIndex(cbOperateCard);
- BYTE CaiShenCount = m_GameLogic.GetMaigcCardCount(m_cbCardIndex[wChairID]);
- if (CaiShenCount > 1)
- {
- if (m_cbCardIndex[wChairID][cbCardIndex] - 2 >= 0)
- {
- m_cbCardIndex[wChairID][cbCardIndex] -= 2;
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[0])]--)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[1])]--)
- {
- cbWeaveIndex = m_cbWeaveItemCount[wChairID]++;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = FALSE;
- m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[0] = cbCaiShenCard[0];
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[1] = cbCaiShenCard[1];
-
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
-
- m_cbGangCount++;//打了几个杠
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_DAN_AN_GANG:
- {
- //变量定义
- BYTE cbWeaveIndex = 0xFF;
- BYTE cbCardIndex = m_GameLogic.SwitchToCardIndex(cbOperateCard);
- BYTE CaiShenCount = m_GameLogic.GetMaigcCardCount(m_cbCardIndex[wChairID]);
- if (CaiShenCount > 0)
- {
- if (m_cbCardIndex[wChairID][cbCardIndex] - 3 >= 0)
- {
- m_cbCardIndex[wChairID][cbCardIndex] -= 3;
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[0])]--)
- {
- cbWeaveIndex = m_cbWeaveItemCount[wChairID]++;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = FALSE;
- m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[0] = cbCaiShenCard[0];
-
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
- m_cbGangCount++;//打了几个杠
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_DAN_BU_GANG:
- {
- //变量定义
- BYTE cbWeaveIndex = 0xFF;
- BYTE cbCardIndex = m_GameLogic.SwitchToCardIndex(cbOperateCard);
- BYTE CaiShenCount = m_GameLogic.GetMaigcCardCount(m_cbCardIndex[wChairID]);
- if (CaiShenCount > 0 && cbCaiShenCard[0] != 0)
- {
- if (m_cbCardIndex[wChairID][m_GameLogic.SwitchToCardIndex(cbCaiShenCard[0])]--)
- {
- INT cbWeaveKind;
- for (BYTE i = 0; i < m_cbWeaveItemCount[wChairID]; i++)
- {
- cbWeaveKind = m_WeaveItemArray[wChairID][i].cbWeaveKind;
- BYTE cbCenterCard = m_WeaveItemArray[wChairID][i].cbCenterCard;
- if ((cbCenterCard == cbOperateCard) && (cbWeaveKind & (WIK_PENG | WIK_DAN_PENG | WIK_SHUANG_PENG)))
- {
- cbWeaveIndex = i;
- break;
- }
- }
- if (cbWeaveKind == WIK_PENG)
- {
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = true;
- //m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[0] = cbCaiShenCard[0];
- }
- else if (cbWeaveKind == WIK_DAN_PENG)
- {
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = true;
- //m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[1] = cbCaiShenCard[0];
- }
- else
- {
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = true;
- //m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbMargicOffset[2] = cbCaiShenCard[0];
- }
-
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
-
- m_cbGangCount++;//打了几个杠
- return true;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- else
- {
- ASSERT(false);
- return false;
- }
- }
- case WIK_AN_GANG: //暗杠牌操作
- {
- //扑克效验
- ASSERT((cbOperateCode == WIK_AN_GANG) || (m_GameLogic.IsValidCard(cbOperateCard) == true));
- if ((cbOperateCode != WIK_AN_GANG) && (m_GameLogic.IsValidCard(cbOperateCard) == false))
- return false;
- //变量定义
- BYTE cbWeaveIndex = 0xFF;
- BYTE cbCardIndex = m_GameLogic.SwitchToCardIndex(cbOperateCard);
- //杠牌处理
- if (m_cbCardIndex[wChairID][cbCardIndex] == 4)
- {
- //扑克效验
- ASSERT(m_cbCardIndex[wChairID][cbCardIndex] == 4);
- if (m_cbCardIndex[wChairID][cbCardIndex] != 4)
- {
- ASSERT(false);
- return false;
- }
-
- cbWeaveIndex = m_cbWeaveItemCount[wChairID]++;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = FALSE;
- m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- }
- else
- {
- ASSERT(FALSE);
- return false;
- }
- //删除扑克
- m_cbCardIndex[wChairID][cbCardIndex] = 0;
-
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
-
- m_cbGangCount++;//打了几个杠
- return true;
- }
- case WIK_BU_GANG:
- {
- //扑克效验
- ASSERT((cbOperateCode == WIK_NULL) || (cbOperateCode == WIK_BU_GANG) || (m_GameLogic.IsValidCard(cbOperateCard) == true));
- if ((cbOperateCode != WIK_BU_GANG) && (m_GameLogic.IsValidCard(cbOperateCard) == false))
- return false;
- BYTE cbWeaveIndex = 0xFF;
- BYTE cbCardIndex = m_GameLogic.SwitchToCardIndex(cbOperateCard);
- //杠牌处理
- if (m_cbCardIndex[wChairID][cbCardIndex] >= 1)//表示续杠类型
- {
- //寻找组合
- for (BYTE i = 0; i < m_cbWeaveItemCount[wChairID]; i++)
- {
- INT cbWeaveKind = m_WeaveItemArray[wChairID][i].cbWeaveKind;
- BYTE cbCenterCard = m_WeaveItemArray[wChairID][i].cbCenterCard;
- if ((cbCenterCard == cbOperateCard) && (cbWeaveKind &(WIK_DAN_PENG | WIK_PENG | WIK_SHUANG_PENG)))
- {
- cbWeaveIndex = i;
- break;
- }
- }
- //效验动作
- ASSERT(cbWeaveIndex != 0xFF);
- if (cbWeaveIndex == 0xFF) return false;
- //组合扑克
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbPublicCard = TRUE;
- //m_WeaveItemArray[wChairID][cbWeaveIndex].wProvideUser = wChairID;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbWeaveKind = cbOperateCode;
- m_WeaveItemArray[wChairID][cbWeaveIndex].cbCenterCard = cbOperateCard;
- }
- else
- {
- ASSERT(false);
- return false;
- }
- //删除扑克
- m_cbCardIndex[wChairID][cbCardIndex] -= 1;
- if (mPlayGameUserCount == 4)
- {
- if (m_cbLeftCardCount > 6)//扣除3墩可摸的牌
- m_cbLeftCardCount -= 6;
- else//少于三墩就只有一张可以抓的牌咯
- m_cbLeftCardCount = 1;
-
- }
-
- m_cbGangCount++;//打了几个杠
- return true;
- }
- default:
- {
- ASSERT(false);
- return false;
- };
- }
- }
- //优先级判断
- bool CTableFrameSink_tdh::OperatorPriority(WORD TempUser, WORD &wTargetUser, int &cbTargetAction)
- {
- for (WORD UserPlayIndex = 0; UserPlayIndex < mPlayGameUserCount; UserPlayIndex++)//除了打牌人,操作人与其他两位对操作优先级
- {
- if (m_bTwoPlayerFlag&&UserPlayIndex == TowMjNullseat)
- {
- continue;
- }
-
- TempUser = (TempUser + 1) % mPlayGameUserCount;
- if (TempUser == wTargetUser)continue;
- //获取动作
- int cbUserAction = (m_bResponse[TempUser] == false) ? m_cbUserAction[TempUser] : m_cbPerformAction[TempUser];
- //优先级别
- BYTE cbUserActionRank = m_GameLogic.GetUserActionRank(cbUserAction);
- BYTE cbTargetActionRank = m_GameLogic.GetUserActionRank(cbTargetAction);
- //动作判断
- if (cbUserActionRank > cbTargetActionRank)
- {
- wTargetUser = TempUser;
- cbTargetAction = cbUserAction;
- continue;
- }
- if (cbUserActionRank == cbTargetActionRank && cbTargetActionRank != WIK_NULL)
- {
- if (UserPlayIndex == 2)//肯定和其他人都比了,最后一次两个人的操作一样,且表示操作人不在末端操作人
- {
- return true;
- }
- else if (UserPlayIndex == 1)//对比一次,对比了两次说明操作人不是下家的下家;操作人只能是第一家或者最后一家,如果是第一家操作:,如果是最后一家
- {
- WORD TempTempUser = (TempUser + 1) % mPlayGameUserCount;
- if (wTargetUser == TempTempUser)//确定操作人是最后一个,这是第二次对比
- {
- wTargetUser = TempUser;
- cbTargetAction = cbUserAction;
- return true;
- }
- else//第一次对比,确定操作人是出牌人下家,这个时候再把他和后面一个人的牌权对比
- {
- int cbUserAction = (m_bResponse[TempTempUser] == false) ? m_cbUserAction[TempTempUser] : m_cbPerformAction[TempTempUser];
- //优先级别
- BYTE cbUserActionRank = m_GameLogic.GetUserActionRank(cbUserAction);
- BYTE cbTargetActionRank = m_GameLogic.GetUserActionRank(cbTargetAction);
- if (cbUserActionRank > cbTargetActionRank)
- {
- wTargetUser = TempTempUser;
- cbTargetAction = cbUserAction;
- return true;
- }
- break;
- }
- }
- else//冲上来就比了一次,说操作人不是打牌人下家
- {
- wTargetUser = TempUser;
- cbTargetAction = cbUserAction;
- WORD TempTempUser = (TempUser + 1) % mPlayGameUserCount;
- if (wTargetUser == TempTempUser)TempTempUser = (TempTempUser + 1) % mPlayGameUserCount;//如果在中间就换一个人
- int cbUserAction = (m_bResponse[TempTempUser] == false) ? m_cbUserAction[TempTempUser] : m_cbPerformAction[TempTempUser];
- //优先级别
- BYTE cbUserActionRank = m_GameLogic.GetUserActionRank(cbUserAction);
- BYTE cbTargetActionRank = m_GameLogic.GetUserActionRank(cbTargetAction);
- if (cbUserActionRank > cbTargetActionRank)
- {
- wTargetUser = TempTempUser;
- cbTargetAction = cbUserAction;
- return true;
- }
- return true;
- }
- }
- }
- return true;
- }
-
- int CTableFrameSink_tdh::bHuPaiType(CChiHuRight &CChiHuRight)
- {
- int hutype = 0;
- if (!(CChiHuRight&ZJ_TAI_QingYiSe).IsEmpty())
- {
- hutype |= ZJ_TAI_QingYiSe;
- }
- if (!(CChiHuRight&ZJ_TAI_DongFeng).IsEmpty())
- {
- hutype |= ZJ_TAI_DongFeng;
- }
- if (!(CChiHuRight&ZJ_TAI_WuMagic).IsEmpty())
- {
- hutype |= ZJ_TAI_WuMagic;
- }
- if (!(CChiHuRight&ZJ_TAI_QuanShun).IsEmpty())
- {
- hutype |= ZJ_TAI_QuanShun;
- }
- if (!(CChiHuRight&ZJ_TAI_PengPeng).IsEmpty())
- {
- hutype |= ZJ_TAI_PengPeng;
- }
- if (!(CChiHuRight&ZJ_TAI_HunYiSe).IsEmpty())
- {
- hutype |= ZJ_TAI_HunYiSe;
- }
- if (!(CChiHuRight&ZJ_TAI_Gang).IsEmpty())
- {
- hutype |= ZJ_TAI_Gang;
- }
- if (!(CChiHuRight&ZJ_TAI_ZFB).IsEmpty())
- {
- hutype |= ZJ_TAI_ZFB;
- }
- if (!(CChiHuRight&ZJ_TAI_QuanZi).IsEmpty())
- {
- hutype = ZJ_TAI_QuanZi;
- }
- if (!(CChiHuRight&ZJ_TAI_ZHAHU).IsEmpty())
- {
- hutype = ZJ_TAI_ZHAHU;
- }
- if (!(CChiHuRight&ZJ_TAI_SiCaiHu).IsEmpty())
- {
- hutype = ZJ_TAI_SiCaiHu;
- }
- if (!(CChiHuRight&ZJ_TAI_CaiDiao).IsEmpty())
- {
- hutype = ZJ_TAI_CaiDiao;
- }
- return hutype;
- }
|