void NotifyParentOnDeathSystem::Update( double DeltaTime ) { for ( auto actor : mScene.GetActorsFromMap( GetType_static() ) ) { Opt<INotifyParentOnDeathComponent> notifyParentOnDeathC = actor->Get<INotifyParentOnDeathComponent>(); if ( !notifyParentOnDeathC.IsValid() ) { continue; } Opt<Actor> parent( mScene.GetActor( notifyParentOnDeathC->GetParentGUID() ) ); Opt<Actor> killer( mScene.GetActor( notifyParentOnDeathC->GetKillerGUID() ) ); if( !parent.IsValid() ) { continue; } Opt<IHealthComponent> healthC = actor->Get<IHealthComponent>(); if( !healthC.IsValid() || healthC->IsAlive() ) { continue; } if( !killer.IsValid() ) { continue; } Opt<IListenChildDeathComponent> listenChildDeathC = parent->Get<IListenChildDeathComponent>(); if ( !listenChildDeathC.IsValid() ) { continue; } listenChildDeathC->SetKillerOfChildGUID( killer->GetGUID() ); } }
void RemoveComponentsOnDeathSystem::Update( double DeltaTime ) { for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it ) { Actor& actor = **it; Opt<IRemoveComponentsOnDeathComponent> removeComponentsOnDeathC = actor.Get<IRemoveComponentsOnDeathComponent>(); if ( !removeComponentsOnDeathC.IsValid() ) { continue; } Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>(); if( !healthC.IsValid() ) { continue; } if( healthC->IsAlive() ) { continue; } // create copy, component might drop itself std::vector<int32_t> const comps = removeComponentsOnDeathC->GetComponents(); std::for_each( std::begin( comps ), std::end( comps ), [&]( int32_t id ) { actor.DropComponent( id ); } ); } }
void StopOnDeathSystem::Update( double DeltaTime ) { for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it ) { Actor& actor = **it; Opt<IStopOnDeathComponent> stopOnDeathC = actor.Get<IStopOnDeathComponent>(); if ( !stopOnDeathC.IsValid() || stopOnDeathC->IsStopped() ) { continue; } Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>(); if ( !healthC.IsValid() ) { continue; } if ( healthC->IsAlive() ) { continue; } stopOnDeathC->SetStopped( true ); Opt<IMoveComponent> moveC = actor.Get<IMoveComponent>(); if( moveC.IsValid() ) { moveC->SetMoving( false ); moveC->SetHeadingModifier( 0 ); } } }
std::auto_ptr<Actor> SoldierSpawnSystem::Spawn( core::ClientData& clientData, map::SpawnPoint spawnPoint, std::auto_ptr<Actor> player ) { Opt<Actor> clientActor( mScene.GetActor( clientData.mClientActorGUID ) ); if( clientActor.IsValid() ) { Opt<IHealthComponent> healthC = clientActor->Get<IHealthComponent>(); if ( healthC.IsValid() && healthC->IsAlive() ) { L1( "Cannot spawn soldier for clientData (%s) current soldier still alive!\n", clientData.mClientName.c_str() ); return std::auto_ptr<Actor>(); } } else { L2( "No actor for clientData(%s). (it might be an error on revive)\n", clientData.mClientName.c_str() ); } L2( "player is valid %d", player.get() ); Opt<IPositionComponent> positionC = player->Get<IPositionComponent>(); L2( "positionC is valid %d", positionC.IsValid() ); positionC->SetX( spawnPoint.mX ); positionC->SetY( spawnPoint.mY ); //TODO: temporary till normal inventory sync // Opt<IInventoryComponent> inventoryC = player->Get<IInventoryComponent>(); // if ( inventoryC.IsValid() ) // { // inventoryC->SetSelectedWeapon( AutoId( "pistol" ) ); // } Opt<PlayerControllerComponent> playerControllerC( player->Get<IControllerComponent>() ); if ( playerControllerC.IsValid() ) { playerControllerC->mControllerId = clientData.mClientId; if ( mProgramState.mControlledActorGUID == clientData.mClientActorGUID && mProgramState.mMode != core::ProgramState::Server ) { playerControllerC->SetEnabled( true ); playerControllerC->mActive = true; mProgramState.mControlledActorGUID = player->GetGUID(); } } clientData.mClientActorGUID = player->GetGUID(); //TODO: might seek for a better place L2( "player created clientId:%d clientName:%s actorId:%d\n", clientData.mClientId, clientData.mClientName.c_str(), clientData.mClientActorGUID ); if ( mProgramState.mMode != core::ProgramState::Server && mProgramState.mClientDatas.begin()->mClientActorGUID == player->GetGUID() ) { Scene::Get().SetPlayerModels( Opt<Actor>( player.get() ) ); } EventServer<SoldierCreatedEvent>::Get().SendEvent( SoldierCreatedEvent( clientData, Opt<Actor>( player.get() ) ) ); return player; }
bool HatRecognizer::Recognize( Actor const& actor ) const { Opt<PlayerControllerComponent> playerCC = actor.Get<PlayerControllerComponent>(); if ( !playerCC.IsValid() ) { return false; } Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>(); if ( !healthC.IsValid() || !healthC->IsAlive() ) { return false; } return true; }
void GuardControllerSubSystem::UpdateTarget( Actor& actor, Opt<ITargetHolderComponent> targetHolderC ) { Opt<Actor> currentTarget( mScene.GetActor( targetHolderC->GetTargetGUID() ) ); Opt<GuardControllerComponent> guardCC = actor.Get<IControllerComponent>(); auto positionC( actor.Get<IPositionComponent>() ); if (currentTarget.IsValid()) { auto targetPositionC( currentTarget->Get<IPositionComponent>() ); int32_t const disaggroDistSqr = guardCC->GetPeaceDist()*guardCC->GetPeaceDist(); if (GetDistanceSqr( positionC, targetPositionC) > disaggroDistSqr ) { targetHolderC->SetTargetGUID( -1 ); currentTarget.Reset(); } } if (!currentTarget.IsValid()) { if (!positionC.IsValid()) { return; } for (auto player : ActorListFilter<Scene::CollisionClassActors>( mScene.GetActors(), CollisionClass::Player )) { auto targetPositionC( player->Get<IPositionComponent>() ); if (!targetPositionC.IsValid()) { return; } int32_t const aggroDistSqr = guardCC->GetAggroDist() * guardCC->GetAggroDist(); if (GetDistanceSqr( positionC, targetPositionC ) < aggroDistSqr ) { targetHolderC->SetTargetGUID( player->GetGUID() ); currentTarget = mScene.GetActor( targetHolderC->GetTargetGUID() ); break; } } } if (currentTarget.IsValid()) { Opt<IHealthComponent> healthC = currentTarget->Get<IHealthComponent>(); if (!healthC.IsValid() || !healthC->IsAlive()) { targetHolderC->SetTargetGUID( -1 ); currentTarget.Reset(); } } }
void RemoveOnDeathSystem::Update( double DeltaTime ) { for( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(), n; ( n = it, it != e ? ( ++n, true ) : false ); it = n ) { Actor& actor = **it; Opt<IRemoveOnDeathComponent> removeOnDeathC = actor.Get<IRemoveOnDeathComponent>(); if ( !removeOnDeathC.IsValid() ) { continue; } Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>(); if( !healthC.IsValid() || healthC->IsAlive() ) { continue; } double RemainingTime = removeOnDeathC->GetRemainingTime() - DeltaTime; removeOnDeathC->SetRemainingTime( RemainingTime ); if( RemainingTime <= 0 ) { mScene.RemoveActor( it ); } } }
void RemoveComponentsOnDeathSystem::Update( double DeltaTime ) { for (auto actor : mScene.GetActorsFromMap( GetType_static() )) { Opt<IRemoveComponentsOnDeathComponent> removeComponentsOnDeathC = actor->Get<IRemoveComponentsOnDeathComponent>(); if ( !removeComponentsOnDeathC.IsValid() ) { continue; } Opt<IHealthComponent> healthC = actor->Get<IHealthComponent>(); if( !healthC.IsValid() ) { continue; } if( healthC->IsAlive() ) { continue; } // create copy, component might drop itself std::vector<int32_t> const comps = removeComponentsOnDeathC->GetComponents(); std::for_each( std::begin( comps ), std::end( comps ), [&]( int32_t id ) { actor->DropComponent( id ); } ); } }