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; //} } }
void Network::BoostClient::EnterRoom( const std::string& ip ) { PACKAGE pack; pack.SetCMD( REQUEST_ENTER_ROOM ); RequestEnterRoomBag bag; wcscpy( bag.shipname, MyIrrlichtEngine::GetEngine()->GetCurrentPlayer()->GetShipName().c_str() ); pack.SetData( (char*)&bag, sizeof( RequestEnterRoomBag ) ); //m_network->SendTo( ip, pack ); TcpSendTo( boost::asio::ip::address().from_string( ip ).to_v4().to_ulong(), m_target_port, pack ); }
void Network::BoostClient::SendLock( int index, int target_index ) { PACKAGE p; p.SetCMD( PLAYER_LOCK ); PlayerLockBag bag; bag.owner_index = index; bag.target_index = target_index; p.SetData( (char*)&bag, sizeof(PlayerLockBag) ); TcpSendTo( m_server_IP, m_target_port, p ); }
void Network::BoostClient::SendHeroRot( int index, float x, float y, float z ) { PACKAGE pack; pack.SetCMD( HERO_ROTATE ); HeroRotate rot( index, x, y, z ); pack.SetData( (char*)&rot, sizeof( HeroRotate ) ); m_network->SendTo( m_server_IP, pack ); }
void Network::BoostClient::SendHeroMove( int index, float x, float y, float z ) { PACKAGE pack; pack.SetCMD( HERO_MOVE ); HeroMove move( index, x, y, z ); pack.SetData( (char*)&move, sizeof( HeroMove ) ); m_network->SendTo( m_server_IP, pack ); }
void IAgentPlayer::SendRotate( const core::vector3df& rot ) { //RobotShip_->setRotation( getRotation() ); PACKAGE pack; pack.SetCMD( HERO_ROTATE ); HeroRotate rotate( GetID(), rot.X, rot.Y, rot.Z ); pack.SetData( (char*)&rotate, sizeof( HeroRotate ) ); dynamic_pointer_cast<Network::BoostServer >( Server )->AddPacketToBuffer( pack ); }
void Network::BoostClient::BroadcastMessage( int index, const wchar_t* msg ) { BroadcastMessageBag bag; bag.index = index; bag.target_index = -1; bag.SetMsg( msg ); PACKAGE p; p.SetCMD( MESSAGE_TO ); p.SetData( (char*)&bag, bag.GetLength() ); TcpSendTo( m_server_IP, m_target_port, p ); }
void IAgentPlayer::SendMove( const vector3df& pos ) { //RobotShip_->setPosition( getPosition() ); PACKAGE pack; pack.SetCMD( HERO_MOVE ); HeroMove move( GetID(), pos.X, pos.Y, pos.Z ); pack.SetData( (char*)&move, sizeof( HeroMove ) ); dynamic_pointer_cast<Network::BoostServer >( Server )->AddPacketToBuffer( pack ); //Server->OnReceive( 0, pack ); }
void Network::BoostClient::SendBulletHit( int owner_index, int target_index, int bullet_type, IShip* ship ) { BulletHittedBag bag; bag.owner_index = owner_index; bag.target_index = target_index; bag.bullet_type = bullet_type; bag.armor = (int)ship->GetArmor(); bag.shield = (int)ship->GetShield(); PACKAGE p; p.SetCMD( BULLET_HIT ); p.SetData( (char*)&bag, sizeof( BulletHittedBag ) ); TcpSendTo( m_server_IP, m_target_port, p ); }
void Network::BoostClient::SendBullet( int index, int bullet_type, const irr::core::vector3df& start, const irr::core::vector3df& end, u32 life ) { BulletCreateBag bullet; bullet.owner_index = index; bullet.start_point = start; bullet.end_point = end; bullet.life = life; bullet.type = bullet_type; PACKAGE pack; pack.SetCMD( BULLET_CREATE ); pack.SetData( (char*)&bullet, sizeof( BulletCreateBag ) ); m_network->SendTo( m_server_IP, pack ); }