Skip to content

Commit 96dd657

Browse files
authored
Merge d9d2af0 into 09b4d1f
2 parents 09b4d1f + d9d2af0 commit 96dd657

7 files changed

Lines changed: 622 additions & 448 deletions

File tree

src/game/Object/PetMgr.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* MaNGOS is a full featured server for World of Warcraft, supporting
3+
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
4+
*
5+
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20+
*
21+
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
22+
* and lore are copyrighted by Blizzard Entertainment, Inc.
23+
*/
24+
25+
#include "PetMgr.h"
26+
#include "Player.h"
27+
#include "Pet.h"
28+
#include "Transports.h"
29+
#include "WorldPacket.h"
30+
#include "Opcodes.h"
31+
#include "Log.h"
32+
33+
void PetMgr::LoadStableSlotsFromField(uint32 raw)
34+
{
35+
m_stableSlots = raw;
36+
if (m_stableSlots > MAX_PET_STABLES)
37+
{
38+
sLog.outError("Player can have not more %u stable slots, but have in DB %u", MAX_PET_STABLES, uint32(m_stableSlots));
39+
m_stableSlots = MAX_PET_STABLES;
40+
}
41+
}
42+
43+
void PetMgr::Remove(PetSaveMode mode)
44+
{
45+
if (Pet* pet = m_owner->GetPet())
46+
{
47+
pet->Unsummon(mode, m_owner);
48+
}
49+
}
50+
51+
void PetMgr::RemoveActionBar()
52+
{
53+
WorldPacket data(SMSG_PET_SPELLS, 8);
54+
data << ObjectGuid();
55+
m_owner->SendDirectMessage(&data);
56+
}
57+
58+
void PetMgr::UnsummonTemporaryIfAny()
59+
{
60+
Pet* pet = m_owner->GetPet();
61+
if (!pet)
62+
{
63+
return;
64+
}
65+
66+
if (!m_temporaryUnsummonedPetNumber && pet->isControlled() && !pet->isTemporarySummoned())
67+
{
68+
m_temporaryUnsummonedPetNumber = pet->GetCharmInfo()->GetPetNumber();
69+
}
70+
71+
if (Transport* petTransport = pet->GetTransport())
72+
{
73+
petTransport->RemovePassenger(pet);
74+
pet->SetTransport(nullptr);
75+
}
76+
77+
pet->Unsummon(PET_SAVE_AS_CURRENT, m_owner);
78+
}
79+
80+
void PetMgr::ResummonTemporaryUnsummonedIfAny()
81+
{
82+
if (!m_temporaryUnsummonedPetNumber)
83+
{
84+
return;
85+
}
86+
87+
// not resummon in not appropriate state
88+
if (m_owner->IsPetNeedBeTemporaryUnsummoned())
89+
{
90+
return;
91+
}
92+
93+
if (m_owner->GetPetGuid())
94+
{
95+
return;
96+
}
97+
98+
Pet* NewPet = new Pet;
99+
if (!NewPet->LoadPetFromDB(m_owner, 0, m_temporaryUnsummonedPetNumber, true))
100+
{
101+
delete NewPet;
102+
}
103+
104+
m_temporaryUnsummonedPetNumber = 0;
105+
}

src/game/Object/PetMgr.h

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* MaNGOS is a full featured server for World of Warcraft, supporting
3+
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
4+
*
5+
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20+
*
21+
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
22+
* and lore are copyrighted by Blizzard Entertainment, Inc.
23+
*/
24+
25+
#ifndef MANGOS_H_PETMGR
26+
#define MANGOS_H_PETMGR
27+
28+
#include "Common.h"
29+
#include "Pet.h" // PetSaveMode enum + MAX_PET_STABLES constant
30+
31+
class Player;
32+
33+
/**
34+
* PetMgr — owns a Player's pet-ownership metadata: the stable-slot
35+
* count persisted with the character row and the temporary-unsummon
36+
* tracking number used by transports / mounts to bring the same pet
37+
* back after a short interruption.
38+
*
39+
* What this DOES NOT own:
40+
* - The Pet creature itself (a Creature subclass living in the world,
41+
* managed by Object/Pet.{cpp,h}). Its lifecycle, AI, spells, and
42+
* persistence to the `character_pet` table all stay in Pet.cpp.
43+
* - The pet stable opcode handlers (CMSG_STABLE_PET and friends in
44+
* WorldHandlers/NPCHandler.cpp). They keep reading/updating the slot
45+
* count through Player's public accessors, so the stable-purchase
46+
* economics (gold cost via StableSlotPricesStore, MAX_PET_STABLES
47+
* cap) are untouched.
48+
*/
49+
class PetMgr
50+
{
51+
public:
52+
explicit PetMgr(Player* owner)
53+
: m_owner(owner), m_stableSlots(0), m_temporaryUnsummonedPetNumber(0)
54+
{
55+
}
56+
57+
/// Number of paid stable slots the character has unlocked.
58+
/// Persisted to `characters`.stable_slots; clamped to
59+
/// MAX_PET_STABLES on load.
60+
uint32 GetStableSlots() const { return m_stableSlots; }
61+
void SetStableSlots(uint32 slots) { m_stableSlots = slots; }
62+
63+
/// Called from Player::LoadFromDB with the raw column value.
64+
/// Clamps to MAX_PET_STABLES and logs a server error on
65+
/// out-of-range data so an operator can detect a tampered row.
66+
void LoadStableSlotsFromField(uint32 raw);
67+
68+
/// Pet number that was active before a temporary unsummon (e.g.
69+
/// transport zone-in). Zero means no pending resummon.
70+
uint32 GetTemporaryUnsummonedPetNumber() const { return m_temporaryUnsummonedPetNumber; }
71+
void SetTemporaryUnsummonedPetNumber(uint32 petnumber) { m_temporaryUnsummonedPetNumber = petnumber; }
72+
73+
/// If the owner currently has a controlled pet, asks it to
74+
/// unsummon with the given mode (see PetSaveMode).
75+
void Remove(PetSaveMode mode);
76+
77+
/// SMSG_PET_SPELLS with an empty guid — clears the pet action
78+
/// bar UI on the client.
79+
void RemoveActionBar();
80+
81+
/// Stash the current non-temporary pet's number so we can bring
82+
/// it back later, then unsummon with PET_SAVE_AS_CURRENT.
83+
void UnsummonTemporaryIfAny();
84+
85+
/// Counterpart to UnsummonTemporaryIfAny: if we stashed a pet
86+
/// number and it's now appropriate to resummon, load it from DB.
87+
/// Clears the stash either way.
88+
void ResummonTemporaryUnsummonedIfAny();
89+
90+
private:
91+
Player* m_owner;
92+
uint32 m_stableSlots;
93+
uint32 m_temporaryUnsummonedPetNumber;
94+
};
95+
96+
#endif // MANGOS_H_PETMGR

0 commit comments

Comments
 (0)