Skip to content

Commit

Permalink
Core/Pets: Implemented sound playback when dismissing warlock's pet.
Browse files Browse the repository at this point in the history
  • Loading branch information
r4d1sh committed Feb 9, 2025
1 parent b4adab5 commit e6c0c3d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/server/game/Entities/Pet/PetDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ enum ActionFeedback
FEEDBACK_CANT_ATT_TARGET = 3
};

enum PetTalk
enum PetAction : int32
{
PET_TALK_SPECIAL_SPELL = 0,
PET_TALK_ATTACK = 1
PET_ACTION_SPECIAL_SPELL = 0,
PET_ACTION_ATTACK = 1
};

#define PET_FOLLOW_DIST 1.0f
Expand Down
20 changes: 10 additions & 10 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "PassiveAI.h"
#include "PetAI.h"
#include "Pet.h"
#include "PetPackets.h"
#include "Player.h"
#include "PlayerAI.h"
#include "QuestDef.h"
Expand Down Expand Up @@ -10241,7 +10242,7 @@ void Unit::TriggerAurasProcOnEvent(ProcEventInfo& eventInfo, AuraApplicationProc
}

///----------Pet responses methods-----------------
void Unit::SendPetActionFeedback(uint8 msg)
void Unit::SendPetActionFeedback(uint8 msg) const
{
Unit* owner = GetOwner();
if (!owner || owner->GetTypeId() != TYPEID_PLAYER)
Expand All @@ -10252,19 +10253,18 @@ void Unit::SendPetActionFeedback(uint8 msg)
owner->ToPlayer()->SendDirectMessage(&data);
}

void Unit::SendPetTalk(uint32 pettalk)
void Unit::SendPetActionSound(PetAction action) const
{
Unit* owner = GetOwner();
if (!owner || owner->GetTypeId() != TYPEID_PLAYER)
return;
SendMessageToSet(WorldPackets::Pet::PetActionSound(GetGUID(), static_cast<int32>(action)).Write(), false);
}

WorldPacket data(SMSG_PET_ACTION_SOUND, 8 + 4);
data << uint64(GetGUID());
data << uint32(pettalk);
owner->ToPlayer()->SendDirectMessage(&data);
void Unit::SendPetDismissSound() const
{
if (CreatureDisplayInfoEntry const* displayInfo = sCreatureDisplayInfoStore.LookupEntry(GetNativeDisplayId()))
SendMessageToSet(WorldPackets::Pet::PetDismissSound(displayInfo->ModelID, GetPosition()).Write(), false);
}

void Unit::SendPetAIReaction(ObjectGuid guid)
void Unit::SendPetAIReaction(ObjectGuid guid) const
{
Unit* owner = GetOwner();
if (!owner || owner->GetTypeId() != TYPEID_PLAYER)
Expand Down
8 changes: 5 additions & 3 deletions src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Object.h"
#include "CombatManager.h"
#include "SpellAuraDefines.h"
#include "PetDefines.h"
#include "ThreatManager.h"
#include "Timer.h"
#include "UnitDefines.h"
Expand Down Expand Up @@ -1707,9 +1708,10 @@ class TC_GAME_API Unit : public WorldObject
void ClearComboPointHolders();

///----------Pet responses methods-----------------
void SendPetActionFeedback(uint8 msg);
void SendPetTalk(uint32 pettalk);
void SendPetAIReaction(ObjectGuid guid);
void SendPetActionFeedback(uint8 msg) const;
void SendPetActionSound(PetAction action) const;
void SendPetDismissSound() const;
void SendPetAIReaction(ObjectGuid guid) const;
///----------End of Pet responses methods----------

void PropagateSpeedChange();
Expand Down
24 changes: 14 additions & 10 deletions src/server/game/Handlers/PetHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ void WorldSession::HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint32 spe
AI->AttackStart(TargetUnit);

// 10% chance to play special pet attack talk, else growl
if (pet->IsPet() && ((Pet*)pet)->getPetType() == SUMMON_PET && pet != TargetUnit && urand(0, 100) < 10)
pet->SendPetTalk((uint32)PET_TALK_ATTACK);
if (pet->IsPet() && pet->ToPet()->getPetType() == SUMMON_PET && pet != TargetUnit && roll_chance_i(10))
pet->SendPetActionSound(PET_ACTION_SOUND_ATTACK);
else
{
// 90% chance for pet and 100% chance for charmed creature
Expand Down Expand Up @@ -242,10 +242,14 @@ void WorldSession::HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint32 spe
ASSERT(pet->GetTypeId() == TYPEID_UNIT);
if (pet->IsPet())
{
if (((Pet*)pet)->getPetType() == HUNTER_PET)
GetPlayer()->RemovePet((Pet*)pet, PET_SAVE_AS_DELETED);
if (pet->ToPet()->getPetType() == HUNTER_PET)
GetPlayer()->RemovePet(pet->ToPet(), PET_SAVE_AS_DELETED);
else
GetPlayer()->RemovePet((Pet*)pet, PET_SAVE_NOT_IN_SLOT);
{
pet->SendPetDismissSound();
GetPlayer()->RemovePet(pet->ToPet(), PET_SAVE_NOT_IN_SLOT);
}

}
else if (pet->HasUnitTypeMask(UNIT_MASK_MINION))
{
Expand Down Expand Up @@ -342,8 +346,8 @@ void WorldSession::HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint32 spe

// 10% chance to play special pet attack talk, else growl
// actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell
if (pet->IsPet() && (((Pet*)pet)->getPetType() == SUMMON_PET) && (pet != unit_target) && (urand(0, 100) < 10))
pet->SendPetTalk((uint32)PET_TALK_SPECIAL_SPELL);
if (pet->IsPet() && pet->ToPet()->getPetType() == SUMMON_PET && pet != unit_target && roll_chance_i(10))
pet->SendPetActionSound(PET_ACTION_SOUND_SPECIAL_SPELL);
else
{
pet->SendPetAIReaction(guid1);
Expand Down Expand Up @@ -811,10 +815,10 @@ void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket)
{
if (Pet* pet = creature->ToPet())
{
// 10% chance to play special pet attack talk, else growl
// 10% chance to play special pet attack sound, else growl
// actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell
if (pet->getPetType() == SUMMON_PET && (urand(0, 100) < 10))
pet->SendPetTalk(PET_TALK_SPECIAL_SPELL);
if (pet->getPetType() == SUMMON_PET && roll_chance_i(10))
pet->SendPetActionSound(PET_ACTION_SOUND_SPECIAL_SPELL);
else
pet->SendPetAIReaction(guid);
}
Expand Down
14 changes: 14 additions & 0 deletions src/server/game/Server/Packets/PetPackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ WorldPacket const* WorldPackets::Pet::PetUnlearnedSpell::Write()
_worldPacket << uint32(SpellID);
return &_worldPacket;
}

WorldPacket const* WorldPackets::Pet::PetActionSound::Write()
{
_worldPacket << UnitGUID;
_worldPacket << int32(Action);
return &_worldPacket;
}

WorldPacket const* WorldPackets::Pet::PetDismissSound::Write()
{
_worldPacket << uint32(ModelId);
_worldPacket << Position;
return &_worldPacket;
}
25 changes: 25 additions & 0 deletions src/server/game/Server/Packets/PetPackets.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define PetPackets_h__

#include "Packet.h"
#include "Position.h"
#include "ObjectGuid.h"

namespace WorldPackets
Expand Down Expand Up @@ -94,6 +95,30 @@ namespace WorldPackets

void Read() override { }
};

class PetActionSound final : public ServerPacket
{
public:
PetActionSound(ObjectGuid unitGUID, int32 action)
: ServerPacket(SMSG_PET_ACTION_SOUND, 8 + 4), UnitGUID(unitGUID), Action(action) { }

WorldPacket const* Write() override;

ObjectGuid UnitGUID;
int32 Action = 0;
};

class PetDismissSound final : public ServerPacket
{
public:
PetDismissSound(uint32 modelId, Position position)
: ServerPacket(SMSG_PET_DISMISS_SOUND, 4 + 12), ModelId(modelId), Position(position) { }

WorldPacket const* Write() override;

uint32 ModelId = 0;
TaggedPosition<Position::XYZ> Position;
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/scripts/Commands/cs_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ class debug_commandscript : public CommandScript
handler->PSendSysMessage("Entry: %u Count: %u", p.first, p.second);
}

static bool HandleDebugDummyCommand(ChatHandler* handler)
static bool HandleDebugDummyCommand(ChatHandler* handler, uint32 type)
{
handler->SendSysMessage("This command does nothing right now. Edit your local core (cs_debug.cpp) to make it do whatever you need for testing.");
return true;
Expand Down

0 comments on commit e6c0c3d

Please sign in to comment.