Exemple #1
0
BOOL SFFreeForAll::OnSpawnPlayer(SFPlayer* pPlayer, BasePacket* pPacket)
{
	SFRoom* pRoom = GetOwner()->GetOwner();

	SFProtobufPacket<SFPacketStore::MSG_SPAWN_PLAYER>* pSpawnPlayer = (SFProtobufPacket<SFPacketStore::MSG_SPAWN_PLAYER>*)pPacket;

	SpawnPlayerMsg msg;

	SF_GETPACKET_ARG(&msg, pSpawnPlayer->GetData().spawnplayer(), SpawnPlayerMsg);

	_CharacterInfo* pInfo = pPlayer->GetCharacterInfo();
	pInfo->translation = msg.translation;
	pInfo->IsAlive = true;

	SFRoom::RoomMemberMap MemberMap = pRoom->GetRoomMemberMap();
	SFRoom::RoomMemberMap::iterator iter = MemberMap.begin();

	for(; iter != MemberMap.end();iter++)
	{
		SFPlayer* pTarget = iter->second;
		SendSpawnPlayer(pTarget, pPlayer);
	}

	return TRUE;
}
Exemple #2
0
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;
}
Exemple #3
0
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);
}
Exemple #4
0
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;
}
Exemple #5
0
BOOL SFFreeForAll::OnPlayerHealth(SFPlayer* pPlayer, BasePacket* pPacket)
{
	SFRoom* pRoom = GetOwner()->GetOwner();

	SFProtobufPacket<SFPacketStore::MSG_PLAYER_HEALTH>* pHealth = (SFProtobufPacket<SFPacketStore::MSG_PLAYER_HEALTH>*)pPacket;
	
	PlayerHealthMsg msg;

	SF_GETPACKET_ARG(&msg, pHealth->GetData().playerhealth(), PlayerHealthMsg);

	SFPlayer* pHurtPlayer = NULL;
	SFRoom::RoomMemberMap MemberMap = pRoom->GetRoomMemberMap();
	SFRoom::RoomMemberMap::iterator iter = MemberMap.begin();

	for(; iter != MemberMap.end();iter++)
	{
		if(iter->second->GetSerial() == msg.PlayerID)
		{
			pHurtPlayer = iter->second;
			break;
		}
	}

	if(pHurtPlayer == NULL)
		return FALSE;

	_CharacterInfo* pInfo = pHurtPlayer->GetCharacterInfo();
	
	pInfo->health = msg.health;

	if(pInfo->health == 0)
	{
		pInfo->IsAlive = false;
		pInfo->DeathTime = GetTickCount();
	}
	
	iter = MemberMap.begin();

	for(; iter != MemberMap.end();iter++)
	{
		SFPlayer* pTarget = iter->second;
		SendPlayerHealth(pTarget, pHurtPlayer);
	}

	return TRUE;
}
Exemple #6
0
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;
}
Exemple #7
0
BOOL SGBattle::SendInitCardCount()
{
	SFRoom* pRoom = GetOwner()->GetOwner();
	auto& roomMember = pRoom->GetRoomMemberMap();

	SFProtobufPacket<SevenGamePacket::InitCardCount> initCardCount(SevenGame::InitCardCount);

	for (auto& pos : m_pSevenGameManager->m_userlist)
	{
		SGUser* pUser = (SGUser*)(pos);

		SevenGamePacket::InitCardCount::CardCount* pCardCount = initCardCount.GetData().add_info();
			
		pCardCount->set_playerindex(pUser->GetID());
		pCardCount->set_cardcount(pUser->GetRemainCard());

	}

	BroadCast(initCardCount);

	return TRUE;
}
Exemple #8
0
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;
}
Exemple #9
0
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;
}