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

Commit

Permalink
Core/Player: define and implement PLAYER_FIELD_BYTE_HIDE_PET_BAR
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovahlord committed Sep 28, 2023
1 parent 99cadac commit e492ba0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
7 changes: 2 additions & 5 deletions src/server/game/Entities/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17842,7 +17842,7 @@ Optional<uint8> Player::GetUnusedActivePetSlot()
void Player::DismissPet(bool temporary)
{
NewPet* pet = GetActivelyControlledSummon();
if (!pet || !pet->CanBeDismissed() || (pet->IsClassPet() && !CanControlClassPets()))
if (!pet || !pet->CanBeDismissed())
return;

Optional<PlayerPetDataKey> const& key = pet->GetPlayerPetDataKey();
Expand Down Expand Up @@ -20398,10 +20398,6 @@ bool Player::RemoveMItem(uint32 id)

void Player::SendPetSpellsMessage(NewPet* pet, bool remove /*= false*/)
{
// Warlocks and Hunters cannot control their pets until they have learned their respective control spell
if (pet->IsClassPet() && !CanControlClassPets())
return;

CharmInfo* charmInfo = pet->GetCharmInfo();
if (!charmInfo)
{
Expand Down Expand Up @@ -20441,6 +20437,7 @@ void Player::SendPetSpellsMessage(NewPet* pet, bool remove /*= false*/)
void Player::SetCanControlClassPets()
{
_canControlClassPets = true;
RemoveByteFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTES_OFFSET_FLAGS, PLAYER_FIELD_BYTE_HIDE_PET_BAR);
}

bool Player::CanControlClassPets() const
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Entities/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ enum PlayerFieldByteFlags
{
PLAYER_FIELD_BYTE_TRACK_STEALTHED = 0x00000002,
PLAYER_FIELD_BYTE_RELEASE_TIMER = 0x00000008, // Display time till auto release spirit
PLAYER_FIELD_BYTE_NO_RELEASE_WINDOW = 0x00000010 // Display no "release spirit" window at all
PLAYER_FIELD_BYTE_NO_RELEASE_WINDOW = 0x00000010, // Display no "release spirit" window at all
PLAYER_FIELD_BYTE_HIDE_PET_BAR = 0x00000020 // Hides the control bar of pets
};

// used in PLAYER_FIELD_BYTES2 values
Expand Down
18 changes: 10 additions & 8 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5574,16 +5574,20 @@ void Unit::SetActivelyControlledSummon(NewPet* pet, bool apply)

SetSummonGUID(apply ? pet->GetGUID() : ObjectGuid::Empty);

if (IsPlayer())
if (Player* player = ToPlayer())
{
if (apply)
pet->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
else
pet->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PLAYER_CONTROLLED);
}

if (IsPlayer())
ToPlayer()->SendPetSpellsMessage(pet, !apply);
bool canControlPet = true;
if (pet->IsClassPet() && !player->CanControlClassPets())
canControlPet = false;

player->ApplyModByteFlag(PLAYER_FIELD_BYTES, PLAYER_FIELD_BYTES_OFFSET_FLAGS, PLAYER_FIELD_BYTE_HIDE_PET_BAR, (apply && !canControlPet));
player->SendPetSpellsMessage(pet, !apply);
}
}

Player* Unit::GetControllingPlayer() const
Expand Down Expand Up @@ -14275,9 +14279,7 @@ NewPet* Unit::SummonPet(uint32 creatureId, uint8 slot, uint32 spellId, bool asCl

PhasingHandler::InheritPhaseShift(pet, this);

if (!pet->IsHunterPet())
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spellId);

pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spellId);
pet->SetPermanentSummon(true);

bool successfullyCreated = [&]()
Expand Down Expand Up @@ -14314,7 +14316,7 @@ NewPet* Unit::SummonPet(uint32 creatureId, uint8 slot, uint32 spellId, bool asCl
if (pet->IsHunterPet())
{
// Hunter pets have some special settings
pet->SetByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, UNIT_CAN_BE_ABANDONED);
pet->SetByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, UNIT_CAN_BE_ABANDONED | 0x4);
if (!playerPetData->HasBeenRenamed)
pet->SetByteFlag(UNIT_FIELD_BYTES_2, UNIT_BYTES_2_OFFSET_PET_FLAGS, UNIT_CAN_BE_RENAMED);
}
Expand Down

0 comments on commit e492ba0

Please sign in to comment.