void SGBattle::SendCurrentTurn() { SFRoom* pRoom = GetOwner()->GetOwner(); auto& roomMember = pRoom->GetRoomMemberMap(); int currentUserID = m_pSevenGameManager->GetCurrentUserID(); SGUser* pSGUser = m_pSevenGameManager->FindUser(currentUserID); SFProtobufPacket<SevenGamePacket::CurrentTurn> currentTurn(SevenGame::CurrentTurn); if (pSGUser->GetID() <= 0) { currentTurn.GetData().set_playerindex(pSGUser->GetID()); currentTurn.GetData().set_playername("AI"); } else { auto& iter = roomMember.find(pSGUser->GetID()); SFASSERT(iter != roomMember.end()); SFPlayer* pCurrentTurnPlayer = iter->second; currentTurn.GetData().set_playerindex(pCurrentTurnPlayer->GetSerial()); currentTurn.GetData().set_playername(pCurrentTurnPlayer->GetPlayerName()); } m_dwLastPlayTickCount = GetTickCount(); BroadCast(currentTurn); }
BOOL SGBattle::OnEnter( int gameMode ) { SFRoom* pRoom = GetOwner()->GetOwner(); SFRoom::RoomMemberMap& roomMember = pRoom->GetRoomMemberMap(); m_nGameState = SG_GAME_PLAY; m_dwLastPlayTickCount = GetTickCount(); SFASSERT(roomMember.size() != 0 && roomMember.size() <= SEVENGAME_MEMBER_NUM); m_pSevenGameManager->Reset(); int playerCount = 0; for (auto& iter : roomMember) { SFPlayer* pPlayer = iter.second; m_pSevenGameManager->AddUser(pPlayer->GetSerial()); playerCount++; } int botSerial = -1; while(playerCount < SEVENGAME_MEMBER_NUM) { m_pSevenGameManager->AddUser(botSerial); botSerial--; playerCount++; } ResetGame(); return TRUE; }
BOOL SGBattle::SendPlayerID() { SFRoom* pRoom = GetOwner()->GetOwner(); auto& roomMember = pRoom->GetRoomMemberMap(); for(auto& iter : roomMember) { SFPlayer* pPlayer = iter.second; SFProtobufPacket<SevenGamePacket::PlayerID> packet(SevenGame::PlayerID); packet.SetSerial(pPlayer->GetSerial()); packet.GetData().set_playerindex(pPlayer->GetSerial()); SFEngine::GetInstance()->SendRequest(&packet); } return TRUE; }
BOOL SGBattle::BroadCast(BasePacket& packet) { SFRoom* pRoom = GetOwner()->GetOwner(); auto& roomMember = pRoom->GetRoomMemberMap(); for (auto& iter : roomMember) { SFPlayer* pPlayer = iter.second; packet.SetSerial(pPlayer->GetSerial()); SFEngine::GetInstance()->SendRequest(&packet); } return TRUE; }
BOOL SFRoomManager::SendRoomPage( SFPlayerLobby* pLobbyState, int PageIndex /*= 0*/ ) { SFPlayer* pOwner = pLobbyState->GetOwner(); int roomCnt = m_ActiveRoomMap.size(); //if(roomCnt == 0) //return TRUE; SFProtobufPacket<SFPacketStore::RoomList> roomList = SFProtobufPacket<SFPacketStore::RoomList>(CGSF::RoomList); roomList.SetOwnerSerial(pOwner->GetSerial()); if(m_ActiveRoomMap.size() <= MAX_ROOM_COUNT_PER_PAGE) { ActiveRoomMap::iterator iter = m_ActiveRoomMap.begin(); for(;iter != m_ActiveRoomMap.end(); iter++) { SFPacketStore::RoomList::RoomInfo* pRoomInfo = roomList.GetData().add_info(); SFRoom* pRoom = iter->second; pRoomInfo->set_roomindex(pRoom->GetRoomIndex()); std::string roomName = "GameRoom"; roomName += std::to_string(pRoom->GetRoomIndex()); pRoomInfo->set_roomname(roomName); pRoomInfo->set_roomchief(pRoom->GetRoomChief()->GetPlayerName()); pRoomInfo->set_usercount(pRoom->GetRoomMemberMap().size()); pRoomInfo->set_maxusercount(4); pRoomInfo->set_needpassword(0); pRoomInfo->set_gamemode(pRoom->GetGameModeInfo()->GameMode); } } SFLogicEntry::GetLogicEntry()->SendRequest(&roomList); return TRUE; }
BOOL SGBattle::SendMyCardInfo() { SFRoom* pRoom = GetOwner()->GetOwner(); auto& roomMember = pRoom->GetRoomMemberMap(); for (auto& iter : roomMember) { SFProtobufPacket<SevenGamePacket::MyCardInfo> myCardInfo(SevenGame::MyCardInfo); SFPlayer* pPlayer = iter.second; myCardInfo.SetSerial(pPlayer->GetSerial()); SGUser* pSGUser = m_pSevenGameManager->FindUser(pPlayer->GetSerial()); SFASSERT(pSGUser != NULL); int* pArray = pSGUser->GetSpadeArray(); int CardCount = 0; for( int i=1 ; i<= MAX_CARD_NUM ; i++) { if( pArray[i] != -1) { SevenGamePacket::MyCardInfo::PlayerCard* pPlayerCard = myCardInfo.GetData().add_card(); pPlayerCard->set_cardnum(i); pPlayerCard->set_cardtype(TYPE_SPADE); CardCount++; printf("%d %d\n", i, TYPE_SPADE); } } pArray = pSGUser->GetHeartArray(); for( int i=1 ; i<= MAX_CARD_NUM ; i++) { if( pArray[i] != -1) { SevenGamePacket::MyCardInfo::PlayerCard* pPlayerCard = myCardInfo.GetData().add_card(); pPlayerCard->set_cardnum(i); pPlayerCard->set_cardtype(TYPE_HEART); CardCount++; printf("%d %d\n", i, TYPE_HEART); } } pArray = pSGUser->GetDiamondArray(); for( int i=1 ; i<= MAX_CARD_NUM ; i++) { if( pArray[i] != -1) { SevenGamePacket::MyCardInfo::PlayerCard* pPlayerCard = myCardInfo.GetData().add_card(); pPlayerCard->set_cardnum(i); pPlayerCard->set_cardtype(TYPE_DIAMOND); CardCount++; printf("%d %d\n", i, TYPE_DIAMOND); } } pArray = pSGUser->GetCloverArray(); for( int i=1 ; i<= MAX_CARD_NUM ; i++) { if( pArray[i] != -1) { SevenGamePacket::MyCardInfo::PlayerCard* pPlayerCard = myCardInfo.GetData().add_card(); pPlayerCard->set_cardnum(i); pPlayerCard->set_cardtype(TYPE_CLOVER); CardCount++; printf("%d %d\n", i, TYPE_CLOVER); } } SFASSERT(pSGUser->GetRemainCard() == CardCount); SFEngine::GetInstance()->SendRequest(&myCardInfo); } return TRUE; }