//游戏消息处理 bool __cdecl CTableFrameSink::OnGameMessage(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem) { switch (wSubCmdID) { case SUB_C_ADD_GOLD: //用户加注 { //效验数据 tagServerUserData * pUserData=pIServerUserItem->GetUserData(); if (pUserData->cbUserStatus!=US_PLAY) return true; if (m_cbPlayStatus[pUserData->wChairID]==FALSE) return true; //消息处理 CMD_C_AddGold * pAddGold=(CMD_C_AddGold *)pDataBuffer; OnUserAddGold(pUserData->wChairID,pAddGold->lGold,false); return true; } case SUB_C_GIVE_UP: //用户放弃 { //效验数据 tagServerUserData * pUserData=pIServerUserItem->GetUserData(); if (pUserData->cbUserStatus!=US_PLAY) return true; if (m_cbPlayStatus[pUserData->wChairID]==FALSE) return true; //消息处理 OnUserGiveUp(pUserData->wChairID); return true; } } return false; }
//放弃事件 bool CTableFrameSink::OnUserGiveUp(WORD wChairID) { //状态判断 GT_ASSERT(m_bPlayStatus[wChairID]==TRUE); if (m_bPlayStatus[wChairID]==FALSE) return false; //设置数据 m_bPlayStatus[wChairID]=FALSE; //m_bTableCardCount[wChairID]=0; //发送放弃消息 CMD_S_GiveUp GiveUp; GiveUp.wUserChairID=wChairID; m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_GIVE_UP,&GiveUp,sizeof(GiveUp)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_GIVE_UP,&GiveUp,sizeof(GiveUp)); //判断结束 WORD wPlayerCount=0; for (WORD i=0;i<m_wPlayerCount;i++) { if (m_bPlayStatus[i]==TRUE) wPlayerCount++; } if (wPlayerCount>=2) { if (m_wCurrentUser==wChairID) OnUserAddGold(wChairID,0L,true); } else OnEventGameEnd(INVALID_CHAIR,NULL,GER_NO_PLAYER); return true; }
//放弃事件 bool CTableFrameSink::OnUserGiveUp(WORD wChairID) { //状态判断 ASSERT(m_cbPlayStatus[wChairID]==TRUE); if (m_cbPlayStatus[wChairID]==FALSE) return false; //效验 if( m_bGameEnd ) { m_pITableFrame->KillGameTimer(IDI_GAME_END); return OnEventGameEnd(INVALID_CHAIR,NULL,GER_NORMAL); } //设置数据 m_cbPlayStatus[wChairID]=FALSE; m_cbCardCount[wChairID]=0; //重新获取最大下注 if( m_lUserScore[wChairID] == m_lMaxGold ) { for( WORD i = 0; i < GAME_PLAYER; i ++ ) { if( !m_cbPlayStatus[i] ) continue; m_lMaxGold = m_lUserScore[i]; break; } for( ; i < GAME_PLAYER; i++ ) { if( m_cbPlayStatus[i] ) m_lMaxGold = __min(m_lMaxGold,m_lUserScore[i]); } } m_lTurnMaxGold = m_bSendCardCount>=3?m_lMaxGold:m_lMaxGold/2L; //发送放弃消息 CMD_S_GiveUp GiveUp; GiveUp.wUserChairID=wChairID; GiveUp.lTurnMaxGold = m_lTurnMaxGold; m_pITableFrame->SendTableData(INVALID_CHAIR,SUB_S_GIVE_UP,&GiveUp,sizeof(GiveUp)); m_pITableFrame->SendLookonData(INVALID_CHAIR,SUB_S_GIVE_UP,&GiveUp,sizeof(GiveUp)); //变量定义 LONG lScore=0; LONG lRevenue=0; enScoreKind ScoreKind; //设置变量 ScoreKind=enScoreKind_Lost; lScore=-m_lTableGold[wChairID*2]-m_lTableGold[wChairID*2+1]; //用户写分 m_pITableFrame->WriteUserScore(wChairID,lScore,lRevenue,ScoreKind); //判断结束 WORD wPlayerCount=0; for (WORD i=0;i<m_wPlayerCount;i++) { if (m_cbPlayStatus[i]==TRUE) wPlayerCount++; } if (wPlayerCount>=2) { if (m_wCurrentUser==wChairID) OnUserAddGold(wChairID,0L,true); } else OnEventGameEnd(INVALID_CHAIR,NULL,GER_NO_PLAYER); return true; }