From f5502da3aeb709bed6713fc7e542f0bec86a7edb Mon Sep 17 00:00:00 2001 From: Phatcat Date: Tue, 14 Jun 2016 01:41:38 +0200 Subject: [PATCH] Polishing Pets (InitStatsForLevel, PetHandler) - InitStatsForLevel polish - PetHandler variable naming - SpellEffects: Move level calc further down, no need to do it if we return false --- src/game/Pet.cpp | 4 ++-- src/game/Pet.h | 2 +- src/game/PetAI.cpp | 2 +- src/game/PetHandler.cpp | 14 +++++++------- src/game/SpellEffects.cpp | 25 ++++++++----------------- 5 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index b396ba7ad46..5db6a42781e 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -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(); @@ -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 diff --git a/src/game/Pet.h b/src/game/Pet.h index 0dce45e30dc..9cf9b2c5747 100644 --- a/src/game/Pet.h +++ b/src/game/Pet.h @@ -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; } diff --git a/src/game/PetAI.cpp b/src/game/PetAI.cpp index 1d2cbd90e8f..5721a717d4d 100644 --- a/src/game/PetAI.cpp +++ b/src/game/PetAI.cpp @@ -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)) diff --git a/src/game/PetHandler.cpp b/src/game/PetHandler.cpp index 2c67a64aeef..ed3490d8e3b 100644 --- a/src/game/PetHandler.cpp +++ b/src/game/PetHandler.cpp @@ -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; } diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 9e82079af17..e8497071e94 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -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); @@ -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) @@ -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]; @@ -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(); @@ -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); @@ -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());