本文整理汇总了C++中CharmInfo类的典型用法代码示例。如果您正苦于以下问题:C++ CharmInfo类的具体用法?C++ CharmInfo怎么用?C++ CharmInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CharmInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClearCharmInfoFlags
void PetAI::ClearCharmInfoFlags()
{
// Quick access to set all flags to FALSE
CharmInfo* ci = me->GetCharmInfo();
if (ci)
{
ci->SetIsAtStay(false);
ci->SetIsCommandAttack(false);
ci->SetIsCommandFollow(false);
ci->SetIsFollowing(false);
ci->SetIsReturning(false);
}
}
示例2: DETAIL_LOG
void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
{
DETAIL_LOG( "HandlePetSetAction. CMSG_PET_SET_ACTION" );
uint64 petguid;
uint8 count;
recv_data >> petguid;
// FIXME: charmed case
//Pet* pet = ObjectAccessor::Instance().GetPet(petguid);
if(ObjectAccessor::FindPlayer(petguid))
return;
Creature* pet = _player->GetMap()->GetAnyTypeCreature(petguid);
if(!pet || (pet != _player->GetPet() && pet != _player->GetCharm()))
{
sLog.outError( "HandlePetSetAction: Unknown pet or pet owner." );
return;
}
// pet can have action bar disabled
if(pet->IsPet() && ((Pet*)pet)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
return;
CharmInfo *charmInfo = pet->GetCharmInfo();
if(!charmInfo)
{
sLog.outError("WorldSession::HandlePetSetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
return;
}
count = (recv_data.size() == 24) ? 2 : 1;
uint32 position[2];
uint32 data[2];
bool move_command = false;
for(uint8 i = 0; i < count; ++i)
{
recv_data >> position[i];
recv_data >> data[i];
uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]);
//ignore invalid position
if(position[i] >= MAX_UNIT_ACTION_BAR_INDEX)
return;
// in the normal case, command and reaction buttons can only be moved, not removed
// at moving count ==2, at removing count == 1
// ignore attempt to remove command|reaction buttons (not possible at normal case)
if (act_state == ACT_COMMAND || act_state == ACT_REACTION)
{
if (count == 1)
return;
move_command = true;
}
}
// check swap (at command->spell swap client remove spell first in another packet, so check only command move correctness)
if (move_command)
{
uint8 act_state_0 = UNIT_ACTION_BUTTON_TYPE(data[0]);
if(act_state_0 == ACT_COMMAND || act_state_0 == ACT_REACTION)
{
uint32 spell_id_0 = UNIT_ACTION_BUTTON_ACTION(data[0]);
UnitActionBarEntry const* actionEntry_1 = charmInfo->GetActionBarEntry(position[1]);
if (!actionEntry_1 || spell_id_0 != actionEntry_1->GetAction() ||
act_state_0 != actionEntry_1->GetType())
return;
}
uint8 act_state_1 = UNIT_ACTION_BUTTON_TYPE(data[1]);
if(act_state_1 == ACT_COMMAND || act_state_1 == ACT_REACTION)
{
uint32 spell_id_1 = UNIT_ACTION_BUTTON_ACTION(data[1]);
UnitActionBarEntry const* actionEntry_0 = charmInfo->GetActionBarEntry(position[0]);
if (!actionEntry_0 || spell_id_1 != actionEntry_0->GetAction() ||
act_state_1 != actionEntry_0->GetType())
return;
}
}
for(uint8 i = 0; i < count; ++i)
{
uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(data[i]);
uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]);
DETAIL_LOG( "Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X", _player->GetName(), position[i], spell_id, uint32(act_state));
//if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add
if(!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_PASSIVE) && spell_id && !pet->HasSpell(spell_id)))
{
//sign for autocast
if(act_state == ACT_ENABLED && spell_id)
{
if(pet->isCharmed())
//.........这里部分代码省略.........
示例3: UNIT_ACTION_BUTTON_ACTION
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* pet = _player->GetMap()->GetUnit(petGuid);
if (!pet)
{
sLog.outError("HandlePetAction: %s not exist.", petGuid.GetString().c_str());
return;
}
if (GetPlayer()->GetObjectGuid() != pet->GetCharmerOrOwnerGuid())
{
sLog.outError("HandlePetAction: %s isn't controlled by %s.", petGuid.GetString().c_str(), GetPlayer()->GetGuidStr().c_str());
return;
}
if (!pet->isAlive())
return;
if (pet->GetTypeId() == TYPEID_PLAYER)
{
// controller player can only do melee attack
if (!(flag == ACT_COMMAND && spellid == COMMAND_ATTACK))
return;
}
else if (((Creature*)pet)->IsPet())
{
// pet can have action bar disabled
if(((Pet*)pet)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
return;
}
CharmInfo *charmInfo = pet->GetCharmInfo();
if(!charmInfo)
{
sLog.outError("WorldSession::HandlePetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
return;
}
switch(flag)
{
case ACT_COMMAND: //0x07
switch(spellid)
{
case COMMAND_STAY: //flat=1792 //STAY
pet->StopMoving();
pet->GetMotionMaster()->Clear(false);
pet->GetMotionMaster()->MoveIdle();
charmInfo->SetCommandState( COMMAND_STAY );
break;
case COMMAND_FOLLOW: //spellid=1792 //FOLLOW
pet->AttackStop();
pet->GetMotionMaster()->MoveFollow(_player,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE);
charmInfo->SetCommandState( COMMAND_FOLLOW );
break;
case COMMAND_ATTACK: //spellid=1792 //ATTACK
{
Unit *TargetUnit = _player->GetMap()->GetUnit(targetGuid);
if(!TargetUnit)
return;
// not let attack friendly units.
if(GetPlayer()->IsFriendlyTo(TargetUnit))
return;
// Not let attack through obstructions
if(!pet->IsWithinLOSInMap(TargetUnit))
return;
// This is true if pet has no target or has target but targets differs.
if(pet->getVictim() != TargetUnit)
{
if (pet->getVictim())
pet->AttackStop();
if (pet->hasUnitState(UNIT_STAT_CONTROLLED))
{
pet->Attack(TargetUnit, true);
pet->SendPetAIReaction();
}
else
{
pet->GetMotionMaster()->Clear();
if (((Creature*)pet)->AI())
((Creature*)pet)->AI()->AttackStart(TargetUnit);
// 10% chance to play special pet attack talk, else growl
if(((Creature*)pet)->IsPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && roll_chance_i(10))
//.........这里部分代码省略.........
示例4: CHECK_PACKET_SIZE
void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data, 8+4+2+2);
sLog.outDetail( "HandlePetSetAction. CMSG_PET_SET_ACTION\n" );
uint64 petguid;
uint32 position;
uint16 spell_id;
uint16 act_state;
uint8 count;
recv_data >> petguid;
// FIXME: charmed case
//Pet* pet = ObjectAccessor::Instance().GetPet(petguid);
if(ObjectAccessor::FindPlayer(petguid))
return;
Creature* pet = ObjectAccessor::GetCreatureOrPet(*_player, petguid);
if(!pet || (pet != _player->GetPet() && pet != _player->GetCharm()))
{
sLog.outError( "HandlePetSetAction: Unknown pet or pet owner.\n" );
return;
}
CharmInfo *charmInfo = pet->GetCharmInfo();
if(!charmInfo)
{
sLog.outError("WorldSession::HandlePetSetAction: object "I64FMTD" is considered pet-like but doesn't have a charminfo!", pet->GetGUID());
return;
}
count = (recv_data.size() == 24) ? 2 : 1;
for(uint8 i = 0; i < count; i++)
{
recv_data >> position;
recv_data >> spell_id;
recv_data >> act_state;
sLog.outDetail( "Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X\n", _player->GetName(), position, spell_id, act_state);
//if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add
if(!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_CAST) && spell_id && !pet->HasSpell(spell_id)))
{
//sign for autocast
if(act_state == ACT_ENABLED && spell_id)
{
if(pet->isCharmed())
charmInfo->ToggleCreatureAutocast(spell_id, true);
else
((Pet*)pet)->ToggleAutocast(spell_id, true);
}
//sign for no/turn off autocast
else if(act_state == ACT_DISABLED && spell_id)
{
if(pet->isCharmed())
charmInfo->ToggleCreatureAutocast(spell_id, false);
else
((Pet*)pet)->ToggleAutocast(spell_id, false);
}
charmInfo->GetActionBarEntry(position)->Type = act_state;
charmInfo->GetActionBarEntry(position)->SpellOrAction = spell_id;
}
}
}
示例5: UNIT_ACTION_BUTTON_ACTION
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->GetMasterGuid())
{
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_POSSESSED))
{
// 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 && petUnit->CanAttack(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_DISMISS:
_player->BreakCharmOutgoing(petUnit);
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->HasCharmer())
return;
}
switch (flag)
{
case ACT_COMMAND: // 0x07
switch (spellid)
//.........这里部分代码省略.........
示例6: UpdateAllies
void PetAI::UpdateAI(const uint32 diff)
{
if (!m_unit->isAlive())
return;
Creature* creature = (m_unit->GetTypeId() == TYPEID_UNIT) ? static_cast<Creature*>(m_unit) : nullptr;
Pet* pet = (creature && creature->IsPet()) ? static_cast<Pet*>(m_unit) : nullptr;
Unit* owner = m_unit->GetMaster();
if (!owner)
return;
Unit* victim = (pet && pet->GetModeFlags() & PET_MODE_DISABLE_ACTIONS) ? nullptr : m_unit->getVictim();
if (m_updateAlliesTimer <= diff)
// UpdateAllies self set update timer
UpdateAllies();
else
m_updateAlliesTimer -= diff;
if (inCombat && !victim)
{
m_unit->AttackStop(true, true);
inCombat = false;
}
CharmInfo* charminfo = m_unit->GetCharmInfo();
MANGOS_ASSERT(charminfo);
if (charminfo->GetIsRetreating())
{
if (!owner->IsWithinDistInMap(m_unit, (PET_FOLLOW_DIST * 2)))
{
if (!m_unit->hasUnitState(UNIT_STAT_FOLLOW))
m_unit->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
return;
}
else
charminfo->SetIsRetreating();
}
else if (charminfo->GetSpellOpener() != 0) // have opener stored
{
uint32 minRange = charminfo->GetSpellOpenerMinRange();
if (!(victim = m_unit->getVictim())
|| (minRange != 0 && m_unit->IsWithinDistInMap(victim, minRange)))
charminfo->SetSpellOpener();
else if (m_unit->IsWithinDistInMap(victim, charminfo->GetSpellOpenerMaxRange())
&& m_unit->IsWithinLOSInMap(victim))
{
// stop moving
m_unit->clearUnitState(UNIT_STAT_MOVING);
// auto turn to target
m_unit->SetInFront(victim);
if (victim->GetTypeId() == TYPEID_PLAYER)
m_unit->SendCreateUpdateToPlayer((Player*)victim);
if (owner->GetTypeId() == TYPEID_PLAYER)
m_unit->SendCreateUpdateToPlayer((Player*)owner);
uint32 spell_id = charminfo->GetSpellOpener();
SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spell_id);
Spell* spell = new Spell(m_unit, spellInfo, false);
SpellCastResult result = spell->CheckPetCast(victim);
if (result == SPELL_CAST_OK)
spell->SpellStart(&(spell->m_targets));
else
delete spell;
charminfo->SetSpellOpener();
}
else
return;
}
// Auto cast (casted only in combat or persistent spells in any state)
else if (!m_unit->IsNonMeleeSpellCasted(false))
{
typedef std::vector<std::pair<Unit*, Spell*> > TargetSpellList;
TargetSpellList targetSpellStore;
if (pet)
{
for (uint8 i = 0; i < pet->GetPetAutoSpellSize(); ++i)
{
uint32 spellID = pet->GetPetAutoSpellOnPos(i);
if (!spellID)
continue;
SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spellID);
if (!spellInfo)
continue;
if (!m_unit->IsSpellReady(*spellInfo))
continue;
// ignore some combinations of combat state and combat/non combat spells
//.........这里部分代码省略.........
示例7: HandlePetActionHelper
void WorldSession::HandlePetActionHelper(Unit *pet, uint64 guid1, uint16 spellid, uint16 flag, uint64 guid2)
{
CharmInfo *charmInfo = pet->GetCharmInfo();
if(!charmInfo)
{
sLog.outError("WorldSession::HandlePetAction: object "I64FMTD" is considered pet-like but doesn't have a charminfo!", pet->GetGUID());
return;
}
switch(flag)
{
case ACT_COMMAND: //0x0700
// Possessed or shared vision pets are only able to attack
if ((pet->isPossessed() || pet->HasAuraType(SPELL_AURA_BIND_SIGHT)) && spellid != COMMAND_ATTACK)
return;
switch(spellid)
{
case COMMAND_STAY: //flat=1792 //STAY
pet->AttackStop();
pet->InterruptNonMeleeSpells(false);
pet->GetMotionMaster()->MoveIdle();
charmInfo->SetCommandState( COMMAND_STAY );
break;
case COMMAND_FOLLOW: //spellid=1792 //FOLLOW
pet->AttackStop();
pet->InterruptNonMeleeSpells(false);
pet->GetMotionMaster()->MoveFollow(_player,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE);
charmInfo->SetCommandState( COMMAND_FOLLOW );
break;
case COMMAND_ATTACK: //spellid=1792 //ATTACK
{
// Can't attack if owner is pacified
if (_player->HasAuraType(SPELL_AURA_MOD_PACIFY))
{
//pet->SendPetCastFail(spellid, SPELL_FAILED_PACIFIED);
//TODO: Send proper error message to client
return;
}
// only place where pet can be player
Unit *TargetUnit = ObjectAccessor::GetUnit(*_player, guid2);
if(!TargetUnit)
return;
if(!pet->canAttack(TargetUnit))
return;
// Not let attack through obstructions
//if(!pet->IsWithinLOSInMap(TargetUnit))
// return;
pet->clearUnitState(UNIT_STAT_FOLLOW);
// This is true if pet has no target or has target but targets differs.
if(pet->getVictim() != TargetUnit)
{
if (pet->getVictim())
pet->AttackStop();
if(pet->GetTypeId() != TYPEID_PLAYER && ((Creature*)pet)->IsAIEnabled)
{
((Creature*)pet)->AI()->AttackStart(TargetUnit);
//10% chance to play special pet attack talk, else growl
if(((Creature*)pet)->isPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && urand(0, 100) < 10)
pet->SendPetTalk((uint32)PET_TALK_ATTACK);
else
{
// 90% chance for pet and 100% chance for charmed creature
pet->SendPetAIReaction(guid1);
}
}
else // charmed player
{
if(pet->getVictim() && pet->getVictim() != TargetUnit)
pet->AttackStop();
pet->Attack(TargetUnit,true);
pet->SendPetAIReaction(guid1);
}
}
break;
}
case COMMAND_ABANDON: // abandon (hunter pet) or dismiss (summoned pet)
if(pet->GetCharmerGUID() == GetPlayer()->GetGUID())
{
if(GetPlayer()->m_seer != pet)
_player->StopCastingCharm();
}
else if(pet->GetOwnerGUID() == GetPlayer()->GetGUID())
{
assert(pet->GetTypeId() == TYPEID_UNIT);
if(((Creature*)pet)->isPet())
{
if(((Pet*)pet)->getPetType() == HUNTER_PET)
GetPlayer()->RemovePet((Pet*)pet, PET_SAVE_AS_DELETED);
else
//dismissing a summoned pet is like killing them (this prevents returning a soulshard...)
pet->setDeathState(CORPSE);
}
//.........这里部分代码省略.........
示例8: if
/// Add control and such modifiers to a passenger if required
void VehicleInfo::ApplySeatMods(Unit* passenger, uint32 seatFlags)
{
Unit* pVehicle = (Unit*)m_owner; // Vehicles are alawys Unit
if (seatFlags & SEAT_FLAG_NOT_SELECTABLE)
passenger->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
if (passenger->GetTypeId() == TYPEID_PLAYER)
{
Player* pPlayer = (Player*)passenger;
// group update
if (pPlayer->GetGroup())
pPlayer->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_VEHICLE_SEAT);
if (seatFlags & SEAT_FLAG_CAN_CONTROL)
{
pPlayer->GetCamera().SetView(pVehicle);
pPlayer->SetCharm(pVehicle);
pVehicle->SetCharmerGuid(pPlayer->GetObjectGuid());
pVehicle->addUnitState(UNIT_STAT_CONTROLLED);
pVehicle->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
pPlayer->SetClientControl(pVehicle, 1);
pPlayer->SetMover(pVehicle);
// Unconfirmed - default speed handling
if (pVehicle->GetTypeId() == TYPEID_UNIT)
{
if (!pPlayer->IsWalking() && pVehicle->IsWalking())
{
((Creature*)pVehicle)->SetWalk(false, true);
}
else if (pPlayer->IsWalking() && !pVehicle->IsWalking())
{
((Creature*)pVehicle)->SetWalk(true, true);
}
// set vehicle faction as per the controller faction
((Creature*)pVehicle)->SetFactionTemporary(pPlayer->getFaction(), TEMPFACTION_NONE);
}
}
if (seatFlags & SEAT_FLAG_CAN_CAST)
{
CharmInfo* charmInfo = pVehicle->InitCharmInfo(pVehicle);
charmInfo->InitVehicleCreateSpells();
pPlayer->PossessSpellInitialize();
}
}
else if (passenger->GetTypeId() == TYPEID_UNIT)
{
if (seatFlags & SEAT_FLAG_CAN_CONTROL)
{
passenger->SetCharm(pVehicle);
pVehicle->SetCharmerGuid(passenger->GetObjectGuid());
}
((Creature*)passenger)->AI()->SetCombatMovement(false);
// Not entirely sure how this must be handled in relation to CONTROL
// But in any way this at least would require some changes in the movement system most likely
passenger->GetMotionMaster()->Clear(false, true);
passenger->GetMotionMaster()->MoveIdle();
}
}
示例9: UNIT_ACTION_BUTTON_ACTION
void WorldSession::HandlePetAction(WorldPacket& recv_data)
{
ObjectGuid petGuid;
uint32 data;
ObjectGuid targetGuid;
float x, y, z;
recv_data >> petGuid;
recv_data >> data;
recv_data >> targetGuid;
recv_data >> x >> y >> z;
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* pet = _player->GetMap()->GetUnit(petGuid);
if (!pet)
{
sLog.outError("HandlePetAction: %s not exist.", petGuid.GetString().c_str());
return;
}
if (_player->GetObjectGuid() != pet->GetCharmerOrOwnerGuid())
{
sLog.outError("HandlePetAction: %s isn't controlled by %s.", petGuid.GetString().c_str(), _player->GetGuidStr().c_str());
return;
}
if (!pet->isAlive())
return;
if (pet->GetTypeId() == TYPEID_PLAYER && pet->GetCharmer()->GetTypeId() == TYPEID_PLAYER)
{
// controller player cannot use controlled player's spells
if (flag != (ACT_COMMAND || ACT_REACTION))
return;
}
else if (((Creature*)pet)->IsPet())
{
// pet can have action bar disabled
if (((Pet*)pet)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
return;
}
CharmInfo* charmInfo = pet->GetCharmInfo();
if (!charmInfo)
{
sLog.outError("WorldSession::HandlePetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
return;
}
switch (flag)
{
case ACT_COMMAND: // 0x07
switch (spellid)
{
case COMMAND_STAY: // flat=1792 // STAY
{
pet->StopMoving();
pet->AttackStop(true, true);
pet->GetMotionMaster()->Clear();
((Pet*)pet)->SetStayPosition(true);
((Pet*)pet)->SetIsRetreating();
((Pet*)pet)->SetSpellOpener();
charmInfo->SetCommandState(COMMAND_STAY);
break;
}
case COMMAND_FOLLOW: // spellid=1792 // FOLLOW
{
pet->StopMoving();
pet->AttackStop(true, true);
pet->GetMotionMaster()->Clear();
((Pet*)pet)->SetStayPosition();
((Pet*)pet)->SetIsRetreating(true);
((Pet*)pet)->SetSpellOpener();
charmInfo->SetCommandState(COMMAND_FOLLOW);
break;
}
case COMMAND_ATTACK: // spellid=1792 // ATTACK
{
((Pet*)pet)->SetIsRetreating();
((Pet*)pet)->SetSpellOpener();
Unit* targetUnit = targetGuid ? _player->GetMap()->GetUnit(targetGuid) : nullptr;
if (targetUnit && targetUnit != pet && targetUnit->isTargetableForAttack() && targetUnit->isInAccessablePlaceFor((Creature*)pet))
{
_player->SetInCombatState(true, targetUnit);
// This is true if pet has no target or has target but targets differs.
if (pet->getVictim() != targetUnit)
{
pet->AttackStop();
pet->GetMotionMaster()->Clear();
if (((Creature*)pet)->AI())
{
((Creature*)pet)->AI()->AttackStart(targetUnit);
//.........这里部分代码省略.........
示例10: CHECK_PACKET_SIZE
void WorldSession::HandlePetAction( WorldPacket & recv_data )
{
CHECK_PACKET_SIZE(recv_data, 8+2+2+8);
uint64 guid1;
uint16 spellid;
uint16 flag;
uint64 guid2;
recv_data >> guid1; //pet guid
recv_data >> spellid;
recv_data >> flag; //delete = 0x0700 CastSpell = C100
recv_data >> guid2; //tag guid
// used also for charmed creature
Unit* pet= ObjectAccessor::GetUnit(*_player, guid1);
sLog.outDetail("HandlePetAction.Pet %u flag is %u, spellid is %u, target %u.", uint32(GUID_LOPART(guid1)), flag, spellid, uint32(GUID_LOPART(guid2)) );
if(!pet)
{
sLog.outError( "Pet %u not exist.", uint32(GUID_LOPART(guid1)) );
return;
}
if(pet != GetPlayer()->GetPet() && pet != GetPlayer()->GetCharm())
{
sLog.outError("HandlePetAction.Pet %u isn't pet of player %s.", uint32(GUID_LOPART(guid1)), GetPlayer()->GetName() );
return;
}
if(!pet->isAlive())
return;
if(pet->GetTypeId() == TYPEID_PLAYER && !(flag == ACT_COMMAND && spellid == COMMAND_ATTACK))
return;
CharmInfo *charmInfo = pet->GetCharmInfo();
if(!charmInfo)
{
sLog.outError("WorldSession::HandlePetAction: object "I64FMTD" is considered pet-like but doesn't have a charminfo!", pet->GetGUID());
return;
}
switch(flag)
{
case ACT_COMMAND: //0x0700
switch(spellid)
{
case COMMAND_STAY: //flat=1792 //STAY
pet->StopMoving();
pet->GetMotionMaster()->Clear();
pet->GetMotionMaster()->MoveIdle();
charmInfo->SetCommandState( COMMAND_STAY );
break;
case COMMAND_FOLLOW: //spellid=1792 //FOLLOW
pet->AttackStop();
pet->GetMotionMaster()->MoveFollow(_player,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE);
charmInfo->SetCommandState( COMMAND_FOLLOW );
break;
case COMMAND_ATTACK: //spellid=1792 //ATTACK
{
const uint64& selguid = _player->GetSelection();
Unit *TargetUnit = ObjectAccessor::GetUnit(*_player, selguid);
if(!TargetUnit)
return;
// not let attack friendly units.
if(GetPlayer()->IsFriendlyTo(TargetUnit))
return;
// Not let attack through obstructions
if(!pet->IsWithinLOSInMap(TargetUnit))
return;
// This is true if pet has no target or has target but targets differs.
if(pet->getVictim() != TargetUnit)
{
if (pet->getVictim())
pet->AttackStop();
if(pet->GetTypeId() != TYPEID_PLAYER)
{
pet->GetMotionMaster()->Clear();
if (((Creature*)pet)->AI())
((Creature*)pet)->AI()->AttackStart(TargetUnit);
//10% chance to play special pet attack talk, else growl
if(((Creature*)pet)->isPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && urand(0, 100) < 10)
pet->SendPetTalk((uint32)PET_TALK_ATTACK);
else
{
// 90% chance for pet and 100% chance for charmed creature
pet->SendPetAIReaction(guid1);
}
}
else // charmed player
{
pet->Attack(TargetUnit,true);
pet->SendPetAIReaction(guid1);
}
}
break;
}
//.........这里部分代码省略.........
示例11: IC_LOG_DEBUG
/*
void WorldSession::HandleDismissCritter(WorldPacket& recvData)
{
uint64 guid;
recvData >> guid;
IC_LOG_DEBUG("network", "WORLD: Received CMSG_DISMISS_CRITTER for GUID " UI64FMTD, guid);
Unit* pet = ObjectAccessor::GetCreatureOrPet(*_player, guid);
if (!pet)
{
IC_LOG_DEBUG("network", "Vanitypet (guid: %u) does not exist - player '%s' (guid: %u / account: %u) attempted to dismiss it (possibly lagged out)",
uint32(GUID_LOPART(guid)), GetPlayer()->GetName().c_str(), GetPlayer()->GetGUIDLow(), GetAccountId());
return;
}
if (_player->GetCritterGUID() == pet->GetGUID())
{
if (pet->GetTypeId() == TYPEID_UNIT && pet->ToCreature()->IsSummon())
pet->ToTempSummon()->UnSummon();
}
}
*/
void WorldSession::HandlePetAction(WorldPacket& recvData)
{
uint64 guid1;
uint32 data;
uint64 guid2;
recvData >> guid1; //pet guid
recvData >> data;
recvData >> guid2; //tag guid
uint32 spellid = UNIT_ACTION_BUTTON_ACTION(data);
uint8 flag = UNIT_ACTION_BUTTON_TYPE(data); //delete = 0x07 CastSpell = C1
// used also for charmed creature
Unit* pet= ObjectAccessor::GetUnit(*_player, guid1);
IC_LOG_INFO("network", "HandlePetAction: Pet %u - flag: %u, spellid: %u, target: %u.", uint32(GUID_LOPART(guid1)), uint32(flag), spellid, uint32(GUID_LOPART(guid2)));
if (!pet)
{
IC_LOG_ERROR("network", "HandlePetAction: Pet (GUID: %u) doesn't exist for player %s (GUID: %u)", uint32(GUID_LOPART(guid1)), GetPlayer()->GetName().c_str(), GUID_LOPART(GetPlayer()->GetGUID()));
return;
}
if (pet != GetPlayer()->GetFirstControlled())
{
IC_LOG_ERROR("network", "HandlePetAction: Pet (GUID: %u) does not belong to player %s (GUID: %u)", uint32(GUID_LOPART(guid1)), GetPlayer()->GetName().c_str(), GUID_LOPART(GetPlayer()->GetGUID()));
return;
}
if (!pet->IsAlive())
{
SpellInfo const* spell = (flag == ACT_ENABLED || flag == ACT_PASSIVE) ? sSpellMgr->GetSpellInfo(spellid) : NULL;
if (!spell)
return;
if (!(spell->Attributes & SPELL_ATTR0_CASTABLE_WHILE_DEAD))
return;
}
/// @todo allow control charmed player?
if (pet->GetTypeId() == TYPEID_PLAYER && !(flag == ACT_COMMAND && spellid == COMMAND_ATTACK))
return;
//If a pet is dismissed, m_Controlled will change
std::vector<Unit*> controlled;
for (Unit::ControlList::iterator itr = GetPlayer()->m_Controlled.begin(); itr != GetPlayer()->m_Controlled.end(); ++itr)
if ((*itr)->GetEntry() == pet->GetEntry() && (*itr)->IsAlive())
controlled.push_back(*itr);
CharmInfo* charmInfo = pet->GetCharmInfo();
if (!charmInfo)
{
IC_LOG_ERROR("network", "WorldSession::HandlePetAction(petGuid: " UI64FMTD ", tagGuid: " UI64FMTD ", spellId: %u, flag: %u): object (GUID: %u Entry: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!",
guid1, guid2, spellid, flag, pet->GetGUIDLow(), pet->GetEntry(), pet->GetTypeId());
return;
}
switch (flag)
{
case ACT_COMMAND: //0x07
switch (spellid)
{
case COMMAND_STAY: //flat=1792 //STAY
pet->StopMoving();
pet->GetMotionMaster()->Clear(false);
pet->GetMotionMaster()->MoveIdle();
charmInfo->SetCommandState(COMMAND_STAY);
charmInfo->SetIsCommandAttack(false);
charmInfo->SetIsAtStay(true);
charmInfo->SetIsCommandFollow(false);
charmInfo->SetIsFollowing(false);
charmInfo->SetIsReturning(false);
charmInfo->SaveStayPosition();
break;
case COMMAND_FOLLOW: //spellid=1792 //FOLLOW
//.........这里部分代码省略.........
示例12: HandlePetSetAction
void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
{
sLog.outDetail( "HandlePetSetAction. CMSG_PET_SET_ACTION" );
uint64 petguid;
uint8 count;
recv_data >> petguid;
Unit* pet = ObjectAccessor::GetUnit(*_player, petguid);
if(!pet || pet != _player->GetFirstControlled())
{
sLog.outError( "HandlePetSetAction: Unknown pet or pet owner." );
return;
}
CharmInfo *charmInfo = pet->GetCharmInfo();
if(!charmInfo)
{
sLog.outError("WorldSession::HandlePetSetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
return;
}
count = (recv_data.size() == 24) ? 2 : 1;
for (uint8 i = 0; i < count; ++i)
{
uint32 position;
uint32 data;
recv_data >> position;
recv_data >> data;
uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(data);
uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data);
sLog.outDetail( "Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X", _player->GetName(), position, spell_id, uint32(act_state));
//ignore invalid position
if(position >= MAX_UNIT_ACTION_BAR_INDEX)
return;
//if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add
if(!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_PASSIVE) && spell_id && !pet->HasSpell(spell_id)))
{
//sign for autocast
if(act_state == ACT_ENABLED && spell_id)
{
if(pet->GetTypeId() == TYPEID_UNIT && ((Creature*)pet)->isPet())
((Pet*)pet)->ToggleAutocast(spell_id, true);
else
charmInfo->ToggleCreatureAutocast(spell_id, true);
}
//sign for no/turn off autocast
else if(act_state == ACT_DISABLED && spell_id)
{
if(pet->GetTypeId() == TYPEID_UNIT && ((Creature*)pet)->isPet())
((Pet*)pet)->ToggleAutocast(spell_id, false);
else
charmInfo->ToggleCreatureAutocast(spell_id, false);
}
charmInfo->SetActionBar(position,spell_id,ActiveStates(act_state));
}
}
}
示例13: HandlePetSetAction
void WorldSession::HandlePetSetAction(WorldPacket& recv_data)
{
sLog.outDetail("HandlePetSetAction. CMSG_PET_SET_ACTION");
uint64 petguid;
uint32 position;
uint16 spell_id;
uint16 act_state;
uint8 count;
recv_data >> petguid;
Unit* pet = ObjectAccessor::GetUnit(*_player, petguid);
if (!pet || pet != _player->GetFirstControlled())
{
sLog.outError("HandlePetSetAction: Unknown pet or pet owner.");
return;
}
// pet can have action bar disabled
if (pet->IsPet() && ((Pet*)pet)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
return;
CharmInfo* charmInfo = pet->GetCharmInfo();
if (!charmInfo)
{
sLog.outError("WorldSession::HandlePetSetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
return;
}
count = (recv_data.size() == 24) ? 2 : 1;
for (uint8 i = 0; i < count; i++)
{
recv_data >> position;
recv_data >> spell_id;
recv_data >> act_state;
sLog.outDetail("Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X", _player->GetName(), position, spell_id, act_state);
//if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add
if (!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_CAST) && spell_id && !pet->HasSpell(spell_id)))
{
//sign for autocast
if (act_state == ACT_ENABLED && spell_id)
{
if (pet->GetTypeId() == TYPEID_UNIT && pet->IsPet())
((Pet*)pet)->ToggleAutocast(spell_id, true);
else
charmInfo->ToggleCreatureAutocast(spell_id, true);
}
//sign for no/turn off autocast
else if (act_state == ACT_DISABLED && spell_id)
{
if (pet->GetTypeId() == TYPEID_UNIT && pet->IsPet())
((Pet*)pet)->ToggleAutocast(spell_id, false);
else
charmInfo->ToggleCreatureAutocast(spell_id, false);
}
charmInfo->GetActionBarEntry(position)->Type = act_state;
charmInfo->GetActionBarEntry(position)->SpellOrAction = spell_id;
}
}
}
示例14: object
void WorldSession::HandlePetActionHelper(Unit* pet, uint64 guid1, uint32 spellid, uint16 flag, uint64 guid2)
{
CharmInfo* charmInfo = pet->GetCharmInfo();
if (!charmInfo)
{
sLog->outError("WorldSession::HandlePetAction(petGuid: " UI64FMTD ", tagGuid: " UI64FMTD ", spellId: %u, flag: %u): object (entry: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!",
guid1, guid2, spellid, flag, pet->GetGUIDLow(), pet->GetTypeId());
return;
}
switch (flag)
{
case ACT_COMMAND: //0x07
switch (spellid)
{
case COMMAND_STAY: //flat=1792 //STAY
pet->AttackStop();
pet->InterruptNonMeleeSpells(false);
pet->StopMoving();
pet->GetMotionMaster()->Clear(false);
pet->GetMotionMaster()->MoveIdle();
charmInfo->SetCommandState(COMMAND_STAY);
charmInfo->SetIsCommandAttack(false);
charmInfo->SetIsAtStay(true);
charmInfo->SetIsFollowing(false);
charmInfo->SetIsReturning(false);
charmInfo->SaveStayPosition();
break;
case COMMAND_FOLLOW: //spellid=1792 //FOLLOW
pet->AttackStop();
pet->InterruptNonMeleeSpells(false);
pet->GetMotionMaster()->MoveFollow(_player, PET_FOLLOW_DIST, pet->GetFollowAngle());
charmInfo->SetCommandState(COMMAND_FOLLOW);
charmInfo->SetIsCommandAttack(false);
charmInfo->SetIsAtStay(false);
charmInfo->SetIsReturning(true);
charmInfo->SetIsFollowing(false);
break;
case COMMAND_ATTACK: //spellid=1792 //ATTACK
{
// Can't attack if owner is pacified
if (_player->HasAuraType(SPELL_AURA_MOD_PACIFY))
{
//pet->SendPetCastFail(spellid, SPELL_FAILED_PACIFIED);
//TODO: Send proper error message to client
return;
}
// only place where pet can be player
Unit* TargetUnit = ObjectAccessor::GetUnit(*_player, guid2);
if (!TargetUnit)
return;
if (Unit* owner = pet->GetOwner())
if (!owner->IsValidAttackTarget(TargetUnit))
return;
// Not let attack through obstructions
if (sWorld->getBoolConfig(CONFIG_PET_LOS))
{
if (!pet->IsWithinLOSInMap(TargetUnit))
return;
}
pet->ClearUnitState(UNIT_STATE_FOLLOW);
// This is true if pet has no target or has target but targets differs.
if (pet->getVictim() != TargetUnit || (pet->getVictim() == TargetUnit && !pet->GetCharmInfo()->IsCommandAttack()))
{
if (pet->getVictim())
pet->AttackStop();
if (pet->GetTypeId() != TYPEID_PLAYER && pet->ToCreature()->IsAIEnabled)
{
charmInfo->SetIsCommandAttack(true);
charmInfo->SetIsAtStay(false);
charmInfo->SetIsFollowing(false);
charmInfo->SetIsReturning(false);
pet->ToCreature()->AI()->AttackStart(TargetUnit);
//10% chance to play special pet attack talk, else growl
if (pet->ToCreature()->isPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && urand(0, 100) < 10)
pet->SendPetTalk((uint32)PET_TALK_ATTACK);
else
{
// 90% chance for pet and 100% chance for charmed creature
pet->SendPetAIReaction(guid1);
}
}
else // charmed player
{
if (pet->getVictim() && pet->getVictim() != TargetUnit)
pet->AttackStop();
charmInfo->SetIsCommandAttack(true);
charmInfo->SetIsAtStay(false);
charmInfo->SetIsFollowing(false);
charmInfo->SetIsReturning(false);
//.........这里部分代码省略.........
示例15: DETAIL_LOG
void WorldSession::HandlePetSetAction(WorldPacket& recv_data)
{
DETAIL_LOG("HandlePetSetAction. CMSG_PET_SET_ACTION");
ObjectGuid petGuid;
uint8 count;
recv_data >> petGuid;
Creature* pet = _player->GetMap()->GetAnyTypeCreature(petGuid);
if (!pet || (pet != _player->GetPet() && pet != _player->GetCharm()))
{
sLog.outError("HandlePetSetAction: Unknown pet or pet owner.");
return;
}
CharmInfo* charmInfo = pet->GetCharmInfo();
if (!charmInfo)
{
sLog.outError("WorldSession::HandlePetSetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
return;
}
// pet can have action bar disabled
if (pet->IsPet() && charmInfo->HasState(CHARM_STATE_ACTION,ACTIONS_DISABLE))
return;
// if pet is chained - used first pet action bar
if (((Pet*)pet)->GetPetCounter())
return;
count = (recv_data.size() == 24) ? 2 : 1;
uint32 position[2];
uint32 data[2];
bool move_command = false;
for (uint8 i = 0; i < count; ++i)
{
recv_data >> position[i];
recv_data >> data[i];
uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]);
// ignore invalid position
if (position[i] >= MAX_UNIT_ACTION_BAR_INDEX)
return;
// in the normal case, command and reaction buttons can only be moved, not removed
// at moving count ==2, at removing count == 1
// ignore attempt to remove command|reaction buttons (not possible at normal case)
if (act_state == ACT_COMMAND || act_state == ACT_REACTION)
{
if (count == 1)
return;
move_command = true;
}
}
// check swap (at command->spell swap client remove spell first in another packet, so check only command move correctness)
if (move_command)
{
uint8 act_state_0 = UNIT_ACTION_BUTTON_TYPE(data[0]);
if (act_state_0 == ACT_COMMAND || act_state_0 == ACT_REACTION)
{
uint32 spell_id_0 = UNIT_ACTION_BUTTON_ACTION(data[0]);
UnitActionBarEntry const* actionEntry_1 = charmInfo->GetActionBarEntry(position[1]);
if (!actionEntry_1 || spell_id_0 != actionEntry_1->GetAction() ||
act_state_0 != actionEntry_1->GetType())
return;
}
uint8 act_state_1 = UNIT_ACTION_BUTTON_TYPE(data[1]);
if (act_state_1 == ACT_COMMAND || act_state_1 == ACT_REACTION)
{
uint32 spell_id_1 = UNIT_ACTION_BUTTON_ACTION(data[1]);
UnitActionBarEntry const* actionEntry_0 = charmInfo->GetActionBarEntry(position[0]);
if (!actionEntry_0 || spell_id_1 != actionEntry_0->GetAction() ||
act_state_1 != actionEntry_0->GetType())
return;
}
}
for (uint8 i = 0; i < count; ++i)
{
uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(data[i]);
uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]);
DETAIL_LOG("Player %s has changed pet spell action. Position: %u, Spell: %u, State: 0x%X", _player->GetName(), position[i], spell_id, uint32(act_state));
// if it's act for spell (en/disable/cast) and there is a spell given (0 = remove spell) which pet doesn't know, don't add
if ((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_PASSIVE) && spell_id && ((Pet*)pet)->HasSpell(spell_id))
{
// sign for autocast on/off
if (act_state == ACT_ENABLED || act_state == ACT_DISABLED)
{
bool enabled = act_state == ACT_ENABLED;
//.........这里部分代码省略.........