Exemple #1
0
BOOL SFRoomLoading::OnEnter()
{
	SFRoom* pRoom = GetOwner();
	pRoom->ChangePlayerFSM(PLAYER_STATE_LOADING);

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

	switch(pPacket->GetPacketID())
	{
	case FPS::MSG_PLAYER_SCORE:
	case FPS::MSG_PLAYER_WEAPON_CHANGE:
	case FPS::MSG_PLAYER_WEAPON_CHANGING:
		{
			pRoom->BroadCast(pPacket);

		}
		break;
	case FPS::MSG_SPAWN_PLAYER:
		{
			OnSpawnPlayer(pPlayer, pPacket);
		}
		break;
	case FPS::MSG_PLAYER_HEALTH:
		{
			OnPlayerHealth(pPlayer, pPacket);
		}
	}

	return TRUE;
}
Exemple #6
0
BOOL SFRoomManager::Update()
{
	for (auto& iter : m_ActiveRoomMap)
	{
		SFRoom* pRoom = iter.second;
		pRoom->Update(0);
		//if (thread.joinable())
			//thread.join();
	}

	return TRUE;
}
Exemple #7
0
BOOL SFRoomLoading::OnLoadingComplete( SFPlayer* pPlayer, BasePacket* pPacket)
{
	SFRoom* pRoom = GetOwner();

	pRoom->GetP2PSys()->AddPeer(pPlayer->GetSerial(), pPlayer->GetIPInfo());

	if(TRUE != pRoom->CheckLoadingComplete())
		return FALSE;

	pRoom->ChangeState(ROOM_STATE_PLAYREADY);
	pRoom->ChangeState(ROOM_STATE_PLAY);

	return TRUE;
}
Exemple #8
0
SFRoom* SFRoomManager::GetEmptyRoom()
{
	EmptyRoomMap::iterator iter = m_EmptyRoomMap.begin();

	if(iter == m_EmptyRoomMap.end())
		return NULL;

	SFRoom* pRoom = iter->second;

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

	m_EmptyRoomMap.erase(iter);

	return pRoom;
}
Exemple #9
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 #10
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 #11
0
SFRoom* SFRoomManager::GetRoom( int RoomIndex )
{
	if(RoomIndex < 0 || RoomIndex >= MAX_ROOM_COUNT)
	{
		SFASSERT(0);
		return NULL;
	}

	SFRoom* pRoom = m_RoomArray[RoomIndex];

	if(pRoom->GetRoomState() == ROOM_STATE_NONE)
	{
		return NULL;
	}

	return pRoom;
}
Exemple #12
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 #13
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 #14
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;
}
Exemple #15
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;
}
Exemple #16
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 #17
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;
}