本文整理汇总了C++中Pet::AI方法的典型用法代码示例。如果您正苦于以下问题:C++ Pet::AI方法的具体用法?C++ Pet::AI怎么用?C++ Pet::AI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pet
的用法示例。
在下文中一共展示了Pet::AI方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandlePetAction
void WorldSession::HandlePetAction(WorldPacket& recv_data)
{
ObjectGuid petGuid;
uint32 data;
ObjectGuid targetGuid;
recv_data >> petGuid;
recv_data >> data;
recv_data >> targetGuid;
uint32 spellid = UNIT_ACTION_BUTTON_ACTION(data);
uint8 flag = UNIT_ACTION_BUTTON_TYPE(data); // delete = 0x07 CastSpell = C1
DETAIL_LOG("HandlePetAction: %s flag is %u, spellid is %u, target %s.", petGuid.GetString().c_str(), uint32(flag), spellid, targetGuid.GetString().c_str());
// used also for charmed creature/player
Unit* petUnit = _player->GetMap()->GetUnit(petGuid);
if (!petUnit)
{
sLog.outError("HandlePetAction: %s not exist.", petGuid.GetString().c_str());
return;
}
if (_player->GetObjectGuid() != petUnit->GetCharmerOrOwnerGuid())
{
sLog.outError("HandlePetAction: %s isn't controlled by %s.", petGuid.GetString().c_str(), _player->GetGuidStr().c_str());
return;
}
if (!petUnit->isAlive())
return;
CharmInfo* charmInfo = petUnit->GetCharmInfo();
if (!charmInfo)
{
sLog.outError("WorldSession::HandlePetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", petUnit->GetGUIDLow(), petUnit->GetTypeId());
return;
}
Pet* pet = nullptr;
Creature* creature = nullptr;
if (petUnit->GetTypeId() == TYPEID_UNIT)
{
creature = static_cast<Creature*>(petUnit);
if (creature->IsPet())
{
pet = static_cast<Pet*>(petUnit);
if (pet->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
return;
}
}
if (!pet && petUnit->hasUnitState(UNIT_STAT_CONTROLLED))
{
// possess case
if (flag != uint8(ACT_COMMAND))
{
sLog.outError("PetHAndler: unknown PET flag Action %i and spellid %i. For possessed %s", uint32(flag), spellid, petUnit->GetGuidStr().c_str());
return;
}
switch (spellid)
{
case COMMAND_STAY:
case COMMAND_FOLLOW:
charmInfo->SetCommandState(CommandStates(spellid));
break;
case COMMAND_ATTACK:
{
Unit* targetUnit = targetGuid ? _player->GetMap()->GetUnit(targetGuid) : nullptr;
if (targetUnit && targetUnit != petUnit && targetUnit->isTargetableForAttack())
{
_player->SetInCombatState(true, targetUnit);
// This is true if pet has no target or has target but targets differs.
if (petUnit->getVictim() != targetUnit)
petUnit->Attack(targetUnit, true);
}
break;
}
case COMMAND_ABANDON:
_player->Uncharm();
break;
default:
sLog.outError("PetHandler: Not allowed action %i and spellid %i. Pet %s owner is %s", uint32(flag), spellid, petUnit->GetGuidStr().c_str(), _player->GetGuidStr().c_str());
break;
}
return;
}
// only real pet should go there
if (!pet)
{
sLog.outError("PetHandler: A not pet trying to do unknown Action %i and spellid %i. Pet %s owner is %s", uint32(flag), spellid, petUnit->GetGuidStr().c_str(), _player->GetGuidStr().c_str());
return;
}
//.........这里部分代码省略.........
示例2: DoNextCombatManeuver
void PlayerbotHunterAI::DoNextCombatManeuver(Unit *pTarget)
{
if (!pTarget || pTarget->isDead()) return;
PlayerbotAI *ai = GetAI();
if (!ai) return;
Player *m_bot = GetPlayerBot();
if (!m_bot || m_bot->isDead()) return;
Unit *pVictim = pTarget->getVictim();
Unit *m_tank = FindMainTankInRaid(GetMaster());
if (!m_tank && m_bot->GetGroup() && GetMaster()->GetGroup() != m_bot->GetGroup()) { FindMainTankInRaid(m_bot); }
if (!m_tank) { m_tank = m_bot; }
uint32 masterHP = GetMaster()->GetHealth()*100 / GetMaster()->GetMaxHealth();
float pDist = m_bot->GetDistance(pTarget);
uint8 pThreat = GetThreatPercent(pTarget);
Pet *pet = m_bot->GetPet();
if (m_tank->GetGUID() == m_bot->GetGUID() && pet && pet->isAlive() && pet->isInCombat()) { m_tank = pet; }
uint8 petThreat = 0;
if (pet) { GetThreatPercent(pTarget,pet); }
// switch (ai->GetScenarioType())
// {
// case PlayerbotAI::SCENARIO_DUEL:
// ai->CastSpell(RAPTOR_STRIKE);
// return;
// }
// ------- Non Duel combat ----------
#pragma region Choose Target
// Choose Target
if (isUnderAttack()) // I am under attack
{
if (pVictim && pVictim->GetGUID() == m_bot->GetGUID() && pDist <= 2) { } // My target is almost up to me, no need to search
else //Have to select nearest target
{
Unit *curAtt = GetNearestAttackerOf(m_bot);
if (curAtt && curAtt->GetGUID() != pTarget->GetGUID())
{
m_bot->SetSelection(curAtt->GetGUID());
//ai->AddLootGUID(curAtt->GetGUID());
DoNextCombatManeuver(curAtt); //Restart new update to get variables fixed..
return;
}
}
//my target is attacking me
}
#pragma endregion
#pragma region Pet Actions
// Pet's own Actions
if( pet && pet->isAlive() )
{
// Setup pet
if (pet->GetCharmInfo()->IsAtStay()) {pet->GetCharmInfo()->SetCommandState(COMMAND_FOLLOW); }
//Heal pet
if ( ( ((float)pet->GetHealth()/(float)pet->GetMaxHealth()) < 0.5f )
&& ( PET_MEND>0 && !pet->getDeathState() != ALIVE && pVictim != m_bot
&& CastSpell(PET_MEND,m_bot) )) { return; }
// Set pet to attack hunter's attacker > its own attackers > hunter's target
if (!pet->getVictim()) { pet->AI()->AttackStart(pTarget); }
else if (isUnderAttack(m_bot)) { pet->AI()->AttackStart(pTarget); } //Always help hunter if she's under attack
else if (pet->getVictim()->GetGUID() != pTarget->GetGUID() && !isUnderAttack(pet)) { pet->AI()->AttackStart(pTarget); }
else if (isUnderAttack(pet)) // Pet is under attack and hunter has no attackers
{
if ( pet->getVictim()->getVictim() && pet->getVictim()->getVictim()->GetGUID() == pet->GetGUID() && pDist <= 2) { } // My target is almost up to me, no need to search
else //Have to select nearest target
{
Unit *curAtt = GetNearestAttackerOf(pet,true);
if (curAtt && (!pet->getVictim() || curAtt->GetGUID() != pet->getVictim()->GetGUID()))
{
pet->AI()->AttackStart(curAtt); //Attack nearest attacker
}
}
//Actions to do under attack (Always tank it, and try to kill it, until someone (!= hunter) takes aggro back)
//Hunter should help her pet whether main tank or not, unless she's being attacked (BEWARE Targeting Loop possibility)
if (pet->getVictim() && !isUnderAttack(m_bot) && pet->getVictim()->GetGUID() != pTarget->GetGUID())
{
m_bot->SetSelection(pet->getVictim()->GetGUID());
DoNextCombatManeuver(pet->getVictim()); //Restart new update to get variables fixed..
return;
}
}
// Pet tanking behaviour
if (pet->GetGUID() == m_tank->GetGUID() || isUnderAttack(m_bot) || isUnderAttack(pet))
{
if (GROWL) pet->GetCharmInfo()->SetSpellAutocast(GROWL,true); //Autocast growl
if (BAD_ATTITUDE) pet->GetCharmInfo()->SetSpellAutocast(BAD_ATTITUDE,true);
if (COWER) pet->GetCharmInfo()->SetSpellAutocast(COWER,false);
if (CastSpell(INTIMIDATION,m_bot)) { return; }
}
else
{
if (GROWL) pet->GetCharmInfo()->SetSpellAutocast(GROWL,false); //Do not try to get aggro
if (BAD_ATTITUDE) pet->GetCharmInfo()->SetSpellAutocast(BAD_ATTITUDE,false);
//.........这里部分代码省略.........