當前位置: 首頁>>代碼示例>>C++>>正文


C++ CanAttack函數代碼示例

本文整理匯總了C++中CanAttack函數的典型用法代碼示例。如果您正苦於以下問題:C++ CanAttack函數的具體用法?C++ CanAttack怎麽用?C++ CanAttack使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了CanAttack函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: AttackStart

void PetAI::AttackStart(Unit* target)
{
    // Overrides Unit::AttackStart to correctly evaluate Pet states

    // Check all pet states to decide if we can attack this target
    if (!CanAttack(target))
        return;

    // Only chase if not commanded to stay or if stay but commanded to attack
    DoAttack(target, (!m_creature->GetCharmInfo()->HasCommandState(COMMAND_STAY) || m_creature->GetCharmInfo()->IsCommandAttack()));
}
開發者ID:Maduse,項目名稱:server,代碼行數:11,代碼來源:PetAI.cpp

示例2: TryRangedAttack

bool RPG_AiControllerComponent::TryRangedAttack()
{
  if(CanAttack())
  {
    m_lastAttackTime = Vision::GetTimer()->GetTime();
    SetState(RPG_ControllerStateId::kRangedAttacking);
    return true;
  }

  return false;
}
開發者ID:RexBaribal,項目名稱:projectanarchy,代碼行數:11,代碼來源:AiControllerComponent.cpp

示例3: AttackStart

void PetAI::AttackStart(Unit* target)
{
    // Overrides Unit::AttackStart to correctly evaluate Pet states

    // Check all pet states to decide if we can attack this target
    if (!CanAttack(target))
        return;

    if (Unit* owner = me->GetOwner())
        owner->SetInCombatWith(target);

    DoAttack(target, true);
}
開發者ID:AlmasServer,項目名稱:TrinityCore,代碼行數:13,代碼來源:PetAI.cpp

示例4: ToTFPlayer

//-----------------------------------------------------------------------------
// Purpose: Attempt to heal any player within range of the medikit
//-----------------------------------------------------------------------------
void CWeaponMedigun::PrimaryAttack( void )
{
	CTFPlayer *pOwner = ToTFPlayer( GetOwnerEntity() );
	if ( !pOwner )
		return;


	if ( !CanAttack() )
		return;

#ifdef GAME_DLL
	/*
	// Start boosting ourself if we're not
	if ( m_bChargeRelease && !m_bHealingSelf )
	{
		pOwner->m_Shared.Heal( pOwner, GetHealRate() * 2 );
		m_bHealingSelf = true;
	}
	*/
#endif

#if !defined (CLIENT_DLL)
	if ( tf_medigun_lagcomp.GetBool() )
		lagcompensation->StartLagCompensation( pOwner, pOwner->GetCurrentCommand() );
#endif

	if ( FindAndHealTargets() )
	{
		// Start the animation
		if ( !m_bHealing )
		{
#ifdef GAME_DLL
			pOwner->SpeakWeaponFire();
#endif

			SendWeaponAnim( ACT_MP_ATTACK_STAND_PREFIRE );
			pOwner->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRE );
		}

		m_bHealing = true;
	}
	else
	{
		RemoveHealingTarget();
	}
	
#if !defined (CLIENT_DLL)
	if ( tf_medigun_lagcomp.GetBool() )
		lagcompensation->FinishLagCompensation( pOwner );
#endif
}
開發者ID:Navton,項目名稱:TF2Classic,代碼行數:54,代碼來源:tf_weapon_medigun.cpp

示例5: CanAttack

bool cCombatManager::ValidateEnemy(const int& unitID, UnitInfo* U, bool IdleIfInvalid)
{
	if( U->enemyID == -1 || G->Enemies.find(U->enemyID) == G->Enemies.end() )
	{	// old enemy target that doesn't exist
		U->enemyID=-1;
		if( IdleIfInvalid )
			G->UpdateEventAdd(1,cb->GetCurrentFrame()+90,unitID,U);
		return false;
	}
	float3 EPos = cb->GetUnitPos(U->enemyID);
	if( U->group == 0 )
	{	// keeping variables up-to-date, this is event-driven for groups
		U->E = &G->Enemies.find(U->enemyID)->second;
		U->enemyEff = CanAttack(U,U->E,EPos);
	}
	if( cb->GetUnitDef(U->enemyID) != 0 && cb->GetUnitAllyTeam(unitID) == cb->GetUnitAllyTeam(U->enemyID) )
	{	// an enemy ID was reused by an ally team
		if( U->E->inLOS || U->E->inRadar ) // ! Work Around:  Spring-Version(v0.72b1-0.76b1)
		{	// OR an ally captures an enemy unit & no events were sent
			*l<<"\nWARNING: ValidateEnemy(eID="<<U->enemyID<<"): an ally has captured an enemy unit";
		}
		G->EnemyDestroyed(U->enemyID,-1);
		U->enemyID=-1;
		return false;
	}
	if( EPos.x > 0 || EPos.z > 0 || EPos.y > 0 ) // Position is valid
	{
		if( !U->E->inLOS && !U->E->inRadar ) // ! Work Around:  Spring-Version(v0.72b1-0.76b1)
		{
			if( cb->GetUnitDef(U->enemyID) != 0 )
			{
				*l<<"\nWARNING: ValidateEnemy(eID="<<U->enemyID<<"): incorrect LOS status";
				G->EnemyEnterLOS(U->enemyID);
			}
			else
			{
				*l<<"\nWARNING: ValidateEnemy(eID="<<U->enemyID<<"): incorrect radar status";
				G->EnemyEnterRadar(U->enemyID);
			}
		}
		return true;
	}
	if( !U->E->inLOS && !U->E->inRadar && cb->GetUnitPos(unitID).distance2D(U->E->position) > 300.0f )
		return true;
	G->EnemyRemove(U->enemyID,U->E);
	U->enemyID=-1;
	if( IdleIfInvalid )
		G->UpdateEventAdd(1,cb->GetCurrentFrame()+90,unitID,U);
	return false;
}
開發者ID:Mocahteam,項目名稱:SpringPP,代碼行數:50,代碼來源:CombatManager.cpp

示例6: AttackStart

void PetAI::AttackStart(Unit* target)
{
    // Overrides Unit::AttackStart to correctly evaluate Pet states

    // Check all pet states to decide if we can attack this target
    if (!CanAttack(target))
        return;

    if (Unit* owner = me->GetCharmerOrOwner())
        owner->RemoveAurasByType(SPELL_AURA_MOD_CAMOUFLAGE);

    // Only chase if not commanded to stay or if stay but commanded to attack
    DoAttack(target, (!me->GetCharmInfo()->HasCommandState(COMMAND_STAY) || me->GetCharmInfo()->IsCommandAttack()));
}
開發者ID:Cailiaock,項目名稱:5.4.7-Wow-source,代碼行數:14,代碼來源:PetAI.cpp

示例7: DetermineWeaponState

void AWeapon::DetermineWeaponState(){
	EWeaponState::Type NewState = EWeaponState::Idle;

	if (IsEquiped())
	{
		if (bWantsToAttack && CanAttack())
		{
			NewState = EWeaponState::Attacking;
		}
	}
	else if (bPendingEquip)
	{
		NewState = EWeaponState::Equipping;
	}

	SetCurrentState(NewState);
}
開發者ID:belven,項目名稱:Mutagen,代碼行數:17,代碼來源:Weapon.cpp

示例8: PrimaryAttack

//-----------------------------------------------------------------------------
// Purpose: Primary fire function
//-----------------------------------------------------------------------------
void CTFFlareGun::PrimaryAttack(void)
{
	// Check for ammunition.
	if (m_iClip1 <= 0 && m_iClip1 != -1)
		return;

	// Are we capable of firing again?
	if (m_flNextPrimaryAttack > gpGlobals->curtime)
		return;

	if (!CanAttack())
		return;

	m_iWeaponMode = TF_WEAPON_PRIMARY_MODE;

	LaunchProjectile();
}
開發者ID:staticfox,項目名稱:TF2Classic,代碼行數:20,代碼來源:tf_weapon_flaregun.cpp

示例9: if

int cCombatManager::GetClosestThreat(float3 Pos, UnitInfo* U)
{
    sWeaponEfficiency* weTemp;
    float distance,fTemp;
    distance=0.0f;
    float3 fE;
    set<int> deletion;
    for( map<int,EnemyInfo*>::iterator E=G->EThreat.begin(); E!=G->EThreat.end(); ++E )
    {
        fE=GetEnemyPosition(E->first,E->second);
        if( E->second->baseThreatFrame > cb->GetCurrentFrame()+3600 ||
                (E->second->baseThreatFrame > cb->GetCurrentFrame()+1200 && G->UImmobile.find(E->second->baseThreatID) == G->UImmobile.end() ) ||
                (E->second->ud != 0 && G->UImmobile.find(E->second->baseThreatID) != G->UImmobile.end() && 1.3*E->second->ud->maxWeaponRange < fE.distance(cb->GetUnitPos(E->second->baseThreatID)) ) )
        {
            E->second->baseThreatID = -1;
            E->second->baseThreatFrame = -1;
            deletion.insert(E->first);
        }
        else if( (weTemp = CanAttack(U,E->second,fE)) != 0 )
        {
            fTemp=Pos.distance(fE);
            if( U->enemyID == -1 || fTemp < distance )
            {
                U->enemyID=E->first;
                U->E = E->second;
                U->enemyEff = weTemp;
                distance=fTemp;
            }
        }
    }
    while( int(deletion.size()) > 0 )
    {
        if( !G->UM->ActiveAttackOrders() )
        {
            EnemyInfo* E = G->EThreat.find(*deletion.begin())->second;
            while( int(E->attackGroups.size()) > 0 )
                G->UM->GroupRemoveEnemy(*deletion.begin(),E,*E->attackGroups.begin());
        }
        G->EThreat.erase(*deletion.begin());
        deletion.erase(*deletion.begin());
    }
    if( U->enemyID != -1 && U->group != 0 )
        G->UM->GroupAddEnemy(U->enemyID,U->E,U->group);
    return U->enemyID;
}
開發者ID:9heart,項目名稱:spring,代碼行數:45,代碼來源:CombatManager.cpp

示例10: GetTFPlayerOwner

void CTFChainsaw::PrimaryAttack(void)
{
	// Get the current player.
	CTFPlayer *pPlayer = GetTFPlayerOwner();
	if ( !pPlayer )
		return;

	if ( !CanAttack() )
		return;

	// Set the weapon usage mode - primary, secondary.
	m_iWeaponMode = TF_WEAPON_PRIMARY_MODE;
	m_bConnected = false;

	bIsAttacking = true;

	BaseClass::PrimaryAttack();
}
開發者ID:TenmaPL,項目名稱:TF2Classic,代碼行數:18,代碼來源:tf_weapon_chainsaw.cpp

示例11: CanAttackSpell

/////////////////////////////////////////////////
/// [Serverside] Opposition: Unit can target a target with a harmful spell
///
/// @note Relations API Tier 3
///
/// This function is not intented to have client-side counterpart by original design.
/// It utilizes SpellEntry for additional target filtering.
/// Also an additional fine grained check needs to be done for AOE spells, because they
/// need to skip PVP enabled targets in some special cases. (Chain spells, AOE)
/////////////////////////////////////////////////
bool Unit::CanAttackSpell(Unit const* target, SpellEntry const* spellInfo, bool isAOE) const
{
    if (spellInfo)
    {
        // inversealive is needed for some spells which need to be casted at dead targets (aoe)
        if (!target->isAlive() && !spellInfo->HasAttribute(SPELL_ATTR_EX2_CAN_TARGET_DEAD))
            return false;
    }

    if (CanAttack(target))
    {
        if (isAOE)
        {
            if (HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED))
            {
                if (target->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED))
                {
                    const Player* thisPlayer = GetControllingPlayer();
                    if (!thisPlayer)
                        return true;

                    const Player* unitPlayer = target->GetControllingPlayer();
                    if (!unitPlayer)
                        return true;

                    if (thisPlayer->IsInDuelWith(unitPlayer))
                        return true;

                    if (unitPlayer->IsPvP() && (!isAOE || thisPlayer->IsPvP()))
                        return true;

                    if (thisPlayer->IsPvPFreeForAll() && unitPlayer->IsPvPFreeForAll())
                        return true;

                    return false;
                }
            }
        }

        return true;
    }
    return false;
}
開發者ID:Tobschinski,項目名稱:mangos-classic,代碼行數:53,代碼來源:Relations.cpp

示例12: ToBasePlayer

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFPistol::PrimaryAttack( void )
{
#if 0
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );

	if( pOwner )
	{
		// Each time the player fires the pistol, reset the view punch. This prevents
		// the aim from 'drifting off' when the player fires very quickly. This may
		// not be the ideal way to achieve this, but it's cheap and it works, which is
		// great for a feature we're evaluating. (sjb)
		//pOwner->ViewPunchReset();
	}
#endif

	if ( !CanAttack() )
		return;

	BaseClass::PrimaryAttack();
}
開發者ID:TenmaPL,項目名稱:TF2Classic,代碼行數:23,代碼來源:tf_weapon_pistol.cpp

示例13: GetTFPlayerOwner

// -----------------------------------------------------------------------------
// Purpose:
// -----------------------------------------------------------------------------
void CTFWeaponBaseMelee::PrimaryAttack()
{
	// Get the current player.
	CTFPlayer *pPlayer = GetTFPlayerOwner();
	if ( !pPlayer )
		return;

	if ( !CanAttack() )
		return;

	// Set the weapon usage mode - primary, secondary.
	m_iWeaponMode = TF_WEAPON_PRIMARY_MODE;
	m_bConnected = false;

	// Swing the weapon.
	Swing( pPlayer );

#if !defined( CLIENT_DLL ) 
	pPlayer->SpeakWeaponFire();
	CTF_GameStats.Event_PlayerFiredWeapon( pPlayer, IsCurrentAttackACritical() );
#endif
}
開發者ID:staticfox,項目名稱:TF2Classic,代碼行數:25,代碼來源:tf_weaponbase_melee.cpp

示例14: GetPlayerOwner

void CDODBaseRocketWeapon::SecondaryAttack()
{
	CBasePlayer *pPlayer = GetPlayerOwner();

	//if we're underwater, lower it
	if( pPlayer->GetWaterLevel() > 2 )
	{
		if( IsDeployed() )
			Lower();
		return;
	}

	if( IsDeployed() )
	{	
		Lower();
	}
	else
	{
		if ( CanAttack() )
            Raise();
	}	
}
開發者ID:Axitonium,項目名稱:SourceEngine2007,代碼行數:22,代碼來源:weapon_dodbaserpg.cpp

示例15: CanAttack

/////////////////////////////////////////////////
/// Opposition: Unit treats another unit as an enemy it can attack (immediate response)
///
/// @note Relations API Tier 1
///
/// Backported from TBC+ client-side counterpart: <tt>CGUnit_C::CanAttackNow(const CGUnit_C *this, const CGUnit_C *unit)</tt>
/// Intended usage is to verify direct requests to attack something.
/// First appeared in TBC+ clients, backported for API unification between expansions.
/////////////////////////////////////////////////
bool Unit::CanAttackNow(const Unit* unit) const
{
    // Simple sanity check
    if (!unit)
        return false;

    // Original logic

    // We can't initiate attack while dead or ghost
    if (!isAlive())
        return false;

    // We can't initiate attack while mounted
    if (IsMounted())
        return false;

    // We can't initiate attack on dead units
    if (!unit->isAlive())
        return false;

    return CanAttack(unit);
}
開發者ID:Tobschinski,項目名稱:mangos-classic,代碼行數:31,代碼來源:Relations.cpp


注:本文中的CanAttack函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。