Example #1
0
void CTaxasRoom::writeGameResultLog()
{
	LOGFMTD("write game result dlg");
	stMsgSaveLog saveMsg ;
	saveMsg.nLogType = eLog_TaxasGameResult ;
	saveMsg.nTargetID = getRoomID();
	saveMsg.vArg[0] = 0;
	for ( uint8_t nIdx = 0 ; nIdx < TAXAS_PUBLIC_CARD; ++nIdx )
	{
		saveMsg.vArg[nIdx+1] = m_vPublicCardNums[nIdx];
	}

	for ( uint8_t nIdx = 0 ; nIdx < MAX_PEERS_IN_TAXAS_ROOM ; ++nIdx )
	{
		writePlayerResultLogToJson((CTaxasPlayer*)getPlayerByIdx(nIdx)) ;
	}

	Json::StyledWriter write ;
	std::string str = write.write(m_arrPlayers);
	CAutoBuffer auBuffer (sizeof(saveMsg) + str.size());
	saveMsg.nJsonExtnerLen = str.size() ;
	auBuffer.addContent((char*)&saveMsg,sizeof(saveMsg)) ;
	auBuffer.addContent(str.c_str(),str.size());
	CTaxasServerApp::SharedGameServerApp()->sendMsg(getRoomID(),auBuffer.getBufferPtr(),auBuffer.getContentSize()) ;
	LOGFMTD("all player info json str = %s" , str.c_str());
}
Example #2
0
void CTaxasRoom::OnPlayerActTimeOut()
{
	stMsgTaxasPlayerAct msg ;
	msg.cSysIdentifer = 0 ;
	msg.nValue = 0 ;
	msg.nRoomID = getRoomID() ;
	CTaxasPlayer* pPlayer = (CTaxasPlayer*)getPlayerByIdx(m_nCurWaitPlayerActionIdx);
	if ( pPlayer == nullptr )
	{
		LOGFMTE("why cur wait player is null ");
		return ;
	}

	if ( m_nMostBetCoinThisRound == pPlayer->getBetCoinThisRound() )
	{
		msg.nPlayerAct = eRoomPeerAction_Pass ;
	}
	else
	{
		msg.nPlayerAct = eRoomPeerAction_GiveUp ;
	}
	LOGFMTD("wait player act time out auto act room id = %d",getRoomID()) ;
	onMessage(&msg,ID_MSG_PORT_CLIENT,pPlayer->getSessionID()) ;
	pPlayer->increaseNoneActTimes();
}
Example #3
0
void CNiuNiuRoom::onGameDidEnd()
{
	stMsgSaveLog msgSaveLog ;
	msgSaveLog.nLogType = eLog_NiuNiuGameResult ;
	msgSaveLog.nTargetID = getRoomID() ;
	msgSaveLog.nJsonExtnerLen = 0 ;
	memset(msgSaveLog.vArg,0,sizeof(msgSaveLog.vArg));
	msgSaveLog.vArg[0] = 0;//getPlayerByIdx(m_nBankerIdx)->getUserUID();
	msgSaveLog.vArg[1] = m_nBetBottomTimes ;
	msgSaveLog.vArg[2] = getBaseBet() * m_nBetBottomTimes ;
	m_arrPlayers.clear() ;

	/*m_nBankerIdx = 0 ;
	m_nBankerCoinLimitForBet = 0 ;
	m_nBetBottomTimes = 0 ;*/

	uint8_t nSeatCnt = (uint8_t)getSeatCount() ;
	for ( uint8_t nIdx = 0; nIdx < nSeatCnt; ++nIdx )
	{
		ISitableRoomPlayer* pSitDown = getPlayerByIdx(nIdx) ;
		if ( pSitDown == nullptr )
		{
			continue;
		}

		// write to log 
		if ( pSitDown->isHaveState(eRoomPeer_CanAct) )
		{
			CNiuNiuRoomPlayer* pNiuPlayer = (CNiuNiuRoomPlayer*)pSitDown ;
			Json::Value refPlayer ;
			refPlayer["uid"] = pNiuPlayer->getUserUID() ;
			refPlayer["idx"] = pNiuPlayer->getIdx();
			refPlayer["betTimes"] = pNiuPlayer->getBetTimes() <= 0 ? 5 : pNiuPlayer->getBetTimes();
			refPlayer["card0"] = pNiuPlayer->getCardByIdx(0);
			refPlayer["card1"] = pNiuPlayer->getCardByIdx(1);
			refPlayer["card2"] = pNiuPlayer->getCardByIdx(2);
			refPlayer["card3"] = pNiuPlayer->getCardByIdx(3);
			refPlayer["card4"] = pNiuPlayer->getCardByIdx(4);
			refPlayer["offset"] = 0 ;//pNiuPlayer->getCoinOffsetThisGame() ;
			refPlayer["coin"] = (int32_t)pNiuPlayer->getCoin() ;
			m_arrPlayers[pNiuPlayer->getIdx()] = refPlayer ;
		}

		//pSitDown->removeState(eRoomPeer_CanAct);
	}

	Json::StyledWriter write ;
	std::string str = write.write(m_arrPlayers);
	CAutoBuffer auBuffer (sizeof(msgSaveLog) + str.size());
	msgSaveLog.nJsonExtnerLen = str.size() ;
	auBuffer.addContent((char*)&msgSaveLog,sizeof(msgSaveLog)) ;
	auBuffer.addContent(str.c_str(),str.size());
	sendMsgToPlayer((stMsg*)auBuffer.getBufferPtr(),auBuffer.getContentSize(),getRoomID()) ;

	ISitableRoom::onGameDidEnd();
	LOGFMTD("room game End");
}
Example #4
0
void IRoom::onPlayerEnterRoom(stEnterRoomData* pEnterRoomPlayer ,int8_t& nSubIdx)
{
	stStandPlayer* pp = getPlayerByUserUID(pEnterRoomPlayer->nUserUID);
	stStandPlayer * pStandPlayer = nullptr ;
	if ( pp )
	{
		LOGFMTE("player uid = %d , already in this room, can not enter twice, data svr crashed ?",pEnterRoomPlayer->nUserUID) ;
		pStandPlayer = pp ;
		pStandPlayer->nUserSessionID = pEnterRoomPlayer->nUserSessionID;
	}
	else
	{
		pStandPlayer = new stStandPlayer ;
		memset(pStandPlayer,0,sizeof(stStandPlayer));
	}

	memcpy_s(pStandPlayer,sizeof(stStandPlayer),pEnterRoomPlayer,sizeof(stEnterRoomData));
	if ( getDelegate() && getDelegate()->isOmitNewPlayerHalo(this)  )
	{
		pStandPlayer->nNewPlayerHaloWeight = 0 ;
		LOGFMTD("room id = %d omit new player halo so halo weith = 0  for uid = %d", getRoomID(),pStandPlayer->nUserUID) ;
	}

	addRoomPlayer(pStandPlayer) ;
}
Example #5
0
void CTaxasRoom::didCaculateGameResult()
{
	// save serve log 
	writeGameResultLog();
	
	// update coin Tax  and insurance ;
	Json::Value arrayJs ;
	for ( uint8_t nIdx = 0 ; nIdx < getSeatCount(); ++nIdx )
	{
		CTaxasPlayer* pPlayer = (CTaxasPlayer*)getPlayerByIdx(nIdx);
		if ( pPlayer == nullptr || pPlayer->isHaveState(eRoomPeer_StayThisRound) == false || pPlayer->getGameOffset() < (int)0 ) 
		{
			continue;
		}
		LOGFMTE("game end update offset");
		int32_t nTaxFee = (int32_t)(pPlayer->getGameOffset() * getChouShuiRate()) + pPlayer->getInsuranceLoseCoin();
		pPlayer->setCoin(pPlayer->getCoin() - nTaxFee );
		addTotoalProfit((uint32_t)nTaxFee);
		LOGFMTD("room id = %u uid = %u , give tax = %d coin = %u",getRoomID(),nTaxFee,pPlayer->getCoin()) ;

		Json::Value jsPeer ;
		jsPeer["idx"] = nIdx ;
		jsPeer["coin"] = pPlayer->getCoin() ;
		arrayJs[arrayJs.size()] = jsPeer ;
	}

	Json::Value jsmsg ;
	jsmsg["players"] = arrayJs ;
	sendRoomMsg(jsmsg,MSG_SYNC_TAXAS_ROOM_PLAYER_COIN) ;
}
Example #6
0
void IRoom::onTimeSave( )
{
	LOGFMTD("time save room info room id = %u",getRoomID());

	//if ( m_bRoomInfoDiry )
	//{
	//	serializationToDB();
	//	m_bRoomInfoDiry = false ;
	//}
}
Example #7
0
bool IRoom::onFirstBeCreated(IRoomManager* pRoomMgr,uint32_t nRoomID, const Json::Value& vJsValue )
{
	m_pRoomMgr = pRoomMgr ;
	m_nRoomID = nRoomID ;
	m_nDeskFree = 0 ;
	m_fDividFeeRate = 0 ;

	m_nChatRoomID = 0;
	if ( vJsValue["chatRoomID"].isNull() == false )
	{
		m_nChatRoomID = vJsValue["chatRoomID"].asUInt() ;
		LOGFMTD("already have chat room id = %u, chat id = %u" , getRoomID(),getChatRoomID() ) ;
	}
	m_nTotalProfit = 0 ;
	prepareState();
	return true ;
}
Example #8
0
void IRoom::goToState(IRoomState* pTargetState )
{
	//assert(pTargetState != m_pCurRoomState && "go to the same state ? " );
	if ( pTargetState == m_pCurRoomState)
	{
		LOGFMTI("go to the same state %d , room id = %d ? ",pTargetState->getStateID(), getRoomID() );
	}
	
	m_pCurRoomState->leaveState() ;
	m_pCurRoomState = pTargetState ;
	m_pCurRoomState->enterState(this) ;

	stMsgRoomEnterNewState msgNewState ;
	msgNewState.m_fStateDuring = m_pCurRoomState->getStateDuring();
	msgNewState.nNewState = m_pCurRoomState->getStateID();
	//LOGFMTD(" enter to state = %u room id = %u",msgNewState.nNewState,getRoomID()) ;
	sendRoomMsg(&msgNewState,sizeof(msgNewState)) ;
}
Example #9
0
void GameScene::hidePopup(CCObject* pSender) {
	// Hide the popup again.
	if(pPopup->isVisible())
	{
		pPopup->setVisible(false);
		CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(pPopup);
 
		// Add this scene to the touch dispatcher again so that we enable all our touch input.
		CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
		CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(pMenu, kCCMenuHandlerPriority, true);

		int val = ((CCInteger*)pSender)->getValue();
		char data[128];
		sprintf(data, "%d", val);

		string result;
		g_Client->request(result, getRoomID(), 101, string(data));
	}
}
Example #10
0
uint8_t CTaxasRoom::InformPlayerAct()
{
	if ( m_nCurWaitPlayerActionIdx < 0 ) // first round 
	{
		LOGFMTD("fist round");
		m_nCurWaitPlayerActionIdx = GetFirstInvalidIdxWithState(m_nBigBlindIdx + 1 ,eRoomPeer_CanAct) ;
	}
	else
	{
		LOGFMTD("second round");
		m_nCurWaitPlayerActionIdx = GetFirstInvalidIdxWithState( m_nCurWaitPlayerActionIdx + 1 ,eRoomPeer_CanAct) ;
	}

	stMsgTaxasRoomWaitPlayerAct msgWait ;
	msgWait.nActPlayerIdx = m_nCurWaitPlayerActionIdx ;
	sendRoomMsg(&msgWait,sizeof(msgWait));
	LOGFMTD("room id = %d ,wait idx = %d act ",getRoomID(),m_nCurWaitPlayerActionIdx ) ;
	return m_nCurWaitPlayerActionIdx ;
}
Example #11
0
void IRoom::forcePlayersLeaveRoom()
{
	if ( getCurRoomState()->getStateID() != eRoomState_Close && eRoomState_WaitJoin != getCurRoomState()->getStateID() )
	{
		LOGFMTE("when player is palying do not force them out room id = %u",getRoomID()) ;
	}

	LIST_STAND_PLAYER vAllInRoomPlayers ;
	auto bGin = m_vInRoomPlayers.begin() ;
	while (bGin != m_vInRoomPlayers.end())
	{
		vAllInRoomPlayers.push_back(bGin->second) ;
		++bGin ;
	}

	for ( auto& p : vAllInRoomPlayers )
	{
		onPlayerWillLeaveRoom(p) ;
		playerDoLeaveRoom(p);
	}
}
Example #12
0
void CNiuNiuRoom::caculateGameResult()
{
	// caculate result ;
	CNiuNiuRoomPlayer* pBanker = (CNiuNiuRoomPlayer*)getPlayerByIdx(getBankerIdx()) ;
	assert(pBanker && "why banker is null ?");
	LOGFMTD("banker coin = %u",pBanker->getCoin()) ;
	
	bool isBankerHaveNiu = pBanker->isHaveNiu() ;
	bool isLoseToAll = true ;
	// send result msg ;
	stMsgNNGameResult msgResult ;
	msgResult.nPlayerCnt = getSortedPlayerCnt() ;

	CAutoBuffer auBuffer(sizeof(msgResult) + msgResult.nPlayerCnt * sizeof(stNNGameResultItem));
	auBuffer.addContent(&msgResult,sizeof(msgResult)) ;

	int32_t nBankerOffset = 0 ;
	// caclulate banker win ;
	uint8_t nIdx = 0 ;
	CNiuNiuPeerCard* perr = (CNiuNiuPeerCard*)pBanker->getPeerCard();
	for (  ;nIdx < msgResult.nPlayerCnt ; ++nIdx )
	{
		CNiuNiuRoomPlayer* pNNP = (CNiuNiuRoomPlayer*)getSortedPlayerByIdx(nIdx) ;
		assert(pNNP && "why have null player in sorted player list" );
		if ( pNNP == pBanker )
		{
			break;
		}

		uint32_t nLoseCoin = min(5,pNNP->getBetTimes()) * getBaseBet() * m_nBetBottomTimes * getReateByNiNiuType(perr->getType(),perr->getPoint()) ;
		if ( nLoseCoin > pNNP->getCoin() )
		{
			nLoseCoin = pNNP->getCoin() ;
			LOGFMTE("you do not have coin why you bet so many coin , uid = %d",pNNP->getUserUID());
		}

		nBankerOffset += nLoseCoin ;
		pNNP->setCoin(pNNP->getCoin() - nLoseCoin ) ;
		pBanker->setCoin(pBanker->getCoin() + nLoseCoin) ;

		stNNGameResultItem item ;
		item.nFinalCoin = pNNP->getCoin() ;
		item.nOffsetCoin = -1* nLoseCoin ;
		item.nPlayerIdx = pNNP->getIdx() ;
		auBuffer.addContent(&item,sizeof(item)) ;
		LOGFMTD("result item : idx = %u, uid = %u , offset = %d",item.nPlayerIdx,pNNP->getUserUID(),item.nOffsetCoin);
		pNNP->setGameOffset(item.nOffsetCoin);

		isLoseToAll = false ;
	}

	// caculate banker lose 
	++nIdx ;
	for (  ; nIdx < msgResult.nPlayerCnt ; ++nIdx )
	{
		CNiuNiuRoomPlayer* pNNP = (CNiuNiuRoomPlayer*)getSortedPlayerByIdx(nIdx) ;
		if ( pNNP == pBanker )
		{
			break;
		}

		CNiuNiuPeerCard* pc = (CNiuNiuPeerCard*)pNNP->getPeerCard();
		uint32_t nBankerLoseCoin = min(5,pNNP->getBetTimes()) * getBaseBet() * m_nBetBottomTimes * getReateByNiNiuType(pc->getType(),pc->getPoint())  ;
		if ( nBankerLoseCoin > pBanker->getCoin() )
		{
			nBankerLoseCoin = pBanker->getCoin() ;
		}

		nBankerOffset -= nBankerLoseCoin ;
		pBanker->setCoin(pBanker->getCoin() - nBankerLoseCoin ) ;
		float fTaxFee = (float)nBankerLoseCoin * getChouShuiRate();
		addTotoalProfit((uint32_t)fTaxFee);
		float nWithoutTaxWin = nBankerLoseCoin - fTaxFee ;

		pNNP->setCoin(pNNP->getCoin() + (int32_t)nWithoutTaxWin ) ;
		LOGFMTD("room id = %u , uid = %u without tax win = %0.3f",getRoomID(),pNNP->getUserUID(),nWithoutTaxWin) ;

		stNNGameResultItem item ;
		item.nFinalCoin = pNNP->getCoin() ;
		item.nOffsetCoin = (int32_t)nWithoutTaxWin ;
		item.nPlayerIdx = pNNP->getIdx() ;
		auBuffer.addContent(&item,sizeof(item)) ;
		LOGFMTD("result item : idx = %u, uid = %u , offset = %d",item.nPlayerIdx,pNNP->getUserUID(),item.nOffsetCoin);
		pNNP->setGameOffset(item.nOffsetCoin);
	}

	if ( nBankerOffset > (int32_t)0 )
	{
		float fTaxFee = (float)nBankerOffset * getChouShuiRate();
		addTotoalProfit((uint32_t)fTaxFee);
		nBankerOffset = nBankerOffset - (int32_t)fTaxFee ;
		LOGFMTD("room id = %u , banker uid = %u without tax win = %d",getRoomID(),pBanker->getUserUID(),nBankerOffset) ;
	}

	stNNGameResultItem item ;
	item.nFinalCoin = pBanker->getCoin() ;
	item.nOffsetCoin = nBankerOffset ;
	item.nPlayerIdx = pBanker->getIdx() ;
	auBuffer.addContent(&item,sizeof(item)) ;
	pBanker->setGameOffset(item.nOffsetCoin);
	LOGFMTD("result item : idx = %u, uid = %u , offset = %d",item.nPlayerIdx,pBanker->getUserUID(),item.nOffsetCoin);
	LOGFMTD("result player idx = %d , finalCoin = %d, offset coin = %d",item.nPlayerIdx,item.nFinalCoin,item.nOffsetCoin) ;

	sendRoomMsg((stMsg*)auBuffer.getBufferPtr(),auBuffer.getContentSize()) ;

	// check banker for coin 
	if ( pBanker->getCoin() < getLeastCoinNeedForBeBanker(1) )
	{
		m_nBankerIdx = -1 ;
		LOGFMTI("coin is not enough , so resign banker uid = %u",pBanker->getUserUID()) ;
	}
	// decide banker ;
	 // // 0 no niu leave banker , 1 lose to all  leave banker ;
	if ( ( m_nResignBankerCtrl == 0 && isBankerHaveNiu == false ) || (m_nResignBankerCtrl == 1 && isLoseToAll ) || ( 2 == m_nResignBankerCtrl && m_isWillManualLeaveBanker ) )
	{
		m_nBankerIdx = -1 ;
		m_isWillManualLeaveBanker = false ;
		LOGFMTD("resign banker ctrl = %u , isBankerHaveNiu = %u , isLoseToAll = %u",m_nResignBankerCtrl,isBankerHaveNiu,isLoseToAll) ;
	}
}
Example #13
0
void CTaxasRoom::CaculateVicePool(stVicePool& pPool )
{
	if ( pPool.nCoin == 0 )
	{
		LOGFMTE("why this pool coin is 0 ? players = %d room id = %d ",pPool.vInPoolPlayerIdx.size(),getRoomID()) ;
		return ;
	}

	if ( pPool.vInPoolPlayerIdx.empty() )
	{
		LOGFMTE("why pool coin = %u , peers is 0 room id = %d  ",pPool.nCoin,getRoomID() ) ;
	}

	// find winner ;
	if ( pPool.vInPoolPlayerIdx.size() == 1 )
	{
		uint8_t nPeerIdx = pPool.vInPoolPlayerIdx[0] ;
		auto pPlayer = (CTaxasPlayer*)getPlayerByIdx(nPeerIdx);
		if ( pPlayer == nullptr )
		{
			LOGFMTE("why this winner idx is invalid = %d, system got coin = %u",nPeerIdx,pPool.nCoin ) ;
			return ;
		}

		if ( pPlayer->isHaveState(eRoomPeer_WaitCaculate) == false )
		{
			LOGFMTE("why this winner idx state is invalid = %d, system got coin = %u",nPeerIdx,pPool.nCoin ) ;
			return ;
		}
		pPool.vWinnerIdxs.push_back( nPeerIdx ) ;
		pPlayer->addWinCoinThisGame(pPool.nCoin);
		return ;
	}

	// pk card
	if ( IsPublicDistributeFinish() == false )
	{
		LOGFMTE("public is not finish how to pk card ? error room id = %d",getRoomID());
		return ;
	}

	CTaxasPlayer* pWiner = nullptr ;
	for ( int8_t nIdx = getSortedPlayerCnt() - 1 ; nIdx >= 0; --nIdx )
	{
		CTaxasPlayer* pData = (CTaxasPlayer*)getSortedPlayerByIdx(nIdx);
		if ( pData == nullptr || pData->isHaveState( eRoomPeer_WaitCaculate ) == false )
		{
			continue; ;
		}

		if ( pPool.isPlayerInThisPool(pData->getIdx()) == false )
		{
			continue;
		}

		if ( pPool.vWinnerIdxs.empty() )
		{
			pPool.vWinnerIdxs.push_back(pData->getIdx()) ;
			pWiner = pData ;
			continue;
		}

		if ( pWiner->getPeerCard()->pk(pData->getPeerCard()) != IPeerCard::PK_RESULT_EQUAL ) // not the same , means small 
		{
			break ;
		}

		pPool.vWinnerIdxs.push_back(pData->getIdx()) ;
	}

	// give coin 
	if ( pPool.vWinnerIdxs.empty() )
	{
		LOGFMTE("why room id = %d pool idx = %d winner is empty , system got coin = %u ",getRoomID(),pPool.nIdx,pPool.nCoin ) ;
		return ;
	}

	uint8_t nElasCoin = uint8_t(pPool.nCoin % pPool.vWinnerIdxs.size()) ;
	pPool.nCoin -= nElasCoin ;
	if ( nElasCoin > 0 )
	{
		addTotoalProfit(nElasCoin);
		LOGFMTI("system got the elaps coin = %d, room id = %d , pool idx = %d ",nElasCoin,getRoomID(),pPool.nIdx ) ;
	}
	uint32_t nCoinPerWinner = pPool.nCoin / pPool.vWinnerIdxs.size() ;
	for ( uint8_t nIdx = 0 ; nIdx < pPool.vWinnerIdxs.size(); ++nIdx )
	{
		uint8_t nPeerIdx = pPool.vWinnerIdxs[nIdx];
		auto pPlayer = (CTaxasPlayer*)getPlayerByIdx(nPeerIdx);
		pPlayer->addWinCoinThisGame(nCoinPerWinner);
		LOGFMTI("player use uid = %d win coin = %u , from pool idx = %d, room id = %d",pPlayer->getUserUID(),nCoinPerWinner,pPool.nIdx,getRoomID()) ;
	}
}
Example #14
0
//return pool cnt ;
uint8_t CTaxasRoom::CaculateGameResult()
{
	// build a main pool;
	if ( m_nCurMainBetPool > 0 )
	{
		stVicePool& pPool = GetFirstCanUseVicePool();
		pPool.nCoin = m_nCurMainBetPool ;
		pPool.bUsed = true ;
		for ( uint8_t nIdx = 0 ; nIdx < getSeatCount() ; ++nIdx )
		{
			auto pPlayer = getPlayerByIdx(nIdx);
			if ( nullptr == pPlayer )
			{
				continue;
			}

			if ( pPlayer->isHaveState(eRoomPeer_CanAct) )
			{
				pPool.vInPoolPlayerIdx.push_back(nIdx) ;
			}
		}
	}

	// cacluate a main pool ;
	for ( uint8_t nIdx = 0 ; nIdx < MAX_PEERS_IN_TAXAS_ROOM; ++nIdx )
	{
		if ( m_vAllVicePools[nIdx].bUsed )
		{
			CaculateVicePool(m_vAllVicePools[nIdx]) ;
		}
	}

	// send msg tell client ;
	if ( GetFirstCanUseVicePool().nIdx == 0 )
	{
		LOGFMTE("why this game have no pool ? at least should have one room id = %d",getRoomID() ) ;
		didCaculateGameResult();
		return 0 ;
	}

	uint8_t nLastPoolIdx = GetFirstCanUseVicePool().nIdx ;
	bool bSendEndFlag = false ;
	for ( uint8_t nIdx = 0 ; nIdx < nLastPoolIdx; ++nIdx )
	{
		stVicePool& pool = m_vAllVicePools[nIdx] ;
		if ( pool.vWinnerIdxs.empty() )
		{
			LOGFMTE("this pool have no winners , coin = %u, room = %d ",pool.nCoin,getRoomID() ) ;
			continue;
		}

		stMsgTaxasRoomGameResult msgResult ;
		msgResult.nCoinPerWinner = pool.nCoin / pool.vWinnerIdxs.size() ;
		msgResult.nPoolIdx = nIdx ;
		msgResult.nWinnerCnt = 0;
		msgResult.bIsLastOne = (nIdx + 1) >= nLastPoolIdx ;
		LOGFMTD("game reuslt pool idx = %d  isLast one = %d",nIdx,msgResult.bIsLastOne ) ;
		VEC_INT8::iterator iter = pool.vWinnerIdxs.begin() ;
		for ( ; iter != pool.vWinnerIdxs.end() ; ++iter )
		{
			msgResult.vWinnerIdx[msgResult.nWinnerCnt++] = (*iter); 
		}
		sendRoomMsg(&msgResult,sizeof(msgResult)) ;
		if ( msgResult.bIsLastOne )
		{
			bSendEndFlag = true ;
		}
	}

	if ( bSendEndFlag == false )  // must have a end flag msg ;
	{
		stMsgTaxasRoomGameResult msgResult ;
		msgResult.nCoinPerWinner = 0;
		msgResult.nPoolIdx = nLastPoolIdx ;
		msgResult.nWinnerCnt = 0;
		msgResult.bIsLastOne = true ;
		sendRoomMsg(&msgResult,sizeof(msgResult)) ;
	}
	didCaculateGameResult();
	return GetFirstCanUseVicePool().nIdx ;
}
Example #15
0
 // return produced vice pool c**t this round ;
uint8_t CTaxasRoom::CaculateOneRoundPool()
{
	// check build vice pool
	uint8_t nBeforeVicePoolIdx = GetFirstCanUseVicePool().nIdx ;
	uint32_t nVicePool = 0 ;
	while ( true )
	{
		// find maybe pool 
		nVicePool = 0 ;
		for ( uint8_t nIdx = 0 ; nIdx < getSeatCount() ; ++nIdx )
		{
			auto pPlayer = (CTaxasPlayer*)getPlayerByIdx(nIdx);
			if ( pPlayer == nullptr || (pPlayer->isHaveState(eRoomPeer_WaitCaculate) == false ) )
			{
				continue;
			}

			if ( pPlayer->getCurActType() == eRoomPeerAction_AllIn && pPlayer->getBetCoinThisRound() > 0 )
			{
				if ( pPlayer->getBetCoinThisRound() < nVicePool || nVicePool == 0 )
				{
					nVicePool = pPlayer->getBetCoinThisRound() ;
				}
			}
		}

		if ( nVicePool == 0 )
		{
			break;
		}

		// real build pool;
		stVicePool& pPool = GetFirstCanUseVicePool();
		pPool.bUsed = true ;
		pPool.nCoin = m_nCurMainBetPool ;
		m_nCurMainBetPool = 0 ;
		
		// put player idx in pool ;
		LOGFMTD("build pool pool idx = %d",pPool.nIdx ) ;
		for ( uint8_t nIdx = 0 ; nIdx < getSeatCount() ; ++nIdx )
		{
			auto pPlayer = (CTaxasPlayer*)getPlayerByIdx(nIdx);
			if ( pPlayer == nullptr || (pPlayer->isHaveState(eRoomPeer_WaitCaculate) == false ) )
			{
				continue;
			}

			if ( pPlayer->getBetCoinThisRound() > 0 )
			{
				if ( pPlayer->getBetCoinThisRound() < nVicePool )
				{
					LOGFMTE("room id = %d , put vice pool coin not enough , why error error",getRoomID()) ;
				}
				pPool.nCoin += nVicePool ;
				pPlayer->setBetCoinThisRound(pPlayer->getBetCoinThisRound() - nVicePool ) ;
				pPool.vInPoolPlayerIdx.push_back(nIdx) ;
				LOGFMTD("put player into pool player Idx = %d, UID = %d",nIdx,pPlayer->getUserUID() ) ;
			}
		}
		LOGFMTI("pool idx = %d : coin = %u",pPool.nIdx,pPool.nCoin) ;
	}

	// build mian pool ;
	LOGFMTD("build main pool: " ) ;
	for ( uint8_t nIdx = 0 ; nIdx < getSeatCount() ; ++nIdx )
	{
		auto pPlayer = (CTaxasPlayer*)getPlayerByIdx(nIdx);
		if ( pPlayer == nullptr || (pPlayer->isHaveState(eRoomPeer_CanAct) == false ) )
		{
			continue;
		}

		if ( pPlayer->getBetCoinThisRound() > 0 )
		{
			m_nCurMainBetPool += pPlayer->getBetCoinThisRound() ;
			pPlayer->setBetCoinThisRound(0);
			LOGFMTD("put player into Main pool player Idx = %d, UID = %d",nIdx,pPlayer->getUserUID()) ;
		}
	}

	uint8_t nProducedVicePoolCnt = GetFirstCanUseVicePool().nIdx - nBeforeVicePoolIdx;
	LOGFMTI("oneRound Caculate over, mainPool = %u, newVicePool = %d",m_nCurMainBetPool,nProducedVicePoolCnt );

	// send msg tell client [ nBeforeVicePoolIdx, GetFirstCanUseVicePoolIdx() ); this set of pool idx are new produced ; not include the last 
	stMsgTaxasRoomOneBetRoundResult msgResult ;
	msgResult.nCurMainPool = m_nCurMainBetPool ;
	msgResult.nNewVicePoolCnt = nProducedVicePoolCnt ;
	memset(msgResult.vNewVicePool,0,sizeof(msgResult.vNewVicePool)) ;
	for ( uint8_t nIdx = nBeforeVicePoolIdx, nNewIdx = 0 ; nIdx < GetFirstCanUseVicePool().nIdx; ++nIdx )
	{
		msgResult.vNewVicePool[nNewIdx++] = m_vAllVicePools[nIdx].nCoin ;
	}
	sendRoomMsg(&msgResult,sizeof(msgResult)) ;
	return nProducedVicePoolCnt ;
}
Example #16
0
uint8_t CTaxasRoom::OnPlayerAction( uint8_t nSeatIdx ,eRoomPeerAction act , uint32_t& nValue )
{
	if ( nSeatIdx >= getSeatCount() || getPlayerByIdx(nSeatIdx) == nullptr )
	{
		return 2 ;
	}

	if ( nSeatIdx != m_nCurWaitPlayerActionIdx && act != eRoomPeerAction_GiveUp )
	{
		return 1 ;
	}

	if ( getPlayerByIdx(nSeatIdx)->isHaveState(eRoomPeer_CanAct) == false )
	{
		return 3 ;
	}

	CTaxasPlayer* pData = (CTaxasPlayer*)getPlayerByIdx(nSeatIdx) ;
	switch ( act )
	{
	case eRoomPeerAction_GiveUp:
		{
			m_nCurMainBetPool += pData->getBetCoinThisRound() ;
			pData->setCurActType(eRoomPeerAction_GiveUp);
			pData->setState(eRoomPeer_GiveUp);
			// remove from vice pool
			for ( uint8_t nIdx = 0 ; nIdx < MAX_PEERS_IN_TAXAS_ROOM; ++nIdx )
			{
				if ( m_vAllVicePools[nIdx].bUsed == false )
				{
					break;
				}
				m_vAllVicePools[nIdx].RemovePlayer(nSeatIdx) ;
			}
		}
		break;
	case eRoomPeerAction_Follow:
		{
			if ( pData->getCoin() + pData->getBetCoinThisRound() <= m_nMostBetCoinThisRound )
			{
				nValue = pData->getCoin() ; // when all in must tell what value have allIned 
				return OnPlayerAction(nSeatIdx,eRoomPeerAction_AllIn,nValue);
			}
			pData->setCurActType(act);
			pData->betCoin(m_nMostBetCoinThisRound - pData->getBetCoinThisRound()) ;
		}
		break;
	case eRoomPeerAction_Add:
		{
			if ( pData->getCoin() <= nValue )
			{
				nValue = pData->getCoin() ; // when all in must tell what value have allIned
				return OnPlayerAction(nSeatIdx,eRoomPeerAction_AllIn,nValue);
			}

			if ( pData->getBetCoinThisRound() + nValue < m_nMostBetCoinThisRound + m_nLittleBlind * 2  )
			{
				return 6 ;
			}

			if ( ((pData->getBetCoinThisRound() + nValue) - m_nMostBetCoinThisRound ) % (m_nLittleBlind * 2) != 0  )
			{
				return 7 ;
			}

			pData->setCurActType(act);
			pData->betCoin(nValue) ;
			m_nMostBetCoinThisRound = pData->getBetCoinThisRound() ;
		}
		break;
	case eRoomPeerAction_AllIn:
		{
			pData->setCurActType(act);
			pData->setState(eRoomPeer_AllIn);
			nValue = pData->getCoin() ;
			pData->betCoin(nValue) ;
			if ( pData->getBetCoinThisRound() == 0 )
			{
				pData->setBetCoinThisRound(1);// avoid 0 all In bug ;
				LOGFMTE("room id = %d , 0 coin all in player idx = %d, uid = %d",getRoomID(),nSeatIdx,pData->getUserUID()) ;
			}

			if ( pData->getBetCoinThisRound() > m_nMostBetCoinThisRound )
			{
				m_nMostBetCoinThisRound = pData->getBetCoinThisRound() ;
			}
		}
		break;
	case eRoomPeerAction_Pass:
		{
			if ( m_nMostBetCoinThisRound != pData->getBetCoinThisRound() )
			{
				return 5 ;
			}

			pData->setCurActType(eRoomPeerAction_Pass);
		}
		break;
	default:
		return 4 ;
	}

	stMsgTaxasRoomAct msgOtherAct ;
	msgOtherAct.nPlayerAct = act ;
	msgOtherAct.nPlayerIdx = nSeatIdx ;
	msgOtherAct.nValue = nValue ;
	sendRoomMsg(&msgOtherAct,sizeof(msgOtherAct)) ;
	LOGFMTD("player do act") ;

	if ( pData->isDelayStandUp() && act == eRoomPeerAction_GiveUp )
	{
		LOGFMTD("uid = %d have delay standup , give up act , right standup and update offset ",pData->getUserUID());
		if ( getDelegate() )
		{
			getDelegate()->onUpdatePlayerGameResult(this,pData->getUserUID(),pData->getGameOffset());
		}
		playerDoStandUp(pData);	
	}

	return 0 ;
}
Example #17
0
void ISitableRoom::doProcessNewPlayerHalo()
{
	// add peer 
	for ( uint8_t nIdx = 0 ; nIdx < m_nSeatCnt ; ++nIdx )
	{
		auto pPlayer = m_vSitdownPlayers[nIdx] ;
		if ( pPlayer && (pPlayer->isHaveState(eRoomPeer_CanAct)) )
		{
			m_vSortByPeerCardsAsc.push_back(pPlayer) ;
		}
	}

	if ( m_vSortByPeerCardsAsc.size() < 2 )
	{
		LOGFMTE("why can act player count not bigger than 2 room id = %u",getRoomID()) ;
		return ;
	}

	// sort by peer card 
	std::sort(m_vSortByPeerCardsAsc.begin(),m_vSortByPeerCardsAsc.end(),sortPlayerByCard);
	//if ( isOmitNewPlayerHalo() )
	//{
	//	return ;
	//}

	// process halo 
	uint8_t nHalfCnt = m_vSortByPeerCardsAsc.size() ;
	uint8_t nSwitchTargetIdx = m_vSortByPeerCardsAsc.size() - 1 ;
	for ( uint8_t nIdx = 0 ; nIdx < nHalfCnt; ++nIdx)
	{
		if ( m_vSortByPeerCardsAsc[nIdx]->isHaveHalo() == false )
		{
			continue;
		}

		for ( ; nSwitchTargetIdx > nIdx ; --nSwitchTargetIdx )
		{
			if ( m_vSortByPeerCardsAsc[nSwitchTargetIdx]->isHaveHalo() )
			{
				continue;
			}

			m_vSortByPeerCardsAsc[nIdx]->switchPeerCard(m_vSortByPeerCardsAsc[nSwitchTargetIdx]);
			auto player = m_vSortByPeerCardsAsc[nIdx] ;
			m_vSortByPeerCardsAsc[nIdx] = m_vSortByPeerCardsAsc[nSwitchTargetIdx] ;
			m_vSortByPeerCardsAsc[nSwitchTargetIdx] = player ;

			if ( nSwitchTargetIdx == 0 )
			{
				return ;
			}
			--nSwitchTargetIdx;
			break;
		}
	}
#ifndef NDEBUG
	LOGFMTD("room id = %u do halo result:",getRoomID());
	for ( uint8_t nIdx = 0 ; nIdx < m_vSortByPeerCardsAsc.size() ; ++nIdx )
	{
		LOGFMTD("idx = %u uid = %u",nIdx,m_vSortByPeerCardsAsc[nIdx]->getUserUID());
	}
	LOGFMTD("room id = %u halo end",getRoomID());
#endif // !NDEBUG

}