本文整理汇总了C++中Opt::SetBullets方法的典型用法代码示例。如果您正苦于以下问题:C++ Opt::SetBullets方法的具体用法?C++ Opt::SetBullets怎么用?C++ Opt::SetBullets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Opt
的用法示例。
在下文中一共展示了Opt::SetBullets方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnShot
void WeaponItemSubSystem::OnShot( core::ShotEvent const& Evt )
{
Opt<Actor> actor( mScene.GetActor( Evt.mActorGUID ) );
if ( !actor.IsValid() )
{
return;
}
Opt<IInventoryComponent> inventoryC = actor->Get<IInventoryComponent>();
if ( !inventoryC.IsValid() )
{
return;
}
Opt<Weapon> weapon = inventoryC->GetSelectedWeapon();
if ( !weapon.IsValid() )
{
return;
}
weapon->GetScatter().Shot( Evt.mIsAlt );
if ( Evt.mIsAlt )
{
weapon->SetCooldown( weapon->GetShootAltCooldown() );
weapon->SetBullets( weapon->GetBullets() - weapon->GetShotCostAlt() );
}
else
{
weapon->SetCooldown( weapon->GetShootCooldown() );
weapon->SetBullets( weapon->GetBullets() - weapon->GetShotCost() );
}
}
示例2: Update
void WeaponItemSubSystem::Update( Actor& actor, double DeltaTime )
{
Opt<IInventoryComponent> inventoryC = actor.Get<IInventoryComponent>();
Opt<Weapon> weapon = inventoryC->GetSelectedWeapon();
if ( !weapon.IsValid() )
{
return;
}
double cd = weapon->GetCooldown();
cd -= DeltaTime;
if( cd < 0 )
{
cd = 0;
}
weapon->SetCooldown( cd );
//scatter updated on client
Opt<IAccuracyComponent> accuracyC = actor.Get<IAccuracyComponent>();
weapon->GetScatter().Update( DeltaTime, accuracyC.IsValid() ? accuracyC->GetAccuracy().Get() : 0 );
if ( weapon->CanReload()
//Not enough bullet for current shot Need to see if the player wants to shoot alt:
&& ( weapon->GetShoot() && weapon->GetBullets() < weapon->GetShotCost()
&& weapon->GetCooldown() <= 0
//Not enough bullet for current alt shot. Need to see if the player wants to shoot normal:
|| weapon->GetShootAlt() && weapon->GetBullets() < weapon->GetShotCostAlt()
&& weapon->GetCooldown() <= 0
//Not enough bullet at all. This time the reload is a sure thing:
|| weapon->GetBullets() < weapon->GetShotCost()
&& weapon->GetBullets() < weapon->GetShotCostAlt() ) )
{
weapon->SetBullets( 0.0 );
weapon->SetReloadTime( weapon->GetReloadTimeMax() );
EventServer<ItemPropertiesChangedEvent>::Get().SendEvent( ItemPropertiesChangedEvent( *weapon ) );
}
weapon->SetReloadTime( weapon->GetReloadTime() - DeltaTime );
if ( weapon->GetBullets() <= 0.0 )
{
if ( weapon->GetReloadTime() <= 0 && weapon->GetStaticReload() == 0.0 )
{
//todo: need to sync reloading with the server (-1 could occur, if a shot comes too fast, then it is reset by the end of the reload missing one bullet)
weapon->SetBullets( weapon->GetBullets() + weapon->GetBulletsMax() );
weapon->SetReloadTime( 0.0 );
}
}
if ( weapon->GetReloadTime() <= 0 && weapon->GetStaticReload() > 0.0 )
{
weapon->SetBullets( std::min(
( weapon->GetBullets() + weapon->GetStaticReload()/**DeltaTime*/ )
, weapon->GetBulletsMax() ) );
weapon->SetReloadTime( weapon->GetReloadTimeMax() );
}
BindIds_t::iterator itemssIt = mSubSystems.get<SubSystemHolder::AllByBindId>().find( weapon->GetId() );
if ( itemssIt != mSubSystems.get<SubSystemHolder::AllByBindId>().end() )
{
itemssIt->mSystem->Update( actor, DeltaTime );
}
if (mProgramState.mMode != core::ProgramState::Client)
{
if (weapon->GetCooldown() <= 0.0) //not synced to client
{
Opt<IPositionComponent> actorPositionC = actor.Get<IPositionComponent>();
if (actorPositionC.IsValid())
{
if (weapon->IsShooting() && weapon->GetBullets() >= weapon->GetShotCost())
{
if (weapon->GetMuzzleId() != -1)
{
std::auto_ptr<Actor> muzzle(mActorFactory(weapon->GetMuzzleId()));
SetProjectilePosition(*muzzle, actor);
BOOST_ASSERT(muzzle->Get<IPositionComponent>().IsValid());
muzzle->Get<IPositionComponent>()->SetOrientation(actorPositionC->GetOrientation());
mScene.AddActor(muzzle.release());
}
EventServer<core::ShotEvent>::Get().SendEvent(core::ShotEvent(actor.GetGUID(), glm::vec2(actorPositionC->GetX(), actorPositionC->GetY()), false));
}
else if (weapon->IsShootingAlt() && weapon->GetBullets() >= weapon->GetShotCostAlt())
{
if (weapon->GetMuzzleAltId() != -1)
{
std::auto_ptr<Actor> muzzle(mActorFactory(weapon->GetMuzzleAltId()));
SetProjectilePosition(*muzzle, actor);
BOOST_ASSERT(muzzle->Get<IPositionComponent>().IsValid());
muzzle->Get<IPositionComponent>()->SetOrientation(actorPositionC->GetOrientation());
mScene.AddActor(muzzle.release());
}
EventServer<core::ShotEvent>::Get().SendEvent(core::ShotEvent(actor.GetGUID(), glm::vec2(actorPositionC->GetX(), actorPositionC->GetY()), true));
}
}
}
}
}