Beispiel #1
0
	void GameManager::OnBuyPencil()
	{
		if (m_gameStatus == GameStatus::ATTACKER_PLACE_PENCILS)
		{
			if (m_scoreManager.CanBuyPencil(GetPlayerNumber(PlayerType::TYPE_ATTACKER)))
			{
				m_scoreManager.PencilBought(GetPlayerNumber(PlayerType::TYPE_ATTACKER));
			}
		}
	}
Beispiel #2
0
	void GameManager::OnTowerCreate(irr::core::vector2di p_position)
	{
		if (m_gameStatus == GameStatus::DEFENDER_PLACE_TOWERS)
		{
			if (m_scoreManager.CanCreateTower(GetPlayerNumber(PlayerType::TYPE_DEFENDER)) &&
					m_playground->CreateTower(p_position))
			{
				m_scoreManager.TowerCreated(GetPlayerNumber(PlayerType::TYPE_DEFENDER));
			}
		}
	}
Beispiel #3
0
	void GameManager::OnTowerUpgradeDamage(irr::core::vector2di p_position)
	{
		// TODO: not in use
		if (m_gameStatus == GameStatus::DEFENDER_PLACE_TOWERS)
		{
			if (m_scoreManager.CanUpgradeTowerDamage(GetPlayerNumber(PlayerType::TYPE_DEFENDER)) &&
					m_playground->UpgradeTowerDamage(p_position))
			{
				m_scoreManager.TowerIncreasedDamage(GetPlayerNumber(PlayerType::TYPE_DEFENDER));
			}
		}
	}
Beispiel #4
0
RecyclePlayerManager::~RecyclePlayerManager()
{
    __ENTER_FUNCTION

    AssertEx(GetPlayerNumber() == 0,"场景中还有玩家存在,强制回收玩家管理器!");

    __LEAVE_FUNCTION
}
BOOL IncomingPlayerManager::ProcessOutputs( )
{
__ENTER_FUNCTION

	BOOL ret = FALSE ;

	if (m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET) // no player exist
	{ 
		return TRUE ;
	}

	//数据发送
	uint nPlayerCount = GetPlayerNumber() ;
	for( uint i=0; i<nPlayerCount; i++ )
	{
		if( m_pPlayers[i]==INVALID_ID )
			continue ;

		GamePlayer* pPlayer = g_pPlayerPool->GetPlayer(m_pPlayers[i]) ;
		Assert( pPlayer ) ;

		SOCKET s = pPlayer->GetSocket()->getSOCKET() ;
		if( s == m_SocketID )
			continue ;

		if( FD_ISSET( s, &m_WriteFDs[SELECT_USE] ) )
		{
			if( pPlayer->GetSocket()->isSockError() )
			{//连接出现错误
				RemovePlayer( pPlayer ) ;
			}
			else
			{//连接正常
				_MY_TRY
				{
					ret = pPlayer->ProcessOutput( ) ;
					if( !ret )
					{
						RemovePlayer( pPlayer ) ;
					}
				}
				_MY_CATCH
				{
					SaveCodeLog( ) ;
					RemovePlayer( pPlayer ) ;
				}
			}
		}
	}

	return TRUE ;

__LEAVE_FUNCTION

	return FALSE ;
}
Beispiel #6
0
BOOL LoginPlayerManager::ProcessInputs( )
{
    __ENTER_FUNCTION

    BOOL ret = FALSE ;

    if (m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET) // no player exist
    {
        return TRUE ;
    }

    //新连接接入:
    if( FD_ISSET(m_SocketID,&m_ReadFDs[SELECT_USE]) )
    {
        for( INT i=0; i<ACCEPT_ONESTEP; i++ )
        {
            if( !AcceptNewConnection() )
                break;
        }
    }

    //数据读取
    uint nPlayerCount = GetPlayerNumber() ;
    for( uint i=0; i<nPlayerCount; i++ )
    {
        if( m_pPlayers[i]==INVALID_ID )
            continue ;

        LoginPlayer* pPlayer = g_pPlayerPool->GetPlayer(m_pPlayers[i]) ;
        Assert( pPlayer ) ;

        SOCKET s = pPlayer->GetSocket()->getSOCKET() ;
        if( s == m_SocketID )
            continue ;

        if( pPlayer->GetSocket()->isSockError() )
        {   //连接出现错误
            RemovePlayer( pPlayer ) ;
        }
        else if( FD_ISSET( s, &m_ReadFDs[SELECT_USE] ) )
        {   //连接正常
            _MY_TRY
            {
                ret = pPlayer->ProcessInput( ) ;
                if( !ret )
                {
                    RemovePlayer( pPlayer ) ;
                }
            }
            _MY_CATCH
            {
                RemovePlayer( pPlayer ) ;
            }
        }
    }
Beispiel #7
0
bool LoginPlayerManager::ProcessOutputs( )
{
__ENTER_FUNCTION

	bool ret = false ;

	if (m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET) // no player exist
	{ 
		return true ;
	}

	//数据发送
	uint32_t nPlayerCount = GetPlayerNumber() ;
	for( uint32_t i=0; i<nPlayerCount; i++ )
	{
		if( m_pPlayers[i]==INVALID_ID )
			continue ;

		LoginPlayer* pPlayer = g_pPlayerPool->GetPlayer(m_pPlayers[i]) ;
		Assert( pPlayer ) ;

		SOCKET s = pPlayer->GetSocket().getSOCKET() ;
		if( s == m_SocketID )
			continue ;

		if( FD_ISSET( s, &m_WriteFDs[SELECT_USE] ) )
		{
			if( pPlayer->GetSocket().isSockError() )
			{//连接出现错误
				RemovePlayer( pPlayer ) ;
			}
			else
			{//连接正常
				_MY_TRY
				{
					ret = pPlayer->ProcessOutput( ) ;
					if( !ret )
					{
						RemovePlayer( pPlayer ) ;
					}
				}
				_MY_CATCH
				{
					RemovePlayer( pPlayer ) ;
				}
			}
		}
	}

	return true ;

__LEAVE_FUNCTION

	return false ;
}