Esempio n. 1
0
void Network::BoostClient::OnBulletHit( unsigned long ip, const PACKAGE& p )
{
	std::cout << "OnBulletHit\n";
	// 获取炮弹类型
	BulletHittedBag* bag = (BulletHittedBag*)p.GetData();

	if ( bag->target_index == m_index )
	{
		auto pEngine = MyIrrlichtEngine::GetEngine();
		if ( pEngine->GetCurrentPlayer()->GetShip()->GetShield() <= 0
			&& pEngine->GetCurrentPlayer()->GetShip()->GetArmor() <= 0 )
		{
			// 自己挂了
			pEngine->GetCurrentPlayer()->SetState( IPlayer::PS_Dead );

			// 通知别人自己挂了
			ScoreArrivalBag score;
			score.ip = 0;
			score.KillCount = pEngine->GetCurrentPlayer()->GetKill();
			score.DeathCount = pEngine->GetCurrentPlayer()->GetDeath();

			PACKAGE pack;
			pack.SetCMD( SCORE_ARRIVAL );			
			pack.SetData( (char*)&score, sizeof( BulletCreateBag ) );			

			TcpSendTo( m_server_IP, m_target_port, pack );
			//m_network->SendTo( m_server_IP, pack );
		}
	}

	// 判断击中目标是否有效
	if ( 0 <= bag->target_index && bag->target_index < 100 )
	{
		ISceneManager* smgr = MyIrrlichtEngine::GetEngine()->GetSceneManager();

		smgr->getSceneNodeFromId( bag->owner_index );

		// 获取命中的节点
		ISceneNode* target_node = smgr->getSceneNodeFromId( bag->target_index );

		IShip* ship = dynamic_cast<IShip*>( target_node );
		if ( ship )
		{
			ship->SetArmor( (f32)bag->armor );
			ship->SetShield( (f32)bag->shield );
		}
		//int damage;
		//// 炮弹
		//if ( bag->bullet_type == 0 )
		//{
		//	damage = 10;
		//}
		//// 导弹
		//else if ( bag->bullet_type == 1 )
		//{
		//	damage = 100;
		//}

	}
}
Esempio n. 2
0
void Network::BoostClient::OnScoreArrival( unsigned long ip, const PACKAGE& p )
{
	ScoreArrivalBag bag = *(ScoreArrivalBag*)p.GetData();

	ScoreNode score;
	score.ip = ip;
	score.KillCount = bag.KillCount;
	score.DeathCount = bag.DeathCount;
	m_PlayerHelper->SetPlayerScore( ip, score );
}
Esempio n. 3
0
void Network::BoostClient::OnPlayerLock( unsigned long ip, const PACKAGE& p )
{
	PlayerLockBag lockBag;
	lockBag = *(PlayerLockBag*)p.GetData();
	if ( lockBag.target_index == m_index )
	{
		//m_PlayerHelper->AddInfoMsg( InfoAndWarn::PIW_PlayerLock );

		MyIrrlichtEngine::GetEngine()->AddToCloneQueue( p );
	}
}
Esempio n. 4
0
void Network::BoostClient::OnBulletCreate( unsigned long ip, const PACKAGE& p )
{
	BulletCreateBag* bag;
	bag = (BulletCreateBag*)p.GetData();

	// 自己的包或者当自己是服务器是忽略机器人的包
	if ( bag->owner_index == m_index || m_IsServer && bag->owner_index > 70 )	return;

	MyIrrlichtEngine::GetEngine()->AddToCloneQueue( p );

}
Esempio n. 5
0
void Network::BoostClient::OnAllowJoinRoom( unsigned long ip, const PACKAGE& p )
{
	std::cout << boost::asio::ip::address_v4( ip ).to_string() << " ==>BoostClient receives ALLOW_JOIN_ROOM\n";

	m_server_IP = ip;

	AllowJoinRoomBag allowBag( 0, 0, 0, 0 );
	allowBag = *(AllowJoinRoomBag*)p.GetData();

	m_index = allowBag.index;
}
Esempio n. 6
0
void Network::BoostClient::OnHeroRotate( unsigned long ip, const PACKAGE& p )
{
	HeroRotate rot;
	rot = *(HeroRotate*)p.GetData();
	if ( rot.index != m_index )
	{
		auto iter = m_players.find( rot.index );
		if ( iter != m_players.end() )
		{
			//std::cout << "=> HERO_MOVE " << move.index << ' ' << move.x << ' ' << move.y << ' ' << move.z << std::endl;
			iter->second->setRotation( irr::core::vector3df( rot.x, rot.y, rot.z ) );
		}
	}
}
Esempio n. 7
0
void Network::BoostClient::OnBroadcastRoom( unsigned long ip, const PACKAGE& p )
{
	BroadcastRoomBag bag = *(BroadcastRoomBag*)p.GetData();
	m_roomMap[ boost::asio::ip::address_v4( ip ).to_string() ] = bag;

	//std::cout << "Server broadcast room: ip= " 
	//	<< boost::asio::ip::address_v4( ip ).to_string() 
	//	<< " room name= ";
	//std::wcout << ((BroadcastRoomBag*)p.GetData())->room_name
	//	<< std::endl;

	//std::cout << "<current rooms>\n";
	//for ( auto iter = m_roomMap.begin(); iter != m_roomMap.end(); ++iter )
	//{
	//	std::cout << "ip " << iter->first << std::endl;
	//}
	//std::cout << "</current rooms>\n";
}
Esempio n. 8
0
void Network::BoostClient::OnNewPlayerJoin( unsigned long ip, const PACKAGE& p )
{
	OnePlayerInfoBag oneplayer;
	oneplayer = *(OnePlayerInfoBag*)p.GetData();

	if ( oneplayer.player_index != m_index )
	{
		MyIrrlichtEngine::GetEngine()->AddToCloneQueue( p );
//		auto smgr = MyIrrlichtEngine::GetEngine()->GetSceneManager();
//
//		// 加载飞船,需要根据玩家飞船信息组装飞船
//		//auto ship = new CFrigate( smgr->getMesh("../model/ship/cf1.obj"), 0, smgr, -1 );
//		auto ship = MyIrrlichtEngine::GetEngine()->GetMySceneManager()->addFrigateSceneNode( L"../model/ship/cf1.obj" );
//		//GeneralCallBack* cb = new GeneralCallBack( ship );
//		//SceneNodeShader shader;
//		//shader.ApplyShaderToSceneNode( ship, cb, "Shader/cf_1V.vert", "Shader/cf_1F.frag" );
//		//cb->drop();
//		//ship->setMaterialFlag( EMF_BACK_FACE_CULLING, false );
//
//		// 设置船的id
//		ship->setID( oneplayer.player_index );
//		// 保存玩家信息
//		m_players[ oneplayer.player_index ] = ship;
//		ship->grab();	///!!!!!!!!!!一定要去drop,还没
//
//		ship->setPosition( core::vector3df( 123141, 12312, 1000000 ) );
//
////		m_playerManager->AddPlayer( ship->getID(), ship );
//		boost::shared_ptr<HumanPlayer> player = boost::shared_ptr<HumanPlayer>( new HumanPlayer( ship ) );
//		player->SetID( oneplayer.player_index );
//		player->SetName( oneplayer.player_name );
//		dynamic_cast<MultiplayerScene*>(
//			MyIrrlichtEngine::GetEngine()->GetGameSceneManager()->GetCurrentGameScene()
//			)->m_playerManager->AddPlayer( player );
//
//		std::cout << "NEW_PLAYER_JOIN " << oneplayer.player_index << std::endl;
	}
	else
	{
		// 设置自己的id		
		//	m_playerManager->m_playerHelper.PlayerShip->setID( m_index );
	}
}
Esempio n. 9
0
void Network::BoostClient::OnMessage( unsigned long ip, const PACKAGE& p )
{
	BroadcastMessageBag* bag;
	bag = (BroadcastMessageBag*)p.GetData();

	//bag->GetMsg();
	//bag->index;

	if ( box == 0 )
	{
		box = MyIrrlichtEngine::GetEngine()->GetDevice()->getGUIEnvironment()->addEditBox( _T(""), core::recti( 0, 100, 100, 130 ) );
	}
	box->setVisible( true );
	box->setText( bag->GetMsg() );

	// 两秒后隐藏
	boost::thread t( []()
	{
		boost::thread::sleep( boost::get_system_time() + boost::posix_time::seconds( 2 ) );
		box->setVisible( false );
	} );
}