std::auto_ptr<HealthMessage> HealthMessageSenderSystem::GenerateHealthMessage( Actor& actor ) { Opt<IHealthComponent> healthC = actor.Get<IHealthComponent>(); if ( !healthC.IsValid() ) { return std::auto_ptr<HealthMessage>(); } std::auto_ptr<HealthMessage> healthMsg( new HealthMessage ); healthMsg->mActorGUID = actor.GetGUID(); healthMsg->mHP = healthC->GetHP(); healthMsg->mMaxHP = healthC->GetMaxHP().mBase.Get(); healthMsg->mMaxHPPercent = std::floor( healthC->GetMaxHP().mPercent.Get() * PRECISION ); healthMsg->mMaxHPFlat = healthC->GetMaxHP().mFlat.Get(); return healthMsg; }
bool HealthMessageHandlerSubSystem::ProcessPending( Message const& message ) { HealthMessage msg = static_cast<HealthMessage const&>( message ); Opt<Actor> actor = mScene.GetActor( msg.mActorGUID ); Opt<IHealthComponent> healthC = actor->Get<IHealthComponent>(); if ( !healthC.IsValid() ) { L1( "no health_component found guid:%s\n", msg.mActorGUID ); return true; } L1( "executing %s: actorGUID %d \n", __FUNCTION__, msg.mActorGUID ); healthC->SetHP( msg.mHP ); healthC->GetMaxHP().mBase.Set( msg.mMaxHP ); healthC->GetMaxHP().mPercent.Set( msg.mMaxHPPercent / PRECISION ); healthC->GetMaxHP().mFlat.Set( msg.mMaxHPFlat ); return true; }