Skip to content

Commit

Permalink
Fix creature pet names.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed Dec 18, 2023
1 parent b98dff5 commit dc3c752
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
38 changes: 33 additions & 5 deletions src/game/Objects/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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)
{
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 2 additions & 3 deletions src/game/Objects/Pet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit dc3c752

Please sign in to comment.