本文整理汇总了C++中Pet::Attack方法的典型用法代码示例。如果您正苦于以下问题:C++ Pet::Attack方法的具体用法?C++ Pet::Attack怎么用?C++ Pet::Attack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pet
的用法示例。
在下文中一共展示了Pet::Attack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
{
if (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())
{
// 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;
}
}
if (!petUnit->GetCharmerGuid())
return;
}
switch (flag)
{
case ACT_COMMAND: // 0x07
switch (spellid)
//.........这里部分代码省略.........