void IRoomState::update(float fDeta) { if ( m_fStateDuring > 0 ) { m_fStateDuring -= fDeta ; if ( m_fStateDuring <= 0 ) { onStateDuringTimeUp(); } } }
bool CNiuNiuRoomStatePlayerCaculateCardState::onMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nPlayerSessionID ) { if ( IRoomState::onMessage(prealMsg,eSenderPort,nPlayerSessionID) ) { return true ; } switch ( prealMsg->usMsgType ) { case MSG_NN_PLAYER_CACULATE_CARD_OK: { ISitableRoomPlayer* pPlayer = m_pRoom->getSitdownPlayerBySessionID(nPlayerSessionID) ; if ( pPlayer == nullptr ) { LOGFMTE("you are not sit down how to caculate card session id = %d",nPlayerSessionID) ; return true ; } if ( pPlayer->isHaveState(eRoomPeer_CanAct) == false ) { LOGFMTE("you are not player in this game , how to cacuate card session id = %d", nPlayerSessionID ) ; return true ; } if ( m_vOperoateRecord.find(nPlayerSessionID) != m_vOperoateRecord.end() ) { LOGFMTE("don't do twice cacualte card session id %d",nPlayerSessionID ) ; return true ; } m_vOperoateRecord[nPlayerSessionID] = 1 ; --m_nWaitOperPlayerCnt; stMsgNNCaculateCardOk msg ; msg.nPlayerIdx = pPlayer->getIdx() ; m_pRoom->sendRoomMsg(&msg,sizeof(msg)); if ( m_nWaitOperPlayerCnt <= 0 ) { onStateDuringTimeUp(); } } break; default: return false; } return true ; }
bool CNiuNiuRoomGrabBanker::onMessage( stMsg* prealMsg , eMsgPort eSenderPort , uint32_t nPlayerSessionID ) { if ( IRoomState::onMessage(prealMsg,eSenderPort,nPlayerSessionID) ) { return true ; } if ( prealMsg->usMsgType != MSG_NN_PLAYER_TRY_BANKER ) { return false ; } stMsgNNPlayerTryBankerRet msgBack ; stMsgNNPlayerTryBanker* pTryBanker = (stMsgNNPlayerTryBanker*)prealMsg ; CNiuNiuRoomPlayer* pPlayer = (CNiuNiuRoomPlayer*)m_pRoom->getSitdownPlayerBySessionID(nPlayerSessionID) ; //SLOGFMTD("try banker uid = %d ,times = %d" , pPlayer->getUserUID(), pTryBanker->nTryBankerBetTimes) ; if ( pPlayer == nullptr ) { msgBack.nRet = 3 ; m_pRoom->sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ; return true ; } else if ( pPlayer->isHaveState(eRoomPeer_CanAct) == false ) { msgBack.nRet = 1 ; LOGFMTD("try banker state error uid = %d ,times = %d" , pPlayer->getUserUID(), pTryBanker->nTryBankerBetTimes) ; m_pRoom->sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ; return true ; } else if ( pPlayer->getCoin() < m_pRoom->getLeastCoinNeedForBeBanker( 1 ) ) { msgBack.nRet = 2 ; LOGFMTD("try banker coin not enough uid = %d ,times = %d" , pPlayer->getUserUID(), pTryBanker->nTryBankerBetTimes) ; m_pRoom->sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ; return true ; } auto iter = std::find(m_vWaitIdxs.begin(),m_vWaitIdxs.end(),pPlayer->getIdx()); if ( iter == m_vWaitIdxs.end() ) { LOGFMTD("you already grabed banker") ; msgBack.nRet = 4 ; m_pRoom->sendMsgToPlayer(&msgBack,sizeof(msgBack),nPlayerSessionID) ; return true ; } m_vWaitIdxs.erase(iter) ; stMsgNNTryBanker msgTry ; msgTry.nTryBankerBetTimes = pTryBanker->nTryBankerBetTimes ; msgTry.nTryerIdx = pPlayer->getIdx() ; m_pRoom->sendRoomMsg(&msgTry,sizeof(msgTry)) ; LOGFMTD("try banker ok uid = %d ,times = %d" , pPlayer->getUserUID(), pTryBanker->nTryBankerBetTimes) ; // if erveryone have bet , then end this state if ( pTryBanker->nTryBankerBetTimes > 0 ) { m_vGrabedIdx.push_back(pPlayer->getIdx()) ; } else { m_vRefusedGrabedIdx.push_back(pPlayer->getIdx()) ; } if ( m_vWaitIdxs.empty() ) { onStateDuringTimeUp(); } //LOGFMTD("try banker uid = %d ",pPlayer->getUserUID() ) ; return true ; }