[11463] Cleanup codestyle in PetHandler.cpp

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Den 2011-05-10 13:10:01 +04:00 committed by VladimirMangos
parent 31c34a940d
commit 6e1988bfc7
2 changed files with 111 additions and 109 deletions

View file

@ -28,7 +28,7 @@
#include "Util.h" #include "Util.h"
#include "Pet.h" #include "Pet.h"
void WorldSession::HandlePetAction( WorldPacket & recv_data ) void WorldSession::HandlePetAction(WorldPacket& recv_data)
{ {
ObjectGuid petGuid; ObjectGuid petGuid;
uint32 data; uint32 data;
@ -38,7 +38,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
recv_data >> targetGuid; recv_data >> targetGuid;
uint32 spellid = UNIT_ACTION_BUTTON_ACTION(data); uint32 spellid = UNIT_ACTION_BUTTON_ACTION(data);
uint8 flag = UNIT_ACTION_BUTTON_TYPE(data); //delete = 0x07 CastSpell = C1 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()); DETAIL_LOG("HandlePetAction: %s flag is %u, spellid is %u, target %s.", petGuid.GetString().c_str(), uint32(flag), spellid, targetGuid.GetString().c_str());
@ -68,48 +68,48 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
else if (((Creature*)pet)->IsPet()) else if (((Creature*)pet)->IsPet())
{ {
// pet can have action bar disabled // pet can have action bar disabled
if(((Pet*)pet)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS) if (((Pet*)pet)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
return; return;
} }
CharmInfo *charmInfo = pet->GetCharmInfo(); CharmInfo* charmInfo = pet->GetCharmInfo();
if(!charmInfo) 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()); sLog.outError("WorldSession::HandlePetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
return; return;
} }
switch(flag) switch (flag)
{ {
case ACT_COMMAND: //0x07 case ACT_COMMAND: // 0x07
switch(spellid) switch (spellid)
{ {
case COMMAND_STAY: //flat=1792 //STAY case COMMAND_STAY: // flat=1792 //STAY
pet->StopMoving(); pet->StopMoving();
pet->GetMotionMaster()->Clear(false); pet->GetMotionMaster()->Clear(false);
pet->GetMotionMaster()->MoveIdle(); pet->GetMotionMaster()->MoveIdle();
charmInfo->SetCommandState( COMMAND_STAY ); charmInfo->SetCommandState(COMMAND_STAY);
break; break;
case COMMAND_FOLLOW: //spellid=1792 //FOLLOW case COMMAND_FOLLOW: // spellid=1792 //FOLLOW
pet->AttackStop(); pet->AttackStop();
pet->GetMotionMaster()->MoveFollow(_player,PET_FOLLOW_DIST,PET_FOLLOW_ANGLE); pet->GetMotionMaster()->MoveFollow(_player, PET_FOLLOW_DIST,PET_FOLLOW_ANGLE);
charmInfo->SetCommandState( COMMAND_FOLLOW ); charmInfo->SetCommandState(COMMAND_FOLLOW);
break; break;
case COMMAND_ATTACK: //spellid=1792 //ATTACK case COMMAND_ATTACK: // spellid=1792 // ATTACK
{ {
Unit *TargetUnit = _player->GetMap()->GetUnit(targetGuid); Unit* TargetUnit = _player->GetMap()->GetUnit(targetGuid);
if(!TargetUnit) if (!TargetUnit)
return; return;
// not let attack friendly units. // not let attack friendly units.
if(GetPlayer()->IsFriendlyTo(TargetUnit)) if (GetPlayer()->IsFriendlyTo(TargetUnit))
return; return;
// Not let attack through obstructions // Not let attack through obstructions
if(!pet->IsWithinLOSInMap(TargetUnit)) if (!pet->IsWithinLOSInMap(TargetUnit))
return; return;
// This is true if pet has no target or has target but targets differs. // This is true if pet has no target or has target but targets differs.
if(pet->getVictim() != TargetUnit) if (pet->getVictim() != TargetUnit)
{ {
if (pet->getVictim()) if (pet->getVictim())
pet->AttackStop(); pet->AttackStop();
@ -127,7 +127,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
((Creature*)pet)->AI()->AttackStart(TargetUnit); ((Creature*)pet)->AI()->AttackStart(TargetUnit);
// 10% chance to play special pet attack talk, else growl // 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)) if (((Creature*)pet)->IsPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && roll_chance_i(10))
pet->SendPetTalk((uint32)PET_TALK_ATTACK); pet->SendPetTalk((uint32)PET_TALK_ATTACK);
else else
{ {
@ -139,13 +139,13 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
break; break;
} }
case COMMAND_ABANDON: // abandon (hunter pet) or dismiss (summoned pet) case COMMAND_ABANDON: // abandon (hunter pet) or dismiss (summoned pet)
if(((Creature*)pet)->IsPet()) if (((Creature*)pet)->IsPet())
{ {
Pet* p = (Pet*)pet; Pet* p = (Pet*)pet;
if(p->getPetType() == HUNTER_PET) if (p->getPetType() == HUNTER_PET)
p->Unsummon(PET_SAVE_AS_DELETED, _player); p->Unsummon(PET_SAVE_AS_DELETED, _player);
else else
//dismissing a summoned pet is like killing them (this prevents returning a soulshard...) // dismissing a summoned pet is like killing them (this prevents returning a soulshard...)
p->SetDeathState(CORPSE); p->SetDeathState(CORPSE);
} }
else // charmed else // charmed
@ -156,12 +156,12 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
} }
break; break;
case ACT_REACTION: // 0x6 case ACT_REACTION: // 0x6
switch(spellid) switch (spellid)
{ {
case REACT_PASSIVE: //passive case REACT_PASSIVE: // passive
case REACT_DEFENSIVE: //recovery case REACT_DEFENSIVE: // recovery
case REACT_AGGRESSIVE: //activete case REACT_AGGRESSIVE: // activete
charmInfo->SetReactState( ReactStates(spellid) ); charmInfo->SetReactState(ReactStates(spellid));
break; break;
} }
break; break;
@ -174,7 +174,7 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
unit_target = _player->GetMap()->GetUnit(targetGuid); unit_target = _player->GetMap()->GetUnit(targetGuid);
// do not cast unknown spells // do not cast unknown spells
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid ); SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
if (!spellInfo) if (!spellInfo)
{ {
sLog.outError("WORLD: unknown PET spell id %i", spellid); sLog.outError("WORLD: unknown PET spell id %i", spellid);
@ -184,59 +184,59 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
if (pet->GetCharmInfo() && pet->GetCharmInfo()->GetGlobalCooldownMgr().HasGlobalCooldown(spellInfo)) if (pet->GetCharmInfo() && pet->GetCharmInfo()->GetGlobalCooldownMgr().HasGlobalCooldown(spellInfo))
return; return;
for(int i = 0; i < MAX_EFFECT_INDEX;++i) for (int i = 0; i < MAX_EFFECT_INDEX; ++i)
{ {
if(spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_INSTANT || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_CHANNELED) if (spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_INSTANT || spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_ENEMY_IN_AREA_CHANNELED)
return; return;
} }
// do not cast not learned spells // do not cast not learned spells
if(!pet->HasSpell(spellid) || IsPassiveSpell(spellInfo)) if (!pet->HasSpell(spellid) || IsPassiveSpell(spellInfo))
return; return;
pet->clearUnitState(UNIT_STAT_MOVING); pet->clearUnitState(UNIT_STAT_MOVING);
Spell *spell = new Spell(pet, spellInfo, false); Spell* spell = new Spell(pet, spellInfo, false);
SpellCastResult result = spell->CheckPetCast(unit_target); SpellCastResult result = spell->CheckPetCast(unit_target);
//auto turn to target unless possessed // auto turn to target unless possessed
if(result == SPELL_FAILED_UNIT_NOT_INFRONT && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS)) if (result == SPELL_FAILED_UNIT_NOT_INFRONT && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS))
{ {
if(unit_target) if (unit_target)
{ {
pet->SetInFront(unit_target); pet->SetInFront(unit_target);
if (unit_target->GetTypeId() == TYPEID_PLAYER) if (unit_target->GetTypeId() == TYPEID_PLAYER)
pet->SendCreateUpdateToPlayer( (Player*)unit_target ); pet->SendCreateUpdateToPlayer( (Player*)unit_target );
} }
else if(Unit *unit_target2 = spell->m_targets.getUnitTarget()) else if (Unit* unit_target2 = spell->m_targets.getUnitTarget())
{ {
pet->SetInFront(unit_target2); pet->SetInFront(unit_target2);
if (unit_target2->GetTypeId() == TYPEID_PLAYER) if (unit_target2->GetTypeId() == TYPEID_PLAYER)
pet->SendCreateUpdateToPlayer( (Player*)unit_target2 ); pet->SendCreateUpdateToPlayer((Player*)unit_target2);
} }
if (Unit* powner = pet->GetCharmerOrOwner()) if (Unit* powner = pet->GetCharmerOrOwner())
if(powner->GetTypeId() == TYPEID_PLAYER) if (powner->GetTypeId() == TYPEID_PLAYER)
pet->SendCreateUpdateToPlayer((Player*)powner); pet->SendCreateUpdateToPlayer((Player*)powner);
result = SPELL_CAST_OK; result = SPELL_CAST_OK;
} }
if(result == SPELL_CAST_OK) if (result == SPELL_CAST_OK)
{ {
((Creature*)pet)->AddCreatureSpellCooldown(spellid); ((Creature*)pet)->AddCreatureSpellCooldown(spellid);
unit_target = spell->m_targets.getUnitTarget(); unit_target = spell->m_targets.getUnitTarget();
//10% chance to play special pet attack talk, else growl // 10% chance to play special pet attack talk, else growl
//actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell // actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell
if(((Creature*)pet)->IsPet() && (((Pet*)pet)->getPetType() == SUMMON_PET) && (pet != unit_target) && (urand(0, 100) < 10)) if (((Creature*)pet)->IsPet() && (((Pet*)pet)->getPetType() == SUMMON_PET) && (pet != unit_target) && (urand(0, 100) < 10))
pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL); pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL);
else else
{ {
pet->SendPetAIReaction(); pet->SendPetAIReaction();
} }
if( unit_target && !GetPlayer()->IsFriendlyTo(unit_target) && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS)) if (unit_target && !GetPlayer()->IsFriendlyTo(unit_target) && !pet->HasAuraType(SPELL_AURA_MOD_POSSESS))
{ {
// This is true if pet has no target or has target but targets differs. // This is true if pet has no target or has target but targets differs.
if (pet->getVictim() != unit_target) if (pet->getVictim() != unit_target)
@ -253,8 +253,8 @@ void WorldSession::HandlePetAction( WorldPacket & recv_data )
} }
else else
{ {
if(pet->HasAuraType(SPELL_AURA_MOD_POSSESS)) if (pet->HasAuraType(SPELL_AURA_MOD_POSSESS))
Spell::SendCastResult(GetPlayer(),spellInfo,0,result); Spell::SendCastResult(GetPlayer(), spellInfo, 0, result);
else else
pet->SendPetCastFail(spellid, result); pet->SendPetCastFail(spellid, result);
@ -297,9 +297,9 @@ void WorldSession::HandlePetStopAttack(WorldPacket& recv_data)
pet->AttackStop(); pet->AttackStop();
} }
void WorldSession::HandlePetNameQueryOpcode( WorldPacket & recv_data ) void WorldSession::HandlePetNameQueryOpcode(WorldPacket& recv_data)
{ {
DETAIL_LOG( "HandlePetNameQuery. CMSG_PET_NAME_QUERY" ); DETAIL_LOG("HandlePetNameQuery. CMSG_PET_NAME_QUERY");
uint32 petnumber; uint32 petnumber;
uint64 petguid; uint64 petguid;
@ -307,13 +307,13 @@ void WorldSession::HandlePetNameQueryOpcode( WorldPacket & recv_data )
recv_data >> petnumber; recv_data >> petnumber;
recv_data >> petguid; recv_data >> petguid;
SendPetNameQuery(petguid,petnumber); SendPetNameQuery(petguid, petnumber);
} }
void WorldSession::SendPetNameQuery( uint64 petguid, uint32 petnumber) void WorldSession::SendPetNameQuery(uint64 petguid, uint32 petnumber)
{ {
Creature* pet = _player->GetMap()->GetAnyTypeCreature(petguid); Creature* pet = _player->GetMap()->GetAnyTypeCreature(petguid);
if(!pet || !pet->GetCharmInfo() || pet->GetCharmInfo()->GetPetNumber() != petnumber) if (!pet || !pet->GetCharmInfo() || pet->GetCharmInfo()->GetPetNumber() != petnumber)
{ {
WorldPacket data(SMSG_PET_NAME_QUERY_RESPONSE, (4+1+4+1)); WorldPacket data(SMSG_PET_NAME_QUERY_RESPONSE, (4+1+4+1));
data << uint32(petnumber); data << uint32(petnumber);
@ -331,10 +331,10 @@ void WorldSession::SendPetNameQuery( uint64 petguid, uint32 petnumber)
data << name.c_str(); data << name.c_str();
data << uint32(pet->GetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP)); data << uint32(pet->GetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP));
if( pet->IsPet() && ((Pet*)pet)->GetDeclinedNames() ) if (pet->IsPet() && ((Pet*)pet)->GetDeclinedNames())
{ {
data << uint8(1); data << uint8(1);
for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) for (int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
data << ((Pet*)pet)->GetDeclinedNames()->name[i]; data << ((Pet*)pet)->GetDeclinedNames()->name[i];
} }
else else
@ -343,9 +343,9 @@ void WorldSession::SendPetNameQuery( uint64 petguid, uint32 petnumber)
_player->GetSession()->SendPacket(&data); _player->GetSession()->SendPacket(&data);
} }
void WorldSession::HandlePetSetAction( WorldPacket & recv_data ) void WorldSession::HandlePetSetAction(WorldPacket& recv_data)
{ {
DETAIL_LOG( "HandlePetSetAction. CMSG_PET_SET_ACTION" ); DETAIL_LOG("HandlePetSetAction. CMSG_PET_SET_ACTION");
uint64 petguid; uint64 petguid;
uint8 count; uint8 count;
@ -354,18 +354,18 @@ void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
Creature* pet = _player->GetMap()->GetAnyTypeCreature(petguid); Creature* pet = _player->GetMap()->GetAnyTypeCreature(petguid);
if(!pet || (pet != _player->GetPet() && pet != _player->GetCharm())) if (!pet || (pet != _player->GetPet() && pet != _player->GetCharm()))
{ {
sLog.outError( "HandlePetSetAction: Unknown pet or pet owner." ); sLog.outError("HandlePetSetAction: Unknown pet or pet owner.");
return; return;
} }
// pet can have action bar disabled // pet can have action bar disabled
if(pet->IsPet() && ((Pet*)pet)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS) if (pet->IsPet() && ((Pet*)pet)->GetModeFlags() & PET_MODE_DISABLE_ACTIONS)
return; return;
CharmInfo *charmInfo = pet->GetCharmInfo(); CharmInfo* charmInfo = pet->GetCharmInfo();
if(!charmInfo) 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()); sLog.outError("WorldSession::HandlePetSetAction: object (GUID: %u TypeId: %u) is considered pet-like but doesn't have a charminfo!", pet->GetGUIDLow(), pet->GetTypeId());
return; return;
@ -377,15 +377,15 @@ void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
uint32 data[2]; uint32 data[2];
bool move_command = false; bool move_command = false;
for(uint8 i = 0; i < count; ++i) for (uint8 i = 0; i < count; ++i)
{ {
recv_data >> position[i]; recv_data >> position[i];
recv_data >> data[i]; recv_data >> data[i];
uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]); uint8 act_state = UNIT_ACTION_BUTTON_TYPE(data[i]);
//ignore invalid position // ignore invalid position
if(position[i] >= MAX_UNIT_ACTION_BAR_INDEX) if (position[i] >= MAX_UNIT_ACTION_BAR_INDEX)
return; return;
// in the normal case, command and reaction buttons can only be moved, not removed // in the normal case, command and reaction buttons can only be moved, not removed
@ -404,7 +404,7 @@ void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
if (move_command) if (move_command)
{ {
uint8 act_state_0 = UNIT_ACTION_BUTTON_TYPE(data[0]); uint8 act_state_0 = UNIT_ACTION_BUTTON_TYPE(data[0]);
if(act_state_0 == ACT_COMMAND || act_state_0 == ACT_REACTION) if (act_state_0 == ACT_COMMAND || act_state_0 == ACT_REACTION)
{ {
uint32 spell_id_0 = UNIT_ACTION_BUTTON_ACTION(data[0]); uint32 spell_id_0 = UNIT_ACTION_BUTTON_ACTION(data[0]);
UnitActionBarEntry const* actionEntry_1 = charmInfo->GetActionBarEntry(position[1]); UnitActionBarEntry const* actionEntry_1 = charmInfo->GetActionBarEntry(position[1]);
@ -414,7 +414,7 @@ void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
} }
uint8 act_state_1 = UNIT_ACTION_BUTTON_TYPE(data[1]); uint8 act_state_1 = UNIT_ACTION_BUTTON_TYPE(data[1]);
if(act_state_1 == ACT_COMMAND || act_state_1 == ACT_REACTION) if (act_state_1 == ACT_COMMAND || act_state_1 == ACT_REACTION)
{ {
uint32 spell_id_1 = UNIT_ACTION_BUTTON_ACTION(data[1]); uint32 spell_id_1 = UNIT_ACTION_BUTTON_ACTION(data[1]);
UnitActionBarEntry const* actionEntry_0 = charmInfo->GetActionBarEntry(position[0]); UnitActionBarEntry const* actionEntry_0 = charmInfo->GetActionBarEntry(position[0]);
@ -424,41 +424,41 @@ void WorldSession::HandlePetSetAction( WorldPacket & recv_data )
} }
} }
for(uint8 i = 0; i < count; ++i) for (uint8 i = 0; i < count; ++i)
{ {
uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(data[i]); uint32 spell_id = UNIT_ACTION_BUTTON_ACTION(data[i]);
uint8 act_state = UNIT_ACTION_BUTTON_TYPE(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)); 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 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))) if (!((act_state == ACT_ENABLED || act_state == ACT_DISABLED || act_state == ACT_PASSIVE) && spell_id && !pet->HasSpell(spell_id)))
{ {
//sign for autocast // sign for autocast
if(act_state == ACT_ENABLED && spell_id) if (act_state == ACT_ENABLED && spell_id)
{ {
if(pet->isCharmed()) if (pet->isCharmed())
charmInfo->ToggleCreatureAutocast(spell_id, true); charmInfo->ToggleCreatureAutocast(spell_id, true);
else else
((Pet*)pet)->ToggleAutocast(spell_id, true); ((Pet*)pet)->ToggleAutocast(spell_id, true);
} }
//sign for no/turn off autocast // sign for no/turn off autocast
else if(act_state == ACT_DISABLED && spell_id) else if (act_state == ACT_DISABLED && spell_id)
{ {
if(pet->isCharmed()) if (pet->isCharmed())
charmInfo->ToggleCreatureAutocast(spell_id, false); charmInfo->ToggleCreatureAutocast(spell_id, false);
else else
((Pet*)pet)->ToggleAutocast(spell_id, false); ((Pet*)pet)->ToggleAutocast(spell_id, false);
} }
charmInfo->SetActionBar(position[i],spell_id,ActiveStates(act_state)); charmInfo->SetActionBar(position[i], spell_id, ActiveStates(act_state));
} }
} }
} }
void WorldSession::HandlePetRename( WorldPacket & recv_data ) void WorldSession::HandlePetRename(WorldPacket& recv_data)
{ {
DETAIL_LOG( "HandlePetRename. CMSG_PET_RENAME" ); DETAIL_LOG("HandlePetRename. CMSG_PET_RENAME");
uint64 petguid; uint64 petguid;
uint8 isdeclined; uint8 isdeclined;
@ -472,19 +472,19 @@ void WorldSession::HandlePetRename( WorldPacket & recv_data )
Pet* pet = _player->GetMap()->GetPet(petguid); Pet* pet = _player->GetMap()->GetPet(petguid);
// check it! // check it!
if( !pet || pet->getPetType() != HUNTER_PET || if (!pet || pet->getPetType() != HUNTER_PET ||
!pet->HasByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED) || !pet->HasByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED) ||
pet->GetOwnerGuid() != _player->GetObjectGuid() || !pet->GetCharmInfo() ) pet->GetOwnerGuid() != _player->GetObjectGuid() || !pet->GetCharmInfo())
return; return;
PetNameInvalidReason res = ObjectMgr::CheckPetName(name); PetNameInvalidReason res = ObjectMgr::CheckPetName(name);
if(res != PET_NAME_SUCCESS) if (res != PET_NAME_SUCCESS)
{ {
SendPetNameInvalid(res, name, NULL); SendPetNameInvalid(res, name, NULL);
return; return;
} }
if(sObjectMgr.IsReservedName(name)) if (sObjectMgr.IsReservedName(name))
{ {
SendPetNameInvalid(PET_NAME_RESERVED, name, NULL); SendPetNameInvalid(PET_NAME_RESERVED, name, NULL);
return; return;
@ -492,21 +492,21 @@ void WorldSession::HandlePetRename( WorldPacket & recv_data )
pet->SetName(name); pet->SetName(name);
if(_player->GetGroup()) if (_player->GetGroup())
_player->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_NAME); _player->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_NAME);
pet->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED); pet->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
if(isdeclined) if (isdeclined)
{ {
for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) for (int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
{ {
recv_data >> declinedname.name[i]; recv_data >> declinedname.name[i];
} }
std::wstring wname; std::wstring wname;
Utf8toWStr(name, wname); Utf8toWStr(name, wname);
if(!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname,0),declinedname)) if (!ObjectMgr::CheckDeclinedNames(GetMainPartOfName(wname, 0), declinedname))
{ {
SendPetNameInvalid(PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME, name, &declinedname); SendPetNameInvalid(PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME, name, &declinedname);
return; return;
@ -514,9 +514,9 @@ void WorldSession::HandlePetRename( WorldPacket & recv_data )
} }
CharacterDatabase.BeginTransaction(); CharacterDatabase.BeginTransaction();
if(isdeclined) if (isdeclined)
{ {
for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i) for (int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
CharacterDatabase.escape_string(declinedname.name[i]); CharacterDatabase.escape_string(declinedname.name[i]);
CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'", _player->GetGUIDLow(), pet->GetCharmInfo()->GetPetNumber()); CharacterDatabase.PExecute("DELETE FROM character_pet_declinedname WHERE owner = '%u' AND id = '%u'", _player->GetGUIDLow(), pet->GetCharmInfo()->GetPetNumber());
CharacterDatabase.PExecute("INSERT INTO character_pet_declinedname (id, owner, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%u','%s','%s','%s','%s','%s')", CharacterDatabase.PExecute("INSERT INTO character_pet_declinedname (id, owner, genitive, dative, accusative, instrumental, prepositional) VALUES ('%u','%u','%s','%s','%s','%s','%s')",
@ -530,10 +530,10 @@ void WorldSession::HandlePetRename( WorldPacket & recv_data )
pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL)));
} }
void WorldSession::HandlePetAbandon( WorldPacket & recv_data ) void WorldSession::HandlePetAbandon(WorldPacket& recv_data)
{ {
ObjectGuid guid; ObjectGuid guid;
recv_data >> guid; //pet guid recv_data >> guid; // pet guid
DETAIL_LOG("HandlePetAbandon. CMSG_PET_ABANDON pet guid is %s", guid.GetString().c_str()); DETAIL_LOG("HandlePetAbandon. CMSG_PET_ABANDON pet guid is %s", guid.GetString().c_str());
@ -548,7 +548,7 @@ void WorldSession::HandlePetAbandon( WorldPacket & recv_data )
if (pet->GetObjectGuid() == _player->GetPetGuid()) if (pet->GetObjectGuid() == _player->GetPetGuid())
{ {
uint32 feelty = pet->GetPower(POWER_HAPPINESS); uint32 feelty = pet->GetPower(POWER_HAPPINESS);
pet->SetPower(POWER_HAPPINESS ,(feelty-50000) > 0 ?(feelty-50000) : 0); pet->SetPower(POWER_HAPPINESS, (feelty - 50000) > 0 ? (feelty - 50000) : 0);
} }
((Pet*)pet)->Unsummon(PET_SAVE_AS_DELETED, _player); ((Pet*)pet)->Unsummon(PET_SAVE_AS_DELETED, _player);
@ -563,6 +563,7 @@ void WorldSession::HandlePetAbandon( WorldPacket & recv_data )
void WorldSession::HandlePetUnlearnOpcode(WorldPacket& recvPacket) void WorldSession::HandlePetUnlearnOpcode(WorldPacket& recvPacket)
{ {
DETAIL_LOG("CMSG_PET_UNLEARN"); DETAIL_LOG("CMSG_PET_UNLEARN");
ObjectGuid guid; ObjectGuid guid;
recvPacket >> guid; // Pet guid recvPacket >> guid; // Pet guid
@ -577,7 +578,7 @@ void WorldSession::HandlePetUnlearnOpcode(WorldPacket& recvPacket)
if (pet->getPetType() != HUNTER_PET || pet->m_usedTalentCount == 0) if (pet->getPetType() != HUNTER_PET || pet->m_usedTalentCount == 0)
return; return;
CharmInfo *charmInfo = pet->GetCharmInfo(); CharmInfo* charmInfo = pet->GetCharmInfo();
if (!charmInfo) if (!charmInfo)
{ {
sLog.outError("WorldSession::HandlePetUnlearnOpcode: %s is considered pet-like but doesn't have a charminfo!", pet->GetGuidStr().c_str()); sLog.outError("WorldSession::HandlePetUnlearnOpcode: %s is considered pet-like but doesn't have a charminfo!", pet->GetGuidStr().c_str());
@ -587,12 +588,13 @@ void WorldSession::HandlePetUnlearnOpcode(WorldPacket& recvPacket)
_player->SendTalentsInfoData(true); _player->SendTalentsInfoData(true);
} }
void WorldSession::HandlePetSpellAutocastOpcode( WorldPacket& recvPacket ) void WorldSession::HandlePetSpellAutocastOpcode(WorldPacket& recvPacket)
{ {
DETAIL_LOG("CMSG_PET_SPELL_AUTOCAST"); DETAIL_LOG("CMSG_PET_SPELL_AUTOCAST");
ObjectGuid guid; ObjectGuid guid;
uint32 spellid; uint32 spellid;
uint8 state; //1 for on, 0 for off uint8 state; // 1 for on, 0 for off
recvPacket >> guid >> spellid >> state; recvPacket >> guid >> spellid >> state;
Creature* pet = _player->GetMap()->GetAnyTypeCreature(guid); Creature* pet = _player->GetMap()->GetAnyTypeCreature(guid);
@ -606,7 +608,7 @@ void WorldSession::HandlePetSpellAutocastOpcode( WorldPacket& recvPacket )
if (!pet->HasSpell(spellid) || IsPassiveSpell(spellid)) if (!pet->HasSpell(spellid) || IsPassiveSpell(spellid))
return; return;
CharmInfo *charmInfo = pet->GetCharmInfo(); CharmInfo* charmInfo = pet->GetCharmInfo();
if (!charmInfo) if (!charmInfo)
{ {
sLog.outError("WorldSession::HandlePetSpellAutocastOpcod: %s is considered pet-like but doesn't have a charminfo!", guid.GetString().c_str()); sLog.outError("WorldSession::HandlePetSpellAutocastOpcod: %s is considered pet-like but doesn't have a charminfo!", guid.GetString().c_str());
@ -614,15 +616,15 @@ void WorldSession::HandlePetSpellAutocastOpcode( WorldPacket& recvPacket )
} }
if (pet->isCharmed()) if (pet->isCharmed())
//state can be used as boolean // state can be used as boolean
pet->GetCharmInfo()->ToggleCreatureAutocast(spellid, state); pet->GetCharmInfo()->ToggleCreatureAutocast(spellid, state);
else else
((Pet*)pet)->ToggleAutocast(spellid, state); ((Pet*)pet)->ToggleAutocast(spellid, state);
charmInfo->SetSpellAutocast(spellid,state); charmInfo->SetSpellAutocast(spellid, state);
} }
void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket ) void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket)
{ {
DETAIL_LOG("WORLD: CMSG_PET_CAST_SPELL"); DETAIL_LOG("WORLD: CMSG_PET_CAST_SPELL");
@ -643,7 +645,7 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
return; return;
} }
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellid); SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
if (!spellInfo) if (!spellInfo)
{ {
sLog.outError("WORLD: unknown PET spell id %i", spellid); sLog.outError("WORLD: unknown PET spell id %i", spellid);
@ -664,7 +666,7 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
pet->clearUnitState(UNIT_STAT_MOVING); pet->clearUnitState(UNIT_STAT_MOVING);
Spell *spell = new Spell(pet, spellInfo, false); Spell* spell = new Spell(pet, spellInfo, false);
spell->m_cast_count = cast_count; // probably pending spell cast spell->m_cast_count = cast_count; // probably pending spell cast
spell->m_targets = targets; spell->m_targets = targets;
@ -674,9 +676,9 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
pet->AddCreatureSpellCooldown(spellid); pet->AddCreatureSpellCooldown(spellid);
if (pet->IsPet()) if (pet->IsPet())
{ {
//10% chance to play special pet attack talk, else growl // 10% chance to play special pet attack talk, else growl
//actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell // actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell
if(((Pet*)pet)->getPetType() == SUMMON_PET && (urand(0, 100) < 10)) if (((Pet*)pet)->getPetType() == SUMMON_PET && (urand(0, 100) < 10))
pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL); pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL);
else else
pet->SendPetAIReaction(); pet->SendPetAIReaction();
@ -695,15 +697,15 @@ void WorldSession::HandlePetCastSpellOpcode( WorldPacket& recvPacket )
} }
} }
void WorldSession::SendPetNameInvalid(uint32 error, const std::string& name, DeclinedName *declinedName) void WorldSession::SendPetNameInvalid(uint32 error, const std::string& name, DeclinedName* declinedName)
{ {
WorldPacket data(SMSG_PET_NAME_INVALID, 4 + name.size() + 1 + 1); WorldPacket data(SMSG_PET_NAME_INVALID, 4 + name.size() + 1 + 1);
data << uint32(error); data << uint32(error);
data << name; data << name;
if(declinedName) if (declinedName)
{ {
data << uint8(1); data << uint8(1);
for(uint32 i = 0; i < MAX_DECLINED_NAME_CASES; ++i) for (uint32 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
data << declinedName->name[i]; data << declinedName->name[i];
} }
else else
@ -711,7 +713,7 @@ void WorldSession::SendPetNameInvalid(uint32 error, const std::string& name, Dec
SendPacket(&data); SendPacket(&data);
} }
void WorldSession::HandlePetLearnTalent( WorldPacket & recv_data ) void WorldSession::HandlePetLearnTalent(WorldPacket& recv_data)
{ {
DEBUG_LOG("WORLD: CMSG_PET_LEARN_TALENT"); DEBUG_LOG("WORLD: CMSG_PET_LEARN_TALENT");
@ -723,7 +725,7 @@ void WorldSession::HandlePetLearnTalent( WorldPacket & recv_data )
_player->SendTalentsInfoData(true); _player->SendTalentsInfoData(true);
} }
void WorldSession::HandleLearnPreviewTalentsPet( WorldPacket & recv_data ) void WorldSession::HandleLearnPreviewTalentsPet(WorldPacket& recv_data)
{ {
DEBUG_LOG("CMSG_LEARN_PREVIEW_TALENTS_PET"); DEBUG_LOG("CMSG_LEARN_PREVIEW_TALENTS_PET");
@ -735,7 +737,7 @@ void WorldSession::HandleLearnPreviewTalentsPet( WorldPacket & recv_data )
uint32 talentId, talentRank; uint32 talentId, talentRank;
for(uint32 i = 0; i < talentsCount; ++i) for (uint32 i = 0; i < talentsCount; ++i)
{ {
recv_data >> talentId >> talentRank; recv_data >> talentId >> talentRank;

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11462" #define REVISION_NR "11463"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__