diff --git a/src/game/Objects/Pet.cpp b/src/game/Objects/Pet.cpp index 308d3a6e2bd..ad897d85b2f 100644 --- a/src/game/Objects/Pet.cpp +++ b/src/game/Objects/Pet.cpp @@ -1275,11 +1275,14 @@ bool Pet::CreateBaseAtCreature(Creature* creature) return false; } + InitializeDefaultName(); + if (cinfo->type == CREATURE_TYPE_CRITTER) { setPetType(MINI_PET); return true; } + SetDisplayId(creature->GetDisplayId()); SetNativeDisplayId(creature->GetNativeDisplayId()); SetMaxPower(POWER_HAPPINESS, GetCreatePowers(POWER_HAPPINESS)); @@ -1290,11 +1293,6 @@ bool Pet::CreateBaseAtCreature(Creature* creature) SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, sObjectMgr.GetXPForPetLevel(creature->GetLevel())); SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE); - if (CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->pet_family)) - SetName(cFamily->Name[sWorld.GetDefaultDbcLocale()]); - else - SetName(creature->GetNameForLocaleIdx(sObjectMgr.GetDBCLocaleIndex())); - m_loyaltyPoints = 1000; if (cinfo->type == CREATURE_TYPE_BEAST) { @@ -2257,6 +2255,36 @@ bool Pet::IsPermanentPetFor(Player* owner) const } } +void Pet::InitializeDefaultName() +{ + switch (getPetType()) + { + case SUMMON_PET: + case HUNTER_PET: + { + if (CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(GetCreatureInfo()->pet_family)) + { + SetName(cFamily->Name[sWorld.GetDefaultDbcLocale()]); + break; + } + // no break + } + default: + { + SetName(Creature::GetNameForLocaleIdx(sObjectMgr.GetDBCLocaleIndex())); + break; + } + } +} + +char const* Pet::GetNameForLocaleIdx(int32 locale_idx) const +{ + if (GetOwnerGuid().IsPlayer() && (getPetType() == SUMMON_PET || getPetType() == HUNTER_PET)) + return GetName(); + + return Creature::GetNameForLocaleIdx(locale_idx); +} + bool Pet::Create(uint32 guidlow, CreatureCreatePos& cPos, CreatureInfo const* cinfo, uint32 pet_number) { SetMap(cPos.GetMap()); diff --git a/src/game/Objects/Pet.h b/src/game/Objects/Pet.h index 218ddb67c00..7f28cba2b79 100644 --- a/src/game/Objects/Pet.h +++ b/src/game/Objects/Pet.h @@ -165,8 +165,10 @@ class Pet : public Creature void DelayedUnsummon(uint32 timeMSToDespawn, PetSaveMode mode); static void DeleteFromDB(uint32 guidlow, bool separate_transaction = true); + void InitializeDefaultName(); char const* GetName() const final { return m_name.c_str(); } void SetName(std::string const& newname) { m_name = newname; } + char const* GetNameForLocaleIdx(int32 locale_idx) const final; void SetDeathState(DeathState s) override; // overwrite virtual Creature::SetDeathState and Unit::SetDeathState void Update(uint32 update_diff, uint32 diff) override; // overwrite virtual Creature::Update and Unit::Update @@ -261,9 +263,6 @@ class Pet : public Creature void SetAuraUpdateMask(uint64 mask) { m_auraUpdateMask = mask; } void ResetAuraUpdateMask() { m_auraUpdateMask = 0; } - // overwrite Creature function for name localization back to WorldObject version without localization - char const* GetNameForLocaleIdx(int32 locale_idx) const final { return Pet::GetName(); } - bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved) protected: std::string m_name; diff --git a/src/game/Spells/SpellEffects.cpp b/src/game/Spells/SpellEffects.cpp index ff569b68f82..15cfa3ff0fe 100644 --- a/src/game/Spells/SpellEffects.cpp +++ b/src/game/Spells/SpellEffects.cpp @@ -3106,7 +3106,7 @@ void Spell::EffectSummon(SpellEffectIndex effIdx) if (m_duration > 0) spawnCreature->SetDuration(m_duration); - //spawnCreature->SetName(""); // generated by client + spawnCreature->InitializeDefaultName(); spawnCreature->SetOwnerGuid(m_casterUnit->GetObjectGuid()); spawnCreature->SetCreatorGuid(m_casterUnit->GetObjectGuid()); spawnCreature->SetFactionTemplateId(m_casterUnit->GetFactionTemplateId()); @@ -3647,7 +3647,7 @@ void Spell::EffectSummonGuardian(SpellEffectIndex effIdx) if (m_duration > 0) spawnCreature->SetDuration(m_duration); - //spawnCreature->SetName(""); // generated by client + spawnCreature->InitializeDefaultName(); spawnCreature->SetOwnerGuid(m_casterUnit->GetObjectGuid()); spawnCreature->SetCreatorGuid(m_casterUnit->GetObjectGuid()); spawnCreature->SetFactionTemplateId(m_casterUnit->GetFactionTemplateId()); @@ -4090,9 +4090,14 @@ ObjectGuid Unit::EffectSummonPet(uint32 spellId, uint32 petEntry, uint32 petLeve std::string newName = sObjectMgr.GeneratePetName(petEntry); if (!newName.empty()) newSummon->SetName(newName); + else + newSummon->InitializeDefaultName(); } else if (newSummon->getPetType() == HUNTER_PET) + { newSummon->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PET_RENAME); + newSummon->InitializeDefaultName(); + } if (IsPvP()) newSummon->SetPvP(true); @@ -6402,6 +6407,7 @@ void Spell::EffectSummonCritter(SpellEffectIndex effIdx) if (m_duration > 0) critter->SetDuration(m_duration); + critter->InitializeDefaultName(); critter->SetOwnerGuid(m_caster->GetObjectGuid()); critter->SetCreatorGuid(m_caster->GetObjectGuid()); critter->SetFactionTemplateId(m_caster->GetFactionTemplateId());