Skip to content

Commit

Permalink
Polishing Pets (InitStatsForLevel, PetHandler)
Browse files Browse the repository at this point in the history
- InitStatsForLevel polish
- PetHandler variable naming
- SpellEffects: Move level calc further down,
no need to do it if we return false
  • Loading branch information
Phatcat committed Jul 2, 2016
1 parent 5d5e6ed commit f5502da
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/game/Pet.cpp
Expand Up @@ -821,7 +821,7 @@ bool Pet::CreateBaseAtCreature(Creature* creature)
return true;
}

bool Pet::InitStatsForLevel(uint32 petlevel)
void Pet::InitStatsForLevel(uint32 petlevel)
{
Unit* owner = GetOwner();
CreatureInfo const* cInfo = GetCreatureInfo();
Expand Down Expand Up @@ -1040,7 +1040,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
// Remove rage bar from pets
SetMaxPower(POWER_RAGE, 0);

return true;
return;
}

bool Pet::HaveInDiet(ItemPrototype const* item) const
Expand Down
2 changes: 1 addition & 1 deletion src/game/Pet.h
Expand Up @@ -188,7 +188,7 @@ class MANGOS_DLL_SPEC Pet : public Creature
void GivePetXP(uint32 xp);
void GivePetLevel(uint32 level);
void SynchronizeLevelWithOwner();
bool InitStatsForLevel(uint32 level);
void InitStatsForLevel(uint32 level);
bool HaveInDiet(ItemPrototype const* item) const;
uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel);
void SetDuration(int32 dur) { m_duration = dur; }
Expand Down
2 changes: 1 addition & 1 deletion src/game/PetAI.cpp
Expand Up @@ -333,7 +333,7 @@ void PetAI::UpdateAI(const uint32 diff)
if (m_creature->IsStopped() && m_creature->IsNonMeleeSpellCasted(false))
{
if (m_creature->hasUnitState(UNIT_STAT_FOLLOW_MOVE))
m_creature->InterruptNonMeleeSpells(false);
m_creature->InterruptNonMeleeSpells(false);
}

else if (m_creature->CanReachWithMeleeAttack(victim))
Expand Down
14 changes: 7 additions & 7 deletions src/game/PetHandler.cpp
Expand Up @@ -109,34 +109,34 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)
}
case COMMAND_ATTACK: // spellid=1792 // ATTACK
{
Unit* TargetUnit = _player->GetMap()->GetUnit(targetGuid);
if (!TargetUnit)
Unit* targetUnit = _player->GetMap()->GetUnit(targetGuid);
if (!targetUnit)
return;

// not let attack friendly units.
if (GetPlayer()->IsFriendlyTo(TargetUnit))
if (GetPlayer()->IsFriendlyTo(targetUnit))
return;

((Pet*)pet)->SetIsRetreating();
((Pet*)pet)->SetSpellOpener();

// This is true if pet has no target or has target but targets differs.
if (pet->getVictim() != TargetUnit)
if (pet->getVictim() != targetUnit)
pet->AttackStop();

pet->GetMotionMaster()->Clear();

if (((Creature*)pet)->AI())
{
((Creature*)pet)->AI()->AttackStart(TargetUnit);
((Creature*)pet)->AI()->AttackStart(targetUnit);
// 10% chance to play special warlock 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->SendPetAIReaction();
}
else
pet->Attack(TargetUnit, true);
pet->Attack(targetUnit, true);

break;
}
Expand Down
25 changes: 8 additions & 17 deletions src/game/SpellEffects.cpp
Expand Up @@ -5767,11 +5767,12 @@ bool Spell::DoSummonGuardian(CreatureSummonPositions& list, SummonPropertiesEntr
if (m_duration > 0)
spawnCreature->SetDuration(m_duration);

CreatureInfo const* cInfo = spawnCreature->GetCreatureInfo();

// spawnCreature->SetName(""); // generated by client
spawnCreature->SetOwnerGuid(m_caster->GetObjectGuid());
spawnCreature->SetPowerType(POWER_MANA);
spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, spawnCreature->GetCreatureInfo()->NpcFlags);

spawnCreature->SetUInt32Value(UNIT_FIELD_FLAGS, cInfo->UnitFlags);
spawnCreature->SetUInt32Value(UNIT_NPC_FLAGS, cInfo->NpcFlags);
spawnCreature->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, 0);
spawnCreature->SetCreatorGuid(m_caster->GetObjectGuid());
spawnCreature->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
Expand Down Expand Up @@ -6617,12 +6618,7 @@ void Spell::EffectTameCreature(SpellEffectIndex /*eff_idx*/)
// level of hunter pet can't be less owner level at 5 levels
uint32 level = creatureTarget->getLevel() + 5 < plr->getLevel() ? (plr->getLevel() - 5) : creatureTarget->getLevel();

if (!pet->InitStatsForLevel(level))
{
sLog.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!", creatureTarget->GetEntry());
delete pet;
return;
}
pet->InitStatsForLevel(level);

pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
// this enables pet details window (Shift+P)
Expand Down Expand Up @@ -12039,7 +12035,7 @@ void Spell::EffectGravityPull(SpellEffectIndex eff_idx)

void Spell::EffectCreateTamedPet(SpellEffectIndex eff_idx)
{
if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER || unitTarget->getClass() != CLASS_HUNTER)
if (!unitTarget || unitTarget->getClass() != CLASS_HUNTER)
return;

uint32 creatureEntry = m_spellInfo->EffectMiscValue[eff_idx];
Expand All @@ -12051,7 +12047,7 @@ void Spell::EffectCreateTamedPet(SpellEffectIndex eff_idx)
return;
}

Pet* newTamedPet = new Pet;
Pet* newTamedPet = new Pet(HUNTER_PET);
CreatureCreatePos pos(unitTarget, unitTarget->GetOrientation());

Map* map = unitTarget->GetMap();
Expand All @@ -12063,15 +12059,12 @@ void Spell::EffectCreateTamedPet(SpellEffectIndex eff_idx)
}

newTamedPet->SetRespawnCoord(pos);
newTamedPet->setPetType(HUNTER_PET);

newTamedPet->SetOwnerGuid(unitTarget->GetObjectGuid());
newTamedPet->SetCreatorGuid(unitTarget->GetObjectGuid());
newTamedPet->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
newTamedPet->setFaction(unitTarget->getFaction());
newTamedPet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(nullptr)));
newTamedPet->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0);
newTamedPet->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000);
newTamedPet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);

newTamedPet->GetCharmInfo()->SetPetNumber(petNumber, true);
Expand All @@ -12087,12 +12080,10 @@ void Spell::EffectCreateTamedPet(SpellEffectIndex eff_idx)
newTamedPet->InitLevelupSpellsForLevel();
newTamedPet->InitTalentForLevel();

newTamedPet->RemoveByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
newTamedPet->SetByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_RENAMED);
newTamedPet->SetByteFlag(UNIT_FIELD_BYTES_2, 2, UNIT_CAN_BE_ABANDONED);

newTamedPet->AIM_Initialize();
newTamedPet->SetHealth(newTamedPet->GetMaxHealth());
newTamedPet->SetPower(POWER_MANA, newTamedPet->GetMaxPower(POWER_MANA));

float x, y, z;
unitTarget->GetClosePoint(x, y, z, newTamedPet->GetObjectBoundingRadius());
Expand Down

0 comments on commit f5502da

Please sign in to comment.