Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/Pets: fixed pet health and power initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovahlord committed Sep 26, 2023
1 parent feeb8b9 commit 9e5c2d2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "NewGuardian.h"
#include "DBCStores.h"
#include "ObjectMgr.h"
#include "NewPet.h"
#include "SpellMgr.h"
#include "SpellInfo.h"

Expand Down Expand Up @@ -47,14 +48,25 @@ void NewGuardian::InitializeStats()

SetMeleeDamageSchool(SpellSchools(creatureInfo->dmgschool));

if (PetLevelInfo const* petLevelInfo = sObjectMgr->GetPetLevelInfo(creatureInfo->Entry, getLevel()))
uint32 creatureIdForStats = creatureInfo->Entry;
if (IsPet() && ToNewPet()->IsHunterPet())
{
creatureIdForStats = 1; // hunter pet level stats are stored under creatureId 1 in pet_levelstats
SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_CLASS, CLASS_WARRIOR);
SetByteValue(UNIT_FIELD_BYTES_0, UNIT_BYTES_0_OFFSET_GENDER, GENDER_NONE);
SetSheath(SHEATH_STATE_MELEE);
SetPowerType(POWER_FOCUS);
}

if (PetLevelInfo const* petLevelInfo = sObjectMgr->GetPetLevelInfo(creatureIdForStats, getLevel()))
{
for (uint8 i = 0; i < MAX_STATS; ++i)
SetCreateStat(Stats(i), float(petLevelInfo->stats[i]));

if (petLevelInfo->armor > 0)
SetStatFlatModifier(UNIT_MOD_ARMOR, BASE_VALUE, float(petLevelInfo->armor));

SetMaxHealth(petLevelInfo->health);
SetCreateHealth(petLevelInfo->health);
SetCreateMana(petLevelInfo->mana);

Expand Down
7 changes: 5 additions & 2 deletions src/server/game/Entities/Creature/TemporarySummon/NewPet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ bool NewPet::LearnSpell(uint32 spellId)
if (!AddSpell(spellId))
return false;

SendSpellLearnedToSummoner(spellId);
if (IsInWorld())
SendSpellLearnedToSummoner(spellId);

return true;
}
Expand All @@ -256,7 +257,9 @@ bool NewPet::UnlearnSpell(uint32 spellId, bool learnPreviousRank, bool clearActi
if (!RemoveSpell(spellId, learnPreviousRank, clearActionbar))
return false;

SendSpellUnlearnedToSummoner(spellId);
if (IsInWorld())
SendSpellUnlearnedToSummoner(spellId);

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/server/game/Entities/Creature/TemporarySummon/NewPet.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class TC_GAME_API NewPet final : public NewGuardian

// Returns true if the pet is belongs to a specific class (Hunter Pets, Mage Water Elementals, DK Ghouls and Warlock Demons)
bool IsClassPet() const { return _isClassPet; }
// Returns true if the pet is a hunter class pet. This is the case when the pet has player pet data and is stored under creatureId = 0
bool IsHunterPet() const { return _playerPetDataKey.has_value() && _playerPetDataKey->second == 0; }

// Returns true if the summoner is allowed to dismiss the pet via pet action
bool CanBeDismissed() const;
// Returns or creates player pet data. Does return nullptr when the summon is a hunter pet and no pet data is available
Expand Down
46 changes: 29 additions & 17 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5165,6 +5165,7 @@ void Unit::SetPowerType(Powers new_powertype)
if (ToPlayer()->GetGroup())
ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POWER_TYPE);
}
/*
else if (Pet* pet = ToCreature()->ToPet())
{
if (pet->isControlled())
Expand All @@ -5173,7 +5174,7 @@ void Unit::SetPowerType(Powers new_powertype)
if (owner && (owner->GetTypeId() == TYPEID_PLAYER) && owner->ToPlayer()->GetGroup())
owner->ToPlayer()->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_PET_POWER_TYPE);
}
}
}*/

// Update max power
UpdateMaxPower(new_powertype);
Expand All @@ -5187,9 +5188,6 @@ void Unit::SetPowerType(Powers new_powertype)
case POWER_RAGE: // Reset to zero
SetPower(POWER_RAGE, 0);
break;
case POWER_FOCUS: // Make it full
SetFullPower(new_powertype);
break;
default:
break;
}
Expand Down Expand Up @@ -5228,13 +5226,6 @@ void Unit::UpdateDisplayPower()
else if (getClass() == CLASS_ROGUE)
displayPower = POWER_ENERGY;
}
else if (Pet* pet = ToPet())
{
if (pet->getPetType() == HUNTER_PET) // Hunter pets have focus
displayPower = POWER_FOCUS;
else if (pet->IsPetGhoul() || pet->IsRisenAlly()) // DK pets have energy
displayPower = POWER_ENERGY;
}
}
break;
}
Expand Down Expand Up @@ -9008,9 +8999,7 @@ int32 Unit::GetCreatePowers(Powers power) const
case POWER_RAGE:
return 1000;
case POWER_FOCUS:
if (GetTypeId() == TYPEID_PLAYER && getClass() == CLASS_HUNTER)
return 100;
return (GetTypeId() == TYPEID_PLAYER || !((Creature const*)this)->IsPet() || ((Pet const*)this)->getPetType() != HUNTER_PET ? 0 : 100);
return 100;
case POWER_ENERGY:
return 100;
case POWER_RUNIC_POWER:
Expand Down Expand Up @@ -14244,8 +14233,13 @@ NewPet* Unit::SummonPet(uint32 creatureId, uint8 slot, uint32 spellId, bool asCl
}

uint32 creatureTemplateEntry = creatureId;
if (playerPetData && playerPetData->TamedCreatureId)
creatureTemplateEntry = playerPetData->TamedCreatureId;
if (playerPetData)
{
if (playerPetData->TamedCreatureId)
creatureTemplateEntry = playerPetData->TamedCreatureId;

pet->SetPlayerPetDataKey(slot, creatureId);
}

Map* map = GetMap();
if (!pet->Create(map->GenerateLowGuid<HighGuid::Pet>(), map, creatureTemplateEntry, playerPetData != nullptr ? playerPetData->PetNumber : 0))
Expand Down Expand Up @@ -14278,20 +14272,38 @@ NewPet* Unit::SummonPet(uint32 creatureId, uint8 slot, uint32 spellId, bool asCl
// initialize pet behavior
if (playerPetData)
{
pet->SetPlayerPetDataKey(slot, creatureId);
playerPetData->IsActive = true;
playerPetData->DisplayId = pet->GetNativeDisplayId();
playerPetData->CreatedBySpellId = spellId;
pet->GetCharmInfo()->SetPetNumber(playerPetData->PetNumber, pet->IsClassPet());
pet->GetCharmInfo()->LoadPetActionBar(playerPetData->ActionBar);
pet->SetName(playerPetData->Name);
pet->SetReactState(playerPetData->ReactState);
if (playerPetData->Status != PlayerPetDataStatus::New)
{
if (IsHunterPet())
{
if (playerPetData->SavedHealth != 0)
pet->SetHealth(playerPetData->SavedHealth);
else
pet->setDeathState(JUST_DIED);
}
else
pet->SetFullHealth();
}
else
pet->SetFullHealth();

if (!creatureId)
{
// Hunter pets have some special settings
SetByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, playerPetData->HasBeenRenamed ? UNIT_CAN_BE_ABANDONED : (UNIT_CAN_BE_RENAMED | UNIT_CAN_BE_ABANDONED));
}
else
SetByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, 0);
}
else
pet->SetFullHealth();

return map->AddToMap(pet->ToCreature());
}();
Expand Down

0 comments on commit 9e5c2d2

Please sign in to comment.