Ejemplo n.º 1
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;
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
0
BOOL SFLogicEntry::OnDBResult(SFMessage* pMessage)
{
	PlayerMap::iterator iter = m_PlayerMap.find(pMessage->GetSerial());

	if(iter == m_PlayerMap.end())
	{
		SFASSERT(0);
		return FALSE;
	}

	SFPlayer* pPlayer = iter->second;

	return pPlayer->ProcessDBResult(pMessage);
}
Ejemplo n.º 4
0
BOOL SFLogicEntry::OnPlayerData( BasePacket* pPacket )
{
	PlayerMap::iterator iter = m_PlayerMap.find(pPacket->GetSerial());

	if(iter == m_PlayerMap.end())
	{
		SFASSERT(0);
		return FALSE;
	}

	SFPlayer* pPlayer = iter->second;

	return pPlayer->ProcessPacket(pPacket);
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
BOOL SFLogicEntry::OnConnectPlayer(int serial)
{
	SFPlayer* pPlayer = m_pPlayerPool->Alloc();

	if(pPlayer == NULL)
		return FALSE;

	pPlayer->Reset();
	pPlayer->SetSerial(serial);

	pPlayer->ChangeState(PLAYER_STATE_INIT);

	m_PlayerMap.insert(PlayerMap::value_type(serial, pPlayer));

	SendAuthPacket(serial);

	return TRUE;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
BOOL SFRoomManager::OnCreateRoom( SFPlayerLobby* pLobbyState, int GameMode )
{
	SFRoom* pRoom = GetEmptyRoom();
	SFPlayer* pPlayer = pLobbyState->GetOwner();

	if(NULL == pRoom)
		return FALSE;

	SFASSERT(pRoom->GetRoomState() == ROOM_STATE_NONE);

	pRoom->Open(pPlayer);
	pRoom->ChangeState(ROOM_STATE_WAIT);
	pPlayer->SetRoomIndex(pRoom->GetRoomIndex());

	_GameModeInfo* pInfo = pRoom->GetGameModeInfo();
	pInfo->SetGameMode(GameMode);

	m_ActiveRoomMap.insert(std::make_pair(pRoom->GetRoomIndex(), pRoom));

	return TRUE;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
0
BOOL SFLogicEntry::OnDisconnectPlayer(int serial)
{
	PlayerMap::iterator iter = m_PlayerMap.find(serial);
	
	if(iter == m_PlayerMap.end())
	{
		SFASSERT(0);
		return FALSE;
	}

	SFPlayer* pPlayer = iter->second;

	m_pPlayerManager->DelPlayer(pPlayer);

///////////////////////////////////////////////////////////
//20120619 이런식으로 짜면 실수할 여지가 크다.... 나중에 수정할 수 있도록 한다.
///////////////////////////////////////////////////////////
	if (pPlayer->GetPlayerState() == PLAYER_STATE_LOADING ||
		pPlayer->GetPlayerState() == PLAYER_STATE_ROOM ||
		pPlayer->GetPlayerState() == PLAYER_STATE_PLAY ||
		pPlayer->GetPlayerState() == PLAYER_STATE_PLAYEND ||
		pPlayer->GetPlayerState() == PLAYER_STATE_PLAYREADY)
	{
		SFRoomManager* pManager = GetRoomManager();
		SFRoom* pRoom = pManager->GetRoom(pPlayer->GetRoomIndex());
		pRoom->GetRoomFSM()->OnLeaveRoom(pPlayer);
	}

	pPlayer->ChangeState(PLAYER_STATE_NONE);

	m_pPlayerPool->Release(pPlayer);

	m_PlayerMap.erase(iter);

	return TRUE;
}
Ejemplo n.º 12
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;
}